ant-design/components/theme/util/calc/NumCalculator.ts
MadCcc 5f1dd427df
feat: css var (#45589)
* feat: css variables theme

* chore: temp

* chore temp

* chore: temp

* chore: temp

* chore: tmp

* chore: temp

* feat: full css variables

* feat: css var

* chore: code clean

* chore: code clean

* chore: bump cssinjs

* test: fix lint

* feat: better key logic

* feat: useStyle add param rootCls for cssVar scope

* chore: fix lint

* chore: code clean

* chore: fix lint

* perf: minimize component token size

* chore: make useId compatible

* chore: code clean

* chore: fix lint

* chore: code clean

* chore: update test case

* feat: genCSSVarRegister

* feat: RPN Calculator

* chore: add test for css var

* chore: code clean

* test: add test for calc

* feat: better calc type

* chore: code clean

* chore: update size limit

* feat: better useCSSVar

* chore: better useCSSVar

* test: add cov

* feat: better calc logic

* test: add test case

* chore: code clean

---------

Signed-off-by: MadCcc <madccc@foxmail.com>
2023-11-06 10:31:51 +08:00

55 lines
1.2 KiB
TypeScript

import AbstractCalculator from './calculator';
export default class NumCalculator extends AbstractCalculator {
result: number = 0;
constructor(num: number | string | AbstractCalculator) {
super();
if (num instanceof NumCalculator) {
this.result = num.result;
} else if (typeof num === 'number') {
this.result = num;
}
}
add(num: number | AbstractCalculator): this {
if (num instanceof NumCalculator) {
this.result += num.result;
} else if (typeof num === 'number') {
this.result += num;
}
return this;
}
sub(num: number | AbstractCalculator): this {
if (num instanceof NumCalculator) {
this.result -= num.result;
} else if (typeof num === 'number') {
this.result -= num;
}
return this;
}
mul(num: number | AbstractCalculator): this {
if (num instanceof NumCalculator) {
this.result *= num.result;
} else if (typeof num === 'number') {
this.result *= num;
}
return this;
}
div(num: number | AbstractCalculator): this {
if (num instanceof NumCalculator) {
this.result /= num.result;
} else if (typeof num === 'number') {
this.result /= num;
}
return this;
}
equal(): number {
return this.result;
}
}