@workday/canvas-kit-styling 10.1.3 → 10.2.0-628-next.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.
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +2 -0
- package/dist/commonjs/lib/calc.d.ts +109 -0
- package/dist/commonjs/lib/calc.d.ts.map +1 -0
- package/dist/commonjs/lib/calc.js +136 -0
- package/dist/commonjs/lib/px2rem.d.ts +10 -0
- package/dist/commonjs/lib/px2rem.d.ts.map +1 -0
- package/dist/commonjs/lib/px2rem.js +15 -0
- package/dist/es6/index.d.ts +2 -0
- package/dist/es6/index.d.ts.map +1 -1
- package/dist/es6/index.js +2 -0
- package/dist/es6/lib/calc.d.ts +109 -0
- package/dist/es6/lib/calc.d.ts.map +1 -0
- package/dist/es6/lib/calc.js +133 -0
- package/dist/es6/lib/px2rem.d.ts +10 -0
- package/dist/es6/lib/px2rem.d.ts.map +1 -0
- package/dist/es6/lib/px2rem.js +11 -0
- package/index.ts +2 -0
- package/package.json +3 -3
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -10,6 +10,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./lib/calc"), exports);
|
|
13
14
|
__exportStar(require("./lib/cs"), exports);
|
|
15
|
+
__exportStar(require("./lib/px2rem"), exports);
|
|
14
16
|
__exportStar(require("./lib/slugify"), exports);
|
|
15
17
|
__exportStar(require("./lib/uniqueId"), exports);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that returns a CSS `calc()` addition string.
|
|
3
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const styles = {
|
|
7
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) + 0.125rem)'
|
|
8
|
+
* padding: calc.add("--cnvs-sys-space-x1", '0.125rem'),
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param augend
|
|
13
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
14
|
+
*
|
|
15
|
+
* @param addend
|
|
16
|
+
* The value being added to the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
17
|
+
*
|
|
18
|
+
* @returns 'calc(augend + addend)'
|
|
19
|
+
*/
|
|
20
|
+
declare function add(augend: string, addend: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Function that returns a CSS `calc()` subtraction string.
|
|
23
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const styles = {
|
|
27
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) - 0.125rem)'
|
|
28
|
+
* padding: calc.subtract("--cnvs-sys-space-x1", '0.125rem'),
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param minuend
|
|
33
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
34
|
+
*
|
|
35
|
+
* @param subtrahend
|
|
36
|
+
* The value being subtracted from the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
37
|
+
*
|
|
38
|
+
* @returns 'calc(minuend - subtrahend)'
|
|
39
|
+
*/
|
|
40
|
+
declare function subtract(minuend: string, subtrahend: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Function that returns a CSS `calc()` multiplication string.
|
|
43
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* const styles = {
|
|
47
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) * 3)'
|
|
48
|
+
* padding: calc.multiply("--cnvs-sys-space-x1", 3),
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param multiplicand
|
|
53
|
+
* The base value being multiplied. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
54
|
+
*
|
|
55
|
+
* @param multiplier
|
|
56
|
+
* The value being multiplied to the base. E.g. 2 or '--cnvs-sys-space-x1'
|
|
57
|
+
*
|
|
58
|
+
* @returns 'calc(multiplicand * multiplier)'
|
|
59
|
+
*/
|
|
60
|
+
declare function multiply(multiplicand: string, multiplier?: string | number): string;
|
|
61
|
+
/**
|
|
62
|
+
* Function that returns a CSS `calc()` division string
|
|
63
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const styles = {
|
|
67
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) / 2)'
|
|
68
|
+
* padding: calc.divide("--cnvs-sys-space-x1", 2),
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param dividend
|
|
73
|
+
* The base value being divided. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
74
|
+
*
|
|
75
|
+
* @param divisor
|
|
76
|
+
* The divisor of the base value. E.g. 2 or '--cnvs-sys-space-x1'
|
|
77
|
+
*
|
|
78
|
+
* @returns 'calc(dividend / divisor)'
|
|
79
|
+
*/
|
|
80
|
+
declare function divide(dividend: string, divisor?: string | number): string;
|
|
81
|
+
/**
|
|
82
|
+
* Function that negates the value of a CSS variable or value.
|
|
83
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const styles = {
|
|
87
|
+
* // returns 'calc(var(--cnvs-sys-space-x4) * -1)'
|
|
88
|
+
* padding: negate('--cnvs-sys-space-x4');
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param value
|
|
93
|
+
* The value being negated. E.g. '--cnvs-sys-space-x1' or '1rem'
|
|
94
|
+
*
|
|
95
|
+
* @param fallback
|
|
96
|
+
* An optional fallback value for a CSS variable. E.g. '1rem'
|
|
97
|
+
*
|
|
98
|
+
* @returns 'calc(var(value) * -1)'
|
|
99
|
+
*/
|
|
100
|
+
declare function negate(value: string, fallback?: string): string;
|
|
101
|
+
export declare const calc: {
|
|
102
|
+
add: typeof add;
|
|
103
|
+
divide: typeof divide;
|
|
104
|
+
multiply: typeof multiply;
|
|
105
|
+
negate: typeof negate;
|
|
106
|
+
subtract: typeof subtract;
|
|
107
|
+
};
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=calc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc.d.ts","sourceRoot":"","sources":["../../../lib/calc.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAE1C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAEpD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,GAAG,MAAU,UAItE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG,MAAU,UAI7D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAI/C;AAED,eAAO,MAAM,IAAI;;;;;;CAMhB,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calc = void 0;
|
|
4
|
+
const cs_1 = require("./cs");
|
|
5
|
+
/**
|
|
6
|
+
* Function to conditionally wrap CSS vars if they are not already wrapped with `var()`.
|
|
7
|
+
* Only intended for internal use in these functions.
|
|
8
|
+
*/
|
|
9
|
+
function wrapCSSVar(value, fallback) {
|
|
10
|
+
if (typeof value === 'string' && value.startsWith('--')) {
|
|
11
|
+
return cs_1.cssVar(value, fallback);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Function that returns a CSS `calc()` addition string.
|
|
19
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const styles = {
|
|
23
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) + 0.125rem)'
|
|
24
|
+
* padding: calc.add("--cnvs-sys-space-x1", '0.125rem'),
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param augend
|
|
29
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
30
|
+
*
|
|
31
|
+
* @param addend
|
|
32
|
+
* The value being added to the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
33
|
+
*
|
|
34
|
+
* @returns 'calc(augend + addend)'
|
|
35
|
+
*/
|
|
36
|
+
function add(augend, addend) {
|
|
37
|
+
return `calc(${wrapCSSVar(augend)} + ${wrapCSSVar(addend)})`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Function that returns a CSS `calc()` subtraction string.
|
|
41
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const styles = {
|
|
45
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) - 0.125rem)'
|
|
46
|
+
* padding: calc.subtract("--cnvs-sys-space-x1", '0.125rem'),
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param minuend
|
|
51
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
52
|
+
*
|
|
53
|
+
* @param subtrahend
|
|
54
|
+
* The value being subtracted from the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
55
|
+
*
|
|
56
|
+
* @returns 'calc(minuend - subtrahend)'
|
|
57
|
+
*/
|
|
58
|
+
function subtract(minuend, subtrahend) {
|
|
59
|
+
return `calc(${wrapCSSVar(minuend)} - ${wrapCSSVar(subtrahend)})`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Function that returns a CSS `calc()` multiplication string.
|
|
63
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const styles = {
|
|
67
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) * 3)'
|
|
68
|
+
* padding: calc.multiply("--cnvs-sys-space-x1", 3),
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param multiplicand
|
|
73
|
+
* The base value being multiplied. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
74
|
+
*
|
|
75
|
+
* @param multiplier
|
|
76
|
+
* The value being multiplied to the base. E.g. 2 or '--cnvs-sys-space-x1'
|
|
77
|
+
*
|
|
78
|
+
* @returns 'calc(multiplicand * multiplier)'
|
|
79
|
+
*/
|
|
80
|
+
function multiply(multiplicand, multiplier = 1) {
|
|
81
|
+
const formattedMultiplier = typeof multiplier === 'string' ? wrapCSSVar(multiplier) : multiplier;
|
|
82
|
+
return `calc(${wrapCSSVar(multiplicand)} * ${formattedMultiplier})`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Function that returns a CSS `calc()` division string
|
|
86
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* const styles = {
|
|
90
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) / 2)'
|
|
91
|
+
* padding: calc.divide("--cnvs-sys-space-x1", 2),
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param dividend
|
|
96
|
+
* The base value being divided. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
97
|
+
*
|
|
98
|
+
* @param divisor
|
|
99
|
+
* The divisor of the base value. E.g. 2 or '--cnvs-sys-space-x1'
|
|
100
|
+
*
|
|
101
|
+
* @returns 'calc(dividend / divisor)'
|
|
102
|
+
*/
|
|
103
|
+
function divide(dividend, divisor = 1) {
|
|
104
|
+
const formattedDivisor = typeof divisor === 'string' ? wrapCSSVar(divisor) : divisor;
|
|
105
|
+
return `calc(${wrapCSSVar(dividend)} / ${formattedDivisor})`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Function that negates the value of a CSS variable or value.
|
|
109
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* const styles = {
|
|
113
|
+
* // returns 'calc(var(--cnvs-sys-space-x4) * -1)'
|
|
114
|
+
* padding: negate('--cnvs-sys-space-x4');
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param value
|
|
119
|
+
* The value being negated. E.g. '--cnvs-sys-space-x1' or '1rem'
|
|
120
|
+
*
|
|
121
|
+
* @param fallback
|
|
122
|
+
* An optional fallback value for a CSS variable. E.g. '1rem'
|
|
123
|
+
*
|
|
124
|
+
* @returns 'calc(var(value) * -1)'
|
|
125
|
+
*/
|
|
126
|
+
function negate(value, fallback) {
|
|
127
|
+
const multiplicand = wrapCSSVar(value, fallback);
|
|
128
|
+
return multiply(multiplicand, -1);
|
|
129
|
+
}
|
|
130
|
+
exports.calc = {
|
|
131
|
+
add,
|
|
132
|
+
divide,
|
|
133
|
+
multiply,
|
|
134
|
+
negate,
|
|
135
|
+
subtract,
|
|
136
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that converts a `px` value (number) to `rem` (string).
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* margin: px2rem(2);
|
|
6
|
+
* // returns '0.125rem'
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare function px2rem(px: number, base?: number): string;
|
|
10
|
+
//# sourceMappingURL=px2rem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"px2rem.d.ts","sourceRoot":"","sources":["../../../lib/px2rem.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,SAAK,UAE3C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.px2rem = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Function that converts a `px` value (number) to `rem` (string).
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* margin: px2rem(2);
|
|
9
|
+
* // returns '0.125rem'
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
function px2rem(px, base = 16) {
|
|
13
|
+
return `${px / base}rem`;
|
|
14
|
+
}
|
|
15
|
+
exports.px2rem = px2rem;
|
package/dist/es6/index.d.ts
CHANGED
package/dist/es6/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/es6/index.js
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that returns a CSS `calc()` addition string.
|
|
3
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const styles = {
|
|
7
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) + 0.125rem)'
|
|
8
|
+
* padding: calc.add("--cnvs-sys-space-x1", '0.125rem'),
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param augend
|
|
13
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
14
|
+
*
|
|
15
|
+
* @param addend
|
|
16
|
+
* The value being added to the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
17
|
+
*
|
|
18
|
+
* @returns 'calc(augend + addend)'
|
|
19
|
+
*/
|
|
20
|
+
declare function add(augend: string, addend: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Function that returns a CSS `calc()` subtraction string.
|
|
23
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const styles = {
|
|
27
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) - 0.125rem)'
|
|
28
|
+
* padding: calc.subtract("--cnvs-sys-space-x1", '0.125rem'),
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param minuend
|
|
33
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
34
|
+
*
|
|
35
|
+
* @param subtrahend
|
|
36
|
+
* The value being subtracted from the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
37
|
+
*
|
|
38
|
+
* @returns 'calc(minuend - subtrahend)'
|
|
39
|
+
*/
|
|
40
|
+
declare function subtract(minuend: string, subtrahend: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Function that returns a CSS `calc()` multiplication string.
|
|
43
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* const styles = {
|
|
47
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) * 3)'
|
|
48
|
+
* padding: calc.multiply("--cnvs-sys-space-x1", 3),
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param multiplicand
|
|
53
|
+
* The base value being multiplied. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
54
|
+
*
|
|
55
|
+
* @param multiplier
|
|
56
|
+
* The value being multiplied to the base. E.g. 2 or '--cnvs-sys-space-x1'
|
|
57
|
+
*
|
|
58
|
+
* @returns 'calc(multiplicand * multiplier)'
|
|
59
|
+
*/
|
|
60
|
+
declare function multiply(multiplicand: string, multiplier?: string | number): string;
|
|
61
|
+
/**
|
|
62
|
+
* Function that returns a CSS `calc()` division string
|
|
63
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const styles = {
|
|
67
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) / 2)'
|
|
68
|
+
* padding: calc.divide("--cnvs-sys-space-x1", 2),
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param dividend
|
|
73
|
+
* The base value being divided. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
74
|
+
*
|
|
75
|
+
* @param divisor
|
|
76
|
+
* The divisor of the base value. E.g. 2 or '--cnvs-sys-space-x1'
|
|
77
|
+
*
|
|
78
|
+
* @returns 'calc(dividend / divisor)'
|
|
79
|
+
*/
|
|
80
|
+
declare function divide(dividend: string, divisor?: string | number): string;
|
|
81
|
+
/**
|
|
82
|
+
* Function that negates the value of a CSS variable or value.
|
|
83
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const styles = {
|
|
87
|
+
* // returns 'calc(var(--cnvs-sys-space-x4) * -1)'
|
|
88
|
+
* padding: negate('--cnvs-sys-space-x4');
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param value
|
|
93
|
+
* The value being negated. E.g. '--cnvs-sys-space-x1' or '1rem'
|
|
94
|
+
*
|
|
95
|
+
* @param fallback
|
|
96
|
+
* An optional fallback value for a CSS variable. E.g. '1rem'
|
|
97
|
+
*
|
|
98
|
+
* @returns 'calc(var(value) * -1)'
|
|
99
|
+
*/
|
|
100
|
+
declare function negate(value: string, fallback?: string): string;
|
|
101
|
+
export declare const calc: {
|
|
102
|
+
add: typeof add;
|
|
103
|
+
divide: typeof divide;
|
|
104
|
+
multiply: typeof multiply;
|
|
105
|
+
negate: typeof negate;
|
|
106
|
+
subtract: typeof subtract;
|
|
107
|
+
};
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=calc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc.d.ts","sourceRoot":"","sources":["../../../lib/calc.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAE1C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAEpD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,GAAG,MAAU,UAItE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG,MAAU,UAI7D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAI/C;AAED,eAAO,MAAM,IAAI;;;;;;CAMhB,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { cssVar } from './cs';
|
|
2
|
+
/**
|
|
3
|
+
* Function to conditionally wrap CSS vars if they are not already wrapped with `var()`.
|
|
4
|
+
* Only intended for internal use in these functions.
|
|
5
|
+
*/
|
|
6
|
+
function wrapCSSVar(value, fallback) {
|
|
7
|
+
if (typeof value === 'string' && value.startsWith('--')) {
|
|
8
|
+
return cssVar(value, fallback);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Function that returns a CSS `calc()` addition string.
|
|
16
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const styles = {
|
|
20
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) + 0.125rem)'
|
|
21
|
+
* padding: calc.add("--cnvs-sys-space-x1", '0.125rem'),
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param augend
|
|
26
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
27
|
+
*
|
|
28
|
+
* @param addend
|
|
29
|
+
* The value being added to the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
30
|
+
*
|
|
31
|
+
* @returns 'calc(augend + addend)'
|
|
32
|
+
*/
|
|
33
|
+
function add(augend, addend) {
|
|
34
|
+
return `calc(${wrapCSSVar(augend)} + ${wrapCSSVar(addend)})`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Function that returns a CSS `calc()` subtraction string.
|
|
38
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* const styles = {
|
|
42
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) - 0.125rem)'
|
|
43
|
+
* padding: calc.subtract("--cnvs-sys-space-x1", '0.125rem'),
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param minuend
|
|
48
|
+
* The base value. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
49
|
+
*
|
|
50
|
+
* @param subtrahend
|
|
51
|
+
* The value being subtracted from the base. E.g. '1rem' or '--cnvs-sys-space-x4'
|
|
52
|
+
*
|
|
53
|
+
* @returns 'calc(minuend - subtrahend)'
|
|
54
|
+
*/
|
|
55
|
+
function subtract(minuend, subtrahend) {
|
|
56
|
+
return `calc(${wrapCSSVar(minuend)} - ${wrapCSSVar(subtrahend)})`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Function that returns a CSS `calc()` multiplication string.
|
|
60
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* const styles = {
|
|
64
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) * 3)'
|
|
65
|
+
* padding: calc.multiply("--cnvs-sys-space-x1", 3),
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param multiplicand
|
|
70
|
+
* The base value being multiplied. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
71
|
+
*
|
|
72
|
+
* @param multiplier
|
|
73
|
+
* The value being multiplied to the base. E.g. 2 or '--cnvs-sys-space-x1'
|
|
74
|
+
*
|
|
75
|
+
* @returns 'calc(multiplicand * multiplier)'
|
|
76
|
+
*/
|
|
77
|
+
function multiply(multiplicand, multiplier = 1) {
|
|
78
|
+
const formattedMultiplier = typeof multiplier === 'string' ? wrapCSSVar(multiplier) : multiplier;
|
|
79
|
+
return `calc(${wrapCSSVar(multiplicand)} * ${formattedMultiplier})`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Function that returns a CSS `calc()` division string
|
|
83
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const styles = {
|
|
87
|
+
* // returns 'calc(var(--cnvs-sys-space-x1) / 2)'
|
|
88
|
+
* padding: calc.divide("--cnvs-sys-space-x1", 2),
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param dividend
|
|
93
|
+
* The base value being divided. E.g. '1rem' or '--cnvs-sys-space-x1'
|
|
94
|
+
*
|
|
95
|
+
* @param divisor
|
|
96
|
+
* The divisor of the base value. E.g. 2 or '--cnvs-sys-space-x1'
|
|
97
|
+
*
|
|
98
|
+
* @returns 'calc(dividend / divisor)'
|
|
99
|
+
*/
|
|
100
|
+
function divide(dividend, divisor = 1) {
|
|
101
|
+
const formattedDivisor = typeof divisor === 'string' ? wrapCSSVar(divisor) : divisor;
|
|
102
|
+
return `calc(${wrapCSSVar(dividend)} / ${formattedDivisor})`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Function that negates the value of a CSS variable or value.
|
|
106
|
+
* CSS vars will be automatically wrapped in `var()` if provided.
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* const styles = {
|
|
110
|
+
* // returns 'calc(var(--cnvs-sys-space-x4) * -1)'
|
|
111
|
+
* padding: negate('--cnvs-sys-space-x4');
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param value
|
|
116
|
+
* The value being negated. E.g. '--cnvs-sys-space-x1' or '1rem'
|
|
117
|
+
*
|
|
118
|
+
* @param fallback
|
|
119
|
+
* An optional fallback value for a CSS variable. E.g. '1rem'
|
|
120
|
+
*
|
|
121
|
+
* @returns 'calc(var(value) * -1)'
|
|
122
|
+
*/
|
|
123
|
+
function negate(value, fallback) {
|
|
124
|
+
const multiplicand = wrapCSSVar(value, fallback);
|
|
125
|
+
return multiply(multiplicand, -1);
|
|
126
|
+
}
|
|
127
|
+
export const calc = {
|
|
128
|
+
add,
|
|
129
|
+
divide,
|
|
130
|
+
multiply,
|
|
131
|
+
negate,
|
|
132
|
+
subtract,
|
|
133
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that converts a `px` value (number) to `rem` (string).
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* margin: px2rem(2);
|
|
6
|
+
* // returns '0.125rem'
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare function px2rem(px: number, base?: number): string;
|
|
10
|
+
//# sourceMappingURL=px2rem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"px2rem.d.ts","sourceRoot":"","sources":["../../../lib/px2rem.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,SAAK,UAE3C"}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-styling",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.0-628-next.0",
|
|
4
4
|
"description": "The custom CSS in JS solution that takes JS styles and turns them into static CSS",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"@emotion/serialize": "^1.0.2",
|
|
55
55
|
"@emotion/styled": "^11.6.0",
|
|
56
56
|
"@emotion/utils": "^1.0.0",
|
|
57
|
-
"@workday/canvas-kit-react": "^10.
|
|
57
|
+
"@workday/canvas-kit-react": "^10.2.0-628-next.0",
|
|
58
58
|
"@workday/canvas-tokens-web": "^1.0.0",
|
|
59
59
|
"typescript": "4.2"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e87d2573a126d186bd1e45e3eedef40a9e0dcc4f"
|
|
62
62
|
}
|