@goadminuiux/calculator 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @adminuiux/calculator
3
+ * AdminUIUX - Production-Ready Universal Calculator Package
4
+ *
5
+ * Lightweight, zero-dependency vanilla JavaScript calculator engine & DOM component.
6
+ * Works seamlessly in Browser (direct <script> / CDN), CommonJS (Node.js), and ES Modules.
7
+ *
8
+ * @version 1.0.0
9
+ * @author AdminUIUX (adminuiux.com)
10
+ * @license MIT
11
+ *
12
+ * Public APIs:
13
+ * - Calculator: Pure mathematical calculation & evaluation engine (framework-independent)
14
+ * - Formatter: High-precision number rounding, currency, and thousand-separator formatting
15
+ * - StreamCalculator: Decoupled desk/stream calculator state machine (digits, chained ops, memory, tape)
16
+ * - AdminUIUXCalculator: DOM-binding component connecting HTML buttons, displays, outputs & keyboard
17
+ */
18
+ !function(t,e){"use strict";if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{const r=e();t.AdminUIUXCalculator=r.AdminUIUXCalculator,t.Calculator=r.Calculator,t.Formatter=r.Formatter,t.StreamCalculator=r.StreamCalculator}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this,function(){"use strict";const t={round(t,e=8){if(!isFinite(t)||isNaN(t))return 0;const r=Math.pow(10,e);return Math.round((t+Number.EPSILON)*r)/r},format(t,e={}){if(null==t||""===t)return"";const r="number"==typeof t?t:parseFloat(t);if(isNaN(r))return"Error";let i=t;"number"==typeof e.precision&&(i=this.round(r,e.precision));const n=String(i);if(n.includes("e")||n.includes("E"))return n;const s=n.split("."),a=s[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),o=s.length>1?`${a}.${s[1]}`:a;return e.currency?`${e.currency} ${o}`:o},parse(t){if("number"==typeof t)return isNaN(t)?0:t;if(!t||"string"!=typeof t)return 0;const e=t.replace(/[^0-9.-]/g,""),r=parseFloat(e);return isNaN(r)?0:r},getOperatorSymbol(t){switch(t){case"*":case"x":return"×";case"/":return"÷";case"-":return"−";default:return t}}},e={precision:8,add(e,r,i=this.precision){return t.round(Number(e)+Number(r),i)},subtract(e,r,i=this.precision){return t.round(Number(e)-Number(r),i)},multiply(e,r,i=this.precision){return t.round(Number(e)*Number(r),i)},divide(e,r,i=this.precision){const n=Number(r);return 0===n?0:t.round(Number(e)/n,i)},modulo(e,r,i=this.precision){const n=Number(r);return 0===n?0:t.round(Number(e)%n,i)},power(e,r,i=this.precision){return t.round(Math.pow(Number(e),Number(r)),i)},percent(e,r,i=this.precision){return t.round(Number(e)*Number(r)/100,i)},addPercent(e,r,i=this.precision){const n=Number(e)*Number(r)/100;return t.round(Number(e)+n,i)},subtractPercent(e,r,i=this.precision){const n=Number(e)*Number(r)/100;return t.round(Number(e)-n,i)},multiplyPercent(e,r,i=this.precision){return t.round(Number(e)*Number(r)/100,i)},dividePercent(e,r,i=this.precision){const n=Number(r)/100;return 0===n?0:t.round(Number(e)/n,i)},sin(e,r="deg",i=this.precision){const n="deg"===r?Number(e)*Math.PI/180:Number(e);return t.round(Math.sin(n),i)},cos(e,r="deg",i=this.precision){const n="deg"===r?Number(e)*Math.PI/180:Number(e);return t.round(Math.cos(n),i)},tan(e,r="deg",i=this.precision){const n="deg"===r?Number(e)*Math.PI/180:Number(e);return t.round(Math.tan(n),i)},asin(e,r="deg",i=this.precision){const n=Math.asin(Number(e)),s="deg"===r?180*n/Math.PI:n;return t.round(s,i)},acos(e,r="deg",i=this.precision){const n=Math.acos(Number(e)),s="deg"===r?180*n/Math.PI:n;return t.round(s,i)},atan(e,r="deg",i=this.precision){const n=Math.atan(Number(e)),s="deg"===r?180*n/Math.PI:n;return t.round(s,i)},sqrt(e,r=this.precision){const i=Number(e);return i>=0?t.round(Math.sqrt(i),r):0},sqr(e,r=this.precision){return t.round(Number(e)*Number(e),r)},cube(e,r=this.precision){return t.round(Number(e)*Number(e)*Number(e),r)},log(e,r=this.precision){const i=Number(e);return i>0?t.round(Math.log10(i),r):0},ln(e,r=this.precision){const i=Number(e);return i>0?t.round(Math.log(i),r):0},exp(e,r=this.precision){return t.round(Math.exp(Number(e)),r)},reciprocal(e,r=this.precision){const i=Number(e);return 0!==i?t.round(1/i,r):0},abs:t=>Math.abs(Number(t)),factorial(t){const e=Math.floor(Number(t));if(e<0)return 0;if(0===e||1===e)return 1;let r=1;for(let t=2;t<=Math.min(e,170);t++)r*=t;return r},tax(e,r=.18,i=!0,n=this.precision){const s=Number(e),a=i?s*(1+r):s/(1+r);return t.round(a,n)},tip(e,r=15,i=this.precision){const n=Number(e),s=n*r/100;return t.round(n+s,i)},discount(e,r=10,i=this.precision){const n=Number(e),s=n*r/100;return t.round(n-s,i)},format:(e,r)=>t.format(e,r),executePerform(e,r){if(!r)return{value:e,history:""};const i=String(r).trim(),n=Number(e)||0,s=i.match(/^([+\-*/]?)\s*(\d+(?:\.\d+)?)\s*%$/);if(s){const e=s[1]||"+",r=parseFloat(s[2]);let i=n;"+"!==e&&s[1]?"-"===e?i=this.subtractPercent(n,r):"*"===e?i=this.multiplyPercent(n,r):"/"===e&&(i=this.dividePercent(n,r)):i=this.addPercent(n,r);const a="-"===e?"−":"*"===e?"×":"/"===e?"÷":"+";return{value:i,history:`${t.format(n)} ${a} ${r}% =`}}const a=i.match(/^([+\-*/]?)\s*(\d+(?:\.\d+)?)$/);if(a){const e=a[1]||"+",r=parseFloat(a[2]);let i=n;"+"===e?i=this.add(n,r):"-"===e?i=this.subtract(n,r):"*"===e?i=this.multiply(n,r):"/"===e&&(i=this.divide(n,r));const s="-"===e?"−":"*"===e?"×":"/"===e?"÷":"+";return{value:i,history:`${t.format(n)} ${s} ${t.format(r)} =`}}return{value:n,history:""}},evaluate(e,r={}){if(!e||"string"!=typeof e)return 0;const i=r.precision??this.precision;let n=e.replace(/×/g,"*").replace(/÷/g,"/").replace(/−/g,"-").replace(/,/g,"").trim();if(!n)return 0;const s=[];let a=0,o=null;for(;a<n.length;){const t=n[a];if(/\s/.test(t))a++;else{if(/\d/.test(t)||"."===t&&a+1<n.length&&/\d/.test(n[a+1])){let t="";for(;a<n.length&&/[\d.]/.test(n[a]);)t+=n[a],a++;let e=!1;for(;a<n.length&&/\s/.test(n[a]);)a++;a<n.length&&"%"===n[a]&&(e=!0,a++);const r=parseFloat(t);s.push({type:"number",value:r,isPercent:e}),o="number";continue}if("+"===t||"-"===t||"*"===t||"/"===t||"^"===t||"("===t||")"===t){!("+"!==t&&"-"!==t||null!==o&&"operator"!==o&&"lparen"!==o)?(s.push({type:"unary",value:t}),o="unary"):"("===t?(s.push({type:"lparen",value:"("}),o="lparen"):")"===t?(s.push({type:"rparen",value:")"}),o="rparen"):(s.push({type:"operator",value:t}),o="operator"),a++;continue}a++}}if(0===s.length)return 0;const u={"+":1,"-":1,"*":2,"/":2,"^":3,"u+":4,"u-":4},c=[],l=[];for(let t=0;t<s.length;t++){const e=s[t];if("number"===e.type)c.push(e);else if("unary"===e.type)l.push({type:"unary",op:"u"+e.value});else if("operator"===e.type){const t=e.value;for(;l.length>0&&"lparen"!==l[l.length-1].type&&(u[l[l.length-1].op]>u[t]||u[l[l.length-1].op]===u[t]&&"^"!==t);)c.push(l.pop());l.push({type:"operator",op:t})}else if("lparen"===e.type)l.push(e);else if("rparen"===e.type){for(;l.length>0&&"lparen"!==l[l.length-1].type;)c.push(l.pop());l.length>0&&"lparen"===l[l.length-1].type&&l.pop()}}for(;l.length>0;){const t=l.pop();"lparen"!==t.type&&c.push(t)}const h=[];for(let t=0;t<c.length;t++){const e=c[t];if("number"===e.type)h.push(e);else if("unary"===e.type){const t=h.pop(),r="object"==typeof t?t.value:t,i="u-"===e.op?-r:r;h.push({type:"number",value:i})}else if("operator"===e.type){const t=h.pop(),r=h.pop(),i="object"==typeof r?r.value:Number(r);let n="object"==typeof t?t.value:Number(t);t&&t.isPercent&&("+"===e.op||"-"===e.op?n=i*n/100:"*"!==e.op&&"/"!==e.op||(n/=100));let s=0;switch(e.op){case"+":s=i+n;break;case"-":s=i-n;break;case"*":s=i*n;break;case"/":s=0===n?0:i/n;break;case"^":s=Math.pow(i,n)}h.push({type:"number",value:s})}}if(0===h.length)return 0;const p=h[0].value??h[0];return t.round(Number(p),i)},createStream:(t={})=>new r(t)};class r{constructor(t={}){this.config=Object.assign({precision:8,currency:"",taxRate:.18,tipRates:[10,15,20],angleMode:"deg",onCalculate:null},t),this.reset()}reset(){this.currentInput="0",this.previousValue=null,this.pendingOperator=null,this.historyTokens=[],this.hasJustCalculated=!1,this.hasPercentApplied=!1,this.rawPercent=null,this.memory=0,this.tapeHistory=[]}inputDigit(t){if(this.hasJustCalculated)return this.currentInput="."===t?"0.":t,this.previousValue=null,this.pendingOperator=null,this.historyTokens=[],this.hasJustCalculated=!1,this.hasPercentApplied=!1,void(this.rawPercent=null);this.hasPercentApplied=!1,this.rawPercent=null,"."===t?this.currentInput.includes(".")||(this.currentInput=""===this.currentInput||"0"===this.currentInput?"0.":this.currentInput+"."):"00"===t?"0"===this.currentInput||""===this.currentInput?this.currentInput="0":this.currentInput+="00":"0"===this.currentInput||""===this.currentInput?this.currentInput=String(t):this.currentInput+=String(t)}inputOperator(e){const r=t.getOperatorSymbol(e);if(this.hasJustCalculated){const i=this.parseCurrent();return this.previousValue=i,this.pendingOperator=e,this.historyTokens=[t.format(i),r],this.currentInput="",void(this.hasJustCalculated=!1)}if(null===this.previousValue){const i=this.parseCurrent();return this.previousValue=i,this.pendingOperator=e,this.historyTokens=[t.format(i),r],void(this.currentInput="")}if(""!==this.currentInput){const i=parseFloat(this.currentInput);let n=0;if(this.hasPercentApplied){const e=this.pendingOperator;if("+"===e)n=this.previousValue+i;else if("-"===e)n=this.previousValue-i;else if("*"===e||"x"===e||"×"===e)n=i;else if("/"===e||"÷"===e){const t=null!==this.rawPercent?this.rawPercent/100:i/(this.previousValue||1);n=0===t?0:this.previousValue/t}else n=this.calculate(this.previousValue,e,i);n=t.round(n,this.config.precision),this.hasPercentApplied=!1,this.rawPercent=null}else n=this.calculate(this.previousValue,this.pendingOperator,i);return this.historyTokens.length>0&&String(this.historyTokens[this.historyTokens.length-1]).endsWith("%")?this.historyTokens.push(r):this.historyTokens.push(t.format(i),r),this.previousValue=n,this.pendingOperator=e,void(this.currentInput="")}this.pendingOperator=e,this.historyTokens.length>0&&(this.historyTokens[this.historyTokens.length-1]=r)}inputEquals(){if(null===this.pendingOperator||null===this.previousValue)return this.parseCurrent();const e=""!==this.currentInput?parseFloat(this.currentInput):this.previousValue;let r=0;if(this.hasPercentApplied){const i=this.pendingOperator;if("+"===i)r=this.previousValue+e;else if("-"===i)r=this.previousValue-e;else if("*"===i||"x"===i||"×"===i)r=e;else if("/"===i||"÷"===i){const t=null!==this.rawPercent?this.rawPercent/100:e/(this.previousValue||1);r=0===t?0:this.previousValue/t}else r=this.calculate(this.previousValue,i,e);r=t.round(r,this.config.precision),this.hasPercentApplied=!1,this.rawPercent=null}else r=this.calculate(this.previousValue,this.pendingOperator,e);this.historyTokens.length>0&&String(this.historyTokens[this.historyTokens.length-1]).endsWith("%")?this.historyTokens.push("="):this.historyTokens.push(t.format(e),"=");const i=this.historyTokens.join(" ");return this.tapeHistory.unshift(`${i} ${t.format(r)}`),"function"==typeof this.config.onCalculate&&this.config.onCalculate(r,i),this.previousValue=r,this.currentInput=String(r),this.pendingOperator=null,this.hasJustCalculated=!0,r}calculate(e,r,i){let n=0;switch(r){case"+":n=e+i;break;case"-":n=e-i;break;case"*":case"x":case"×":n=e*i;break;case"/":case"÷":n=0===i?0:e/i;break;case"%":case"mod":n=e%i;break;case"^":case"pow":n=Math.pow(e,i);break;default:n=i}return t.round(n,this.config.precision)}toggleSign(){""!==this.currentInput&&"0"!==this.currentInput?this.currentInput.startsWith("-")?this.currentInput=this.currentInput.slice(1):this.currentInput="-"+this.currentInput:null!==this.previousValue&&(this.previousValue=-this.previousValue,this.currentInput=String(this.previousValue))}applyPercent(){const e=this.parseCurrent();if(null!==this.previousValue&&null!==this.pendingOperator){const r=this.previousValue*e/100;this.currentInput=String(t.round(r,this.config.precision)),this.hasPercentApplied=!0,this.rawPercent=e,this.historyTokens=[t.format(this.previousValue),t.getOperatorSymbol(this.pendingOperator),`${t.format(e)}%`]}else{const r=e/100;this.currentInput=String(t.round(r,this.config.precision)),this.hasPercentApplied=!1,this.rawPercent=null,this.historyTokens=[`${t.format(e)}%`]}}backspace(){this.hasJustCalculated?this.clearAll():this.currentInput.length>1?this.currentInput=this.currentInput.slice(0,-1):this.currentInput="0"}clearAll(){this.currentInput="0",this.previousValue=null,this.pendingOperator=null,this.historyTokens=[],this.hasJustCalculated=!1,this.hasPercentApplied=!1,this.rawPercent=null}parseCurrent(){return parseFloat(this.currentInput)||0}getDisplayValue(){let t=this.currentInput;return""===t&&null!==this.previousValue&&(t=String(this.previousValue)),""===t&&(t="0"),t}getFormattedDisplay(){return t.format(this.getDisplayValue(),{currency:this.config.currency})}getHistoryString(){return this.historyTokens.join(" ")}}class i{constructor(t,e={}){this.wrapper="string"==typeof t?document.querySelector(t):t,this.wrapper&&(this.wrapper._calculatorInstance||(this.wrapper._calculatorInstance=this,this.config=Object.assign({type:this.wrapper.getAttribute("data-calculator-type")||this.wrapper.getAttribute("data-calendar-type")||this.wrapper.getAttribute("data-calc-mode")||"basic",precision:parseInt(this.wrapper.getAttribute("data-calc-precision"),10)||(e.precision??8),angleMode:"deg",currency:this.wrapper.getAttribute("data-calc-currency")||e.currency||"",taxRate:e.taxRate??.18,tipRates:e.tipRates??[10,15,20],quickPresets:e.quickPresets??[50,100,500,1e3],enableKeyboard:e.enableKeyboard??!0,showTape:e.showTape??!1,onCalculate:e.onCalculate||null},e),this.engine=new r(this.config),this.hasInteracted=!1,this.memory=0,this.displayEl=this.wrapper.querySelector(".calculator-display, [data-calc-display]"),this.historyEl=this.wrapper.querySelector(".calculator-history, [data-calc-history]"),this.memoryBadge=this.wrapper.querySelector("[data-calc-memory-badge]"),this.angleModeBtn=this.wrapper.querySelector("[data-calc-angle-toggle]"),this.tapeListEl=this.wrapper.querySelector(".calculator-tape, [data-calc-tape]"),this.initEventListeners(),this.updateDisplay()))}initEventListeners(){this.wrapper.querySelectorAll("[data-calc-action], [data-calculator-perfom], [data-calculator-perform]").forEach(t=>{t.addEventListener("click",e=>{e.preventDefault();const r=t.getAttribute("data-calculator-perfom")||t.getAttribute("data-calculator-perform");if(r)return void this.executePerform(r);const i=t.getAttribute("data-calc-action"),n=t.getAttribute("data-val");this.handleAction(i,n)})}),this.config.enableKeyboard&&(this.wrapper.addEventListener("keydown",t=>{this.handleKeyDown(t)}),this.wrapper.hasAttribute("tabindex")||this.wrapper.setAttribute("tabindex","0"))}handleKeyDown(t){if(["input","textarea"].includes(document.activeElement?.tagName?.toLowerCase()))return;const e=t.key;isNaN(e)?"."===e?(t.preventDefault(),this.handleAction("num",".")):"+"===e||"-"===e||"*"===e||"/"===e?(t.preventDefault(),this.handleAction("operator",e)):"Enter"===e||"="===e?(t.preventDefault(),this.handleAction("equals")):"Backspace"===e?(t.preventDefault(),this.handleAction("backspace")):"Escape"===e?(t.preventDefault(),this.handleAction("clear")):"%"===e&&(t.preventDefault(),this.handleAction("percent")):(t.preventDefault(),this.handleAction("num",e))}handleAction(t,e){switch(this.hasInteracted=!0,t){case"num":this.engine.inputDigit(e);break;case"operator":this.engine.inputOperator(e);break;case"equals":this.engine.inputEquals(),this.syncTape();break;case"clear":this.engine.clearAll();break;case"clear-entry":case"backspace":this.engine.backspace();break;case"negate":this.engine.toggleSign();break;case"percent":this.engine.applyPercent();break;case"scientific":this.applyScientific(e);break;case"memory":this.handleMemory(e);break;case"angle-toggle":this.toggleAngleMode();break;case"preset":this.applyPreset(parseFloat(e));break;case"tax-add":this.applyTax(!0);break;case"tax-sub":this.applyTax(!1);break;case"tip":this.applyTip(parseFloat(e));break;case"discount":this.applyDiscount(parseFloat(e))}this.updateDisplay()}applyScientific(r){const i=this.engine.parseCurrent();let n=i;switch(r){case"sin":n=e.sin(i,this.config.angleMode,this.config.precision);break;case"cos":n=e.cos(i,this.config.angleMode,this.config.precision);break;case"tan":n=e.tan(i,this.config.angleMode,this.config.precision);break;case"asin":n=e.asin(i,this.config.angleMode,this.config.precision);break;case"acos":n=e.acos(i,this.config.angleMode,this.config.precision);break;case"atan":n=e.atan(i,this.config.angleMode,this.config.precision);break;case"sqrt":n=e.sqrt(i,this.config.precision);break;case"sqr":n=e.sqr(i,this.config.precision);break;case"cube":n=e.cube(i,this.config.precision);break;case"log":n=e.log(i,this.config.precision);break;case"ln":n=e.ln(i,this.config.precision);break;case"exp":n=e.exp(i,this.config.precision);break;case"1/x":n=e.reciprocal(i,this.config.precision);break;case"abs":n=e.abs(i);break;case"pi":n=t.round(Math.PI,this.config.precision);break;case"e":n=t.round(Math.E,this.config.precision);break;case"fact":n=e.factorial(i)}this.engine.currentInput=String(n),this.engine.hasJustCalculated&&(this.engine.historyTokens=[`${r}(${t.format(i)}) =`])}handleMemory(t){const e=this.engine.parseCurrent();switch(t){case"mc":this.memory=0;break;case"mr":this.engine.currentInput=String(this.memory),this.engine.hasJustCalculated=!1;break;case"m+":this.memory+=e;break;case"m-":this.memory-=e;break;case"ms":this.memory=e}this.memoryBadge&&(this.memoryBadge.style.display=0!==this.memory?"inline-block":"none")}toggleAngleMode(){this.config.angleMode="deg"===this.config.angleMode?"rad":"deg",this.angleModeBtn&&(this.angleModeBtn.textContent=this.config.angleMode.toUpperCase())}applyPreset(t){const e=this.engine.parseCurrent();this.engine.currentInput=String(e+t),this.engine.hasJustCalculated=!1}applyTax(r){const i=this.engine.parseCurrent(),n=this.config.taxRate,s=e.tax(i,n,r,this.config.precision);this.engine.currentInput=String(s),this.engine.historyTokens=[`${t.format(i)} ${r?"+":"-"} ${Math.round(100*n)}% Tax =`],this.engine.hasJustCalculated=!0}applyTip(r){const i=this.engine.parseCurrent(),n=e.tip(i,r,this.config.precision);this.engine.currentInput=String(n),this.engine.historyTokens=[`${t.format(i)} + ${r}% Tip =`],this.engine.hasJustCalculated=!0}applyDiscount(r){const i=this.engine.parseCurrent(),n=e.discount(i,r,this.config.precision);this.engine.currentInput=String(n),this.engine.historyTokens=[`${t.format(i)} - ${r}% Off =`],this.engine.hasJustCalculated=!0}executePerform(t){if(!t)return;this.hasInteracted=!0;const r=this.engine.parseCurrent(),i=e.executePerform(r,t);this.engine.currentInput=String(i.value),i.history&&(this.engine.historyTokens=[i.history]),this.engine.hasJustCalculated=!0,this.updateDisplay()}getOutputTargets(){const t=this.wrapper.getAttribute("data-calculator-output")||this.wrapper.getAttribute("data-output-target")||this.config.outputTarget||this.config.output;if(!t)return[];try{return Array.from(document.querySelectorAll(t))}catch(t){return[]}}getCalculationTargets(){const t=this.wrapper.getAttribute("data-calculator-calculation")||this.wrapper.getAttribute("data-calculation-target")||this.config.calculationTarget||this.config.calculation;if(!t)return[];try{return Array.from(document.querySelectorAll(t))}catch(t){return[]}}updateOutputTargets(t,e){const r=this.getOutputTargets();0!==r.length&&(r.forEach(e=>{"INPUT"===e.tagName||"TEXTAREA"===e.tagName?(e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))):e.textContent=t}),this.wrapper.dispatchEvent(new CustomEvent("calculator:change",{bubbles:!0,detail:{value:e,formatted:t,history:this.engine.getHistoryString(),calculator:this}})))}updateCalculationTargets(t){const e=this.getCalculationTargets();0!==e.length&&e.forEach(e=>{"INPUT"===e.tagName||"TEXTAREA"===e.tagName?(e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))):e.textContent=t})}updateDisplay(){const t=this.config.currency?`${this.config.currency} `:"",e=this.engine.parseCurrent();let r=this.engine.getDisplayValue();const i=r.split("."),n=i[0].replace(/\B(?=(\d{3})+(?!\d))/g,",");r=i.length>1?`${n}.${i[1]}`:n,this.displayEl&&(this.displayEl.textContent=`${t}${r}`);const s=this.engine.getHistoryString();this.historyEl&&(s?this.historyEl.textContent=s:this.historyEl.innerHTML="&nbsp;"),this.scrollToEnd(this.historyEl),this.scrollToEnd(this.displayEl),this.hasInteracted&&(this.updateOutputTargets(`${t}${r}`,e),this.updateCalculationTargets(s||"Result:"))}isRTL(){return"undefined"!=typeof document&&("rtl"===document.documentElement.getAttribute("dir")||"rtl"===document.documentElement.getAttribute("data-bs-direction")||"rtl"===document.body?.getAttribute("dir")||"rtl"===this.wrapper?.getAttribute("dir")||"rtl"===getComputedStyle(this.wrapper||document.documentElement).direction)}scrollToEnd(t){if(!t)return;const e=this.isRTL();t.scrollLeft=e?-t.scrollWidth:t.scrollWidth,"function"==typeof requestAnimationFrame&&requestAnimationFrame(()=>{t&&(t.scrollLeft=e?-t.scrollWidth:t.scrollWidth)})}syncTape(){this.tapeListEl&&(this.tapeListEl.innerHTML="",this.engine.tapeHistory.forEach((t,e)=>{const r=document.createElement("div");r.className="d-flex justify-content-between py-1 border-bottom border-light-subtle",r.innerHTML=`<span class="text-secondary">${this.engine.tapeHistory.length-e}.</span> <span>${t}</span>`,this.tapeListEl.appendChild(r)}))}static create(t,e={}){const r="string"==typeof t?document.querySelector(t):t;return r?new i(r,e):null}static init(t,e={}){const r="string"==typeof t?document.querySelector(t):t;return r?new i(r,e):null}static initAll(){"undefined"!=typeof document&&document.querySelectorAll(".calculator, [data-calculator-type], [data-calendar-type]").forEach(t=>{t._calculatorInstance||new i(t)})}}return i.Calculator=e,i.Formatter=t,i.StreamCalculator=r,"undefined"!=typeof window&&"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>i.initAll()):i.initAll()),{AdminUIUXCalculator:i,Calculator:e,Formatter:t,StreamCalculator:r,default:i}});
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@goadminuiux/calculator",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Production-ready, zero-dependency universal JavaScript calculator engine and DOM component with stream arithmetic, smart percentage handling, scientific functions, and WCAG accessibility.",
5
+ "main": "dist/calculator.js",
6
+ "module": "dist/calculator.esm.js",
7
+ "browser": "dist/calculator.min.js",
8
+ "unpkg": "dist/calculator.min.js",
9
+ "jsdelivr": "dist/calculator.min.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/calculator.esm.js",
13
+ "require": "./dist/calculator.js",
14
+ "default": "./dist/calculator.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "README.md",
22
+ "LICENSE",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "scripts": {
26
+ "test": "node test/calculator.test.js",
27
+ "build": "node scripts/build.js"
28
+ },
29
+ "keywords": [
30
+ "calculator",
31
+ "javascript-calculator",
32
+ "math-evaluator",
33
+ "arithmetic",
34
+ "scientific-calculator",
35
+ "percentage-calculator",
36
+ "desk-calculator",
37
+ "vanilla-js",
38
+ "zero-dependencies",
39
+ "adminuiux",
40
+ "bootstrap-5"
41
+ ],
42
+ "author": "adminuiux.com",
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/adminuiux/calculator.git"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/adminuiux/calculator/issues"
50
+ },
51
+ "homepage": "https://adminuiux.com"
52
+ }