@arbor-css/calc 0.0.1
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/README.md +5 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +399 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
- package/src/index.ts +539 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
This is a _highly_ idiosyncratic, selective re-implementation of CSS `calc` as a JS tree-like thingy.
|
|
2
|
+
|
|
3
|
+
I use it to "bake" values into CSS or leave them dynamic as `--property` references. You define the equation in this tree structure, and then give it some subset of 'baked' values, and it reduces the equation to the minimal version with baked values all computed in as much as possible.
|
|
4
|
+
|
|
5
|
+
Is this necessary? Maybe not...
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface CalcEvaluationContext {
|
|
2
|
+
propertyValues: Record<string, string | undefined>;
|
|
3
|
+
/** Prevents the baking of known literals into calculations. */
|
|
4
|
+
skipBaking?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type Equation = OperationTree;
|
|
7
|
+
export type OperationTree = AddOperation | SubtractOperation | MultiplyOperation | DivideOperation | LiteralOperation | ClampOperation | CastOperation | FunctionCallOperation | ConcatenateOperation;
|
|
8
|
+
interface AddOperation {
|
|
9
|
+
type: 'add';
|
|
10
|
+
values: Equation[];
|
|
11
|
+
}
|
|
12
|
+
interface SubtractOperation {
|
|
13
|
+
type: 'subtract';
|
|
14
|
+
values: Equation[];
|
|
15
|
+
}
|
|
16
|
+
interface MultiplyOperation {
|
|
17
|
+
type: 'multiply';
|
|
18
|
+
values: Equation[];
|
|
19
|
+
}
|
|
20
|
+
interface DivideOperation {
|
|
21
|
+
type: 'divide';
|
|
22
|
+
values: [Equation, Equation];
|
|
23
|
+
}
|
|
24
|
+
interface LiteralOperation {
|
|
25
|
+
type: 'literal';
|
|
26
|
+
value: string | number;
|
|
27
|
+
}
|
|
28
|
+
interface ClampOperation {
|
|
29
|
+
type: 'clamp';
|
|
30
|
+
values: Equation[];
|
|
31
|
+
}
|
|
32
|
+
interface CastOperation {
|
|
33
|
+
type: 'cast';
|
|
34
|
+
value: Equation;
|
|
35
|
+
unit: '%' | '';
|
|
36
|
+
}
|
|
37
|
+
interface FunctionCallOperation {
|
|
38
|
+
type: 'function';
|
|
39
|
+
name: string;
|
|
40
|
+
args: Equation[];
|
|
41
|
+
}
|
|
42
|
+
/** Not strictly calc(), but useful for constructing non-numeric outputs... */
|
|
43
|
+
interface ConcatenateOperation {
|
|
44
|
+
type: 'concatenate';
|
|
45
|
+
separator: string;
|
|
46
|
+
values: Equation[];
|
|
47
|
+
}
|
|
48
|
+
export declare const $: {
|
|
49
|
+
literal: (value: string | number) => LiteralOperation;
|
|
50
|
+
add: (...values: Equation[]) => AddOperation;
|
|
51
|
+
subtract: (...values: Equation[]) => SubtractOperation;
|
|
52
|
+
multiply: (...values: Equation[]) => MultiplyOperation;
|
|
53
|
+
divide: (numerator: Equation, denominator: Equation) => DivideOperation;
|
|
54
|
+
clamp: (equation: Equation, min: Equation, max: Equation) => Equation;
|
|
55
|
+
castPercentage: (value: Equation) => Equation;
|
|
56
|
+
fn: (name: string, ...args: Equation[]) => FunctionCallOperation;
|
|
57
|
+
concat: (values: Equation[], sep?: string) => ConcatenateOperation;
|
|
58
|
+
};
|
|
59
|
+
export type CalcOperations = typeof $;
|
|
60
|
+
export declare function printEquation(equation: Equation): string;
|
|
61
|
+
export type ComputationResult = {
|
|
62
|
+
type: 'numeric';
|
|
63
|
+
value: number;
|
|
64
|
+
unit: '%' | '';
|
|
65
|
+
} | {
|
|
66
|
+
type: 'calc';
|
|
67
|
+
value: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'concatenated';
|
|
70
|
+
value: string;
|
|
71
|
+
};
|
|
72
|
+
export declare function printComputationResult(result: ComputationResult): string;
|
|
73
|
+
export declare function computeEquation(equation: Equation, userContext: CalcEvaluationContext): ComputationResult;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACrC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACnD,+DAA+D;IAC/D,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC;AACrC,MAAM,MAAM,aAAa,GACtB,YAAY,GACZ,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,cAAc,GACd,aAAa,GACb,qBAAqB,GACrB,oBAAoB,CAAC;AAExB,UAAU,YAAY;IACrB,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,QAAQ,EAAE,CAAC;CACnB;AACD,UAAU,iBAAiB;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,QAAQ,EAAE,CAAC;CACnB;AACD,UAAU,iBAAiB;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,QAAQ,EAAE,CAAC;CACnB;AACD,UAAU,eAAe;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;CAC7B;AACD,UAAU,gBAAgB;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AACD,UAAU,cAAc;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,QAAQ,EAAE,CAAC;CACnB;AACD,UAAU,aAAa;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,E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iBAAiB,CAkEnB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
export const $ = {
|
|
2
|
+
literal: (value) => {
|
|
3
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
4
|
+
return { type: 'literal', value };
|
|
5
|
+
}
|
|
6
|
+
return { type: 'literal', value };
|
|
7
|
+
},
|
|
8
|
+
add: (...values) => {
|
|
9
|
+
return { type: 'add', values };
|
|
10
|
+
},
|
|
11
|
+
subtract: (...values) => {
|
|
12
|
+
return { type: 'subtract', values };
|
|
13
|
+
},
|
|
14
|
+
multiply: (...values) => {
|
|
15
|
+
return { type: 'multiply', values };
|
|
16
|
+
},
|
|
17
|
+
divide: (numerator, denominator) => {
|
|
18
|
+
return { type: 'divide', values: [numerator, denominator] };
|
|
19
|
+
},
|
|
20
|
+
clamp: (equation, min, max) => {
|
|
21
|
+
return { type: 'clamp', values: [min, equation, max] };
|
|
22
|
+
},
|
|
23
|
+
castPercentage: (value) => {
|
|
24
|
+
return { type: 'cast', value, unit: '%' };
|
|
25
|
+
},
|
|
26
|
+
fn: (name, ...args) => {
|
|
27
|
+
return { type: 'function', name, args };
|
|
28
|
+
},
|
|
29
|
+
concat: (values, sep = ' ') => {
|
|
30
|
+
return { type: 'concatenate', values, separator: sep };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export function printEquation(equation) {
|
|
34
|
+
switch (equation.type) {
|
|
35
|
+
case 'literal':
|
|
36
|
+
return equation.value.toString();
|
|
37
|
+
case 'add':
|
|
38
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' + ')})`;
|
|
39
|
+
case 'subtract':
|
|
40
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' - ')})`;
|
|
41
|
+
case 'multiply':
|
|
42
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' * ')})`;
|
|
43
|
+
case 'divide':
|
|
44
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' / ')})`;
|
|
45
|
+
case 'clamp':
|
|
46
|
+
if (equation.values.length !== 3) {
|
|
47
|
+
throw new Error('Clamp operation requires exactly 3 values: min, value, max');
|
|
48
|
+
}
|
|
49
|
+
return `clamp(${equation.values
|
|
50
|
+
.map((v) => printEquation(v))
|
|
51
|
+
.join(', ')})`;
|
|
52
|
+
case 'cast':
|
|
53
|
+
return `(${printEquation(equation.value)} * ${equation.unit === '%' ? '100%' : '1'})`;
|
|
54
|
+
case 'function':
|
|
55
|
+
return `${equation.name}(${equation.args
|
|
56
|
+
.map((v) => printEquation(v))
|
|
57
|
+
.join(', ')})`;
|
|
58
|
+
case 'concatenate':
|
|
59
|
+
return equation.values
|
|
60
|
+
.map((v) => printEquation(v))
|
|
61
|
+
.join(equation.separator);
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unknown equation type: ${equation.type}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function add(a, b) {
|
|
67
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
68
|
+
return {
|
|
69
|
+
type: 'concatenated',
|
|
70
|
+
value: `${printComputationResult(a)} + ${printComputationResult(b)}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (a.value === 0) {
|
|
74
|
+
return b;
|
|
75
|
+
}
|
|
76
|
+
if (b.value === 0) {
|
|
77
|
+
return a;
|
|
78
|
+
}
|
|
79
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
80
|
+
return {
|
|
81
|
+
type: 'calc',
|
|
82
|
+
value: `calc(${printComputationResult(a)} + ${printComputationResult(b)})`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { type: 'numeric', value: a.value + b.value, unit: a.unit };
|
|
86
|
+
}
|
|
87
|
+
function subtract(a, b) {
|
|
88
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
89
|
+
return {
|
|
90
|
+
type: 'concatenated',
|
|
91
|
+
value: `${printComputationResult(a)} - ${printComputationResult(b)}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (b.value === 0) {
|
|
95
|
+
return a;
|
|
96
|
+
}
|
|
97
|
+
if (a.value === 0 && b.type === 'numeric') {
|
|
98
|
+
return { type: 'numeric', value: -b.value, unit: b.unit };
|
|
99
|
+
}
|
|
100
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
101
|
+
return {
|
|
102
|
+
type: 'calc',
|
|
103
|
+
value: `calc(${printComputationResult(a)} - ${printComputationResult(b)})`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return { type: 'numeric', value: a.value - b.value, unit: a.unit };
|
|
107
|
+
}
|
|
108
|
+
function multiply(a, b) {
|
|
109
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
110
|
+
return {
|
|
111
|
+
type: 'concatenated',
|
|
112
|
+
value: `${printComputationResult(a)} * ${printComputationResult(b)}`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (a.type === 'numeric' && a.value === 0) {
|
|
116
|
+
return { type: 'numeric', value: 0, unit: a.unit };
|
|
117
|
+
}
|
|
118
|
+
if (b.type === 'numeric' && b.value === 0) {
|
|
119
|
+
return { type: 'numeric', value: 0, unit: b.unit };
|
|
120
|
+
}
|
|
121
|
+
if (a.type === 'numeric' && a.value === 1) {
|
|
122
|
+
return b;
|
|
123
|
+
}
|
|
124
|
+
if (b.type === 'numeric' && b.value === 1) {
|
|
125
|
+
return a;
|
|
126
|
+
}
|
|
127
|
+
if (a.type === 'numeric' && a.unit === '%' && a.value === 100) {
|
|
128
|
+
return b;
|
|
129
|
+
}
|
|
130
|
+
if (b.type === 'numeric' && b.unit === '%' && b.value === 100) {
|
|
131
|
+
return a;
|
|
132
|
+
}
|
|
133
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
134
|
+
return {
|
|
135
|
+
type: 'calc',
|
|
136
|
+
value: `calc(${printComputationResult(a)} * ${printComputationResult(b)})`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (a.unit === '%' && b.unit === '%') {
|
|
140
|
+
return { type: 'numeric', value: (a.value * b.value) / 100, unit: '%' };
|
|
141
|
+
}
|
|
142
|
+
const unit = a.unit === '%' || b.unit === '%' ? '%' : '';
|
|
143
|
+
return { type: 'numeric', value: a.value * b.value, unit };
|
|
144
|
+
}
|
|
145
|
+
function divide(a, b) {
|
|
146
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
147
|
+
return {
|
|
148
|
+
type: 'concatenated',
|
|
149
|
+
value: `${printComputationResult(a)} / ${printComputationResult(b)}`,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (b.type === 'numeric' && b.value === 0) {
|
|
153
|
+
throw new Error('Division by zero');
|
|
154
|
+
}
|
|
155
|
+
if (a.type === 'numeric' && a.value === 0) {
|
|
156
|
+
return { type: 'numeric', value: 0, unit: a.unit };
|
|
157
|
+
}
|
|
158
|
+
if (b.type === 'numeric' && b.value === 1) {
|
|
159
|
+
return a;
|
|
160
|
+
}
|
|
161
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
162
|
+
return {
|
|
163
|
+
type: 'calc',
|
|
164
|
+
value: `calc(${printComputationResult(a)} / ${printComputationResult(b)})`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (a.unit === '%' && b.unit === '%') {
|
|
168
|
+
return { type: 'numeric', value: a.value / b.value, unit: '' };
|
|
169
|
+
}
|
|
170
|
+
const unit = a.unit === '%' && b.unit === '' ? '%' : '';
|
|
171
|
+
return { type: 'numeric', value: a.value / b.value, unit };
|
|
172
|
+
}
|
|
173
|
+
function clamp(value, min, max) {
|
|
174
|
+
if (value.type === 'concatenated' ||
|
|
175
|
+
min.type === 'concatenated' ||
|
|
176
|
+
max.type === 'concatenated') {
|
|
177
|
+
return {
|
|
178
|
+
type: 'concatenated',
|
|
179
|
+
value: `clamp(${printComputationResult(min)}, ${printComputationResult(value)}, ${printComputationResult(max)})`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (value.type === 'calc' ||
|
|
183
|
+
min.type === 'calc' ||
|
|
184
|
+
max.type === 'calc' ||
|
|
185
|
+
value.unit !== min.unit ||
|
|
186
|
+
value.unit !== max.unit ||
|
|
187
|
+
min.unit !== max.unit) {
|
|
188
|
+
return {
|
|
189
|
+
type: 'calc',
|
|
190
|
+
value: `calc(clamp(${printComputationResult(min)}, ${printComputationResult(value)}, ${printComputationResult(max)}))`,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
type: 'numeric',
|
|
195
|
+
value: Math.min(Math.max(value.value, min.value), max.value),
|
|
196
|
+
unit: value.unit,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function cast(value, unit) {
|
|
200
|
+
if (value.type === 'concatenated') {
|
|
201
|
+
return {
|
|
202
|
+
type: 'concatenated',
|
|
203
|
+
value: `(${printComputationResult(value)} * ${unit === '%' ? '100%' : '1'})`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (value.type === 'calc') {
|
|
207
|
+
return {
|
|
208
|
+
type: 'calc',
|
|
209
|
+
value: `calc(${printComputationResult(value)} * ${unit === '%' ? '100%' : '1'})`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (unit === '%') {
|
|
213
|
+
if (value.unit === '%') {
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
return { type: 'numeric', value: value.value * 100, unit: '%' };
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (value.unit === '') {
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
return { type: 'numeric', value: value.value / 100, unit: '' };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function numericToNumber(value) {
|
|
226
|
+
if (value.unit === '%') {
|
|
227
|
+
return value.value / 100;
|
|
228
|
+
}
|
|
229
|
+
return value.value;
|
|
230
|
+
}
|
|
231
|
+
function fnCall(name, ...args) {
|
|
232
|
+
// inline some functions if all args are numerics
|
|
233
|
+
if (args.every((arg) => arg.type === 'numeric')) {
|
|
234
|
+
const argsInOrderAsNumbers = args.map((arg) => numericToNumber(arg));
|
|
235
|
+
switch (name) {
|
|
236
|
+
case 'sin':
|
|
237
|
+
return {
|
|
238
|
+
type: 'numeric',
|
|
239
|
+
value: Math.sin(argsInOrderAsNumbers[0]),
|
|
240
|
+
unit: '',
|
|
241
|
+
};
|
|
242
|
+
case 'cos':
|
|
243
|
+
return {
|
|
244
|
+
type: 'numeric',
|
|
245
|
+
value: Math.cos(argsInOrderAsNumbers[0]),
|
|
246
|
+
unit: '',
|
|
247
|
+
};
|
|
248
|
+
case 'tan':
|
|
249
|
+
return {
|
|
250
|
+
type: 'numeric',
|
|
251
|
+
value: Math.tan(argsInOrderAsNumbers[0]),
|
|
252
|
+
unit: '',
|
|
253
|
+
};
|
|
254
|
+
case 'min':
|
|
255
|
+
return {
|
|
256
|
+
type: 'numeric',
|
|
257
|
+
value: Math.min(...argsInOrderAsNumbers),
|
|
258
|
+
unit: '',
|
|
259
|
+
};
|
|
260
|
+
case 'max':
|
|
261
|
+
return {
|
|
262
|
+
type: 'numeric',
|
|
263
|
+
value: Math.max(...argsInOrderAsNumbers),
|
|
264
|
+
unit: '',
|
|
265
|
+
};
|
|
266
|
+
case 'pow':
|
|
267
|
+
return {
|
|
268
|
+
type: 'numeric',
|
|
269
|
+
value: Math.pow(argsInOrderAsNumbers[0], argsInOrderAsNumbers[1]),
|
|
270
|
+
unit: '',
|
|
271
|
+
};
|
|
272
|
+
case 'abs':
|
|
273
|
+
return {
|
|
274
|
+
type: 'numeric',
|
|
275
|
+
value: Math.abs(argsInOrderAsNumbers[0]),
|
|
276
|
+
unit: '',
|
|
277
|
+
};
|
|
278
|
+
case 'exp':
|
|
279
|
+
return {
|
|
280
|
+
type: 'numeric',
|
|
281
|
+
value: Math.exp(argsInOrderAsNumbers[0]),
|
|
282
|
+
unit: '',
|
|
283
|
+
};
|
|
284
|
+
case 'log':
|
|
285
|
+
return {
|
|
286
|
+
type: 'numeric',
|
|
287
|
+
value: Math.log(argsInOrderAsNumbers[0]),
|
|
288
|
+
unit: '',
|
|
289
|
+
};
|
|
290
|
+
default:
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const isConcatenated = args.some((arg) => arg.type === 'concatenated');
|
|
295
|
+
if (isConcatenated) {
|
|
296
|
+
return {
|
|
297
|
+
type: 'concatenated',
|
|
298
|
+
value: `${name}(${args.map(printComputationResult).join(', ')})`,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
type: 'calc',
|
|
303
|
+
value: `${name}(${args.map(printComputationResult).join(', ')})`,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
export function printComputationResult(result) {
|
|
307
|
+
if (result.type === 'calc') {
|
|
308
|
+
return result.value;
|
|
309
|
+
}
|
|
310
|
+
if (result.type === 'concatenated') {
|
|
311
|
+
return result.value;
|
|
312
|
+
}
|
|
313
|
+
return result.unit === '%' ? `${result.value}%` : `${result.value}`;
|
|
314
|
+
}
|
|
315
|
+
function evaluateLiteral(literal, context) {
|
|
316
|
+
if (literal.startsWith('var(')) {
|
|
317
|
+
const propertyName = literal.slice(4, -1).trim();
|
|
318
|
+
const propertyValue = context.propertyValues[propertyName];
|
|
319
|
+
if (!propertyValue || context.skipBaking) {
|
|
320
|
+
return { type: 'calc', value: literal };
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// replace literal with known value from context
|
|
324
|
+
return evaluateLiteral(propertyValue, context);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else if (literal === 'PI') {
|
|
328
|
+
return { type: 'numeric', value: Math.PI, unit: '' };
|
|
329
|
+
}
|
|
330
|
+
else if (literal.endsWith('%')) {
|
|
331
|
+
const asNumber = Number(literal.slice(0, -1));
|
|
332
|
+
if (isNaN(asNumber)) {
|
|
333
|
+
throw new Error(`Literal value did not evaluate to a number: ${literal}`);
|
|
334
|
+
}
|
|
335
|
+
return { type: 'numeric', value: asNumber, unit: '%' };
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
const asNumber = Number(literal);
|
|
339
|
+
if (isNaN(asNumber)) {
|
|
340
|
+
return { type: 'calc', value: literal };
|
|
341
|
+
}
|
|
342
|
+
return { type: 'numeric', value: asNumber, unit: '' };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
export function computeEquation(equation, userContext) {
|
|
346
|
+
const context = {
|
|
347
|
+
propertyValues: userContext.propertyValues,
|
|
348
|
+
// unless otherwise specified, we do NOT bake literal values when
|
|
349
|
+
// running in a browser - this makes a runtime-evaluated equation
|
|
350
|
+
// responsive to runtime-tweaked globals.
|
|
351
|
+
skipBaking: userContext.skipBaking ?? typeof window !== 'undefined',
|
|
352
|
+
};
|
|
353
|
+
switch (equation.type) {
|
|
354
|
+
case 'literal':
|
|
355
|
+
return evaluateLiteral(equation.value.toString(), context);
|
|
356
|
+
case 'add':
|
|
357
|
+
return equation.values.reduce((sum, v) => add(sum, computeEquation(v, context)), { type: 'numeric', value: 0, unit: '' });
|
|
358
|
+
case 'subtract':
|
|
359
|
+
if (equation.values.length === 0) {
|
|
360
|
+
return { type: 'numeric', value: 0, unit: '' };
|
|
361
|
+
}
|
|
362
|
+
const first = computeEquation(equation.values[0], context);
|
|
363
|
+
return equation.values
|
|
364
|
+
.slice(1)
|
|
365
|
+
.reduce((difference, v) => subtract(difference, computeEquation(v, context)), first);
|
|
366
|
+
case 'multiply':
|
|
367
|
+
return equation.values.reduce((product, v) => multiply(product, computeEquation(v, context)), { type: 'numeric', value: 1, unit: '' });
|
|
368
|
+
case 'divide':
|
|
369
|
+
if (equation.values.length !== 2) {
|
|
370
|
+
throw new Error('Divide operation requires exactly 2 values');
|
|
371
|
+
}
|
|
372
|
+
const numerator = computeEquation(equation.values[0], context);
|
|
373
|
+
const denominator = computeEquation(equation.values[1], context);
|
|
374
|
+
return divide(numerator, denominator);
|
|
375
|
+
case 'clamp':
|
|
376
|
+
if (equation.values.length !== 3) {
|
|
377
|
+
throw new Error('Clamp operation requires exactly 3 values: min, value, max');
|
|
378
|
+
}
|
|
379
|
+
const min = computeEquation(equation.values[0], context);
|
|
380
|
+
const value = computeEquation(equation.values[1], context);
|
|
381
|
+
const max = computeEquation(equation.values[2], context);
|
|
382
|
+
return clamp(value, min, max);
|
|
383
|
+
case 'cast':
|
|
384
|
+
const innerValue = computeEquation(equation.value, context);
|
|
385
|
+
return cast(innerValue, equation.unit);
|
|
386
|
+
case 'function':
|
|
387
|
+
const args = equation.args.map((arg) => computeEquation(arg, context));
|
|
388
|
+
return fnCall(equation.name, ...args);
|
|
389
|
+
case 'concatenate':
|
|
390
|
+
const concatenatedValues = equation.values.map((v) => printComputationResult(computeEquation(v, context)));
|
|
391
|
+
return {
|
|
392
|
+
type: 'concatenated',
|
|
393
|
+
value: concatenatedValues.join(equation.separator),
|
|
394
|
+
};
|
|
395
|
+
default:
|
|
396
|
+
throw new Error(`Unknown equation type: ${equation.type}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2DA,MAAM,CAAC,MAAM,CAAC,GAAG;IAChB,OAAO,EAAE,CAAC,KAAsB,EAAoB,EAAE;QACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IACD,GAAG,EAAE,CAAC,GAAG,MAAkB,EAAgB,EAAE;QAC5C,OAAO,EAAE,IAA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,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,MAAM;YACV,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC5D,OAAO,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,UAAU;YACd,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;YACvE,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACvC,KAAK,aAAa;YACjB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACpD,sBAAsB,CAAC,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CACnD,CAAC;YACF,OAAO;gBACN,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;aAClD,CAAC;QACH;YACC,MAAM,IAAI,KAAK,CAAC,0BAA2B,QAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;AACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arbor-css/calc",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"development": "./src/index.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"node": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^6.0.3"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@arbor-css/tokens": "0.0.1"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"dev": "tsc -w --preserveWatchOutput"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
export interface CalcEvaluationContext {
|
|
2
|
+
propertyValues: Record<string, string | undefined>;
|
|
3
|
+
/** Prevents the baking of known literals into calculations. */
|
|
4
|
+
skipBaking?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type Equation = OperationTree;
|
|
8
|
+
export type OperationTree =
|
|
9
|
+
| AddOperation
|
|
10
|
+
| SubtractOperation
|
|
11
|
+
| MultiplyOperation
|
|
12
|
+
| DivideOperation
|
|
13
|
+
| LiteralOperation
|
|
14
|
+
| ClampOperation
|
|
15
|
+
| CastOperation
|
|
16
|
+
| FunctionCallOperation
|
|
17
|
+
| ConcatenateOperation;
|
|
18
|
+
|
|
19
|
+
interface AddOperation {
|
|
20
|
+
type: 'add';
|
|
21
|
+
values: Equation[];
|
|
22
|
+
}
|
|
23
|
+
interface SubtractOperation {
|
|
24
|
+
type: 'subtract';
|
|
25
|
+
values: Equation[];
|
|
26
|
+
}
|
|
27
|
+
interface MultiplyOperation {
|
|
28
|
+
type: 'multiply';
|
|
29
|
+
values: Equation[];
|
|
30
|
+
}
|
|
31
|
+
interface DivideOperation {
|
|
32
|
+
type: 'divide';
|
|
33
|
+
values: [Equation, Equation];
|
|
34
|
+
}
|
|
35
|
+
interface LiteralOperation {
|
|
36
|
+
type: 'literal';
|
|
37
|
+
value: string | number;
|
|
38
|
+
}
|
|
39
|
+
interface ClampOperation {
|
|
40
|
+
type: 'clamp';
|
|
41
|
+
values: Equation[];
|
|
42
|
+
}
|
|
43
|
+
interface CastOperation {
|
|
44
|
+
type: 'cast';
|
|
45
|
+
value: Equation;
|
|
46
|
+
unit: '%' | '';
|
|
47
|
+
}
|
|
48
|
+
interface FunctionCallOperation {
|
|
49
|
+
type: 'function';
|
|
50
|
+
name: string;
|
|
51
|
+
args: Equation[];
|
|
52
|
+
}
|
|
53
|
+
/** Not strictly calc(), but useful for constructing non-numeric outputs... */
|
|
54
|
+
interface ConcatenateOperation {
|
|
55
|
+
type: 'concatenate';
|
|
56
|
+
separator: string;
|
|
57
|
+
values: Equation[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const $ = {
|
|
61
|
+
literal: (value: string | number): LiteralOperation => {
|
|
62
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
63
|
+
return { type: 'literal', value };
|
|
64
|
+
}
|
|
65
|
+
return { type: 'literal', value };
|
|
66
|
+
},
|
|
67
|
+
add: (...values: Equation[]): AddOperation => {
|
|
68
|
+
return { type: 'add', values };
|
|
69
|
+
},
|
|
70
|
+
subtract: (...values: Equation[]): SubtractOperation => {
|
|
71
|
+
return { type: 'subtract', values };
|
|
72
|
+
},
|
|
73
|
+
multiply: (...values: Equation[]): MultiplyOperation => {
|
|
74
|
+
return { type: 'multiply', values };
|
|
75
|
+
},
|
|
76
|
+
divide: (numerator: Equation, denominator: Equation): DivideOperation => {
|
|
77
|
+
return { type: 'divide', values: [numerator, denominator] };
|
|
78
|
+
},
|
|
79
|
+
clamp: (equation: Equation, min: Equation, max: Equation): Equation => {
|
|
80
|
+
return { type: 'clamp', values: [min, equation, max] };
|
|
81
|
+
},
|
|
82
|
+
castPercentage: (value: Equation): Equation => {
|
|
83
|
+
return { type: 'cast', value, unit: '%' };
|
|
84
|
+
},
|
|
85
|
+
fn: (name: string, ...args: Equation[]): FunctionCallOperation => {
|
|
86
|
+
return { type: 'function', name, args };
|
|
87
|
+
},
|
|
88
|
+
concat: (values: Equation[], sep = ' '): ConcatenateOperation => {
|
|
89
|
+
return { type: 'concatenate', values, separator: sep };
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
export type CalcOperations = typeof $;
|
|
93
|
+
|
|
94
|
+
export function printEquation(equation: Equation): string {
|
|
95
|
+
switch (equation.type) {
|
|
96
|
+
case 'literal':
|
|
97
|
+
return equation.value.toString();
|
|
98
|
+
case 'add':
|
|
99
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' + ')})`;
|
|
100
|
+
case 'subtract':
|
|
101
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' - ')})`;
|
|
102
|
+
case 'multiply':
|
|
103
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' * ')})`;
|
|
104
|
+
case 'divide':
|
|
105
|
+
return `(${equation.values.map((v) => printEquation(v)).join(' / ')})`;
|
|
106
|
+
case 'clamp':
|
|
107
|
+
if (equation.values.length !== 3) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
'Clamp operation requires exactly 3 values: min, value, max',
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return `clamp(${equation.values
|
|
113
|
+
.map((v) => printEquation(v))
|
|
114
|
+
.join(', ')})`;
|
|
115
|
+
case 'cast':
|
|
116
|
+
return `(${printEquation(equation.value)} * ${
|
|
117
|
+
equation.unit === '%' ? '100%' : '1'
|
|
118
|
+
})`;
|
|
119
|
+
case 'function':
|
|
120
|
+
return `${equation.name}(${equation.args
|
|
121
|
+
.map((v) => printEquation(v))
|
|
122
|
+
.join(', ')})`;
|
|
123
|
+
case 'concatenate':
|
|
124
|
+
return equation.values
|
|
125
|
+
.map((v) => printEquation(v))
|
|
126
|
+
.join(equation.separator);
|
|
127
|
+
default:
|
|
128
|
+
throw new Error(`Unknown equation type: ${(equation as any).type}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type ComputationResult =
|
|
133
|
+
| {
|
|
134
|
+
type: 'numeric';
|
|
135
|
+
value: number;
|
|
136
|
+
unit: '%' | '';
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
type: 'calc';
|
|
140
|
+
value: string;
|
|
141
|
+
}
|
|
142
|
+
| {
|
|
143
|
+
type: 'concatenated';
|
|
144
|
+
value: string;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function add(a: ComputationResult, b: ComputationResult): ComputationResult {
|
|
148
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
149
|
+
return {
|
|
150
|
+
type: 'concatenated',
|
|
151
|
+
value: `${printComputationResult(a)} + ${printComputationResult(b)}`,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (a.value === 0) {
|
|
155
|
+
return b;
|
|
156
|
+
}
|
|
157
|
+
if (b.value === 0) {
|
|
158
|
+
return a;
|
|
159
|
+
}
|
|
160
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
161
|
+
return {
|
|
162
|
+
type: 'calc',
|
|
163
|
+
value: `calc(${printComputationResult(a)} + ${printComputationResult(
|
|
164
|
+
b,
|
|
165
|
+
)})`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return { type: 'numeric', value: a.value + b.value, unit: a.unit };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function subtract(
|
|
172
|
+
a: ComputationResult,
|
|
173
|
+
b: ComputationResult,
|
|
174
|
+
): ComputationResult {
|
|
175
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
176
|
+
return {
|
|
177
|
+
type: 'concatenated',
|
|
178
|
+
value: `${printComputationResult(a)} - ${printComputationResult(b)}`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (b.value === 0) {
|
|
182
|
+
return a;
|
|
183
|
+
}
|
|
184
|
+
if (a.value === 0 && b.type === 'numeric') {
|
|
185
|
+
return { type: 'numeric', value: -b.value, unit: b.unit };
|
|
186
|
+
}
|
|
187
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
188
|
+
return {
|
|
189
|
+
type: 'calc',
|
|
190
|
+
value: `calc(${printComputationResult(a)} - ${printComputationResult(
|
|
191
|
+
b,
|
|
192
|
+
)})`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return { type: 'numeric', value: a.value - b.value, unit: a.unit };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function multiply(
|
|
199
|
+
a: ComputationResult,
|
|
200
|
+
b: ComputationResult,
|
|
201
|
+
): ComputationResult {
|
|
202
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
203
|
+
return {
|
|
204
|
+
type: 'concatenated',
|
|
205
|
+
value: `${printComputationResult(a)} * ${printComputationResult(b)}`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (a.type === 'numeric' && a.value === 0) {
|
|
209
|
+
return { type: 'numeric', value: 0, unit: a.unit };
|
|
210
|
+
}
|
|
211
|
+
if (b.type === 'numeric' && b.value === 0) {
|
|
212
|
+
return { type: 'numeric', value: 0, unit: b.unit };
|
|
213
|
+
}
|
|
214
|
+
if (a.type === 'numeric' && a.value === 1) {
|
|
215
|
+
return b;
|
|
216
|
+
}
|
|
217
|
+
if (b.type === 'numeric' && b.value === 1) {
|
|
218
|
+
return a;
|
|
219
|
+
}
|
|
220
|
+
if (a.type === 'numeric' && a.unit === '%' && a.value === 100) {
|
|
221
|
+
return b;
|
|
222
|
+
}
|
|
223
|
+
if (b.type === 'numeric' && b.unit === '%' && b.value === 100) {
|
|
224
|
+
return a;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
228
|
+
return {
|
|
229
|
+
type: 'calc',
|
|
230
|
+
value: `calc(${printComputationResult(a)} * ${printComputationResult(
|
|
231
|
+
b,
|
|
232
|
+
)})`,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (a.unit === '%' && b.unit === '%') {
|
|
236
|
+
return { type: 'numeric', value: (a.value * b.value) / 100, unit: '%' };
|
|
237
|
+
}
|
|
238
|
+
const unit = a.unit === '%' || b.unit === '%' ? '%' : '';
|
|
239
|
+
return { type: 'numeric', value: a.value * b.value, unit };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function divide(a: ComputationResult, b: ComputationResult): ComputationResult {
|
|
243
|
+
if (a.type === 'concatenated' || b.type === 'concatenated') {
|
|
244
|
+
return {
|
|
245
|
+
type: 'concatenated',
|
|
246
|
+
value: `${printComputationResult(a)} / ${printComputationResult(b)}`,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (b.type === 'numeric' && b.value === 0) {
|
|
250
|
+
throw new Error('Division by zero');
|
|
251
|
+
}
|
|
252
|
+
if (a.type === 'numeric' && a.value === 0) {
|
|
253
|
+
return { type: 'numeric', value: 0, unit: a.unit };
|
|
254
|
+
}
|
|
255
|
+
if (b.type === 'numeric' && b.value === 1) {
|
|
256
|
+
return a;
|
|
257
|
+
}
|
|
258
|
+
if (a.type === 'calc' || b.type === 'calc' || a.unit !== b.unit) {
|
|
259
|
+
return {
|
|
260
|
+
type: 'calc',
|
|
261
|
+
value: `calc(${printComputationResult(a)} / ${printComputationResult(
|
|
262
|
+
b,
|
|
263
|
+
)})`,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (a.unit === '%' && b.unit === '%') {
|
|
267
|
+
return { type: 'numeric', value: a.value / b.value, unit: '' };
|
|
268
|
+
}
|
|
269
|
+
const unit = a.unit === '%' && b.unit === '' ? '%' : '';
|
|
270
|
+
return { type: 'numeric', value: a.value / b.value, unit };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function clamp(
|
|
274
|
+
value: ComputationResult,
|
|
275
|
+
min: ComputationResult,
|
|
276
|
+
max: ComputationResult,
|
|
277
|
+
): ComputationResult {
|
|
278
|
+
if (
|
|
279
|
+
value.type === 'concatenated' ||
|
|
280
|
+
min.type === 'concatenated' ||
|
|
281
|
+
max.type === 'concatenated'
|
|
282
|
+
) {
|
|
283
|
+
return {
|
|
284
|
+
type: 'concatenated',
|
|
285
|
+
value: `clamp(${printComputationResult(min)}, ${printComputationResult(
|
|
286
|
+
value,
|
|
287
|
+
)}, ${printComputationResult(max)})`,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (
|
|
291
|
+
value.type === 'calc' ||
|
|
292
|
+
min.type === 'calc' ||
|
|
293
|
+
max.type === 'calc' ||
|
|
294
|
+
value.unit !== min.unit ||
|
|
295
|
+
value.unit !== max.unit ||
|
|
296
|
+
min.unit !== max.unit
|
|
297
|
+
) {
|
|
298
|
+
return {
|
|
299
|
+
type: 'calc',
|
|
300
|
+
value: `calc(clamp(${printComputationResult(
|
|
301
|
+
min,
|
|
302
|
+
)}, ${printComputationResult(value)}, ${printComputationResult(max)}))`,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
type: 'numeric',
|
|
307
|
+
value: Math.min(Math.max(value.value, min.value), max.value),
|
|
308
|
+
unit: value.unit,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function cast(value: ComputationResult, unit: '%' | ''): ComputationResult {
|
|
313
|
+
if (value.type === 'concatenated') {
|
|
314
|
+
return {
|
|
315
|
+
type: 'concatenated',
|
|
316
|
+
value: `(${printComputationResult(value)} * ${
|
|
317
|
+
unit === '%' ? '100%' : '1'
|
|
318
|
+
})`,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (value.type === 'calc') {
|
|
322
|
+
return {
|
|
323
|
+
type: 'calc',
|
|
324
|
+
value: `calc(${printComputationResult(value)} * ${
|
|
325
|
+
unit === '%' ? '100%' : '1'
|
|
326
|
+
})`,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (unit === '%') {
|
|
330
|
+
if (value.unit === '%') {
|
|
331
|
+
return value;
|
|
332
|
+
}
|
|
333
|
+
return { type: 'numeric', value: value.value * 100, unit: '%' };
|
|
334
|
+
} else {
|
|
335
|
+
if (value.unit === '') {
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
338
|
+
return { type: 'numeric', value: value.value / 100, unit: '' };
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function numericToNumber(value: {
|
|
343
|
+
type: 'numeric';
|
|
344
|
+
value: number;
|
|
345
|
+
unit: string;
|
|
346
|
+
}): number {
|
|
347
|
+
if (value.unit === '%') {
|
|
348
|
+
return value.value / 100;
|
|
349
|
+
}
|
|
350
|
+
return value.value;
|
|
351
|
+
}
|
|
352
|
+
function fnCall(name: string, ...args: ComputationResult[]): ComputationResult {
|
|
353
|
+
// inline some functions if all args are numerics
|
|
354
|
+
if (args.every((arg) => arg.type === 'numeric')) {
|
|
355
|
+
const argsInOrderAsNumbers = args.map((arg) =>
|
|
356
|
+
numericToNumber(arg as Extract<ComputationResult, { type: 'numeric' }>),
|
|
357
|
+
);
|
|
358
|
+
switch (name) {
|
|
359
|
+
case 'sin':
|
|
360
|
+
return {
|
|
361
|
+
type: 'numeric',
|
|
362
|
+
value: Math.sin(argsInOrderAsNumbers[0]),
|
|
363
|
+
unit: '',
|
|
364
|
+
};
|
|
365
|
+
case 'cos':
|
|
366
|
+
return {
|
|
367
|
+
type: 'numeric',
|
|
368
|
+
value: Math.cos(argsInOrderAsNumbers[0]),
|
|
369
|
+
unit: '',
|
|
370
|
+
};
|
|
371
|
+
case 'tan':
|
|
372
|
+
return {
|
|
373
|
+
type: 'numeric',
|
|
374
|
+
value: Math.tan(argsInOrderAsNumbers[0]),
|
|
375
|
+
unit: '',
|
|
376
|
+
};
|
|
377
|
+
case 'min':
|
|
378
|
+
return {
|
|
379
|
+
type: 'numeric',
|
|
380
|
+
value: Math.min(...argsInOrderAsNumbers),
|
|
381
|
+
unit: '',
|
|
382
|
+
};
|
|
383
|
+
case 'max':
|
|
384
|
+
return {
|
|
385
|
+
type: 'numeric',
|
|
386
|
+
value: Math.max(...argsInOrderAsNumbers),
|
|
387
|
+
unit: '',
|
|
388
|
+
};
|
|
389
|
+
case 'pow':
|
|
390
|
+
return {
|
|
391
|
+
type: 'numeric',
|
|
392
|
+
value: Math.pow(argsInOrderAsNumbers[0], argsInOrderAsNumbers[1]),
|
|
393
|
+
unit: '',
|
|
394
|
+
};
|
|
395
|
+
case 'abs':
|
|
396
|
+
return {
|
|
397
|
+
type: 'numeric',
|
|
398
|
+
value: Math.abs(argsInOrderAsNumbers[0]),
|
|
399
|
+
unit: '',
|
|
400
|
+
};
|
|
401
|
+
case 'exp':
|
|
402
|
+
return {
|
|
403
|
+
type: 'numeric',
|
|
404
|
+
value: Math.exp(argsInOrderAsNumbers[0]),
|
|
405
|
+
unit: '',
|
|
406
|
+
};
|
|
407
|
+
case 'log':
|
|
408
|
+
return {
|
|
409
|
+
type: 'numeric',
|
|
410
|
+
value: Math.log(argsInOrderAsNumbers[0]),
|
|
411
|
+
unit: '',
|
|
412
|
+
};
|
|
413
|
+
default:
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const isConcatenated = args.some((arg) => arg.type === 'concatenated');
|
|
418
|
+
if (isConcatenated) {
|
|
419
|
+
return {
|
|
420
|
+
type: 'concatenated',
|
|
421
|
+
value: `${name}(${args.map(printComputationResult).join(', ')})`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
type: 'calc',
|
|
426
|
+
value: `${name}(${args.map(printComputationResult).join(', ')})`,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function printComputationResult(result: ComputationResult): string {
|
|
431
|
+
if (result.type === 'calc') {
|
|
432
|
+
return result.value;
|
|
433
|
+
}
|
|
434
|
+
if (result.type === 'concatenated') {
|
|
435
|
+
return result.value;
|
|
436
|
+
}
|
|
437
|
+
return result.unit === '%' ? `${result.value}%` : `${result.value}`;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function evaluateLiteral(
|
|
441
|
+
literal: string,
|
|
442
|
+
context: CalcEvaluationContext,
|
|
443
|
+
): ComputationResult {
|
|
444
|
+
if (literal.startsWith('var(')) {
|
|
445
|
+
const propertyName = literal.slice(4, -1).trim();
|
|
446
|
+
const propertyValue = context.propertyValues[propertyName];
|
|
447
|
+
if (!propertyValue || context.skipBaking) {
|
|
448
|
+
return { type: 'calc', value: literal };
|
|
449
|
+
} else {
|
|
450
|
+
// replace literal with known value from context
|
|
451
|
+
return evaluateLiteral(propertyValue, context);
|
|
452
|
+
}
|
|
453
|
+
} else if (literal === 'PI') {
|
|
454
|
+
return { type: 'numeric', value: Math.PI, unit: '' };
|
|
455
|
+
} else if (literal.endsWith('%')) {
|
|
456
|
+
const asNumber = Number(literal.slice(0, -1));
|
|
457
|
+
if (isNaN(asNumber)) {
|
|
458
|
+
throw new Error(`Literal value did not evaluate to a number: ${literal}`);
|
|
459
|
+
}
|
|
460
|
+
return { type: 'numeric', value: asNumber, unit: '%' };
|
|
461
|
+
} else {
|
|
462
|
+
const asNumber = Number(literal);
|
|
463
|
+
if (isNaN(asNumber)) {
|
|
464
|
+
return { type: 'calc', value: literal };
|
|
465
|
+
}
|
|
466
|
+
return { type: 'numeric', value: asNumber, unit: '' };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export function computeEquation(
|
|
471
|
+
equation: Equation,
|
|
472
|
+
userContext: CalcEvaluationContext,
|
|
473
|
+
): ComputationResult {
|
|
474
|
+
const context: CalcEvaluationContext = {
|
|
475
|
+
propertyValues: userContext.propertyValues,
|
|
476
|
+
// unless otherwise specified, we do NOT bake literal values when
|
|
477
|
+
// running in a browser - this makes a runtime-evaluated equation
|
|
478
|
+
// responsive to runtime-tweaked globals.
|
|
479
|
+
skipBaking: userContext.skipBaking ?? typeof window !== 'undefined',
|
|
480
|
+
};
|
|
481
|
+
switch (equation.type) {
|
|
482
|
+
case 'literal':
|
|
483
|
+
return evaluateLiteral(equation.value.toString(), context);
|
|
484
|
+
case 'add':
|
|
485
|
+
return equation.values.reduce<ComputationResult>(
|
|
486
|
+
(sum, v) => add(sum, computeEquation(v, context)),
|
|
487
|
+
{ type: 'numeric', value: 0, unit: '' },
|
|
488
|
+
);
|
|
489
|
+
case 'subtract':
|
|
490
|
+
if (equation.values.length === 0) {
|
|
491
|
+
return { type: 'numeric', value: 0, unit: '' };
|
|
492
|
+
}
|
|
493
|
+
const first = computeEquation(equation.values[0], context);
|
|
494
|
+
return equation.values
|
|
495
|
+
.slice(1)
|
|
496
|
+
.reduce(
|
|
497
|
+
(difference, v) => subtract(difference, computeEquation(v, context)),
|
|
498
|
+
first,
|
|
499
|
+
);
|
|
500
|
+
case 'multiply':
|
|
501
|
+
return equation.values.reduce<ComputationResult>(
|
|
502
|
+
(product, v) => multiply(product, computeEquation(v, context)),
|
|
503
|
+
{ type: 'numeric', value: 1, unit: '' },
|
|
504
|
+
);
|
|
505
|
+
case 'divide':
|
|
506
|
+
if (equation.values.length !== 2) {
|
|
507
|
+
throw new Error('Divide operation requires exactly 2 values');
|
|
508
|
+
}
|
|
509
|
+
const numerator = computeEquation(equation.values[0], context);
|
|
510
|
+
const denominator = computeEquation(equation.values[1], context);
|
|
511
|
+
return divide(numerator, denominator);
|
|
512
|
+
case 'clamp':
|
|
513
|
+
if (equation.values.length !== 3) {
|
|
514
|
+
throw new Error(
|
|
515
|
+
'Clamp operation requires exactly 3 values: min, value, max',
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
const min = computeEquation(equation.values[0], context);
|
|
519
|
+
const value = computeEquation(equation.values[1], context);
|
|
520
|
+
const max = computeEquation(equation.values[2], context);
|
|
521
|
+
return clamp(value, min, max);
|
|
522
|
+
case 'cast':
|
|
523
|
+
const innerValue = computeEquation(equation.value, context);
|
|
524
|
+
return cast(innerValue, equation.unit);
|
|
525
|
+
case 'function':
|
|
526
|
+
const args = equation.args.map((arg) => computeEquation(arg, context));
|
|
527
|
+
return fnCall(equation.name, ...args);
|
|
528
|
+
case 'concatenate':
|
|
529
|
+
const concatenatedValues = equation.values.map((v) =>
|
|
530
|
+
printComputationResult(computeEquation(v, context)),
|
|
531
|
+
);
|
|
532
|
+
return {
|
|
533
|
+
type: 'concatenated',
|
|
534
|
+
value: concatenatedValues.join(equation.separator),
|
|
535
|
+
};
|
|
536
|
+
default:
|
|
537
|
+
throw new Error(`Unknown equation type: ${(equation as any).type}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fileNames":["../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2023.collection.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2023.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.collection.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.object.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.regexp.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2024.string.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.collection.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.float16.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.iterator.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.promise.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2025.regexp.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.array.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.collection.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.date.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.error.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.temporal.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.typedarrays.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","./src/index.ts"],"fileInfos":[{"version":"bcd24271a113971ba9eb71ff8cb01bc6b0f872a85c23fdbe5d93065b375933cd","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f88bedbeb09c6f5a6645cb24c7c55f1aa22d19ae96c8e6959cbd8b85a707bc6","impliedFormat":1},{"version":"7fe93b39b810eadd916be8db880dd7f0f7012a5cc6ffb62de8f62a2117fa6f1f","impliedFormat":1},{"version":"bb0074cc08b84a2374af33d8bf044b80851ccc9e719a5e202eacf40db2c31600","impliedFormat":1},{"version":"1a7daebe4f45fb03d9ec53d60008fbf9ac45a697fdc89e4ce218bc94b94f94d6","impliedFormat":1},{"version":"f94b133a3cb14a288803be545ac2683e0d0ff6661bcd37e31aaaec54fc382aed","impliedFormat":1},{"version":"f59d0650799f8782fd74cf73c19223730c6d1b9198671b1c5b3a38e1188b5953","impliedFormat":1},{"version":"8a15b4607d9a499e2dbeed9ec0d3c0d7372c850b2d5f1fb259e8f6d41d468a84","impliedFormat":1},{"version":"26e0fe14baee4e127f4365d1ae0b276f400562e45e19e35fd2d4c296684715e6","impliedFormat":1},{"version":"1e9332c23e9a907175e0ffc6a49e236f97b48838cc8aec9ce7e4cec21e544b65","impliedFormat":1},{"version":"3753fbc1113dc511214802a2342280a8b284ab9094f6420e7aa171e868679f91","impliedFormat":1},{"version":"999ca32883495a866aa5737fe1babc764a469e4cde6ee6b136a4b9ae68853e4b","impliedFormat":1},{"version":"17f13ecb98cbc39243f2eee1f16d45cd8ec4706b03ee314f1915f1a8b42f6984","impliedFormat":1},{"version":"d6b1eba8496bdd0eed6fc8a685768fe01b2da4a0388b5fe7df558290bffcf32f","affectsGlobalScope":true,"impliedFormat":1},{"version":"eadcffda2aa84802c73938e589b9e58248d74c59cb7fcbca6474e3435ac15504","affectsGlobalScope":true,"impliedFormat":1},{"version":"105ba8ff7ba746404fe1a2e189d1d3d2e0eb29a08c18dded791af02f29fb4711","affectsGlobalScope":true,"impliedFormat":1},{"version":"00343ca5b2e3d48fa5df1db6e32ea2a59afab09590274a6cccb1dbae82e60c7c","affectsGlobalScope":true,"impliedFormat":1},{"version":"ebd9f816d4002697cb2864bea1f0b70a103124e18a8cd9645eeccc09bdf80ab4","affectsGlobalScope":true,"impliedFormat":1},{"version":"2c1afac30a01772cd2a9a298a7ce7706b5892e447bb46bdbeef720f7b5da77ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"7b0225f483e4fa685625ebe43dd584bb7973bbd84e66a6ba7bbe175ee1048b4f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c0a4b8ac6ce74679c1da2b3795296f5896e31c38e888469a8e0f99dc3305de60","affectsGlobalScope":true,"impliedFormat":1},{"version":"3084a7b5f569088e0146533a00830e206565de65cae2239509168b11434cd84f","affectsGlobalScope":true,"impliedFormat":1},{"version":"c5079c53f0f141a0698faa903e76cb41cd664e3efb01cc17a5c46ec2eb0bef42","affectsGlobalScope":true,"impliedFormat":1},{"version":"32cafbc484dea6b0ab62cf8473182bbcb23020d70845b406f80b7526f38ae862","affectsGlobalScope":true,"impliedFormat":1},{"version":"fca4cdcb6d6c5ef18a869003d02c9f0fd95df8cfaf6eb431cd3376bc034cad36","affectsGlobalScope":true,"impliedFormat":1},{"version":"b93ec88115de9a9dc1b602291b85baf825c85666bf25985cc5f698073892b467","affectsGlobalScope":true,"impliedFormat":1},{"version":"f5c06dcc3fe849fcb297c247865a161f995cc29de7aa823afdd75aaaddc1419b","affectsGlobalScope":true,"impliedFormat":1},{"version":"b77e16112127a4b169ef0b8c3a4d730edf459c5f25fe52d5e436a6919206c4d7","affectsGlobalScope":true,"impliedFormat":1},{"version":"fbffd9337146eff822c7c00acbb78b01ea7ea23987f6c961eba689349e744f8c","affectsGlobalScope":true,"impliedFormat":1},{"version":"a995c0e49b721312f74fdfb89e4ba29bd9824c770bbb4021d74d2bf560e4c6bd","affectsGlobalScope":true,"impliedFormat":1},{"version":"c7b3542146734342e440a84b213384bfa188835537ddbda50d30766f0593aff9","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce6180fa19b1cccd07ee7f7dbb9a367ac19c0ed160573e4686425060b6df7f57","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f02e2476bccb9dbe21280d6090f0df17d2f66b74711489415a8aa4df73c9675","affectsGlobalScope":true,"impliedFormat":1},{"version":"45e3ab34c1c013c8ab2dc1ba4c80c780744b13b5676800ae2e3be27ae862c40c","affectsGlobalScope":true,"impliedFormat":1},{"version":"805c86f6cca8d7702a62a844856dbaa2a3fd2abef0536e65d48732441dde5b5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"e42e397f1a5a77994f0185fd1466520691456c772d06bf843e5084ceb879a0ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"f4c2b41f90c95b1c532ecc874bd3c111865793b23aebcc1c3cbbabcd5d76ffb0","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab26191cfad5b66afa11b8bf935ef1cd88fabfcb28d30b2dfa6fad877d050332","affectsGlobalScope":true,"impliedFormat":1},{"version":"2088bc26531e38fb05eedac2951480db5309f6be3fa4a08d2221abb0f5b4200d","affectsGlobalScope":true,"impliedFormat":1},{"version":"cb9d366c425fea79716a8fb3af0d78e6b22ebbab3bd64d25063b42dc9f531c1e","affectsGlobalScope":true,"impliedFormat":1},{"version":"500934a8089c26d57ebdb688fc9757389bb6207a3c8f0674d68efa900d2abb34","affectsGlobalScope":true,"impliedFormat":1},{"version":"689da16f46e647cef0d64b0def88910e818a5877ca5379ede156ca3afb780ac3","affectsGlobalScope":true,"impliedFormat":1},{"version":"bc21cc8b6fee4f4c2440d08035b7ea3c06b3511314c8bab6bef7a92de58a2593","affectsGlobalScope":true,"impliedFormat":1},{"version":"7ca53d13d2957003abb47922a71866ba7cb2068f8d154877c596d63c359fed25","affectsGlobalScope":true,"impliedFormat":1},{"version":"54725f8c4df3d900cb4dac84b64689ce29548da0b4e9b7c2de61d41c79293611","affectsGlobalScope":true,"impliedFormat":1},{"version":"e5594bc3076ac29e6c1ebda77939bc4c8833de72f654b6e376862c0473199323","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f3eb332c2d73e729f3364fcc0c2b375e72a121e8157d25a82d67a138c83a95c","affectsGlobalScope":true,"impliedFormat":1},{"version":"6f4427f9642ce8d500970e4e69d1397f64072ab73b97e476b4002a646ac743b1","affectsGlobalScope":true,"impliedFormat":1},{"version":"48915f327cd1dea4d7bd358d9dc7732f58f9e1626a29cc0c05c8c692419d9bb7","affectsGlobalScope":true,"impliedFormat":1},{"version":"b7bf9377723203b5a6a4b920164df22d56a43f593269ba6ae1fdc97774b68855","affectsGlobalScope":true,"impliedFormat":1},{"version":"db9709688f82c9e5f65a119c64d835f906efe5f559d08b11642d56eb85b79357","affectsGlobalScope":true,"impliedFormat":1},{"version":"4b25b8c874acd1a4cf8444c3617e037d444d19080ac9f634b405583fd10ce1f7","affectsGlobalScope":true,"impliedFormat":1},{"version":"37be57d7c90cf1f8112ee2636a068d8fd181289f82b744160ec56a7dc158a9f5","affectsGlobalScope":true,"impliedFormat":1},{"version":"a917a49ac94cd26b754ab84e113369a75d1a47a710661d7cd25e961cc797065f","affectsGlobalScope":true,"impliedFormat":1},{"version":"6d3261badeb7843d157ef3e6f5d1427d0eeb0af0cf9df84a62cfd29fd47ac86e","affectsGlobalScope":true,"impliedFormat":1},{"version":"195daca651dde22f2167ac0d0a05e215308119a3100f5e6268e8317d05a92526","affectsGlobalScope":true,"impliedFormat":1},{"version":"8b11e4285cd2bb164a4dc09248bdec69e9842517db4ca47c1ba913011e44ff2f","affectsGlobalScope":true,"impliedFormat":1},{"version":"0508571a52475e245b02bc50fa1394065a0a3d05277fbf5120c3784b85651799","affectsGlobalScope":true,"impliedFormat":1},{"version":"8f9af488f510c3015af3cc8c267a9e9d96c4dd38a1fdff0e11dc5a544711415b","affectsGlobalScope":true,"impliedFormat":1},{"version":"fc611fea8d30ea72c6bbfb599c9b4d393ce22e2f5bfef2172534781e7d138104","affectsGlobalScope":true,"impliedFormat":1},{"version":"0bd714129fca875f7d4c477a1a392200b0bcd13fb2e80928cd334b63830ea047","affectsGlobalScope":true,"impliedFormat":1},{"version":"e2c9037ae6cd2c52d80ceef0b3c5ffdb488627d71529cf4f63776daf11161c9a","affectsGlobalScope":true,"impliedFormat":1},{"version":"135d5cf4d345f59f1a9caadfafcd858d3d9cc68290db616cc85797224448cccc","affectsGlobalScope":true,"impliedFormat":1},{"version":"bc238c3f81c2984751932b6aab223cd5b830e0ac6cad76389e5e9d2ffc03287d","affectsGlobalScope":true,"impliedFormat":1},{"version":"4a07f9b76d361f572620927e5735b77d6d2101c23cdd94383eb5b706e7b36357","affectsGlobalScope":true,"impliedFormat":1},{"version":"7c4e8dc6ab834cc6baa0227e030606d29e3e8449a9f67cdf5605ea5493c4db29","affectsGlobalScope":true,"impliedFormat":1},{"version":"de7ba0fd02e06cd9a5bd4ab441ed0e122735786e67dde1e849cced1cd8b46b78","affectsGlobalScope":true,"impliedFormat":1},{"version":"6148e4e88d720a06855071c3db02069434142a8332cf9c182cda551adedf3156","affectsGlobalScope":true,"impliedFormat":1},{"version":"d63dba625b108316a40c95a4425f8d4294e0deeccfd6c7e59d819efa19e23409","affectsGlobalScope":true,"impliedFormat":1},{"version":"0568d6befee03dd435bed4fc25c4e46865b24bdcb8c563fdc21f580a2c301904","affectsGlobalScope":true,"impliedFormat":1},{"version":"30d62269b05b584741f19a5369852d5d34895aa2ac4fd948956f886d15f9cc0d","affectsGlobalScope":true,"impliedFormat":1},{"version":"f128dae7c44d8f35ee42e0a437000a57c9f06cc04f8b4fb42eebf44954d53dc8","affectsGlobalScope":true,"impliedFormat":1},{"version":"ffbe6d7b295306b2ba88030f65b74c107d8d99bdcf596ea99c62a02f606108b0","affectsGlobalScope":true,"impliedFormat":1},{"version":"996fb27b15277369c68a4ba46ed138b4e9e839a02fb4ec756f7997629242fd9f","affectsGlobalScope":true,"impliedFormat":1},{"version":"79b712591b270d4778c89706ca2cfc56ddb8c3f895840e477388f1710dc5eda9","affectsGlobalScope":true,"impliedFormat":1},{"version":"20884846cef428b992b9bd032e70a4ef88e349263f63aeddf04dda837a7dba26","affectsGlobalScope":true,"impliedFormat":1},{"version":"5fcab789c73a97cd43828ee3cc94a61264cf24d4c44472ce64ced0e0f148bdb2","affectsGlobalScope":true,"impliedFormat":1},{"version":"db59a81f070c1880ad645b2c0275022baa6a0c4f0acdc58d29d349c6efcf0903","affectsGlobalScope":true,"impliedFormat":1},{"version":"673294292640f5722b700e7d814e17aaf7d93f83a48a2c9b38f33cbc940ad8b0","affectsGlobalScope":true,"impliedFormat":1},{"version":"d786b48f934cbca483b3c6d0a798cb43bbb4ada283e76fb22c28e53ae05b9e69","affectsGlobalScope":true,"impliedFormat":1},{"version":"1ecb8e347cb6b2a8927c09b86263663289418df375f5e68e11a0ae683776978f","affectsGlobalScope":true,"impliedFormat":1},{"version":"142efd4ce210576f777dc34df121777be89eda476942d6d6663b03dcb53be3ff","affectsGlobalScope":true,"impliedFormat":1},{"version":"379bc41580c2d774f82e828c70308f24a005b490c25ba34d679d84bcf05c3d9d","affectsGlobalScope":true,"impliedFormat":1},{"version":"ed484fb2aa8a1a23d0277056ec3336e0a0b52f9b8d6a961f338a642faf43235d","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ffedae1d1c2d53fdbca1c96d3c7dda544281f7d262f99b6880634f8fd8d9820","affectsGlobalScope":true,"impliedFormat":1},{"version":"83a730b125d477dd264df8ba479afab27a3dae7152b005c214ab94dc7ee44fd3","affectsGlobalScope":true,"impliedFormat":1},{"version":"1ce14b81c5cc821994aa8ec1d42b220dd41b27fcc06373bce3958af7421b77d4","affectsGlobalScope":true,"impliedFormat":1},{"version":"b3a048b3e9302ef9a34ef4ebb9aecfb28b66abb3bce577206a79fee559c230da","affectsGlobalScope":true,"impliedFormat":1},{"version":"59f35ec475c3905ba299f58cbce4010d73db3e86d6604355d053e77643c0f816","signature":"c2e6b6444f9d7a4cba927a9db92ac169c9e23208b977e721744cff020f034fd7","impliedFormat":99}],"root":[89],"options":{"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"module":199,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":7},"latestChangedDtsFile":"./dist/index.d.ts","version":"6.0.3"}
|