formlab-mcp 0.7.6 → 0.7.8
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/tools/ingredients.js +9 -1
- package/vendor/cost.js +87 -16
- package/vendor/fragrance.js +3 -2
- package/vendor/nesting.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
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.8",
|
|
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.8",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/tools/ingredients.js
CHANGED
|
@@ -36,7 +36,13 @@ function _costPerKg(i) {
|
|
|
36
36
|
const dens = _densityKgPerL(i);
|
|
37
37
|
return dens ? +((v / _VOL_TO_L[unit]) / dens).toFixed(6) : null;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
const pk = _pieceKg(i); // priced per piece (a wick): through the weight per piece (0.7.8)
|
|
40
|
+
return pk ? +(v / pk).toFixed(6) : null;
|
|
41
|
+
}
|
|
42
|
+
function _pieceKg(i) {
|
|
43
|
+
const m = i && i.unitMass; const v = m ? Number(m.value) : NaN;
|
|
44
|
+
const f = m ? _MASS_TO_KG[String(m.unit || '').toLowerCase()] : null;
|
|
45
|
+
return isFinite(v) && v > 0 && f ? v * f : null;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
function _trimIngredient(i) {
|
|
@@ -60,6 +66,8 @@ function _trimIngredient(i) {
|
|
|
60
66
|
purity: i.purity != null && i.purity !== '' ? Number(i.purity) : null,
|
|
61
67
|
density: i.density != null ? i.density : null,
|
|
62
68
|
densityUnit: i.densityUnit || (i.density != null ? 'kg/L' : null),
|
|
69
|
+
// What one piece weighs (a wick): a recipe row counted in pieces converts through it (0.7.8).
|
|
70
|
+
...(_pieceKg(i) ? { weightPerPiece: { value: Number(i.unitMass.value), unit: i.unitMass.unit } } : {}),
|
|
63
71
|
cost: (cost && cost.value != null && cost.value !== '')
|
|
64
72
|
? { value: cost.value, currency: cost.currency || 'USD', unit: cost.unit || 'kg' } : null,
|
|
65
73
|
costPerKg: _costPerKg(i),
|
package/vendor/cost.js
CHANGED
|
@@ -170,7 +170,28 @@ function ensureUnitDatalists() {
|
|
|
170
170
|
function getQuantityUnits() {
|
|
171
171
|
const customCount = Object.entries((typeof db !== 'undefined' && db?.customUnits) || {})
|
|
172
172
|
.filter(([_, v]) => v?.dimension === 'count').map(([k]) => k);
|
|
173
|
-
return [...new Set([...Object.keys(getMassUnits()), ...Object.keys(getVolUnits()), 'units', 'each', ...customCount])];
|
|
173
|
+
return [...new Set([...Object.keys(getMassUnits()), ...Object.keys(getVolUnits()), 'units', 'each', ...customCount, ..._usedCountUnits(), ...FL_COUNT_UNITS_COMMON])];
|
|
174
|
+
}
|
|
175
|
+
// Everyday count units for finished goods, offered before anyone uses them (Jun, 2 Dec: "and remember pill?").
|
|
176
|
+
// Each one gets a Mass per unit on the batch or sample so cost and yield still work.
|
|
177
|
+
const FL_COUNT_UNITS_COMMON = ['piece', 'pill', 'tablet', 'capsule', 'softgel', 'gummy', 'lozenge', 'sachet', 'stick',
|
|
178
|
+
'bar', 'candle', 'cookie', 'bottle', 'jar', 'tube', 'can', 'vial', 'ampoule', 'pouch', 'bag', 'box', 'pack', 'kit',
|
|
179
|
+
// Lab and R&D pieces (Jun, 2 Dec: "bottle? cell? etc"): test cells, coated panels, pressed pellets, specimens.
|
|
180
|
+
'cell', 'wafer', 'panel', 'coupon', 'plate', 'slide', 'disc', 'pellet', 'sheet', 'roll', 'swatch', 'specimen', 'cartridge', 'pod'];
|
|
181
|
+
// Count units already used on batches and samples beyond the common ones (Jun, 2 Dec), most used first, so the
|
|
182
|
+
// list offers them next time. A unit differing only in case from one already listed is left out.
|
|
183
|
+
function _usedCountUnits() {
|
|
184
|
+
if (typeof db === 'undefined' || !db) return [];
|
|
185
|
+
const known = new Set([...Object.keys(getMassUnits()), ...Object.keys(getVolUnits()), 'units', 'each', ...FL_COUNT_UNITS_COMMON].map(u => u.toLowerCase()));
|
|
186
|
+
const n = new Map();
|
|
187
|
+
[...(db.batches || []), ...(db.samples || [])].forEach(r => {
|
|
188
|
+
const u = String((r && r.unit) || '').trim();
|
|
189
|
+
if (!u || u.length > 24 || known.has(u.toLowerCase()) || isMassUnit(u) || isVolUnit(u)) return;
|
|
190
|
+
n.set(u, (n.get(u) || 0) + 1);
|
|
191
|
+
});
|
|
192
|
+
const seen = new Set();
|
|
193
|
+
return [...n.entries()].sort((x, y) => y[1] - x[1]).map(([u]) => u)
|
|
194
|
+
.filter(u => { const k = u.toLowerCase(); if (seen.has(k)) return false; seen.add(k); return true; }).slice(0, 30);
|
|
174
195
|
}
|
|
175
196
|
|
|
176
197
|
// ============================================================
|
|
@@ -204,7 +225,13 @@ function getQuantityUnits() {
|
|
|
204
225
|
}
|
|
205
226
|
function isOpen() { var p = document.getElementById(POP_ID); return !!(p && p.style.display !== 'none'); }
|
|
206
227
|
function optionsFor(input) {
|
|
207
|
-
var
|
|
228
|
+
var id = input.getAttribute('data-unit-list') || '';
|
|
229
|
+
// The amount-made list is read live: a count unit saved a moment ago (candle) shows the next time it opens.
|
|
230
|
+
if (id === 'fl-units-qty' && typeof getQuantityUnits === 'function') {
|
|
231
|
+
countUnits = FL_COUNT_UNITS_COMMON.concat(_usedCountUnits()); // filed under Amount / count, not Other
|
|
232
|
+
return unitsCommonFirst(getQuantityUnits());
|
|
233
|
+
}
|
|
234
|
+
var dl = document.getElementById(id);
|
|
208
235
|
return dl ? Array.prototype.map.call(dl.children, function (o) { return o.value; }) : [];
|
|
209
236
|
}
|
|
210
237
|
function listEl() { var p = document.getElementById(POP_ID); return p ? p.querySelector('.fl-unit-combo-list') : null; }
|
|
@@ -213,12 +240,13 @@ function getQuantityUnits() {
|
|
|
213
240
|
// Classify a unit into a display group. Mirrors the formula picker's grouping
|
|
214
241
|
// (Mass / Volume / Length …) and uses the same isMassUnit/isVolUnit helpers
|
|
215
242
|
// so custom units land in the right bucket too.
|
|
243
|
+
var countUnits = []; // the amount-made list's count units, refreshed each time that list opens
|
|
216
244
|
function classify(u) {
|
|
217
245
|
if (['wt%', 'vol%', '%', 'ppm', 'ppb'].indexOf(u) !== -1) return 'frac';
|
|
218
246
|
if (typeof isMassUnit === 'function' && isMassUnit(u)) return 'mass';
|
|
219
247
|
if (typeof isVolUnit === 'function' && isVolUnit(u)) return 'vol';
|
|
220
248
|
if (typeof isLengthUnit === 'function' && isLengthUnit(u)) return 'len';
|
|
221
|
-
if (['mol', 'eq', 'each', 'pcs', 'unit', 'units'].indexOf(u) !== -1) return 'amt';
|
|
249
|
+
if (['mol', 'eq', 'each', 'pcs', 'unit', 'units'].indexOf(u) !== -1 || countUnits.indexOf(u) !== -1) return 'amt';
|
|
222
250
|
return 'other';
|
|
223
251
|
}
|
|
224
252
|
var GROUP_ORDER = [['frac', 'Fraction'], ['mass', 'Mass'], ['vol', 'Volume'], ['len', 'Length'], ['amt', 'Amount / count'], ['other', 'Other']];
|
|
@@ -783,13 +811,39 @@ function _densityToKgPerL(value, unit) {
|
|
|
783
811
|
|
|
784
812
|
// Convert an ing.cost to $/kg in the cost's own currency.
|
|
785
813
|
// Returns null if conversion isn't possible (no density for vol→mass).
|
|
786
|
-
|
|
814
|
+
// An ingredient's weight per piece (a wick, a jar, a label) in kg, from ing.unitMass {value, unit}; null when unset
|
|
815
|
+
// (Jun, 2 Dec: "Build it properly"). Pieces are any unit that isn't a mass, volume, length or a percent.
|
|
816
|
+
function flPieceMassKg(unitMass) {
|
|
817
|
+
const v = unitMass ? parseFloat(unitMass.value) : NaN;
|
|
818
|
+
return (isFinite(v) && v > 0 && unitMass.unit in MASS_TO_KG) ? v * MASS_TO_KG[unitMass.unit] : null;
|
|
819
|
+
}
|
|
820
|
+
function flIsPieceUnit(u) {
|
|
821
|
+
const raw = String(u || '').trim(), lower = raw.toLowerCase();
|
|
822
|
+
if (!raw || raw === '%' || lower.startsWith('wt') || lower.startsWith('vol') || ['ppm', 'ppb', 'mol', 'mmol', 'eq', 'phr'].includes(lower)) return false;
|
|
823
|
+
const _cu = (typeof db !== 'undefined' && db && db.customUnits && Object.prototype.hasOwnProperty.call(db.customUnits, raw)) ? db.customUnits[raw] : null;
|
|
824
|
+
if (_cu) return _cu.dimension === 'count'; // a custom count unit ("wick") is a piece; other custom units convert by their own rule
|
|
825
|
+
const hit = t => Object.keys(t).some(k => k === raw || k.toLowerCase() === lower);
|
|
826
|
+
return !hit(MASS_TO_KG) && !hit(VOL_TO_L) && !(typeof LENGTH_TO_M !== 'undefined' && hit(LENGTH_TO_M));
|
|
827
|
+
}
|
|
828
|
+
// A recipe row counted in pieces ("1 wick"), as kg through its ingredient's weight per piece. Null for any other row,
|
|
829
|
+
// or a piece row whose ingredient has no weight per piece (it stays unpriced and unscaled, as before).
|
|
830
|
+
function flPieceRowKg(c) {
|
|
831
|
+
if (!c || !c.ingredientId || !flIsPieceUnit(c.unit)) return null;
|
|
832
|
+
const amt = parseFloat(c.amount);
|
|
833
|
+
if (!isFinite(amt) || amt < 0) return null;
|
|
834
|
+
const ing = (typeof flFindById === 'function') ? flFindById('ingredients', c.ingredientId) : (db.ingredients || []).find(i => i.id === c.ingredientId);
|
|
835
|
+
const per = ing ? flPieceMassKg(ing.unitMass) : null;
|
|
836
|
+
return per == null ? null : amt * per;
|
|
837
|
+
}
|
|
838
|
+
function costPerKgInOwnCurrency(cost, density, densityUnit, unitMass) {
|
|
787
839
|
if (!cost || cost.value == null || cost.value === '') return null;
|
|
788
840
|
const v = parseFloat(cost.value);
|
|
789
841
|
if (!isFinite(v)) return null;
|
|
790
842
|
const u = cost.unit || 'kg';
|
|
791
843
|
|
|
792
844
|
if (u in MASS_TO_KG) return v / MASS_TO_KG[u];
|
|
845
|
+
// A price per piece ($0.12 per wick) through the weight per piece.
|
|
846
|
+
if (flIsPieceUnit(u)) { const per = flPieceMassKg(unitMass); return per ? v / per : null; }
|
|
793
847
|
|
|
794
848
|
if (u in VOL_TO_L) {
|
|
795
849
|
const d = _densityToKgPerL(density, densityUnit);
|
|
@@ -1113,7 +1167,8 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1113
1167
|
return raw;
|
|
1114
1168
|
};
|
|
1115
1169
|
|
|
1116
|
-
|
|
1170
|
+
// A piece row with a weight per piece counts as mass (2 Dec).
|
|
1171
|
+
const kinds = comp.map(c => flPieceRowKg(c) != null ? 'mass-abs' : classifyUnit(c.unit));
|
|
1117
1172
|
const allWt = comp.length && kinds.every(k => k === 'wt-frac');
|
|
1118
1173
|
const allVol = comp.length && kinds.every(k => k === 'vol-frac');
|
|
1119
1174
|
const allAbs = comp.length && kinds.every(k => k === 'mass-abs' || k === 'vol-abs');
|
|
@@ -1162,8 +1217,9 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1162
1217
|
d = _densityToKgPerL(ing.density, ing.densityUnit);
|
|
1163
1218
|
}
|
|
1164
1219
|
if (!isFinite(amt) || flBadAmount(c.amount, c.unit)) continue;
|
|
1165
|
-
|
|
1166
|
-
|
|
1220
|
+
const _pk = flPieceRowKg(c);
|
|
1221
|
+
if (_pk != null || u in MASS_TO_KG) {
|
|
1222
|
+
const m = _pk != null ? _pk : amt * MASS_TO_KG[u];
|
|
1167
1223
|
massKgPerRow.set(c, m);
|
|
1168
1224
|
totalMassKg += m;
|
|
1169
1225
|
if (d) { const v = m / d; volLPerRow.set(c, v); totalVolL += v; }
|
|
@@ -1191,7 +1247,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1191
1247
|
|
|
1192
1248
|
const tryAutoPrice = (ing, c, unit, amount, kind) => {
|
|
1193
1249
|
if (!ing.cost || ing.cost.value == null || ing.cost.value === '') return { ok: false, reason: 'no cost on file' };
|
|
1194
|
-
const perKgOwn = costPerKgInOwnCurrency(ing.cost, ing.density, ing.densityUnit);
|
|
1250
|
+
const perKgOwn = costPerKgInOwnCurrency(ing.cost, ing.density, ing.densityUnit, ing.unitMass);
|
|
1195
1251
|
if (perKgOwn == null) return { ok: false, reason: 'could not convert price unit (needs density?)' };
|
|
1196
1252
|
const perKgDisplay = convertCurrencySync(perKgOwn, ing.cost.currency || 'USD', displayCcy);
|
|
1197
1253
|
if (perKgDisplay == null) return { ok: false, reason: 'unknown currency rate' };
|
|
@@ -1288,9 +1344,9 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1288
1344
|
if (flBadAmount(c.amount, c.unit)) { missing.push({ reason: `bad amount (${flBadAmount(c.amount, c.unit)})`, ingredient: ing }); continue; }
|
|
1289
1345
|
if (!isFinite(amount)) { missing.push({ reason: 'no amount', ingredient: ing }); continue; }
|
|
1290
1346
|
|
|
1291
|
-
const kind = classifyUnit(unit);
|
|
1347
|
+
const kind = flPieceRowKg(c) != null ? 'mass-abs' : classifyUnit(unit);
|
|
1292
1348
|
if (kind === 'unknown') {
|
|
1293
|
-
missing.push({ reason: `unsupported composition unit "${c.unit}"`, ingredient: ing });
|
|
1349
|
+
missing.push({ reason: flIsPieceUnit(c.unit) ? `set a weight per piece on ${ing.name || 'the ingredient'} to cost "${c.unit}"` : `unsupported composition unit "${c.unit}"`, ingredient: ing });
|
|
1294
1350
|
continue;
|
|
1295
1351
|
}
|
|
1296
1352
|
|
|
@@ -1490,9 +1546,11 @@ function computeCompositionFractions(formulation) {
|
|
|
1490
1546
|
if (u.startsWith('wt') || u === '%') { out.kind = 'wt-frac'; return out; }
|
|
1491
1547
|
if (u.startsWith('vol')) { out.kind = 'vol-frac'; return out; }
|
|
1492
1548
|
const cu = canonUnit(rawU);
|
|
1493
|
-
|
|
1549
|
+
const _pk = flPieceRowKg(c);
|
|
1550
|
+
if (_pk != null || cu in MASS_TO_KG) {
|
|
1494
1551
|
out.kind = 'mass-abs';
|
|
1495
|
-
out.massKg = amount * MASS_TO_KG[cu];
|
|
1552
|
+
out.massKg = _pk != null ? _pk : amount * MASS_TO_KG[cu];
|
|
1553
|
+
if (_pk != null) out.pieces = true;
|
|
1496
1554
|
out.volL = d ? out.massKg / d : null;
|
|
1497
1555
|
return out;
|
|
1498
1556
|
}
|
|
@@ -1673,6 +1731,14 @@ function scaleCompositionToBatch(formulation, batchAmount, batchUnit) {
|
|
|
1673
1731
|
byRow.set(comp[i], ok ? frac * amt : null);
|
|
1674
1732
|
});
|
|
1675
1733
|
const out = { unit: batchUnit, dim, byRow, anyNull };
|
|
1734
|
+
// Piece rows (wicks) also as a count: their scaled mass over the weight per piece (2 Dec).
|
|
1735
|
+
if (dim === 'mass') {
|
|
1736
|
+
out.pieces = new Map();
|
|
1737
|
+
fr.rows.forEach((r, i) => {
|
|
1738
|
+
const c = comp[i], g = byRow.get(c), one = r.pieces ? flPieceRowKg(Object.assign({}, c, { amount: 1 })) : null;
|
|
1739
|
+
if (one && g != null && isFinite(g)) out.pieces.set(c, +((g * MASS_TO_KG[batchUnit]) / one).toFixed(3));
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1676
1742
|
if (dim === 'volume' && pd) { out.density = pd; out.totalMassKg = amt * VOL_TO_L[batchUnit] * pd.kgPerL; out.partsSum = amt; }
|
|
1677
1743
|
return out;
|
|
1678
1744
|
}
|
|
@@ -1914,6 +1980,11 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
1914
1980
|
const fmt = n => (n == null || !isFinite(n)) ? '—' : _woDp(n);
|
|
1915
1981
|
const sgn = n => (n == null || !isFinite(n)) ? '—' : (n > 0 ? '+' : '') + _woDp(n);
|
|
1916
1982
|
if (!w || !w.available) {
|
|
1983
|
+
// A count unit (candle, tablet) needs its weight, not a different unit (2 Dec: the note told a 1-candle sample to
|
|
1984
|
+
// switch to g, when Mass per unit is the fix).
|
|
1985
|
+
const _wu = w ? String(w.unit || '').trim() : '';
|
|
1986
|
+
if (w && w.reason === 'bad-unit' && _wu && ['%', 'wt%', 'vol%', 'ppm', 'ppb'].indexOf(_wu) === -1 && !(typeof isMassUnit === 'function' && isMassUnit(_wu)) && !(typeof isVolUnit === 'function' && isVolUnit(_wu)))
|
|
1987
|
+
return `<div style="padding:8px 11px;margin-bottom:12px;background:var(--dk-amber-bg, #fffbeb);border:1px solid var(--dk-amber-line, #fde68a);border-radius:6px;color:var(--dk-amber-fg, #92400e);font-size:12px"><span class="fl-warn" aria-hidden="true"></span> Set a <strong>Mass per unit</strong> (how much one ${esc(_wu)} weighs) to get a weigh-out sheet.</div>`;
|
|
1917
1988
|
if (w && w.reason === 'bad-unit')
|
|
1918
1989
|
return `<div style="padding:8px 11px;margin-bottom:12px;background:var(--dk-amber-bg, #fffbeb);border:1px solid var(--dk-amber-line, #fde68a);border-radius:6px;color:var(--dk-amber-fg, #92400e);font-size:12px"><span class="fl-warn" aria-hidden="true"></span> Set the ${noun} quantity in a <strong>mass or volume unit</strong> (g, kg, mL, L…) to get a weigh-out sheet — currently <strong>${esc(w.unit || '—')}</strong>.</div>`;
|
|
1919
1990
|
if (w && w.reason === 'no-qty')
|
|
@@ -1999,7 +2070,7 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
1999
2070
|
if (a) { actInUnit = toUnit(a.amount, a.unit, r.key); if (actInUnit != null) actualTotal += actInUnit; }
|
|
2000
2071
|
const delta = (hasActuals && planned != null && actInUnit != null) ? (actInUnit - planned) : null;
|
|
2001
2072
|
const rel = (delta != null && planned > 0) ? Math.abs(delta) / planned : (delta != null && actInUnit > 0 ? 1 : null);
|
|
2002
|
-
return { key: r.key, name: r.name, planned, actInUnit, actRaw: a, delta, rel, purity: r.purity, activeAmount: r.activeAmount, qs: r.qs, lotDev: r.lotDev || null, lotBasis: r.lotBasis || null };
|
|
2073
|
+
return { key: r.key, name: r.name, planned, actInUnit, actRaw: a, delta, rel, purity: r.purity, activeAmount: r.activeAmount, qs: r.qs, lotDev: r.lotDev || null, lotBasis: r.lotBasis || null, pieces: r.pieces != null ? r.pieces : null, pieceUnit: r.pieceUnit || '' };
|
|
2003
2074
|
});
|
|
2004
2075
|
// Union in ingredients that were ADDED to the As-prepared table but aren't in
|
|
2005
2076
|
// the recipe (a spike / colorant / q.s. carrier). Without this the weigh-out
|
|
@@ -2106,7 +2177,7 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
|
|
|
2106
2177
|
: `<div class="fl-wo-why" style="font-size:11px;color:var(--dk-muted, #64748b);margin-top:1px;font-variant-numeric:tabular-nums">${cv(r.activeAmount)} ${esc(displayUnit)} active ÷ ${esc(String(+r.purity))}% ${r.lotBasis ? `(lot <span translate="no">${esc(String(r.lotBasis.lotNumber))}</span> assay)` : '(nominal)'} = <strong style="color:var(--dk-text-2, #334155)">${cv(r.planned)} ${esc(displayUnit)}</strong></div>`;
|
|
2107
2178
|
const body = rows.map((r, i) => `<tr data-wo-key="${esc(r.key)}" style="${hasActuals ? dRowBg(r.rel) : ''}">
|
|
2108
2179
|
<td style="padding:4px 8px;color:var(--dk-faint, #94a3b8)">${i + 1}</td>
|
|
2109
|
-
<td style="padding:4px 8px">${esc(r.name)}${purityWhy(r)}${r._added ? ` <span style="font-size:9.5px;color:var(--dk-red-fg, #b91c1c);font-weight:600;background:var(--dk-red-bg, #fef2f2);border:1px solid var(--dk-red-line, #fecaca);border-radius:4px;padding:0 4px;vertical-align:middle;white-space:nowrap" title="Added to the as-prepared batch — not part of the linked recipe">+ not in recipe</span>` : ''}</td>
|
|
2180
|
+
<td style="padding:4px 8px">${esc(r.name)}${purityWhy(r)}${r.pieces != null ? `<div class="fl-wo-why" style="font-size:11px;color:var(--dk-muted, #64748b);margin-top:1px">${esc(String(r.pieces))} ${esc(r.pieceUnit === 'piece' && r.pieces !== 1 ? 'pieces' : r.pieceUnit)} by count</div>` : ''}${r._added ? ` <span style="font-size:9.5px;color:var(--dk-red-fg, #b91c1c);font-weight:600;background:var(--dk-red-bg, #fef2f2);border:1px solid var(--dk-red-line, #fecaca);border-radius:4px;padding:0 4px;vertical-align:middle;white-space:nowrap" title="Added to the as-prepared batch — not part of the linked recipe">+ not in recipe</span>` : ''}</td>
|
|
2110
2181
|
<td style="padding:4px 8px;text-align:right;font-variant-numeric:tabular-nums;font-weight:600;color:var(--dk-text, #0f172a)">${r.planned != null ? `${cv(r.planned)}${purityTag(r)}${qsTag(r)}` : '<span style="color:var(--dk-dim, #cbd5e1)">—</span>'}</td>
|
|
2111
2182
|
${hasActuals ? `<td style="padding:4px 8px;text-align:right;font-variant-numeric:tabular-nums">${
|
|
2112
2183
|
r.actInUnit != null ? cv(r.actInUnit)
|
|
@@ -2419,11 +2490,11 @@ function computeProjectCost(projectId, displayCcy = getDisplayCurrency()) {
|
|
|
2419
2490
|
// ============================================================
|
|
2420
2491
|
function ingredientCostChangePct(ing) {
|
|
2421
2492
|
if (!ing?.cost?.history?.length) return null;
|
|
2422
|
-
const cur = costPerKgInOwnCurrency(ing.cost, ing.density, ing.densityUnit);
|
|
2493
|
+
const cur = costPerKgInOwnCurrency(ing.cost, ing.density, ing.densityUnit, ing.unitMass);
|
|
2423
2494
|
// Walk back to oldest entry that has a comparable per-kg value
|
|
2424
2495
|
for (let i = 0; i < ing.cost.history.length; i++) {
|
|
2425
2496
|
const old = ing.cost.history[i];
|
|
2426
|
-
const oldPerKg = costPerKgInOwnCurrency(old, ing.density, ing.densityUnit);
|
|
2497
|
+
const oldPerKg = costPerKgInOwnCurrency(old, ing.density, ing.densityUnit, ing.unitMass);
|
|
2427
2498
|
// Convert to same currency for fair comparison
|
|
2428
2499
|
const oldInCurCcy = convertCurrencySync(oldPerKg, old.currency || 'USD', ing.cost.currency || 'USD');
|
|
2429
2500
|
if (cur != null && oldInCurCcy && oldInCurCcy > 0) {
|
package/vendor/fragrance.js
CHANGED
|
@@ -278,7 +278,8 @@ function flFrCompute(f, opts) {
|
|
|
278
278
|
const st = { ..._frgSettings(f), ...(opts || {}) };
|
|
279
279
|
// What-if values get the same checks as stored ones.
|
|
280
280
|
st.category = FL_FR_CATEGORIES.includes(String(st.category || '').toUpperCase()) ? String(st.category).toUpperCase() : '';
|
|
281
|
-
|
|
281
|
+
// Category 12 has no product use: a use kept from another category is ignored, not shown (2 Dec: 11A, leave-on, then 12).
|
|
282
|
+
st.use = _frgIsUse(st.use) && _frgUseApplies(st.category) ? st.use : '';
|
|
282
283
|
st.dosage = _frgNum(st.dosage) > 0 && _frgNum(st.dosage) <= FL_FR_DOSAGE_MAX ? _frgNum(st.dosage) : 100;
|
|
283
284
|
const out = { has: false, category: st.category, use: st.use, dosage: st.dosage, rootOil: false, rows: [], others: [], noLimit: [], noDecl: [],
|
|
284
285
|
noSource: [], unresolved: 0, max: [], allergens: [], unlisted: [], toLabel: [], over: [], verdict: 'setup', why: [], useApplies: _frgUseApplies(st.category) };
|
|
@@ -799,7 +800,7 @@ function flFrOverviewHtml(f) {
|
|
|
799
800
|
}
|
|
800
801
|
return `<div id="fr-overview" style="display:contents">
|
|
801
802
|
${st.category ? `<div class="detail-field"><div class="label">IFRA category</div><div class="value">${_frgEsc(_frgCatText(st.category))}</div></div>` : ''}
|
|
802
|
-
${st.use ? `<div class="detail-field"><div class="label">Product use</div><div class="value">${FL_FR_USES[st.use]}</div></div>` : ''}
|
|
803
|
+
${st.use && _frgUseApplies(st.category) ? `<div class="detail-field"><div class="label">Product use</div><div class="value">${FL_FR_USES[st.use]}</div></div>` : ''}
|
|
803
804
|
${st.dosage !== 100 ? `<div class="detail-field"><div class="label">Fragrance dosage</div><div class="value">${_frgPct(st.dosage)}% in the product</div></div>` : ''}
|
|
804
805
|
${line}</div>`;
|
|
805
806
|
}
|
package/vendor/nesting.js
CHANGED
|
@@ -277,6 +277,7 @@ function _rowWtFractionsWithin(f, unresolved) {
|
|
|
277
277
|
if (lower.startsWith('vol')) return 'vol';
|
|
278
278
|
if (typeof MASS_TO_KG !== 'undefined' && u in MASS_TO_KG) return 'mass';
|
|
279
279
|
if (typeof VOL_TO_L !== 'undefined' && u in VOL_TO_L) return 'volabs';
|
|
280
|
+
if (typeof flPieceRowKg === 'function' && flPieceRowKg(c) != null) return 'piece'; // 1 wick, by its weight (2 Dec)
|
|
280
281
|
return 'unknown';
|
|
281
282
|
});
|
|
282
283
|
|
|
@@ -290,7 +291,7 @@ function _rowWtFractionsWithin(f, unresolved) {
|
|
|
290
291
|
// the block or arrived by import. wt% WITH vol% is NOT this case — density
|
|
291
292
|
// reconciles those, and they resolve through the branches below.
|
|
292
293
|
const _hasFrac = kinds.some(k => k === 'wt' || k === 'vol');
|
|
293
|
-
const _hasAbs = kinds.some(k => k === 'mass' || k === 'volabs');
|
|
294
|
+
const _hasAbs = kinds.some(k => k === 'mass' || k === 'volabs' || k === 'piece');
|
|
294
295
|
if (_hasFrac && _hasAbs) {
|
|
295
296
|
unresolved && unresolved.push({ reason: 'mixed-basis', formulationId: f ? f.id : null });
|
|
296
297
|
return comp.map(_ => 0);
|
|
@@ -312,6 +313,7 @@ function _rowWtFractionsWithin(f, unresolved) {
|
|
|
312
313
|
const amt = _usableAmount(c, unresolved);
|
|
313
314
|
if (!amt) return 0;
|
|
314
315
|
if (kinds[i] === 'mass') return amt * MASS_TO_KG[u];
|
|
316
|
+
if (kinds[i] === 'piece') return flPieceRowKg(c) || 0;
|
|
315
317
|
if (kinds[i] === 'volabs') {
|
|
316
318
|
if (c.ingredientId) {
|
|
317
319
|
const ing = db.ingredients.find(x => x.id === c.ingredientId);
|