removed trash files, changed how Formula Wozard catalog works
Update .gitignore, strings.json, and 21 more files...
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,6 +22,8 @@ resources/NibblePoker/js/*.min.js
|
||||
|
||||
# Compiled Stuff
|
||||
*.min.php
|
||||
tools/items/formula-wizard/*.js
|
||||
tools/items/formula-wizard/src/*.js
|
||||
|
||||
# Others
|
||||
*.pdn
|
||||
|
File diff suppressed because one or more lines are too long
29
compile.bat
29
compile.bat
@@ -57,7 +57,7 @@ popd
|
||||
:libs-end
|
||||
|
||||
|
||||
:: THE FW min files don't poitn to the proper JS file !!!!
|
||||
:: THE Formula-wizard minified files don't point to the proper minified JS file !!!!
|
||||
|
||||
|
||||
:formula-wizard
|
||||
@@ -65,6 +65,14 @@ echo.
|
||||
echo Handling the 'Formula Wizard'
|
||||
echo -----------------------------
|
||||
|
||||
:formula-wizard-clean
|
||||
echo Cleaning...
|
||||
pushd %CD%
|
||||
cd %~dp0\tools\items\formula-wizard\src\
|
||||
del *.js
|
||||
del *.map
|
||||
popd
|
||||
|
||||
:formula-wizard-compile
|
||||
echo Compiling TypeScript...
|
||||
pushd %CD%
|
||||
@@ -76,13 +84,14 @@ popd
|
||||
echo Fixing imports...
|
||||
pushd %CD%
|
||||
cd %~dp0\tools\items\formula-wizard\src\
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "decimal" "decimal.min.mjs"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "lang" "lang.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "formulas" "formulas.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "units" "units.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "ui_catalog" "ui_catalog.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "mvc_context" "mvc_context.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js" "sets" "sets.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "decimal" "decimal.min.mjs"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "lang" "lang.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "formulas" "formulas.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "units" "units.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "ui_catalog" "ui_catalog.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "mvc_context" "mvc_context.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "sets" "sets.js"
|
||||
call node "%~dp0fix-import-path.js" "formulas.js;lang.js;main.js;units.js;ui_catalog.js;mvc_context.js;sets.js;mvc_formula.js" "mvc_formula" "mvc_formula.js"
|
||||
popd
|
||||
|
||||
:formula-wizard-bundle
|
||||
@@ -100,6 +109,10 @@ call "%~dp0node_modules\.bin\terser" main.js -c -m --toplevel -o main.min.js
|
||||
call "%~dp0node_modules\.bin\terser" lang.js -c -m --toplevel -o lang.min.js
|
||||
call "%~dp0node_modules\.bin\terser" formulas.js -c -m --toplevel -o formulas.min.js
|
||||
call "%~dp0node_modules\.bin\terser" units.js -c -m --toplevel -o units.min.js
|
||||
call "%~dp0node_modules\.bin\terser" ui_catalog.js -c -m --toplevel -o ui_catalog.min.js
|
||||
call "%~dp0node_modules\.bin\terser" mvc_context.js -c -m --toplevel -o mvc_context.min.js
|
||||
call "%~dp0node_modules\.bin\terser" sets.js -c -m --toplevel -o sets.min.js
|
||||
call "%~dp0node_modules\.bin\terser" mvc_formula.js -c -m --toplevel -o mvc_formula.min.js
|
||||
call "%~dp0node_modules\.bin\terser" formula-wizard.js -c -m --toplevel -o formula-wizard.min.js
|
||||
popd
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"dom": "formula-wizard/page.min.php",
|
||||
"dom": "formula-wizard/page.php",
|
||||
"lang": "formula-wizard/lang.json",
|
||||
"code": [],
|
||||
"module": [
|
||||
|
@@ -1,855 +0,0 @@
|
||||
import { Decimal } from "../../../resources/DecimalJs/10.4.3/decimal.min.mjs";
|
||||
const version = [0, 0, 1];
|
||||
console.log("Initializing 'Formula Wizard v" + version.join(".") + "'...");
|
||||
const startTime = new Date().getMilliseconds();
|
||||
Decimal.set({ precision: 25, rounding: 8 });
|
||||
function isStringValidNumber(text) {
|
||||
return isNaN(parseFloat(text));
|
||||
}
|
||||
console.debug("Preparing langs...");
|
||||
const langKey = document.documentElement.lang.match("(en|fr)") ? document.documentElement.lang : "en";
|
||||
const langData = {
|
||||
en: {
|
||||
"unit.any.name": "Not Important",
|
||||
"unit.watt.name": "Watt",
|
||||
"unit.ampere.name": "Ampere",
|
||||
"unit.ohm.name": "Ohm",
|
||||
"unit.ohm.desc": "Electrical Resistance",
|
||||
"unit.volt.name": "Volt",
|
||||
"unit.farad.name": "Farad",
|
||||
"error.formulaValue.noParent": "Attempting to get a formula's value whose parent formula isn't set !",
|
||||
"error.formulaValue.noSource": "Attempting to get a formula's value whose value source is null !",
|
||||
"error.formulaContext.tooSmall": "The current calculation context is too small !",
|
||||
"ui.formulaCount": "formulas",
|
||||
"formula.ohm_law.name": "Ohm's Law",
|
||||
"dataset.resistor-e3.name": "E3 IEC Resistors",
|
||||
"dataset.resistor-e3.desc": "???",
|
||||
"dataset.resistor-e6.name": "E6 IEC Resistors",
|
||||
"dataset.resistor-e6.desc": "???",
|
||||
"dataset.resistor-e12.name": "E12 IEC Resistors",
|
||||
"dataset.resistor-e12.desc": "???",
|
||||
"dataset.resistor-e24.name": "E24 IEC Resistors",
|
||||
"dataset.resistor-e24.desc": "???",
|
||||
"dataset.resistor-e48.name": "E48 IEC Resistors",
|
||||
"dataset.resistor-e48.desc": "???",
|
||||
"dataset.capacitor-iec.name": "IEC E24 Capacitors",
|
||||
"dataset.capacitor-iec.desc": "???",
|
||||
"context.type.disabled.name": "Disabled",
|
||||
"context.type.constant.name": "Constant",
|
||||
"context.type.continuous.name": "Continuous",
|
||||
"context.type.valueRange.name": "Value Range",
|
||||
"context.type.dataSetRange.name": "Set-based Range",
|
||||
"context.type.disabled.desc": "???",
|
||||
"context.type.constant.desc": "???",
|
||||
"context.type.continuous.desc": "???",
|
||||
"context.type.valueRange.desc": "???",
|
||||
"context.type.dataSetRange.desc": "???",
|
||||
},
|
||||
fr: {
|
||||
"unit.ampere.name": "Ampère",
|
||||
"unit.ohm.desc": "Résistance électrique",
|
||||
"_error.formulaValue.noParent": "",
|
||||
"_error.formulaValue.noSource": "",
|
||||
"ui.formulaCount": "formules",
|
||||
"formula.ohm_law.name": "Loi d'Ohm",
|
||||
"context.type.disabled.name": "Désactivé",
|
||||
"context.type.constant.name": "Constante",
|
||||
"context.type.continuous.name": "Continue",
|
||||
"context.type.valueRange.name": "Valeurs distinctes",
|
||||
"context.type.dataSetRange.name": "Set de valeurs",
|
||||
}
|
||||
};
|
||||
function localize(stringKey) {
|
||||
let _langData = langKey in langData ? langData[langKey] : langData.en;
|
||||
return stringKey in _langData ? _langData[stringKey] : (stringKey in langData["en"] ? langData["en"][stringKey] : stringKey);
|
||||
}
|
||||
console.debug("Preparing scales...");
|
||||
const scales = {
|
||||
SI: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
IMPERIAL_DISTANCE: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
IMPERIAL_WEIGHT: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
TIME_SECONDS: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
NONE: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.name;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
};
|
||||
const scaleFactors = {
|
||||
SI_GIGA: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e9');
|
||||
this.prefix = "giga";
|
||||
this.suffix = "";
|
||||
this.symbol = "G";
|
||||
}
|
||||
},
|
||||
SI_MEGA: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e6');
|
||||
this.prefix = "mega";
|
||||
this.suffix = "";
|
||||
this.symbol = "M";
|
||||
}
|
||||
},
|
||||
SI_KILO: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e3');
|
||||
this.prefix = "kilo";
|
||||
this.suffix = "";
|
||||
this.symbol = "k";
|
||||
}
|
||||
},
|
||||
SI_BASE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
SI_CENTI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e-2');
|
||||
this.prefix = "centi";
|
||||
this.suffix = "";
|
||||
this.symbol = "c";
|
||||
}
|
||||
},
|
||||
SI_MILLI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e-3');
|
||||
this.prefix = "milli";
|
||||
this.suffix = "";
|
||||
this.symbol = "m";
|
||||
}
|
||||
},
|
||||
TIME_MILLI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('1e-3');
|
||||
this.prefix = "milli";
|
||||
this.suffix = "";
|
||||
this.symbol = "m";
|
||||
}
|
||||
},
|
||||
TIME_BASE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('1');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_MINUTE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('60');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_HOUR: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('3600');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_DAY: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('86400');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
};
|
||||
Object.keys(scaleFactors).forEach(scaleFactorKey => {
|
||||
const scaleFactor = scaleFactors[scaleFactorKey];
|
||||
scaleFactor.scale.scaleFactors.push(scaleFactor);
|
||||
});
|
||||
function scaleToBase(value, scaleFactor) {
|
||||
return value.times(scaleFactor.multiplier);
|
||||
}
|
||||
function scaleFromBase(value, scaleFactor) {
|
||||
return value.dividedBy(scaleFactor.multiplier);
|
||||
}
|
||||
function getScaleKeyFromValue(scaleFactor) {
|
||||
return Object.keys(scaleFactors).find(scaleFactorKey => (scaleFactors[scaleFactorKey]) === scaleFactor);
|
||||
}
|
||||
function populateScaleSelectForUnit(unit, eSelect, selectedScaleFactor) {
|
||||
unit.scale.scaleFactors.forEach(scaleFactor => {
|
||||
const eNewScaleOption = document.createElement("option");
|
||||
eNewScaleOption.setAttribute("value", getScaleKeyFromValue(scaleFactor));
|
||||
eNewScaleOption.innerText = scaleFactor.prefix + " - " + eNewScaleOption.getAttribute("value");
|
||||
eNewScaleOption.selected = (scaleFactor === selectedScaleFactor);
|
||||
eSelect.appendChild(eNewScaleOption);
|
||||
});
|
||||
}
|
||||
console.debug("Preparing units...");
|
||||
class Unit {
|
||||
constructor(unitKey, symbol, scale) {
|
||||
this.name = localize("unit." + unitKey + ".name");
|
||||
this.symbol = symbol;
|
||||
this.scale = scale;
|
||||
this.description = localize("unit." + unitKey + ".desc");
|
||||
}
|
||||
}
|
||||
const units = {
|
||||
ANY: new Unit("any", "", scales.NONE),
|
||||
WATT: new Unit("watt", "W", scales.SI),
|
||||
VOLT: new Unit("volt", "V", scales.SI),
|
||||
AMPERE: new Unit("ampere", "A", scales.SI),
|
||||
OHM: new Unit("ohm", "Ω", scales.SI),
|
||||
FARAD: new Unit("farad", "F", scales.SI),
|
||||
METER: new Unit("meter", "m", scales.SI),
|
||||
INCH: new Unit("inch", "in", scales.IMPERIAL_DISTANCE),
|
||||
POUND: new Unit("pound", "p", scales.IMPERIAL_WEIGHT),
|
||||
};
|
||||
console.debug("Preparing formulas...");
|
||||
class FormulaContextHandler {
|
||||
constructor(contextValueIndex) {
|
||||
this.contextValueIndex = contextValueIndex;
|
||||
}
|
||||
getContextValue(context) {
|
||||
if (context.length <= this.contextValueIndex) {
|
||||
alert(localize("error.formulaContext.tooSmall"));
|
||||
throw new Error(localize("error.formulaContext.tooSmall"));
|
||||
}
|
||||
return context[this.contextValueIndex];
|
||||
}
|
||||
}
|
||||
class FormulaValue {
|
||||
constructor(unit, scaleFactor) {
|
||||
this.unit = unit;
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.parentFormula = null;
|
||||
this.valueSource = null;
|
||||
}
|
||||
getFormulaValue(context) {
|
||||
if (this.parentFormula === null) {
|
||||
alert(localize("error.formulaValue.noParent"));
|
||||
throw new Error(localize("error.formulaValue.noParent"));
|
||||
}
|
||||
if (this.valueSource === null) {
|
||||
alert(localize("error.formulaValue.noSource"));
|
||||
throw new Error(localize("error.formulaValue.noSource"));
|
||||
}
|
||||
if (this.valueSource instanceof FormulaContextHandler) {
|
||||
return this.valueSource.getContextValue(context);
|
||||
}
|
||||
return scaleFromBase(scaleToBase(this.valueSource.getVariantValue(this.parentFormula, context), this.valueSource.getOutputValueDefinition().scaleFactor), this.scaleFactor);
|
||||
}
|
||||
}
|
||||
class Formula {
|
||||
constructor(values, variants, formulaKey, categories, wikiLink) {
|
||||
this.values = values;
|
||||
this.variants = variants;
|
||||
this.formulaKey = formulaKey;
|
||||
this.name = localize("formula." + formulaKey + ".name");
|
||||
this.description = localize("formula." + formulaKey + ".desc");
|
||||
this.categories = categories;
|
||||
this.wikiLink = wikiLink;
|
||||
this.values.forEach(value => {
|
||||
value.parentFormula = this;
|
||||
});
|
||||
}
|
||||
getClone() {
|
||||
const clonedFormulaValues = [];
|
||||
this.values.forEach(originalValue => {
|
||||
clonedFormulaValues.push(new FormulaValue(originalValue.unit, originalValue.scaleFactor));
|
||||
});
|
||||
return new Formula(clonedFormulaValues, this.variants, this.formulaKey, this.categories, this.wikiLink);
|
||||
}
|
||||
}
|
||||
const formulas = {
|
||||
OHM_LAW: new Formula([
|
||||
new FormulaValue(units.OHM, scaleFactors.SI_BASE),
|
||||
new FormulaValue(units.AMPERE, scaleFactors.SI_BASE),
|
||||
new FormulaValue(units.VOLT, scaleFactors.SI_BASE),
|
||||
], [
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "V=I*R";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[0].getFormulaValue(context).times(formula.values[1].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[0], this.parentFormula.values[1]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[2];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mo>=</mo><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi><mo>*</mo><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "I=V/R";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[2].getFormulaValue(context).dividedBy(formula.values[0].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[0], this.parentFormula.values[2]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[1];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi><mo>=</mo><mfrac><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi></mfrac></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "R=V/I";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[2].getFormulaValue(context).dividedBy(formula.values[1].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[2], this.parentFormula.values[1]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[0];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi><mo>=</mo><mfrac><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi></mfrac></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
], "ohm_law", ["electricity"], new URL("https://wikipedia.org/wiki/Ohm's_law")),
|
||||
};
|
||||
Object.keys(formulas).forEach(formulaKey => {
|
||||
formulas[formulaKey].variants.forEach(formulaVariant => {
|
||||
formulaVariant.parentFormula = formulas[formulaKey];
|
||||
});
|
||||
});
|
||||
class ContextType {
|
||||
constructor(name, description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
const contextTypes = {
|
||||
DISABLED: new ContextType(localize("context.type.disabled.name"), localize("context.type.disabled.desc")),
|
||||
CONSTANT: new ContextType(localize("context.type.constant.name"), localize("context.type.constant.desc")),
|
||||
CONTINUOUS: new ContextType(localize("context.type.continuous.name"), localize("context.type.continuous.desc")),
|
||||
VALUE_RANGE: new ContextType(localize("context.type.valueRange.name"), localize("context.type.valueRange.desc")),
|
||||
DATASET_RANG: new ContextType(localize("context.type.dataSetRange.name"), localize("context.type.dataSetRange.desc")),
|
||||
};
|
||||
console.debug("Preparing sets...");
|
||||
class DataSet {
|
||||
constructor(name, description, values, unit, scaleFactor) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.values = values;
|
||||
this.unit = unit;
|
||||
this.scaleFactor = scaleFactor;
|
||||
if (unit.scale != scaleFactor.scale) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
}
|
||||
getDataSet() {
|
||||
return this.values;
|
||||
}
|
||||
}
|
||||
const e3Range = [1, 2.2, 4.7];
|
||||
const e6Range = [1, 1.5, 2.2, 3.3, 4.7, 6.8];
|
||||
const e12Range = [1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2];
|
||||
const e24Range = [
|
||||
1, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2, 2.2, 2.4, 2.7, 3, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1
|
||||
];
|
||||
const e48Range = [
|
||||
1, 1.05, 1.1, 1.15, 1.21, 1.27, 1.33, 1.4, 1.47, 1.54, 1.62, 1.69, 1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49,
|
||||
2.61, 2.74, 2.87, 3.01, 3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 5.62, 5.9, 6.19,
|
||||
6.49, 6.81, 7.15, 7.5, 7.87, 8.25, 8.66, 9.09, 9.53
|
||||
];
|
||||
const resistorsScales = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000];
|
||||
const capacitorScales = [10e-12, 10e-11, 10e-10, 10e-9, 10e-8, 10e-7, 10e-6, 10e-5, 10e-4, 10e-3, 10e-2];
|
||||
const sets = {
|
||||
RESISTOR_E3: new DataSet(localize("dataset.resistor-e3.name"), localize("dataset.resistor-e3.desc"), resistorsScales.flatMap((e3Scale) => e3Range.map((e3Multiplier) => new Decimal(e3Scale).times(e3Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E6: new DataSet(localize("dataset.resistor-e6.name"), localize("dataset.resistor-e6.desc"), resistorsScales.flatMap((e6Scale) => e6Range.map((e6Multiplier) => new Decimal(e6Scale).times(e6Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E12: new DataSet(localize("dataset.resistor-e12.name"), localize("dataset.resistor-e12.desc"), resistorsScales.flatMap((e12Scale) => e12Range.map((e12Multiplier) => new Decimal(e12Scale).times(e12Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E24: new DataSet(localize("dataset.resistor-e24.name"), localize("dataset.resistor-e24.desc"), resistorsScales.flatMap((e24Scale) => e24Range.map((e24Multiplier) => new Decimal(e24Scale).times(e24Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E48: new DataSet(localize("dataset.resistor-e48.name"), localize("dataset.resistor-e48.desc"), resistorsScales.flatMap((e48Scale) => e48Range.map((e48Multiplier) => new Decimal(e48Scale).times(e48Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
CAPACITOR_IEC: new DataSet(localize("dataset.capacitor-iec.name"), localize("dataset.capacitor-iec.desc"), capacitorScales.flatMap((cScale) => e24Range.map((eMultiplier) => new Decimal(cScale).times(eMultiplier))), units.FARAD, scaleFactors.SI_BASE),
|
||||
};
|
||||
console.debug("Preparing UI...");
|
||||
const idWorkbenchFormulaPrefix = "fw-workbench-formula-";
|
||||
const idWorkbenchFormulaSpawnPoint = idWorkbenchFormulaPrefix + "spawn";
|
||||
const idTemplateFormula = "template-workbench-formula";
|
||||
const idFormulaName = idWorkbenchFormulaPrefix + "name";
|
||||
const idFormulaInputs = idWorkbenchFormulaPrefix + "inputs";
|
||||
const idFormulaOutputs = idWorkbenchFormulaPrefix + "outputs";
|
||||
const classTemplateFormulaValue = "formula-value-input-form";
|
||||
const idTemplateFormulaValue = idTemplateFormula + "-value";
|
||||
const idFormulaValuePrefix = idWorkbenchFormulaPrefix + "value-";
|
||||
const idFormulaValueId = idFormulaValuePrefix + "id";
|
||||
const idFormulaValueName = idFormulaValuePrefix + "name";
|
||||
const idFormulaValueLink = idFormulaValuePrefix + "link";
|
||||
const idFormulaValueTestValue = idFormulaValuePrefix + "test-value";
|
||||
const idFormulaValueTestScale = idFormulaValuePrefix + "test-scale";
|
||||
const idFormulaValueTestValueSet = idFormulaValuePrefix + "test-value-set";
|
||||
let eTemplateWorkbenchFormula = document.getElementById(idTemplateFormula);
|
||||
let eTemplateWorkbenchFormulaValue = document.getElementById(idTemplateFormulaValue);
|
||||
if (eTemplateWorkbenchFormula === null || eTemplateWorkbenchFormulaValue === null) {
|
||||
alert("error.ui.workbench.noTemplate");
|
||||
throw Error("error.ui.workbench.noTemplate");
|
||||
}
|
||||
eTemplateWorkbenchFormula = eTemplateWorkbenchFormula.cloneNode(true).content;
|
||||
eTemplateWorkbenchFormulaValue = eTemplateWorkbenchFormulaValue.cloneNode(true).content;
|
||||
const eWorkbenchFormulaSpawnPoint = document.querySelector(`a#${idWorkbenchFormulaSpawnPoint}`);
|
||||
if (eWorkbenchFormulaSpawnPoint === null) {
|
||||
alert("error.ui.workbench.noAnchor");
|
||||
throw Error("error.ui.workbench.noAnchor");
|
||||
}
|
||||
let uiWorkbenchFormulas = [];
|
||||
var WorkbenchFormulaValueTypes;
|
||||
(function (WorkbenchFormulaValueTypes) {
|
||||
WorkbenchFormulaValueTypes[WorkbenchFormulaValueTypes["INPUT"] = 0] = "INPUT";
|
||||
WorkbenchFormulaValueTypes[WorkbenchFormulaValueTypes["OUTPUT"] = 1] = "OUTPUT";
|
||||
})(WorkbenchFormulaValueTypes || (WorkbenchFormulaValueTypes = {}));
|
||||
class WorkbenchFormulaValueUiElement {
|
||||
constructor(rootElement, formulaValue, parentFormulaElement, valueType) {
|
||||
this.rootElement = rootElement;
|
||||
this.idSuffix = Date.now().toString() + Math.floor(Math.random() * 99);
|
||||
this.valueType = valueType;
|
||||
this.formulaValue = formulaValue;
|
||||
this.parentFormulaElement = parentFormulaElement;
|
||||
this.eFormulaValueId = rootElement.querySelector(`input#${idFormulaValueId}`);
|
||||
this.eFormulaValueName = rootElement.querySelector(`p#${idFormulaValueName}`);
|
||||
this.eFormulaValueLink = rootElement.querySelector(`select#${idFormulaValueLink}`);
|
||||
this.eFormulaValueTestValue = rootElement.querySelector(`input#${idFormulaValueTestValue}`);
|
||||
this.eFormulaValueTestScale = rootElement.querySelector(`select#${idFormulaValueTestScale}`);
|
||||
this.eFormulaValueTestValueSet = rootElement.querySelector(`select#${idFormulaValueTestValueSet}`);
|
||||
if ([this.eFormulaValueId, this.eFormulaValueName, this.eFormulaValueLink, this.eFormulaValueTestValue,
|
||||
this.eFormulaValueTestScale, this.eFormulaValueTestValueSet].some((item) => item === null)) {
|
||||
alert("error.ui.formula.value.missingElement");
|
||||
throw Error("error.ui.formula.value.missingElement");
|
||||
}
|
||||
this.toggleField(this.eFormulaValueTestValueSet, true);
|
||||
this.rootElement.querySelectorAll(`input, select, p, div`).forEach(eFormInput => {
|
||||
if (eFormInput.hasAttribute("id")) {
|
||||
eFormInput.setAttribute("id", eFormInput.getAttribute("id") + this.idSuffix);
|
||||
}
|
||||
});
|
||||
this.rootElement.querySelectorAll(`label`).forEach(eFormLabel => {
|
||||
if (eFormLabel.hasAttribute("for")) {
|
||||
eFormLabel.setAttribute("for", eFormLabel.getAttribute("for") + this.idSuffix);
|
||||
}
|
||||
});
|
||||
this.eFormulaValueName.innerText = `${this.formulaValue.unit.name} (${this.formulaValue.unit.symbol})`;
|
||||
this.eFormulaValueId.value = this.idSuffix;
|
||||
populateScaleSelectForUnit(this.formulaValue.unit, this.eFormulaValueTestScale, this.formulaValue.scaleFactor);
|
||||
if (this.valueType === WorkbenchFormulaValueTypes.INPUT) {
|
||||
this.setupInput();
|
||||
}
|
||||
else {
|
||||
this.setupOutput();
|
||||
}
|
||||
}
|
||||
onTestFieldChange(event) {
|
||||
this.parentFormulaElement.calculateTestValues();
|
||||
}
|
||||
getTestValue() {
|
||||
return new Decimal(isStringValidNumber(this.eFormulaValueTestValue.value) ? this.eFormulaValueTestValue.value : 0);
|
||||
}
|
||||
setTestValue(newValue) {
|
||||
this.eFormulaValueTestValue.value = newValue.toString();
|
||||
}
|
||||
toggleTestMode(hidden) {
|
||||
this.eFormulaValueTestScale.parentNode.parentNode.hidden = hidden;
|
||||
this.eFormulaValueTestScale.parentNode.parentNode.hidden = hidden;
|
||||
}
|
||||
toggleField(eFormField, hidden) {
|
||||
eFormField.parentNode.parentNode.hidden = hidden;
|
||||
}
|
||||
setupInput() {
|
||||
this.toggleField(this.eFormulaValueId, true);
|
||||
this.eFormulaValueTestValue.value = "0";
|
||||
this.eFormulaValueTestValue.onchange = this.onTestFieldChange.bind(this);
|
||||
this.eFormulaValueTestScale.onchange = this.onTestFieldChange.bind(this);
|
||||
}
|
||||
setupOutput() {
|
||||
this.toggleField(this.eFormulaValueLink, true);
|
||||
this.eFormulaValueTestValue.readOnly = true;
|
||||
this.eFormulaValueTestScale.onchange = this.onTestFieldChange.bind(this);
|
||||
}
|
||||
static getNew(formulaValue, parentFormulaElement, valueType) {
|
||||
const eNewWorkbenchFormulaValue = eTemplateWorkbenchFormulaValue.cloneNode(true).firstElementChild;
|
||||
if (eNewWorkbenchFormulaValue === null) {
|
||||
alert("error.ui.workbench.formula.value.cannotGetElement");
|
||||
throw Error("error.ui.workbench.formula.value.cannotGetElement");
|
||||
}
|
||||
return new WorkbenchFormulaValueUiElement(eNewWorkbenchFormulaValue, formulaValue, parentFormulaElement, valueType);
|
||||
}
|
||||
}
|
||||
class WorkbenchFormulaUiElement {
|
||||
constructor(rootElement, formulaVariant) {
|
||||
this.rootElement = rootElement;
|
||||
this.idSuffix = Date.now().toString();
|
||||
this.formulaVariant = formulaVariant;
|
||||
this.eFormulaName = rootElement.querySelector(`p#${idFormulaName}`);
|
||||
this.eFormulaInputs = rootElement.querySelector(`div#${idFormulaInputs}`);
|
||||
this.eFormulaOutputs = rootElement.querySelector(`div#${idFormulaOutputs}`);
|
||||
if ([this.eFormulaName, this.eFormulaInputs, this.eFormulaOutputs].some((item) => item === null)) {
|
||||
alert("error.ui.formula.missingElement");
|
||||
throw Error("error.ui.formula.missingElement");
|
||||
}
|
||||
this.eFormulaName.innerText = this.formulaVariant.parentFormula.name;
|
||||
this.inputValueElements = [];
|
||||
this.formulaVariant.getInputValuesDefinition().forEach(variantValue => {
|
||||
const newInputValueElement = WorkbenchFormulaValueUiElement.getNew(variantValue, this, WorkbenchFormulaValueTypes.INPUT);
|
||||
this.inputValueElements.push(newInputValueElement);
|
||||
this.eFormulaInputs.appendChild(newInputValueElement.rootElement);
|
||||
});
|
||||
this.outputValueElements = [];
|
||||
[this.formulaVariant.getOutputValueDefinition()].forEach(variantValue => {
|
||||
const newOutputValueElement = WorkbenchFormulaValueUiElement.getNew(variantValue, this, WorkbenchFormulaValueTypes.OUTPUT);
|
||||
this.outputValueElements.push(newOutputValueElement);
|
||||
this.eFormulaOutputs.appendChild(newOutputValueElement.rootElement);
|
||||
});
|
||||
}
|
||||
toggleTestMode(hidden) {
|
||||
}
|
||||
calculateTestValues() {
|
||||
console.log("Handling change...");
|
||||
}
|
||||
static createNew(formulaVariant) {
|
||||
const eNewWorkbenchFormula = eTemplateWorkbenchFormula.cloneNode(true).firstElementChild;
|
||||
if (eNewWorkbenchFormula === null) {
|
||||
alert("error.ui.workbench.formula.cannotGetElement");
|
||||
throw Error("error.ui.workbench.formula.cannotGetElement");
|
||||
}
|
||||
const newWorkbenchUiElement = new WorkbenchFormulaUiElement(eNewWorkbenchFormula, formulaVariant);
|
||||
uiWorkbenchFormulas.push(newWorkbenchUiElement);
|
||||
eWorkbenchFormulaSpawnPoint.parentNode.insertBefore(newWorkbenchUiElement.rootElement, eWorkbenchFormulaSpawnPoint);
|
||||
return newWorkbenchUiElement;
|
||||
}
|
||||
}
|
||||
const idCatalogPrefix = "fw-catalog-";
|
||||
const idCatalogCategoryPrefix = idCatalogPrefix + "category-";
|
||||
const idCatalogCategoryCount = idCatalogPrefix + "formula-count";
|
||||
const eCategoryContainers = {};
|
||||
document.querySelectorAll('[id]').forEach((element) => {
|
||||
if (element.id.startsWith(idCatalogCategoryPrefix)) {
|
||||
eCategoryContainers[element.id.replace(idCatalogCategoryPrefix, "")] = element;
|
||||
}
|
||||
});
|
||||
const eFormulaCount = document.getElementById(idCatalogCategoryCount);
|
||||
if (eFormulaCount !== null) {
|
||||
eFormulaCount.innerText = Object.keys(formulas).length.toString();
|
||||
}
|
||||
let eTemplateFormula = document.getElementById("template-formula-available");
|
||||
let eTemplateFormulaVariant = document.getElementById("template-formula-available-variant");
|
||||
if (eTemplateFormula === null || eTemplateFormulaVariant === null) {
|
||||
alert("error.ui.catalog.noTemplate");
|
||||
throw Error("error.ui.catalog.noTemplate");
|
||||
}
|
||||
Object.keys(formulas).forEach(formulaKey => {
|
||||
const hasValidCategory = formulas[formulaKey].categories.every(function (categoryId) {
|
||||
return Object.keys(eCategoryContainers).indexOf(categoryId) !== -1;
|
||||
});
|
||||
if (hasValidCategory) {
|
||||
let eNewFormula = eTemplateFormula.content.cloneNode(true);
|
||||
let eNewFormulaTitle = eNewFormula.querySelector("p");
|
||||
if (eNewFormulaTitle !== null) {
|
||||
eNewFormulaTitle.innerText = formulas[formulaKey].name;
|
||||
}
|
||||
let eNewFormulaVariants = eNewFormula.querySelector("div.fw-variants");
|
||||
if (eNewFormulaVariants === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
eNewFormulaVariants.innerHTML = "";
|
||||
formulas[formulaKey].variants.forEach(variant => {
|
||||
let eNewFormulaVariant = eTemplateFormulaVariant.content.cloneNode(true);
|
||||
let eNewFormulaVariantButton = eNewFormulaVariant.querySelector("button");
|
||||
if (eNewFormulaVariantButton === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
eNewFormulaVariantButton.innerHTML = variant.getMathMl(formulas[formulaKey]);
|
||||
eNewFormulaVariantButton.title = variant.description;
|
||||
eNewFormulaVariantButton.onclick = function () {
|
||||
WorkbenchFormulaUiElement.createNew(variant);
|
||||
};
|
||||
eNewFormulaVariants.appendChild(eNewFormulaVariant);
|
||||
});
|
||||
formulas[formulaKey].categories.forEach(categoryKey => {
|
||||
if (Object.keys(eCategoryContainers).includes(categoryKey)) {
|
||||
eCategoryContainers[categoryKey].appendChild(eNewFormula);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const idContextComponentPrefix = "fw-context-component-";
|
||||
const idContextComponentId = idContextComponentPrefix + "id";
|
||||
const idContextComponentDelete = idContextComponentPrefix + "delete";
|
||||
const idContextComponentTypes = idContextComponentPrefix + "type";
|
||||
const idContextComponentManualValue = idContextComponentPrefix + "manual-value";
|
||||
const idContextComponentManualValues = idContextComponentManualValue + "s";
|
||||
const idContextComponentRangeFrom = idContextComponentPrefix + "range-from";
|
||||
const idContextComponentRangeTo = idContextComponentPrefix + "range-to";
|
||||
const idContextComponentRangeStep = idContextComponentPrefix + "range-step";
|
||||
const idContextComponentSets = idContextComponentPrefix + "set";
|
||||
const idContextComponentUnit = idContextComponentPrefix + "unit";
|
||||
const idContextComponentScale = idContextComponentPrefix + "scale";
|
||||
let uiContextComponents = [];
|
||||
let eTemplateContextComponent = document.getElementById("template-context-component");
|
||||
if (eTemplateContextComponent === null) {
|
||||
alert("error.ui.context.noTemplate");
|
||||
throw Error("error.ui.context.noTemplate");
|
||||
}
|
||||
eTemplateContextComponent = eTemplateContextComponent.cloneNode(true).content;
|
||||
const eContextTypes = eTemplateContextComponent.getElementById(idContextComponentTypes);
|
||||
const eContextSets = eTemplateContextComponent.getElementById(idContextComponentSets);
|
||||
const eContextUnits = eTemplateContextComponent.getElementById(idContextComponentUnit);
|
||||
const eContextScales = eTemplateContextComponent.getElementById(idContextComponentScale);
|
||||
if ([eContextTypes, eContextSets, eContextUnits, eContextScales].some((item) => item === null)) {
|
||||
alert("error.ui.context.noSets");
|
||||
throw Error("error.ui.context.noSets");
|
||||
}
|
||||
Object.keys(contextTypes).forEach(value => {
|
||||
const eNewContextTypesOption = document.createElement("option");
|
||||
eNewContextTypesOption.setAttribute("value", value);
|
||||
eNewContextTypesOption.innerText = contextTypes[value].name;
|
||||
eContextTypes.appendChild(eNewContextTypesOption);
|
||||
});
|
||||
Object.keys(sets).forEach(value => {
|
||||
const eNewContextSetsOption = document.createElement("option");
|
||||
eNewContextSetsOption.setAttribute("value", value);
|
||||
eNewContextSetsOption.innerText = sets[value].name;
|
||||
eContextSets.appendChild(eNewContextSetsOption);
|
||||
});
|
||||
Object.keys(units).forEach(unitKey => {
|
||||
const eNewContextUnitsOption = document.createElement("option");
|
||||
eNewContextUnitsOption.setAttribute("value", unitKey);
|
||||
eNewContextUnitsOption.innerText = units[unitKey].name;
|
||||
eContextUnits.appendChild(eNewContextUnitsOption);
|
||||
});
|
||||
Object.keys(scaleFactors).forEach(scaleKey => {
|
||||
const eNewContextScalesOption = document.createElement("option");
|
||||
eNewContextScalesOption.setAttribute("value", scaleKey);
|
||||
eNewContextScalesOption.innerText = scaleFactors[scaleKey].prefix;
|
||||
eContextScales.appendChild(eNewContextScalesOption);
|
||||
});
|
||||
let eContextStatusMessage = document.getElementById("fw-text-context-middle");
|
||||
if (eContextStatusMessage === null) {
|
||||
alert("error.ui.context.noStatus");
|
||||
throw Error("error.ui.context.noStatus");
|
||||
}
|
||||
let eContextAddButton = document.querySelector("button#fw-button-add-context");
|
||||
if (eContextAddButton === null) {
|
||||
alert("error.ui.context.missingButton");
|
||||
throw Error("error.ui.context.missingButton");
|
||||
}
|
||||
class ContextComponentUiElement {
|
||||
constructor(rootElement) {
|
||||
this.rootElement = rootElement;
|
||||
this.idSuffix = Date.now().toString();
|
||||
this.eIdLabel = rootElement.querySelector(`label[for="${idContextComponentId}"]`);
|
||||
this.eIdInput = rootElement.querySelector(`input#${idContextComponentId}`);
|
||||
this.eDeleteButton = rootElement.querySelector(`button#${idContextComponentDelete}`);
|
||||
this.eTypeLabel = rootElement.querySelector(`label[for="${idContextComponentTypes}"]`);
|
||||
this.eTypeSelect = rootElement.querySelector(`select#${idContextComponentTypes}`);
|
||||
this.eManualValueLabel = rootElement.querySelector(`label[for="${idContextComponentManualValue}"]`);
|
||||
this.eManualValueInput = rootElement.querySelector(`input#${idContextComponentManualValue}`);
|
||||
this.eManualValuesLabel = rootElement.querySelector(`label[for="${idContextComponentManualValues}"]`);
|
||||
this.eManualValuesInput = rootElement.querySelector(`input#${idContextComponentManualValues}`);
|
||||
this.eRangeFromLabel = rootElement.querySelector(`label[for="${idContextComponentRangeFrom}"]`);
|
||||
this.eRangeFromInput = rootElement.querySelector(`input#${idContextComponentRangeFrom}`);
|
||||
this.eRangeToLabel = rootElement.querySelector(`label[for="${idContextComponentRangeTo}"]`);
|
||||
this.eRangeToInput = rootElement.querySelector(`input#${idContextComponentRangeTo}`);
|
||||
this.eRangeStepLabel = rootElement.querySelector(`label[for="${idContextComponentRangeStep}"]`);
|
||||
this.eRangeStepInput = rootElement.querySelector(`input#${idContextComponentRangeStep}`);
|
||||
this.eDataSetLabel = rootElement.querySelector(`label[for="${idContextComponentSets}"]`);
|
||||
this.eDataSetSelect = rootElement.querySelector(`select#${idContextComponentSets}`);
|
||||
this.eUnitLabel = rootElement.querySelector(`label[for="${idContextComponentUnit}"]`);
|
||||
this.eUnitSelect = rootElement.querySelector(`select#${idContextComponentUnit}`);
|
||||
this.eScaleLabel = rootElement.querySelector(`label[for="${idContextComponentScale}"]`);
|
||||
this.eScaleSelect = rootElement.querySelector(`select#${idContextComponentScale}`);
|
||||
this.allElements = [
|
||||
this.eIdLabel, this.eIdInput, this.eDeleteButton, this.eTypeLabel, this.eTypeSelect,
|
||||
this.eManualValuesLabel, this.eManualValuesInput, this.eRangeFromLabel, this.eRangeFromInput,
|
||||
this.eRangeToLabel, this.eRangeToInput, this.eRangeStepLabel, this.eRangeStepInput, this.eDataSetLabel,
|
||||
this.eDataSetSelect, this.eUnitLabel, this.eUnitSelect, this.eScaleLabel, this.eScaleSelect,
|
||||
this.eManualValueLabel, this.eManualValueInput
|
||||
];
|
||||
if (this.allElements.some((item) => item === null)) {
|
||||
alert("error.ui.context.component.missingElement");
|
||||
throw Error("error.ui.context.component.missingElement");
|
||||
}
|
||||
rootElement.querySelectorAll(`input, select`).forEach(eFormInput => {
|
||||
if (eFormInput.hasAttribute("id")) {
|
||||
eFormInput.setAttribute("id", eFormInput.getAttribute("id") + this.idSuffix);
|
||||
}
|
||||
});
|
||||
rootElement.querySelectorAll(`label`).forEach(eFormLabel => {
|
||||
if (eFormLabel.hasAttribute("for")) {
|
||||
eFormLabel.setAttribute("for", eFormLabel.getAttribute("for") + this.idSuffix);
|
||||
}
|
||||
});
|
||||
this.eDeleteButton.removeAttribute('id');
|
||||
this.eIdInput.value = this.idSuffix;
|
||||
this.eTypeSelect.onchange = this.onTypeChange.bind(this);
|
||||
this.eDeleteButton.onclick = this.onDeleteClick.bind(this);
|
||||
this.onTypeChange(null);
|
||||
}
|
||||
onTypeChange(event) {
|
||||
this.allElements.forEach(eFormElement => {
|
||||
this.toggleField(eFormElement, true);
|
||||
});
|
||||
this.toggleField(this.eIdLabel, false);
|
||||
this.toggleField(this.eTypeLabel, false);
|
||||
if (this.getContextType() !== contextTypes.DISABLED) {
|
||||
this.toggleField(this.eUnitLabel, false);
|
||||
this.toggleField(this.eScaleLabel, false);
|
||||
}
|
||||
switch (this.getContextType()) {
|
||||
case contextTypes.CONSTANT:
|
||||
this.toggleField(this.eManualValueInput, false);
|
||||
break;
|
||||
case contextTypes.CONTINUOUS:
|
||||
this.toggleField(this.eRangeFromLabel, false);
|
||||
this.toggleField(this.eRangeToLabel, false);
|
||||
this.toggleField(this.eRangeStepLabel, false);
|
||||
break;
|
||||
case contextTypes.VALUE_RANGE:
|
||||
this.toggleField(this.eManualValuesInput, false);
|
||||
break;
|
||||
case contextTypes.DATASET_RANG:
|
||||
this.toggleField(this.eDataSetLabel, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
onDeleteClick(event) {
|
||||
this.rootElement.remove();
|
||||
uiContextComponents = uiContextComponents.filter(item => item !== this);
|
||||
if (uiContextComponents.length < 1) {
|
||||
eContextStatusMessage.hidden = false;
|
||||
}
|
||||
}
|
||||
toggleField(eFormField, hidden) {
|
||||
eFormField.parentNode.parentNode.hidden = hidden;
|
||||
}
|
||||
getContextType() {
|
||||
return contextTypes[this.eTypeSelect.value];
|
||||
}
|
||||
}
|
||||
eContextAddButton.onclick = function () {
|
||||
const eNewContextComponent = eTemplateContextComponent.cloneNode(true).firstElementChild;
|
||||
if (eNewContextComponent === null) {
|
||||
alert("error.ui.context.component.cannotGetElement");
|
||||
throw Error("error.ui.context.component.cannotGetElement");
|
||||
}
|
||||
const newContextComponent = new ContextComponentUiElement(eNewContextComponent);
|
||||
uiContextComponents.push(newContextComponent);
|
||||
eContextStatusMessage.parentNode.insertBefore(newContextComponent.rootElement, eContextStatusMessage);
|
||||
eContextStatusMessage.hidden = true;
|
||||
};
|
||||
function getRee() {
|
||||
}
|
||||
class NumberProlapsingMachine {
|
||||
static createNewFromUi(formulaVariant) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (new URLSearchParams(window.location.search).has("debug")) {
|
||||
console.debug("Preparing debugging tools...");
|
||||
let eDebugContainer = document.querySelector("div#fw-debug-root");
|
||||
let eDebugLinkAndIdsButton = document.querySelector("button#fw-button-debug-linkAndIds");
|
||||
if (eDebugContainer === null || eDebugLinkAndIdsButton === null) {
|
||||
alert("error.ui.context.missingButton");
|
||||
throw Error("error.ui.context.missingButton");
|
||||
}
|
||||
eDebugContainer.hidden = false;
|
||||
eDebugLinkAndIdsButton.onclick = function () {
|
||||
alert(JSON.stringify({ 'a': 1, 'b': 3 }, null, 4));
|
||||
};
|
||||
}
|
||||
const endTime = new Date().getMilliseconds();
|
||||
console.log("Done, took " + (endTime - startTime) + "ms !");
|
||||
//# sourceMappingURL=code.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,150 +0,0 @@
|
||||
import { localize } from "./lang.js";
|
||||
import { scaleFactors, units, scaleToBase, scaleFromBase } from "./units.js";
|
||||
class FormulaContextHandler {
|
||||
constructor(contextValueIndex) {
|
||||
this.contextValueIndex = contextValueIndex;
|
||||
}
|
||||
getContextValue(context) {
|
||||
if (context.length <= this.contextValueIndex) {
|
||||
alert(localize("error.formulaContext.tooSmall"));
|
||||
throw new Error(localize("error.formulaContext.tooSmall"));
|
||||
}
|
||||
return context[this.contextValueIndex];
|
||||
}
|
||||
}
|
||||
export class FormulaValue {
|
||||
constructor(unit, scaleFactor) {
|
||||
this.unit = unit;
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.parentFormula = null;
|
||||
this.valueSource = null;
|
||||
}
|
||||
getFormulaValue(context) {
|
||||
if (this.parentFormula === null) {
|
||||
alert(localize("error.formulaValue.noParent"));
|
||||
throw new Error(localize("error.formulaValue.noParent"));
|
||||
}
|
||||
if (this.valueSource === null) {
|
||||
alert(localize("error.formulaValue.noSource"));
|
||||
throw new Error(localize("error.formulaValue.noSource"));
|
||||
}
|
||||
if (this.valueSource instanceof FormulaContextHandler) {
|
||||
return this.valueSource.getContextValue(context);
|
||||
}
|
||||
return scaleFromBase(scaleToBase(this.valueSource.getVariantValue(this.parentFormula, context), this.valueSource.getOutputValueDefinition().scaleFactor), this.scaleFactor);
|
||||
}
|
||||
}
|
||||
export class Formula {
|
||||
constructor(values, variants, formulaKey, categories, wikiLink) {
|
||||
this.values = values;
|
||||
this.variants = variants;
|
||||
this.formulaKey = formulaKey;
|
||||
this.name = localize("formula." + formulaKey + ".name");
|
||||
this.description = localize("formula." + formulaKey + ".desc");
|
||||
this.categories = categories;
|
||||
this.wikiLink = wikiLink;
|
||||
this.values.forEach(value => {
|
||||
value.parentFormula = this;
|
||||
});
|
||||
}
|
||||
getClone() {
|
||||
const clonedFormulaValues = [];
|
||||
this.values.forEach(originalValue => {
|
||||
clonedFormulaValues.push(new FormulaValue(originalValue.unit, originalValue.scaleFactor));
|
||||
});
|
||||
return new Formula(clonedFormulaValues, this.variants, this.formulaKey, this.categories, this.wikiLink);
|
||||
}
|
||||
}
|
||||
export const formulas = {
|
||||
OHM_LAW: new Formula([
|
||||
new FormulaValue(units.OHM, scaleFactors.SI_BASE),
|
||||
new FormulaValue(units.AMPERE, scaleFactors.SI_BASE),
|
||||
new FormulaValue(units.VOLT, scaleFactors.SI_BASE),
|
||||
], [
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "V=I*R";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[0].getFormulaValue(context).times(formula.values[1].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[0], this.parentFormula.values[1]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[2];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mo>=</mo><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi><mo>*</mo><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "I=V/R";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[2].getFormulaValue(context).dividedBy(formula.values[0].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[0], this.parentFormula.values[2]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[1];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi><mo>=</mo><mfrac><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi></mfrac></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
new class {
|
||||
constructor() {
|
||||
this.description = "R=V/I";
|
||||
this.getVariantValue = (formula, context) => {
|
||||
return formula.values[2].getFormulaValue(context).dividedBy(formula.values[1].getFormulaValue(context));
|
||||
};
|
||||
this.getInputValuesDefinition = () => {
|
||||
return [this.parentFormula.values[2], this.parentFormula.values[1]];
|
||||
};
|
||||
this.getOutputValueDefinition = () => {
|
||||
return this.parentFormula.values[0];
|
||||
};
|
||||
this.getMathMl = (formula) => {
|
||||
return "<math><mi>" +
|
||||
formula.values[0].unit.symbol +
|
||||
"</mi><mo>=</mo><mfrac><mi>" +
|
||||
formula.values[2].unit.symbol +
|
||||
"</mi><mi>" +
|
||||
formula.values[1].unit.symbol +
|
||||
"</mi></mfrac></math>";
|
||||
};
|
||||
this.parentFormula = null;
|
||||
}
|
||||
},
|
||||
], "ohm_law", ["electricity"], new URL("https://wikipedia.org/wiki/Ohm's_law")),
|
||||
};
|
||||
let areFormulasInitialized = false;
|
||||
export function initFormulas() {
|
||||
if (!areFormulasInitialized) {
|
||||
console.debug("Initializing formulas...");
|
||||
Object.keys(formulas).forEach(formulaKey => {
|
||||
formulas[formulaKey].variants.forEach(formulaVariant => {
|
||||
formulaVariant.parentFormula = formulas[formulaKey];
|
||||
});
|
||||
});
|
||||
areFormulasInitialized = true;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=formulas.js.map
|
@@ -1 +0,0 @@
|
||||
import{localize as t}from"./lang.js";import{scaleFactors as e,units as a,scaleToBase as l,scaleFromBase as u}from"./units.js";class r{constructor(t){this.contextValueIndex=t}getContextValue(e){if(e.length<=this.contextValueIndex)throw alert(t("error.formulaContext.tooSmall")),new Error(t("error.formulaContext.tooSmall"));return e[this.contextValueIndex]}}export class FormulaValue{constructor(t,e){this.unit=t,this.scaleFactor=e,this.parentFormula=null,this.valueSource=null}getFormulaValue(e){if(null===this.parentFormula)throw alert(t("error.formulaValue.noParent")),new Error(t("error.formulaValue.noParent"));if(null===this.valueSource)throw alert(t("error.formulaValue.noSource")),new Error(t("error.formulaValue.noSource"));return this.valueSource instanceof r?this.valueSource.getContextValue(e):u(l(this.valueSource.getVariantValue(this.parentFormula,e),this.valueSource.getOutputValueDefinition().scaleFactor),this.scaleFactor)}}export class Formula{constructor(e,a,l,u,r){this.values=e,this.variants=a,this.formulaKey=l,this.name=t("formula."+l+".name"),this.description=t("formula."+l+".desc"),this.categories=u,this.wikiLink=r,this.values.forEach((t=>{t.parentFormula=this}))}getClone(){const t=[];return this.values.forEach((e=>{t.push(new FormulaValue(e.unit,e.scaleFactor))})),new Formula(t,this.variants,this.formulaKey,this.categories,this.wikiLink)}}export const formulas={OHM_LAW:new Formula([new FormulaValue(a.OHM,e.SI_BASE),new FormulaValue(a.AMPERE,e.SI_BASE),new FormulaValue(a.VOLT,e.SI_BASE)],[new class{constructor(){this.description="V=I*R",this.getVariantValue=(t,e)=>t.values[0].getFormulaValue(e).times(t.values[1].getFormulaValue(e)),this.getInputValuesDefinition=()=>[this.parentFormula.values[0],this.parentFormula.values[1]],this.getOutputValueDefinition=()=>this.parentFormula.values[2],this.getMathMl=t=>"<math><mi>"+t.values[2].unit.symbol+"</mi><mo>=</mo><mi>"+t.values[0].unit.symbol+"</mi><mo>*</mo><mi>"+t.values[1].unit.symbol+"</mi></math>",this.parentFormula=null}},new class{constructor(){this.description="I=V/R",this.getVariantValue=(t,e)=>t.values[2].getFormulaValue(e).dividedBy(t.values[0].getFormulaValue(e)),this.getInputValuesDefinition=()=>[this.parentFormula.values[0],this.parentFormula.values[2]],this.getOutputValueDefinition=()=>this.parentFormula.values[1],this.getMathMl=t=>"<math><mi>"+t.values[1].unit.symbol+"</mi><mo>=</mo><mfrac><mi>"+t.values[2].unit.symbol+"</mi><mi>"+t.values[0].unit.symbol+"</mi></mfrac></math>",this.parentFormula=null}},new class{constructor(){this.description="R=V/I",this.getVariantValue=(t,e)=>t.values[2].getFormulaValue(e).dividedBy(t.values[1].getFormulaValue(e)),this.getInputValuesDefinition=()=>[this.parentFormula.values[2],this.parentFormula.values[1]],this.getOutputValueDefinition=()=>this.parentFormula.values[0],this.getMathMl=t=>"<math><mi>"+t.values[0].unit.symbol+"</mi><mo>=</mo><mfrac><mi>"+t.values[2].unit.symbol+"</mi><mi>"+t.values[1].unit.symbol+"</mi></mfrac></math>",this.parentFormula=null}}],"ohm_law",["electricity"],new URL("https://wikipedia.org/wiki/Ohm's_law"))};let i=!1;export function initFormulas(){i||(console.debug("Initializing formulas..."),Object.keys(formulas).forEach((t=>{formulas[t].variants.forEach((e=>{e.parentFormula=formulas[t]}))})),i=!0)}
|
@@ -1,57 +0,0 @@
|
||||
export const langKey = document.documentElement.lang.match("(en|fr)") ? document.documentElement.lang : "en";
|
||||
const langData = {
|
||||
en: {
|
||||
"unit.any.name": "Not Important",
|
||||
"unit.watt.name": "Watt",
|
||||
"unit.ampere.name": "Ampere",
|
||||
"unit.ohm.name": "Ohm",
|
||||
"unit.ohm.desc": "Electrical Resistance",
|
||||
"unit.volt.name": "Volt",
|
||||
"unit.farad.name": "Farad",
|
||||
"error.formulaValue.noParent": "Attempting to get a formula's value whose parent formula isn't set !",
|
||||
"error.formulaValue.noSource": "Attempting to get a formula's value whose value source is null !",
|
||||
"error.formulaContext.tooSmall": "The current calculation context is too small !",
|
||||
"ui.formulaCount": "formulas",
|
||||
"formula.ohm_law.name": "Ohm's Law",
|
||||
"dataset.resistor-e3.name": "E3 IEC Resistors",
|
||||
"dataset.resistor-e3.desc": "???",
|
||||
"dataset.resistor-e6.name": "E6 IEC Resistors",
|
||||
"dataset.resistor-e6.desc": "???",
|
||||
"dataset.resistor-e12.name": "E12 IEC Resistors",
|
||||
"dataset.resistor-e12.desc": "???",
|
||||
"dataset.resistor-e24.name": "E24 IEC Resistors",
|
||||
"dataset.resistor-e24.desc": "???",
|
||||
"dataset.resistor-e48.name": "E48 IEC Resistors",
|
||||
"dataset.resistor-e48.desc": "???",
|
||||
"dataset.capacitor-iec.name": "IEC E24 Capacitors",
|
||||
"dataset.capacitor-iec.desc": "???",
|
||||
"context.type.disabled.name": "Disabled",
|
||||
"context.type.constant.name": "Constant",
|
||||
"context.type.continuous.name": "Continuous",
|
||||
"context.type.valueRange.name": "Value Range",
|
||||
"context.type.dataSetRange.name": "Set-based Range",
|
||||
"context.type.disabled.desc": "???",
|
||||
"context.type.constant.desc": "???",
|
||||
"context.type.continuous.desc": "???",
|
||||
"context.type.valueRange.desc": "???",
|
||||
"context.type.dataSetRange.desc": "???",
|
||||
},
|
||||
fr: {
|
||||
"unit.ampere.name": "Ampère",
|
||||
"unit.ohm.desc": "Résistance électrique",
|
||||
"_error.formulaValue.noParent": "",
|
||||
"_error.formulaValue.noSource": "",
|
||||
"ui.formulaCount": "formules",
|
||||
"formula.ohm_law.name": "Loi d'Ohm",
|
||||
"context.type.disabled.name": "Désactivé",
|
||||
"context.type.constant.name": "Constante",
|
||||
"context.type.continuous.name": "Continue",
|
||||
"context.type.valueRange.name": "Valeurs distinctes",
|
||||
"context.type.dataSetRange.name": "Set de valeurs",
|
||||
}
|
||||
};
|
||||
export function localize(stringKey) {
|
||||
let _langData = langKey in langData ? langData[langKey] : langData.en;
|
||||
return stringKey in _langData ? _langData[stringKey] : (stringKey in langData["en"] ? langData["en"][stringKey] : stringKey);
|
||||
}
|
||||
//# sourceMappingURL=lang.js.map
|
1
tools/items/formula-wizard/src/lang.min.js
vendored
1
tools/items/formula-wizard/src/lang.min.js
vendored
@@ -1 +0,0 @@
|
||||
export const langKey=document.documentElement.lang.match("(en|fr)")?document.documentElement.lang:"en";const e={en:{"unit.any.name":"Not Important","unit.watt.name":"Watt","unit.ampere.name":"Ampere","unit.ohm.name":"Ohm","unit.ohm.desc":"Electrical Resistance","unit.volt.name":"Volt","unit.farad.name":"Farad","error.formulaValue.noParent":"Attempting to get a formula's value whose parent formula isn't set !","error.formulaValue.noSource":"Attempting to get a formula's value whose value source is null !","error.formulaContext.tooSmall":"The current calculation context is too small !","ui.formulaCount":"formulas","formula.ohm_law.name":"Ohm's Law","dataset.resistor-e3.name":"E3 IEC Resistors","dataset.resistor-e3.desc":"???","dataset.resistor-e6.name":"E6 IEC Resistors","dataset.resistor-e6.desc":"???","dataset.resistor-e12.name":"E12 IEC Resistors","dataset.resistor-e12.desc":"???","dataset.resistor-e24.name":"E24 IEC Resistors","dataset.resistor-e24.desc":"???","dataset.resistor-e48.name":"E48 IEC Resistors","dataset.resistor-e48.desc":"???","dataset.capacitor-iec.name":"IEC E24 Capacitors","dataset.capacitor-iec.desc":"???","context.type.disabled.name":"Disabled","context.type.constant.name":"Constant","context.type.continuous.name":"Continuous","context.type.valueRange.name":"Value Range","context.type.dataSetRange.name":"Set-based Range","context.type.disabled.desc":"???","context.type.constant.desc":"???","context.type.continuous.desc":"???","context.type.valueRange.desc":"???","context.type.dataSetRange.desc":"???"},fr:{"unit.ampere.name":"Ampère","unit.ohm.desc":"Résistance électrique","_error.formulaValue.noParent":"","_error.formulaValue.noSource":"","ui.formulaCount":"formules","formula.ohm_law.name":"Loi d'Ohm","context.type.disabled.name":"Désactivé","context.type.constant.name":"Constante","context.type.continuous.name":"Continue","context.type.valueRange.name":"Valeurs distinctes","context.type.dataSetRange.name":"Set de valeurs"}};export function localize(t){let a=langKey in e?e[langKey]:e.en;return t in a?a[t]:t in e.en?e.en[t]:t}
|
@@ -1,25 +0,0 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
const version = [0, 0, 2];
|
||||
console.log("Initializing 'Formula Wizard v" + version.join(".") + "'...");
|
||||
const startTime = new Date().getMilliseconds();
|
||||
import { Decimal } from "../../../../resources/DecimalJs/10.4.3/decimal.min.mjs";
|
||||
import { localize } from "./lang.js";
|
||||
import { units, initUnits } from "./units.js";
|
||||
import { formulas, initFormulas } from "./formulas.js";
|
||||
import { initCatalog } from "./ui_catalog.js";
|
||||
import { setupWorkbenchContext } from "./mvc_context.js";
|
||||
Decimal.set({ precision: 25, rounding: 8 });
|
||||
initUnits();
|
||||
initFormulas();
|
||||
initCatalog();
|
||||
setupWorkbenchContext();
|
||||
console.log(localize("joe.mama"));
|
||||
console.log(units);
|
||||
console.log(formulas);
|
||||
//# sourceMappingURL=main.js.map
|
8
tools/items/formula-wizard/src/main.min.js
vendored
8
tools/items/formula-wizard/src/main.min.js
vendored
@@ -1,8 +0,0 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
console.log("Initializing 'Formula Wizard v"+[0,0,2].join(".")+"'...");(new Date).getMilliseconds();import{Decimal as o}from"../../../../resources/DecimalJs/10.4.3/decimal.min.mjs";import{localize as i}from"./lang.js";import{units as m,initUnits as r}from"./units.js";import{formulas as s,initFormulas as l}from"./formulas.js";import{initCatalog as e}from"./ui_catalog.js";import{setupWorkbenchContext as n}from"./mvc_context.js";o.set({precision:25,rounding:8}),r(),l(),e(),n(),console.log(i("joe.mama")),console.log(m),console.log(s);
|
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
* Formula Wizard v0.0.3
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
@@ -17,17 +17,22 @@ import {localize} from "./lang";
|
||||
import {units, initUnits} from "./units";
|
||||
import {formulas, initFormulas} from "./formulas";
|
||||
import {initCatalog} from "./ui_catalog";
|
||||
import {setupWorkbenchContext} from "./mvc_context"
|
||||
import {setupWorkbenchContext} from "./mvc_context";
|
||||
import {setupWorkbenchFormula} from "./mvc_formula";
|
||||
|
||||
// Configuring the Decimal.JS library to use its maximum potential precision.
|
||||
Decimal.set({ precision: 25, rounding: 8 });
|
||||
|
||||
// Setting up non-primary things
|
||||
// Setting up common collections
|
||||
initUnits();
|
||||
initFormulas();
|
||||
|
||||
// Preparing the UI
|
||||
initCatalog();
|
||||
setupWorkbenchContext();
|
||||
setupWorkbenchFormula();
|
||||
|
||||
// ???
|
||||
|
||||
// Tests
|
||||
console.log(localize("joe.mama"));
|
||||
|
@@ -1,124 +0,0 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
import { localize } from "./lang.js";
|
||||
import { units, scaleFactors } from "./units.js";
|
||||
import { sets } from "./sets.js";
|
||||
class ContextType {
|
||||
constructor(name, description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
export const contextTypes = {
|
||||
DISABLED: new ContextType(localize("context.type.disabled.name"), localize("context.type.disabled.desc")),
|
||||
CONSTANT: new ContextType(localize("context.type.constant.name"), localize("context.type.constant.desc")),
|
||||
CONTINUOUS: new ContextType(localize("context.type.continuous.name"), localize("context.type.continuous.desc")),
|
||||
VALUE_RANGE: new ContextType(localize("context.type.valueRange.name"), localize("context.type.valueRange.desc")),
|
||||
DATASET_RANG: new ContextType(localize("context.type.dataSetRange.name"), localize("context.type.dataSetRange.desc")),
|
||||
};
|
||||
const idContextComponentPrefix = "fw-context-component-";
|
||||
const idContextComponentId = idContextComponentPrefix + "id";
|
||||
const idContextComponentDelete = idContextComponentPrefix + "delete";
|
||||
const idContextComponentTypes = idContextComponentPrefix + "type";
|
||||
const idContextComponentManualValue = idContextComponentPrefix + "manual-value";
|
||||
const idContextComponentManualValues = idContextComponentManualValue + "s";
|
||||
const idContextComponentRangeFrom = idContextComponentPrefix + "range-from";
|
||||
const idContextComponentRangeTo = idContextComponentPrefix + "range-to";
|
||||
const idContextComponentRangeStep = idContextComponentPrefix + "range-step";
|
||||
const idContextComponentSets = idContextComponentPrefix + "set";
|
||||
const idContextComponentUnit = idContextComponentPrefix + "unit";
|
||||
const idContextComponentScale = idContextComponentPrefix + "scale";
|
||||
class WorkbenchContextComponentData {
|
||||
}
|
||||
class WorkbenchContextComponentInterface {
|
||||
}
|
||||
export class WorkbenchContextComponent {
|
||||
constructor(uiElement, data) {
|
||||
this.uiElement = uiElement;
|
||||
this.data = data;
|
||||
}
|
||||
static createNew(eRootElement) {
|
||||
return null;
|
||||
}
|
||||
toJson() {
|
||||
return JSON.stringify(this.data);
|
||||
}
|
||||
fromJson() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export let workbenchContextComponents = [];
|
||||
let eTemplateContextComponent = null;
|
||||
let eContextStatusMessage = null;
|
||||
let eContextAddButton = null;
|
||||
let isWorkbenchContextSetup = false;
|
||||
export function setupWorkbenchContext() {
|
||||
if (!isWorkbenchContextSetup) {
|
||||
console.debug("Preparing UI for workbench context components...");
|
||||
eTemplateContextComponent = document.getElementById("template-context-component");
|
||||
if (eTemplateContextComponent === null) {
|
||||
alert(localize("error.ui.context.noTemplate"));
|
||||
throw Error(localize("error.ui.context.noTemplate"));
|
||||
}
|
||||
eTemplateContextComponent = eTemplateContextComponent.cloneNode(true).content;
|
||||
document.getElementById("template-context-component").remove();
|
||||
const eContextTypes = eTemplateContextComponent.getElementById(idContextComponentTypes);
|
||||
const eContextSets = eTemplateContextComponent.getElementById(idContextComponentSets);
|
||||
const eContextUnits = eTemplateContextComponent.getElementById(idContextComponentUnit);
|
||||
const eContextScales = eTemplateContextComponent.getElementById(idContextComponentScale);
|
||||
if ([eContextTypes, eContextSets, eContextUnits, eContextScales].some((item) => item === null)) {
|
||||
alert(localize("error.ui.context.noSets"));
|
||||
throw Error(localize("error.ui.context.noSets"));
|
||||
}
|
||||
Object.keys(contextTypes).forEach(value => {
|
||||
const eNewContextTypesOption = document.createElement("option");
|
||||
eNewContextTypesOption.setAttribute("value", value);
|
||||
eNewContextTypesOption.innerText = contextTypes[value].name;
|
||||
eContextTypes.appendChild(eNewContextTypesOption);
|
||||
});
|
||||
Object.keys(sets).forEach(value => {
|
||||
const eNewContextSetsOption = document.createElement("option");
|
||||
eNewContextSetsOption.setAttribute("value", value);
|
||||
eNewContextSetsOption.innerText = sets[value].name;
|
||||
eContextSets.appendChild(eNewContextSetsOption);
|
||||
});
|
||||
Object.keys(units).forEach(unitKey => {
|
||||
const eNewContextUnitsOption = document.createElement("option");
|
||||
eNewContextUnitsOption.setAttribute("value", unitKey);
|
||||
eNewContextUnitsOption.innerText = units[unitKey].name;
|
||||
eContextUnits.appendChild(eNewContextUnitsOption);
|
||||
});
|
||||
Object.keys(scaleFactors).forEach(scaleKey => {
|
||||
const eNewContextScalesOption = document.createElement("option");
|
||||
eNewContextScalesOption.setAttribute("value", scaleKey);
|
||||
eNewContextScalesOption.innerText = scaleFactors[scaleKey].prefix;
|
||||
eContextScales.appendChild(eNewContextScalesOption);
|
||||
});
|
||||
eContextStatusMessage = document.getElementById("fw-text-context-middle");
|
||||
if (eContextStatusMessage === null) {
|
||||
alert(localize("error.ui.context.noStatus"));
|
||||
throw Error(localize("error.ui.context.noStatus"));
|
||||
}
|
||||
eContextAddButton = document.querySelector("button#fw-button-add-context");
|
||||
if (eContextAddButton === null) {
|
||||
alert(localize("error.ui.context.missingButton"));
|
||||
throw Error(localize("error.ui.context.missingButton"));
|
||||
}
|
||||
eContextAddButton.onclick = function () {
|
||||
const eNewContextComponent = eTemplateContextComponent.cloneNode(true).firstElementChild;
|
||||
if (eNewContextComponent === null) {
|
||||
alert(localize("error.ui.context.component.cannotGetElement"));
|
||||
throw Error(localize("error.ui.context.component.cannotGetElement"));
|
||||
}
|
||||
const newContextComponent = WorkbenchContextComponent.createNew(eNewContextComponent);
|
||||
workbenchContextComponents.push(newContextComponent);
|
||||
};
|
||||
isWorkbenchContextSetup = true;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=mvc_context.js.map
|
@@ -1,4 +1,4 @@
|
||||
/*!
|
||||
/*
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
@@ -52,13 +52,110 @@ const idContextComponentUnit = idContextComponentPrefix + "unit";
|
||||
const idContextComponentScale = idContextComponentPrefix + "scale";
|
||||
|
||||
class WorkbenchContextComponentData {
|
||||
//id: string;
|
||||
id: string;
|
||||
|
||||
constructor(controllerId: string) {
|
||||
this.id = controllerId;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkbenchContextComponentInterface {
|
||||
public rootElement: HTMLElement;
|
||||
|
||||
private readonly eIdLabel: HTMLLabelElement;
|
||||
private readonly eIdInput: HTMLInputElement;
|
||||
public readonly eDeleteButton: HTMLButtonElement;
|
||||
private readonly eTypeLabel: HTMLLabelElement;
|
||||
private readonly eTypeSelect: HTMLSelectElement;
|
||||
|
||||
private readonly eManualValueLabel: HTMLLabelElement;
|
||||
private readonly eManualValueInput: HTMLInputElement;
|
||||
|
||||
private readonly eManualValuesLabel: HTMLLabelElement;
|
||||
private readonly eManualValuesInput: HTMLInputElement;
|
||||
|
||||
private readonly eRangeFromLabel: HTMLLabelElement;
|
||||
private readonly eRangeFromInput: HTMLInputElement;
|
||||
private readonly eRangeToLabel: HTMLLabelElement;
|
||||
private readonly eRangeToInput: HTMLInputElement;
|
||||
private readonly eRangeStepLabel: HTMLLabelElement;
|
||||
private readonly eRangeStepInput: HTMLInputElement;
|
||||
|
||||
private readonly eDataSetLabel: HTMLLabelElement;
|
||||
private readonly eDataSetSelect: HTMLSelectElement;
|
||||
|
||||
private readonly eUnitLabel: HTMLLabelElement;
|
||||
private readonly eUnitSelect: HTMLSelectElement;
|
||||
private readonly eScaleLabel: HTMLLabelElement;
|
||||
private readonly eScaleSelect: HTMLSelectElement;
|
||||
|
||||
private readonly allElements: HTMLElement[];
|
||||
|
||||
constructor(controllerId: string, rootElement: HTMLElement) {
|
||||
this.rootElement = rootElement;
|
||||
|
||||
// Grabbing references to essential UI elements.
|
||||
// All "null" checks are done below.
|
||||
this.eIdLabel = rootElement.querySelector(`label[for="${idContextComponentId}"]`)!;
|
||||
this.eIdInput = rootElement.querySelector(`input#${idContextComponentId}`)!;
|
||||
|
||||
this.eDeleteButton = rootElement.querySelector(`button#${idContextComponentDelete}`)!;
|
||||
|
||||
this.eTypeLabel = rootElement.querySelector(`label[for="${idContextComponentTypes}"]`)!;
|
||||
this.eTypeSelect = rootElement.querySelector(`select#${idContextComponentTypes}`)!;
|
||||
|
||||
this.eManualValueLabel = rootElement.querySelector(`label[for="${idContextComponentManualValue}"]`)!;
|
||||
this.eManualValueInput = rootElement.querySelector(`input#${idContextComponentManualValue}`)!;
|
||||
|
||||
this.eManualValuesLabel = rootElement.querySelector(`label[for="${idContextComponentManualValues}"]`)!;
|
||||
this.eManualValuesInput = rootElement.querySelector(`input#${idContextComponentManualValues}`)!;
|
||||
|
||||
this.eRangeFromLabel = rootElement.querySelector(`label[for="${idContextComponentRangeFrom}"]`)!;
|
||||
this.eRangeFromInput = rootElement.querySelector(`input#${idContextComponentRangeFrom}`)!;
|
||||
this.eRangeToLabel = rootElement.querySelector(`label[for="${idContextComponentRangeTo}"]`)!;
|
||||
this.eRangeToInput = rootElement.querySelector(`input#${idContextComponentRangeTo}`)!;
|
||||
this.eRangeStepLabel = rootElement.querySelector(`label[for="${idContextComponentRangeStep}"]`)!;
|
||||
this.eRangeStepInput = rootElement.querySelector(`input#${idContextComponentRangeStep}`)!;
|
||||
|
||||
this.eDataSetLabel = rootElement.querySelector(`label[for="${idContextComponentSets}"]`)!;
|
||||
this.eDataSetSelect = rootElement.querySelector(`select#${idContextComponentSets}`)!;
|
||||
|
||||
this.eUnitLabel = rootElement.querySelector(`label[for="${idContextComponentUnit}"]`)!;
|
||||
this.eUnitSelect = rootElement.querySelector(`select#${idContextComponentUnit}`)!;
|
||||
this.eScaleLabel = rootElement.querySelector(`label[for="${idContextComponentScale}"]`)!;
|
||||
this.eScaleSelect = rootElement.querySelector(`select#${idContextComponentScale}`)!;
|
||||
|
||||
// Making sure we got all elements.
|
||||
this.allElements = [
|
||||
this.eIdLabel, this.eIdInput, this.eDeleteButton, this.eTypeLabel, this.eTypeSelect,
|
||||
this.eManualValuesLabel, this.eManualValuesInput, this.eRangeFromLabel, this.eRangeFromInput,
|
||||
this.eRangeToLabel, this.eRangeToInput, this.eRangeStepLabel, this.eRangeStepInput, this.eDataSetLabel,
|
||||
this.eDataSetSelect, this.eUnitLabel, this.eUnitSelect, this.eScaleLabel, this.eScaleSelect,
|
||||
this.eManualValueLabel, this.eManualValueInput
|
||||
];
|
||||
if(this.allElements.some((item) => item === null)) {
|
||||
alert(localize("error.ui.context.component.missingElement"));
|
||||
throw Error(localize("error.ui.context.component.missingElement"));
|
||||
}
|
||||
|
||||
// Appending the "idSuffix" to all the IDs and "for" attributes.
|
||||
rootElement.querySelectorAll(`input, select`).forEach(eFormInput => {
|
||||
if(eFormInput.hasAttribute("id")) {
|
||||
eFormInput.setAttribute("id", eFormInput.getAttribute("id") + controllerId);
|
||||
}
|
||||
});
|
||||
rootElement.querySelectorAll(`label`).forEach(eFormLabel => {
|
||||
if(eFormLabel.hasAttribute("for")) {
|
||||
eFormLabel.setAttribute("for", eFormLabel.getAttribute("for") + controllerId);
|
||||
}
|
||||
});
|
||||
|
||||
// Other manual ID-related changes.
|
||||
this.eDeleteButton.removeAttribute('id');
|
||||
|
||||
// Setting up default values in fields.
|
||||
this.eIdInput.value = controllerId;
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkbenchContextComponent {
|
||||
@@ -68,11 +165,28 @@ export class WorkbenchContextComponent {
|
||||
constructor(uiElement: WorkbenchContextComponentInterface, data: WorkbenchContextComponentData) {
|
||||
this.uiElement = uiElement;
|
||||
this.data = data;
|
||||
|
||||
// Binding UI-sourced events to controller functions.
|
||||
|
||||
// Setting actions & events.
|
||||
//this.eTypeSelect.onchange = this.onTypeChange.bind(this);
|
||||
this.uiElement.eDeleteButton.onclick = this.handleDelete.bind(this);
|
||||
|
||||
// Forcing some actions
|
||||
this.handleTypeChange();
|
||||
}
|
||||
|
||||
public static createNew(eRootElement: HTMLElement): WorkbenchContextComponent {
|
||||
// formulaVariant: FormulaVariant
|
||||
return null!;
|
||||
setId(newId: string): void {
|
||||
|
||||
}
|
||||
|
||||
handleDelete(): void {
|
||||
this.uiElement.rootElement.remove();
|
||||
deleteWorkbenchComponent(this);
|
||||
}
|
||||
|
||||
handleTypeChange(): void {
|
||||
|
||||
}
|
||||
|
||||
toJson(): string {
|
||||
@@ -82,6 +196,20 @@ export class WorkbenchContextComponent {
|
||||
fromJson(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static createNew(eRootElement: HTMLElement): WorkbenchContextComponent {
|
||||
const id: string = Date.now().toString();
|
||||
|
||||
return new WorkbenchContextComponent(
|
||||
new WorkbenchContextComponentInterface(
|
||||
id,
|
||||
eRootElement,
|
||||
),
|
||||
new WorkbenchContextComponentData(
|
||||
id,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +219,18 @@ export class WorkbenchContextComponent {
|
||||
|
||||
export let workbenchContextComponents: WorkbenchContextComponent[] = [];
|
||||
|
||||
function deleteWorkbenchComponent(deletedComponent: WorkbenchContextComponent) {
|
||||
workbenchContextComponents = workbenchContextComponents.filter(item => item !== deletedComponent);
|
||||
if(workbenchContextComponents.length < 1) {
|
||||
eContextStatusMessage!.hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------
|
||||
// ???
|
||||
// ----------------
|
||||
|
||||
//
|
||||
let eTemplateContextComponent: HTMLElement | DocumentFragment | null = null;
|
||||
|
||||
@@ -163,6 +303,9 @@ export function setupWorkbenchContext() {
|
||||
}
|
||||
|
||||
eContextAddButton.onclick = function() {
|
||||
console.group("Adding new context component to workbench...");
|
||||
|
||||
console.debug("Copying the template...");
|
||||
// We only get the fragment via the template, we have to use this monstrosity to get a proper element out of it.
|
||||
const eNewContextComponent=
|
||||
(eTemplateContextComponent!.cloneNode(true) as DocumentFragment).firstElementChild as HTMLElement;
|
||||
@@ -171,15 +314,19 @@ export function setupWorkbenchContext() {
|
||||
throw Error(localize("error.ui.context.component.cannotGetElement"));
|
||||
}
|
||||
|
||||
console.debug("Instantiating and saving the 'WorkbenchContextComponent'...");
|
||||
const newContextComponent = WorkbenchContextComponent.createNew(
|
||||
eNewContextComponent
|
||||
);
|
||||
workbenchContextComponents.push(newContextComponent);
|
||||
|
||||
//eContextStatusMessage!.parentNode!.insertBefore(newContextComponent.uiElement, eContextStatusMessage);
|
||||
//eContextStatusMessage!.hidden = true;
|
||||
////eContextStatusMessage!.parentNode!.insertBefore(newContextComponent.rootElement, eContextStatusMessage);
|
||||
////eContextStatusMessage!.hidden = true;
|
||||
console.debug("> ID: " + newContextComponent.data.id);
|
||||
|
||||
console.debug("Inserting the element in the DOM...");
|
||||
eContextStatusMessage!.parentNode!.insertBefore(newContextComponent.uiElement.rootElement, eContextStatusMessage!);
|
||||
eContextStatusMessage!.hidden = true;
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
|
||||
isWorkbenchContextSetup = true;
|
||||
|
184
tools/items/formula-wizard/src/mvc_formula.ts
Normal file
184
tools/items/formula-wizard/src/mvc_formula.ts
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
|
||||
import {localize} from "./lang";
|
||||
import {isCatalogInitialized, catalogFormulas} from "./ui_catalog";
|
||||
|
||||
// -----------
|
||||
// Constants
|
||||
// -----------
|
||||
|
||||
const ID_TEMPLATE_FORMULA = "template-workbench-formula";
|
||||
const ID_TEMPLATE_FORMULA_VALUE = ID_TEMPLATE_FORMULA + "-value";
|
||||
|
||||
const ID_FORMULA_PREFIX = "fw-workbench-formula-";
|
||||
const ID_FORMULA_SPAWN_POINT = ID_FORMULA_PREFIX + "spawn";
|
||||
|
||||
//const idWorkbenchFormulaPrefix = "fw-workbench-formula-";
|
||||
//const idWorkbenchFormulaSpawnPoint = idWorkbenchFormulaPrefix + "spawn";
|
||||
//
|
||||
//// Formula template
|
||||
//const idTemplateFormula = "template-workbench-formula";
|
||||
//const idFormulaName = idWorkbenchFormulaPrefix + "name";
|
||||
//const idFormulaInputs = idWorkbenchFormulaPrefix + "inputs";
|
||||
//const idFormulaOutputs = idWorkbenchFormulaPrefix + "outputs";
|
||||
//
|
||||
//// FormulaUnit template
|
||||
//const classTemplateFormulaValue = "formula-value-input-form";
|
||||
//const idTemplateFormulaValue = idTemplateFormula + "-value";
|
||||
//const idFormulaValuePrefix = idWorkbenchFormulaPrefix + "value-";
|
||||
//const idFormulaValueId = idFormulaValuePrefix + "id";
|
||||
//const idFormulaValueName = idFormulaValuePrefix + "name";
|
||||
//const idFormulaValueLink = idFormulaValuePrefix + "link";
|
||||
//const idFormulaValueTestValue = idFormulaValuePrefix + "test-value";
|
||||
//const idFormulaValueTestScale = idFormulaValuePrefix + "test-scale";
|
||||
//const idFormulaValueTestValueSet = idFormulaValuePrefix + "test-value-set";
|
||||
|
||||
|
||||
// ---------
|
||||
// Globals
|
||||
// ---------
|
||||
|
||||
let eTemplateWorkbenchFormula: HTMLElement | DocumentFragment | null = null;
|
||||
let eTemplateWorkbenchFormulaValue: HTMLElement | DocumentFragment | null = null;
|
||||
|
||||
export let workbenchFormulas: WorkbenchFormula[] = [];
|
||||
|
||||
|
||||
// ----------------------
|
||||
// Global-related utils
|
||||
// ----------------------
|
||||
|
||||
function deleteWorkbenchFormula(deletedFormula: WorkbenchFormula, removeDom: boolean = true) {
|
||||
workbenchFormulas = workbenchFormulas.filter(item => item !== deletedFormula);
|
||||
//if(removeDom) {
|
||||
// //deletedFormula.uiElement
|
||||
//}
|
||||
//if(workbenchContextComponents.length < 1) {
|
||||
// eContextStatusMessage!.hidden = false;
|
||||
//}
|
||||
}
|
||||
|
||||
// --------------------
|
||||
// Formula Values MVC
|
||||
// --------------------
|
||||
|
||||
enum EWorkbenchFormulaValueTypes {
|
||||
//UNKNOWN,
|
||||
INPUT,
|
||||
OUTPUT,
|
||||
}
|
||||
|
||||
class WorkbenchFormulaValueData {
|
||||
id: string;
|
||||
|
||||
constructor(controllerId: string) {
|
||||
this.id = controllerId;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkbenchFormulaValueInterface {
|
||||
|
||||
}
|
||||
|
||||
class WorkbenchFormulaValue {
|
||||
uiElement: WorkbenchFormulaValueInterface;
|
||||
data: WorkbenchFormulaValueData;
|
||||
|
||||
constructor(uiElement: WorkbenchFormulaValueInterface, data: WorkbenchFormulaValueData) {
|
||||
this.uiElement = uiElement;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static createNew(eRootElement: HTMLElement): WorkbenchFormulaValue {
|
||||
const id: string = Date.now().toString();
|
||||
|
||||
return null!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------
|
||||
// Formulas MVC
|
||||
// --------------
|
||||
|
||||
class WorkbenchFormulaData {
|
||||
id: string;
|
||||
|
||||
constructor(controllerId: string) {
|
||||
this.id = controllerId;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkbenchFormulaInterface {
|
||||
|
||||
}
|
||||
|
||||
class WorkbenchFormula {
|
||||
uiElement: WorkbenchFormulaInterface;
|
||||
data: WorkbenchFormulaData;
|
||||
|
||||
constructor(uiElement: WorkbenchFormulaInterface, data: WorkbenchFormulaData) {
|
||||
this.uiElement = uiElement;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static createNew(eRootElement: HTMLElement): WorkbenchFormula {
|
||||
const id: string = Date.now().toString();
|
||||
|
||||
return null!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------
|
||||
// ???
|
||||
// ----------------
|
||||
|
||||
let isWorkbenchFormulaSetup = false;
|
||||
|
||||
export function setupWorkbenchFormula() {
|
||||
if (!isWorkbenchFormulaSetup) {
|
||||
console.group("Preparing UI for workbench formula components...");
|
||||
|
||||
console.debug("Checking if the catalog is ready...");
|
||||
if(!isCatalogInitialized()) {
|
||||
console.groupEnd();
|
||||
alert(localize("error.ui.workbench.catalog.no-init"));
|
||||
throw Error(localize("error.ui.workbench.catalog.no-init"));
|
||||
}
|
||||
|
||||
console.debug("Grabbing & processing the templates from the DOM...");
|
||||
eTemplateWorkbenchFormula = document.getElementById(ID_TEMPLATE_FORMULA);
|
||||
eTemplateWorkbenchFormulaValue = document.getElementById(ID_TEMPLATE_FORMULA_VALUE);
|
||||
if(eTemplateWorkbenchFormula === null || eTemplateWorkbenchFormulaValue === null) {
|
||||
console.groupEnd();
|
||||
alert(localize("error.ui.workbench.noTemplate"));
|
||||
throw Error(localize("error.ui.workbench.noTemplate"));
|
||||
}
|
||||
eTemplateWorkbenchFormula = (eTemplateWorkbenchFormula.cloneNode(true) as HTMLTemplateElement).content;
|
||||
eTemplateWorkbenchFormulaValue = (eTemplateWorkbenchFormulaValue.cloneNode(true) as HTMLTemplateElement).content;
|
||||
|
||||
console.debug("Grabbing the anchor point for new formulas...");
|
||||
const eWorkbenchFormulaSpawnPoint: HTMLAnchorElement | null = document.querySelector(`a#${ID_FORMULA_SPAWN_POINT}`);
|
||||
if(eWorkbenchFormulaSpawnPoint === null) {
|
||||
console.groupEnd();
|
||||
alert(localize("error.ui.workbench.noAnchor"));
|
||||
throw Error(localize("error.ui.workbench.noAnchor"));
|
||||
}
|
||||
|
||||
// catalogFormulas
|
||||
|
||||
|
||||
|
||||
|
||||
isWorkbenchFormulaSetup = true;
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
import { Decimal } from "../../../../resources/DecimalJs/10.4.3/decimal.min.mjs";
|
||||
import { localize } from "./lang.js";
|
||||
import { units, scaleFactors } from "./units.js";
|
||||
export class DataSet {
|
||||
constructor(name, description, values, unit, scaleFactor) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.values = values;
|
||||
this.unit = unit;
|
||||
this.scaleFactor = scaleFactor;
|
||||
if (unit.scale != scaleFactor.scale) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
}
|
||||
getDataSet() {
|
||||
return this.values;
|
||||
}
|
||||
}
|
||||
const e3Range = [1, 2.2, 4.7];
|
||||
const e6Range = [1, 1.5, 2.2, 3.3, 4.7, 6.8];
|
||||
const e12Range = [1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2];
|
||||
const e24Range = [
|
||||
1, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2, 2.2, 2.4, 2.7, 3, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1
|
||||
];
|
||||
const e48Range = [
|
||||
1, 1.05, 1.1, 1.15, 1.21, 1.27, 1.33, 1.4, 1.47, 1.54, 1.62, 1.69, 1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49,
|
||||
2.61, 2.74, 2.87, 3.01, 3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 5.62, 5.9, 6.19,
|
||||
6.49, 6.81, 7.15, 7.5, 7.87, 8.25, 8.66, 9.09, 9.53
|
||||
];
|
||||
const resistorsScales = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000];
|
||||
const capacitorScales = [10e-12, 10e-11, 10e-10, 10e-9, 10e-8, 10e-7, 10e-6, 10e-5, 10e-4, 10e-3, 10e-2];
|
||||
export const sets = {
|
||||
RESISTOR_E3: new DataSet(localize("dataset.resistor-e3.name"), localize("dataset.resistor-e3.desc"), resistorsScales.flatMap((e3Scale) => e3Range.map((e3Multiplier) => new Decimal(e3Scale).times(e3Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E6: new DataSet(localize("dataset.resistor-e6.name"), localize("dataset.resistor-e6.desc"), resistorsScales.flatMap((e6Scale) => e6Range.map((e6Multiplier) => new Decimal(e6Scale).times(e6Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E12: new DataSet(localize("dataset.resistor-e12.name"), localize("dataset.resistor-e12.desc"), resistorsScales.flatMap((e12Scale) => e12Range.map((e12Multiplier) => new Decimal(e12Scale).times(e12Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E24: new DataSet(localize("dataset.resistor-e24.name"), localize("dataset.resistor-e24.desc"), resistorsScales.flatMap((e24Scale) => e24Range.map((e24Multiplier) => new Decimal(e24Scale).times(e24Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
RESISTOR_E48: new DataSet(localize("dataset.resistor-e48.name"), localize("dataset.resistor-e48.desc"), resistorsScales.flatMap((e48Scale) => e48Range.map((e48Multiplier) => new Decimal(e48Scale).times(e48Multiplier))), units.OHM, scaleFactors.SI_BASE),
|
||||
CAPACITOR_IEC: new DataSet(localize("dataset.capacitor-iec.name"), localize("dataset.capacitor-iec.desc"), capacitorScales.flatMap((cScale) => e24Range.map((eMultiplier) => new Decimal(cScale).times(eMultiplier))), units.FARAD, scaleFactors.SI_BASE),
|
||||
};
|
||||
//# sourceMappingURL=sets.js.map
|
@@ -1,115 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2019", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "ES6", /* Specify what module code is generated. */
|
||||
"rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
//"outFile": "./formula-wizard.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
"removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"files": [
|
||||
"./main.ts",
|
||||
],
|
||||
"exclude": [
|
||||
"../../../../resources/DecimalJs/10.4.3"
|
||||
]
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
* [Short desc here]
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
import { formulas } from "./formulas.js";
|
||||
const idCatalogPrefix = "fw-catalog-";
|
||||
const idCatalogCategoryPrefix = idCatalogPrefix + "category-";
|
||||
const idCatalogCategoryCount = idCatalogPrefix + "formula-count";
|
||||
export const eCategoryContainers = {};
|
||||
let IsCatalogInitialized = false;
|
||||
export function initCatalog() {
|
||||
if (!IsCatalogInitialized) {
|
||||
console.debug("Populating formula catalog...");
|
||||
document.querySelectorAll('[id]').forEach((element) => {
|
||||
if (element.id.startsWith(idCatalogCategoryPrefix)) {
|
||||
eCategoryContainers[element.id.replace(idCatalogCategoryPrefix, "")] = element;
|
||||
}
|
||||
});
|
||||
const eFormulaCount = document.getElementById(idCatalogCategoryCount);
|
||||
if (eFormulaCount !== null) {
|
||||
eFormulaCount.innerText = Object.keys(formulas).length.toString();
|
||||
}
|
||||
let eTemplateFormula = document.getElementById("template-formula-available");
|
||||
let eTemplateFormulaVariant = document.getElementById("template-formula-available-variant");
|
||||
if (eTemplateFormula === null || eTemplateFormulaVariant === null) {
|
||||
alert("error.ui.catalog.noTemplate");
|
||||
throw Error("error.ui.catalog.noTemplate");
|
||||
}
|
||||
Object.keys(formulas).forEach(formulaKey => {
|
||||
const hasValidCategory = formulas[formulaKey].categories.every(function (categoryId) {
|
||||
return Object.keys(eCategoryContainers).indexOf(categoryId) !== -1;
|
||||
});
|
||||
if (hasValidCategory) {
|
||||
let eNewFormula = eTemplateFormula.content.cloneNode(true);
|
||||
let eNewFormulaTitle = eNewFormula.querySelector("p");
|
||||
if (eNewFormulaTitle !== null) {
|
||||
eNewFormulaTitle.innerText = formulas[formulaKey].name;
|
||||
}
|
||||
let eNewFormulaVariants = eNewFormula.querySelector("div.fw-variants");
|
||||
if (eNewFormulaVariants === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
eNewFormulaVariants.innerHTML = "";
|
||||
formulas[formulaKey].variants.forEach(variant => {
|
||||
let eNewFormulaVariant = eTemplateFormulaVariant.content.cloneNode(true);
|
||||
let eNewFormulaVariantButton = eNewFormulaVariant.querySelector("button");
|
||||
if (eNewFormulaVariantButton === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
eNewFormulaVariantButton.innerHTML = variant.getMathMl(formulas[formulaKey]);
|
||||
eNewFormulaVariantButton.title = variant.description;
|
||||
eNewFormulaVariants.appendChild(eNewFormulaVariant);
|
||||
});
|
||||
formulas[formulaKey].categories.forEach(categoryKey => {
|
||||
if (Object.keys(eCategoryContainers).includes(categoryKey)) {
|
||||
eCategoryContainers[categoryKey].appendChild(eNewFormula);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
IsCatalogInitialized = true;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ui_catalog.js.map
|
@@ -1,12 +1,16 @@
|
||||
/*!
|
||||
* Formula Wizard v0.0.2
|
||||
/*
|
||||
* Formula Wizard v1.0.0 - Formula Catalog
|
||||
* --------------------------------------------------------------------------------
|
||||
* [Short desc here]
|
||||
* This module handles the indexation of all formulas and their elements to be
|
||||
* show in the UI.
|
||||
* --------------------------------------------------------------------------------
|
||||
* https://github.com/aziascreations/Web-NibblePoker
|
||||
* Copyright (c) 2023 Herwin Bozet <herwin.bozet@gmail.com>
|
||||
* Unlicense Licence
|
||||
*/
|
||||
|
||||
import {formulas} from "./formulas";
|
||||
import {formulas, Formula} from "./formulas";
|
||||
|
||||
const idCatalogPrefix = "fw-catalog-";
|
||||
const idCatalogCategoryPrefix = idCatalogPrefix + "category-"
|
||||
@@ -16,26 +20,104 @@ const idCatalogCategoryCount = idCatalogPrefix + "formula-count"
|
||||
// The key is their ID without the prefix. (Result: electricity, chemistry, ...)
|
||||
export const eCategoryContainers: { [key: string]: HTMLElement } = {};
|
||||
|
||||
// ----------------
|
||||
// ???
|
||||
// ----------------
|
||||
|
||||
export const catalogFormulas: CatalogFormula[] = [];
|
||||
|
||||
class CatalogFormula {
|
||||
formula: Formula;
|
||||
eFormulaContainer: HTMLElement;
|
||||
eVariantContainer: HTMLElement;
|
||||
eCategories: HTMLElement[];
|
||||
eVariantContainers: HTMLElement[];
|
||||
eVariantButtons: HTMLButtonElement[];
|
||||
|
||||
constructor(formula: Formula, eCategories: HTMLElement[], eFormulaContainer: HTMLElement,
|
||||
eVariantContainers: HTMLElement[], eVariantButtons: HTMLButtonElement[]) {
|
||||
this.formula = formula;
|
||||
this.eCategories = eCategories;
|
||||
this.eFormulaContainer = eFormulaContainer;
|
||||
this.eVariantContainers = eVariantContainers;
|
||||
this.eVariantButtons = eVariantButtons;
|
||||
|
||||
// Setting up the title
|
||||
let eNewFormulaTitle = this.eFormulaContainer.querySelector("p");
|
||||
if(eNewFormulaTitle !== null) {
|
||||
eNewFormulaTitle.innerText = this.formula.name;
|
||||
}
|
||||
|
||||
// Grabbing the spawn point for all variants
|
||||
let eNewFormulaVariants = this.eFormulaContainer.querySelector("div.fw-variants");
|
||||
if(eNewFormulaVariants === null) {
|
||||
alert("idk1");
|
||||
throw Error("idk1");
|
||||
}
|
||||
this.eVariantContainer = eNewFormulaVariants as HTMLElement;
|
||||
this.eVariantContainer.innerHTML = "";
|
||||
|
||||
// Setting up each variant
|
||||
for(let i = 0; i < this.formula.variants.length; i++) {
|
||||
this.eVariantButtons[i].innerHTML = this.formula.variants[i].getMathMl(this.formula);
|
||||
this.eVariantButtons[i].title = this.formula.variants[i].description;
|
||||
|
||||
// Now adding those buttons to the root element.
|
||||
this.eVariantContainer.appendChild(this.eVariantContainers[i]);
|
||||
}
|
||||
|
||||
// NOTE: The "onclick" will be set in "mvc_formula.ts" since it will bind those button and the workbench
|
||||
// formulas these buttons can spawn.
|
||||
}
|
||||
|
||||
insertIntoCategories() {
|
||||
// Adding it to any relevant category.
|
||||
this.eCategories.forEach(eCategory => {
|
||||
eCategory.appendChild(this.eFormulaContainer);
|
||||
});
|
||||
|
||||
// Preventing any double-insertion.
|
||||
this.eCategories = [];
|
||||
}
|
||||
|
||||
// TODO: A function to easily bind a common given function.
|
||||
}
|
||||
|
||||
|
||||
// ----------------
|
||||
// ???
|
||||
// ----------------
|
||||
|
||||
let IsCatalogInitialized = false;
|
||||
|
||||
/**
|
||||
* Used by the Workbench's Formula MVC to determine if the actions on the buttons can be prepared.
|
||||
*
|
||||
* Will always return `true` once `initCatalog()` has been called at least once.
|
||||
*/
|
||||
export function isCatalogInitialized(): boolean {
|
||||
return IsCatalogInitialized;
|
||||
}
|
||||
|
||||
export function initCatalog() {
|
||||
if (!IsCatalogInitialized) {
|
||||
console.debug("Populating formula catalog...");
|
||||
console.group("Preparing the formula catalog...");
|
||||
|
||||
console.debug("Grabbing the category container elements...");
|
||||
document.querySelectorAll('[id]').forEach((element ) => {
|
||||
if(element.id.startsWith(idCatalogCategoryPrefix)) {
|
||||
eCategoryContainers[element.id.replace(idCatalogCategoryPrefix, "")] = element as HTMLElement;
|
||||
}
|
||||
});
|
||||
|
||||
// Showing the formula count.
|
||||
console.debug("Setting up the formula count in the UI...");
|
||||
const eFormulaCount = document.getElementById(idCatalogCategoryCount);
|
||||
if(eFormulaCount !== null) {
|
||||
//eFormulaCount.innerText = Object.keys(formulas).length + " "+ localize("ui.formulaCount");
|
||||
eFormulaCount.innerText = Object.keys(formulas).length.toString();
|
||||
}
|
||||
|
||||
// Grabbing the templates for formulas and their variants
|
||||
console.debug("Grabbing the templates for formulas and their variants...");
|
||||
let eTemplateFormula = document.getElementById("template-formula-available");
|
||||
let eTemplateFormulaVariant = document.getElementById("template-formula-available-variant");
|
||||
if(eTemplateFormula === null || eTemplateFormulaVariant === null) {
|
||||
@@ -43,57 +125,50 @@ export function initCatalog() {
|
||||
throw Error("error.ui.catalog.noTemplate");
|
||||
}
|
||||
|
||||
// Adding the formulas and their variants to the page
|
||||
console.debug("Preparing each formula for later use...");
|
||||
Object.keys(formulas).forEach(formulaKey => {
|
||||
// Checking if the formula has one or more matching category container element.
|
||||
const hasValidCategory: boolean = formulas[formulaKey].categories.every(function(categoryId) {
|
||||
return Object.keys(eCategoryContainers).indexOf(categoryId) !== -1;
|
||||
});
|
||||
|
||||
if(hasValidCategory) {
|
||||
// Preparing the common element for the formula
|
||||
// Preparing the common element for the formula.
|
||||
let eNewFormula = (eTemplateFormula as HTMLTemplateElement).content.cloneNode(true) as HTMLElement;
|
||||
|
||||
let eNewFormulaTitle = eNewFormula.querySelector("p");
|
||||
if(eNewFormulaTitle !== null) {
|
||||
//eNewFormulaTitle.innerText = localize(formulas[formulaKey].name);
|
||||
eNewFormulaTitle.innerText = formulas[formulaKey].name;
|
||||
}
|
||||
|
||||
let eNewFormulaVariants = eNewFormula.querySelector("div.fw-variants");
|
||||
if(eNewFormulaVariants === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
}
|
||||
eNewFormulaVariants.innerHTML = "";
|
||||
let eNewVariantsContainers: HTMLElement[] = [];
|
||||
let eNewVariantsButtons: HTMLButtonElement[] = [];
|
||||
|
||||
formulas[formulaKey].variants.forEach(variant => {
|
||||
let eNewFormulaVariant = (eTemplateFormulaVariant as HTMLTemplateElement).content.cloneNode(true) as HTMLElement;
|
||||
let eNewFormulaVariantButton = eNewFormulaVariant.querySelector("button");
|
||||
if(eNewFormulaVariantButton === null) {
|
||||
alert("");
|
||||
throw Error("");
|
||||
alert("idk2");
|
||||
throw Error("idk2");
|
||||
}
|
||||
eNewFormulaVariantButton.innerHTML = variant.getMathMl(formulas[formulaKey]);
|
||||
eNewFormulaVariantButton.title = variant.description;
|
||||
|
||||
// FIXME: Add this back !
|
||||
//eNewFormulaVariantButton.onclick = function() {
|
||||
// WorkbenchFormulaUiElement.createNew(variant);
|
||||
//};
|
||||
|
||||
// @ts-ignore - "eNewFormulaVariants" cannot be null here !
|
||||
eNewFormulaVariants.appendChild(eNewFormulaVariant);
|
||||
eNewVariantsContainers.push(eNewFormulaVariant);
|
||||
eNewVariantsButtons.push(eNewFormulaVariantButton);
|
||||
});
|
||||
|
||||
// Adding it to any relevant category.
|
||||
formulas[formulaKey].categories.forEach(categoryKey => {
|
||||
if(Object.keys(eCategoryContainers).includes(categoryKey)) {
|
||||
// @ts-ignore - "eCategoryContainers[categoryKey]" cannot be null !
|
||||
eCategoryContainers[categoryKey].appendChild(eNewFormula);
|
||||
}
|
||||
});
|
||||
catalogFormulas.push(
|
||||
new CatalogFormula(
|
||||
formulas[formulaKey],
|
||||
formulas[formulaKey].categories
|
||||
.filter(categoryKey => Object.keys(eCategoryContainers).includes(categoryKey))
|
||||
.map(categoryKey => eCategoryContainers[categoryKey]),
|
||||
eNewFormula,
|
||||
eNewVariantsContainers,
|
||||
eNewVariantsButtons
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
IsCatalogInitialized = true;
|
||||
|
||||
console.debug(catalogFormulas);
|
||||
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
||||
|
@@ -1,197 +0,0 @@
|
||||
import { Decimal } from "../../../../resources/DecimalJs/10.4.3/decimal.min.mjs";
|
||||
import { localize } from "./lang.js";
|
||||
export class Unit {
|
||||
constructor(unitKey, symbol, scale) {
|
||||
this.name = localize("unit." + unitKey + ".name");
|
||||
this.symbol = symbol;
|
||||
this.scale = scale;
|
||||
this.description = localize("unit." + unitKey + ".desc");
|
||||
}
|
||||
}
|
||||
export const scales = {
|
||||
SI: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
IMPERIAL_DISTANCE: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
IMPERIAL_WEIGHT: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
TIME_SECONDS: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
NONE: new class {
|
||||
constructor() {
|
||||
this.formatName = (unit) => {
|
||||
return unit.name;
|
||||
};
|
||||
this.formatSymbol = (unit) => {
|
||||
return unit.symbol;
|
||||
};
|
||||
this.scaleFactors = [];
|
||||
}
|
||||
},
|
||||
};
|
||||
export const scaleFactors = {
|
||||
SI_GIGA: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e9');
|
||||
this.prefix = "giga";
|
||||
this.suffix = "";
|
||||
this.symbol = "G";
|
||||
}
|
||||
},
|
||||
SI_MEGA: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e6');
|
||||
this.prefix = "mega";
|
||||
this.suffix = "";
|
||||
this.symbol = "M";
|
||||
}
|
||||
},
|
||||
SI_KILO: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e3');
|
||||
this.prefix = "kilo";
|
||||
this.suffix = "";
|
||||
this.symbol = "k";
|
||||
}
|
||||
},
|
||||
SI_BASE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
SI_CENTI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e-2');
|
||||
this.prefix = "centi";
|
||||
this.suffix = "";
|
||||
this.symbol = "c";
|
||||
}
|
||||
},
|
||||
SI_MILLI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.SI;
|
||||
this.multiplier = new Decimal('1e-3');
|
||||
this.prefix = "milli";
|
||||
this.suffix = "";
|
||||
this.symbol = "m";
|
||||
}
|
||||
},
|
||||
TIME_MILLI: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('1e-3');
|
||||
this.prefix = "milli";
|
||||
this.suffix = "";
|
||||
this.symbol = "m";
|
||||
}
|
||||
},
|
||||
TIME_BASE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('1');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_MINUTE: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('60');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_HOUR: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('3600');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
TIME_DAY: new class {
|
||||
constructor() {
|
||||
this.scale = scales.TIME_SECONDS;
|
||||
this.multiplier = new Decimal('86400');
|
||||
this.prefix = "";
|
||||
this.suffix = "";
|
||||
this.symbol = "";
|
||||
}
|
||||
},
|
||||
};
|
||||
export const units = {
|
||||
ANY: new Unit("any", "", scales.NONE),
|
||||
WATT: new Unit("watt", "W", scales.SI),
|
||||
VOLT: new Unit("volt", "V", scales.SI),
|
||||
AMPERE: new Unit("ampere", "A", scales.SI),
|
||||
OHM: new Unit("ohm", "Ω", scales.SI),
|
||||
FARAD: new Unit("farad", "F", scales.SI),
|
||||
METER: new Unit("meter", "m", scales.SI),
|
||||
INCH: new Unit("inch", "in", scales.IMPERIAL_DISTANCE),
|
||||
POUND: new Unit("pound", "p", scales.IMPERIAL_WEIGHT),
|
||||
};
|
||||
export function scaleToBase(value, scaleFactor) {
|
||||
return value.times(scaleFactor.multiplier);
|
||||
}
|
||||
export function scaleFromBase(value, scaleFactor) {
|
||||
return value.dividedBy(scaleFactor.multiplier);
|
||||
}
|
||||
let areUnitsInitialized = false;
|
||||
export function initUnits() {
|
||||
if (!areUnitsInitialized) {
|
||||
console.debug("Initializing scales & units...");
|
||||
Object.keys(scaleFactors).forEach(scaleFactorKey => {
|
||||
const scaleFactor = scaleFactors[scaleFactorKey];
|
||||
scaleFactor.scale.scaleFactors.push(scaleFactor);
|
||||
});
|
||||
areUnitsInitialized = true;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=units.js.map
|
1
tools/items/formula-wizard/src/units.min.js
vendored
1
tools/items/formula-wizard/src/units.min.js
vendored
@@ -1 +0,0 @@
|
||||
import{Decimal as s}from"../../../../resources/DecimalJs/10.4.3/decimal.min.mjs";import{localize as t}from"./lang.js";export class Unit{constructor(s,i,e){this.name=t("unit."+s+".name"),this.symbol=i,this.scale=e,this.description=t("unit."+s+".desc")}}export const scales={SI:new class{constructor(){this.formatName=s=>s.symbol,this.formatSymbol=s=>s.symbol,this.scaleFactors=[]}},IMPERIAL_DISTANCE:new class{constructor(){this.formatName=s=>s.symbol,this.formatSymbol=s=>s.symbol,this.scaleFactors=[]}},IMPERIAL_WEIGHT:new class{constructor(){this.formatName=s=>s.symbol,this.formatSymbol=s=>s.symbol,this.scaleFactors=[]}},TIME_SECONDS:new class{constructor(){this.formatName=s=>s.symbol,this.formatSymbol=s=>s.symbol,this.scaleFactors=[]}},NONE:new class{constructor(){this.formatName=s=>s.name,this.formatSymbol=s=>s.symbol,this.scaleFactors=[]}}};export const scaleFactors={SI_GIGA:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1e9"),this.prefix="giga",this.suffix="",this.symbol="G"}},SI_MEGA:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1e6"),this.prefix="mega",this.suffix="",this.symbol="M"}},SI_KILO:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1e3"),this.prefix="kilo",this.suffix="",this.symbol="k"}},SI_BASE:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1"),this.prefix="",this.suffix="",this.symbol=""}},SI_CENTI:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1e-2"),this.prefix="centi",this.suffix="",this.symbol="c"}},SI_MILLI:new class{constructor(){this.scale=scales.SI,this.multiplier=new s("1e-3"),this.prefix="milli",this.suffix="",this.symbol="m"}},TIME_MILLI:new class{constructor(){this.scale=scales.TIME_SECONDS,this.multiplier=new s("1e-3"),this.prefix="milli",this.suffix="",this.symbol="m"}},TIME_BASE:new class{constructor(){this.scale=scales.TIME_SECONDS,this.multiplier=new s("1"),this.prefix="",this.suffix="",this.symbol=""}},TIME_MINUTE:new class{constructor(){this.scale=scales.TIME_SECONDS,this.multiplier=new s("60"),this.prefix="",this.suffix="",this.symbol=""}},TIME_HOUR:new class{constructor(){this.scale=scales.TIME_SECONDS,this.multiplier=new s("3600"),this.prefix="",this.suffix="",this.symbol=""}},TIME_DAY:new class{constructor(){this.scale=scales.TIME_SECONDS,this.multiplier=new s("86400"),this.prefix="",this.suffix="",this.symbol=""}}};export const units={ANY:new Unit("any","",scales.NONE),WATT:new Unit("watt","W",scales.SI),VOLT:new Unit("volt","V",scales.SI),AMPERE:new Unit("ampere","A",scales.SI),OHM:new Unit("ohm","Ω",scales.SI),FARAD:new Unit("farad","F",scales.SI),METER:new Unit("meter","m",scales.SI),INCH:new Unit("inch","in",scales.IMPERIAL_DISTANCE),POUND:new Unit("pound","p",scales.IMPERIAL_WEIGHT)};export function scaleToBase(s,t){return s.times(t.multiplier)}export function scaleFromBase(s,t){return s.dividedBy(t.multiplier)}let i=!1;export function initUnits(){i||(console.debug("Initializing scales & units..."),Object.keys(scaleFactors).forEach((s=>{const t=scaleFactors[s];t.scale.scaleFactors.push(t)})),i=!0)}
|
Reference in New Issue
Block a user