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,264 @@
|
|
|
1
|
+
import { t as Pipeable } from "./utils-DpN6qr94.mjs";
|
|
2
|
+
import { C as Any$1, E as None, c as Name, h as Color, i as PartialBindings, k as Precision, l as Var, n as Bindings, r as Calc, s as Any, t as ApplyBindings, w as Family } from "./index-D-hVWDgZ.mjs";
|
|
3
|
+
import { n as RenderOptions$1 } from "./mediaQuery-VDIAHnM1.mjs";
|
|
4
|
+
//#region src/declaration/declaration.internal.d.ts
|
|
5
|
+
declare const DeclarationTypeId: unique symbol;
|
|
6
|
+
type DeclarationTypeId = typeof DeclarationTypeId;
|
|
7
|
+
declare namespace declaration_d_exports {
|
|
8
|
+
export { Declaration, Read, RenderOptions, Value, ValueFallback, bind, equals, isDeclaration, make, render, vars };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A CSS declaration: a property name paired with a value.
|
|
12
|
+
*
|
|
13
|
+
* This is the seam where the library's two halves meet — the value is
|
|
14
|
+
* either literal CSS text, passed through verbatim, or a value-layer
|
|
15
|
+
* expression (`Calc` or `Color`) serialized when the declaration renders.
|
|
16
|
+
* A `Calc` of any dimension is accepted: a `<number>`, or a `<length>` /
|
|
17
|
+
* `<angle>` built from `fashionable/data`, which carries its own units.
|
|
18
|
+
*
|
|
19
|
+
* The `Vars` parameter carries the value's unbound reads, as on `Calc`;
|
|
20
|
+
* literal text binds nothing and a text-valued declaration is a
|
|
21
|
+
* `Declaration<never>`. A whole-value custom-property read is spelled as a
|
|
22
|
+
* `Var` value, not literal text, so it joins the report:
|
|
23
|
+
* `make('font-family', Var.of('stack'))` is a `Declaration<Var<'stack'>>`.
|
|
24
|
+
*
|
|
25
|
+
* Construct via `make`.
|
|
26
|
+
*
|
|
27
|
+
* @since 0.1.0
|
|
28
|
+
*/
|
|
29
|
+
interface Declaration<out Vars extends Any = Any> extends Pipeable {
|
|
30
|
+
readonly [DeclarationTypeId]: DeclarationTypeId;
|
|
31
|
+
/**
|
|
32
|
+
* The property name, exactly as it renders — `font-size`, or `--depth`
|
|
33
|
+
* for a custom property.
|
|
34
|
+
*/
|
|
35
|
+
readonly name: string;
|
|
36
|
+
/**
|
|
37
|
+
* The declaration's value: literal CSS text or a value-layer expression.
|
|
38
|
+
*/
|
|
39
|
+
readonly value: Value<Vars>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The fallbacks a declaration-level read admits: any declaration value —
|
|
43
|
+
* literal text, a number, an expression of either world, or another read,
|
|
44
|
+
* recursively. This is the widest projection of the generic fallback slot
|
|
45
|
+
* on `Var`: at the declaration level a fallback is an arbitrary token
|
|
46
|
+
* sequence, so every value form qualifies.
|
|
47
|
+
*
|
|
48
|
+
* @since 0.4.0
|
|
49
|
+
*/
|
|
50
|
+
type ValueFallback = string | number | Calc<Any, Any$1, unknown> | Color<Any> | Var<string, unknown, ValueFallback | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* A custom-property read usable as a whole declaration value: bare, or
|
|
53
|
+
* carrying any declaration value as its fallback.
|
|
54
|
+
*
|
|
55
|
+
* @since 0.4.0
|
|
56
|
+
*/
|
|
57
|
+
type Read = Var<string, unknown, ValueFallback | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* The value forms a declaration can hold: literal CSS text, a `Calc`
|
|
60
|
+
* expression of any dimension, a `Color` expression, or a whole-value
|
|
61
|
+
* custom-property read (`font-family: var(--stack, sans-serif)`), whose
|
|
62
|
+
* fallback may be any declaration value.
|
|
63
|
+
*
|
|
64
|
+
* @since 0.1.0
|
|
65
|
+
*/
|
|
66
|
+
type Value<Vars extends Any = Any> = string | Calc<Vars, Any$1, unknown> | Color<Vars> | Var<Name<Vars>, unknown, ValueFallback | undefined>;
|
|
67
|
+
type ReadVars<V> = V extends Var<infer N, infer T, infer F> ? Var<N, T> | ReadFallbackVars<F> : never;
|
|
68
|
+
type ReadFallbackVars<F> = F extends Calc<infer W, Any$1, unknown> ? W : F extends Color<infer W> ? W : F extends Any ? ReadVars<F> : never;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a value is a `Declaration`.
|
|
71
|
+
*
|
|
72
|
+
* True only for values built by this module's constructors, which carry
|
|
73
|
+
* the brand.
|
|
74
|
+
*
|
|
75
|
+
* @param u - The value to check.
|
|
76
|
+
* @returns `true` if the value is a `Declaration`, `false` otherwise.
|
|
77
|
+
* @since 0.1.0
|
|
78
|
+
*/
|
|
79
|
+
declare const isDeclaration: (u: unknown) => u is Declaration<Any>;
|
|
80
|
+
/**
|
|
81
|
+
* A handle usable in name position: a bare (fallback-free) read, written
|
|
82
|
+
* as its property (`make(gap, ...)` renders `--gap: ...`). A fallback
|
|
83
|
+
* belongs to a read site, so a fallback-carrying read is rejected
|
|
84
|
+
* structurally here.
|
|
85
|
+
*
|
|
86
|
+
* @since 0.4.0
|
|
87
|
+
*/
|
|
88
|
+
type Handle<T = unknown> = Var<string, T, undefined>;
|
|
89
|
+
type DeclaredWrite<T, V2 extends Any> = T extends Color<Any> ? Color<V2> | string : T extends Calc<Any, infer R, unknown> ? Calc<V2, Family<R>, unknown> | ([Family<R>] extends [None] ? number : never) | string : never;
|
|
90
|
+
type UndeclaredGuard<H> = H extends Var<string, infer T, undefined> ? [unknown] extends [T] ? unknown : "a declared handle types its write: pass a value of the handle's declared type" : never;
|
|
91
|
+
declare const make: {
|
|
92
|
+
/**
|
|
93
|
+
* Creates a declaration whose value is a whole custom-property read —
|
|
94
|
+
* the honest spelling of `font-family: var(--stack, sans-serif)`, which
|
|
95
|
+
* as literal text would drop the read from the dependency report. The
|
|
96
|
+
* declaration's `Vars` unions the read's identity with its fallback
|
|
97
|
+
* chain's, flattened.
|
|
98
|
+
*
|
|
99
|
+
* @param name - The property name, exactly as it renders. Must be non-empty.
|
|
100
|
+
* @param value - The read, from `Var.of` (optionally through `Var.fallback`).
|
|
101
|
+
* @returns A `Declaration` carrying the read's names.
|
|
102
|
+
* @throws `Error` when `name` is empty, or the read's fallback chain holds a value no declaration can (anything but text, numbers, expressions, and reads).
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* Declaration.make('font-family', Var.of('stack').pipe(Var.fallback('sans-serif')))
|
|
106
|
+
* // renders 'font-family: var(--stack, sans-serif);'
|
|
107
|
+
* ```
|
|
108
|
+
* @since 0.4.0
|
|
109
|
+
*/
|
|
110
|
+
<V extends Read>(name: string, value: V): Declaration<ReadVars<V>>;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a declaration.
|
|
113
|
+
*
|
|
114
|
+
* Literal text is stored verbatim — no parsing, no escaping. A bare
|
|
115
|
+
* number is coerced to an unannotated constant expression, as anywhere
|
|
116
|
+
* else an expression is accepted, so it serializes under the precision
|
|
117
|
+
* context rather than as raw text.
|
|
118
|
+
*
|
|
119
|
+
* @param name - The property name, exactly as it renders (`--x` keeps its dashes). Must be non-empty.
|
|
120
|
+
* @param value - Literal CSS text, a number, or a `Calc`/`Color` expression.
|
|
121
|
+
* @returns A `Declaration` carrying the value's variable names — `Declaration<never>` for text and numbers.
|
|
122
|
+
* @throws `Error` when `name` is empty, or `value` is a non-finite number.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* Declaration.make('color', 'red')
|
|
126
|
+
* Declaration.make('--fluid', Calc.add(14, Calc.multiply(Calc.var('vw'), 0.01)))
|
|
127
|
+
* ```
|
|
128
|
+
* @since 0.1.0
|
|
129
|
+
*/
|
|
130
|
+
<Vars extends Any = never>(name: string, value: Value<Vars> | number): Declaration<Vars>;
|
|
131
|
+
/**
|
|
132
|
+
* Writes a property through its handle with a read as the whole value —
|
|
133
|
+
* the alias pattern, `--gap: var(--spacing)`. The read's names join the
|
|
134
|
+
* report; the written property contributes none (writing is not
|
|
135
|
+
* reading).
|
|
136
|
+
*
|
|
137
|
+
* @param handle - The property's canonical handle. Must be fallback-free.
|
|
138
|
+
* @param value - The read to write, from `Var.of` or a typed constructor (optionally through `Var.fallback`).
|
|
139
|
+
* @returns A `Declaration` carrying the read's names.
|
|
140
|
+
* @throws `Error` when the handle carries a fallback, or the value's fallback chain holds a form no declaration can.
|
|
141
|
+
* @since 0.4.0
|
|
142
|
+
*/
|
|
143
|
+
<V extends Read>(handle: Handle, value: V): Declaration<ReadVars<V>>;
|
|
144
|
+
/**
|
|
145
|
+
* Writes a declared property through its handle, the value typed by the
|
|
146
|
+
* declared type: a `Var.length` handle takes length-family expressions
|
|
147
|
+
* (or literal text), a `Var.color` handle takes colors — so a write
|
|
148
|
+
* that contradicts the registration is a type error at the declaration.
|
|
149
|
+
* The name renders with its `--` prefix.
|
|
150
|
+
*
|
|
151
|
+
* @param handle - The property's canonical handle, from a typed `Var` constructor. Must be fallback-free.
|
|
152
|
+
* @param value - The value to write, typed by the handle's declared type; its own reads become the declaration's `Vars`.
|
|
153
|
+
* @returns A `Declaration` carrying the value's names.
|
|
154
|
+
* @throws `Error` when the handle carries a fallback.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const gap = Var.length('gap')
|
|
158
|
+
* Declaration.render(Declaration.make(gap, Length.px(8))) // '--gap: 8px;'
|
|
159
|
+
* ```
|
|
160
|
+
* @since 0.4.0
|
|
161
|
+
*/
|
|
162
|
+
<T extends Calc<Any, Any$1, unknown> | Color<Any>, V2 extends Any = never>(handle: Handle<T>, value: DeclaredWrite<T, V2>): Declaration<V2>;
|
|
163
|
+
/**
|
|
164
|
+
* Writes a property through its undeclared handle: any declaration
|
|
165
|
+
* value, exactly as the string-name form. The name renders with its
|
|
166
|
+
* `--` prefix.
|
|
167
|
+
*
|
|
168
|
+
* @param handle - The property's canonical handle, from `Var.of`. Must be fallback-free.
|
|
169
|
+
* @param value - Literal CSS text, a number, or a `Calc`/`Color` expression.
|
|
170
|
+
* @returns A `Declaration` carrying the value's names.
|
|
171
|
+
* @throws `Error` when the handle carries a fallback.
|
|
172
|
+
* @since 0.4.0
|
|
173
|
+
*/
|
|
174
|
+
<H extends Handle, V2 extends Any = never>(handle: H & UndeclaredGuard<H>, value: Value<V2> | number): Declaration<V2>;
|
|
175
|
+
};
|
|
176
|
+
declare const bind: {
|
|
177
|
+
/**
|
|
178
|
+
* Returns a function that binds the given names in a declaration's
|
|
179
|
+
* value.
|
|
180
|
+
*
|
|
181
|
+
* @param bindings - Variable names to values or expressions.
|
|
182
|
+
* @returns A function replacing bound variables in its argument's value.
|
|
183
|
+
* @since 0.1.0
|
|
184
|
+
*/
|
|
185
|
+
<const B extends Bindings>(bindings: B): <Vars extends Any>(declaration: Declaration<Vars>) => Declaration<ApplyBindings<Vars, B>>;
|
|
186
|
+
/**
|
|
187
|
+
* Replaces variables in the declaration's value with values or other
|
|
188
|
+
* expressions, re-folding constant subtrees. Semantics match
|
|
189
|
+
* `Calc.bind`: unread names and `undefined` values are ignored, and
|
|
190
|
+
* expression-valued bindings contribute their own variables. A
|
|
191
|
+
* literal-text value binds nothing; the declaration is returned as-is.
|
|
192
|
+
*
|
|
193
|
+
* @param declaration - The declaration to bind.
|
|
194
|
+
* @param bindings - Variable names to values or expressions.
|
|
195
|
+
* @returns The bound declaration.
|
|
196
|
+
* @since 0.1.0
|
|
197
|
+
*/
|
|
198
|
+
<Vars extends Any, const B extends PartialBindings<Vars>>(declaration: Declaration<Vars>, bindings: B): Declaration<ApplyBindings<Vars, B>>;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* The declaration's unbound variable names — empty for literal text,
|
|
202
|
+
* the value's variables otherwise.
|
|
203
|
+
*
|
|
204
|
+
* @param declaration - The declaration to inspect.
|
|
205
|
+
* @returns The set of unbound variable names.
|
|
206
|
+
* @since 0.1.0
|
|
207
|
+
*/
|
|
208
|
+
declare const vars: <Vars extends Any>(declaration: Declaration<Vars>) => ReadonlySet<Name<Vars>>;
|
|
209
|
+
/**
|
|
210
|
+
* Options for `render`, extending `MediaQuery.RenderOptions` — the
|
|
211
|
+
* render-options family's base — with the precision context.
|
|
212
|
+
*
|
|
213
|
+
* @since 0.1.0
|
|
214
|
+
*/
|
|
215
|
+
interface RenderOptions extends RenderOptions$1 {
|
|
216
|
+
/**
|
|
217
|
+
* The precision for expression constants that carry no annotation of
|
|
218
|
+
* their own. Defaults to `Precision.decimals(5)`, as in
|
|
219
|
+
* `Calc.serialize`.
|
|
220
|
+
*/
|
|
221
|
+
readonly precision?: Precision;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Renders the declaration as one CSS declaration, semicolon included:
|
|
225
|
+
* `name: value;`. Literal text passes through verbatim; expression
|
|
226
|
+
* values serialize as `Calc.serialize`/`Color.serialize` would, with
|
|
227
|
+
* unbound variables rendering as `var(--name)`.
|
|
228
|
+
*
|
|
229
|
+
* @param declaration - The declaration to render.
|
|
230
|
+
* @param options - Optional precision context for expression values.
|
|
231
|
+
* @returns Deterministic CSS text.
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* Declaration.render(Declaration.make('--indent', Calc.multiply(Calc.var('depth'), 8)))
|
|
235
|
+
* // '--indent: calc(var(--depth) * 8);'
|
|
236
|
+
* ```
|
|
237
|
+
* @since 0.1.0
|
|
238
|
+
*/
|
|
239
|
+
declare const render: (declaration: Declaration<Any>, options?: RenderOptions) => string;
|
|
240
|
+
declare const equals: {
|
|
241
|
+
/**
|
|
242
|
+
* Returns a function that checks structural equality against `that`.
|
|
243
|
+
*
|
|
244
|
+
* @param that - The declaration to compare against.
|
|
245
|
+
* @returns A function testing its argument for structural equality with `that`.
|
|
246
|
+
* @since 0.1.0
|
|
247
|
+
*/
|
|
248
|
+
(that: Declaration<Any>): (self: Declaration<Any>) => boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Structural equality: names compare as text, expression values as
|
|
251
|
+
* expression trees (`Calc.equals` semantics, precision annotations
|
|
252
|
+
* included). Literal text never equals an expression, even one that
|
|
253
|
+
* would serialize to the same characters.
|
|
254
|
+
*
|
|
255
|
+
* @param self - The first declaration.
|
|
256
|
+
* @param that - The second declaration.
|
|
257
|
+
* @returns `true` if the declarations are structurally equal.
|
|
258
|
+
* @since 0.1.0
|
|
259
|
+
*/
|
|
260
|
+
(self: Declaration<Any>, that: Declaration<Any>): boolean;
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
|
+
export { RenderOptions as n, declaration_d_exports as r, Declaration as t };
|
|
264
|
+
//# sourceMappingURL=declaration-CqRm38oZ.d.mts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Pipeable, dual, invariant } from "../utils.mjs";
|
|
2
|
+
import { a as hash, i as equals$1, n as HashTypeId, r as combine, s as hashString, t as EqualTypeId } from "./equal-U9G5LhtL.mjs";
|
|
3
|
+
import { a as fallback, g as EMPTY_REFS, o as fallbackOf, s as isVar, u as nameOf, v as refsOf$1 } from "./var.internal-DSxAzEFN.mjs";
|
|
4
|
+
import { S as toCalc, c as bind$1, p as isCalc, y as serialize } from "./calc-Uwbxd7CS.mjs";
|
|
5
|
+
import { a as isColor, p as serialize$1, t as bind$2 } from "./color.internal-CxjlaRqR.mjs";
|
|
6
|
+
//#region src/declaration/declaration.internal.ts
|
|
7
|
+
const DeclarationTypeId = Symbol.for("fashionable/declaration");
|
|
8
|
+
const valueEquals = (a, b) => typeof a === "string" || typeof b === "string" ? a === b : equals$1(a, b);
|
|
9
|
+
const valueHash = (value) => typeof value === "string" ? hashString(value) : hash(value);
|
|
10
|
+
const serializeFallback = (fb, precision) => {
|
|
11
|
+
if (typeof fb === "string") return fb;
|
|
12
|
+
const options = precision === void 0 ? {} : { precision };
|
|
13
|
+
if (typeof fb === "number" || isCalc(fb)) return serialize(toCalc(fb), options);
|
|
14
|
+
if (isVar(fb)) return serializeRead(fb, precision);
|
|
15
|
+
return serialize$1(fb, options);
|
|
16
|
+
};
|
|
17
|
+
const serializeRead = (read, precision) => {
|
|
18
|
+
const fb = fallbackOf(read);
|
|
19
|
+
return fb === void 0 ? `var(--${nameOf(read)})` : `var(--${nameOf(read)}, ${serializeFallback(fb, precision)})`;
|
|
20
|
+
};
|
|
21
|
+
const serializeValue = (value, precision) => {
|
|
22
|
+
if (typeof value === "string") return value;
|
|
23
|
+
if (isVar(value)) return serializeRead(value, precision);
|
|
24
|
+
const options = precision === void 0 ? {} : { precision };
|
|
25
|
+
return isCalc(value) ? serialize(value, options) : serialize$1(value, options);
|
|
26
|
+
};
|
|
27
|
+
var DeclarationImpl = class extends Pipeable {
|
|
28
|
+
[DeclarationTypeId] = DeclarationTypeId;
|
|
29
|
+
name;
|
|
30
|
+
value;
|
|
31
|
+
refSet;
|
|
32
|
+
#hash;
|
|
33
|
+
constructor(name, value) {
|
|
34
|
+
super();
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.value = value;
|
|
37
|
+
this.refSet = typeof value === "string" ? EMPTY_REFS : refsOf$1(value);
|
|
38
|
+
}
|
|
39
|
+
[EqualTypeId](that) {
|
|
40
|
+
return isDeclaration(that) && this.name === that.name && valueEquals(this.value, that.value);
|
|
41
|
+
}
|
|
42
|
+
[HashTypeId]() {
|
|
43
|
+
if (this.#hash === void 0) {
|
|
44
|
+
let h = hashString("fashionable/declaration");
|
|
45
|
+
h = combine(h, hashString(this.name));
|
|
46
|
+
h = combine(h, valueHash(this.value));
|
|
47
|
+
this.#hash = h;
|
|
48
|
+
}
|
|
49
|
+
return this.#hash;
|
|
50
|
+
}
|
|
51
|
+
get [Symbol.toStringTag]() {
|
|
52
|
+
return `Declaration(${this.name}: ${serializeValue(this.value)})`;
|
|
53
|
+
}
|
|
54
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
55
|
+
return this[Symbol.toStringTag];
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/** @internal */
|
|
59
|
+
const isDeclaration = (u) => typeof u === "object" && u !== null && DeclarationTypeId in u;
|
|
60
|
+
/** @internal */
|
|
61
|
+
const refsOf = (declaration) => declaration.refSet;
|
|
62
|
+
const validateReadFallback = (fb) => {
|
|
63
|
+
if (fb === void 0 || typeof fb === "string" || typeof fb === "number") return;
|
|
64
|
+
if (isVar(fb)) {
|
|
65
|
+
validateReadFallback(fallbackOf(fb));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
invariant(isCalc(fb) || isColor(fb), "Declaration var fallback must be text, a number, an expression, or a Var read");
|
|
69
|
+
};
|
|
70
|
+
/** @internal */
|
|
71
|
+
function make(name, value) {
|
|
72
|
+
let resolved;
|
|
73
|
+
if (isVar(name)) {
|
|
74
|
+
invariant(fallbackOf(name) === void 0, "A write takes the bare handle — a fallback belongs to a read site, not the property");
|
|
75
|
+
resolved = `--${nameOf(name)}`;
|
|
76
|
+
} else resolved = name;
|
|
77
|
+
invariant(resolved.length > 0, "Declaration name must be a non-empty string");
|
|
78
|
+
if (isVar(value)) validateReadFallback(fallbackOf(value));
|
|
79
|
+
return new DeclarationImpl(resolved, typeof value === "number" ? toCalc(value) : value);
|
|
80
|
+
}
|
|
81
|
+
const bindRead = (read, bindings) => {
|
|
82
|
+
const bound = bindings[nameOf(read)];
|
|
83
|
+
if (bound !== void 0) return toCalc(bound);
|
|
84
|
+
const fb = fallbackOf(read);
|
|
85
|
+
const rebound = bindFallback(fb, bindings);
|
|
86
|
+
return rebound === fb ? read : fallback(read, rebound);
|
|
87
|
+
};
|
|
88
|
+
const bindFallback = (fb, bindings) => {
|
|
89
|
+
if (fb === void 0 || typeof fb === "string" || typeof fb === "number") return fb;
|
|
90
|
+
if (isCalc(fb)) return bind$1(fb, bindings);
|
|
91
|
+
if (isVar(fb)) return bindRead(fb, bindings);
|
|
92
|
+
return bind$2(fb, bindings);
|
|
93
|
+
};
|
|
94
|
+
/** @internal */
|
|
95
|
+
const bind = dual(2, (declaration, bindings) => {
|
|
96
|
+
const value = declaration.value;
|
|
97
|
+
if (typeof value === "string") return declaration;
|
|
98
|
+
if (isVar(value)) {
|
|
99
|
+
let touchesRead = false;
|
|
100
|
+
for (const name of refsOf$1(value)) if (bindings[name] !== void 0) {
|
|
101
|
+
touchesRead = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return touchesRead ? new DeclarationImpl(declaration.name, bindRead(value, bindings)) : declaration;
|
|
105
|
+
}
|
|
106
|
+
return new DeclarationImpl(declaration.name, isCalc(value) ? bind$1(value, bindings) : bind$2(value, bindings));
|
|
107
|
+
});
|
|
108
|
+
/** @internal */
|
|
109
|
+
function refs(declaration) {
|
|
110
|
+
return refsOf(declaration);
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
const renderWith = (declaration, precision) => `${declaration.name}: ${serializeValue(declaration.value, precision)};`;
|
|
114
|
+
/** @internal */
|
|
115
|
+
const render = (declaration, options) => renderWith(declaration, options?.precision);
|
|
116
|
+
/** @internal */
|
|
117
|
+
const equals = dual(2, (self, that) => equals$1(self, that));
|
|
118
|
+
//#endregion
|
|
119
|
+
export { refs as a, renderWith as c, make as i, equals as n, refsOf as o, isDeclaration as r, render as s, bind as t };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=declaration.internal-bHzvbanA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.internal-bHzvbanA.mjs","names":["Equal.equals","Equal.hashString","Equal.hash","serializeCalc","serializeColor","varNameOf","protocolRefsOf","Equal.EqualTypeId","Equal.HashTypeId","#hash","Equal.combine","deriveRead","bindCalc","bindColor"],"sources":["../../src/declaration/declaration.internal.ts"],"sourcesContent":["import type { ApplyBindings, Bindings, Input } from '#calc/calc'\nimport { bind as bindCalc, isCalc, serialize as serializeCalc, toCalc } from '#calc/calc.internal'\nimport type { Precision } from '#calc/precision'\nimport { bind as bindColor, isColor, serialize as serializeColor } from '#data/color.internal'\nimport * as Equal from '#internal/equal'\nimport { EMPTY_REFS, refsOf as protocolRefsOf } from '#internal/refs'\nimport { dual, invariant, Pipeable } from '#util'\nimport type { Name as VarName } from '#var/var'\nimport {\n type AnyVar,\n fallback as deriveRead,\n fallbackOf,\n isVar,\n nameOf as varNameOf,\n} from '#var/var.internal'\nimport type { Declaration, RenderOptions, Value } from './declaration.ts'\n\nexport const DeclarationTypeId = Symbol.for('fashionable/declaration')\nexport type DeclarationTypeId = typeof DeclarationTypeId\n\nconst valueEquals = (a: Value<AnyVar>, b: Value<AnyVar>): boolean =>\n typeof a === 'string' || typeof b === 'string' ? a === b : Equal.equals(a, b)\n\nconst valueHash = (value: Value<AnyVar>): number =>\n typeof value === 'string' ? Equal.hashString(value) : Equal.hash(value)\n\n// A declaration-level fallback renders by its own form: literal text\n// verbatim, numbers as constants under the precision context, expressions\n// through their serializers, nested reads recursively.\nconst serializeFallback = (fb: unknown, precision?: Precision): string => {\n if (typeof fb === 'string') {\n return fb\n }\n const options = precision === undefined ? {} : { precision }\n if (typeof fb === 'number' || isCalc(fb)) {\n return serializeCalc(toCalc(fb as number), options)\n }\n if (isVar(fb)) {\n return serializeRead(fb, precision)\n }\n return serializeColor(fb as Parameters<typeof serializeColor>[0], options)\n}\n\nconst serializeRead = (read: AnyVar, precision?: Precision): string => {\n const fb = fallbackOf(read)\n return fb === undefined\n ? `var(--${varNameOf(read)})`\n : `var(--${varNameOf(read)}, ${serializeFallback(fb, precision)})`\n}\n\nconst serializeValue = (value: Value<AnyVar>, precision?: Precision): string => {\n if (typeof value === 'string') {\n return value\n }\n if (isVar(value)) {\n return serializeRead(value, precision)\n }\n const options = precision === undefined ? {} : { precision }\n return isCalc(value) ? serializeCalc(value, options) : serializeColor(value, options)\n}\n\nclass DeclarationImpl extends Pipeable implements Declaration<AnyVar>, Equal.Equal {\n readonly [DeclarationTypeId]: DeclarationTypeId = DeclarationTypeId\n\n readonly name: string\n readonly value: Value<AnyVar>\n readonly refSet: ReadonlySet<string>\n #hash: number | undefined\n\n constructor(name: string, value: Value<AnyVar>) {\n super()\n this.name = name\n this.value = value\n // the refs protocol covers every non-text form uniformly: Calc, Color,\n // and Var values each expose their vars set behind the shared symbol\n this.refSet = typeof value === 'string' ? EMPTY_REFS : protocolRefsOf(value)\n }\n\n [Equal.EqualTypeId](that: unknown): boolean {\n return isDeclaration(that) && this.name === that.name && valueEquals(this.value, that.value)\n }\n\n [Equal.HashTypeId](): number {\n if (this.#hash === undefined) {\n let h = Equal.hashString('fashionable/declaration')\n h = Equal.combine(h, Equal.hashString(this.name))\n h = Equal.combine(h, valueHash(this.value))\n this.#hash = h\n }\n return this.#hash\n }\n\n get [Symbol.toStringTag]() {\n return `Declaration(${this.name}: ${serializeValue(this.value)})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isDeclaration = (u: unknown): u is Declaration<AnyVar> =>\n typeof u === 'object' && u !== null && DeclarationTypeId in u\n\n/** @internal */\nexport const refsOf = (declaration: Declaration<AnyVar>): ReadonlySet<string> =>\n (declaration as unknown as DeclarationImpl).refSet\n\n// A read's fallback chain must hold declaration-value forms only. The\n// public signatures enforce this; the walk backs them for untyped callers.\nconst validateReadFallback = (fb: unknown): void => {\n if (fb === undefined || typeof fb === 'string' || typeof fb === 'number') {\n return\n }\n if (isVar(fb)) {\n validateReadFallback(fallbackOf(fb))\n return\n }\n invariant(\n isCalc(fb) || isColor(fb),\n 'Declaration var fallback must be text, a number, an expression, or a Var read',\n )\n}\n\n/** @internal */\nexport function make(name: string | AnyVar, value: Value<AnyVar> | number): Declaration<never> {\n let resolved: string\n if (isVar(name)) {\n invariant(\n fallbackOf(name) === undefined,\n 'A write takes the bare handle — a fallback belongs to a read site, not the property',\n )\n resolved = `--${varNameOf(name)}`\n } else {\n resolved = name\n }\n invariant(resolved.length > 0, 'Declaration name must be a non-empty string')\n if (isVar(value)) {\n validateReadFallback(fallbackOf(value))\n }\n return new DeclarationImpl(\n resolved,\n typeof value === 'number' ? toCalc(value) : value,\n ) as Declaration<never>\n}\n\n// Binding a read: a bound name replaces the whole read (fallback\n// discarded, as in calc), an unbound one keeps the read and binds inside\n// its fallback chain instead.\nconst bindRead = (read: AnyVar, bindings: Record<string, Input>): Value<AnyVar> => {\n const bound = bindings[varNameOf(read)]\n if (bound !== undefined) {\n return toCalc(bound)\n }\n const fb = fallbackOf(read)\n const rebound = bindFallback(fb, bindings)\n return rebound === fb ? (read as Value<AnyVar>) : (deriveRead(read, rebound) as Value<AnyVar>)\n}\n\nconst bindFallback = (fb: unknown, bindings: Record<string, Input>): unknown => {\n if (fb === undefined || typeof fb === 'string' || typeof fb === 'number') {\n return fb\n }\n if (isCalc(fb)) {\n return bindCalc(fb, bindings)\n }\n if (isVar(fb)) {\n return bindRead(fb, bindings)\n }\n return bindColor(fb as Parameters<typeof bindColor>[0], bindings)\n}\n\n/** @internal */\nexport const bind: {\n <const B extends Bindings>(\n bindings: B,\n ): <Vars extends AnyVar>(declaration: Declaration<Vars>) => Declaration<ApplyBindings<Vars, B>>\n <Vars extends AnyVar, const B extends Bindings>(\n declaration: Declaration<Vars>,\n bindings: B,\n ): Declaration<ApplyBindings<Vars, B>>\n} = dual(\n 2,\n (declaration: Declaration<AnyVar>, bindings: Record<string, Input>): Declaration<AnyVar> => {\n const value = declaration.value\n if (typeof value === 'string') {\n return declaration\n }\n if (isVar(value)) {\n let touchesRead = false\n for (const name of protocolRefsOf(value)) {\n if (bindings[name] !== undefined) {\n touchesRead = true\n break\n }\n }\n return touchesRead\n ? new DeclarationImpl(declaration.name, bindRead(value, bindings))\n : declaration\n }\n return new DeclarationImpl(\n declaration.name,\n isCalc(value) ? bindCalc(value, bindings) : bindColor(value, bindings),\n )\n },\n)\n\n/** @internal */\nexport function refs<Vars extends AnyVar>(\n declaration: Declaration<Vars>,\n): ReadonlySet<VarName<Vars>> {\n return refsOf(declaration) as ReadonlySet<VarName<Vars>>\n}\n\n/** @internal */\nexport const renderWith = (declaration: Declaration<AnyVar>, precision?: Precision): string =>\n `${declaration.name}: ${serializeValue(declaration.value, precision)};`\n\n/** @internal */\nexport const render = (declaration: Declaration<AnyVar>, options?: RenderOptions): string =>\n renderWith(declaration, options?.precision)\n\n/** @internal */\nexport const equals = dual<\n (that: Declaration<AnyVar>) => (self: Declaration<AnyVar>) => boolean,\n (self: Declaration<AnyVar>, that: Declaration<AnyVar>) => boolean\n>(2, (self: Declaration<AnyVar>, that: Declaration<AnyVar>): boolean => Equal.equals(self, that))\n"],"mappings":";;;;;;AAiBA,MAAa,oBAAoB,OAAO,IAAI,yBAAyB;AAGrE,MAAM,eAAe,GAAkB,MACrC,OAAO,MAAM,YAAY,OAAO,MAAM,WAAW,MAAM,IAAIA,SAAa,GAAG,CAAC;AAE9E,MAAM,aAAa,UACjB,OAAO,UAAU,WAAWC,WAAiB,KAAK,IAAIC,KAAW,KAAK;AAKxE,MAAM,qBAAqB,IAAa,cAAkC;CACxE,IAAI,OAAO,OAAO,UAChB,OAAO;CAET,MAAM,UAAU,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;CAC3D,IAAI,OAAO,OAAO,YAAY,OAAO,EAAE,GACrC,OAAOC,UAAc,OAAO,EAAY,GAAG,OAAO;CAEpD,IAAI,MAAM,EAAE,GACV,OAAO,cAAc,IAAI,SAAS;CAEpC,OAAOC,YAAe,IAA4C,OAAO;AAC3E;AAEA,MAAM,iBAAiB,MAAc,cAAkC;CACrE,MAAM,KAAK,WAAW,IAAI;CAC1B,OAAO,OAAO,KAAA,IACV,SAASC,OAAU,IAAI,EAAE,KACzB,SAASA,OAAU,IAAI,EAAE,IAAI,kBAAkB,IAAI,SAAS,EAAE;AACpE;AAEA,MAAM,kBAAkB,OAAsB,cAAkC;CAC9E,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,MAAM,KAAK,GACb,OAAO,cAAc,OAAO,SAAS;CAEvC,MAAM,UAAU,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;CAC3D,OAAO,OAAO,KAAK,IAAIF,UAAc,OAAO,OAAO,IAAIC,YAAe,OAAO,OAAO;AACtF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AY,KAAK,IAAI,eAAe,YAAY,OAAO,SAAS,EAAE;;AAGvE,MAAa,UAAU,aAAkC,YACvD,WAAW,aAAa,SAAS,SAAS;;AAG5C,MAAa,SAAS,KAGpB,IAAI,MAA2B,SAAuCb,SAAa,MAAM,IAAI,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Pipeable } from "./utils-
|
|
2
|
-
import { n as RenderOptions$1 } from "./declaration-
|
|
1
|
+
import { t as Pipeable } from "./utils-DpN6qr94.mjs";
|
|
2
|
+
import { n as RenderOptions$1 } from "./declaration-CqRm38oZ.mjs";
|
|
3
3
|
//#region src/fontFace/fontFaceRule.internal.d.ts
|
|
4
4
|
declare const FontFaceRuleTypeId: unique symbol;
|
|
5
5
|
type FontFaceRuleTypeId = typeof FontFaceRuleTypeId;
|
|
@@ -291,4 +291,4 @@ declare const equals: {
|
|
|
291
291
|
};
|
|
292
292
|
//#endregion
|
|
293
293
|
export { fontFaceRule_d_exports as n, FontFaceRule as t };
|
|
294
|
-
//# sourceMappingURL=fontFaceRule-
|
|
294
|
+
//# sourceMappingURL=fontFaceRule-BOgUM4PF.d.mts.map
|