@codeleap/styles 6.0.1 → 6.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/package.json.bak +1 -1
- package/src/lib/calc.ts +41 -0
- package/src/lib/index.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/styles"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "6.
|
|
12
|
+
"@codeleap/config": "6.2.3",
|
|
13
13
|
"ts-node-dev": "^1.1.8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
package/package.json.bak
CHANGED
package/src/lib/calc.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
type Unit = 'px' | 'vh' | 'dvh' | 'vw' | 'dvw' | '%' | 'lvh' | 'svh'
|
|
2
|
+
|
|
3
|
+
class CalcBuilder {
|
|
4
|
+
private expression: string
|
|
5
|
+
|
|
6
|
+
constructor(initial: number, unit: Unit = 'px') {
|
|
7
|
+
this.expression = `${initial}${unit}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
private wrap(value: string): string {
|
|
11
|
+
return `(${value})`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
sub(value: number, unit: Unit = 'px') {
|
|
15
|
+
const val = `${value}${unit}`
|
|
16
|
+
this.expression = `${this.wrap(this.expression)} - ${this.wrap(val)}`
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
add(value: number, unit: Unit = 'px') {
|
|
21
|
+
const val = `${value}${unit}`
|
|
22
|
+
this.expression = `${this.wrap(this.expression)} + ${this.wrap(val)}`
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
mult(value: number) {
|
|
27
|
+
this.expression = `${this.wrap(this.expression)} * ${value}`
|
|
28
|
+
return this
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
div(value: number) {
|
|
32
|
+
this.expression = `${this.wrap(this.expression)} / ${value}`
|
|
33
|
+
return this
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
build() {
|
|
37
|
+
return `calc(${this.expression})`
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const calc = (base: number, unit: Unit = 'px') => new CalcBuilder(base, unit)
|
package/src/lib/index.ts
CHANGED