fashionable 0.2.0 → 0.4.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/calc/index.d.mts +1 -1
- package/dist/calc/index.mjs +1 -1
- package/dist/data/index.d.mts +2 -208
- package/dist/data/index.mjs +73 -54
- package/dist/data/index.mjs.map +1 -1
- package/dist/declaration/index.d.mts +1 -1
- package/dist/declaration/index.mjs +9 -28
- package/dist/declaration/index.mjs.map +1 -1
- package/dist/fontFace/index.d.mts +1 -1
- package/dist/property/index.d.mts +1 -1
- package/dist/property/index.mjs +1 -1
- package/dist/property/index.mjs.map +1 -1
- package/dist/query/index.d.mts +1 -1
- package/dist/query/index.mjs +137 -3
- package/dist/query/index.mjs.map +1 -1
- package/dist/rule/index.d.mts +1 -1
- package/dist/rule/index.mjs +45 -33
- package/dist/rule/index.mjs.map +1 -1
- package/dist/selector/index.d.mts +1 -1
- package/dist/selector/index.mjs +117 -21
- package/dist/selector/index.mjs.map +1 -1
- package/dist/shared/{calc-Cih4o2r7.mjs → calc-Uwbxd7CS.mjs} +233 -165
- package/dist/shared/calc-Uwbxd7CS.mjs.map +1 -0
- package/dist/shared/{color.internal-Dts5ycTm.mjs → color.internal-CxjlaRqR.mjs} +48 -13
- package/dist/shared/color.internal-CxjlaRqR.mjs.map +1 -0
- package/dist/shared/declaration-CqRm38oZ.d.mts +264 -0
- package/dist/shared/declaration.internal-bHzvbanA.mjs +121 -0
- package/dist/shared/declaration.internal-bHzvbanA.mjs.map +1 -0
- package/dist/shared/{fontFaceRule-C7nYgH6X.d.mts → fontFaceRule-BOgUM4PF.d.mts} +3 -3
- package/dist/shared/index-D-hVWDgZ.d.mts +2289 -0
- package/dist/shared/mediaQuery-VDIAHnM1.d.mts +333 -0
- package/dist/shared/{mediaQuery.internal-B6iuMd75.mjs → mediaQuery.internal-CKTmLVxL.mjs} +70 -6
- package/dist/shared/mediaQuery.internal-CKTmLVxL.mjs.map +1 -0
- package/dist/shared/{mediaRule-BDB4WCYy.d.mts → mediaRule-2K7Ggwe4.d.mts} +169 -105
- package/dist/shared/{propertyRule-BbkFh9b9.d.mts → propertyRule-B9ii0mv4.d.mts} +56 -21
- package/dist/shared/{propertyRule.internal-Bc_HrfcL.mjs → propertyRule.internal-ncYCWUar.mjs} +31 -4
- package/dist/shared/propertyRule.internal-ncYCWUar.mjs.map +1 -0
- package/dist/shared/{ruleSet.internal-DodzVMUU.mjs → ruleSet.internal-Cj4yIYFI.mjs} +31 -18
- package/dist/shared/ruleSet.internal-Cj4yIYFI.mjs.map +1 -0
- package/dist/shared/selector-BkxnzX_6.d.mts +615 -0
- package/dist/shared/{selector.internal-ESe9s0IH.mjs → selector.internal-B3iu_RpX.mjs} +144 -30
- package/dist/shared/selector.internal-B3iu_RpX.mjs.map +1 -0
- package/dist/shared/{utils-BKm298I-.d.mts → utils-DpN6qr94.d.mts} +4 -4
- package/dist/shared/var.internal-DSxAzEFN.mjs +119 -0
- package/dist/shared/var.internal-DSxAzEFN.mjs.map +1 -0
- package/dist/stylesheet/index.d.mts +93 -60
- package/dist/stylesheet/index.mjs +111 -35
- package/dist/stylesheet/index.mjs.map +1 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.mjs.map +1 -1
- package/dist/var/index.d.mts +2 -0
- package/dist/var/index.mjs +177 -0
- package/dist/var/index.mjs.map +1 -0
- package/package.json +8 -2
- package/dist/shared/calc-Cih4o2r7.mjs.map +0 -1
- package/dist/shared/color-BvNJ2YqL.d.mts +0 -590
- package/dist/shared/color.internal-Dts5ycTm.mjs.map +0 -1
- package/dist/shared/declaration-1DlO_ltT.d.mts +0 -166
- package/dist/shared/declaration.internal-wLB4ssxC.mjs +0 -73
- package/dist/shared/declaration.internal-wLB4ssxC.mjs.map +0 -1
- package/dist/shared/index-BvtwY4FQ.d.mts +0 -841
- package/dist/shared/mediaQuery-BYR1z-iD.d.mts +0 -145
- package/dist/shared/mediaQuery.internal-B6iuMd75.mjs.map +0 -1
- package/dist/shared/propertyRule.internal-Bc_HrfcL.mjs.map +0 -1
- package/dist/shared/ruleSet.internal-DodzVMUU.mjs.map +0 -1
- package/dist/shared/selector-HZY-W6l6.d.mts +0 -346
- package/dist/shared/selector.internal-ESe9s0IH.mjs.map +0 -1
|
@@ -0,0 +1,2289 @@
|
|
|
1
|
+
import { t as Pipeable } from "./utils-DpN6qr94.mjs";
|
|
2
|
+
//#region src/calc/precision.internal.d.ts
|
|
3
|
+
declare const PrecisionTypeId: unique symbol;
|
|
4
|
+
type PrecisionTypeId = typeof PrecisionTypeId;
|
|
5
|
+
declare namespace precision_d_exports {
|
|
6
|
+
export { Precision, decimals, isPrecision, significant };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A number-formatting precision, attached to constants at construction
|
|
10
|
+
* (`Calc.of`) or supplied as a serialization context default
|
|
11
|
+
* (`Calc.serialize`'s `precision` option).
|
|
12
|
+
*
|
|
13
|
+
* Two modes exist. `decimals` fixes the count of digits after the decimal
|
|
14
|
+
* point (`toFixed` semantics); `significant` fixes the count of significant
|
|
15
|
+
* digits (`toPrecision` semantics). Both render plain decimal text with
|
|
16
|
+
* trailing zeros trimmed — CSS never accepts exponent notation.
|
|
17
|
+
*
|
|
18
|
+
* A precision annotated on a constant overrides the serialization context.
|
|
19
|
+
* When constant folding combines annotated constants, the result carries
|
|
20
|
+
* the highest-fidelity annotation among the operands: any `significant`
|
|
21
|
+
* outranks any `decimals`, and more digits outrank fewer.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
*/
|
|
25
|
+
interface Precision extends Pipeable {
|
|
26
|
+
readonly [PrecisionTypeId]: PrecisionTypeId;
|
|
27
|
+
/**
|
|
28
|
+
* The formatting mode: digits after the decimal point (`decimals`) or
|
|
29
|
+
* significant digits (`significant`).
|
|
30
|
+
*/
|
|
31
|
+
readonly mode: 'decimals' | 'significant';
|
|
32
|
+
/**
|
|
33
|
+
* The digit count the mode fixes.
|
|
34
|
+
*/
|
|
35
|
+
readonly digits: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a value is a `Precision`.
|
|
39
|
+
*
|
|
40
|
+
* True only for values built by `decimals` or `significant`, which carry
|
|
41
|
+
* the brand.
|
|
42
|
+
*
|
|
43
|
+
* @param u - The value to check.
|
|
44
|
+
* @returns `true` if the value is a `Precision`, `false` otherwise.
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
*/
|
|
47
|
+
declare const isPrecision: (u: unknown) => u is Precision;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a `Precision` fixing the count of digits after the decimal
|
|
50
|
+
* point. The library default for unannotated constants is `decimals(5)`.
|
|
51
|
+
*
|
|
52
|
+
* @param digits - Digits after the decimal point. Must be an integer in `[0, 100]`.
|
|
53
|
+
* @returns A `Precision` in `decimals` mode.
|
|
54
|
+
* @throws `Error` when `digits` is not an integer in `[0, 100]`.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* Calc.serialize(Calc.of(1 / 3), { precision: Precision.decimals(2) }) // '0.33'
|
|
58
|
+
* ```
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
declare const decimals: (digits: number) => Precision;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a `Precision` fixing the count of significant digits. Use it for
|
|
64
|
+
* unit-free constants whose error is amplified downstream — solved curve
|
|
65
|
+
* coefficients, for example — where fixed decimal places would truncate.
|
|
66
|
+
*
|
|
67
|
+
* @param digits - Significant digits. Must be an integer in `[1, 100]`.
|
|
68
|
+
* @returns A `Precision` in `significant` mode.
|
|
69
|
+
* @throws `Error` when `digits` is not an integer in `[1, 100]`.
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const k = Calc.of(0.8377580409572781, Precision.significant(10))
|
|
73
|
+
* Calc.serialize(k) // '0.837758041'
|
|
74
|
+
* ```
|
|
75
|
+
* @since 0.1.0
|
|
76
|
+
*/
|
|
77
|
+
declare const significant: (digits: number) => Precision;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/var/var.internal.d.ts
|
|
80
|
+
declare const VarTypeId: unique symbol;
|
|
81
|
+
type VarTypeId = typeof VarTypeId;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/calc/calc.internal.d.ts
|
|
84
|
+
declare const CalcTypeId: unique symbol;
|
|
85
|
+
type CalcTypeId = typeof CalcTypeId;
|
|
86
|
+
declare namespace unit_d_exports {
|
|
87
|
+
export { AbsoluteLength, Angle$1 as Angle, Any$1 as Any, ContextFree, Deg, Em, Family, Length$1 as Length, LengthPercentage$1 as LengthPercentage, None$1 as None, Percent, Percentage$1 as Percentage, Px, Rad, Relative, Rem, Token, UnitContext, Vh, Vmax, Vmin, Vw };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The unit vocabulary: the brands `Calc` carries in both its `Result` and
|
|
91
|
+
* `Requires` parameters. Each unit is a distinct nominal type carrying its CSS
|
|
92
|
+
* token, keyed by a per-dimension `unique symbol` so a length unit and an
|
|
93
|
+
* angle unit never unify — that nominal split is what lets `solve` demand a
|
|
94
|
+
* ratio for viewport-relative units while leaving absolute ones alone.
|
|
95
|
+
*
|
|
96
|
+
* You rarely name a unit type directly — `Length.px(10)` and `Angle.rad(2)`
|
|
97
|
+
* stamp them — but they surface in `Calc<Vars, Result, Requires>` hovers: the
|
|
98
|
+
* `Result` side as the units the expression's value is composed from
|
|
99
|
+
* (`Unit.Px | Unit.Vw` for a mixed sum, `Unit.None` for a `<number>`), the
|
|
100
|
+
* `Requires` side as the ratios `solve` may need.
|
|
101
|
+
*
|
|
102
|
+
* Units share the `Requires` parameter with the other requirement brand,
|
|
103
|
+
* `Calc.Ident` — the bare-identifier tokens supplied by value through the
|
|
104
|
+
* `idents` section of the solve options, where a unit is supplied by ratio
|
|
105
|
+
* through `units`.
|
|
106
|
+
*
|
|
107
|
+
* @since 0.2.0
|
|
108
|
+
*/
|
|
109
|
+
declare const LengthUnitId: unique symbol;
|
|
110
|
+
declare const AngleUnitId: unique symbol;
|
|
111
|
+
declare const PercentageUnitId: unique symbol;
|
|
112
|
+
declare const NoneUnitId: unique symbol;
|
|
113
|
+
/**
|
|
114
|
+
* The `px` unit (absolute length).
|
|
115
|
+
*
|
|
116
|
+
* @since 0.2.0
|
|
117
|
+
*/
|
|
118
|
+
interface Px {
|
|
119
|
+
readonly [LengthUnitId]: 'px';
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The `rem` unit (length relative to the root font size).
|
|
123
|
+
*
|
|
124
|
+
* @since 0.2.0
|
|
125
|
+
*/
|
|
126
|
+
interface Rem {
|
|
127
|
+
readonly [LengthUnitId]: 'rem';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The `em` unit (length relative to the element font size).
|
|
131
|
+
*
|
|
132
|
+
* @since 0.2.0
|
|
133
|
+
*/
|
|
134
|
+
interface Em {
|
|
135
|
+
readonly [LengthUnitId]: 'em';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The `vw` unit (length relative to 1% of viewport width).
|
|
139
|
+
*
|
|
140
|
+
* @since 0.2.0
|
|
141
|
+
*/
|
|
142
|
+
interface Vw {
|
|
143
|
+
readonly [LengthUnitId]: 'vw';
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The `vh` unit (length relative to 1% of viewport height).
|
|
147
|
+
*
|
|
148
|
+
* @since 0.2.0
|
|
149
|
+
*/
|
|
150
|
+
interface Vh {
|
|
151
|
+
readonly [LengthUnitId]: 'vh';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The `vmin` unit (length relative to 1% of the smaller viewport axis).
|
|
155
|
+
*
|
|
156
|
+
* @since 0.2.0
|
|
157
|
+
*/
|
|
158
|
+
interface Vmin {
|
|
159
|
+
readonly [LengthUnitId]: 'vmin';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The `vmax` unit (length relative to 1% of the larger viewport axis).
|
|
163
|
+
*
|
|
164
|
+
* @since 0.2.0
|
|
165
|
+
*/
|
|
166
|
+
interface Vmax {
|
|
167
|
+
readonly [LengthUnitId]: 'vmax';
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The `rad` unit (angle in radians).
|
|
171
|
+
*
|
|
172
|
+
* @since 0.2.0
|
|
173
|
+
*/
|
|
174
|
+
interface Rad {
|
|
175
|
+
readonly [AngleUnitId]: 'rad';
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The `deg` unit (angle in degrees). Degrees lower to radians at solve
|
|
179
|
+
* (`180deg` is `pi`), a fixed ratio, so like `rad` a degree needs no context.
|
|
180
|
+
*
|
|
181
|
+
* @since 0.2.0
|
|
182
|
+
*/
|
|
183
|
+
interface Deg {
|
|
184
|
+
readonly [AngleUnitId]: 'deg';
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The `%` unit (percentage). Keyed by its own dimension symbol, so a
|
|
188
|
+
* percentage never unifies with a length or an angle — a `<percentage>`
|
|
189
|
+
* is its own `Calc` kind, not a length that happens to be relative.
|
|
190
|
+
*
|
|
191
|
+
* @since 0.2.0
|
|
192
|
+
*/
|
|
193
|
+
interface Percent {
|
|
194
|
+
readonly [PercentageUnitId]: '%';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Any `<length>` unit.
|
|
198
|
+
*
|
|
199
|
+
* @since 0.2.0
|
|
200
|
+
*/
|
|
201
|
+
type Length$1 = Px | Rem | Em | Vw | Vh | Vmin | Vmax;
|
|
202
|
+
/**
|
|
203
|
+
* Any `<angle>` unit.
|
|
204
|
+
*
|
|
205
|
+
* @since 0.2.0
|
|
206
|
+
*/
|
|
207
|
+
type Angle$1 = Rad | Deg;
|
|
208
|
+
/**
|
|
209
|
+
* Any `<percentage>` unit. There is only one (`%`); the alias exists for
|
|
210
|
+
* symmetry with `Length` and `Angle`, so `Calc<never, Unit.Percentage, ...>`
|
|
211
|
+
* reads uniformly.
|
|
212
|
+
*
|
|
213
|
+
* @since 0.2.0
|
|
214
|
+
*/
|
|
215
|
+
type Percentage$1 = Percent;
|
|
216
|
+
/**
|
|
217
|
+
* The absent unit: the `Result` of a `<number>` expression. A brand rather
|
|
218
|
+
* than a bare marker so it slots into the same algebra as the real units —
|
|
219
|
+
* `Family<None>` is `None`, and a `None`-result operand is what `multiply`
|
|
220
|
+
* and `pow` mean by "a number."
|
|
221
|
+
*
|
|
222
|
+
* @since 0.4.0
|
|
223
|
+
*/
|
|
224
|
+
interface None$1 {
|
|
225
|
+
readonly [NoneUnitId]: 'none';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Any `<length-percentage>` unit: the length units plus `%`. The Result of
|
|
229
|
+
* a mixed expression (`calc(100% - 24px)`) and the family a declared
|
|
230
|
+
* `<length-percentage>` variable reads as. Mixing requires the anchor: the
|
|
231
|
+
* algebra admits a length or a percentage operand beside a
|
|
232
|
+
* length-percentage expression, while a bare `px + %` sum (no anchor
|
|
233
|
+
* naming the destination type) stays a type error.
|
|
234
|
+
*
|
|
235
|
+
* @since 0.4.0
|
|
236
|
+
*/
|
|
237
|
+
type LengthPercentage$1 = Length$1 | Percentage$1;
|
|
238
|
+
/**
|
|
239
|
+
* The whole `Result` domain: every unit, plus `None` for numbers. The top of
|
|
240
|
+
* the parameter — `Calc.Top` and the widest signatures use it where they once
|
|
241
|
+
* used `Kind`.
|
|
242
|
+
*
|
|
243
|
+
* @since 0.4.0
|
|
244
|
+
*/
|
|
245
|
+
type Any$1 = Length$1 | Angle$1 | Percentage$1 | None$1;
|
|
246
|
+
/**
|
|
247
|
+
* A unit widened to its dimension family — `Family<Unit.Px>` is
|
|
248
|
+
* `Unit.Length`, `Family<Unit.None>` is `Unit.None`. This is the
|
|
249
|
+
* specification's own type algebra as a projection of `Result`: CSS
|
|
250
|
+
* type-checks `calc()` at the dimension level, so the same-dimension operand
|
|
251
|
+
* constraints compare families, never single units. Distributes over unions
|
|
252
|
+
* (`Family<Unit.Px | Unit.Vw>` is `Unit.Length`).
|
|
253
|
+
*
|
|
254
|
+
* @since 0.4.0
|
|
255
|
+
*/
|
|
256
|
+
type Family<U> = U extends Length$1 ? Length$1 : U extends Angle$1 ? Angle$1 : U extends Percentage$1 ? Percentage$1 : None$1;
|
|
257
|
+
/**
|
|
258
|
+
* The context-dependent length units — those whose pixel ratio depends on the
|
|
259
|
+
* viewport or a font size, so `solve` requires a `units` entry for each.
|
|
260
|
+
*
|
|
261
|
+
* @since 0.2.0
|
|
262
|
+
*/
|
|
263
|
+
type Relative = Rem | Em | Vw | Vh | Vmin | Vmax;
|
|
264
|
+
/**
|
|
265
|
+
* The absolute length units, whose pixel ratio is fixed (`px` is `1`). The
|
|
266
|
+
* `units` section of the solve options may override them but need not supply
|
|
267
|
+
* them.
|
|
268
|
+
*
|
|
269
|
+
* @since 0.2.0
|
|
270
|
+
*/
|
|
271
|
+
type AbsoluteLength = Px;
|
|
272
|
+
/**
|
|
273
|
+
* The requirements that are all pre-satisfied: absolute lengths (fixed
|
|
274
|
+
* ratio) and angles (radians are already numbers, degrees a fixed ratio of
|
|
275
|
+
* them). An expression whose `Requires` stays inside this set solves with
|
|
276
|
+
* no options.
|
|
277
|
+
*
|
|
278
|
+
* These units ride the `Requires` channel even though they demand nothing —
|
|
279
|
+
* deliberately, and load-bearing: division cancellation may discharge a
|
|
280
|
+
* requirement only when eager folding guarantees the division folds before
|
|
281
|
+
* evaluation needs a ratio, and foldability is a property of every unit in
|
|
282
|
+
* the tree, defaults included (see `docs/result-calc.md`).
|
|
283
|
+
*
|
|
284
|
+
* @since 0.2.0
|
|
285
|
+
*/
|
|
286
|
+
type ContextFree = AbsoluteLength | Angle$1;
|
|
287
|
+
/**
|
|
288
|
+
* The CSS token of a unit brand (`Unit.Px` -> `'px'`), used to key the
|
|
289
|
+
* `units` section of the solve options and to render the unit suffix.
|
|
290
|
+
*
|
|
291
|
+
* @since 0.2.0
|
|
292
|
+
*/
|
|
293
|
+
type Token<U> = U extends {
|
|
294
|
+
readonly [LengthUnitId]: infer T;
|
|
295
|
+
} ? T : U extends {
|
|
296
|
+
readonly [AngleUnitId]: infer T;
|
|
297
|
+
} ? T : U extends {
|
|
298
|
+
readonly [PercentageUnitId]: infer T;
|
|
299
|
+
} ? T : never;
|
|
300
|
+
/**
|
|
301
|
+
* The `units` section of `Calc.SolveOptions`: the ratios that lower an
|
|
302
|
+
* expression with the requirements `R` to a number. Each context-dependent
|
|
303
|
+
* unit present is a required pixels-per-unit ratio — `vw` is
|
|
304
|
+
* `sampleWidth / 100`, and `%` is `basis / 100`, per-hundred alike — while
|
|
305
|
+
* absolute lengths (`px`) are optional overrides and angle units never
|
|
306
|
+
* appear (radians are already numeric, degrees a fixed ratio). An expression
|
|
307
|
+
* whose requirements are all pre-satisfied needs no entries at all.
|
|
308
|
+
*
|
|
309
|
+
* @since 0.2.0
|
|
310
|
+
*/
|
|
311
|
+
type UnitContext<R> = { readonly [K in Token<Extract<R, Relative | Percent>> & string]: number; } & { readonly [K in Token<Extract<R, AbsoluteLength>> & string]?: number; };
|
|
312
|
+
declare namespace channels_d_exports {
|
|
313
|
+
export { Alpha, B, C, ChannelIdent, G, H, L, R$1 as R };
|
|
314
|
+
}
|
|
315
|
+
declare const ChannelId: unique symbol;
|
|
316
|
+
/**
|
|
317
|
+
* The leaf brand of an origin-channel keyword: the refinement of `Calc.Ident`
|
|
318
|
+
* the `Channel` keywords carry. The extra brand is what scopes relative-color
|
|
319
|
+
* slots — a `ColorSpace` names the `ChannelIdent`s it admits, so a bare
|
|
320
|
+
* identifier from some other construct never satisfies a channel slot even if
|
|
321
|
+
* its token collides — while everything generic over identifiers (`solve`'s
|
|
322
|
+
* `idents` section, `Calc.idents`) keys on the `Ident` base and needs no
|
|
323
|
+
* special case.
|
|
324
|
+
*
|
|
325
|
+
* @since 0.2.0
|
|
326
|
+
*/
|
|
327
|
+
interface ChannelIdent<Name extends string> extends Ident<Name> {
|
|
328
|
+
readonly [ChannelId]: Name;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The `l` origin channel — lightness in `oklch`. Serializes bare as `l`.
|
|
332
|
+
*
|
|
333
|
+
* @since 0.2.0
|
|
334
|
+
*/
|
|
335
|
+
declare const L: Calc<never, None$1, ChannelIdent<'l'>>;
|
|
336
|
+
/**
|
|
337
|
+
* The `c` origin channel — chroma in `oklch`. Serializes bare as `c`.
|
|
338
|
+
*
|
|
339
|
+
* @since 0.2.0
|
|
340
|
+
*/
|
|
341
|
+
declare const C: Calc<never, None$1, ChannelIdent<'c'>>;
|
|
342
|
+
/**
|
|
343
|
+
* The `h` origin channel — hue in `oklch`, in degrees. Serializes bare as `h`.
|
|
344
|
+
*
|
|
345
|
+
* @since 0.2.0
|
|
346
|
+
*/
|
|
347
|
+
declare const H: Calc<never, None$1, ChannelIdent<'h'>>;
|
|
348
|
+
/**
|
|
349
|
+
* The `r` origin channel — red in `color(srgb ...)`. Serializes bare as `r`.
|
|
350
|
+
*
|
|
351
|
+
* @since 0.2.0
|
|
352
|
+
*/
|
|
353
|
+
declare const R$1: Calc<never, None$1, ChannelIdent<'r'>>;
|
|
354
|
+
/**
|
|
355
|
+
* The `g` origin channel — green in `color(srgb ...)`. Serializes bare as `g`.
|
|
356
|
+
*
|
|
357
|
+
* @since 0.2.0
|
|
358
|
+
*/
|
|
359
|
+
declare const G: Calc<never, None$1, ChannelIdent<'g'>>;
|
|
360
|
+
/**
|
|
361
|
+
* The `b` origin channel — blue in `color(srgb ...)`. Serializes bare as `b`.
|
|
362
|
+
*
|
|
363
|
+
* @since 0.2.0
|
|
364
|
+
*/
|
|
365
|
+
declare const B: Calc<never, None$1, ChannelIdent<'b'>>;
|
|
366
|
+
/**
|
|
367
|
+
* The `alpha` origin channel — the opacity of the `from` origin, in `oklch`
|
|
368
|
+
* and `color(srgb ...)` alike. Serializes bare as `alpha`.
|
|
369
|
+
*
|
|
370
|
+
* @since 0.2.0
|
|
371
|
+
*/
|
|
372
|
+
declare const Alpha: Calc<never, None$1, ChannelIdent<'alpha'>>;
|
|
373
|
+
declare namespace colorSpace_d_exports {
|
|
374
|
+
export { ColorSpace, Polar, PolarSpace, a98Rgb, displayP3, hsl, hwb, lab, lch, oklab, oklch$1 as oklch, prophotoRgb, rec2020, srgb$1 as srgb, srgbLinear, xyz, xyzD50, xyzD65 };
|
|
375
|
+
}
|
|
376
|
+
declare const ColorSpaceChannels: unique symbol;
|
|
377
|
+
declare const PolarId: unique symbol;
|
|
378
|
+
/**
|
|
379
|
+
* The trait a polar color space carries — one with a hue channel. `Color.mix`
|
|
380
|
+
* requires it to take a `HueInterpolation`, and `PolarSpace` is the space type
|
|
381
|
+
* that has it. Composes by intersection with future space traits, as curvy's
|
|
382
|
+
* brands do.
|
|
383
|
+
*
|
|
384
|
+
* @since 0.2.0
|
|
385
|
+
*/
|
|
386
|
+
type Polar = {
|
|
387
|
+
readonly [PolarId]: 'polar';
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* A color space. `Channels` carries the origin-channel keyword brands
|
|
391
|
+
* (`Channel`) valid for `Color.from`; `Trait` accumulates the space's
|
|
392
|
+
* capability brands (`Polar`), defaulting to `unknown` — a space with no
|
|
393
|
+
* capability claims. A position requires a capability by naming its brand in
|
|
394
|
+
* `Trait` (`ColorSpace<Channels, Polar>`).
|
|
395
|
+
*
|
|
396
|
+
* @since 0.2.0
|
|
397
|
+
*/
|
|
398
|
+
interface ColorSpace<out Channels = ChannelIdent<string>, out Trait = unknown> {
|
|
399
|
+
readonly [ColorSpaceTypeId]: ColorSpaceTypeId;
|
|
400
|
+
readonly [ColorSpaceChannels]?: Channels;
|
|
401
|
+
readonly [ColorSpaceTraits]?: Trait;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* A polar color space — one carrying the `Polar` trait, so `Color.mix` may take
|
|
405
|
+
* a `HueInterpolation` after it.
|
|
406
|
+
*
|
|
407
|
+
* @since 0.2.0
|
|
408
|
+
*/
|
|
409
|
+
type PolarSpace<Channels = ChannelIdent<string>> = ColorSpace<Channels, Polar>;
|
|
410
|
+
/**
|
|
411
|
+
* The `oklch` space: a polar interpolation space, and an `oklch(from ...)`
|
|
412
|
+
* destination with `Channel.L`/`C`/`H` (and `Alpha`) in scope.
|
|
413
|
+
*
|
|
414
|
+
* @since 0.2.0
|
|
415
|
+
*/
|
|
416
|
+
declare const oklch$1: ColorSpace<ChannelIdent<'l'> | ChannelIdent<'c'> | ChannelIdent<'h'> | ChannelIdent<'alpha'>, Polar>;
|
|
417
|
+
/**
|
|
418
|
+
* The `srgb` space: a rectangular interpolation space, and a
|
|
419
|
+
* `color(from ... srgb ...)` destination with `Channel.R`/`G`/`B` (and `Alpha`)
|
|
420
|
+
* in scope.
|
|
421
|
+
*
|
|
422
|
+
* @since 0.2.0
|
|
423
|
+
*/
|
|
424
|
+
declare const srgb$1: ColorSpace<ChannelIdent<'r'> | ChannelIdent<'g'> | ChannelIdent<'b'> | ChannelIdent<'alpha'>>;
|
|
425
|
+
/**
|
|
426
|
+
* The `srgb-linear` space (rectangular).
|
|
427
|
+
*
|
|
428
|
+
* @since 0.2.0
|
|
429
|
+
*/
|
|
430
|
+
declare const srgbLinear: ColorSpace<never>;
|
|
431
|
+
/**
|
|
432
|
+
* The `display-p3` space (rectangular).
|
|
433
|
+
*
|
|
434
|
+
* @since 0.2.0
|
|
435
|
+
*/
|
|
436
|
+
declare const displayP3: ColorSpace<never>;
|
|
437
|
+
/**
|
|
438
|
+
* The `a98-rgb` space (rectangular).
|
|
439
|
+
*
|
|
440
|
+
* @since 0.2.0
|
|
441
|
+
*/
|
|
442
|
+
declare const a98Rgb: ColorSpace<never>;
|
|
443
|
+
/**
|
|
444
|
+
* The `prophoto-rgb` space (rectangular).
|
|
445
|
+
*
|
|
446
|
+
* @since 0.2.0
|
|
447
|
+
*/
|
|
448
|
+
declare const prophotoRgb: ColorSpace<never>;
|
|
449
|
+
/**
|
|
450
|
+
* The `rec2020` space (rectangular).
|
|
451
|
+
*
|
|
452
|
+
* @since 0.2.0
|
|
453
|
+
*/
|
|
454
|
+
declare const rec2020: ColorSpace<never>;
|
|
455
|
+
/**
|
|
456
|
+
* The `lab` space (rectangular).
|
|
457
|
+
*
|
|
458
|
+
* @since 0.2.0
|
|
459
|
+
*/
|
|
460
|
+
declare const lab: ColorSpace<never>;
|
|
461
|
+
/**
|
|
462
|
+
* The `oklab` space (rectangular).
|
|
463
|
+
*
|
|
464
|
+
* @since 0.2.0
|
|
465
|
+
*/
|
|
466
|
+
declare const oklab: ColorSpace<never>;
|
|
467
|
+
/**
|
|
468
|
+
* The `xyz` space (rectangular; an alias for `xyz-d65`).
|
|
469
|
+
*
|
|
470
|
+
* @since 0.2.0
|
|
471
|
+
*/
|
|
472
|
+
declare const xyz: ColorSpace<never>;
|
|
473
|
+
/**
|
|
474
|
+
* The `xyz-d50` space (rectangular).
|
|
475
|
+
*
|
|
476
|
+
* @since 0.2.0
|
|
477
|
+
*/
|
|
478
|
+
declare const xyzD50: ColorSpace<never>;
|
|
479
|
+
/**
|
|
480
|
+
* The `xyz-d65` space (rectangular).
|
|
481
|
+
*
|
|
482
|
+
* @since 0.2.0
|
|
483
|
+
*/
|
|
484
|
+
declare const xyzD65: ColorSpace<never>;
|
|
485
|
+
/**
|
|
486
|
+
* The `hsl` space (polar).
|
|
487
|
+
*
|
|
488
|
+
* @since 0.2.0
|
|
489
|
+
*/
|
|
490
|
+
declare const hsl: ColorSpace<never, Polar>;
|
|
491
|
+
/**
|
|
492
|
+
* The `hwb` space (polar).
|
|
493
|
+
*
|
|
494
|
+
* @since 0.2.0
|
|
495
|
+
*/
|
|
496
|
+
declare const hwb: ColorSpace<never, Polar>;
|
|
497
|
+
/**
|
|
498
|
+
* The `lch` space (polar).
|
|
499
|
+
*
|
|
500
|
+
* @since 0.2.0
|
|
501
|
+
*/
|
|
502
|
+
declare const lch: ColorSpace<never, Polar>;
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/data/colorSpace.internal.d.ts
|
|
505
|
+
declare const ColorSpaceTypeId: unique symbol;
|
|
506
|
+
type ColorSpaceTypeId = typeof ColorSpaceTypeId;
|
|
507
|
+
/**
|
|
508
|
+
* Phantom key holding a `ColorSpace`'s `Trait` parameter. The runtime value
|
|
509
|
+
* never has a value here — traits are type-level brands, so a space is
|
|
510
|
+
* identical at runtime whatever its traits (the curvy trait pattern).
|
|
511
|
+
*
|
|
512
|
+
* @internal
|
|
513
|
+
*/
|
|
514
|
+
declare const ColorSpaceTraits: unique symbol;
|
|
515
|
+
type ColorSpaceTraits = typeof ColorSpaceTraits;
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/data/hueInterpolation.internal.d.ts
|
|
518
|
+
declare const HueInterpolationTypeId: unique symbol;
|
|
519
|
+
type HueInterpolationTypeId = typeof HueInterpolationTypeId;
|
|
520
|
+
declare namespace hueInterpolation_d_exports {
|
|
521
|
+
export { HueInterpolation, decreasing, increasing, interpolate, longer, shorter };
|
|
522
|
+
}
|
|
523
|
+
declare const HueInterpolationStrategy: unique symbol;
|
|
524
|
+
/**
|
|
525
|
+
* A hue-interpolation strategy. The `Strategy` parameter names the specific
|
|
526
|
+
* one (`'longer'`), letting a position accept a particular strategy where it
|
|
527
|
+
* matters; `Color.mix` accepts any.
|
|
528
|
+
*
|
|
529
|
+
* @since 0.2.0
|
|
530
|
+
*/
|
|
531
|
+
interface HueInterpolation<Strategy extends string = string> {
|
|
532
|
+
readonly [HueInterpolationTypeId]: HueInterpolationTypeId;
|
|
533
|
+
readonly [HueInterpolationStrategy]?: Strategy;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* The `shorter` strategy — the short arc between the two hues (the browser
|
|
537
|
+
* default). Serializes as `shorter hue`.
|
|
538
|
+
*
|
|
539
|
+
* @since 0.2.0
|
|
540
|
+
*/
|
|
541
|
+
declare const shorter: HueInterpolation<'shorter'>;
|
|
542
|
+
/**
|
|
543
|
+
* The `longer` strategy — the long arc between the two hues. Serializes as
|
|
544
|
+
* `longer hue`.
|
|
545
|
+
*
|
|
546
|
+
* @since 0.2.0
|
|
547
|
+
*/
|
|
548
|
+
declare const longer: HueInterpolation<'longer'>;
|
|
549
|
+
/**
|
|
550
|
+
* The `increasing` strategy — hues traversed in increasing order, wrapping past
|
|
551
|
+
* `360` if needed. Serializes as `increasing hue`.
|
|
552
|
+
*
|
|
553
|
+
* @since 0.2.0
|
|
554
|
+
*/
|
|
555
|
+
declare const increasing: HueInterpolation<'increasing'>;
|
|
556
|
+
/**
|
|
557
|
+
* The `decreasing` strategy — hues traversed in decreasing order, wrapping past
|
|
558
|
+
* `0` if needed. Serializes as `decreasing hue`.
|
|
559
|
+
*
|
|
560
|
+
* @since 0.2.0
|
|
561
|
+
*/
|
|
562
|
+
declare const decreasing: HueInterpolation<'decreasing'>;
|
|
563
|
+
/**
|
|
564
|
+
* Builds the hue at `t` along the arc from `from` to `to` under `strategy` — the
|
|
565
|
+
* JS side of what a polar `Color.mix` emits for the browser. Hues are numbers of
|
|
566
|
+
* degrees (as an oklch/lch hue channel is), and `from`, `to`, and `t` are each a
|
|
567
|
+
* number or a `Calc`, so the result is a `Calc` too: fully symbolic when any
|
|
568
|
+
* argument is, folding to a constant when all are numbers.
|
|
569
|
+
*
|
|
570
|
+
* The hue math is the CSS Color 4 fixup, written branchlessly with `mod`: each
|
|
571
|
+
* strategy is a signed delta added to `from` as `t` runs `0` (at `from`) to `1`
|
|
572
|
+
* (at `to`). `shorter` and `longer` take the short or long arc between the hues;
|
|
573
|
+
* `increasing`/`decreasing` force the direction. The result is unwrapped — it may
|
|
574
|
+
* fall outside `[0, 360)`, which the browser resolves as a hue — and unions the
|
|
575
|
+
* arguments' variables. Drop it straight into a hue channel (`Color.oklch`).
|
|
576
|
+
*
|
|
577
|
+
* @param strategy - The traversal strategy (`shorter`, `longer`, ...).
|
|
578
|
+
* @param from - The start hue, in degrees: a number or a `Calc`.
|
|
579
|
+
* @param to - The end hue, in degrees: a number or a `Calc`.
|
|
580
|
+
* @param t - The interpolation parameter, `0` to `1`: a number or a `Calc`.
|
|
581
|
+
* @returns The interpolated hue in degrees, a `Calc` unioning the arguments' variables.
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* const hue = HueInterpolation.interpolate(HueInterpolation.shorter, 30, Calc.var('to'), Calc.var('t'))
|
|
585
|
+
* Calc.serialize(hue) // 'calc(30 + (mod(var(--to) - 30 + 180, 360) - 180) * var(--t))'
|
|
586
|
+
* Calc.serialize(HueInterpolation.interpolate(HueInterpolation.increasing, 20, 350, 0.5)) // '185'
|
|
587
|
+
* ```
|
|
588
|
+
* @since 0.2.0
|
|
589
|
+
*/
|
|
590
|
+
declare const interpolate: <F extends Any = never, T extends Any = never, P extends Any = never>(strategy: HueInterpolation, from: Input<F>, to: Input<T>, t: Input<P>) => Calc<F | T | P>;
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/data/keywords.internal.d.ts
|
|
593
|
+
declare const NoneTypeId: unique symbol;
|
|
594
|
+
type NoneTypeId = typeof NoneTypeId;
|
|
595
|
+
declare namespace keywords_d_exports {
|
|
596
|
+
export { None, isNone, none };
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* The type of `none` alone. Naming it lets accepting positions spell
|
|
600
|
+
* their signatures (`Input<R> | Keyword.None`) and overloads recognize
|
|
601
|
+
* the keyword.
|
|
602
|
+
*
|
|
603
|
+
* @since 0.2.0
|
|
604
|
+
*/
|
|
605
|
+
interface None extends Pipeable {
|
|
606
|
+
readonly [NoneTypeId]: NoneTypeId;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* The `none` keyword — CSS's missing-component value. Accepted where a
|
|
610
|
+
* position declares it: color channels today (`oklch(0 0 none)`), other
|
|
611
|
+
* slots as they arrive.
|
|
612
|
+
*
|
|
613
|
+
* @since 0.2.0
|
|
614
|
+
*/
|
|
615
|
+
declare const none: None;
|
|
616
|
+
/**
|
|
617
|
+
* Checks if a value is the `none` keyword.
|
|
618
|
+
*
|
|
619
|
+
* True only for `none` itself, which carries the brand.
|
|
620
|
+
*
|
|
621
|
+
* @param u - The value to check.
|
|
622
|
+
* @returns `true` if the value is `none`, `false` otherwise.
|
|
623
|
+
* @since 0.2.0
|
|
624
|
+
*/
|
|
625
|
+
declare const isNone: (u: unknown) => u is None;
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region src/data/color.internal.d.ts
|
|
628
|
+
declare const ColorTypeId: unique symbol;
|
|
629
|
+
type ColorTypeId = typeof ColorTypeId;
|
|
630
|
+
declare namespace color_d_exports {
|
|
631
|
+
export { Color, RelativeChannel, bind$1 as bind, channels, equals$2 as equals, from, isColor, lightDark, mix, named, oklch, serialize$1 as serialize, srgb, transparent, _var$1 as var, vars$2 as vars };
|
|
632
|
+
}
|
|
633
|
+
declare const ColorVars: unique symbol;
|
|
634
|
+
/**
|
|
635
|
+
* A CSS color expression whose channels are `Calc` number expressions.
|
|
636
|
+
*
|
|
637
|
+
* A color is not a number: it can be bound and serialized, but not
|
|
638
|
+
* solved. The `Vars` parameter unions the channels' unbound variable
|
|
639
|
+
* names, exactly as on `Calc`.
|
|
640
|
+
*
|
|
641
|
+
* `oklch(...)`, `color(srgb ...)`, `light-dark(...)`, `color-mix(...)`,
|
|
642
|
+
* relative colors (`oklch(from ...)`, `color(from ...)`), a color-valued
|
|
643
|
+
* `var(...)`, and named colors are modeled today; other color functions
|
|
644
|
+
* arrive as a consumer needs them. Channels accept `Keyword.none`, CSS's
|
|
645
|
+
* missing-component value.
|
|
646
|
+
*
|
|
647
|
+
* Construct via `oklch`, `srgb`, `lightDark`, `mix`, `named`, `from`, and
|
|
648
|
+
* `var` (or the `transparent` constant).
|
|
649
|
+
*
|
|
650
|
+
* @since 0.1.0
|
|
651
|
+
*/
|
|
652
|
+
interface Color<out Vars extends Any = Any> extends Pipeable {
|
|
653
|
+
readonly [ColorTypeId]: ColorTypeId;
|
|
654
|
+
readonly [ColorVars]?: Vars;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Checks if a value is a `Color`.
|
|
658
|
+
*
|
|
659
|
+
* True only for values built by this module's constructors, which carry
|
|
660
|
+
* the brand.
|
|
661
|
+
*
|
|
662
|
+
* @param u - The value to check.
|
|
663
|
+
* @returns `true` if the value is a `Color`, `false` otherwise.
|
|
664
|
+
* @since 0.1.0
|
|
665
|
+
*/
|
|
666
|
+
declare const isColor: (u: unknown) => u is Color<Any>;
|
|
667
|
+
/**
|
|
668
|
+
* Creates an `oklch(...)` color from three channel expressions: lightness
|
|
669
|
+
* (`0` to `1`), chroma (`0` upward), and hue (degrees). A channel may be
|
|
670
|
+
* `Keyword.none` — the missing-component keyword, the conventional hue
|
|
671
|
+
* for achromatic colors: `oklch(0 0 none)`.
|
|
672
|
+
*
|
|
673
|
+
* Each channel serializes independently, wrapped in `calc()` when it is
|
|
674
|
+
* arithmetic: `oklch(var(--l) calc(var(--c) * 0.5) 220)`.
|
|
675
|
+
*
|
|
676
|
+
* @param lightness - The lightness channel.
|
|
677
|
+
* @param chroma - The chroma channel.
|
|
678
|
+
* @param hue - The hue channel, in degrees.
|
|
679
|
+
* @returns A `Color` with the channels' variables unioned.
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* const accent = Color.oklch(Calc.var('lightness'), 0.15, 220)
|
|
683
|
+
* Color.serialize(accent) // 'oklch(var(--lightness) 0.15 220)'
|
|
684
|
+
* ```
|
|
685
|
+
* @since 0.1.0
|
|
686
|
+
*/
|
|
687
|
+
declare const oklch: <L extends Any = never, C extends Any = never, H extends Any = never>(lightness: Input<L> | None, chroma: Input<C> | None, hue: Input<H> | None) => Color<L | C | H>;
|
|
688
|
+
/**
|
|
689
|
+
* Creates a `color(srgb ...)` color from three channel expressions, each
|
|
690
|
+
* `0` to `1`. A channel may be `Keyword.none`, the missing-component
|
|
691
|
+
* keyword.
|
|
692
|
+
*
|
|
693
|
+
* Each channel serializes independently, wrapped in `calc()` when it is
|
|
694
|
+
* arithmetic, inside the `color()` function's `srgb` colorspace:
|
|
695
|
+
* `color(srgb 0.18 0.34 0.78)`.
|
|
696
|
+
*
|
|
697
|
+
* @param red - The red channel.
|
|
698
|
+
* @param green - The green channel.
|
|
699
|
+
* @param blue - The blue channel.
|
|
700
|
+
* @returns A `Color` with the channels' variables unioned.
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* const brand = Color.srgb(0.18, 0.34, 0.78)
|
|
704
|
+
* Color.serialize(brand) // 'color(srgb 0.18 0.34 0.78)'
|
|
705
|
+
* ```
|
|
706
|
+
* @since 0.2.0
|
|
707
|
+
*/
|
|
708
|
+
declare const srgb: <R extends Any = never, G extends Any = never, B extends Any = never>(red: Input<R> | None, green: Input<G> | None, blue: Input<B> | None) => Color<R | G | B>;
|
|
709
|
+
/**
|
|
710
|
+
* Creates a named color, rendered bare: `named('rebeccapurple')`
|
|
711
|
+
* serializes as `rebeccapurple`. The name is the whole value — a named
|
|
712
|
+
* color has no channels, contributes no variables, and binds nothing.
|
|
713
|
+
*
|
|
714
|
+
* That the name is one of the specification's named colors is not
|
|
715
|
+
* checked, matching the library's posture on identifiers — with one
|
|
716
|
+
* exception: the CSS-wide keywords (`inherit`, `initial`, ...) are
|
|
717
|
+
* whole-declaration values, not colors (`light-dark(inherit, ...)` is
|
|
718
|
+
* invalid CSS), and are rejected.
|
|
719
|
+
*
|
|
720
|
+
* @param name - The color name. Must be non-empty and not a CSS-wide keyword.
|
|
721
|
+
* @returns A `Color<never>`.
|
|
722
|
+
* @throws `Error` when `name` is empty or a CSS-wide keyword.
|
|
723
|
+
* @since 0.2.0
|
|
724
|
+
*/
|
|
725
|
+
declare const named: (name: string) => Color<never>;
|
|
726
|
+
/**
|
|
727
|
+
* The `transparent` named color — `rgb(0 0 0 / 0)` by definition, and
|
|
728
|
+
* the conventional "no color" value.
|
|
729
|
+
*
|
|
730
|
+
* @since 0.2.0
|
|
731
|
+
*/
|
|
732
|
+
declare const transparent: Color<never>;
|
|
733
|
+
type ReadVars$1<V> = V extends Var<infer N, infer T, infer F> ? Var<N, T> | ReadFallbackVars$1<F> : never;
|
|
734
|
+
type ReadFallbackVars$1<F> = F extends Color<infer W> ? W : F extends Any ? ReadVars$1<F> : never;
|
|
735
|
+
type ReadGuard$1<V> = V extends Var<string, infer T, infer F> ? [unknown] extends [T] ? FallbackGuard$1<F> : T extends Color<Any> ? FallbackGuard$1<F> : 'this read is declared inside calc: a numeric read lifts with Calc.var' : never;
|
|
736
|
+
type FallbackGuard$1<F> = [F] extends [undefined] ? unknown : F extends string ? unknown : F extends Color<Any> ? unknown : F extends Var<string, infer T2, infer F2> ? [unknown] extends [T2] ? FallbackGuard$1<F2> : T2 extends Color<Any> ? FallbackGuard$1<F2> : 'a calc-declared read cannot fall back inside a color' : 'a color fallback is a Color, color text, or a Var read';
|
|
737
|
+
declare const _var$1: {
|
|
738
|
+
/**
|
|
739
|
+
* Creates a color-valued read of a CSS variable — `Color.var('accent')`
|
|
740
|
+
* serializes as `var(--accent)`. Use it where a whole color is read from
|
|
741
|
+
* a custom property: as a standalone value, or as the origin of a
|
|
742
|
+
* relative color (`from`). Exported as `var` (`Color.var('accent')`)
|
|
743
|
+
* because `var` is reserved in declaration position.
|
|
744
|
+
*
|
|
745
|
+
* The read is the whole value, so it carries `name` as its one unbound
|
|
746
|
+
* variable — a dependency, exactly as an unbound `Calc.var` is — but has
|
|
747
|
+
* no channels. `bind` substitutes channel expressions, not whole colors,
|
|
748
|
+
* so it leaves a color variable in place; the browser resolves it from
|
|
749
|
+
* the cascade.
|
|
750
|
+
*
|
|
751
|
+
* Sugar for the read overload: `Color.var('accent')` is
|
|
752
|
+
* `Color.var(Var.of('accent'))`.
|
|
753
|
+
*
|
|
754
|
+
* @param name - The variable name, without the `--` prefix. Must be non-empty.
|
|
755
|
+
* @returns A `Color` with `name` as its one unbound variable.
|
|
756
|
+
* @throws `Error` when `name` is empty.
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* Color.serialize(Color.var('accent')) // 'var(--accent)'
|
|
760
|
+
* ```
|
|
761
|
+
* @since 0.2.0
|
|
762
|
+
*/
|
|
763
|
+
<Name extends string>(name: Name): Color<Var<Name>>;
|
|
764
|
+
/**
|
|
765
|
+
* Lifts a `Var` read into a color-valued expression. A fallback-carrying
|
|
766
|
+
* read renders its fallback (`var(--accent, red)`), which must be
|
|
767
|
+
* color-valued here — a `Color`, literal color text, or another such
|
|
768
|
+
* read, recursively. Anything else is a type error at this lift, backed
|
|
769
|
+
* by a runtime check.
|
|
770
|
+
*
|
|
771
|
+
* The returned color's `Vars` unions the read's identity with its
|
|
772
|
+
* fallback chain's, flattened, and every name joins the dependency
|
|
773
|
+
* report. As with the bare form, `bind` leaves the read itself in place
|
|
774
|
+
* (channel substitution cannot produce a whole color), though it does
|
|
775
|
+
* substitute inside a fallback's channels.
|
|
776
|
+
*
|
|
777
|
+
* @param read - The read to lift, from `Var.of` or `Var.color` (optionally through `Var.fallback`).
|
|
778
|
+
* @returns A `Color` reading the read's name, with its fallback chain's reads unioned in.
|
|
779
|
+
* @throws `Error` when the read is calc-declared, or its fallback chain holds anything but colors, color text, and reads.
|
|
780
|
+
* @example
|
|
781
|
+
* ```ts
|
|
782
|
+
* const accent = Var.of('accent')
|
|
783
|
+
* Color.serialize(Color.var(accent.pipe(Var.fallback('rebeccapurple'))))
|
|
784
|
+
* // 'var(--accent, rebeccapurple)'
|
|
785
|
+
* ```
|
|
786
|
+
* @since 0.4.0
|
|
787
|
+
*/
|
|
788
|
+
<V extends Any>(read: V & ReadGuard$1<V>): Color<ReadVars$1<V>>;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Creates a scheme-conditional `light-dark(...)` color: the browser uses
|
|
792
|
+
* the first color under the light scheme and the second under dark.
|
|
793
|
+
*
|
|
794
|
+
* The arms are whole colors and positional — `lightDark(a, b)` and
|
|
795
|
+
* `lightDark(b, a)` are different colors. Any `Color` is accepted,
|
|
796
|
+
* including another `lightDark` (grammatically an arm is any `<color>`;
|
|
797
|
+
* nesting is redundant but legal, and simplification is not this type's
|
|
798
|
+
* job). Note the resolution context: `light-dark()` requires
|
|
799
|
+
* `color-scheme` to be set — that contract is the consumer's.
|
|
800
|
+
*
|
|
801
|
+
* @param light - The color used under the light scheme.
|
|
802
|
+
* @param dark - The color used under the dark scheme.
|
|
803
|
+
* @returns A `Color` with both arms' variables unioned.
|
|
804
|
+
* @example
|
|
805
|
+
* ```ts
|
|
806
|
+
* const accent = Color.lightDark(Color.srgb(0.85, 0.3, 0.4), Color.srgb(0.95, 0.5, 0.55))
|
|
807
|
+
* Color.serialize(accent) // 'light-dark(color(srgb 0.85 0.3 0.4), color(srgb 0.95 0.5 0.55))'
|
|
808
|
+
* ```
|
|
809
|
+
* @since 0.2.0
|
|
810
|
+
*/
|
|
811
|
+
declare const lightDark: <A extends Any = never, B extends Any = never>(light: Color<A>, dark: Color<B>) => Color<A | B>;
|
|
812
|
+
type MixArm<C extends Any, P extends Any> = Color<C> | readonly [Color<C>, number | Calc<P, Percentage$1, unknown>];
|
|
813
|
+
/**
|
|
814
|
+
* Creates a `color-mix(...)`: the browser mixes `color1` and `color2` in the
|
|
815
|
+
* interpolation `space`. Each arm is a bare `Color` or a `[color, percentage]`
|
|
816
|
+
* tuple giving its weight — a bare number reads as a percent (`20` is `20%`,
|
|
817
|
+
* the `<percentage>` convention), a `Percentage` expression an annotated or
|
|
818
|
+
* computed weight (`Percentage.of(20)`, `Calc.multiply(Percentage.of(50), ...)`);
|
|
819
|
+
* a plain number-kind `Calc` is rejected, a weight being a `<percentage>`.
|
|
820
|
+
*
|
|
821
|
+
* A polar `space` (`ColorSpace.oklch`, `ColorSpace.lch`, ...) may take a
|
|
822
|
+
* `HueInterpolation` strategy between the space and the colors — the second
|
|
823
|
+
* overload — for how the hue circle is traversed; omit it and the browser
|
|
824
|
+
* defaults to `shorter`. A rectangular space has no hue channel, so passing a
|
|
825
|
+
* strategy is a compile error, mirroring the grammar where
|
|
826
|
+
* `<hue-interpolation-method>` follows only a polar space.
|
|
827
|
+
*
|
|
828
|
+
* Percentages are optional and preserved verbatim — fashionable emits the
|
|
829
|
+
* authored form and never runs the spec's mixing normalization (omitted weights
|
|
830
|
+
* defaulting to `50%`, weights off `100%` rescaling with an alpha multiplier),
|
|
831
|
+
* which is computed-value behavior the browser owns. Like every `Color`, a mix
|
|
832
|
+
* binds and serializes but does not solve, and each arm and each percentage
|
|
833
|
+
* contributes its variables to the result.
|
|
834
|
+
*
|
|
835
|
+
* @param space - The interpolation `ColorSpace`; a polar one may be followed by a `HueInterpolation`.
|
|
836
|
+
* @param color1 - The first color, or a `[color, percentage]` tuple weighting it.
|
|
837
|
+
* @param color2 - The second color, or a `[color, percentage]` tuple weighting it.
|
|
838
|
+
* @returns A `Color` unioning both arms' and both percentages' variables.
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts
|
|
841
|
+
* Color.serialize(Color.mix(ColorSpace.oklch, Color.named('red'), Color.named('blue')))
|
|
842
|
+
* // 'color-mix(in oklch, red, blue)'
|
|
843
|
+
* Color.serialize(Color.mix(ColorSpace.srgb, [Color.named('white'), 20], Color.named('black')))
|
|
844
|
+
* // 'color-mix(in srgb, white 20%, black)'
|
|
845
|
+
* Color.serialize(Color.mix(ColorSpace.oklch, HueInterpolation.longer, Color.named('red'), Color.named('blue')))
|
|
846
|
+
* // 'color-mix(in oklch longer hue, red, blue)'
|
|
847
|
+
* ```
|
|
848
|
+
* @since 0.2.0
|
|
849
|
+
*/
|
|
850
|
+
declare const mix: {
|
|
851
|
+
<C1 extends Any = never, P1 extends Any = never, C2 extends Any = never, P2 extends Any = never>(space: ColorSpace, color1: MixArm<C1, P1>, color2: MixArm<C2, P2>): Color<C1 | P1 | C2 | P2>;
|
|
852
|
+
<C1 extends Any = never, P1 extends Any = never, C2 extends Any = never, P2 extends Any = never>(space: PolarSpace, hue: HueInterpolation, color1: MixArm<C1, P1>, color2: MixArm<C2, P2>): Color<C1 | P1 | C2 | P2>;
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* A channel slot of a relative color: a bare number, `Keyword.none`, or a
|
|
856
|
+
* `Calc` number expression. `Channels` is the set of origin-channel keyword
|
|
857
|
+
* brands (`ChannelIdent`) the expression may read — the space's own channels —
|
|
858
|
+
* so a keyword from another color space (`Channel.R` in an `oklch` slot) is a
|
|
859
|
+
* compile error. A plain expression (a constant, a `Calc.var`, a `clamp`)
|
|
860
|
+
* carries no channel keyword and fits any slot.
|
|
861
|
+
*
|
|
862
|
+
* @since 0.2.0
|
|
863
|
+
*/
|
|
864
|
+
type RelativeChannel<Vars extends Any, Channels> = number | None | Calc<Vars, None$1, Channels>;
|
|
865
|
+
type ChannelsOf<Space> = Space extends ColorSpace<infer Channels> ? Channels : never;
|
|
866
|
+
/**
|
|
867
|
+
* Creates a relative color from an origin and a destination `ColorSpace`:
|
|
868
|
+
* `Color.from(origin, ColorSpace.oklch, l, c, h)` is `oklch(from origin l c h)`
|
|
869
|
+
* and `Color.from(origin, ColorSpace.srgb, r, g, b)` is
|
|
870
|
+
* `color(from origin srgb r g b)`. The browser converts `origin` into the
|
|
871
|
+
* space and exposes its channels as the `Channel` keywords the space names
|
|
872
|
+
* (`Channel.L`/`C`/`H` for `oklch`, `Channel.R`/`G`/`B` for `srgb`, `Channel.Alpha`
|
|
873
|
+
* for both); passing them straight through reproduces the origin, and
|
|
874
|
+
* arithmetic on them derives a related color.
|
|
875
|
+
*
|
|
876
|
+
* The `space` scopes the channel arguments — a keyword the space does not name
|
|
877
|
+
* is a compile error. Each channel serializes independently, wrapped in
|
|
878
|
+
* `calc()` when arithmetic and bare when a lone keyword, and may be
|
|
879
|
+
* `Keyword.none`. A supplied `alpha` renders after a slash
|
|
880
|
+
* (`/ calc(alpha * 0.5)`); omitted, the origin's alpha carries through. The
|
|
881
|
+
* origin's own variables union into the result; the channel keywords
|
|
882
|
+
* contribute none, since the browser resolves them from the origin.
|
|
883
|
+
*
|
|
884
|
+
* @param origin - The color to derive from — any `Color`, commonly a `var`.
|
|
885
|
+
* @param space - The destination `ColorSpace`, fixing the function form and the channels in scope.
|
|
886
|
+
* @param channel1 - The first channel (`l`/`r`), in the space's order.
|
|
887
|
+
* @param channel2 - The second channel (`c`/`g`).
|
|
888
|
+
* @param channel3 - The third channel (`h`/`b`).
|
|
889
|
+
* @param alpha - The optional alpha channel; omitted, the origin's alpha is kept.
|
|
890
|
+
* @returns A `Color` unioning the origin's and the channels' variables.
|
|
891
|
+
* @example
|
|
892
|
+
* ```ts
|
|
893
|
+
* const hover = Color.from(Color.var('accent'), ColorSpace.oklch, Calc.multiply(Channel.L, 0.8), Channel.C, Channel.H)
|
|
894
|
+
* Color.serialize(hover) // 'oklch(from var(--accent) calc(l * 0.8) c h)'
|
|
895
|
+
* const faded = Color.from(Color.var('brand'), ColorSpace.srgb, Channel.R, Channel.G, Channel.B, Calc.multiply(Channel.Alpha, 0.5))
|
|
896
|
+
* Color.serialize(faded) // 'color(from var(--brand) srgb r g b / calc(alpha * 0.5))'
|
|
897
|
+
* ```
|
|
898
|
+
* @since 0.2.0
|
|
899
|
+
*/
|
|
900
|
+
declare const from: <O extends Any = never, Space extends ColorSpace = ColorSpace, C1 extends Any = never, C2 extends Any = never, C3 extends Any = never, A extends Any = never>(origin: Color<O>, space: Space, channel1: RelativeChannel<C1, ChannelsOf<Space>>, channel2: RelativeChannel<C2, ChannelsOf<Space>>, channel3: RelativeChannel<C3, ChannelsOf<Space>>, alpha?: RelativeChannel<A, ChannelsOf<Space>>) => Color<O | C1 | C2 | C3 | A>;
|
|
901
|
+
declare const bind$1: {
|
|
902
|
+
/**
|
|
903
|
+
* Returns a function that binds the given names in a color's channels.
|
|
904
|
+
*
|
|
905
|
+
* @param bindings - Variable names to values or expressions.
|
|
906
|
+
* @returns A function replacing bound variables in its argument.
|
|
907
|
+
* @since 0.1.0
|
|
908
|
+
*/
|
|
909
|
+
<const B extends Bindings>(bindings: B): <Vars extends Any>(color: Color<Vars>) => Color<ApplyBindings<Vars, B>>;
|
|
910
|
+
/**
|
|
911
|
+
* Replaces variables in the color's channels with values or other
|
|
912
|
+
* expressions, re-folding constant subtrees. Semantics match
|
|
913
|
+
* `Calc.bind`: unread names and `undefined` values are ignored, and
|
|
914
|
+
* expression-valued bindings contribute their own variables.
|
|
915
|
+
*
|
|
916
|
+
* @param color - The color to bind.
|
|
917
|
+
* @param bindings - Variable names to values or expressions.
|
|
918
|
+
* @returns The bound color.
|
|
919
|
+
* @since 0.1.0
|
|
920
|
+
*/
|
|
921
|
+
<Vars extends Any, const B extends PartialBindings<Vars>>(color: Color<Vars>, bindings: B): Color<ApplyBindings<Vars, B>>;
|
|
922
|
+
};
|
|
923
|
+
/**
|
|
924
|
+
* Renders a color as CSS text. Channels render space-separated inside
|
|
925
|
+
* the color's own function form — `oklch(...)` or `color(srgb ...)` —
|
|
926
|
+
* each wrapped in `calc()` when it is arithmetic; a `lightDark` renders
|
|
927
|
+
* both arms in full, comma-separated.
|
|
928
|
+
*
|
|
929
|
+
* Options match `Calc.serialize`: partial bindings applied first, and a
|
|
930
|
+
* precision context for unannotated constants.
|
|
931
|
+
*
|
|
932
|
+
* @param color - The color to render.
|
|
933
|
+
* @param options - Optional bindings and precision context.
|
|
934
|
+
* @returns Deterministic CSS text.
|
|
935
|
+
* @example
|
|
936
|
+
* ```ts
|
|
937
|
+
* const surface = Color.oklch(Calc.add(Calc.var('l'), 0.1), 0.04, 250)
|
|
938
|
+
* Color.serialize(surface) // 'oklch(calc(var(--l) + 0.1) 0.04 250)'
|
|
939
|
+
* ```
|
|
940
|
+
* @since 0.1.0
|
|
941
|
+
*/
|
|
942
|
+
declare const serialize$1: <Vars extends Any>(color: Color<Vars>, options?: SerializeOptions<Vars>) => string;
|
|
943
|
+
/**
|
|
944
|
+
* The color's unbound variable names, unioned across channels.
|
|
945
|
+
*
|
|
946
|
+
* @param color - The color to inspect.
|
|
947
|
+
* @returns The set of unbound variable names.
|
|
948
|
+
* @since 0.1.0
|
|
949
|
+
*/
|
|
950
|
+
declare const vars$2: <Vars extends Any>(color: Color<Vars>) => ReadonlySet<Name<Vars>>;
|
|
951
|
+
/**
|
|
952
|
+
* The origin-channel keyword tokens the color reads — the `Channel` keywords a
|
|
953
|
+
* relative color's channels reference (`l`, `c`, `h`, ...), gathered across its
|
|
954
|
+
* channels and any nested colors. Empty for a color with no relative parts.
|
|
955
|
+
*
|
|
956
|
+
* The `Color` companion to `Calc.idents`, and the mirror of `vars`: where
|
|
957
|
+
* `vars` reports the custom properties a color depends on, `channels` reports
|
|
958
|
+
* the origin channels a relative color reads. They are disjoint — a channel
|
|
959
|
+
* keyword is never a variable — so a channel token never appears in `vars` nor
|
|
960
|
+
* reaches a `Stylesheet`'s dependency report.
|
|
961
|
+
*
|
|
962
|
+
* @param color - The color to inspect.
|
|
963
|
+
* @returns The set of channel-keyword tokens the color reads.
|
|
964
|
+
* @example
|
|
965
|
+
* ```ts
|
|
966
|
+
* const hover = Color.from(Color.var('accent'), ColorSpace.oklch, Calc.multiply(Channel.L, 0.8), Channel.C, Channel.H)
|
|
967
|
+
* Color.channels(hover) // Set { 'l', 'c', 'h' }
|
|
968
|
+
* Color.vars(hover) // Set { 'accent' }
|
|
969
|
+
* ```
|
|
970
|
+
* @since 0.2.0
|
|
971
|
+
*/
|
|
972
|
+
declare const channels: (color: Color<Any>) => ReadonlySet<string>;
|
|
973
|
+
declare const equals$2: {
|
|
974
|
+
/**
|
|
975
|
+
* Returns a function that checks structural equality against `that`.
|
|
976
|
+
*
|
|
977
|
+
* @param that - The color to compare against.
|
|
978
|
+
* @returns A function testing its argument for structural equality with `that`.
|
|
979
|
+
* @since 0.1.0
|
|
980
|
+
*/
|
|
981
|
+
(that: Color<Any>): (self: Color<Any>) => boolean;
|
|
982
|
+
/**
|
|
983
|
+
* Structural equality over colors: channel trees compare node for node,
|
|
984
|
+
* as in `Calc.equals`. Different color functions never compare equal,
|
|
985
|
+
* even where they would name the same point in color space.
|
|
986
|
+
*
|
|
987
|
+
* @param self - The first color.
|
|
988
|
+
* @param that - The second color.
|
|
989
|
+
* @returns `true` if the colors are structurally equal.
|
|
990
|
+
* @since 0.1.0
|
|
991
|
+
*/
|
|
992
|
+
(self: Color<Any>, that: Color<Any>): boolean;
|
|
993
|
+
};
|
|
994
|
+
declare namespace length_d_exports {
|
|
995
|
+
export { Length, em, px, rem, vh, vmax, vmin, vw };
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* A `<length>` expression: a `Calc` of length kind, in any length unit. Names
|
|
999
|
+
* the dimension without spelling `Calc<Vars, Unit.Length, unknown>` —
|
|
1000
|
+
* `Length.px(16)` produces one, and it composes with every `Calc` combinator
|
|
1001
|
+
* (adding two lengths is a length, dividing one by another is a number). `Vars`
|
|
1002
|
+
* unions the unbound variable names, as on `Calc`.
|
|
1003
|
+
*
|
|
1004
|
+
* The result is the widened `Unit.Length` and the requirements stay open, so
|
|
1005
|
+
* a mixed-unit sum (`Calc.add(Length.px(16), Length.vw(2))`) and every
|
|
1006
|
+
* single-unit length are alike assignable to it. Declared as an
|
|
1007
|
+
* interface so the name survives inference — the shape a typed `Var`'s
|
|
1008
|
+
* `Type` slot displays.
|
|
1009
|
+
*
|
|
1010
|
+
* @since 0.2.0
|
|
1011
|
+
*/
|
|
1012
|
+
interface Length<out Vars extends Any = Any> extends Calc<Vars, Length$1, unknown> {}
|
|
1013
|
+
/**
|
|
1014
|
+
* A length in `px` (absolute pixels).
|
|
1015
|
+
*
|
|
1016
|
+
* @param value - The pixel count.
|
|
1017
|
+
* @param precision - Optional serialization precision.
|
|
1018
|
+
* @returns A `px` length expression.
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* Calc.serialize(Length.px(16)) // '16px'
|
|
1022
|
+
* ```
|
|
1023
|
+
* @since 0.2.0
|
|
1024
|
+
*/
|
|
1025
|
+
declare const px: (value: number, precision?: Precision) => Calc<never, Px, Px>;
|
|
1026
|
+
/**
|
|
1027
|
+
* A length in `rem` (relative to the root font size).
|
|
1028
|
+
*
|
|
1029
|
+
* @param value - The multiple of the root font size.
|
|
1030
|
+
* @param precision - Optional serialization precision.
|
|
1031
|
+
* @returns A `rem` length expression.
|
|
1032
|
+
* @since 0.2.0
|
|
1033
|
+
*/
|
|
1034
|
+
declare const rem: (value: number, precision?: Precision) => Calc<never, Rem, Rem>;
|
|
1035
|
+
/**
|
|
1036
|
+
* A length in `em` (relative to the element font size).
|
|
1037
|
+
*
|
|
1038
|
+
* @param value - The multiple of the element font size.
|
|
1039
|
+
* @param precision - Optional serialization precision.
|
|
1040
|
+
* @returns An `em` length expression.
|
|
1041
|
+
* @since 0.2.0
|
|
1042
|
+
*/
|
|
1043
|
+
declare const em: (value: number, precision?: Precision) => Calc<never, Em, Em>;
|
|
1044
|
+
/**
|
|
1045
|
+
* A length in `vw` (1% of the viewport width).
|
|
1046
|
+
*
|
|
1047
|
+
* @param value - The percentage of viewport width.
|
|
1048
|
+
* @param precision - Optional serialization precision.
|
|
1049
|
+
* @returns A `vw` length expression.
|
|
1050
|
+
* @since 0.2.0
|
|
1051
|
+
*/
|
|
1052
|
+
declare const vw: (value: number, precision?: Precision) => Calc<never, Vw, Vw>;
|
|
1053
|
+
/**
|
|
1054
|
+
* A length in `vh` (1% of the viewport height).
|
|
1055
|
+
*
|
|
1056
|
+
* @param value - The percentage of viewport height.
|
|
1057
|
+
* @param precision - Optional serialization precision.
|
|
1058
|
+
* @returns A `vh` length expression.
|
|
1059
|
+
* @since 0.2.0
|
|
1060
|
+
*/
|
|
1061
|
+
declare const vh: (value: number, precision?: Precision) => Calc<never, Vh, Vh>;
|
|
1062
|
+
/**
|
|
1063
|
+
* A length in `vmin` (1% of the smaller viewport axis).
|
|
1064
|
+
*
|
|
1065
|
+
* @param value - The percentage of the smaller viewport axis.
|
|
1066
|
+
* @param precision - Optional serialization precision.
|
|
1067
|
+
* @returns A `vmin` length expression.
|
|
1068
|
+
* @since 0.2.0
|
|
1069
|
+
*/
|
|
1070
|
+
declare const vmin: (value: number, precision?: Precision) => Calc<never, Vmin, Vmin>;
|
|
1071
|
+
/**
|
|
1072
|
+
* A length in `vmax` (1% of the larger viewport axis).
|
|
1073
|
+
*
|
|
1074
|
+
* @param value - The percentage of the larger viewport axis.
|
|
1075
|
+
* @param precision - Optional serialization precision.
|
|
1076
|
+
* @returns A `vmax` length expression.
|
|
1077
|
+
* @since 0.2.0
|
|
1078
|
+
*/
|
|
1079
|
+
declare const vmax: (value: number, precision?: Precision) => Calc<never, Vmax, Vmax>;
|
|
1080
|
+
declare namespace lengthPercentage_d_exports {
|
|
1081
|
+
export { LengthPercentage, of$3 as of };
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* A `<length-percentage>` expression: a `Calc` whose Result spans the
|
|
1085
|
+
* length and percentage families. Every plain length and every percentage
|
|
1086
|
+
* is assignable to it; anchoring an operation on one admits operands from
|
|
1087
|
+
* both families, and the sum stays a `<length-percentage>`.
|
|
1088
|
+
*
|
|
1089
|
+
* Declared as an interface rather than a type alias so the name survives
|
|
1090
|
+
* inference — the shape a `Var.lengthPercentage` handle's `Type` slot
|
|
1091
|
+
* displays.
|
|
1092
|
+
*
|
|
1093
|
+
* @since 0.4.0
|
|
1094
|
+
*/
|
|
1095
|
+
interface LengthPercentage<out Vars extends Any = Any> extends Calc<Vars, LengthPercentage$1, unknown> {}
|
|
1096
|
+
type VarsOf$1<A> = A extends Calc<infer V, Any$1, unknown> ? V : never;
|
|
1097
|
+
type RequiresOf$1<A> = A extends Calc<Any, Any$1, infer Q> ? Q : never;
|
|
1098
|
+
/**
|
|
1099
|
+
* Widens a length or percentage expression to a `<length-percentage>` —
|
|
1100
|
+
* the identity at runtime, an anchor at the type level. Widening is what
|
|
1101
|
+
* unlocks mixing: the combinators key their operand family on the first
|
|
1102
|
+
* argument, so `Calc.subtract(LengthPercentage.of(Percentage.of(100)),
|
|
1103
|
+
* Length.px(24))` builds `calc(100% - 24px)` where the unwidened spelling
|
|
1104
|
+
* is a cross-family type error.
|
|
1105
|
+
*
|
|
1106
|
+
* A `<length-percentage>` read (`Calc.var(Var.lengthPercentage('inset'))`)
|
|
1107
|
+
* is already this wide; `of` serves values built from concrete units.
|
|
1108
|
+
*
|
|
1109
|
+
* @param value - A length, percentage, or already-mixed expression.
|
|
1110
|
+
* @returns The same expression, typed as a `<length-percentage>`.
|
|
1111
|
+
* @example
|
|
1112
|
+
* ```ts
|
|
1113
|
+
* const inset = LengthPercentage.of(Percentage.of(100))
|
|
1114
|
+
* Calc.serialize(Calc.subtract(inset, Length.px(24))) // 'calc(100% - 24px)'
|
|
1115
|
+
* ```
|
|
1116
|
+
* @since 0.4.0
|
|
1117
|
+
*/
|
|
1118
|
+
declare const of$3: <A extends Calc<Any, LengthPercentage$1, unknown>>(value: A) => Calc<VarsOf$1<A>, LengthPercentage$1, RequiresOf$1<A>>;
|
|
1119
|
+
declare namespace numeric_d_exports {
|
|
1120
|
+
export { Numeric };
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* A `<number>` expression: a `Calc` of number result, in no unit. Names the
|
|
1124
|
+
* dimension without spelling `Calc<Vars, Unit.None, unknown>` — `Calc.of(4)`
|
|
1125
|
+
* produces one, as does any combinator whose operands cancel to a number.
|
|
1126
|
+
* `Vars` unions the unbound variable names, as on `Calc`.
|
|
1127
|
+
*
|
|
1128
|
+
* The requirements stay open: a number-result expression can still carry
|
|
1129
|
+
* requirements (a relative-color channel ident, or the units of a
|
|
1130
|
+
* `vw / px` ratio), so no signature may assume number-result means
|
|
1131
|
+
* requirement-free.
|
|
1132
|
+
*
|
|
1133
|
+
* Declared as an interface rather than a type alias so the name survives
|
|
1134
|
+
* inference — this is the shape the `Type` slot of a typed `Var` displays,
|
|
1135
|
+
* and an alias would expand to its `Calc` spelling there.
|
|
1136
|
+
*
|
|
1137
|
+
* @since 0.4.0
|
|
1138
|
+
*/
|
|
1139
|
+
interface Numeric<out Vars extends Any = Any> extends Calc<Vars, None$1, unknown> {}
|
|
1140
|
+
declare namespace percentage_d_exports {
|
|
1141
|
+
export { Percentage, of$2 as of };
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* A `<percentage>` expression: a `Calc` of percentage kind. Names the dimension
|
|
1145
|
+
* without spelling `Calc<Vars, Unit.Percentage, unknown>` —
|
|
1146
|
+
* `Percentage.of(40)` produces one, and it composes with every `Calc`
|
|
1147
|
+
* combinator (adding two percentages is a percentage, one over another is a
|
|
1148
|
+
* number). `Vars` unions the unbound variable names, as on `Calc`.
|
|
1149
|
+
*
|
|
1150
|
+
* @since 0.2.0
|
|
1151
|
+
*/
|
|
1152
|
+
interface Percentage<out Vars extends Any = Any> extends Calc<Vars, Percentage$1, unknown> {}
|
|
1153
|
+
/**
|
|
1154
|
+
* A percentage — a number rendered with a trailing `%`. `Percentage.of(40)`
|
|
1155
|
+
* serializes as `40%`. The value passes through unrounded; the optional
|
|
1156
|
+
* `Precision` pins serialization exactly as `Calc.of` does.
|
|
1157
|
+
*
|
|
1158
|
+
* @param value - The percentage magnitude (`40` for `40%`, not `0.4`).
|
|
1159
|
+
* @param precision - Optional serialization precision.
|
|
1160
|
+
* @returns A `<percentage>` expression.
|
|
1161
|
+
* @example
|
|
1162
|
+
* ```ts
|
|
1163
|
+
* Calc.serialize(Percentage.of(40)) // '40%'
|
|
1164
|
+
* Calc.serialize(Calc.add(Percentage.of(20), Percentage.of(5))) // '25%'
|
|
1165
|
+
* Calc.solve(Percentage.of(50), { units: { '%': 320 / 100 } }) // 160
|
|
1166
|
+
* ```
|
|
1167
|
+
* @since 0.2.0
|
|
1168
|
+
*/
|
|
1169
|
+
declare const of$2: (value: number, precision?: Precision) => Calc<never, Percent, Percent>;
|
|
1170
|
+
declare namespace var_d_exports {
|
|
1171
|
+
export { Any, Fallback, Identity, Name, Type, Var, angle, color, equals$1 as equals, fallback, isVar, length, lengthPercentage, name, number, of$1 as of, percentage, vars$1 as vars };
|
|
1172
|
+
}
|
|
1173
|
+
declare const VarVariance: unique symbol;
|
|
1174
|
+
/**
|
|
1175
|
+
* A read of a CSS custom property: one `var()` invocation, modeled as a
|
|
1176
|
+
* value. A bare read (`Var.of('gap')`) doubles as the property's canonical
|
|
1177
|
+
* handle — the one value a consumer exports for a property — and
|
|
1178
|
+
* site-specific reads derive from it through `fallback` without disturbing
|
|
1179
|
+
* it.
|
|
1180
|
+
*
|
|
1181
|
+
* Three type parameters track the read:
|
|
1182
|
+
*
|
|
1183
|
+
* - `Name` — the property name, without the `--` prefix. This is the
|
|
1184
|
+
* read's identity: it is what the `Vars` parameter of `Calc`, `Color`,
|
|
1185
|
+
* and the containers unions, and what the runtime `vars()` reports list.
|
|
1186
|
+
* - `Type` — the declared value type, `unknown` while undeclared. The
|
|
1187
|
+
* vocabulary is the data types themselves: `length('gap')` is a
|
|
1188
|
+
* `Var<'gap', Length>`, `color('accent')` a `Var<'accent', Color>`. A
|
|
1189
|
+
* declared type gives the read a Result at the lift, types its
|
|
1190
|
+
* bindings, and drives `PropertyRule.make`'s syntax derivation; an
|
|
1191
|
+
* undeclared read lifts as a `<number>` with unconstrained bindings.
|
|
1192
|
+
* - `Fallback` — the fallback value, `undefined` on a bare read. The slot
|
|
1193
|
+
* is generic here: what a fallback may be depends on where the read
|
|
1194
|
+
* lands, and each admitting context (`Declaration.Value`, `Calc.var`,
|
|
1195
|
+
* `Color.var`) constrains it there.
|
|
1196
|
+
*
|
|
1197
|
+
* A read is not itself an expression. `Calc.var` and `Color.var` lift it
|
|
1198
|
+
* into their worlds, and a declaration accepts it directly as a whole
|
|
1199
|
+
* value (`Declaration.make('font-family', stack)` renders
|
|
1200
|
+
* `font-family: var(--stack)`).
|
|
1201
|
+
*
|
|
1202
|
+
* Values are immutable and structurally comparable via `equals` — two
|
|
1203
|
+
* reads of the same property with different fallbacks are different
|
|
1204
|
+
* values that report the same dependency.
|
|
1205
|
+
*
|
|
1206
|
+
* @since 0.4.0
|
|
1207
|
+
*/
|
|
1208
|
+
interface Var<out Name extends string = string, out Type = unknown, out Fallback = undefined> extends Pipeable {
|
|
1209
|
+
readonly [VarTypeId]: VarTypeId;
|
|
1210
|
+
readonly [VarVariance]?: {
|
|
1211
|
+
readonly name: Name;
|
|
1212
|
+
readonly type: Type;
|
|
1213
|
+
readonly fallback: Fallback;
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* The widest read — any name, any declared type, any fallback. The
|
|
1218
|
+
* supertype every read extends, used to constrain a parameter before its
|
|
1219
|
+
* facets are extracted.
|
|
1220
|
+
*
|
|
1221
|
+
* @since 0.4.0
|
|
1222
|
+
*/
|
|
1223
|
+
type Any = Var<string, unknown, unknown>;
|
|
1224
|
+
/**
|
|
1225
|
+
* The property name a read carries — `Name<Var<'gap'>>` is `'gap'`.
|
|
1226
|
+
* Distributes over unions, so applying it to a `Vars` phantom recovers the
|
|
1227
|
+
* name union the runtime `vars()` sets mirror.
|
|
1228
|
+
*
|
|
1229
|
+
* @since 0.4.0
|
|
1230
|
+
*/
|
|
1231
|
+
type Name<V extends Any> = V extends Var<infer N, unknown, unknown> ? N : never;
|
|
1232
|
+
/**
|
|
1233
|
+
* The declared value type a read carries — `unknown` while undeclared.
|
|
1234
|
+
*
|
|
1235
|
+
* @since 0.4.0
|
|
1236
|
+
*/
|
|
1237
|
+
type Type<V extends Any> = V extends Var<string, infer T, unknown> ? T : never;
|
|
1238
|
+
/**
|
|
1239
|
+
* The fallback value a read carries — `undefined` on a bare read.
|
|
1240
|
+
*
|
|
1241
|
+
* @since 0.4.0
|
|
1242
|
+
*/
|
|
1243
|
+
type Fallback<V extends Any> = V extends Var<string, unknown, infer F> ? F : never;
|
|
1244
|
+
/**
|
|
1245
|
+
* A read stripped to its identity: the name-and-type pair, fallback slot
|
|
1246
|
+
* cleared. This is what phantoms union — `Calc.var` on
|
|
1247
|
+
* `var(--x, var(--y))` returns a `Calc<Var<'x'> | Var<'y'>>`, identities
|
|
1248
|
+
* flattened, never a nested read.
|
|
1249
|
+
*
|
|
1250
|
+
* @since 0.4.0
|
|
1251
|
+
*/
|
|
1252
|
+
type Identity<V extends Any> = V extends Var<infer N, infer T, unknown> ? Var<N, T> : never;
|
|
1253
|
+
/**
|
|
1254
|
+
* Checks if a value is a `Var`.
|
|
1255
|
+
*
|
|
1256
|
+
* True only for values built by this module's constructors, which carry
|
|
1257
|
+
* the brand.
|
|
1258
|
+
*
|
|
1259
|
+
* @param u - The value to check.
|
|
1260
|
+
* @returns `true` if the value is a `Var`, `false` otherwise.
|
|
1261
|
+
* @since 0.4.0
|
|
1262
|
+
*/
|
|
1263
|
+
declare const isVar: (u: unknown) => u is Any;
|
|
1264
|
+
/**
|
|
1265
|
+
* Creates a bare read of a custom property — the property's canonical
|
|
1266
|
+
* handle. Accepted wherever a read is: as a declaration value, lifted by
|
|
1267
|
+
* `Calc.var` or `Color.var`, and (as sugar) both lifts also take the bare
|
|
1268
|
+
* name directly, so `Calc.var('gap')` and `Calc.var(Var.of('gap'))` are
|
|
1269
|
+
* the same expression.
|
|
1270
|
+
*
|
|
1271
|
+
* The read is undeclared: it lifts as a `<number>` and its bindings are
|
|
1272
|
+
* unconstrained. The typed constructors (`number`, `length`, `angle`,
|
|
1273
|
+
* `percentage`, `color`) declare a value type instead.
|
|
1274
|
+
*
|
|
1275
|
+
* Repeated calls with the same name return the same instance.
|
|
1276
|
+
*
|
|
1277
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1278
|
+
* @returns A bare undeclared read of `--name`.
|
|
1279
|
+
* @throws `Error` when `name` is empty.
|
|
1280
|
+
* @example
|
|
1281
|
+
* ```ts
|
|
1282
|
+
* const gap = Var.of('gap')
|
|
1283
|
+
* Calc.serialize(Calc.var(gap)) // 'var(--gap)'
|
|
1284
|
+
* ```
|
|
1285
|
+
* @since 0.4.0
|
|
1286
|
+
*/
|
|
1287
|
+
declare const of$1: <Name extends string>(name: Name) => Var<Name>;
|
|
1288
|
+
/**
|
|
1289
|
+
* Creates a read declared `<number>`. The declaration types the channel
|
|
1290
|
+
* end to end: the read lifts as a number-result expression (as an
|
|
1291
|
+
* undeclared read does), `bind` and `solve` accept only number-family
|
|
1292
|
+
* values for the name, and `PropertyRule.make` derives the `<number>`
|
|
1293
|
+
* syntax from the handle.
|
|
1294
|
+
*
|
|
1295
|
+
* Repeated calls with the same name return the same instance; a
|
|
1296
|
+
* differently-declared read of the same name is a different value (one
|
|
1297
|
+
* name, one type is the consumer's contract — see `docs/vars.md`).
|
|
1298
|
+
*
|
|
1299
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1300
|
+
* @returns A bare read of `--name`, declared `<number>`.
|
|
1301
|
+
* @throws `Error` when `name` is empty.
|
|
1302
|
+
* @since 0.4.0
|
|
1303
|
+
*/
|
|
1304
|
+
declare const number: <Name extends string>(name: Name) => Var<Name, Numeric>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Creates a read declared `<length>`. The read lifts as a length-family
|
|
1307
|
+
* expression — `Calc.add(Calc.var(gap), Length.px(4))` composes through
|
|
1308
|
+
* the ordinary dimension algebra — its bindings take length-family
|
|
1309
|
+
* values, and `PropertyRule.make` derives the `<length>` syntax.
|
|
1310
|
+
*
|
|
1311
|
+
* Repeated calls with the same name return the same instance.
|
|
1312
|
+
*
|
|
1313
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1314
|
+
* @returns A bare read of `--name`, declared `<length>`.
|
|
1315
|
+
* @throws `Error` when `name` is empty.
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```ts
|
|
1318
|
+
* const gap = Var.length('gap')
|
|
1319
|
+
* Calc.serialize(Calc.add(Calc.var(gap), Length.px(4))) // 'calc(var(--gap) + 4px)'
|
|
1320
|
+
* ```
|
|
1321
|
+
* @since 0.4.0
|
|
1322
|
+
*/
|
|
1323
|
+
declare const length: <Name extends string>(name: Name) => Var<Name, Length>;
|
|
1324
|
+
/**
|
|
1325
|
+
* Creates a read declared `<length-percentage>`. The read lifts spanning
|
|
1326
|
+
* both families — the anchor that admits length and percentage operands
|
|
1327
|
+
* beside it, so `Calc.subtract(Calc.var(inset), Length.px(24))` and a
|
|
1328
|
+
* percentage subtrahend both compose — its bindings take either family
|
|
1329
|
+
* (or a mix), and `PropertyRule.make` derives the `<length-percentage>`
|
|
1330
|
+
* syntax.
|
|
1331
|
+
*
|
|
1332
|
+
* Repeated calls with the same name return the same instance.
|
|
1333
|
+
*
|
|
1334
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1335
|
+
* @returns A bare read of `--name`, declared `<length-percentage>`.
|
|
1336
|
+
* @throws `Error` when `name` is empty.
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```ts
|
|
1339
|
+
* const inset = Var.lengthPercentage('inset')
|
|
1340
|
+
* Calc.serialize(Calc.subtract(Calc.var(inset), Length.px(24)))
|
|
1341
|
+
* // 'calc(var(--inset) - 24px)'
|
|
1342
|
+
* ```
|
|
1343
|
+
* @since 0.4.0
|
|
1344
|
+
*/
|
|
1345
|
+
declare const lengthPercentage: <Name extends string>(name: Name) => Var<Name, LengthPercentage>;
|
|
1346
|
+
/**
|
|
1347
|
+
* Creates a read declared `<angle>`: an angle-family read at the lift,
|
|
1348
|
+
* angle-family bindings, the `<angle>` syntax under `PropertyRule.make`.
|
|
1349
|
+
*
|
|
1350
|
+
* Repeated calls with the same name return the same instance.
|
|
1351
|
+
*
|
|
1352
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1353
|
+
* @returns A bare read of `--name`, declared `<angle>`.
|
|
1354
|
+
* @throws `Error` when `name` is empty.
|
|
1355
|
+
* @since 0.4.0
|
|
1356
|
+
*/
|
|
1357
|
+
declare const angle: <Name extends string>(name: Name) => Var<Name, Angle>;
|
|
1358
|
+
/**
|
|
1359
|
+
* Creates a read declared `<percentage>`: a percentage-family read at the
|
|
1360
|
+
* lift, percentage-family bindings, the `<percentage>` syntax under
|
|
1361
|
+
* `PropertyRule.make`.
|
|
1362
|
+
*
|
|
1363
|
+
* Repeated calls with the same name return the same instance.
|
|
1364
|
+
*
|
|
1365
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1366
|
+
* @returns A bare read of `--name`, declared `<percentage>`.
|
|
1367
|
+
* @throws `Error` when `name` is empty.
|
|
1368
|
+
* @since 0.4.0
|
|
1369
|
+
*/
|
|
1370
|
+
declare const percentage: <Name extends string>(name: Name) => Var<Name, Percentage>;
|
|
1371
|
+
/**
|
|
1372
|
+
* Creates a read declared `<color>`. A color does not participate in calc,
|
|
1373
|
+
* and the type says so: the read lifts through `Color.var` (never
|
|
1374
|
+
* `Calc.var`), and `PropertyRule.make` derives the `<color>` syntax.
|
|
1375
|
+
*
|
|
1376
|
+
* Repeated calls with the same name return the same instance.
|
|
1377
|
+
*
|
|
1378
|
+
* @param name - The property name, without the `--` prefix. Must be non-empty.
|
|
1379
|
+
* @returns A bare read of `--name`, declared `<color>`.
|
|
1380
|
+
* @throws `Error` when `name` is empty.
|
|
1381
|
+
* @example
|
|
1382
|
+
* ```ts
|
|
1383
|
+
* const accent = Var.color('accent')
|
|
1384
|
+
* Color.serialize(Color.var(accent)) // 'var(--accent)'
|
|
1385
|
+
* ```
|
|
1386
|
+
* @since 0.4.0
|
|
1387
|
+
*/
|
|
1388
|
+
declare const color: <Name extends string>(name: Name) => Var<Name, Color>;
|
|
1389
|
+
declare const fallback: {
|
|
1390
|
+
/**
|
|
1391
|
+
* Returns a function that derives a read carrying `fb` as its fallback.
|
|
1392
|
+
*
|
|
1393
|
+
* @param fb - The fallback value.
|
|
1394
|
+
* @returns A function that takes a read and returns the same property's read with `fb` as its fallback.
|
|
1395
|
+
* @since 0.4.0
|
|
1396
|
+
*/
|
|
1397
|
+
<const F>(fb: F): <V extends Any>(v: V) => Var<Name<V>, Type<V>, F>;
|
|
1398
|
+
/**
|
|
1399
|
+
* Derives a read of the same property carrying a fallback — the second
|
|
1400
|
+
* argument of the rendered `var()`, used by the browser when the
|
|
1401
|
+
* property is unset. The original read is untouched: fallback is a
|
|
1402
|
+
* property of the read site, not the variable, so one canonical handle
|
|
1403
|
+
* derives as many site-specific reads as needed.
|
|
1404
|
+
*
|
|
1405
|
+
* The fallback is held opaquely here. What it may be is constrained
|
|
1406
|
+
* where the read is used: a declaration value accepts any declaration
|
|
1407
|
+
* value (nested reads included), `Calc.var` accepts numeric fallbacks,
|
|
1408
|
+
* `Color.var` color-valued ones.
|
|
1409
|
+
*
|
|
1410
|
+
* A fallback joins the dependency report (`var(--x, var(--y))` reads
|
|
1411
|
+
* both names) but is discarded by `bind` when its read's own name is
|
|
1412
|
+
* bound, and does not reduce what `solve` requires — see `docs/vars.md`.
|
|
1413
|
+
*
|
|
1414
|
+
* @param v - The read to derive from.
|
|
1415
|
+
* @param fb - The fallback value. Must not be `undefined`.
|
|
1416
|
+
* @returns A read of the same property with `fb` as its fallback.
|
|
1417
|
+
* @throws `Error` when `fb` is `undefined`.
|
|
1418
|
+
* @example
|
|
1419
|
+
* ```ts
|
|
1420
|
+
* const gap = Var.of('gap')
|
|
1421
|
+
* Calc.serialize(Calc.var(gap.pipe(Var.fallback(8)))) // 'var(--gap, 8)'
|
|
1422
|
+
* ```
|
|
1423
|
+
* @since 0.4.0
|
|
1424
|
+
*/
|
|
1425
|
+
<V extends Any, const F>(v: V, fb: F): Var<Name<V>, Type<V>, F>;
|
|
1426
|
+
};
|
|
1427
|
+
/**
|
|
1428
|
+
* The property name a read carries, without the `--` prefix.
|
|
1429
|
+
*
|
|
1430
|
+
* @param v - The read to inspect.
|
|
1431
|
+
* @returns The bare property name.
|
|
1432
|
+
* @since 0.4.0
|
|
1433
|
+
*/
|
|
1434
|
+
declare const name: <V extends Any>(v: V) => Name<V>;
|
|
1435
|
+
/**
|
|
1436
|
+
* The names a read reads: its own, plus everything its fallback chain
|
|
1437
|
+
* reads (`var(--x, var(--y))` reads `x` and `y`). The runtime mirror of
|
|
1438
|
+
* the identities the read contributes to a `Vars` phantom when lifted.
|
|
1439
|
+
*
|
|
1440
|
+
* @param v - The read to inspect.
|
|
1441
|
+
* @returns The set of property names read.
|
|
1442
|
+
* @since 0.4.0
|
|
1443
|
+
*/
|
|
1444
|
+
declare const vars$1: (v: Any) => ReadonlySet<string>;
|
|
1445
|
+
declare const equals$1: {
|
|
1446
|
+
/**
|
|
1447
|
+
* Returns a function that checks structural equality against `that`.
|
|
1448
|
+
*
|
|
1449
|
+
* @param that - The read to compare against.
|
|
1450
|
+
* @returns A function testing its argument for structural equality with `that`.
|
|
1451
|
+
* @since 0.4.0
|
|
1452
|
+
*/
|
|
1453
|
+
(that: Any): (self: Any) => boolean;
|
|
1454
|
+
/**
|
|
1455
|
+
* Structural equality: names compare as text, declared types as data
|
|
1456
|
+
* (`Var.length('x')` never equals `Var.of('x')`), and fallbacks by
|
|
1457
|
+
* their own structural equality (expression fallbacks as expression
|
|
1458
|
+
* trees, primitive fallbacks by value). A bare read never equals a
|
|
1459
|
+
* fallback-carrying one.
|
|
1460
|
+
*
|
|
1461
|
+
* @param self - The first read.
|
|
1462
|
+
* @param that - The second read.
|
|
1463
|
+
* @returns `true` if the reads are structurally equal.
|
|
1464
|
+
* @since 0.4.0
|
|
1465
|
+
*/
|
|
1466
|
+
(self: Any, that: Any): boolean;
|
|
1467
|
+
};
|
|
1468
|
+
declare namespace angle_d_exports {
|
|
1469
|
+
export { Angle, deg, rad };
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* An `<angle>` expression: a `Calc` of angle kind, in any angle unit. Names the
|
|
1473
|
+
* dimension without spelling `Calc<Vars, Unit.Angle, unknown>` — `Angle.rad(2)`
|
|
1474
|
+
* produces one, and it composes with every `Calc` combinator (subtracting two
|
|
1475
|
+
* angles is an angle, scaling by a number stays an angle). `Vars` unions the
|
|
1476
|
+
* unbound variable names, as on `Calc`.
|
|
1477
|
+
*
|
|
1478
|
+
* The result is the widened `Unit.Angle`, so every specific angle expression
|
|
1479
|
+
* is assignable to it; a constructor narrows it (`Angle.rad` carries `Unit.Rad`). Declared as an
|
|
1480
|
+
* interface so the name survives inference — the shape a typed `Var`'s
|
|
1481
|
+
* `Type` slot displays.
|
|
1482
|
+
*
|
|
1483
|
+
* @since 0.2.0
|
|
1484
|
+
*/
|
|
1485
|
+
interface Angle<out Vars extends Any = Any> extends Calc<Vars, Angle$1, unknown> {}
|
|
1486
|
+
/**
|
|
1487
|
+
* An angle in `rad` (radians). Radians are the numeric measure of an angle, so
|
|
1488
|
+
* a radian-only expression solves with no unit context.
|
|
1489
|
+
*
|
|
1490
|
+
* @param value - The angle in radians.
|
|
1491
|
+
* @param precision - Optional serialization precision.
|
|
1492
|
+
* @returns A `rad` angle expression.
|
|
1493
|
+
* @example
|
|
1494
|
+
* ```ts
|
|
1495
|
+
* Calc.serialize(Angle.rad(1.5708)) // '1.5708rad'
|
|
1496
|
+
* ```
|
|
1497
|
+
* @since 0.2.0
|
|
1498
|
+
*/
|
|
1499
|
+
declare const rad: (value: number, precision?: Precision) => Calc<never, Rad, Rad>;
|
|
1500
|
+
/**
|
|
1501
|
+
* An angle in `deg` (degrees). Degrees lower to radians at solve (`180deg` is
|
|
1502
|
+
* `pi`), a fixed ratio, so a degree-only expression solves with no unit context.
|
|
1503
|
+
*
|
|
1504
|
+
* @param value - The angle in degrees.
|
|
1505
|
+
* @param precision - Optional serialization precision.
|
|
1506
|
+
* @returns A `deg` angle expression.
|
|
1507
|
+
* @example
|
|
1508
|
+
* ```ts
|
|
1509
|
+
* Calc.serialize(Angle.deg(45)) // '45deg'
|
|
1510
|
+
* ```
|
|
1511
|
+
* @since 0.2.0
|
|
1512
|
+
*/
|
|
1513
|
+
declare const deg: (value: number, precision?: Precision) => Calc<never, Deg, Deg>;
|
|
1514
|
+
declare namespace calc_d_exports {
|
|
1515
|
+
export { ApplyBindings, BindingRequires, Bindings, Calc, DeclaredType, Ident, IdentValues, Input, Kind, PartialBindings, ReadResult, SerializeOptions, SolveOptions, Top, abs, acos, add, atan2, bind, clamp, cos, divide, equals, idents, isCalc, lerp, max, min, mod, multiply, of, pow, serialize, sign, signedPow, sin, solve, subtract, tan, units, _var as var, vars };
|
|
1516
|
+
}
|
|
1517
|
+
declare const CalcVariance: unique symbol;
|
|
1518
|
+
declare const IdentId: unique symbol;
|
|
1519
|
+
/**
|
|
1520
|
+
* The CSS dimension vocabulary: `<number>`, `<length>`, `<angle>`, or
|
|
1521
|
+
* `<percentage>`. The algebra itself runs on `Result` unit brands compared by
|
|
1522
|
+
* `Unit.Family` — CSS type-checks `calc()` at this dimension level, and the
|
|
1523
|
+
* family comparison implements exactly that — so `Kind` remains as the prose
|
|
1524
|
+
* and runtime vocabulary: dimensioned constants carry it, and the docs speak
|
|
1525
|
+
* it. A `<percentage>` is its own dimension, not a length: it adds only to
|
|
1526
|
+
* another percentage — unless the expression is anchored on a
|
|
1527
|
+
* `<length-percentage>` value (a `Var.lengthPercentage` read, or
|
|
1528
|
+
* `LengthPercentage.of`), which admits both families (see `docs/design.md`).
|
|
1529
|
+
*
|
|
1530
|
+
* @since 0.2.0
|
|
1531
|
+
*/
|
|
1532
|
+
type Kind = 'number' | 'length' | 'angle' | 'percentage';
|
|
1533
|
+
/**
|
|
1534
|
+
* The leaf brand of a bare CSS identifier — a token like a relative color's
|
|
1535
|
+
* `l` that serializes as itself and is resolved by the CSS construct around
|
|
1536
|
+
* it, not read from the cascade. It rides the `Requires` parameter of `Calc`,
|
|
1537
|
+
* so `solve` demands a value for the token through the `idents` section of
|
|
1538
|
+
* its options, the way a relative unit demands a ratio through `units`.
|
|
1539
|
+
*
|
|
1540
|
+
* Constructs that introduce identifiers refine this brand: the `Channel`
|
|
1541
|
+
* keywords (`Channel.L`, ...) carry a subtype scoped to their color space,
|
|
1542
|
+
* and `Color.from` admits them by that subtype. Generic machinery — the
|
|
1543
|
+
* solve options, `idents` — keys on this base, so every identifier source
|
|
1544
|
+
* is covered without new plumbing.
|
|
1545
|
+
*
|
|
1546
|
+
* @since 0.2.0
|
|
1547
|
+
*/
|
|
1548
|
+
interface Ident<Name extends string = string> {
|
|
1549
|
+
readonly [IdentId]: Name;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* A CSS value expression: a tree of constants, unbound variables, and math
|
|
1553
|
+
* operations that can be solved to a number, serialized to CSS `calc()`
|
|
1554
|
+
* text, or partially bound and passed along.
|
|
1555
|
+
*
|
|
1556
|
+
* Three type parameters track the expression structurally:
|
|
1557
|
+
*
|
|
1558
|
+
* - `Vars` — the identities of the custom-property reads still unbound,
|
|
1559
|
+
* as `Var` values from `fashionable/var`: `var('u')` is a
|
|
1560
|
+
* `Calc<Var<'u'>>`. Combining expressions unions their reads; `bind`
|
|
1561
|
+
* subtracts the names it binds. A fully bound (or constant) expression
|
|
1562
|
+
* is a `Calc<never>`. Names stay the value-level currency — binding
|
|
1563
|
+
* records are keyed by bare name, and `vars` reports names — while the
|
|
1564
|
+
* phantom carries the identities.
|
|
1565
|
+
* - `Result` — what the expression produces, as a set of `Unit` brands:
|
|
1566
|
+
* `Unit.Px` for a pure pixel length, `Unit.Px | Unit.Vw` for a mixed sum
|
|
1567
|
+
* (a composition, not an uncertainty), `Unit.None` for a `<number>`. The
|
|
1568
|
+
* algebra enforces the CSS dimension rules through it — same-family
|
|
1569
|
+
* addition, family-merging multiplication, same-family division producing
|
|
1570
|
+
* `Unit.None` — so a `<length>` plus a `<number>` is a type error.
|
|
1571
|
+
* - `Requires` — what stands between the expression and a number: the unit
|
|
1572
|
+
* ratios and identifier values the matching sections of `solve`'s options
|
|
1573
|
+
* must supply (`never` when nothing is needed). Absolute units ride it
|
|
1574
|
+
* with default supplies — `px`, `rad`, and `deg` demand no entry.
|
|
1575
|
+
*
|
|
1576
|
+
* Values are immutable and structurally comparable via `equals`.
|
|
1577
|
+
* Construction folds constant subtrees eagerly: `add(1, 2)` is the
|
|
1578
|
+
* constant `3`, and binding every variable of a tree collapses it to a
|
|
1579
|
+
* constant.
|
|
1580
|
+
*
|
|
1581
|
+
* An unbound variable serializes as `var(--name)` — the read side of a CSS
|
|
1582
|
+
* custom property.
|
|
1583
|
+
*
|
|
1584
|
+
* Construct via `of`, `var`, the `Length`/`Angle` constructors in
|
|
1585
|
+
* `fashionable/data`, and the math combinators.
|
|
1586
|
+
*
|
|
1587
|
+
* @since 0.1.0
|
|
1588
|
+
*/
|
|
1589
|
+
interface Calc<out Vars extends Any = Any, out Result = None$1, out Requires = never> extends Pipeable {
|
|
1590
|
+
readonly [CalcTypeId]: CalcTypeId;
|
|
1591
|
+
readonly [CalcVariance]?: {
|
|
1592
|
+
readonly vars: Vars;
|
|
1593
|
+
readonly result: Result;
|
|
1594
|
+
readonly requires: Requires;
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* The widest `Calc` — the supertype every expression extends, used to
|
|
1599
|
+
* constrain a combinator operand before its facets are extracted.
|
|
1600
|
+
*
|
|
1601
|
+
* @since 0.2.0
|
|
1602
|
+
*/
|
|
1603
|
+
type Top = Calc<Any, Any$1, unknown>;
|
|
1604
|
+
/** Any operand a combinator accepts: an expression of any dimension, or a bare number. */
|
|
1605
|
+
type In = Top | number;
|
|
1606
|
+
type VarsOf<A> = A extends Calc<infer X, Any$1, unknown> ? X : never;
|
|
1607
|
+
type ResultOf<A> = A extends Calc<Any, infer R, unknown> ? R : None$1;
|
|
1608
|
+
type RequiresOf<A> = A extends Calc<Any, Any$1, infer Q> ? Q : never;
|
|
1609
|
+
/** An operand constrained to number-result (or a bare number). */
|
|
1610
|
+
type NumberIn = number | Calc<Any, None$1, unknown>;
|
|
1611
|
+
/** An operand accepted by `sin`/`cos`: a plain number (radians) or an angle. */
|
|
1612
|
+
type NumberOrAngleIn = number | Calc<Any, None$1 | Angle$1, unknown>;
|
|
1613
|
+
/**
|
|
1614
|
+
* An operand constrained to `A`'s dimension family — a bare number only when
|
|
1615
|
+
* `A` is number-result, so `add(length, 1)` is rejected while
|
|
1616
|
+
* `add(length, length)` holds.
|
|
1617
|
+
*/
|
|
1618
|
+
type SameKindIn<A> = Calc<Any, Family<ResultOf<A>>, unknown> | (Family<ResultOf<A>> extends None$1 ? number : never);
|
|
1619
|
+
type VarsOfAll<T extends ReadonlyArray<unknown>> = { [K in keyof T]: VarsOf<T[K]>; }[number];
|
|
1620
|
+
type ResultOfAll<T extends ReadonlyArray<unknown>> = { [K in keyof T]: ResultOf<T[K]>; }[number];
|
|
1621
|
+
type RequiresOfAll<T extends ReadonlyArray<unknown>> = { [K in keyof T]: RequiresOf<T[K]>; }[number];
|
|
1622
|
+
type IsUnion<T, U = T> = [T] extends [never] ? false : T extends T ? [U] extends [T] ? false : true : never;
|
|
1623
|
+
type Singleton<T> = [T] extends [never] ? false : IsUnion<T> extends true ? false : true;
|
|
1624
|
+
type LeafFn<X> = <T>() => T extends X ? 1 : 2;
|
|
1625
|
+
type LeafEqual<A, B> = LeafFn<A> extends LeafFn<B> ? true : false;
|
|
1626
|
+
type SameSingleton<A, B> = LeafEqual<A, B> extends true ? Singleton<A> : false;
|
|
1627
|
+
type DivRequires<A, B> = Family<ResultOf<B>> extends None$1 ? RequiresOf<A> | RequiresOf<B> : SameSingleton<RequiresOf<A>, RequiresOf<B>> extends true ? [Extract<RequiresOf<A>, Ident<string>>] extends [never] ? never : RequiresOf<A> | RequiresOf<B> : RequiresOf<A> | RequiresOf<B>;
|
|
1628
|
+
/**
|
|
1629
|
+
* A value accepted where an expression is expected: an existing `Calc` or
|
|
1630
|
+
* a bare number, which is coerced to an unannotated constant.
|
|
1631
|
+
*
|
|
1632
|
+
* @since 0.1.0
|
|
1633
|
+
*/
|
|
1634
|
+
type Input<Vars extends Any = Any> = Calc<Vars> | number;
|
|
1635
|
+
/**
|
|
1636
|
+
* The declared type of the read named `N` in `Vars` — the identity's
|
|
1637
|
+
* `Type` slot, recovered per name. `unknown` while the name is undeclared;
|
|
1638
|
+
* a union when a name is declared twice (a violation of the one-name,
|
|
1639
|
+
* one-type contract, met leniently).
|
|
1640
|
+
*
|
|
1641
|
+
* @since 0.4.0
|
|
1642
|
+
*/
|
|
1643
|
+
type DeclaredType<Vars extends Any, N extends string> = Type<Extract<Vars, Var<N, unknown, unknown>>>;
|
|
1644
|
+
type BindingValue<T> = [unknown] extends [T] ? Input : T extends Calc<Any, infer R, unknown> ? Calc<Any, Family<R>, unknown> | ([Family<R>] extends [None$1] ? number : never) : Input;
|
|
1645
|
+
/**
|
|
1646
|
+
* A bindings record: bare variable names to the values that replace them.
|
|
1647
|
+
* A value may itself be an expression, whose own reads join the result.
|
|
1648
|
+
*
|
|
1649
|
+
* Keys are names, not `Var` values — names are the value-level currency
|
|
1650
|
+
* of the variables channel; the identities live in the `Vars` phantom the
|
|
1651
|
+
* record is derived from (mapped over `Var.Name<Vars>`). A declared name
|
|
1652
|
+
* types its value: a `Var.length` read binds only to length-family
|
|
1653
|
+
* expressions, while undeclared names accept any `Input`.
|
|
1654
|
+
*
|
|
1655
|
+
* @since 0.1.0
|
|
1656
|
+
*/
|
|
1657
|
+
type Bindings<Vars extends Any = Any> = { readonly [N in Name<Vars>]: BindingValue<DeclaredType<Vars, N>>; };
|
|
1658
|
+
type ValueVars<V> = V extends Calc<infer R> ? R : never;
|
|
1659
|
+
type BindingVars<T> = T extends Record<string, infer V> ? ValueVars<V> : never;
|
|
1660
|
+
/**
|
|
1661
|
+
* The read identities remaining after applying the bindings `B` to an
|
|
1662
|
+
* expression with reads `Vars`: identities whose names are bound are
|
|
1663
|
+
* removed, and the reads of any expression-valued bindings are added.
|
|
1664
|
+
*
|
|
1665
|
+
* @since 0.1.0
|
|
1666
|
+
*/
|
|
1667
|
+
type ApplyBindings<Vars extends Any, B> = (Vars extends unknown ? (Name<Vars> extends keyof B ? never : Vars) : never) | BindingVars<Pick<B, Extract<keyof B, Name<Vars>>>>;
|
|
1668
|
+
type ValueRequires<V> = V extends Calc<Any, Any$1, infer Q> ? Q : never;
|
|
1669
|
+
type RecordRequires<T> = T extends Record<string, infer V> ? ValueRequires<V> : never;
|
|
1670
|
+
/**
|
|
1671
|
+
* What `bind` accepts for an expression with reads `Vars`: `Bindings`
|
|
1672
|
+
* with every name optional (binding may be partial), intersected with a
|
|
1673
|
+
* wide index signature so a record sharing no names with the expression
|
|
1674
|
+
* stays legal — unread names are ignored, and without the index signature
|
|
1675
|
+
* the all-optional record would be a weak type that rejects exactly the
|
|
1676
|
+
* spread-a-wider-object usage the contract promises. Present names still
|
|
1677
|
+
* check against their declared types through the `Bindings` half.
|
|
1678
|
+
*
|
|
1679
|
+
* @since 0.4.0
|
|
1680
|
+
*/
|
|
1681
|
+
type PartialBindings<Vars extends Any> = Partial<Bindings<Vars>> & {
|
|
1682
|
+
readonly [name: string]: Calc<Any, Any$1, unknown> | number | undefined;
|
|
1683
|
+
};
|
|
1684
|
+
/**
|
|
1685
|
+
* The requirements the bindings `B` contribute to an expression with reads
|
|
1686
|
+
* `Vars`: the union of the bound values' own `Requires`, over the names
|
|
1687
|
+
* the expression actually reads. This is `bind`'s side of the split with
|
|
1688
|
+
* `solve` — `bind` is partial evaluation, so a bound `Length.vw(2)` may
|
|
1689
|
+
* carry its `vw` requirement into the result, where `solve` is total and
|
|
1690
|
+
* accepts only pre-satisfied values (see `docs/vars.md`).
|
|
1691
|
+
*
|
|
1692
|
+
* @since 0.4.0
|
|
1693
|
+
*/
|
|
1694
|
+
type BindingRequires<Vars extends Any, B> = RecordRequires<Pick<B, Extract<keyof B, Name<Vars>>>>;
|
|
1695
|
+
/**
|
|
1696
|
+
* Options for `serialize`.
|
|
1697
|
+
*
|
|
1698
|
+
* @since 0.1.0
|
|
1699
|
+
*/
|
|
1700
|
+
interface SerializeOptions<Vars extends Any = Any> {
|
|
1701
|
+
/**
|
|
1702
|
+
* Bindings applied before rendering. May be partial: variables left
|
|
1703
|
+
* unbound render as `var(--name)`.
|
|
1704
|
+
*/
|
|
1705
|
+
readonly bindings?: Partial<Bindings<Vars>>;
|
|
1706
|
+
/**
|
|
1707
|
+
* The precision for constants that carry no annotation of their own.
|
|
1708
|
+
* Defaults to `Precision.decimals(5)`.
|
|
1709
|
+
*/
|
|
1710
|
+
readonly precision?: Precision;
|
|
1711
|
+
}
|
|
1712
|
+
type IdentName<I> = I extends Ident<infer Name> ? Name : never;
|
|
1713
|
+
/**
|
|
1714
|
+
* The `idents` section of `SolveOptions`: a numeric value for each
|
|
1715
|
+
* bare-identifier token in the requirements `R`. The value is the token's
|
|
1716
|
+
* own — read directly, not multiplied as a ratio — so `{ l: 0.62 }` supplies
|
|
1717
|
+
* the relative-color `l` keyword.
|
|
1718
|
+
*
|
|
1719
|
+
* @since 0.4.0
|
|
1720
|
+
*/
|
|
1721
|
+
type IdentValues<R> = { readonly [K in IdentName<Extract<R, Ident<string>>> & string]: number; };
|
|
1722
|
+
/**
|
|
1723
|
+
* Options for `solve`: the environments that satisfy an expression's
|
|
1724
|
+
* dependency channels. Each section is required exactly when the
|
|
1725
|
+
* expression's type demands it — `bindings` while unbound variables remain,
|
|
1726
|
+
* `units` while a relative unit or percentage is present, `idents` while a
|
|
1727
|
+
* bare identifier is — and optional otherwise.
|
|
1728
|
+
*
|
|
1729
|
+
* - `bindings` — a closed value (a number or a `Calc<never>`) for every
|
|
1730
|
+
* unbound variable. Substitution, as in `bind`, but total: a value
|
|
1731
|
+
* carrying its own unbound variables is a type error here, since nothing
|
|
1732
|
+
* later could close it.
|
|
1733
|
+
* - `units` — a pixels-per-unit ratio for every context-dependent unit:
|
|
1734
|
+
* `vw` is `sampleWidth / 100`, `%` is `basis / 100`. Absolute lengths
|
|
1735
|
+
* default (`px` is `1`) unless overridden; angles never appear (radians
|
|
1736
|
+
* and degrees lower on their own).
|
|
1737
|
+
* - `idents` — the value each bare-identifier token stands for
|
|
1738
|
+
* (`{ l: 0.62 }`).
|
|
1739
|
+
*
|
|
1740
|
+
* @since 0.4.0
|
|
1741
|
+
*/
|
|
1742
|
+
type SolveBindingValue<T> = [unknown] extends [T] ? Input<never> : T extends Calc<Any, infer R, unknown> ? Calc<never, Family<R>, ContextFree> | ([Family<R>] extends [None$1] ? number : never) : Input<never>;
|
|
1743
|
+
type SolveOptions<Vars extends Any, R> = ([Vars] extends [never] ? {
|
|
1744
|
+
readonly bindings?: Record<string, Input<never>>;
|
|
1745
|
+
} : {
|
|
1746
|
+
readonly bindings: { readonly [N in Name<Vars>]: SolveBindingValue<DeclaredType<Vars, N>>; };
|
|
1747
|
+
}) & ([Exclude<R, ContextFree | Ident<string>>] extends [never] ? {
|
|
1748
|
+
readonly units?: UnitContext<R>;
|
|
1749
|
+
} : {
|
|
1750
|
+
readonly units: UnitContext<R>;
|
|
1751
|
+
}) & ([Extract<R, Ident<string>>] extends [never] ? {
|
|
1752
|
+
readonly idents?: IdentValues<R>;
|
|
1753
|
+
} : {
|
|
1754
|
+
readonly idents: IdentValues<R>;
|
|
1755
|
+
});
|
|
1756
|
+
/**
|
|
1757
|
+
* Checks if a value is a `Calc`.
|
|
1758
|
+
*
|
|
1759
|
+
* True only for values built by this module's constructors, which carry
|
|
1760
|
+
* the brand.
|
|
1761
|
+
*
|
|
1762
|
+
* @param u - The value to check.
|
|
1763
|
+
* @returns `true` if the value is a `Calc`, `false` otherwise.
|
|
1764
|
+
* @since 0.1.0
|
|
1765
|
+
*/
|
|
1766
|
+
declare const isCalc: (u: unknown) => u is Calc<Any, Any$1, unknown>;
|
|
1767
|
+
/**
|
|
1768
|
+
* Creates a constant expression, optionally annotated with a serialization
|
|
1769
|
+
* precision that overrides the context default wherever the constant lands
|
|
1770
|
+
* — including in constants produced by folding it with others (the
|
|
1771
|
+
* highest-fidelity operand annotation wins).
|
|
1772
|
+
*
|
|
1773
|
+
* Bare numbers passed to combinators become unannotated constants; `of`
|
|
1774
|
+
* exists to name a value or pin its precision.
|
|
1775
|
+
*
|
|
1776
|
+
* @param value - The constant value. Must be finite.
|
|
1777
|
+
* @param precision - Optional precision annotation.
|
|
1778
|
+
* @returns A constant `Calc<never>`.
|
|
1779
|
+
* @throws `Error` when `value` is not finite.
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```ts
|
|
1782
|
+
* const k = Calc.of(0.8377580409572781, Precision.significant(10))
|
|
1783
|
+
* Calc.serialize(Calc.multiply(k, Calc.var('t'))) // 'calc(0.837758041 * var(--t))'
|
|
1784
|
+
* ```
|
|
1785
|
+
* @since 0.1.0
|
|
1786
|
+
*/
|
|
1787
|
+
declare const of: (value: number, precision?: Precision) => Calc<never>;
|
|
1788
|
+
/**
|
|
1789
|
+
* The Result a lifted read produces: its declared type's Result when the
|
|
1790
|
+
* declaration is calc-shaped — the trait is the `Result` parameter itself,
|
|
1791
|
+
* read structurally — and `Unit.None` while the read is undeclared.
|
|
1792
|
+
*
|
|
1793
|
+
* @since 0.4.0
|
|
1794
|
+
*/
|
|
1795
|
+
type ReadResult<T> = T extends Calc<Any, infer R, unknown> ? R : None$1;
|
|
1796
|
+
type ReadVars<V> = V extends Var<infer N, infer T, infer F> ? Var<N, T> | ReadFallbackVars<F> : never;
|
|
1797
|
+
type ReadFallbackVars<F> = F extends Calc<infer W, Any$1, unknown> ? W : F extends Any ? ReadVars<F> : never;
|
|
1798
|
+
type ReadGuard<V> = V extends Var<string, infer T, infer F> ? [unknown] extends [T] ? FallbackGuard<F, None$1> : T extends Calc<Any, Any$1, unknown> ? FallbackGuard<F, Family<ReadResult<T>>> : 'this read is declared outside calc: a color-typed read lifts with Color.var' : never;
|
|
1799
|
+
type FallbackGuard<F, Fam> = [F] extends [undefined] ? unknown : F extends number ? [Fam] extends [None$1] ? unknown : 'a bare-number fallback fits only a number-result read' : F extends Calc<Any, infer R, unknown> ? [Family<R>] extends [Fam] ? unknown : "this fallback's family does not match the read's declared type" : F extends Var<string, infer T2, infer F2> ? [unknown] extends [T2] ? [None$1] extends [Fam] ? FallbackGuard<F2, Fam> : "an undeclared nested read is number-result; declare it to match the outer read's family" : T2 extends Calc<Any, Any$1, unknown> ? [Family<ReadResult<T2>>] extends [Fam] ? FallbackGuard<F2, Fam> : "a nested read's declared family must match the outer read's" : 'a color-typed read cannot fall back inside calc' : 'a calc fallback is a number, a Calc expression, or a Var read';
|
|
1800
|
+
declare const _var: {
|
|
1801
|
+
/**
|
|
1802
|
+
* Creates a read of a CSS variable (custom property): `var('width')`
|
|
1803
|
+
* serializes as `var(--width)`. Variables are the substitutable
|
|
1804
|
+
* dependency channel — `bind` replaces them with values or other
|
|
1805
|
+
* expressions, and an expression's `Vars` parameter tracks the reads
|
|
1806
|
+
* still unbound. Exported as `var` (`Calc.var('width')`) because `var`
|
|
1807
|
+
* is reserved in declaration position.
|
|
1808
|
+
*
|
|
1809
|
+
* Sugar for the read overload: `Calc.var('width')` is
|
|
1810
|
+
* `Calc.var(Var.of('width'))`. Repeated calls with the same name return
|
|
1811
|
+
* the same instance.
|
|
1812
|
+
*
|
|
1813
|
+
* @param name - The variable name, without the `--` prefix. Must be non-empty.
|
|
1814
|
+
* @returns A `Calc` reading `name`, its one unbound variable.
|
|
1815
|
+
* @throws `Error` when `name` is empty.
|
|
1816
|
+
* @example
|
|
1817
|
+
* ```ts
|
|
1818
|
+
* Calc.serialize(Calc.var('width')) // 'var(--width)'
|
|
1819
|
+
* ```
|
|
1820
|
+
* @since 0.1.0
|
|
1821
|
+
*/
|
|
1822
|
+
<Name extends string>(name: Name): Calc<Var<Name>>;
|
|
1823
|
+
/**
|
|
1824
|
+
* Lifts a `Var` read into an expression. The read's declared type sets
|
|
1825
|
+
* the expression's Result: a `Var.length` read is a length-family
|
|
1826
|
+
* expression that composes through the ordinary dimension algebra, an
|
|
1827
|
+
* undeclared read is a `<number>` as before, and a color-typed read is
|
|
1828
|
+
* rejected — it lifts with `Color.var`.
|
|
1829
|
+
*
|
|
1830
|
+
* A fallback-carrying read renders its fallback (`var(--gap, 8)`),
|
|
1831
|
+
* which must land in the read's family: a bare number only under a
|
|
1832
|
+
* number-result read, a `Calc` of the declared family (rendered under
|
|
1833
|
+
* the normal rules, so arithmetic gets a nested `calc()` wrapper), or
|
|
1834
|
+
* another read of the same family, recursively. Anything else is a type
|
|
1835
|
+
* error at this lift, backed by a runtime check on the world (family
|
|
1836
|
+
* fidelity within calc is the type level's job alone, as everywhere
|
|
1837
|
+
* else in the algebra).
|
|
1838
|
+
*
|
|
1839
|
+
* The returned expression's `Vars` unions the read's identity with its
|
|
1840
|
+
* fallback chain's, flattened — `var(--x, var(--y))` is a
|
|
1841
|
+
* `Calc<Var<'x'> | Var<'y'>>`, and both names join the dependency
|
|
1842
|
+
* report. Binding the read's own name replaces the whole read and
|
|
1843
|
+
* discards the fallback; a fallback never reduces what `solve`
|
|
1844
|
+
* requires (see `docs/vars.md`).
|
|
1845
|
+
*
|
|
1846
|
+
* @param read - The read to lift, from `Var.of` or a typed constructor (optionally through `Var.fallback`).
|
|
1847
|
+
* @returns A `Calc` of the read's declared family, with its fallback chain's reads unioned in.
|
|
1848
|
+
* @throws `Error` when the read is color-declared, or its fallback chain holds anything but numbers, `Calc` expressions, and reads.
|
|
1849
|
+
* @example
|
|
1850
|
+
* ```ts
|
|
1851
|
+
* const gap = Var.length('gap')
|
|
1852
|
+
* Calc.serialize(Calc.add(Calc.var(gap), Length.px(4))) // 'calc(var(--gap) + 4px)'
|
|
1853
|
+
* ```
|
|
1854
|
+
* @since 0.4.0
|
|
1855
|
+
*/
|
|
1856
|
+
<V extends Any>(read: V & ReadGuard<V>): Calc<ReadVars<V>, ReadResult<Type<V>>, never>;
|
|
1857
|
+
};
|
|
1858
|
+
/**
|
|
1859
|
+
* Adds expressions. Constant operands fold at construction.
|
|
1860
|
+
*
|
|
1861
|
+
* Serializes as `a + b + ...` inside a `calc()` wrapper; negative constant
|
|
1862
|
+
* terms (and products led by a negative constant) render subtractively:
|
|
1863
|
+
* `a + (-2)` serializes as `a - 2`.
|
|
1864
|
+
*
|
|
1865
|
+
* @param a - The first operand.
|
|
1866
|
+
* @param b - The second operand, sharing `a`'s dimension.
|
|
1867
|
+
* @returns The sum, with the operands' variables, results, and requirements unioned.
|
|
1868
|
+
* @example
|
|
1869
|
+
* ```ts
|
|
1870
|
+
* Calc.serialize(Calc.add(Calc.var('x'), 10)) // 'calc(var(--x) + 10)'
|
|
1871
|
+
* ```
|
|
1872
|
+
* @since 0.1.0
|
|
1873
|
+
*/
|
|
1874
|
+
declare const add: <A extends In, B extends SameKindIn<A>, Rest extends ReadonlyArray<SameKindIn<A>>>(a: A, b: B, ...rest: Rest) => Calc<VarsOf<A> | VarsOf<B> | VarsOfAll<Rest>, ResultOf<A> | ResultOf<B> | ResultOfAll<Rest>, RequiresOf<A> | RequiresOf<B> | RequiresOfAll<Rest>>;
|
|
1875
|
+
/**
|
|
1876
|
+
* Subtracts `right` from `left`. Constant operands fold at construction.
|
|
1877
|
+
*
|
|
1878
|
+
* @param left - The minuend.
|
|
1879
|
+
* @param right - The subtrahend, sharing `left`'s dimension.
|
|
1880
|
+
* @returns The difference, with the operands' variables, results, and requirements unioned.
|
|
1881
|
+
* @since 0.1.0
|
|
1882
|
+
*/
|
|
1883
|
+
declare const subtract: <A extends In, B extends SameKindIn<A>>(left: A, right: B) => Calc<VarsOf<A> | VarsOf<B>, ResultOf<A> | ResultOf<B>, RequiresOf<A> | RequiresOf<B>>;
|
|
1884
|
+
/**
|
|
1885
|
+
* The CSS `mod()` of `dividend` and `divisor` — the remainder that takes the
|
|
1886
|
+
* sign of the divisor (the floored modulo), so `mod(x, 360)` lands in
|
|
1887
|
+
* `[0, 360)` for a positive divisor. Same-dimension operands, as `subtract`;
|
|
1888
|
+
* constant operands fold at construction.
|
|
1889
|
+
*
|
|
1890
|
+
* @param dividend - The value to reduce.
|
|
1891
|
+
* @param divisor - The modulus, sharing `dividend`'s dimension.
|
|
1892
|
+
* @returns The modulo, with the operands' variables, results, and requirements unioned.
|
|
1893
|
+
* @example
|
|
1894
|
+
* ```ts
|
|
1895
|
+
* Calc.serialize(Calc.mod(Calc.var('h'), 360)) // 'mod(var(--h), 360)'
|
|
1896
|
+
* ```
|
|
1897
|
+
* @since 0.2.0
|
|
1898
|
+
*/
|
|
1899
|
+
declare const mod: <A extends In, B extends SameKindIn<A>>(dividend: A, divisor: B) => Calc<VarsOf<A> | VarsOf<B>, ResultOf<A> | ResultOf<B>, RequiresOf<A> | RequiresOf<B>>;
|
|
1900
|
+
/**
|
|
1901
|
+
* Multiplies expressions. One factor must be a `<number>`; the dimensioned
|
|
1902
|
+
* factor's result rides through. Constant operands fold at construction.
|
|
1903
|
+
*
|
|
1904
|
+
* Addition and subtraction operands are parenthesized when serialized
|
|
1905
|
+
* under a product: `(a + b) * c`.
|
|
1906
|
+
*
|
|
1907
|
+
* @param left - The first factor.
|
|
1908
|
+
* @param right - The second factor.
|
|
1909
|
+
* @returns The product, carrying the dimensioned factor's result and both operands' variables and requirements.
|
|
1910
|
+
* @since 0.1.0
|
|
1911
|
+
*/
|
|
1912
|
+
declare const multiply: {
|
|
1913
|
+
<A extends NumberIn, B extends In>(left: A, right: B): Calc<VarsOf<A> | VarsOf<B>, ResultOf<B>, RequiresOf<A> | RequiresOf<B>>;
|
|
1914
|
+
<A extends In, B extends NumberIn>(left: A, right: B): Calc<VarsOf<A> | VarsOf<B>, ResultOf<A>, RequiresOf<A> | RequiresOf<B>>;
|
|
1915
|
+
};
|
|
1916
|
+
/**
|
|
1917
|
+
* Divides `left` by `right`. Constant operands fold at construction.
|
|
1918
|
+
*
|
|
1919
|
+
* Dividing by a `<number>` keeps the dividend's result; dividing two
|
|
1920
|
+
* same-dimension expressions produces a `<number>` (`Unit.None`) — the
|
|
1921
|
+
* units cancel. The requirements discharge only where folding guarantees
|
|
1922
|
+
* they can: a same-single-unit division always folds once bound, so its
|
|
1923
|
+
* requirement drops; anything mixed keeps both operands'.
|
|
1924
|
+
*
|
|
1925
|
+
* @param left - The dividend.
|
|
1926
|
+
* @param right - The divisor: a number, or an expression sharing `left`'s dimension.
|
|
1927
|
+
* @returns The quotient, with the operands' variables unioned.
|
|
1928
|
+
* @since 0.1.0
|
|
1929
|
+
*/
|
|
1930
|
+
declare const divide: {
|
|
1931
|
+
<A extends In, B extends NumberIn>(left: A, right: B): Calc<VarsOf<A> | VarsOf<B>, ResultOf<A>, DivRequires<A, B>>;
|
|
1932
|
+
<A extends In, B extends SameKindIn<A>>(left: A, right: B): Calc<VarsOf<A> | VarsOf<B>, None$1, DivRequires<A, B>>;
|
|
1933
|
+
};
|
|
1934
|
+
/**
|
|
1935
|
+
* Raises `base` to `exponent`. Serializes as the CSS `pow()` function,
|
|
1936
|
+
* whose operands are `<number>`s — so both take number-result expressions,
|
|
1937
|
+
* which may carry identifier requirements (`pow(l, 2.2)` gamma-adjusts a
|
|
1938
|
+
* relative-color channel).
|
|
1939
|
+
*
|
|
1940
|
+
* @param base - The base.
|
|
1941
|
+
* @param exponent - The exponent.
|
|
1942
|
+
* @returns The power, a `<number>`, with the operands' variables and requirements unioned.
|
|
1943
|
+
* @since 0.1.0
|
|
1944
|
+
*/
|
|
1945
|
+
declare const pow: <A extends NumberIn, B extends NumberIn>(base: A, exponent: B) => Calc<VarsOf<A> | VarsOf<B>, None$1, RequiresOf<A> | RequiresOf<B>>;
|
|
1946
|
+
/**
|
|
1947
|
+
* Sign-preserving power: `abs(base) ^ exponent * sign(base)`. Unlike
|
|
1948
|
+
* `pow`, well-defined for negative bases with fractional exponents.
|
|
1949
|
+
* Serializes as `pow(abs(base), exponent) * sign(base)`.
|
|
1950
|
+
*
|
|
1951
|
+
* @param base - The base.
|
|
1952
|
+
* @param exponent - The exponent.
|
|
1953
|
+
* @returns The signed power, a `<number>`, with the operands' variables and requirements unioned.
|
|
1954
|
+
* @since 0.1.0
|
|
1955
|
+
*/
|
|
1956
|
+
declare const signedPow: <A extends NumberIn, B extends NumberIn>(base: A, exponent: B) => Calc<VarsOf<A> | VarsOf<B>, None$1, RequiresOf<A> | RequiresOf<B>>;
|
|
1957
|
+
/**
|
|
1958
|
+
* The minimum of the operands. Serializes as the CSS `min()` function.
|
|
1959
|
+
*
|
|
1960
|
+
* @param a - The first operand.
|
|
1961
|
+
* @param b - The second operand, sharing `a`'s dimension.
|
|
1962
|
+
* @returns The minimum, with the operands' variables, results, and requirements unioned.
|
|
1963
|
+
* @since 0.1.0
|
|
1964
|
+
*/
|
|
1965
|
+
declare const min: <A extends In, B extends SameKindIn<A>, Rest extends ReadonlyArray<SameKindIn<A>>>(a: A, b: B, ...rest: Rest) => Calc<VarsOf<A> | VarsOf<B> | VarsOfAll<Rest>, ResultOf<A> | ResultOf<B> | ResultOfAll<Rest>, RequiresOf<A> | RequiresOf<B> | RequiresOfAll<Rest>>;
|
|
1966
|
+
/**
|
|
1967
|
+
* The maximum of the operands. Serializes as the CSS `max()` function.
|
|
1968
|
+
*
|
|
1969
|
+
* @param a - The first operand.
|
|
1970
|
+
* @param b - The second operand, sharing `a`'s dimension.
|
|
1971
|
+
* @returns The maximum, with the operands' variables, results, and requirements unioned.
|
|
1972
|
+
* @since 0.1.0
|
|
1973
|
+
*/
|
|
1974
|
+
declare const max: <A extends In, B extends SameKindIn<A>, Rest extends ReadonlyArray<SameKindIn<A>>>(a: A, b: B, ...rest: Rest) => Calc<VarsOf<A> | VarsOf<B> | VarsOfAll<Rest>, ResultOf<A> | ResultOf<B> | ResultOfAll<Rest>, RequiresOf<A> | RequiresOf<B> | RequiresOfAll<Rest>>;
|
|
1975
|
+
/**
|
|
1976
|
+
* Clamps `value` between `minimum` and `maximum`. Serializes as the CSS
|
|
1977
|
+
* `clamp()` function, with the CSS argument order `(min, value, max)`.
|
|
1978
|
+
*
|
|
1979
|
+
* @param minimum - The lower bound.
|
|
1980
|
+
* @param value - The value to clamp, sharing `minimum`'s dimension.
|
|
1981
|
+
* @param maximum - The upper bound, likewise.
|
|
1982
|
+
* @returns The clamped expression, with the operands' variables, results, and requirements unioned.
|
|
1983
|
+
* @example
|
|
1984
|
+
* ```ts
|
|
1985
|
+
* Calc.serialize(Calc.clamp(-1, Calc.var('u'), 1)) // 'clamp(-1, var(--u), 1)'
|
|
1986
|
+
* ```
|
|
1987
|
+
* @since 0.1.0
|
|
1988
|
+
*/
|
|
1989
|
+
declare const clamp: <A extends In, B extends SameKindIn<A>, C extends SameKindIn<A>>(minimum: A, value: B, maximum: C) => Calc<VarsOf<A> | VarsOf<B> | VarsOf<C>, ResultOf<A> | ResultOf<B> | ResultOf<C>, RequiresOf<A> | RequiresOf<B> | RequiresOf<C>>;
|
|
1990
|
+
/**
|
|
1991
|
+
* Linear interpolation from `a` to `b` by `t`. This is sugar, not a node:
|
|
1992
|
+
* it desugars to `(1 - t) * a + t * b`, and serializes as that expanded
|
|
1993
|
+
* form. `t` contributes its variables and requirements but never the
|
|
1994
|
+
* result — the endpoints alone fix the dimension.
|
|
1995
|
+
*
|
|
1996
|
+
* @param a - The value at `t = 0`.
|
|
1997
|
+
* @param b - The value at `t = 1`, sharing `a`'s dimension.
|
|
1998
|
+
* @param t - The interpolation parameter, a `<number>`.
|
|
1999
|
+
* @returns The interpolated expression, with the operands' variables unioned.
|
|
2000
|
+
* @since 0.1.0
|
|
2001
|
+
*/
|
|
2002
|
+
declare const lerp: {
|
|
2003
|
+
<A extends In, B extends SameKindIn<A>, T extends NumberIn>(a: A, b: B, t: T): Calc<VarsOf<A> | VarsOf<B> | VarsOf<T>, ResultOf<A> | ResultOf<B>, RequiresOf<A> | RequiresOf<B> | RequiresOf<T>>;
|
|
2004
|
+
};
|
|
2005
|
+
/**
|
|
2006
|
+
* The absolute value. Serializes as the CSS `abs()` function.
|
|
2007
|
+
*
|
|
2008
|
+
* @param argument - The operand.
|
|
2009
|
+
* @returns The absolute value expression, preserving the operand's result.
|
|
2010
|
+
* @since 0.1.0
|
|
2011
|
+
*/
|
|
2012
|
+
declare const abs: {
|
|
2013
|
+
<A extends In>(argument: A): Calc<VarsOf<A>, ResultOf<A>, RequiresOf<A>>;
|
|
2014
|
+
};
|
|
2015
|
+
/**
|
|
2016
|
+
* The sign (`-1`, `0`, or `1`). Serializes as the CSS `sign()` function,
|
|
2017
|
+
* which accepts a calculation of any dimension and returns a `<number>` —
|
|
2018
|
+
* so any operand is accepted here.
|
|
2019
|
+
*
|
|
2020
|
+
* @param argument - The operand, of any dimension.
|
|
2021
|
+
* @returns The sign, a `<number>`, carrying the operand's requirements.
|
|
2022
|
+
* @since 0.1.0
|
|
2023
|
+
*/
|
|
2024
|
+
declare const sign: {
|
|
2025
|
+
<A extends In>(argument: A): Calc<VarsOf<A>, None$1, RequiresOf<A>>;
|
|
2026
|
+
};
|
|
2027
|
+
/**
|
|
2028
|
+
* The sine of its argument. Serializes as the CSS `sin()` function, which
|
|
2029
|
+
* accepts an `<angle>` or a plain number treated as radians — so this takes
|
|
2030
|
+
* either an angle expression or a number, and returns a number.
|
|
2031
|
+
*
|
|
2032
|
+
* @param argument - An angle, or a plain number in radians.
|
|
2033
|
+
* @returns The sine, a `<number>`, carrying the argument's requirements.
|
|
2034
|
+
* @since 0.1.0
|
|
2035
|
+
*/
|
|
2036
|
+
declare const sin: {
|
|
2037
|
+
<A extends NumberOrAngleIn>(argument: A): Calc<VarsOf<A>, None$1, RequiresOf<A>>;
|
|
2038
|
+
};
|
|
2039
|
+
/**
|
|
2040
|
+
* The cosine of its argument. Serializes as the CSS `cos()` function, which
|
|
2041
|
+
* accepts an `<angle>` or a plain number treated as radians — so this takes
|
|
2042
|
+
* either an angle expression or a number, and returns a number.
|
|
2043
|
+
*
|
|
2044
|
+
* @param argument - An angle, or a plain number in radians.
|
|
2045
|
+
* @returns The cosine, a `<number>`, carrying the argument's requirements.
|
|
2046
|
+
* @since 0.1.0
|
|
2047
|
+
*/
|
|
2048
|
+
declare const cos: {
|
|
2049
|
+
<A extends NumberOrAngleIn>(argument: A): Calc<VarsOf<A>, None$1, RequiresOf<A>>;
|
|
2050
|
+
};
|
|
2051
|
+
/**
|
|
2052
|
+
* The tangent of its argument. Serializes as the CSS `tan()` function, which
|
|
2053
|
+
* accepts an `<angle>` or a plain number treated as radians. Paired with
|
|
2054
|
+
* `atan2`, `tan(atan2(a, b))` divides two same-dimension expressions to a
|
|
2055
|
+
* `<number>` — the length ratio that works where `a / b` does not, since
|
|
2056
|
+
* Firefox does not yet support `<length> / <length>` in `calc()`.
|
|
2057
|
+
*
|
|
2058
|
+
* @param argument - An angle, or a plain number in radians.
|
|
2059
|
+
* @returns The tangent, a `<number>`, carrying the argument's requirements.
|
|
2060
|
+
* @since 0.2.0
|
|
2061
|
+
*/
|
|
2062
|
+
declare const tan: {
|
|
2063
|
+
<A extends NumberOrAngleIn>(argument: A): Calc<VarsOf<A>, None$1, RequiresOf<A>>;
|
|
2064
|
+
};
|
|
2065
|
+
/**
|
|
2066
|
+
* The arccosine of a value in `[-1, 1]`, an `<angle>` in radians — the
|
|
2067
|
+
* result is `Unit.Rad`, matching what solving evaluates (`Math.acos`) and
|
|
2068
|
+
* what constant folding emits (`rad` constants); CSS's `acos()` returns an
|
|
2069
|
+
* `<angle>` and serialization is unchanged.
|
|
2070
|
+
*
|
|
2071
|
+
* Because the result is an angle, it composes only with other angles: divide
|
|
2072
|
+
* or scale it by a number, and add or subtract an `Angle.rad(...)` phase. A
|
|
2073
|
+
* plain number added to it is a type error — supply the phase as an angle.
|
|
2074
|
+
*
|
|
2075
|
+
* @param argument - The cosine value, in `[-1, 1]`.
|
|
2076
|
+
* @returns The arccosine in radians, carrying the argument's requirements.
|
|
2077
|
+
* @example
|
|
2078
|
+
* ```ts
|
|
2079
|
+
* const phase = Angle.rad(2.0943951)
|
|
2080
|
+
* Calc.serialize(Calc.cos(Calc.subtract(Calc.divide(Calc.acos(Calc.var('u')), 3), phase)))
|
|
2081
|
+
* // 'cos(acos(var(--u)) / 3 - 2.0944rad)'
|
|
2082
|
+
* ```
|
|
2083
|
+
* @since 0.1.0
|
|
2084
|
+
*/
|
|
2085
|
+
declare const acos: {
|
|
2086
|
+
<A extends NumberIn>(argument: A): Calc<VarsOf<A>, Rad, RequiresOf<A>>;
|
|
2087
|
+
};
|
|
2088
|
+
/**
|
|
2089
|
+
* The angle, in radians, of the vector from the origin to `(x, y)` — CSS's
|
|
2090
|
+
* `atan2()`, which returns an `<angle>`; the result is `Unit.Rad`, as
|
|
2091
|
+
* `acos`. The operands must share a dimension (two numbers, two lengths,
|
|
2092
|
+
* two angles); their units cancel in the ratio, so `tan(atan2(a, b))`
|
|
2093
|
+
* recovers `a / b` as a `<number>` and is the portable way to divide two
|
|
2094
|
+
* `<length>`s.
|
|
2095
|
+
*
|
|
2096
|
+
* @param y - The vertical component.
|
|
2097
|
+
* @param x - The horizontal component, sharing `y`'s dimension.
|
|
2098
|
+
* @returns The angle in radians, with the operands' variables and requirements unioned.
|
|
2099
|
+
* @example
|
|
2100
|
+
* ```ts
|
|
2101
|
+
* const ratio = Calc.tan(Calc.atan2(Calc.subtract(Length.vw(100), Length.px(320)), Length.px(160)))
|
|
2102
|
+
* Calc.serialize(ratio) // 'tan(atan2(100vw - 320px, 160px))'
|
|
2103
|
+
* ```
|
|
2104
|
+
* @since 0.2.0
|
|
2105
|
+
*/
|
|
2106
|
+
declare const atan2: {
|
|
2107
|
+
<A extends In, B extends SameKindIn<A>>(y: A, x: B): Calc<VarsOf<A> | VarsOf<B>, Rad, RequiresOf<A> | RequiresOf<B>>;
|
|
2108
|
+
};
|
|
2109
|
+
declare const bind: {
|
|
2110
|
+
/**
|
|
2111
|
+
* Returns a function that binds the given names in an expression.
|
|
2112
|
+
*
|
|
2113
|
+
* The data-last form cannot see its eventual expression, so the
|
|
2114
|
+
* per-name declared-type checking rides the data-first overload only;
|
|
2115
|
+
* requirement threading works in both.
|
|
2116
|
+
*
|
|
2117
|
+
* @param bindings - Variable names to values or expressions. Names the expression does not read are ignored, as are `undefined` values.
|
|
2118
|
+
* @returns A function replacing bound variables in its argument, preserving its result and joining the bound values' requirements to its own.
|
|
2119
|
+
* @since 0.1.0
|
|
2120
|
+
*/
|
|
2121
|
+
<const B extends Bindings>(bindings: B): <A extends Top>(expr: A) => Calc<ApplyBindings<VarsOf<A>, B>, ResultOf<A>, RequiresOf<A> | BindingRequires<VarsOf<A>, B>>;
|
|
2122
|
+
/**
|
|
2123
|
+
* Replaces variables with values or other expressions. Binding is
|
|
2124
|
+
* partial evaluation: substituted subtrees re-fold, so binding every
|
|
2125
|
+
* variable collapses the tree to a constant. The expression's result is
|
|
2126
|
+
* preserved — binding touches only the variable channel — and the bound
|
|
2127
|
+
* values' own requirements join the expression's, so a `Length.vw(2)`
|
|
2128
|
+
* binding carries its `vw` ratio demand into the result for `solve` to
|
|
2129
|
+
* collect later.
|
|
2130
|
+
*
|
|
2131
|
+
* A declared name types its value: binding a `Var.length` read to a
|
|
2132
|
+
* bare number (or any non-length) is a type error, the check the
|
|
2133
|
+
* declaration exists for. Undeclared names accept any `Input`.
|
|
2134
|
+
*
|
|
2135
|
+
* Names the expression does not read are ignored (spreading a wider
|
|
2136
|
+
* bindings object is fine), as are `undefined` values. Binding a
|
|
2137
|
+
* variable to another expression composes trees; the bound expression's
|
|
2138
|
+
* own variables join the result, tracked in the return type by
|
|
2139
|
+
* `ApplyBindings`.
|
|
2140
|
+
*
|
|
2141
|
+
* @param expr - The expression to bind.
|
|
2142
|
+
* @param bindings - Variable names to values or expressions, typed per name by its declared type. May be partial: unbound names stay in the result.
|
|
2143
|
+
* @returns The bound expression.
|
|
2144
|
+
* @example
|
|
2145
|
+
* ```ts
|
|
2146
|
+
* const half = Calc.bind(Calc.divide(Calc.var('x'), 2), { x: Calc.var('width') })
|
|
2147
|
+
* Calc.serialize(half) // 'calc(var(--width) / 2)'
|
|
2148
|
+
* Calc.solve(Calc.bind(half, { width: 100 })) // 50
|
|
2149
|
+
* ```
|
|
2150
|
+
* @since 0.1.0
|
|
2151
|
+
*/
|
|
2152
|
+
<A extends Top, const B extends PartialBindings<VarsOf<A>>>(expr: A, bindings: B): Calc<ApplyBindings<VarsOf<A>, B>, ResultOf<A>, RequiresOf<A> | BindingRequires<VarsOf<A>, B>>;
|
|
2153
|
+
};
|
|
2154
|
+
declare const solve: {
|
|
2155
|
+
/**
|
|
2156
|
+
* Evaluates a closed expression to a number. Absolute lengths (`px`) and
|
|
2157
|
+
* angles (radians and degrees) lower with no options; an unbound
|
|
2158
|
+
* variable, a relative unit, a percentage, or a bare identifier needs the
|
|
2159
|
+
* options overload.
|
|
2160
|
+
*
|
|
2161
|
+
* @param expr - The expression. No unbound variables, only pre-satisfied requirements.
|
|
2162
|
+
* @returns The numeric value.
|
|
2163
|
+
* @throws `Error` when unbound variables or unresolvable requirements remain at runtime.
|
|
2164
|
+
* @since 0.1.0
|
|
2165
|
+
*/
|
|
2166
|
+
(expr: Calc<never, Any$1, ContextFree>): number;
|
|
2167
|
+
/**
|
|
2168
|
+
* Applies bindings, lowers each unit and identifier through the matching
|
|
2169
|
+
* options section, then evaluates to a number. `SolveOptions` requires
|
|
2170
|
+
* each section exactly when the expression's type demands it: `bindings`
|
|
2171
|
+
* while variables are unbound, `units` while a relative unit or
|
|
2172
|
+
* percentage is present, `idents` while a bare identifier is.
|
|
2173
|
+
*
|
|
2174
|
+
* @param expr - The expression to evaluate.
|
|
2175
|
+
* @param options - The bindings, unit ratios, and identifier values the expression needs.
|
|
2176
|
+
* @returns The numeric value.
|
|
2177
|
+
* @throws `Error` when unbound variables remain after binding, or a unit or identifier has no entry at runtime.
|
|
2178
|
+
* @example
|
|
2179
|
+
* ```ts
|
|
2180
|
+
* Calc.solve(Calc.lerp(Calc.var('a'), Calc.var('b'), 0.5), { bindings: { a: 0, b: 10 } }) // 5
|
|
2181
|
+
* const position = Calc.divide(Calc.subtract(Length.vw(100), Length.px(320)), Length.px(160))
|
|
2182
|
+
* Calc.solve(position, { units: { vw: 1280 / 100 } }) // 6
|
|
2183
|
+
* Calc.solve(Calc.multiply(Channel.L, 0.8), { idents: { l: 0.62 } }) // 0.496
|
|
2184
|
+
* ```
|
|
2185
|
+
* @since 0.1.0
|
|
2186
|
+
*/
|
|
2187
|
+
<Vars extends Any, R>(expr: Calc<Vars, Any$1, R>, options: SolveOptions<Vars, R>): number;
|
|
2188
|
+
};
|
|
2189
|
+
/**
|
|
2190
|
+
* Renders an expression as CSS text. Arithmetic gets a `calc()` wrapper;
|
|
2191
|
+
* function forms (`min`, `clamp`, `sin`, ...) and leaves stand alone.
|
|
2192
|
+
* Variables render as `var(--name)`.
|
|
2193
|
+
*
|
|
2194
|
+
* Bindings in `options` are applied first and may be partial — this is
|
|
2195
|
+
* the serialize half of the solve/serialize duality, and unbound
|
|
2196
|
+
* variables are the values left for the browser. Constants render with
|
|
2197
|
+
* their annotated precision, or the context `precision` option (default
|
|
2198
|
+
* `Precision.decimals(5)`). Constants equal to pi render as the CSS
|
|
2199
|
+
* constant `pi` where a math function surrounds them.
|
|
2200
|
+
*
|
|
2201
|
+
* @param expr - The expression to render.
|
|
2202
|
+
* @param options - Optional bindings and precision context.
|
|
2203
|
+
* @returns Deterministic CSS text.
|
|
2204
|
+
* @example
|
|
2205
|
+
* ```ts
|
|
2206
|
+
* const fluid = Calc.add(10, Calc.var('runtime'))
|
|
2207
|
+
* Calc.serialize(fluid) // 'calc(10 + var(--runtime))'
|
|
2208
|
+
* Calc.serialize(fluid, { bindings: { runtime: 4 } }) // '14'
|
|
2209
|
+
* ```
|
|
2210
|
+
* @since 0.1.0
|
|
2211
|
+
*/
|
|
2212
|
+
declare const serialize: <Vars extends Any>(expr: Calc<Vars, Any$1, unknown>, options?: SerializeOptions<Vars>) => string;
|
|
2213
|
+
/**
|
|
2214
|
+
* The expression's unbound variable names — bare names, the value-level
|
|
2215
|
+
* mirror of the read identities in `Vars`. A fallback chain's names are
|
|
2216
|
+
* included: `var(--x, var(--y))` reads both.
|
|
2217
|
+
*
|
|
2218
|
+
* @param expr - The expression to inspect.
|
|
2219
|
+
* @returns The set of unbound variable names.
|
|
2220
|
+
* @since 0.1.0
|
|
2221
|
+
*/
|
|
2222
|
+
declare const vars: <Vars extends Any>(expr: Calc<Vars, Any$1, unknown>) => ReadonlySet<Name<Vars>>;
|
|
2223
|
+
/**
|
|
2224
|
+
* The bare-identifier tokens the expression reads — leaves that serialize
|
|
2225
|
+
* as themselves (`l`, not `var(--l)`) and are resolved by the CSS construct
|
|
2226
|
+
* around them, the `Channel` keywords being the only source today. Empty
|
|
2227
|
+
* for an expression with none.
|
|
2228
|
+
*
|
|
2229
|
+
* The runtime mirror of the `Ident` brands in `Requires`: it reports which
|
|
2230
|
+
* values the `idents` section of `solve`'s options must supply, exactly as
|
|
2231
|
+
* `vars` reports what `bindings` must — and, unlike the type parameter, it
|
|
2232
|
+
* survives on a `Calc<Vars, Unit.Any, unknown>` whose requirements have
|
|
2233
|
+
* been erased. Identifiers are not variables, so `vars` never lists them
|
|
2234
|
+
* and they never reach a `Stylesheet`'s dependency report.
|
|
2235
|
+
*
|
|
2236
|
+
* @param expr - The expression to inspect.
|
|
2237
|
+
* @returns The set of bare-identifier tokens the expression reads.
|
|
2238
|
+
* @example
|
|
2239
|
+
* ```ts
|
|
2240
|
+
* Calc.idents(Calc.multiply(Channel.L, 0.8)) // Set { 'l' }
|
|
2241
|
+
* Calc.idents(Calc.var('x')) // Set {}
|
|
2242
|
+
* ```
|
|
2243
|
+
* @since 0.2.0
|
|
2244
|
+
*/
|
|
2245
|
+
declare const idents: (expr: Calc<Any, Any$1, unknown>) => ReadonlySet<string>;
|
|
2246
|
+
/**
|
|
2247
|
+
* The unit tokens the expression's dimensioned constants carry (`'vw'`,
|
|
2248
|
+
* `'px'`, `'%'`). Empty for a unit-free expression.
|
|
2249
|
+
*
|
|
2250
|
+
* The runtime mirror of the `Unit` brands in `Requires`: it reports which
|
|
2251
|
+
* ratios the `units` section of `solve`'s options may need to supply, and —
|
|
2252
|
+
* unlike the type parameter — it survives on a `Calc<Vars, Unit.Any, unknown>`
|
|
2253
|
+
* whose requirements have been erased. Pre-satisfied units (`px`, `rad`,
|
|
2254
|
+
* `deg`) are reported too; they lower with no entry.
|
|
2255
|
+
*
|
|
2256
|
+
* @param expr - The expression to inspect.
|
|
2257
|
+
* @returns The set of unit tokens the expression's constants carry.
|
|
2258
|
+
* @example
|
|
2259
|
+
* ```ts
|
|
2260
|
+
* Calc.units(Calc.subtract(Length.vw(100), Length.px(320))) // Set { 'vw', 'px' }
|
|
2261
|
+
* ```
|
|
2262
|
+
* @since 0.4.0
|
|
2263
|
+
*/
|
|
2264
|
+
declare const units: (expr: Calc<Any, Any$1, unknown>) => ReadonlySet<string>;
|
|
2265
|
+
declare const equals: {
|
|
2266
|
+
/**
|
|
2267
|
+
* Returns a function that checks structural equality against `that`.
|
|
2268
|
+
*
|
|
2269
|
+
* @param that - The expression to compare against.
|
|
2270
|
+
* @returns A function testing its argument for structural equality with `that`.
|
|
2271
|
+
* @since 0.1.0
|
|
2272
|
+
*/
|
|
2273
|
+
(that: Calc<Any, Any$1, unknown>): (self: Calc<Any, Any$1, unknown>) => boolean;
|
|
2274
|
+
/**
|
|
2275
|
+
* Structural equality over expression trees. Two expressions are equal
|
|
2276
|
+
* when their trees match node for node — including constant units and
|
|
2277
|
+
* precision annotations, which affect serialization. Expression trees are
|
|
2278
|
+
* ordered syntax: `add(a, b)` and `add(b, a)` are not equal.
|
|
2279
|
+
*
|
|
2280
|
+
* @param self - The first expression.
|
|
2281
|
+
* @param that - The second expression.
|
|
2282
|
+
* @returns `true` if the expressions are structurally equal.
|
|
2283
|
+
* @since 0.1.0
|
|
2284
|
+
*/
|
|
2285
|
+
(self: Calc<Any, Any$1, unknown>, that: Calc<Any, Any$1, unknown>): boolean;
|
|
2286
|
+
};
|
|
2287
|
+
//#endregion
|
|
2288
|
+
export { precision_d_exports as A, Any$1 as C, Percentage$1 as D, None$1 as E, unit_d_exports as O, Angle$1 as S, Length$1 as T, keywords_d_exports as _, calc_d_exports as a, channels_d_exports as b, Name as c, percentage_d_exports as d, numeric_d_exports as f, color_d_exports as g, Color as h, PartialBindings as i, Precision as k, Var as l, length_d_exports as m, Bindings as n, angle_d_exports as o, lengthPercentage_d_exports as p, Calc as r, Any as s, ApplyBindings as t, var_d_exports as u, hueInterpolation_d_exports as v, Family as w, AbsoluteLength as x, colorSpace_d_exports as y };
|
|
2289
|
+
//# sourceMappingURL=index-D-hVWDgZ.d.mts.map
|