1&&(U=e(U,d,f),L=e(L,d,f),P=U.length,A=L.length),F=P,M=(y=L.slice(0,P)).length;M=f/2&&++S;do{d=0,(a=i(U,y,P,M))<0?(q=y[0],P!=M&&(q=q*f+(y[1]||0)),(d=q/S|0)>1?(d>=f&&(d=f-1),1==(a=i(w=e(U,d,f),y,v=w.length,M=y.length))&&(d--,r(w,P=10;d/=10)l++;N.e=l+h*p-1,Z(N,c?o+N.e+1:o,u,m);}return N}}();function Z(n,e,i,r){var t,s,o,u,f,a,h,l,d,g=n.constructor;n:if(null!=e){if(!(l=n.d))return n;for(t=1,u=l[0];u>=10;u/=10)t++;if((s=e-t)<0)s+=E,o=e,f=(h=l[d=0])/p(10,t-o-1)%10|0;else if((d=Math.ceil((s+1)/E))>=(u=l.length)){if(!r)break n;for(;u++<=d;)l.push(0);h=f=0,t=1,o=(s%=E)-E+1;}else {for(h=u=l[d],t=1;u>=10;u/=10)t++;f=(o=(s%=E)-E+t)<0?0:h/p(10,t-o-1)%10|0;}if(r=r||e<0||void 0!==l[d+1]||(o<0?h:h%p(10,t-o-1)),a=i<4?(f||r)&&(0==i||i==(n.s<0?3:2)):f>5||5==f&&(4==i||r||6==i&&(s>0?o>0?h/p(10,t-o):0:l[d-1])%10&1||i==(n.s<0?8:7)),e<1||!l[0])return l.length=0,a?(e-=n.e+1,l[0]=p(10,(E-e%E)%E),n.e=-e||0):l[0]=n.e=0,n;if(0==s?(l.length=d,u=1,d--):(l.length=d+1,u=p(10,E-s),l[d]=o>0?(h/p(10,t-o)%p(10,o)|0)*u:0),a)for(;;){if(0==d){for(s=1,o=l[0];o>=10;o/=10)s++;for(o=l[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,l[0]==b&&(l[0]=1));break}if(l[d]+=u,l[d]!=b)break;l[d--]=0,u=1;}for(s=l.length;0===l[--s];)l.pop();}return c&&(n.e>g.maxE?(n.d=null,n.e=NaN):n.e0?s=s.charAt(0)+"."+s.slice(1)+L(r):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):t<0?(s="0."+L(-t-1)+s,i&&(r=i-o)>0&&(s+=L(r))):t>=o?(s+=L(t+1-o),i&&(r=i-t-1)>0&&(s=s+"."+L(r))):((r=t+1)0&&(t+1===o&&(s+="."),s+=L(r))),s}function P(n,e){var i=n[0];for(e*=E;i>=10;i/=10)e++;return e}function R(n,e,i){if(e>x)throw c=!0,i&&(n.precision=i),Error(h);return Z(new n(s),e,1,!0)}function T(n,e,i){if(e>y)throw Error(h);return Z(new n(o),e,i,!0)}function _(n){var e=n.length-1,i=e*E+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++;}return i}function L(n){for(var e="";n--;)e+="0";return e}function U(n,e,i,r){var t,s=new n(1),o=Math.ceil(r/E+4);for(c=!1;;){if(i%2&&G((s=s.times(e)).d,o)&&(t=!0),0===(i=g(i/2))){i=s.d.length-1,t&&0===s.d[i]&&++s.d[i];break}G((e=e.times(e)).d,o);}return c=!0,s}function k(n){return 1&n.d[n.d.length-1]}function I(n,e,i){for(var r,t=new n(e[0]),s=0;++s17)return new d(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==e?(c=!1,f=m):f=e,u=new d(.03125);n.e>-2;)n=n.times(u),l+=5;for(f+=r=Math.log(p(2,l))/Math.LN10*2+5|0,i=s=o=new d(1),d.precision=f;;){if(s=Z(s.times(n),f,1),i=i.times(++h),q((u=o.plus(A(s,i,f,1))).d).slice(0,f)===q(o.d).slice(0,f)){for(t=l;t--;)o=Z(o.times(o),f,1);if(null!=e)return d.precision=m,o;if(!(a<3&&D(o.d,f-r,g,a)))return Z(o,d.precision=m,g,c=!0);d.precision=f+=10,i=s=u=new d(1),h=0,a++;}o=u;}}function H(n,e){var i,r,t,s,o,u,f,a,h,l,d,g=1,p=n,m=p.d,w=p.constructor,v=w.rounding,N=w.precision;if(p.s<0||!m||!m[0]||!p.e&&1==m[0]&&1==m.length)return new w(m&&!m[0]?-1/0:1!=p.s?NaN:m?0:p);if(null==e?(c=!1,h=N):h=e,w.precision=h+=10,r=(i=q(m)).charAt(0),!(Math.abs(s=p.e)<15e14))return a=R(w,h+2,N).times(s+""),p=H(new w(r+"."+i.slice(1)),h-10).plus(a),w.precision=N,null==e?Z(p,N,v,c=!0):p;for(;r<7&&1!=r||1==r&&i.charAt(1)>3;)r=(i=q((p=p.times(n)).d)).charAt(0),g++;for(s=p.e,r>1?(p=new w("0."+i),s++):p=new w(r+"."+i.slice(1)),l=p,f=o=p=A(p.minus(1),p.plus(1),h,1),d=Z(p.times(p),h,1),t=3;;){if(o=Z(o.times(d),h,1),q((a=f.plus(A(o,new w(t),h,1))).d).slice(0,h)===q(f.d).slice(0,h)){if(f=f.times(2),0!==s&&(f=f.plus(R(w,h+2,N).times(s+""))),f=A(f,new w(g),h,1),null!=e)return w.precision=N,f;if(!D(f.d,h-10,v,u))return Z(f,w.precision=N,v,c=!0);w.precision=h+=10,a=o=p=A(l.minus(1),l.plus(1),h,1),d=Z(p.times(p),h,1),t=u=1;}f=a,t+=2;}}function B(n){return String(n.s*n.s/0)}function V(n,e){var i,r,t;for((i=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(i<0&&(i=r),i+=+e.slice(r+1),e=e.substring(0,r)):i<0&&(i=e.length),r=0;48===e.charCodeAt(r);r++);for(t=e.length;48===e.charCodeAt(t-1);--t);if(e=e.slice(r,t)){if(t-=r,n.e=i=i-r-1,n.d=[],r=(i+1)%E,i<0&&(r+=E),rn.constructor.maxE?(n.d=null,n.e=NaN):n.e-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),N.test(e))return V(n,e)}else if("Infinity"===e||"NaN"===e)return +e||(n.s=NaN),n.e=NaN,n.d=null,n;if(w.test(e))i=16,e=e.toLowerCase();else if(m.test(e))i=2;else {if(!v.test(e))throw Error(a+e);i=8;}for((s=e.search(/p/i))>0?(f=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),o=(s=e.indexOf("."))>=0,r=n.constructor,o&&(s=(u=(e=e.replace(".","")).length)-s,t=U(r,new r(i),s,2*s)),s=l=(h=F(e,i,b)).length-1;0===h[s];--s)h.pop();return s<0?new r(0*n.s):(n.e=P(h,l),n.d=h,c=!1,o&&(n=A(n,t,4*u)),f&&(n=n.times(Math.abs(f)<54?p(2,f):Decimal.pow(2,f))),c=!0,n)}function j(n,e,i,r,t){var s,o,u,f,a=n.precision,h=Math.ceil(a/E);for(c=!1,f=i.times(i),u=new n(r);;){if(o=A(u.times(f),new n(e++*e++),a,1),u=t?r.plus(o):r.minus(o),r=A(o.times(f),new n(e++*e++),a,1),void 0!==(o=u.plus(r)).d[h]){for(s=h;o.d[s]===u.d[s]&&s--;);if(-1==s)break}s=u,u=r,r=o,o=s;}return c=!0,o.d.length=h+1,o}function W(n,e){for(var i=n;--e;)i*=n;return i}function J(n,i){var r,t=i.s<0,s=T(n,n.precision,1),o=s.times(.5);if((i=i.abs()).lte(o))return e=t?4:1,i;if((r=i.divToInt(s)).isZero())e=t?3:2;else {if((i=i.minus(r.times(s))).lte(o))return e=k(r)?t?2:3:t?4:1,i;e=k(r)?t?1:4:t?3:2;}return i.minus(s).abs()}function z(e,i,s,o){var u,c,f,a,h,l,d,g,p,m=e.constructor,w=void 0!==s;if(w?(O(s,1,r),void 0===o?o=m.rounding:O(o,0,8)):(s=m.precision,o=m.rounding),e.isFinite()){for(w?(u=2,16==i?s=4*s-3:8==i&&(s=3*s-2)):u=i,(f=(d=S(e)).indexOf("."))>=0&&(d=d.replace(".",""),(p=new m(1)).e=d.length-f,p.d=F(S(p),10,u),p.e=p.d.length),c=h=(g=F(d,10,u)).length;0==g[--h];)g.pop();if(g[0]){if(f<0?c--:((e=new m(e)).d=g,e.e=c,g=(e=A(e,p,s,o,0,u)).d,c=e.e,l=n),f=g[s],a=u/2,l=l||void 0!==g[s+1],l=o<4?(void 0!==f||l)&&(0===o||o===(e.s<0?3:2)):f>a||f===a&&(4===o||l||6===o&&1&g[s-1]||o===(e.s<0?8:7)),g.length=s,l)for(;++g[--s]>u-1;)g[s]=0,s||(++c,g.unshift(1));for(h=g.length;!g[h-1];--h);for(f=0,d="";f1)if(16==i||8==i){for(f=16==i?4:3,--h;h%f;h++)d+="0";for(h=(g=F(d,u,i)).length;!g[h-1];--h);for(f=1,d="1.";fh)for(c-=h;c--;)d+="0";else ce)return n.length=e,!0}function K(n){return new this(n).abs()}function Q(n){return new this(n).acos()}function X(n){return new this(n).acosh()}function Y(n,e){return new this(n).plus(e)}function nn(n){return new this(n).asin()}function en(n){return new this(n).asinh()}function rn(n){return new this(n).atan()}function tn(n){return new this(n).atanh()}function sn(n,e){n=new this(n),e=new this(e);var i,r=this.precision,t=this.rounding,s=r+4;return n.s&&e.s?n.d||e.d?!e.d||n.isZero()?(i=e.s<0?T(this,r,t):new this(0)).s=n.s:!n.d||e.isZero()?(i=T(this,s,1).times(.5)).s=n.s:e.s<0?(this.precision=s,this.rounding=1,i=this.atan(A(n,e,s,1)),e=T(this,s,1),this.precision=r,this.rounding=t,i=n.s<0?i.minus(e):i.plus(e)):i=this.atan(A(n,e,s,1)):(i=T(this,s,1).times(e.s>0?.25:.75)).s=n.s:i=new this(NaN),i}function on(n){return new this(n).cbrt()}function un(n){return Z(n=new this(n),n.e+1,2)}function cn(n,e,i){return new this(n).clamp(e,i)}function fn(n){if(!n||"object"!=typeof n)throw Error(f+"Object expected");var e,t,s,o=!0===n.defaults,c=["precision",1,r,"rounding",0,8,"toExpNeg",-i,0,"toExpPos",0,i,"maxE",0,i,"minE",-i,0,"modulo",0,9];for(e=0;e=c[e+1]&&s<=c[e+2]))throw Error(a+t+": "+s);this[t]=s;}if(t="crypto",o&&(this[t]=u[t]),void 0!==(s=n[t])){if(!0!==s&&!1!==s&&0!==s&&1!==s)throw Error(a+t+": "+s);if(s){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(l);this[t]=!0;}else this[t]=!1;}return this}function an(n){return new this(n).cos()}function hn(n){return new this(n).cosh()}function ln(n,e){return new this(n).div(e)}function dn(n){return new this(n).exp()}function gn(n){return Z(n=new this(n),n.e+1,3)}function pn(){var n,e,i=new this(0);for(c=!1,n=0;n=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:c[o++]=s%1e7;else {if(!crypto.randomBytes)throw Error(l);for(e=crypto.randomBytes(t*=4);o=214e7?crypto.randomBytes(4).copy(e,o):(c.push(s%1e7),o+=4);o=t/4;}else for(;o=10;s/=10)t++;ts.maxE?(t.e=NaN,t.d=null):n.e=10;i/=10)e++;return void(c?e>s.maxE?(t.e=NaN,t.d=null):e {
- 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 = "";
- }
- },
-};
-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),
-};
-function scaleToBase(value, scaleFactor) {
- return value.times(scaleFactor.multiplier);
-}
-function scaleFromBase(value, scaleFactor) {
- return value.dividedBy(scaleFactor.multiplier);
-}
-let areUnitsInitialized = false;
-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;
- }
-}
-
-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 "";
- };
- 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 "";
- };
- 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 "";
- };
- this.parentFormula = null;
- }
- },
- ], "ohm_law", ["electricity"], new URL("https://wikipedia.org/wiki/Ohm's_law")),
-};
-let areFormulasInitialized = false;
-function initFormulas() {
- if (!areFormulasInitialized) {
- console.debug("Initializing formulas...");
- Object.keys(formulas).forEach(formulaKey => {
- formulas[formulaKey].variants.forEach(formulaVariant => {
- formulaVariant.parentFormula = formulas[formulaKey];
- });
- });
- areFormulasInitialized = true;
- }
-}
-
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */
-const idCatalogPrefix = "fw-catalog-";
-const idCatalogCategoryPrefix = idCatalogPrefix + "category-";
-const idCatalogCategoryCount = idCatalogPrefix + "formula-count";
-const eCategoryContainers = {};
-let IsCatalogInitialized = false;
-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;
- }
-}
-
-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),
-};
-
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */
-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")),
-};
-const idContextComponentPrefix = "fw-context-component-";
-const idContextComponentTypes = idContextComponentPrefix + "type";
-const idContextComponentSets = idContextComponentPrefix + "set";
-const idContextComponentUnit = idContextComponentPrefix + "unit";
-const idContextComponentScale = idContextComponentPrefix + "scale";
-let eTemplateContextComponent = null;
-let eContextStatusMessage = null;
-let eContextAddButton = null;
-let isWorkbenchContextSetup = false;
-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"));
- }
- };
- isWorkbenchContextSetup = true;
- }
-}
-
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */
-const version = [0, 0, 2];
-console.log("Initializing 'Formula Wizard v" + version.join(".") + "'...");
-new Date().getMilliseconds();
-Decimal.set({ precision: 25, rounding: 8 });
-initUnits();
-initFormulas();
-initCatalog();
-setupWorkbenchContext();
-console.log(localize("joe.mama"));
-console.log(units);
-console.log(formulas);
-//# sourceMappingURL=formula-wizard.js.map
diff --git a/tools/items/formula-wizard/src/formula-wizard.min.js b/tools/items/formula-wizard/src/formula-wizard.min.js
deleted file mode 100644
index 7428737..0000000
--- a/tools/items/formula-wizard/src/formula-wizard.min.js
+++ /dev/null
@@ -1,31 +0,0 @@
-"use strict";
-/*!
- * decimal.js v10.4.3
- * An arbitrary-precision Decimal type for JavaScript.
- * https://github.com/MikeMcl/decimal.js
- * Copyright (c) 2022 Michael Mclaughlin
- * MIT Licence
- */var e,t,n=9e15,i=1e9,r="0123456789abcdef",s="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",o="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",u={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-n,maxE:n,crypto:!1},a=!0,c="[DecimalError] ",l=c+"Invalid argument: ",h=c+"Precision limit exceeded",f=c+"crypto unavailable",m="[object Decimal]",d=Math.floor,p=Math.pow,g=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,w=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,v=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,E=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,N=1e7,y=7,x=s.length-1,b=o.length-1,S={toStringTag:m};function I(e){var t,n,i,r=e.length-1,s="",o=e[0];if(r>0){for(s+=o,t=1;tn)throw Error(l+e)}function O(e,t,n,i){var r,s,o,u;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=y,r=0):(r=Math.ceil((t+1)/y),t%=y),s=p(10,y-t),u=e[r]%s|0,null==i?t<3?(0==t?u=u/100|0:1==t&&(u=u/10|0),o=n<4&&99999==u||n>3&&49999==u||5e4==u||0==u):o=(n<4&&u+1==s||n>3&&u+1==s/2)&&(e[r+1]/s/100|0)==p(10,t-2)-1||(u==s/2||0==u)&&0==(e[r+1]/s/100|0):t<4?(0==t?u=u/1e3|0:1==t?u=u/100|0:2==t&&(u=u/10|0),o=(i||n<4)&&9999==u||!i&&n>3&&4999==u):o=((i||n<4)&&u+1==s||!i&&n>3&&u+1==s/2)&&(e[r+1]/s/1e3|0)==p(10,t-3)-1,o}function A(e,t,n){for(var i,s,o=[0],u=0,a=e.length;un-1&&(void 0===o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/n|0,o[i]%=n)}return o.reverse()}S.absoluteValue=S.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),R(e)},S.ceil=function(){return R(new this.constructor(this),this.e+1,2)},S.clampedTo=S.clamp=function(e,t){var n=this,i=n.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(l+t);return n.cmp(e)<0?e:n.cmp(t)>0?t:new i(n)},S.comparedTo=S.cmp=function(e){var t,n,i,r,s=this,o=s.d,u=(e=new s.constructor(e)).d,a=s.s,c=e.s;if(!o||!u)return a&&c?a!==c?a:o===u?0:!o^a<0?1:-1:NaN;if(!o[0]||!u[0])return o[0]?a:u[0]?-c:0;if(a!==c)return a;if(s.e!==e.e)return s.e>e.e^a<0?1:-1;for(t=0,n=(i=o.length)<(r=u.length)?i:r;tu[t]^a<0?1:-1;return i===r?0:i>r^a<0?1:-1},S.cosine=S.cos=function(){var e,n,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,n=r.rounding,r.precision=e+Math.max(i.e,i.sd())+y,r.rounding=1,i=function(e,t){var n,i,r;if(t.isZero())return t;(i=t.d.length)<32?r=(1/G(4,n=Math.ceil(i/3))).toString():(n=16,r="2.3283064365386962890625e-10"),e.precision+=n,t=j(e,1,t.times(r),new e(1));for(var s=n;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}(r,W(r,i)),r.precision=e,r.rounding=n,R(2==t||3==t?i.neg():i,e,n,!0)):new r(1):new r(NaN)},S.cubeRoot=S.cbrt=function(){var e,t,n,i,r,s,o,u,c,l,h=this,f=h.constructor;if(!h.isFinite()||h.isZero())return new f(h);for(a=!1,(s=h.s*p(h.s*h,1/3))&&Math.abs(s)!=1/0?i=new f(s.toString()):(n=I(h.d),(s=((e=h.e)-n.length+1)%3)&&(n+=1==s||-2==s?"0":"00"),s=p(n,1/3),e=d((e+1)/3)-(e%3==(e<0?-1:2)),(i=new f(n=s==1/0?"5e"+e:(n=s.toExponential()).slice(0,n.indexOf("e")+1)+e)).s=h.s),o=(e=f.precision)+3;;)if(l=(c=(u=i).times(u).times(u)).plus(h),i=F(l.plus(h).times(u),l.plus(c),o+2,1),I(u.d).slice(0,o)===(n=I(i.d)).slice(0,o)){if("9999"!=(n=n.slice(o-3,o+1))&&(r||"4999"!=n)){+n&&(+n.slice(1)||"5"!=n.charAt(0))||(R(i,e+1,1),t=!i.times(i).times(i).eq(h));break}if(!r&&(R(u,e+1,0),u.times(u).times(u).eq(h))){i=u;break}o+=4,r=1}return a=!0,R(i,e,f.rounding,t)},S.decimalPlaces=S.dp=function(){var e,t=this.d,n=NaN;if(t){if(n=((e=t.length-1)-d(this.e/y))*y,e=t[e])for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},S.dividedBy=S.div=function(e){return F(this,new this.constructor(e))},S.dividedToIntegerBy=S.divToInt=function(e){var t=this.constructor;return R(F(this,new t(e),0,1,1),t.precision,t.rounding)},S.equals=S.eq=function(e){return 0===this.cmp(e)},S.floor=function(){return R(new this.constructor(this),this.e+1,3)},S.greaterThan=S.gt=function(e){return this.cmp(e)>0},S.greaterThanOrEqualTo=S.gte=function(e){var t=this.cmp(e);return 1==t||0===t},S.hyperbolicCosine=S.cosh=function(){var e,t,n,i,r,s=this,o=s.constructor,u=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return u;n=o.precision,i=o.rounding,o.precision=n+Math.max(s.e,s.sd())+4,o.rounding=1,(r=s.d.length)<32?t=(1/G(4,e=Math.ceil(r/3))).toString():(e=16,t="2.3283064365386962890625e-10"),s=j(o,1,s.times(t),new o(1),!0);for(var a,c=e,l=new o(8);c--;)a=s.times(s),s=u.minus(a.times(l.minus(a.times(l))));return R(s,o.precision=n,o.rounding=i,!0)},S.hyperbolicSine=S.sinh=function(){var e,t,n,i,r=this,s=r.constructor;if(!r.isFinite()||r.isZero())return new s(r);if(t=s.precision,n=s.rounding,s.precision=t+Math.max(r.e,r.sd())+4,s.rounding=1,(i=r.d.length)<3)r=j(s,2,r,r,!0);else{e=(e=1.4*Math.sqrt(i))>16?16:0|e,r=j(s,2,r=r.times(1/G(5,e)),r,!0);for(var o,u=new s(5),a=new s(16),c=new s(20);e--;)o=r.times(r),r=r.times(u.plus(o.times(a.times(o).plus(c))))}return s.precision=t,s.rounding=n,R(r,t,n,!0)},S.hyperbolicTangent=S.tanh=function(){var e,t,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+7,i.rounding=1,F(n.sinh(),n.cosh(),i.precision=e,i.rounding=t)):new i(n.s)},S.inverseCosine=S.acos=function(){var e,t=this,n=t.constructor,i=t.abs().cmp(1),r=n.precision,s=n.rounding;return-1!==i?0===i?t.isNeg()?V(n,r,s):new n(0):new n(NaN):t.isZero()?V(n,r+4,s).times(.5):(n.precision=r+6,n.rounding=1,t=t.asin(),e=V(n,r+4,s).times(.5),n.precision=r,n.rounding=s,e.minus(t))},S.inverseHyperbolicCosine=S.acosh=function(){var e,t,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(e=i.precision,t=i.rounding,i.precision=e+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,a=!1,n=n.times(n).minus(1).sqrt().plus(n),a=!0,i.precision=e,i.rounding=t,n.ln()):new i(n)},S.inverseHyperbolicSine=S.asinh=function(){var e,t,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(e=i.precision,t=i.rounding,i.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,a=!1,n=n.times(n).plus(1).sqrt().plus(n),a=!0,i.precision=e,i.rounding=t,n.ln())},S.inverseHyperbolicTangent=S.atanh=function(){var e,t,n,i,r=this,s=r.constructor;return r.isFinite()?r.e>=0?new s(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(e=s.precision,t=s.rounding,i=r.sd(),Math.max(i,e)<2*-r.e-1?R(new s(r),e,t,!0):(s.precision=n=i-r.e,r=F(r.plus(1),new s(1).minus(r),n+e,1),s.precision=e+4,s.rounding=1,r=r.ln(),s.precision=e,s.rounding=t,r.times(.5))):new s(NaN)},S.inverseSine=S.asin=function(){var e,t,n,i,r=this,s=r.constructor;return r.isZero()?new s(r):(t=r.abs().cmp(1),n=s.precision,i=s.rounding,-1!==t?0===t?((e=V(s,n+4,i).times(.5)).s=r.s,e):new s(NaN):(s.precision=n+6,s.rounding=1,r=r.div(new s(1).minus(r.times(r)).sqrt().plus(1)).atan(),s.precision=n,s.rounding=i,r.times(2)))},S.inverseTangent=S.atan=function(){var e,t,n,i,r,s,o,u,c,l=this,h=l.constructor,f=h.precision,m=h.rounding;if(l.isFinite()){if(l.isZero())return new h(l);if(l.abs().eq(1)&&f+4<=b)return(o=V(h,f+4,m).times(.25)).s=l.s,o}else{if(!l.s)return new h(NaN);if(f+4<=b)return(o=V(h,f+4,m).times(.5)).s=l.s,o}for(h.precision=u=f+10,h.rounding=1,e=n=Math.min(28,u/y+2|0);e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(a=!1,t=Math.ceil(u/y),i=1,c=l.times(l),o=new h(l),r=l;-1!==e;)if(r=r.times(c),s=o.minus(r.div(i+=2)),r=r.times(c),void 0!==(o=s.plus(r.div(i+=2))).d[t])for(e=t;o.d[e]===s.d[e]&&e--;);return n&&(o=o.times(2<this.d.length-2},S.isNaN=function(){return!this.s},S.isNegative=S.isNeg=function(){return this.s<0},S.isPositive=S.isPos=function(){return this.s>0},S.isZero=function(){return!!this.d&&0===this.d[0]},S.lessThan=S.lt=function(e){return this.cmp(e)<0},S.lessThanOrEqualTo=S.lte=function(e){return this.cmp(e)<1},S.logarithm=S.log=function(e){var t,n,i,r,s,o,u,c,l=this,h=l.constructor,f=h.precision,m=h.rounding;if(null==e)e=new h(10),t=!0;else{if(n=(e=new h(e)).d,e.s<0||!n||!n[0]||e.eq(1))return new h(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new h(n&&!n[0]?-1/0:1!=l.s?NaN:n?0:1/0);if(t)if(n.length>1)s=!0;else{for(r=n[0];r%10==0;)r/=10;s=1!==r}if(a=!1,o=H(l,u=f+5),i=t?C(h,u+10):H(e,u),O((c=F(o,i,u,1)).d,r=f,m))do{if(o=H(l,u+=10),i=t?C(h,u+10):H(e,u),c=F(o,i,u,1),!s){+I(c.d).slice(r+1,r+15)+1==1e14&&(c=R(c,f+1,0));break}}while(O(c.d,r+=10,m));return a=!0,R(c,f,m)},S.minus=S.sub=function(e){var t,n,i,r,s,o,u,c,l,h,f,m,p=this,g=p.constructor;if(e=new g(e),!p.d||!e.d)return p.s&&e.s?p.d?e.s=-e.s:e=new g(e.d||p.s!==e.s?p:NaN):e=new g(NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,m=e.d,u=g.precision,c=g.rounding,!l[0]||!m[0]){if(m[0])e.s=-e.s;else{if(!l[0])return new g(3===c?-0:0);e=new g(p)}return a?R(e,u,c):e}if(n=d(e.e/y),h=d(p.e/y),l=l.slice(),s=h-n){for((f=s<0)?(t=l,s=-s,o=m.length):(t=m,n=h,o=l.length),s>(i=Math.max(Math.ceil(u/y),o)+2)&&(s=i,t.length=1),t.reverse(),i=s;i--;)t.push(0);t.reverse()}else{for((f=(i=l.length)<(o=m.length))&&(o=i),i=0;i0;--i)l[o++]=0;for(i=m.length;i>s;){if(l[--i](o=(s=Math.ceil(u/y))>o?s+1:o+1)&&(r=o,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for((o=l.length)-(r=h.length)<0&&(r=o,n=h,h=l,l=n),t=0;r;)t=(l[--r]=l[r]+h[r]+t)/N|0,l[r]%=N;for(t&&(l.unshift(t),++i),o=l.length;0==l[--o];)l.pop();return e.d=l,e.e=_(l,i),a?R(e,u,c):e},S.precision=S.sd=function(e){var t,n=this;if(void 0!==e&&e!==!!e&&1!==e&&0!==e)throw Error(l+e);return n.d?(t=D(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},S.round=function(){var e=this,t=e.constructor;return R(new t(e),e.e+1,t.rounding)},S.sine=S.sin=function(){var e,n,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,n=r.rounding,r.precision=e+Math.max(i.e,i.sd())+y,r.rounding=1,i=function(e,t){var n,i=t.d.length;if(i<3)return t.isZero()?t:j(e,2,t,t);n=(n=1.4*Math.sqrt(i))>16?16:0|n,t=j(e,2,t=t.times(1/G(5,n)),t);for(var r,s=new e(5),o=new e(16),u=new e(20);n--;)r=t.times(t),t=t.times(s.plus(r.times(o.times(r).minus(u))));return t}(r,W(r,i)),r.precision=e,r.rounding=n,R(t>2?i.neg():i,e,n,!0)):new r(NaN)},S.squareRoot=S.sqrt=function(){var e,t,n,i,r,s,o=this,u=o.d,c=o.e,l=o.s,h=o.constructor;if(1!==l||!u||!u[0])return new h(!l||l<0&&(!u||u[0])?NaN:u?o:1/0);for(a=!1,0==(l=Math.sqrt(+o))||l==1/0?(((t=I(u)).length+c)%2==0&&(t+="0"),l=Math.sqrt(t),c=d((c+1)/2)-(c<0||c%2),i=new h(t=l==1/0?"5e"+c:(t=l.toExponential()).slice(0,t.indexOf("e")+1)+c)):i=new h(l.toString()),n=(c=h.precision)+3;;)if(i=(s=i).plus(F(o,s,n+2,1)).times(.5),I(s.d).slice(0,n)===(t=I(i.d)).slice(0,n)){if("9999"!=(t=t.slice(n-3,n+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(R(i,c+1,1),e=!i.times(i).eq(o));break}if(!r&&(R(s,c+1,0),s.times(s).eq(o))){i=s;break}n+=4,r=1}return a=!0,R(i,c,h.rounding,e)},S.tangent=S.tan=function(){var e,n,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,n=r.rounding,r.precision=e+10,r.rounding=1,(i=i.sin()).s=1,i=F(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=n,R(2==t||4==t?i.neg():i,e,n,!0)):new r(NaN)},S.times=S.mul=function(e){var t,n,i,r,s,o,u,c,l,h=this,f=h.constructor,m=h.d,p=(e=new f(e)).d;if(e.s*=h.s,!(m&&m[0]&&p&&p[0]))return new f(!e.s||m&&!m[0]&&!p||p&&!p[0]&&!m?NaN:m&&p?0*e.s:e.s/0);for(n=d(h.e/y)+d(e.e/y),(c=m.length)<(l=p.length)&&(s=m,m=p,p=s,o=c,c=l,l=o),s=[],i=o=c+l;i--;)s.push(0);for(i=l;--i>=0;){for(t=0,r=c+i;r>i;)u=s[r]+p[i]*m[r-i-1]+t,s[r--]=u%N|0,t=u/N|0;s[r]=(s[r]+t)%N|0}for(;!s[--o];)s.pop();return t?++n:s.shift(),e.d=s,e.e=_(s,n),a?R(e,f.precision,f.rounding):e},S.toBinary=function(e,t){return $(this,2,e,t)},S.toDecimalPlaces=S.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),void 0===e?n:(M(e,0,i),void 0===t?t=r.rounding:M(t,0,8),R(n,e+n.e+1,t))},S.toExponential=function(e,t){var n,r=this,s=r.constructor;return void 0===e?n=T(r,!0):(M(e,0,i),void 0===t?t=s.rounding:M(t,0,8),n=T(r=R(new s(r),e+1,t),!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n},S.toFixed=function(e,t){var n,r,s=this,o=s.constructor;return void 0===e?n=T(s):(M(e,0,i),void 0===t?t=o.rounding:M(t,0,8),n=T(r=R(new o(s),e+s.e+1,t),!1,e+r.e+1)),s.isNeg()&&!s.isZero()?"-"+n:n},S.toFraction=function(e){var t,n,i,r,s,o,u,c,h,f,m,d,g=this,w=g.d,v=g.constructor;if(!w)return new v(g);if(h=n=new v(1),i=c=new v(0),o=(s=(t=new v(i)).e=D(w)-g.e-1)%y,t.d[0]=p(10,o<0?y+o:o),null==e)e=s>0?t:h;else{if(!(u=new v(e)).isInt()||u.lt(h))throw Error(l+u);e=u.gt(t)?s>0?t:h:u}for(a=!1,u=new v(I(w)),f=v.precision,v.precision=s=w.length*y*2;m=F(u,t,0,1,1),1!=(r=n.plus(m.times(i))).cmp(e);)n=i,i=r,r=h,h=c.plus(m.times(r)),c=r,r=t,t=u.minus(m.times(r)),u=r;return r=F(e.minus(n),i,0,1,1),c=c.plus(r.times(h)),n=n.plus(r.times(i)),c.s=h.s=g.s,d=F(h,i,s,1).minus(g).abs().cmp(F(c,n,s,1).minus(g).abs())<1?[h,i]:[c,n],v.precision=f,a=!0,d},S.toHexadecimal=S.toHex=function(e,t){return $(this,16,e,t)},S.toNearest=function(e,t){var n=this,i=n.constructor;if(n=new i(n),null==e){if(!n.d)return n;e=new i(1),t=i.rounding}else{if(e=new i(e),void 0===t?t=i.rounding:M(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(a=!1,n=F(n,e,0,t,1).times(e),a=!0,R(n)):(e.s=n.s,n=e),n},S.toNumber=function(){return+this},S.toOctal=function(e,t){return $(this,8,e,t)},S.toPower=S.pow=function(e){var t,n,i,r,s,o,u=this,c=u.constructor,l=+(e=new c(e));if(!(u.d&&e.d&&u.d[0]&&e.d[0]))return new c(p(+u,l));if((u=new c(u)).eq(1))return u;if(i=c.precision,s=c.rounding,e.eq(1))return R(u,i,s);if((t=d(e.e/y))>=e.d.length-1&&(n=l<0?-l:l)<=9007199254740991)return r=L(c,u,n,i),e.s<0?new c(1).div(r):R(r,i,s);if((o=u.s)<0){if(tc.maxE+1||t0?o/0:0):(a=!1,c.rounding=u.s=1,n=Math.min(12,(t+"").length),(r=P(e.times(H(u,i+n)),i)).d&&O((r=R(r,i+5,1)).d,i,s)&&(t=i+10,+I((r=R(P(e.times(H(u,t+n)),t),t+5,1)).d).slice(i+1,i+15)+1==1e14&&(r=R(r,i+1,0))),r.s=o,a=!0,c.rounding=s,R(r,i,s))},S.toPrecision=function(e,t){var n,r=this,s=r.constructor;return void 0===e?n=T(r,r.e<=s.toExpNeg||r.e>=s.toExpPos):(M(e,1,i),void 0===t?t=s.rounding:M(t,0,8),n=T(r=R(new s(r),e,t),e<=r.e||r.e<=s.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n},S.toSignificantDigits=S.toSD=function(e,t){var n=this.constructor;return void 0===e?(e=n.precision,t=n.rounding):(M(e,1,i),void 0===t?t=n.rounding:M(t,0,8)),R(new n(this),e,t)},S.toString=function(){var e=this,t=e.constructor,n=T(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n},S.truncated=S.trunc=function(){return R(new this.constructor(this),this.e+1,1)},S.valueOf=S.toJSON=function(){var e=this,t=e.constructor,n=T(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};var F=function(){function t(e,t,n){var i,r=0,s=e.length;for(e=e.slice();s--;)i=e[s]*t+r,e[s]=i%n|0,r=i/n|0;return r&&e.unshift(r),e}function n(e,t,n,i){var r,s;if(n!=i)s=n>i?1:-1;else for(r=s=0;rt[r]?1:-1;break}return s}function i(e,t,n,i){for(var r=0;n--;)e[n]-=r,r=e[n]1;)e.shift()}return function(r,s,o,u,a,c){var l,h,f,m,p,g,w,v,E,x,b,S,I,M,O,A,F,T,_,C,V=r.constructor,D=r.s==s.s?1:-1,q=r.d,L=s.d;if(!(q&&q[0]&&L&&L[0]))return new V(r.s&&s.s&&(q?!L||q[0]!=L[0]:L)?q&&0==q[0]||!L?0*D:D/0:NaN);for(c?(p=1,h=r.e-s.e):(c=N,p=y,h=d(r.e/p)-d(s.e/p)),_=L.length,F=q.length,x=(E=new V(D)).d=[],f=0;L[f]==(q[f]||0);f++);if(L[f]>(q[f]||0)&&h--,null==o?(M=o=V.precision,u=V.rounding):M=a?o+(r.e-s.e)+1:o,M<0)x.push(1),g=!0;else{if(M=M/p+2|0,f=0,1==_){for(m=0,L=L[0],M++;(f1&&(L=t(L,m,c),q=t(q,m,c),_=L.length,F=q.length),A=_,S=(b=q.slice(0,_)).length;S<_;)b[S++]=0;(C=L.slice()).unshift(0),T=L[0],L[1]>=c/2&&++T;do{m=0,(l=n(L,b,_,S))<0?(I=b[0],_!=S&&(I=I*c+(b[1]||0)),(m=I/T|0)>1?(m>=c&&(m=c-1),1==(l=n(w=t(L,m,c),b,v=w.length,S=b.length))&&(m--,i(w,_=10;m/=10)f++;E.e=f+h*p-1,R(E,a?o+E.e+1:o,u,g)}return E}}();function R(e,t,n,i){var r,s,o,u,c,l,h,f,m,d=e.constructor;e:if(null!=t){if(!(f=e.d))return e;for(r=1,u=f[0];u>=10;u/=10)r++;if((s=t-r)<0)s+=y,o=t,c=(h=f[m=0])/p(10,r-o-1)%10|0;else if((m=Math.ceil((s+1)/y))>=(u=f.length)){if(!i)break e;for(;u++<=m;)f.push(0);h=c=0,r=1,o=(s%=y)-y+1}else{for(h=u=f[m],r=1;u>=10;u/=10)r++;c=(o=(s%=y)-y+r)<0?0:h/p(10,r-o-1)%10|0}if(i=i||t<0||void 0!==f[m+1]||(o<0?h:h%p(10,r-o-1)),l=n<4?(c||i)&&(0==n||n==(e.s<0?3:2)):c>5||5==c&&(4==n||i||6==n&&(s>0?o>0?h/p(10,r-o):0:f[m-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,l?(t-=e.e+1,f[0]=p(10,(y-t%y)%y),e.e=-t||0):f[0]=e.e=0,e;if(0==s?(f.length=m,u=1,m--):(f.length=m+1,u=p(10,y-s),f[m]=o>0?(h/p(10,r-o)%p(10,o)|0)*u:0),l)for(;;){if(0==m){for(s=1,o=f[0];o>=10;o/=10)s++;for(o=f[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(e.e++,f[0]==N&&(f[0]=1));break}if(f[m]+=u,f[m]!=N)break;f[m--]=0,u=1}for(s=f.length;0===f[--s];)f.pop()}return a&&(e.e>d.maxE?(e.d=null,e.e=NaN):e.e0?s=s.charAt(0)+"."+s.slice(1)+q(i):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):r<0?(s="0."+q(-r-1)+s,n&&(i=n-o)>0&&(s+=q(i))):r>=o?(s+=q(r+1-o),n&&(i=n-r-1)>0&&(s=s+"."+q(i))):((i=r+1)0&&(r+1===o&&(s+="."),s+=q(i))),s}function _(e,t){var n=e[0];for(t*=y;n>=10;n/=10)t++;return t}function C(e,t,n){if(t>x)throw a=!0,n&&(e.precision=n),Error(h);return R(new e(s),t,1,!0)}function V(e,t,n){if(t>b)throw Error(h);return R(new e(o),t,n,!0)}function D(e){var t=e.length-1,n=t*y+1;if(t=e[t]){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function q(e){for(var t="";e--;)t+="0";return t}function L(e,t,n,i){var r,s=new e(1),o=Math.ceil(i/y+4);for(a=!1;;){if(n%2&&z((s=s.times(t)).d,o)&&(r=!0),0===(n=d(n/2))){n=s.d.length-1,r&&0===s.d[n]&&++s.d[n];break}z((t=t.times(t)).d,o)}return a=!0,s}function B(e){return 1&e.d[e.d.length-1]}function k(e,t,n){for(var i,r=new e(t[0]),s=0;++s17)return new m(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(null==t?(a=!1,c=g):c=t,u=new m(.03125);e.e>-2;)e=e.times(u),f+=5;for(c+=i=Math.log(p(2,f))/Math.LN10*2+5|0,n=s=o=new m(1),m.precision=c;;){if(s=R(s.times(e),c,1),n=n.times(++h),I((u=o.plus(F(s,n,c,1))).d).slice(0,c)===I(o.d).slice(0,c)){for(r=f;r--;)o=R(o.times(o),c,1);if(null!=t)return m.precision=g,o;if(!(l<3&&O(o.d,c-i,d,l)))return R(o,m.precision=g,d,a=!0);m.precision=c+=10,n=s=u=new m(1),h=0,l++}o=u}}function H(e,t){var n,i,r,s,o,u,c,l,h,f,m,d=1,p=e,g=p.d,w=p.constructor,v=w.rounding,E=w.precision;if(p.s<0||!g||!g[0]||!p.e&&1==g[0]&&1==g.length)return new w(g&&!g[0]?-1/0:1!=p.s?NaN:g?0:p);if(null==t?(a=!1,h=E):h=t,w.precision=h+=10,i=(n=I(g)).charAt(0),!(Math.abs(s=p.e)<15e14))return l=C(w,h+2,E).times(s+""),p=H(new w(i+"."+n.slice(1)),h-10).plus(l),w.precision=E,null==t?R(p,E,v,a=!0):p;for(;i<7&&1!=i||1==i&&n.charAt(1)>3;)i=(n=I((p=p.times(e)).d)).charAt(0),d++;for(s=p.e,i>1?(p=new w("0."+n),s++):p=new w(i+"."+n.slice(1)),f=p,c=o=p=F(p.minus(1),p.plus(1),h,1),m=R(p.times(p),h,1),r=3;;){if(o=R(o.times(m),h,1),I((l=c.plus(F(o,new w(r),h,1))).d).slice(0,h)===I(c.d).slice(0,h)){if(c=c.times(2),0!==s&&(c=c.plus(C(w,h+2,E).times(s+""))),c=F(c,new w(d),h,1),null!=t)return w.precision=E,c;if(!O(c.d,h-10,v,u))return R(c,w.precision=E,v,a=!0);w.precision=h+=10,l=o=p=F(f.minus(1),f.plus(1),h,1),m=R(p.times(p),h,1),r=u=1}c=l,r+=2}}function U(e){return String(e.s*e.s/0)}function Z(e,t){var n,i,r;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(n<0&&(n=i),n+=+t.slice(i+1),t=t.substring(0,i)):n<0&&(n=t.length),i=0;48===t.charCodeAt(i);i++);for(r=t.length;48===t.charCodeAt(r-1);--r);if(t=t.slice(i,r)){if(r-=i,e.e=n=n-i-1,e.d=[],i=(n+1)%y,n<0&&(i+=y),ie.constructor.maxE?(e.d=null,e.e=NaN):e.e=0&&(m=m.replace(".",""),(p=new g(1)).e=m.length-c,p.d=A(T(p),10,u),p.e=p.d.length),a=h=(d=A(m,10,u)).length;0==d[--h];)d.pop();if(d[0]){if(c<0?a--:((t=new g(t)).d=d,t.e=a,d=(t=F(t,p,s,o,0,u)).d,a=t.e,f=e),c=d[s],l=u/2,f=f||void 0!==d[s+1],f=o<4?(void 0!==c||f)&&(0===o||o===(t.s<0?3:2)):c>l||c===l&&(4===o||f||6===o&&1&d[s-1]||o===(t.s<0?8:7)),d.length=s,f)for(;++d[--s]>u-1;)d[s]=0,s||(++a,d.unshift(1));for(h=d.length;!d[h-1];--h);for(c=0,m="";c1)if(16==n||8==n){for(c=16==n?4:3,--h;h%c;h++)m+="0";for(h=(d=A(m,u,n)).length;!d[h-1];--h);for(c=1,m="1.";ch)for(a-=h;a--;)m+="0";else at)return e.length=t,!0}function K(e){return new this(e).abs()}function Y(e){return new this(e).acos()}function J(e){return new this(e).acosh()}function Q(e,t){return new this(e).plus(t)}function X(e){return new this(e).asin()}function ee(e){return new this(e).asinh()}function te(e){return new this(e).atan()}function ne(e){return new this(e).atanh()}function ie(e,t){e=new this(e),t=new this(t);var n,i=this.precision,r=this.rounding,s=i+4;return e.s&&t.s?e.d||t.d?!t.d||e.isZero()?(n=t.s<0?V(this,i,r):new this(0)).s=e.s:!e.d||t.isZero()?(n=V(this,s,1).times(.5)).s=e.s:t.s<0?(this.precision=s,this.rounding=1,n=this.atan(F(e,t,s,1)),t=V(this,s,1),this.precision=i,this.rounding=r,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(F(e,t,s,1)):(n=V(this,s,1).times(t.s>0?.25:.75)).s=e.s:n=new this(NaN),n}function re(e){return new this(e).cbrt()}function se(e){return R(e=new this(e),e.e+1,2)}function oe(e,t,n){return new this(e).clamp(t,n)}function ue(e){if(!e||"object"!=typeof e)throw Error(c+"Object expected");var t,r,s,o=!0===e.defaults,a=["precision",1,i,"rounding",0,8,"toExpNeg",-n,0,"toExpPos",0,n,"maxE",0,n,"minE",-n,0,"modulo",0,9];for(t=0;t=a[t+1]&&s<=a[t+2]))throw Error(l+r+": "+s);this[r]=s}if(r="crypto",o&&(this[r]=u[r]),void 0!==(s=e[r])){if(!0!==s&&!1!==s&&0!==s&&1!==s)throw Error(l+r+": "+s);if(s){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(f);this[r]=!0}else this[r]=!1}return this}function ae(e){return new this(e).cos()}function ce(e){return new this(e).cosh()}function le(e,t){return new this(e).div(t)}function he(e){return new this(e).exp()}function fe(e){return R(e=new this(e),e.e+1,3)}function me(){var e,t,n=new this(0);for(a=!1,e=0;e=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=s%1e7;else{if(!crypto.randomBytes)throw Error(f);for(t=crypto.randomBytes(r*=4);o=214e7?crypto.randomBytes(4).copy(t,o):(a.push(s%1e7),o+=4);o=r/4}else for(;o=10;s/=10)r++;rs.maxE?(r.e=NaN,r.d=null):e.e=10;n/=10)t++;return void(a?t>s.maxE?(r.e=NaN,r.d=null):t-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),E.test(t))return Z(e,t)}else if("Infinity"===t||"NaN"===t)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(w.test(t))n=16,t=t.toLowerCase();else if(g.test(t))n=2;else{if(!v.test(t))throw Error(l+t);n=8}for((s=t.search(/p/i))>0?(c=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),o=(s=t.indexOf("."))>=0,i=e.constructor,o&&(s=(u=(t=t.replace(".","")).length)-s,r=L(i,new i(n),s,2*s)),s=f=(h=A(t,n,N)).length-1;0===h[s];--s)h.pop();return s<0?new i(0*e.s):(e.e=_(h,f),e.d=h,a=!1,o&&(e=F(e,r,4*u)),c&&(e=e.times(Math.abs(c)<54?p(2,c):De.pow(2,c))),a=!0,e)}(r,e)}if(s.prototype=S,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=ue,s.clone=e,s.isDecimal=de,s.abs=K,s.acos=Y,s.acosh=J,s.add=Q,s.asin=X,s.asinh=ee,s.atan=te,s.atanh=ne,s.atan2=ie,s.cbrt=re,s.ceil=se,s.clamp=oe,s.cos=ae,s.cosh=ce,s.div=le,s.exp=he,s.floor=fe,s.hypot=me,s.ln=pe,s.log=ge,s.log10=ve,s.log2=we,s.max=Ee,s.min=Ne,s.mod=ye,s.mul=xe,s.pow=be,s.random=Se,s.round=Ie,s.sign=Me,s.sin=Oe,s.sinh=Ae,s.sqrt=Fe,s.sub=Re,s.sum=Te,s.tan=_e,s.tanh=Ce,s.trunc=Ve,void 0===t&&(t={}),t&&!0!==t.defaults)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;ne.symbol,this.formatSymbol=e=>e.symbol,this.scaleFactors=[]}},IMPERIAL_DISTANCE:new class{constructor(){this.formatName=e=>e.symbol,this.formatSymbol=e=>e.symbol,this.scaleFactors=[]}},IMPERIAL_WEIGHT:new class{constructor(){this.formatName=e=>e.symbol,this.formatSymbol=e=>e.symbol,this.scaleFactors=[]}},TIME_SECONDS:new class{constructor(){this.formatName=e=>e.symbol,this.formatSymbol=e=>e.symbol,this.scaleFactors=[]}},NONE:new class{constructor(){this.formatName=e=>e.name,this.formatSymbol=e=>e.symbol,this.scaleFactors=[]}}},He={SI_GIGA:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1e9"),this.prefix="giga",this.suffix="",this.symbol="G"}},SI_MEGA:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1e6"),this.prefix="mega",this.suffix="",this.symbol="M"}},SI_KILO:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1e3"),this.prefix="kilo",this.suffix="",this.symbol="k"}},SI_BASE:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1"),this.prefix="",this.suffix="",this.symbol=""}},SI_CENTI:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1e-2"),this.prefix="centi",this.suffix="",this.symbol="c"}},SI_MILLI:new class{constructor(){this.scale=Pe.SI,this.multiplier=new De("1e-3"),this.prefix="milli",this.suffix="",this.symbol="m"}},TIME_MILLI:new class{constructor(){this.scale=Pe.TIME_SECONDS,this.multiplier=new De("1e-3"),this.prefix="milli",this.suffix="",this.symbol="m"}},TIME_BASE:new class{constructor(){this.scale=Pe.TIME_SECONDS,this.multiplier=new De("1"),this.prefix="",this.suffix="",this.symbol=""}},TIME_MINUTE:new class{constructor(){this.scale=Pe.TIME_SECONDS,this.multiplier=new De("60"),this.prefix="",this.suffix="",this.symbol=""}},TIME_HOUR:new class{constructor(){this.scale=Pe.TIME_SECONDS,this.multiplier=new De("3600"),this.prefix="",this.suffix="",this.symbol=""}},TIME_DAY:new class{constructor(){this.scale=Pe.TIME_SECONDS,this.multiplier=new De("86400"),this.prefix="",this.suffix="",this.symbol=""}}},Ue={ANY:new ke("any","",Pe.NONE),WATT:new ke("watt","W",Pe.SI),VOLT:new ke("volt","V",Pe.SI),AMPERE:new ke("ampere","A",Pe.SI),OHM:new ke("ohm","Ω",Pe.SI),FARAD:new ke("farad","F",Pe.SI),METER:new ke("meter","m",Pe.SI),INCH:new ke("inch","in",Pe.IMPERIAL_DISTANCE),POUND:new ke("pound","p",Pe.IMPERIAL_WEIGHT)};let Ze=!1;class je{constructor(e){this.contextValueIndex=e}getContextValue(e){if(e.length<=this.contextValueIndex)throw alert(Be("error.formulaContext.tooSmall")),new Error(Be("error.formulaContext.tooSmall"));return e[this.contextValueIndex]}}class Ge{constructor(e,t){this.unit=e,this.scaleFactor=t,this.parentFormula=null,this.valueSource=null}getFormulaValue(e){if(null===this.parentFormula)throw alert(Be("error.formulaValue.noParent")),new Error(Be("error.formulaValue.noParent"));if(null===this.valueSource)throw alert(Be("error.formulaValue.noSource")),new Error(Be("error.formulaValue.noSource"));return this.valueSource instanceof je?this.valueSource.getContextValue(e):function(e,t){return e.dividedBy(t.multiplier)}((t=this.valueSource.getVariantValue(this.parentFormula,e),n=this.valueSource.getOutputValueDefinition().scaleFactor,t.times(n.multiplier)),this.scaleFactor);var t,n}}class We{constructor(e,t,n,i,r){this.values=e,this.variants=t,this.formulaKey=n,this.name=Be("formula."+n+".name"),this.description=Be("formula."+n+".desc"),this.categories=i,this.wikiLink=r,this.values.forEach((e=>{e.parentFormula=this}))}getClone(){const e=[];return this.values.forEach((t=>{e.push(new Ge(t.unit,t.scaleFactor))})),new We(e,this.variants,this.formulaKey,this.categories,this.wikiLink)}}const $e={OHM_LAW:new We([new Ge(Ue.OHM,He.SI_BASE),new Ge(Ue.AMPERE,He.SI_BASE),new Ge(Ue.VOLT,He.SI_BASE)],[new class{constructor(){this.description="V=I*R",this.getVariantValue=(e,t)=>e.values[0].getFormulaValue(t).times(e.values[1].getFormulaValue(t)),this.getInputValuesDefinition=()=>[this.parentFormula.values[0],this.parentFormula.values[1]],this.getOutputValueDefinition=()=>this.parentFormula.values[2],this.getMathMl=e=>"",this.parentFormula=null}},new class{constructor(){this.description="I=V/R",this.getVariantValue=(e,t)=>e.values[2].getFormulaValue(t).dividedBy(e.values[0].getFormulaValue(t)),this.getInputValuesDefinition=()=>[this.parentFormula.values[0],this.parentFormula.values[2]],this.getOutputValueDefinition=()=>this.parentFormula.values[1],this.getMathMl=e=>"",this.parentFormula=null}},new class{constructor(){this.description="R=V/I",this.getVariantValue=(e,t)=>e.values[2].getFormulaValue(t).dividedBy(e.values[1].getFormulaValue(t)),this.getInputValuesDefinition=()=>[this.parentFormula.values[2],this.parentFormula.values[1]],this.getOutputValueDefinition=()=>this.parentFormula.values[0],this.getMathMl=e=>"",this.parentFormula=null}}],"ohm_law",["electricity"],new URL("https://wikipedia.org/wiki/Ohm's_law"))};let ze=!1;
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */
-const Ke="fw-catalog-",Ye=Ke+"category-",Je=Ke+"formula-count",Qe={};let Xe=!1;class et{constructor(e,t,n,i,r){if(this.name=e,this.description=t,this.values=n,this.unit=i,this.scaleFactor=r,i.scale!=r.scale)throw alert(""),Error("")}getDataSet(){return this.values}}const tt=[1,2.2,4.7],nt=[1,1.5,2.2,3.3,4.7,6.8],it=[1,1.2,1.5,1.8,2.2,2.7,3.3,3.9,4.7,5.6,6.8,8.2],rt=[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],st=[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],ot=[1,10,100,1e3,1e4,1e5,1e6,1e7],ut={RESISTOR_E3:new et(Be("dataset.resistor-e3.name"),Be("dataset.resistor-e3.desc"),ot.flatMap((e=>tt.map((t=>new De(e).times(t))))),Ue.OHM,He.SI_BASE),RESISTOR_E6:new et(Be("dataset.resistor-e6.name"),Be("dataset.resistor-e6.desc"),ot.flatMap((e=>nt.map((t=>new De(e).times(t))))),Ue.OHM,He.SI_BASE),RESISTOR_E12:new et(Be("dataset.resistor-e12.name"),Be("dataset.resistor-e12.desc"),ot.flatMap((e=>it.map((t=>new De(e).times(t))))),Ue.OHM,He.SI_BASE),RESISTOR_E24:new et(Be("dataset.resistor-e24.name"),Be("dataset.resistor-e24.desc"),ot.flatMap((e=>rt.map((t=>new De(e).times(t))))),Ue.OHM,He.SI_BASE),RESISTOR_E48:new et(Be("dataset.resistor-e48.name"),Be("dataset.resistor-e48.desc"),ot.flatMap((e=>st.map((t=>new De(e).times(t))))),Ue.OHM,He.SI_BASE),CAPACITOR_IEC:new et(Be("dataset.capacitor-iec.name"),Be("dataset.capacitor-iec.desc"),[1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,.001,.01,.1].flatMap((e=>rt.map((t=>new De(e).times(t))))),Ue.FARAD,He.SI_BASE)};
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */
-class at{constructor(e,t){this.name=e,this.description=t}}const ct={DISABLED:new at(Be("context.type.disabled.name"),Be("context.type.disabled.desc")),CONSTANT:new at(Be("context.type.constant.name"),Be("context.type.constant.desc")),CONTINUOUS:new at(Be("context.type.continuous.name"),Be("context.type.continuous.desc")),VALUE_RANGE:new at(Be("context.type.valueRange.name"),Be("context.type.valueRange.desc")),DATASET_RANG:new at(Be("context.type.dataSetRange.name"),Be("context.type.dataSetRange.desc"))},lt="fw-context-component-",ht=lt+"type",ft=lt+"set",mt=lt+"unit",dt=lt+"scale";let pt=null,gt=null,wt=null,vt=!1;console.log("Initializing 'Formula Wizard v"+[0,0,2].join(".")+"'..."),(new Date).getMilliseconds(),De.set({precision:25,rounding:8}),Ze||(console.debug("Initializing scales & units..."),Object.keys(He).forEach((e=>{const t=He[e];t.scale.scaleFactors.push(t)})),Ze=!0),ze||(console.debug("Initializing formulas..."),Object.keys($e).forEach((e=>{$e[e].variants.forEach((t=>{t.parentFormula=$e[e]}))})),ze=!0),function(){if(!Xe){console.debug("Populating formula catalog..."),document.querySelectorAll("[id]").forEach((e=>{e.id.startsWith(Ye)&&(Qe[e.id.replace(Ye,"")]=e)}));const e=document.getElementById(Je);null!==e&&(e.innerText=Object.keys($e).length.toString());let t=document.getElementById("template-formula-available"),n=document.getElementById("template-formula-available-variant");if(null===t||null===n)throw alert("error.ui.catalog.noTemplate"),Error("error.ui.catalog.noTemplate");Object.keys($e).forEach((e=>{if($e[e].categories.every((function(e){return-1!==Object.keys(Qe).indexOf(e)}))){let i=t.content.cloneNode(!0),r=i.querySelector("p");null!==r&&(r.innerText=$e[e].name);let s=i.querySelector("div.fw-variants");if(null===s)throw alert(""),Error("");s.innerHTML="",$e[e].variants.forEach((t=>{let i=n.content.cloneNode(!0),r=i.querySelector("button");if(null===r)throw alert(""),Error("");r.innerHTML=t.getMathMl($e[e]),r.title=t.description,s.appendChild(i)})),$e[e].categories.forEach((e=>{Object.keys(Qe).includes(e)&&Qe[e].appendChild(i)}))}})),Xe=!0}}(),function(){if(!vt){if(console.debug("Preparing UI for workbench context components..."),pt=document.getElementById("template-context-component"),null===pt)throw alert(Be("error.ui.context.noTemplate")),Error(Be("error.ui.context.noTemplate"));pt=pt.cloneNode(!0).content,document.getElementById("template-context-component").remove();const e=pt.getElementById(ht),t=pt.getElementById(ft),n=pt.getElementById(mt),i=pt.getElementById(dt);if([e,t,n,i].some((e=>null===e)))throw alert(Be("error.ui.context.noSets")),Error(Be("error.ui.context.noSets"));if(Object.keys(ct).forEach((t=>{const n=document.createElement("option");n.setAttribute("value",t),n.innerText=ct[t].name,e.appendChild(n)})),Object.keys(ut).forEach((e=>{const n=document.createElement("option");n.setAttribute("value",e),n.innerText=ut[e].name,t.appendChild(n)})),Object.keys(Ue).forEach((e=>{const t=document.createElement("option");t.setAttribute("value",e),t.innerText=Ue[e].name,n.appendChild(t)})),Object.keys(He).forEach((e=>{const t=document.createElement("option");t.setAttribute("value",e),t.innerText=He[e].prefix,i.appendChild(t)})),gt=document.getElementById("fw-text-context-middle"),null===gt)throw alert(Be("error.ui.context.noStatus")),Error(Be("error.ui.context.noStatus"));if(wt=document.querySelector("button#fw-button-add-context"),null===wt)throw alert(Be("error.ui.context.missingButton")),Error(Be("error.ui.context.missingButton"));wt.onclick=function(){if(null===pt.cloneNode(!0).firstElementChild)throw alert(Be("error.ui.context.component.cannotGetElement")),Error(Be("error.ui.context.component.cannotGetElement"))},vt=!0}}
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * Unlicense Licence
- */(),console.log(Be("joe.mama")),console.log(Ue),console.log($e);
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/formulas.js b/tools/items/formula-wizard/src/formulas.js
deleted file mode 100644
index 35d499a..0000000
--- a/tools/items/formula-wizard/src/formulas.js
+++ /dev/null
@@ -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 "";
- };
- 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 "";
- };
- 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 "";
- };
- 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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/formulas.min.js b/tools/items/formula-wizard/src/formulas.min.js
deleted file mode 100644
index 1837a3b..0000000
--- a/tools/items/formula-wizard/src/formulas.min.js
+++ /dev/null
@@ -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=>"",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=>"",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=>"",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)}
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/lang.js b/tools/items/formula-wizard/src/lang.js
deleted file mode 100644
index 628ec2b..0000000
--- a/tools/items/formula-wizard/src/lang.js
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/lang.min.js b/tools/items/formula-wizard/src/lang.min.js
deleted file mode 100644
index 07dda17..0000000
--- a/tools/items/formula-wizard/src/lang.min.js
+++ /dev/null
@@ -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}
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/main.js b/tools/items/formula-wizard/src/main.js
deleted file mode 100644
index bac2173..0000000
--- a/tools/items/formula-wizard/src/main.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * 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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/main.min.js b/tools/items/formula-wizard/src/main.min.js
deleted file mode 100644
index faf4b91..0000000
--- a/tools/items/formula-wizard/src/main.min.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * 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);
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/main.ts b/tools/items/formula-wizard/src/main.ts
index 8a1305c..003a19e 100644
--- a/tools/items/formula-wizard/src/main.ts
+++ b/tools/items/formula-wizard/src/main.ts
@@ -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
@@ -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"));
diff --git a/tools/items/formula-wizard/src/mvc_context.js b/tools/items/formula-wizard/src/mvc_context.js
deleted file mode 100644
index 34de15c..0000000
--- a/tools/items/formula-wizard/src/mvc_context.js
+++ /dev/null
@@ -1,124 +0,0 @@
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * 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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/mvc_context.ts b/tools/items/formula-wizard/src/mvc_context.ts
index 1e0fffc..09bbf11 100644
--- a/tools/items/formula-wizard/src/mvc_context.ts
+++ b/tools/items/formula-wizard/src/mvc_context.ts
@@ -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;
diff --git a/tools/items/formula-wizard/src/mvc_formula.ts b/tools/items/formula-wizard/src/mvc_formula.ts
new file mode 100644
index 0000000..c807aa5
--- /dev/null
+++ b/tools/items/formula-wizard/src/mvc_formula.ts
@@ -0,0 +1,184 @@
+/*
+ * Formula Wizard v0.0.2
+ * [Short desc here]
+ * https://github.com/aziascreations/Web-NibblePoker
+ * Copyright (c) 2023 Herwin Bozet
+ * 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();
+ }
+}
diff --git a/tools/items/formula-wizard/src/sets.js b/tools/items/formula-wizard/src/sets.js
deleted file mode 100644
index a2ee032..0000000
--- a/tools/items/formula-wizard/src/sets.js
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/tsconfig.json b/tools/items/formula-wizard/src/tsconfig.json
deleted file mode 100644
index 5e7a0d6..0000000
--- a/tools/items/formula-wizard/src/tsconfig.json
+++ /dev/null
@@ -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 ''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"
- ]
-}
diff --git a/tools/items/formula-wizard/src/ui_catalog.js b/tools/items/formula-wizard/src/ui_catalog.js
deleted file mode 100644
index cb53bdf..0000000
--- a/tools/items/formula-wizard/src/ui_catalog.js
+++ /dev/null
@@ -1,69 +0,0 @@
-/*!
- * Formula Wizard v0.0.2
- * [Short desc here]
- * https://github.com/aziascreations/Web-NibblePoker
- * Copyright (c) 2023 Herwin Bozet
- * 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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/ui_catalog.ts b/tools/items/formula-wizard/src/ui_catalog.ts
index 25cbd30..5a0e3f3 100644
--- a/tools/items/formula-wizard/src/ui_catalog.ts
+++ b/tools/items/formula-wizard/src/ui_catalog.ts
@@ -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
* 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();
}
}
diff --git a/tools/items/formula-wizard/src/units.js b/tools/items/formula-wizard/src/units.js
deleted file mode 100644
index 2046c57..0000000
--- a/tools/items/formula-wizard/src/units.js
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/tools/items/formula-wizard/src/units.min.js b/tools/items/formula-wizard/src/units.min.js
deleted file mode 100644
index 2164cf3..0000000
--- a/tools/items/formula-wizard/src/units.min.js
+++ /dev/null
@@ -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)}
\ No newline at end of file