fashionable 0.3.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/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-9fpSiiJk.mjs → color.internal-CxjlaRqR.mjs} +46 -11
- 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-DdnLAuVw.d.mts → fontFaceRule-BOgUM4PF.d.mts} +3 -3
- package/dist/shared/index-D-hVWDgZ.d.mts +2289 -0
- package/dist/shared/{mediaQuery-DsBivHi0.d.mts → mediaQuery-VDIAHnM1.d.mts} +2 -2
- package/dist/shared/{mediaRule-4kY2IOq-.d.mts → mediaRule-2K7Ggwe4.d.mts} +169 -105
- package/dist/shared/{propertyRule-B5pf7NgH.d.mts → propertyRule-B9ii0mv4.d.mts} +56 -21
- package/dist/shared/{propertyRule.internal-CRyFLwbn.mjs → propertyRule.internal-ncYCWUar.mjs} +31 -4
- package/dist/shared/propertyRule.internal-ncYCWUar.mjs.map +1 -0
- package/dist/shared/{ruleSet.internal-a5m40W9E.mjs → ruleSet.internal-Cj4yIYFI.mjs} +30 -17
- 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 +67 -53
- package/dist/stylesheet/index.mjs +44 -30
- 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-9fpSiiJk.mjs.map +0 -1
- package/dist/shared/declaration-B-6Ykgs_.d.mts +0 -166
- package/dist/shared/declaration.internal-BeasYIJ0.mjs +0 -73
- package/dist/shared/declaration.internal-BeasYIJ0.mjs.map +0 -1
- package/dist/shared/index-BvtwY4FQ.d.mts +0 -841
- package/dist/shared/propertyRule.internal-CRyFLwbn.mjs.map +0 -1
- package/dist/shared/ruleSet.internal-a5m40W9E.mjs.map +0 -1
- package/dist/shared/selector-HZY-W6l6.d.mts +0 -346
- package/dist/shared/selector.internal-ESe9s0IH.mjs.map +0 -1
package/dist/rule/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { t as __exportAll } from "../shared/rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { _ as equals$3, a as forMediaQuery$1, b as refs
|
|
2
|
+
import { _ as equals$3, a as forMediaQuery$1, b as refs, c as isRuleSet$1, d as render$4, f as equals$5, g as render$5, h as refs$2, i as equals$4, l as make$4, m as make$5, n as concat$1, o as forSelector$1, p as isStyleRule$1, r as empty$1, s as isEmpty$1, t as append$1, u as refs$1, v as isMediaRule$1, x as render$3, y as make$3 } from "../shared/ruleSet.internal-Cj4yIYFI.mjs";
|
|
3
3
|
//#region src/rule/mediaRule.ts
|
|
4
4
|
var mediaRule_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
equals: () => equals$2,
|
|
6
6
|
isMediaRule: () => isMediaRule,
|
|
7
7
|
make: () => make$2,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
render: () => render$2,
|
|
9
|
+
vars: () => vars$2
|
|
10
10
|
});
|
|
11
11
|
/**
|
|
12
12
|
* Checks if a value is a `MediaRule`.
|
|
@@ -20,11 +20,11 @@ var mediaRule_exports = /* @__PURE__ */ __exportAll({
|
|
|
20
20
|
*/
|
|
21
21
|
const isMediaRule = isMediaRule$1;
|
|
22
22
|
/**
|
|
23
|
-
* Creates a
|
|
23
|
+
* Creates a `@media` rule.
|
|
24
24
|
*
|
|
25
25
|
* @param query - The media query gating the block.
|
|
26
|
-
* @param block - The rule's block.
|
|
27
|
-
* @returns A `MediaRule` carrying the block's
|
|
26
|
+
* @param block - The rule's block. Declarations make the rule nested-only; a block of closed style rules makes it top-level-capable.
|
|
27
|
+
* @returns A `MediaRule` carrying the block's variable names and requirements.
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
30
30
|
* MediaRule.make(
|
|
@@ -36,14 +36,14 @@ const isMediaRule = isMediaRule$1;
|
|
|
36
36
|
*/
|
|
37
37
|
const make$2 = make$3;
|
|
38
38
|
/**
|
|
39
|
-
* The rule's unbound
|
|
39
|
+
* The rule's unbound variable names — the block's, since a query
|
|
40
40
|
* contributes none.
|
|
41
41
|
*
|
|
42
42
|
* @param rule - The rule to inspect.
|
|
43
|
-
* @returns The set of unbound
|
|
43
|
+
* @returns The set of unbound variable names.
|
|
44
44
|
* @since 0.1.0
|
|
45
45
|
*/
|
|
46
|
-
const
|
|
46
|
+
const vars$2 = refs;
|
|
47
47
|
/**
|
|
48
48
|
* Renders the rule in nested form: `@media query { ... }`, the body as
|
|
49
49
|
* `RuleSet.render` emits it, one level deeper — declarations directly
|
|
@@ -51,13 +51,15 @@ const refs$2 = refs$3;
|
|
|
51
51
|
* style rule (CSSNestedDeclarations). A rule whose block is empty
|
|
52
52
|
* renders as the empty string.
|
|
53
53
|
*
|
|
54
|
+
* Nested style rules render as indented sub-blocks with `&` kept
|
|
55
|
+
* verbatim — native CSS nesting is the output shape.
|
|
56
|
+
*
|
|
54
57
|
* A fragment renderer: whole sheets render via `Stylesheet.render`,
|
|
55
58
|
* which emits each rule's media in this same nested shape.
|
|
56
59
|
*
|
|
57
60
|
* @param rule - The rule to render.
|
|
58
61
|
* @param options - Optional indentation unit, precision context, and media syntax.
|
|
59
62
|
* @returns Deterministic CSS text.
|
|
60
|
-
* @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.
|
|
61
63
|
* @example
|
|
62
64
|
* ```ts
|
|
63
65
|
* MediaRule.render(
|
|
@@ -80,8 +82,8 @@ var ruleSet_exports = /* @__PURE__ */ __exportAll({
|
|
|
80
82
|
isEmpty: () => isEmpty,
|
|
81
83
|
isRuleSet: () => isRuleSet,
|
|
82
84
|
make: () => make$1,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
render: () => render$1,
|
|
86
|
+
vars: () => vars$1
|
|
85
87
|
});
|
|
86
88
|
/**
|
|
87
89
|
* Checks if a value is a `RuleSet`.
|
|
@@ -116,11 +118,11 @@ const isEmpty = isEmpty$1;
|
|
|
116
118
|
* Creates a rule set holding the given members, in the given order.
|
|
117
119
|
*
|
|
118
120
|
* @param members - Declarations and nested rules, in authored order.
|
|
119
|
-
* @returns A `RuleSet` whose `
|
|
121
|
+
* @returns A `RuleSet` whose `Vars` unions the members' variable names and whose `Requires` unions their requirement contributions.
|
|
120
122
|
* @example
|
|
121
123
|
* ```ts
|
|
122
124
|
* const block = RuleSet.make(
|
|
123
|
-
* Declaration.make('--depth', Calc.
|
|
125
|
+
* Declaration.make('--depth', Calc.var('depth')),
|
|
124
126
|
* Declaration.make('color', 'oklch(0.7 0.1 250)'),
|
|
125
127
|
* ) // RuleSet<'depth'>
|
|
126
128
|
* ```
|
|
@@ -132,27 +134,29 @@ const concat = concat$1;
|
|
|
132
134
|
const forSelector = forSelector$1;
|
|
133
135
|
const forMediaQuery = forMediaQuery$1;
|
|
134
136
|
/**
|
|
135
|
-
* The block's unbound
|
|
137
|
+
* The block's unbound variable names, unioned across members —
|
|
136
138
|
* including everything nested rules contribute.
|
|
137
139
|
*
|
|
138
140
|
* @param set - The block to inspect.
|
|
139
|
-
* @returns The set of unbound
|
|
141
|
+
* @returns The set of unbound variable names.
|
|
140
142
|
* @since 0.1.0
|
|
141
143
|
*/
|
|
142
|
-
const
|
|
144
|
+
const vars$1 = refs$1;
|
|
143
145
|
/**
|
|
144
146
|
* Renders the block's body — the text between a rule's braces, without
|
|
145
|
-
* the braces: one line per declaration, nested `@media` rules
|
|
146
|
-
* indented sub-blocks, in member order. Empty
|
|
147
|
-
* whose blocks are empty) render as the empty
|
|
147
|
+
* the braces: one line per declaration, nested `@media` and style rules
|
|
148
|
+
* as indented sub-blocks (`&` kept verbatim), in member order. Empty
|
|
149
|
+
* blocks (and nested rules whose blocks are empty) render as the empty
|
|
150
|
+
* string.
|
|
148
151
|
*
|
|
149
152
|
* A fragment renderer: use it to compose blocks the model does not
|
|
150
|
-
* represent. Whole sheets render via `Stylesheet.render
|
|
153
|
+
* represent. Whole sheets render via `Stylesheet.render`, and the binder
|
|
154
|
+
* invariant on nested selectors is `StyleRule.make`'s — a free-standing
|
|
155
|
+
* block renders without it.
|
|
151
156
|
*
|
|
152
157
|
* @param set - The block to render.
|
|
153
158
|
* @param options - Optional indentation unit, precision context, and media syntax.
|
|
154
159
|
* @returns Deterministic CSS text.
|
|
155
|
-
* @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.
|
|
156
160
|
* @example
|
|
157
161
|
* ```ts
|
|
158
162
|
* RuleSet.render(RuleSet.make(Declaration.make('--depth', 4), Declaration.make('color', 'red')))
|
|
@@ -168,8 +172,8 @@ var styleRule_exports = /* @__PURE__ */ __exportAll({
|
|
|
168
172
|
equals: () => equals,
|
|
169
173
|
isStyleRule: () => isStyleRule,
|
|
170
174
|
make: () => make,
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
render: () => render,
|
|
176
|
+
vars: () => vars
|
|
173
177
|
});
|
|
174
178
|
/**
|
|
175
179
|
* Checks if a value is a `StyleRule`.
|
|
@@ -185,32 +189,41 @@ const isStyleRule = isStyleRule$1;
|
|
|
185
189
|
/**
|
|
186
190
|
* Creates a style rule.
|
|
187
191
|
*
|
|
188
|
-
*
|
|
192
|
+
* The binder check runs here: every style rule nested in `block` —
|
|
193
|
+
* directly, or inside its `@media` blocks — must reference `&` in its
|
|
194
|
+
* selector, because this rule's selector is what that `&` reads. CSS
|
|
195
|
+
* would silently prepend a descendant `&` instead; the model rejects
|
|
196
|
+
* the shape rather than rewriting the authored selector.
|
|
197
|
+
*
|
|
198
|
+
* @param selector - The selector the block applies to. References `&` exactly when this rule itself nests.
|
|
189
199
|
* @param block - The rule's block.
|
|
190
|
-
* @returns A `StyleRule` carrying the block's
|
|
200
|
+
* @returns A `StyleRule` carrying the block's variable names and the selector's requirements.
|
|
201
|
+
* @throws `Error` when a style rule nested in `block` has a selector that does not reference `&`.
|
|
191
202
|
* @example
|
|
192
203
|
* ```ts
|
|
193
204
|
* StyleRule.make(
|
|
194
205
|
* Selector.root,
|
|
195
|
-
* RuleSet.make(Declaration.make('--depth', Calc.
|
|
206
|
+
* RuleSet.make(Declaration.make('--depth', Calc.var('depth'))),
|
|
196
207
|
* ) // StyleRule<'depth'>
|
|
197
208
|
* ```
|
|
198
209
|
* @since 0.1.0
|
|
199
210
|
*/
|
|
200
211
|
const make = make$5;
|
|
201
212
|
/**
|
|
202
|
-
* The rule's unbound
|
|
213
|
+
* The rule's unbound variable names — the block's, since a selector
|
|
203
214
|
* contributes none.
|
|
204
215
|
*
|
|
205
216
|
* @param rule - The rule to inspect.
|
|
206
|
-
* @returns The set of unbound
|
|
217
|
+
* @returns The set of unbound variable names.
|
|
207
218
|
* @since 0.1.0
|
|
208
219
|
*/
|
|
209
|
-
const
|
|
220
|
+
const vars = refs$2;
|
|
210
221
|
/**
|
|
211
222
|
* Renders the rule in nested form: `selector { ... }`, the body as
|
|
212
|
-
* `RuleSet.render` emits it, one level deeper.
|
|
213
|
-
*
|
|
223
|
+
* `RuleSet.render` emits it, one level deeper. Nested style rules render
|
|
224
|
+
* as indented sub-blocks with `&` kept verbatim — native CSS nesting is
|
|
225
|
+
* the output shape. A rule whose block is empty renders as the empty
|
|
226
|
+
* string.
|
|
214
227
|
*
|
|
215
228
|
* A fragment renderer: whole sheets render via `Stylesheet.render`,
|
|
216
229
|
* which emits each rule in this same nested shape.
|
|
@@ -218,7 +231,6 @@ const refs = refs$5;
|
|
|
218
231
|
* @param rule - The rule to render.
|
|
219
232
|
* @param options - Optional indentation unit, precision context, and media syntax.
|
|
220
233
|
* @returns Deterministic CSS text.
|
|
221
|
-
* @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.
|
|
222
234
|
* @example
|
|
223
235
|
* ```ts
|
|
224
236
|
* StyleRule.render(StyleRule.make(Selector.root, RuleSet.make(Declaration.make('--depth', 4))))
|
package/dist/rule/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["internal.isMediaRule","make","internal.make","refs","internal.refs","render","internal.render","equals","internal.equals","internal.isRuleSet","internal.empty","internal.isEmpty","make","internal.make","internal.append","internal.concat","internal.forSelector","internal.forMediaQuery","refs","internal.refs","render","internal.render","equals","internal.equals","internal.isStyleRule","internal.make","internal.refs","internal.render","internal.equals"],"sources":["../../src/rule/mediaRule.ts","../../src/rule/ruleSet.ts","../../src/rule/styleRule.ts"],"sourcesContent":["import type { MediaQuery } from '#query/mediaQuery'\nimport type { Pipeable } from '#util'\nimport type { MediaRuleTypeId } from './mediaRule.internal.ts'\nimport * as internal from './mediaRule.internal.ts'\nimport type { RenderOptions as RuleSetRenderOptions, RuleSet } from './ruleSet.ts'\n\n/**\n * A nested `@media` rule: a media query and the block it gates.\n *\n * This is the nested form — a member of an enclosing style rule's block,\n * per the CSSNestedDeclarations grammar — not a top-level `@media`\n * statement. Media enters the model inside a style rule\n * (`:root { @media ... { ... } }`) and renders there, nested. The `Refs`\n * parameter is the block's.\n *\n * Construct via `make`.\n *\n * @since 0.1.0\n */\nexport interface MediaRule<out Refs extends string = string> extends Pipeable {\n readonly [MediaRuleTypeId]: MediaRuleTypeId\n /**\n * The media query gating the block.\n */\n readonly query: MediaQuery\n /**\n * The rule's block.\n */\n readonly block: RuleSet<Refs>\n}\n\n/**\n * Checks if a value is a `MediaRule`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `MediaRule`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isMediaRule: (u: unknown) => u is MediaRule<string> = internal.isMediaRule\n\n/**\n * Creates a nested `@media` rule.\n *\n * @param query - The media query gating the block.\n * @param block - The rule's block.\n * @returns A `MediaRule` carrying the block's reference names.\n * @example\n * ```ts\n * MediaRule.make(\n * MediaQuery.prefersColorScheme('dark'),\n * RuleSet.make(Declaration.make('--scheme', 'dark')),\n * )\n * ```\n * @since 0.1.0\n */\nexport const make: <Refs extends string>(\n query: MediaQuery,\n block: RuleSet<Refs>,\n) => MediaRule<Refs> = internal.make\n\n/**\n * The rule's unbound reference names — the block's, since a query\n * contributes none.\n *\n * @param rule - The rule to inspect.\n * @returns The set of unbound reference names.\n * @since 0.1.0\n */\nexport const refs: <Refs extends string>(rule: MediaRule<Refs>) => ReadonlySet<Refs> = internal.refs\n\n/**\n * Options for `render` — the block renderers' shared shape,\n * `RuleSet.RenderOptions`, unchanged.\n *\n * @since 0.1.0\n */\nexport type RenderOptions = RuleSetRenderOptions\n\n/**\n * Renders the rule in nested form: `@media query { ... }`, the body as\n * `RuleSet.render` emits it, one level deeper — declarations directly\n * inside the query block, the shape a media rule takes nested in a\n * style rule (CSSNestedDeclarations). A rule whose block is empty\n * renders as the empty string.\n *\n * A fragment renderer: whole sheets render via `Stylesheet.render`,\n * which emits each rule's media in this same nested shape.\n *\n * @param rule - The rule to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.\n * @example\n * ```ts\n * MediaRule.render(\n * MediaRule.make(MediaQuery.minWidth(768), RuleSet.make(Declaration.make('--gutter', 24))),\n * ) // '@media (min-width: 768px) {\\n\\t--gutter: 24;\\n}'\n * ```\n * @since 0.1.0\n */\nexport const render: (rule: MediaRule<string>, options?: RenderOptions) => string = internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The rule to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: MediaRule<string>): (self: MediaRule<string>) => boolean\n /**\n * Structural equality: queries compare as in `MediaQuery.equals`\n * (canonically ordered features), blocks as in `RuleSet.equals`\n * (members in order).\n *\n * @param self - The first rule.\n * @param that - The second rule.\n * @returns `true` if the rules are structurally equal.\n * @since 0.1.0\n */\n (self: MediaRule<string>, that: MediaRule<string>): boolean\n} = internal.equals\n","import type {\n Declaration,\n RenderOptions as DeclarationRenderOptions,\n} from '#declaration/declaration'\nimport type { MediaQuery } from '#query/mediaQuery'\nimport type { Selector } from '#selector/selector'\nimport type { Pipeable } from '#util'\nimport type { MediaRule } from './mediaRule.ts'\nimport type { RuleSetTypeId } from './ruleSet.internal.ts'\nimport * as internal from './ruleSet.internal.ts'\nimport type { StyleRule } from './styleRule.ts'\n\n/**\n * An ordered block of rule members — the nesting unit of the rule layer.\n *\n * Member order is preserved exactly as authored: never sorted, never\n * deduplicated. A block's order is cascade behavior, and since\n * CSSNestedDeclarations shipped (late 2024), declarations trailing a\n * nested rule keep their source position rather than hoisting above it —\n * so what you append is what renders.\n *\n * The `Refs` parameter unions the members' unbound reference names, as on\n * `Calc`; `refs` is the runtime set.\n *\n * Construct via `make` (or `empty` and `append`).\n *\n * @since 0.1.0\n */\nexport interface RuleSet<out Refs extends string = string> extends Pipeable {\n readonly [RuleSetTypeId]: RuleSetTypeId\n /**\n * The block's members, in authored order.\n */\n readonly members: ReadonlyArray<Member<Refs>>\n}\n\n/**\n * The forms a rule block may contain: declarations, nested style rules,\n * and nested `@media` rules.\n *\n * Deliberately absent are the declaration-block at-rules (`@font-face`,\n * `@property`) — the CSS grammar keeps them at the top level, so this\n * union keeps them out of blocks at the type level.\n *\n * @since 0.1.0\n */\nexport type Member<Refs extends string = string> =\n | Declaration<Refs>\n | StyleRule<Refs>\n | MediaRule<Refs>\n\n/**\n * The unbound reference names of a `Member`, or the union of them for a\n * union of members — the type-level counterpart of `refs`, used by the\n * container constructors to thread their members' names into the result.\n *\n * @since 0.1.0\n */\nexport type MemberRefs<M extends Member<string>> =\n M extends Declaration<infer R>\n ? R\n : M extends StyleRule<infer R>\n ? R\n : M extends MediaRule<infer R>\n ? R\n : never\n\n/**\n * Checks if a value is a `RuleSet`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `RuleSet`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isRuleSet: (u: unknown) => u is RuleSet<string> = internal.isRuleSet\n\n/**\n * The empty block — the identity for `concat`.\n *\n * @since 0.1.0\n */\nexport const empty: RuleSet<never> = internal.empty\n\n/**\n * Checks if the block has no members.\n *\n * Structural emptiness only: a non-empty block can still *render* as the\n * empty string, when every member is a nested rule whose block renders\n * empty.\n *\n * @param set - The block to inspect.\n * @returns `true` if the block has no members.\n * @since 0.2.0\n */\nexport const isEmpty: (set: RuleSet<string>) => boolean = internal.isEmpty\n\n/**\n * Creates a rule set holding the given members, in the given order.\n *\n * @param members - Declarations and nested rules, in authored order.\n * @returns A `RuleSet` whose `Refs` unions the members' reference names.\n * @example\n * ```ts\n * const block = RuleSet.make(\n * Declaration.make('--depth', Calc.ref('depth')),\n * Declaration.make('color', 'oklch(0.7 0.1 250)'),\n * ) // RuleSet<'depth'>\n * ```\n * @since 0.1.0\n */\nexport const make: <Members extends ReadonlyArray<Member<string>>>(\n ...members: Members\n) => RuleSet<MemberRefs<Members[number]>> = internal.make\n\nexport const append: {\n /**\n * Returns a function that appends `member` to its argument's block.\n *\n * @param member - The member to append.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <M extends Member<string>>(\n member: M,\n ): <Refs extends string>(self: RuleSet<Refs>) => RuleSet<Refs | MemberRefs<M>>\n /**\n * Returns a function that appends the style rule `selector { block }`\n * to its argument's block.\n *\n * @param selector - The nested rule's selector.\n * @param block - The nested rule's block.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <B extends string>(\n selector: Selector,\n block: RuleSet<B>,\n ): <Refs extends string>(self: RuleSet<Refs>) => RuleSet<Refs | B>\n /**\n * Returns a function that appends the media rule `@media query { block }`\n * to its argument's block.\n *\n * @param query - The nested rule's media query.\n * @param block - The nested rule's block.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <B extends string>(\n query: MediaQuery,\n block: RuleSet<B>,\n ): <Refs extends string>(self: RuleSet<Refs>) => RuleSet<Refs | B>\n /**\n * Appends a member at the end of the block. The result is a new set;\n * the original is untouched.\n *\n * @param self - The block to extend.\n * @param member - The member to append.\n * @returns The extended block, with the member's reference names joined in.\n * @example\n * ```ts\n * RuleSet.empty.pipe(\n * RuleSet.append(Declaration.make('color', 'red')),\n * RuleSet.append(Declaration.make('--depth', Calc.ref('depth'))),\n * ) // RuleSet<'depth'>\n * ```\n * @since 0.1.0\n */\n <Refs extends string, M extends Member<string>>(\n self: RuleSet<Refs>,\n member: M,\n ): RuleSet<Refs | MemberRefs<M>>\n /**\n * Appends a nested style rule from its parts — sugar for\n * `append(self, StyleRule.make(selector, block))`, so blocks compose\n * without naming `StyleRule` at the call site.\n *\n * @param self - The block to extend.\n * @param selector - The nested rule's selector.\n * @param block - The nested rule's block.\n * @returns The extended block, with the nested block's reference names joined in.\n * @example\n * ```ts\n * RuleSet.empty.pipe(RuleSet.append(Selector.class('btn'), RuleSet.make(Declaration.make('color', 'red'))))\n * ```\n * @since 0.1.0\n */\n <Refs extends string, B extends string>(\n self: RuleSet<Refs>,\n selector: Selector,\n block: RuleSet<B>,\n ): RuleSet<Refs | B>\n /**\n * Appends a nested media rule from its parts — sugar for\n * `append(self, MediaRule.make(query, block))`, so blocks compose\n * without naming `MediaRule` at the call site.\n *\n * @param self - The block to extend.\n * @param query - The nested rule's media query.\n * @param block - The nested rule's block.\n * @returns The extended block, with the nested block's reference names joined in.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--gutter', 16)).pipe(\n * RuleSet.append(MediaQuery.minWidth(768), RuleSet.make(Declaration.make('--gutter', 24))),\n * )\n * ```\n * @since 0.1.0\n */\n <Refs extends string, B extends string>(\n self: RuleSet<Refs>,\n query: MediaQuery,\n block: RuleSet<B>,\n ): RuleSet<Refs | B>\n} = internal.append\n\nexport const concat: {\n /**\n * Returns a function that appends `that`'s members after its argument's.\n *\n * @param that - The block whose members come second.\n * @returns A function producing the concatenated block.\n * @since 0.1.0\n */\n <B extends string>(that: RuleSet<B>): <A extends string>(self: RuleSet<A>) => RuleSet<A | B>\n /**\n * Concatenates two blocks: `self`'s members followed by `that`'s, order\n * preserved on both sides. No deduplication happens here — repeated\n * declarations are legal CSS and their repetition is cascade behavior.\n *\n * @param self - The block whose members come first.\n * @param that - The block whose members come second.\n * @returns The concatenated block, with both sides' reference names unioned.\n * @since 0.1.0\n */\n <A extends string, B extends string>(self: RuleSet<A>, that: RuleSet<B>): RuleSet<A | B>\n} = internal.concat\n\nexport const forSelector: {\n /**\n * Returns a function that wraps its argument as the block of a style\n * rule applying to `selector`.\n *\n * @param selector - The selector the resulting rule's block applies to.\n * @returns A function that takes a block and returns the style rule applying it to `selector`.\n * @since 0.2.0\n */\n (selector: Selector): <Refs extends string>(self: RuleSet<Refs>) => StyleRule<Refs>\n /**\n * Lifts a block into a style rule applying to `selector` — sugar for\n * `StyleRule.make(selector, self)` with the arguments flipped, so a\n * block built up through `pipe` caps off as a rule without naming\n * `StyleRule` at the call site. The rule carries the block's reference\n * names unchanged; a selector contributes none.\n *\n * @param self - The block the rule applies.\n * @param selector - The selector the block applies to.\n * @returns The style rule pairing `selector` with the block.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--depth', Calc.ref('depth'))).pipe(\n * RuleSet.forSelector(Selector.root),\n * ) // StyleRule<'depth'>\n * ```\n * @since 0.2.0\n */\n <Refs extends string>(self: RuleSet<Refs>, selector: Selector): StyleRule<Refs>\n} = internal.forSelector\n\nexport const forMediaQuery: {\n /**\n * Returns a function that wraps its argument as the block of a nested\n * `@media` rule gated by `query`.\n *\n * @param query - The media query gating the resulting rule's block.\n * @returns A function that takes a block and returns the media rule gating it by `query`.\n * @since 0.2.0\n */\n (query: MediaQuery): <Refs extends string>(self: RuleSet<Refs>) => MediaRule<Refs>\n /**\n * Lifts a block into a nested `@media` rule gated by `query` — sugar\n * for `MediaRule.make(query, self)` with the arguments flipped, so a\n * block built up through `pipe` caps off as a rule without naming\n * `MediaRule` at the call site. The rule carries the block's reference\n * names unchanged; a query contributes none.\n *\n * @param self - The block the rule gates.\n * @param query - The media query gating the block.\n * @returns The media rule pairing `query` with the block.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--gutter', Calc.ref('gutter'))).pipe(\n * RuleSet.forMediaQuery(MediaQuery.minWidth(768)),\n * ) // MediaRule<'gutter'>\n * ```\n * @since 0.2.0\n */\n <Refs extends string>(self: RuleSet<Refs>, query: MediaQuery): MediaRule<Refs>\n} = internal.forMediaQuery\n\n/**\n * The block's unbound reference names, unioned across members —\n * including everything nested rules contribute.\n *\n * @param set - The block to inspect.\n * @returns The set of unbound reference names.\n * @since 0.1.0\n */\nexport const refs: <Refs extends string>(set: RuleSet<Refs>) => ReadonlySet<Refs> = internal.refs\n\n/**\n * Options for `render`, extending `Declaration.RenderOptions` (and\n * through it the family base, `MediaQuery.RenderOptions`) with the\n * indentation unit — the block renderers' shared shape, which\n * `StyleRule.render` and `MediaRule.render` take unchanged.\n *\n * @since 0.1.0\n */\nexport interface RenderOptions extends DeclarationRenderOptions {\n /**\n * The indentation unit, applied once per nesting level. Defaults to a\n * tab.\n */\n readonly indent?: string\n}\n\n/**\n * Renders the block's body — the text between a rule's braces, without\n * the braces: one line per declaration, nested `@media` rules as\n * indented sub-blocks, in member order. Empty blocks (and nested rules\n * whose blocks are empty) render as the empty string.\n *\n * A fragment renderer: use it to compose blocks the model does not\n * represent. Whole sheets render via `Stylesheet.render`.\n *\n * @param set - The block to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.\n * @example\n * ```ts\n * RuleSet.render(RuleSet.make(Declaration.make('--depth', 4), Declaration.make('color', 'red')))\n * // '--depth: 4;\\ncolor: red;'\n * ```\n * @since 0.1.0\n */\nexport const render: (set: RuleSet<string>, options?: RenderOptions) => string = internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The block to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: RuleSet<string>): (self: RuleSet<string>) => boolean\n /**\n * Structural equality over members, in order. Order participates —\n * `make(a, b)` and `make(b, a)` are different blocks, because they\n * cascade differently.\n *\n * @param self - The first block.\n * @param that - The second block.\n * @returns `true` if the blocks are structurally equal.\n * @since 0.1.0\n */\n (self: RuleSet<string>, that: RuleSet<string>): boolean\n} = internal.equals\n","import type { Selector } from '#selector/selector'\nimport type { Pipeable } from '#util'\nimport type { RenderOptions as RuleSetRenderOptions, RuleSet } from './ruleSet.ts'\nimport type { StyleRuleTypeId } from './styleRule.internal.ts'\nimport * as internal from './styleRule.internal.ts'\n\n/**\n * A style rule: a compound selector and the block it applies.\n *\n * The block is a full `RuleSet`, so a style rule holds declarations and\n * nested `@media` rules in one authored order. The `Refs` parameter is\n * the block's — a selector contributes no reference names.\n *\n * Construct via `make`.\n *\n * @since 0.1.0\n */\nexport interface StyleRule<out Refs extends string = string> extends Pipeable {\n readonly [StyleRuleTypeId]: StyleRuleTypeId\n /**\n * The compound selector the block applies to.\n */\n readonly selector: Selector\n /**\n * The rule's block.\n */\n readonly block: RuleSet<Refs>\n}\n\n/**\n * Checks if a value is a `StyleRule`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `StyleRule`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isStyleRule: (u: unknown) => u is StyleRule<string> = internal.isStyleRule\n\n/**\n * Creates a style rule.\n *\n * @param selector - The compound selector the block applies to.\n * @param block - The rule's block.\n * @returns A `StyleRule` carrying the block's reference names.\n * @example\n * ```ts\n * StyleRule.make(\n * Selector.root,\n * RuleSet.make(Declaration.make('--depth', Calc.ref('depth'))),\n * ) // StyleRule<'depth'>\n * ```\n * @since 0.1.0\n */\nexport const make: <Refs extends string>(\n selector: Selector,\n block: RuleSet<Refs>,\n) => StyleRule<Refs> = internal.make\n\n/**\n * The rule's unbound reference names — the block's, since a selector\n * contributes none.\n *\n * @param rule - The rule to inspect.\n * @returns The set of unbound reference names.\n * @since 0.1.0\n */\nexport const refs: <Refs extends string>(rule: StyleRule<Refs>) => ReadonlySet<Refs> = internal.refs\n\n/**\n * Options for `render` — the block renderers' shared shape,\n * `RuleSet.RenderOptions`, unchanged.\n *\n * @since 0.1.0\n */\nexport type RenderOptions = RuleSetRenderOptions\n\n/**\n * Renders the rule in nested form: `selector { ... }`, the body as\n * `RuleSet.render` emits it, one level deeper. A rule whose block is\n * empty renders as the empty string.\n *\n * A fragment renderer: whole sheets render via `Stylesheet.render`,\n * which emits each rule in this same nested shape.\n *\n * @param rule - The rule to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @throws `Error` when the block nests a style rule — selector composition (`&`) is a later extension, not part of v1 rendering.\n * @example\n * ```ts\n * StyleRule.render(StyleRule.make(Selector.root, RuleSet.make(Declaration.make('--depth', 4))))\n * // ':root {\\n\\t--depth: 4;\\n}'\n * ```\n * @since 0.1.0\n */\nexport const render: (rule: StyleRule<string>, options?: RenderOptions) => string = internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The rule to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: StyleRule<string>): (self: StyleRule<string>) => boolean\n /**\n * Structural equality: selectors compare as in `Selector.equals`\n * (canonically ordered parts), blocks as in `RuleSet.equals` (members\n * in order).\n *\n * @param self - The first rule.\n * @param that - The second rule.\n * @returns `true` if the rules are structurally equal.\n * @since 0.1.0\n */\n (self: StyleRule<string>, that: StyleRule<string>): boolean\n} = internal.equals\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,cAAsDA;;;;;;;;;;;;;;;;AAiBnE,MAAaC,SAGUC;;;;;;;;;AAUvB,MAAaC,SAA0EC;;;;;;;;;;;;;;;;;;;;;;;AAgCvF,MAAaC,WAAuEC;AAEpF,MAAaC,WAoBTC;;;;;;;;;;;;;;;;;;;;;;;;;;AChDJ,MAAa,YAAkDC;;;;;;AAO/D,MAAa,QAAwBC;;;;;;;;;;;;AAarC,MAAa,UAA6CC;;;;;;;;;;;;;;;AAgB1D,MAAaC,SAE+BC;AAE5C,MAAa,SAmGTC;AAEJ,MAAa,SAoBTC;AAEJ,MAAa,cA6BTC;AAEJ,MAAa,gBA6BTC;;;;;;;;;AAUJ,MAAaC,SAAuEC;;;;;;;;;;;;;;;;;;;;;AAsCpF,MAAaC,WAAoEC;AAEjF,MAAaC,WAoBTC;;;;;;;;;;;;;;;;;;;;AC3UJ,MAAa,cAAsDC;;;;;;;;;;;;;;;;AAiBnE,MAAa,OAGUC;;;;;;;;;AAUvB,MAAa,OAA0EC;;;;;;;;;;;;;;;;;;;;AA6BvF,MAAa,SAAuEC;AAEpF,MAAa,SAoBTC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["internal.isMediaRule","make","internal.make","vars","internal.refs","render","internal.render","equals","internal.equals","internal.isRuleSet","internal.empty","internal.isEmpty","make","internal.make","internal.append","internal.concat","internal.forSelector","internal.forMediaQuery","vars","internal.refs","render","internal.render","equals","internal.equals","internal.isStyleRule","internal.make","internal.refs","internal.render","internal.equals"],"sources":["../../src/rule/mediaRule.ts","../../src/rule/ruleSet.ts","../../src/rule/styleRule.ts"],"sourcesContent":["import type { MediaQuery } from '#query/mediaQuery'\nimport type { Requirement } from '#selector/selector'\nimport type { Pipeable } from '#util'\nimport type { Var } from '#var'\nimport type { MediaRuleTypeId } from './mediaRule.internal.ts'\nimport * as internal from './mediaRule.internal.ts'\nimport type { RenderOptions as RuleSetRenderOptions, RuleSet } from './ruleSet.ts'\n\n/**\n * A `@media` rule: a media query and the block it gates.\n *\n * The usual position is nested — a member of an enclosing style rule's\n * block, holding declarations that apply to that rule's selector, per\n * the CSSNestedDeclarations grammar. A media rule whose block holds only\n * closed style rules may instead sit at a stylesheet's top level, the\n * authored `@media { selector { ... } }` grouping. The `Vars` parameter\n * is the block's.\n *\n * `Requires` is the block's too — a media rule has no selector of its\n * own, so it is transparent to the requirements channel. Bare\n * declarations put `Parent` in the block's requirements, which is what\n * confines a declaration-bearing media rule to nested position:\n * `Stylesheet`'s node union takes `MediaRule<Vars, never>`.\n *\n * Construct via `make`.\n *\n * @since 0.1.0\n */\nexport interface MediaRule<\n out Vars extends Var.Any = Var.Any,\n out Requires extends Requirement = Requirement,\n> extends Pipeable {\n readonly [MediaRuleTypeId]: MediaRuleTypeId\n /**\n * The media query gating the block.\n */\n readonly query: MediaQuery\n /**\n * The rule's block.\n */\n readonly block: RuleSet<Vars, Requires>\n}\n\n/**\n * Checks if a value is a `MediaRule`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `MediaRule`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isMediaRule: (u: unknown) => u is MediaRule<Var.Any> = internal.isMediaRule\n\n/**\n * Creates a `@media` rule.\n *\n * @param query - The media query gating the block.\n * @param block - The rule's block. Declarations make the rule nested-only; a block of closed style rules makes it top-level-capable.\n * @returns A `MediaRule` carrying the block's variable names and requirements.\n * @example\n * ```ts\n * MediaRule.make(\n * MediaQuery.prefersColorScheme('dark'),\n * RuleSet.make(Declaration.make('--scheme', 'dark')),\n * )\n * ```\n * @since 0.1.0\n */\nexport const make: <Vars extends Var.Any, Requires extends Requirement>(\n query: MediaQuery,\n block: RuleSet<Vars, Requires>,\n) => MediaRule<Vars, Requires> = internal.make\n\n/**\n * The rule's unbound variable names — the block's, since a query\n * contributes none.\n *\n * @param rule - The rule to inspect.\n * @returns The set of unbound variable names.\n * @since 0.1.0\n */\nexport const vars: <Vars extends Var.Any>(rule: MediaRule<Vars>) => ReadonlySet<Var.Name<Vars>> =\n internal.refs\n\n/**\n * Options for `render` — the block renderers' shared shape,\n * `RuleSet.RenderOptions`, unchanged.\n *\n * @since 0.1.0\n */\nexport type RenderOptions = RuleSetRenderOptions\n\n/**\n * Renders the rule in nested form: `@media query { ... }`, the body as\n * `RuleSet.render` emits it, one level deeper — declarations directly\n * inside the query block, the shape a media rule takes nested in a\n * style rule (CSSNestedDeclarations). A rule whose block is empty\n * renders as the empty string.\n *\n * Nested style rules render as indented sub-blocks with `&` kept\n * verbatim — native CSS nesting is the output shape.\n *\n * A fragment renderer: whole sheets render via `Stylesheet.render`,\n * which emits each rule's media in this same nested shape.\n *\n * @param rule - The rule to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @example\n * ```ts\n * MediaRule.render(\n * MediaRule.make(MediaQuery.minWidth(768), RuleSet.make(Declaration.make('--gutter', 24))),\n * ) // '@media (min-width: 768px) {\\n\\t--gutter: 24;\\n}'\n * ```\n * @since 0.1.0\n */\nexport const render: (rule: MediaRule<Var.Any>, options?: RenderOptions) => string = internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The rule to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: MediaRule<Var.Any>): (self: MediaRule<Var.Any>) => boolean\n /**\n * Structural equality: queries compare as in `MediaQuery.equals`\n * (canonically ordered features), blocks as in `RuleSet.equals`\n * (members in order).\n *\n * @param self - The first rule.\n * @param that - The second rule.\n * @returns `true` if the rules are structurally equal.\n * @since 0.1.0\n */\n (self: MediaRule<Var.Any>, that: MediaRule<Var.Any>): boolean\n} = internal.equals\n","import type {\n Declaration,\n RenderOptions as DeclarationRenderOptions,\n} from '#declaration/declaration'\nimport type { MediaQuery } from '#query/mediaQuery'\nimport type { Parent, Requirement, Selector } from '#selector/selector'\nimport type { Pipeable } from '#util'\nimport type { Var } from '#var'\nimport type { MediaRule } from './mediaRule.ts'\nimport type { RuleSetTypeId } from './ruleSet.internal.ts'\nimport * as internal from './ruleSet.internal.ts'\nimport type { StyleRule } from './styleRule.ts'\n\n/**\n * An ordered block of rule members — the nesting unit of the rule layer.\n *\n * Member order is preserved exactly as authored: never sorted, never\n * deduplicated. A block's order is cascade behavior, and since\n * CSSNestedDeclarations shipped (late 2024), declarations trailing a\n * nested rule keep their source position rather than hoisting above it —\n * so what you append is what renders.\n *\n * The `Vars` parameter unions the members' unbound variable names, as on\n * `Calc`; `vars` is the runtime set.\n *\n * The `Requires` parameter unions the members' context requirements\n * (`Selector.Requirement`, section 4.4 of `docs/design.md`): `Parent`\n * from every bare declaration and from every nested rule whose selector\n * references `&`. A style rule discharges its block's requirements\n * against its own selector; a block of closed style rules and nothing\n * else is `RuleSet<Vars, never>`, the only form a top-level `@media`\n * block may take.\n *\n * Construct via `make` (or `empty` and `append`).\n *\n * @since 0.1.0\n */\nexport interface RuleSet<\n out Vars extends Var.Any = Var.Any,\n out Requires extends Requirement = Requirement,\n> extends Pipeable {\n readonly [RuleSetTypeId]: RuleSetTypeId\n /**\n * The block's members, in authored order.\n */\n readonly members: ReadonlyArray<Member<Vars, Requires>>\n}\n\n/**\n * The forms a rule block may contain: declarations, nested style rules,\n * and nested `@media` rules. `Requires` bounds the rule arms'\n * requirements; `MemberRequires` computes a member's contribution.\n *\n * Deliberately absent are the declaration-block at-rules (`@font-face`,\n * `@property`) — the CSS grammar keeps them at the top level, so this\n * union keeps them out of blocks at the type level.\n *\n * @since 0.1.0\n */\nexport type Member<Vars extends Var.Any = Var.Any, Requires extends Requirement = Requirement> =\n | Declaration<Vars>\n | StyleRule<Vars, Requires>\n | MediaRule<Vars, Requires>\n\n/**\n * The unbound variable names of a `Member`, or the union of them for a\n * union of members — the type-level counterpart of `vars`, used by the\n * container constructors to thread their members' names into the result.\n *\n * @since 0.1.0\n */\nexport type MemberVars<M extends Member<Var.Any>> =\n M extends Declaration<infer R>\n ? R\n : M extends StyleRule<infer R, Requirement>\n ? R\n : M extends MediaRule<infer R, Requirement>\n ? R\n : never\n\n/**\n * The requirement contribution of a `Member`, or the union of them for a\n * union of members — the type-level counterpart of the containers'\n * `Requires` parameter, used by the constructors to thread member\n * requirements into the result.\n *\n * A bare declaration contributes `Parent`: without a host selector it\n * has no subject. A style rule contributes its selector's requirements —\n * its block's are its own to discharge. A media rule is transparent and\n * contributes its block's.\n *\n * @since 0.4.0\n */\nexport type MemberRequires<M extends Member<Var.Any>> =\n M extends Declaration<Var.Any>\n ? Parent\n : M extends StyleRule<Var.Any, infer R>\n ? R\n : M extends MediaRule<Var.Any, infer R>\n ? R\n : never\n\n/**\n * Checks if a value is a `RuleSet`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `RuleSet`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isRuleSet: (u: unknown) => u is RuleSet<Var.Any> = internal.isRuleSet\n\n/**\n * The empty block — the identity for `concat`.\n *\n * @since 0.1.0\n */\nexport const empty: RuleSet<never, never> = internal.empty\n\n/**\n * Checks if the block has no members.\n *\n * Structural emptiness only: a non-empty block can still *render* as the\n * empty string, when every member is a nested rule whose block renders\n * empty.\n *\n * @param set - The block to inspect.\n * @returns `true` if the block has no members.\n * @since 0.2.0\n */\nexport const isEmpty: (set: RuleSet<Var.Any>) => boolean = internal.isEmpty\n\n/**\n * Creates a rule set holding the given members, in the given order.\n *\n * @param members - Declarations and nested rules, in authored order.\n * @returns A `RuleSet` whose `Vars` unions the members' variable names and whose `Requires` unions their requirement contributions.\n * @example\n * ```ts\n * const block = RuleSet.make(\n * Declaration.make('--depth', Calc.var('depth')),\n * Declaration.make('color', 'oklch(0.7 0.1 250)'),\n * ) // RuleSet<'depth'>\n * ```\n * @since 0.1.0\n */\nexport const make: <Members extends ReadonlyArray<Member<Var.Any>>>(\n ...members: Members\n) => RuleSet<MemberVars<Members[number]>, MemberRequires<Members[number]>> = internal.make\n\nexport const append: {\n /**\n * Returns a function that appends `member` to its argument's block.\n *\n * @param member - The member to append.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <M extends Member<Var.Any>>(\n member: M,\n ): <Vars extends Var.Any, Requires extends Requirement>(\n self: RuleSet<Vars, Requires>,\n ) => RuleSet<Vars | MemberVars<M>, Requires | MemberRequires<M>>\n /**\n * Returns a function that appends the style rule `selector { block }`\n * to its argument's block.\n *\n * @param selector - The nested rule's selector. Must reference `&` by the time an enclosing rule binds the block.\n * @param block - The nested rule's block.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <B extends Var.Any, S extends Requirement>(\n selector: Selector<S>,\n block: RuleSet<B>,\n ): <Vars extends Var.Any, Requires extends Requirement>(\n self: RuleSet<Vars, Requires>,\n ) => RuleSet<Vars | B, Requires | S>\n /**\n * Returns a function that appends the media rule `@media query { block }`\n * to its argument's block.\n *\n * @param query - The nested rule's media query.\n * @param block - The nested rule's block.\n * @returns A function producing the extended block.\n * @since 0.1.0\n */\n <B extends Var.Any, BR extends Requirement>(\n query: MediaQuery,\n block: RuleSet<B, BR>,\n ): <Vars extends Var.Any, Requires extends Requirement>(\n self: RuleSet<Vars, Requires>,\n ) => RuleSet<Vars | B, Requires | BR>\n /**\n * Appends a member at the end of the block. The result is a new set;\n * the original is untouched.\n *\n * @param self - The block to extend.\n * @param member - The member to append.\n * @returns The extended block, with the member's variable names joined in.\n * @example\n * ```ts\n * RuleSet.empty.pipe(\n * RuleSet.append(Declaration.make('color', 'red')),\n * RuleSet.append(Declaration.make('--depth', Calc.var('depth'))),\n * ) // RuleSet<'depth'>\n * ```\n * @since 0.1.0\n */\n <Vars extends Var.Any, Requires extends Requirement, M extends Member<Var.Any>>(\n self: RuleSet<Vars, Requires>,\n member: M,\n ): RuleSet<Vars | MemberVars<M>, Requires | MemberRequires<M>>\n /**\n * Appends a nested style rule from its parts — sugar for\n * `append(self, StyleRule.make(selector, block))`, so blocks compose\n * without naming `StyleRule` at the call site.\n *\n * The nested rule's selector must reference `&` (`Selector.nest`) by\n * the time an enclosing rule binds this block — `StyleRule.make`\n * enforces it there, as the binder.\n *\n * @param self - The block to extend.\n * @param selector - The nested rule's selector.\n * @param block - The nested rule's block.\n * @returns The extended block, with the nested block's variable names joined in.\n * @throws `Error` when a style rule nested in `block` has a selector that does not reference `&`.\n * @example\n * ```ts\n * RuleSet.empty.pipe(\n * RuleSet.append(\n * Selector.and(Selector.nest, Selector.pseudoClass('hover')),\n * RuleSet.make(Declaration.make('color', 'red')),\n * ),\n * )\n * ```\n * @since 0.1.0\n */\n <Vars extends Var.Any, Requires extends Requirement, B extends Var.Any, S extends Requirement>(\n self: RuleSet<Vars, Requires>,\n selector: Selector<S>,\n block: RuleSet<B>,\n ): RuleSet<Vars | B, Requires | S>\n /**\n * Appends a nested media rule from its parts — sugar for\n * `append(self, MediaRule.make(query, block))`, so blocks compose\n * without naming `MediaRule` at the call site.\n *\n * @param self - The block to extend.\n * @param query - The nested rule's media query.\n * @param block - The nested rule's block.\n * @returns The extended block, with the nested block's variable names joined in.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--gutter', 16)).pipe(\n * RuleSet.append(MediaQuery.minWidth(768), RuleSet.make(Declaration.make('--gutter', 24))),\n * )\n * ```\n * @since 0.1.0\n */\n <Vars extends Var.Any, Requires extends Requirement, B extends Var.Any, BR extends Requirement>(\n self: RuleSet<Vars, Requires>,\n query: MediaQuery,\n block: RuleSet<B, BR>,\n ): RuleSet<Vars | B, Requires | BR>\n} = internal.append\n\nexport const concat: {\n /**\n * Returns a function that appends `that`'s members after its argument's.\n *\n * @param that - The block whose members come second.\n * @returns A function producing the concatenated block.\n * @since 0.1.0\n */\n <B extends Var.Any, BR extends Requirement>(\n that: RuleSet<B, BR>,\n ): <A extends Var.Any, AR extends Requirement>(self: RuleSet<A, AR>) => RuleSet<A | B, AR | BR>\n /**\n * Concatenates two blocks: `self`'s members followed by `that`'s, order\n * preserved on both sides. No deduplication happens here — repeated\n * declarations are legal CSS and their repetition is cascade behavior.\n *\n * @param self - The block whose members come first.\n * @param that - The block whose members come second.\n * @returns The concatenated block, with both sides' variable names and requirements unioned.\n * @since 0.1.0\n */\n <A extends Var.Any, AR extends Requirement, B extends Var.Any, BR extends Requirement>(\n self: RuleSet<A, AR>,\n that: RuleSet<B, BR>,\n ): RuleSet<A | B, AR | BR>\n} = internal.concat\n\nexport const forSelector: {\n /**\n * Returns a function that wraps its argument as the block of a style\n * rule applying to `selector`.\n *\n * @param selector - The selector the resulting rule's block applies to.\n * @returns A function that takes a block and returns the style rule applying it to `selector`.\n * @since 0.2.0\n */\n <S extends Requirement>(\n selector: Selector<S>,\n ): <Vars extends Var.Any>(self: RuleSet<Vars>) => StyleRule<Vars, S>\n /**\n * Lifts a block into a style rule applying to `selector` — sugar for\n * `StyleRule.make(selector, self)` with the arguments flipped, so a\n * block built up through `pipe` caps off as a rule without naming\n * `StyleRule` at the call site. The rule carries the block's variable\n * names unchanged; its requirements are the selector's, the block's\n * discharged. The binder check runs here, as in `StyleRule.make`.\n *\n * @param self - The block the rule applies.\n * @param selector - The selector the block applies to.\n * @returns The style rule pairing `selector` with the block.\n * @throws `Error` when a style rule nested in `self` has a selector that does not reference `&`.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--depth', Calc.var('depth'))).pipe(\n * RuleSet.forSelector(Selector.root),\n * ) // StyleRule<'depth'>\n * ```\n * @since 0.2.0\n */\n <Vars extends Var.Any, S extends Requirement>(\n self: RuleSet<Vars>,\n selector: Selector<S>,\n ): StyleRule<Vars, S>\n} = internal.forSelector\n\nexport const forMediaQuery: {\n /**\n * Returns a function that wraps its argument as the block of a nested\n * `@media` rule gated by `query`.\n *\n * @param query - The media query gating the resulting rule's block.\n * @returns A function that takes a block and returns the media rule gating it by `query`.\n * @since 0.2.0\n */\n (\n query: MediaQuery,\n ): <Vars extends Var.Any, Requires extends Requirement>(\n self: RuleSet<Vars, Requires>,\n ) => MediaRule<Vars, Requires>\n /**\n * Lifts a block into a `@media` rule gated by `query` — sugar for\n * `MediaRule.make(query, self)` with the arguments flipped, so a block\n * built up through `pipe` caps off as a rule without naming\n * `MediaRule` at the call site. The rule carries the block's variable\n * names and requirements unchanged; a query contributes neither.\n *\n * @param self - The block the rule gates.\n * @param query - The media query gating the block.\n * @returns The media rule pairing `query` with the block.\n * @example\n * ```ts\n * RuleSet.make(Declaration.make('--gutter', Calc.var('gutter'))).pipe(\n * RuleSet.forMediaQuery(MediaQuery.minWidth(768)),\n * ) // MediaRule<'gutter'>\n * ```\n * @since 0.2.0\n */\n <Vars extends Var.Any, Requires extends Requirement>(\n self: RuleSet<Vars, Requires>,\n query: MediaQuery,\n ): MediaRule<Vars, Requires>\n} = internal.forMediaQuery\n\n/**\n * The block's unbound variable names, unioned across members —\n * including everything nested rules contribute.\n *\n * @param set - The block to inspect.\n * @returns The set of unbound variable names.\n * @since 0.1.0\n */\nexport const vars: <Vars extends Var.Any>(set: RuleSet<Vars>) => ReadonlySet<Var.Name<Vars>> =\n internal.refs\n\n/**\n * Options for `render`, extending `Declaration.RenderOptions` (and\n * through it the family base, `MediaQuery.RenderOptions`) with the\n * indentation unit — the block renderers' shared shape, which\n * `StyleRule.render` and `MediaRule.render` take unchanged.\n *\n * @since 0.1.0\n */\nexport interface RenderOptions extends DeclarationRenderOptions {\n /**\n * The indentation unit, applied once per nesting level. Defaults to a\n * tab.\n */\n readonly indent?: string\n}\n\n/**\n * Renders the block's body — the text between a rule's braces, without\n * the braces: one line per declaration, nested `@media` and style rules\n * as indented sub-blocks (`&` kept verbatim), in member order. Empty\n * blocks (and nested rules whose blocks are empty) render as the empty\n * string.\n *\n * A fragment renderer: use it to compose blocks the model does not\n * represent. Whole sheets render via `Stylesheet.render`, and the binder\n * invariant on nested selectors is `StyleRule.make`'s — a free-standing\n * block renders without it.\n *\n * @param set - The block to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @example\n * ```ts\n * RuleSet.render(RuleSet.make(Declaration.make('--depth', 4), Declaration.make('color', 'red')))\n * // '--depth: 4;\\ncolor: red;'\n * ```\n * @since 0.1.0\n */\nexport const render: (set: RuleSet<Var.Any>, options?: RenderOptions) => string = internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The block to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: RuleSet<Var.Any>): (self: RuleSet<Var.Any>) => boolean\n /**\n * Structural equality over members, in order. Order participates —\n * `make(a, b)` and `make(b, a)` are different blocks, because they\n * cascade differently.\n *\n * @param self - The first block.\n * @param that - The second block.\n * @returns `true` if the blocks are structurally equal.\n * @since 0.1.0\n */\n (self: RuleSet<Var.Any>, that: RuleSet<Var.Any>): boolean\n} = internal.equals\n","import type { Requirement, Selector } from '#selector/selector'\nimport type { Pipeable } from '#util'\nimport type { Var } from '#var'\nimport type { RenderOptions as RuleSetRenderOptions, RuleSet } from './ruleSet.ts'\nimport type { StyleRuleTypeId } from './styleRule.internal.ts'\nimport * as internal from './styleRule.internal.ts'\n\n/**\n * A style rule: a selector and the block it applies.\n *\n * The block is a full `RuleSet`, so a style rule holds declarations,\n * nested style rules, and nested `@media` rules in one authored order.\n * The rule is selector nesting's binder: `&` in a nested rule's selector\n * reads this rule's selector. The `Vars` parameter is the block's — a\n * selector contributes no variable names.\n *\n * `Requires` is the *selector's* requirements, not the block's: the\n * binder discharges everything its block needs, so the rule needs a\n * parent exactly when its own selector references `&`. It defaults to\n * `never` — the closed, top-level form — because that is the form\n * consumer annotations usually name.\n *\n * Construct via `make`.\n *\n * @since 0.1.0\n */\nexport interface StyleRule<\n out Vars extends Var.Any = Var.Any,\n out Requires extends Requirement = never,\n> extends Pipeable {\n readonly [StyleRuleTypeId]: StyleRuleTypeId\n /**\n * The selector the block applies to. References `&` exactly when the\n * rule nests inside another rule's block.\n */\n readonly selector: Selector<Requires>\n /**\n * The rule's block.\n */\n readonly block: RuleSet<Vars>\n}\n\n/**\n * Checks if a value is a `StyleRule`.\n *\n * True only for values built by this module's constructors, which carry\n * the brand.\n *\n * @param u - The value to check.\n * @returns `true` if the value is a `StyleRule`, `false` otherwise.\n * @since 0.1.0\n */\nexport const isStyleRule: (u: unknown) => u is StyleRule<Var.Any, Requirement> =\n internal.isStyleRule\n\n/**\n * Creates a style rule.\n *\n * The binder check runs here: every style rule nested in `block` —\n * directly, or inside its `@media` blocks — must reference `&` in its\n * selector, because this rule's selector is what that `&` reads. CSS\n * would silently prepend a descendant `&` instead; the model rejects\n * the shape rather than rewriting the authored selector.\n *\n * @param selector - The selector the block applies to. References `&` exactly when this rule itself nests.\n * @param block - The rule's block.\n * @returns A `StyleRule` carrying the block's variable names and the selector's requirements.\n * @throws `Error` when a style rule nested in `block` has a selector that does not reference `&`.\n * @example\n * ```ts\n * StyleRule.make(\n * Selector.root,\n * RuleSet.make(Declaration.make('--depth', Calc.var('depth'))),\n * ) // StyleRule<'depth'>\n * ```\n * @since 0.1.0\n */\nexport const make: <Vars extends Var.Any, S extends Requirement>(\n selector: Selector<S>,\n block: RuleSet<Vars>,\n) => StyleRule<Vars, S> = internal.make\n\n/**\n * The rule's unbound variable names — the block's, since a selector\n * contributes none.\n *\n * @param rule - The rule to inspect.\n * @returns The set of unbound variable names.\n * @since 0.1.0\n */\nexport const vars: <Vars extends Var.Any>(\n rule: StyleRule<Vars, Requirement>,\n) => ReadonlySet<Var.Name<Vars>> = internal.refs\n\n/**\n * Options for `render` — the block renderers' shared shape,\n * `RuleSet.RenderOptions`, unchanged.\n *\n * @since 0.1.0\n */\nexport type RenderOptions = RuleSetRenderOptions\n\n/**\n * Renders the rule in nested form: `selector { ... }`, the body as\n * `RuleSet.render` emits it, one level deeper. Nested style rules render\n * as indented sub-blocks with `&` kept verbatim — native CSS nesting is\n * the output shape. A rule whose block is empty renders as the empty\n * string.\n *\n * A fragment renderer: whole sheets render via `Stylesheet.render`,\n * which emits each rule in this same nested shape.\n *\n * @param rule - The rule to render.\n * @param options - Optional indentation unit, precision context, and media syntax.\n * @returns Deterministic CSS text.\n * @example\n * ```ts\n * StyleRule.render(StyleRule.make(Selector.root, RuleSet.make(Declaration.make('--depth', 4))))\n * // ':root {\\n\\t--depth: 4;\\n}'\n * ```\n * @since 0.1.0\n */\nexport const render: (rule: StyleRule<Var.Any, Requirement>, options?: RenderOptions) => string =\n internal.render\n\nexport const equals: {\n /**\n * Returns a function that checks structural equality against `that`.\n *\n * @param that - The rule to compare against.\n * @returns A function testing its argument for structural equality with `that`.\n * @since 0.1.0\n */\n (that: StyleRule<Var.Any, Requirement>): (self: StyleRule<Var.Any, Requirement>) => boolean\n /**\n * Structural equality: selectors compare as in `Selector.equals`\n * (canonically ordered parts), blocks as in `RuleSet.equals` (members\n * in order).\n *\n * @param self - The first rule.\n * @param that - The second rule.\n * @returns `true` if the rules are structurally equal.\n * @since 0.1.0\n */\n (self: StyleRule<Var.Any, Requirement>, that: StyleRule<Var.Any, Requirement>): boolean\n} = internal.equals\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqDA,MAAa,cAAuDA;;;;;;;;;;;;;;;;AAiBpE,MAAaC,SAGoBC;;;;;;;;;AAUjC,MAAaC,SACXC;;;;;;;;;;;;;;;;;;;;;;;;;AAkCF,MAAaC,WAAwEC;AAErF,MAAaC,WAoBTC;;;;;;;;;;;;;;;;;;;;;;;;;;AC5BJ,MAAa,YAAmDC;;;;;;AAOhE,MAAa,QAA+BC;;;;;;;;;;;;AAa5C,MAAa,UAA8CC;;;;;;;;;;;;;;;AAgB3D,MAAaC,SAEgEC;AAE7E,MAAa,SAmHTC;AAEJ,MAAa,SAyBTC;AAEJ,MAAa,cAoCTC;AAEJ,MAAa,gBAoCTC;;;;;;;;;AAUJ,MAAaC,SACXC;;;;;;;;;;;;;;;;;;;;;;;AAwCF,MAAaC,WAAqEC;AAElF,MAAaC,WAoBTC;;;;;;;;;;;;;;;;;;;;ACvYJ,MAAa,cACXC;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,OAGaC;;;;;;;;;AAU1B,MAAa,OAEsBC;;;;;;;;;;;;;;;;;;;;;AA8BnC,MAAa,SACXC;AAEF,MAAa,SAoBTC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as specificity_d_exports, i as selector_d_exports } from "../shared/selector-BkxnzX_6.mjs";
|
|
2
2
|
export { selector_d_exports as Selector, specificity_d_exports as Specificity };
|
package/dist/selector/index.mjs
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import { t as __exportAll } from "../shared/rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { C as universal$1, D as isSpecificity$1, E as equals$3, O as make$1, S as under$1, T as compare$1, _ as render$1, a as descendant$1, b as subsequentSibling$1, c as id$1, f as nest$1, g as pseudoElement$1, h as pseudoClass$1, i as child$1, l as is$1, m as not$1, n as and$1, o as equals$2, p as nextSibling$1, r as attribute$1, s as has$1, t as _class$1, u as isSelector$1, v as root$1, w as where$1, x as type$1, y as specificity$1 } from "../shared/selector.internal-B3iu_RpX.mjs";
|
|
3
3
|
//#region src/selector/selector.ts
|
|
4
4
|
var selector_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
and: () => and,
|
|
6
6
|
attribute: () => attribute,
|
|
7
|
+
child: () => child,
|
|
7
8
|
class: () => _class,
|
|
9
|
+
descendant: () => descendant,
|
|
8
10
|
equals: () => equals$1,
|
|
11
|
+
has: () => has,
|
|
9
12
|
id: () => id,
|
|
13
|
+
is: () => is,
|
|
10
14
|
isSelector: () => isSelector,
|
|
15
|
+
nest: () => nest,
|
|
16
|
+
nextSibling: () => nextSibling,
|
|
11
17
|
not: () => not,
|
|
12
18
|
pseudoClass: () => pseudoClass,
|
|
13
19
|
pseudoElement: () => pseudoElement,
|
|
14
20
|
render: () => render,
|
|
15
21
|
root: () => root,
|
|
16
22
|
specificity: () => specificity,
|
|
23
|
+
subsequentSibling: () => subsequentSibling,
|
|
17
24
|
type: () => type,
|
|
18
|
-
|
|
25
|
+
under: () => under,
|
|
26
|
+
universal: () => universal,
|
|
27
|
+
where: () => where
|
|
19
28
|
});
|
|
20
29
|
/**
|
|
21
30
|
* Checks if a value is a `Selector`.
|
|
22
31
|
*
|
|
23
32
|
* True only for values built by this module's constructors, which carry
|
|
24
|
-
* the brand.
|
|
33
|
+
* the brand. The guard widens to `Selector<Requirement>` — it proves the
|
|
34
|
+
* brand, not closedness.
|
|
25
35
|
*
|
|
26
36
|
* @param u - The value to check.
|
|
27
37
|
* @returns `true` if the value is a `Selector`, `false` otherwise.
|
|
@@ -35,6 +45,23 @@ const isSelector = isSelector$1;
|
|
|
35
45
|
*/
|
|
36
46
|
const universal = universal$1;
|
|
37
47
|
/**
|
|
48
|
+
* The nesting selector, `&` — a reference to the enclosing rule's
|
|
49
|
+
* selector, usable anywhere a simple selector is: merged into a compound
|
|
50
|
+
* (`&.active`), under a combinator (`& *`), or inside a selector list
|
|
51
|
+
* (`:is(&, & *)`).
|
|
52
|
+
*
|
|
53
|
+
* Carrying it marks the selector `Parent`-requiring: nested style rules
|
|
54
|
+
* must reference it, and top-level positions reject it. Its specificity
|
|
55
|
+
* is the parent selector's, so `specificity` refuses it unresolved —
|
|
56
|
+
* substitute the parent with `under` first.
|
|
57
|
+
*
|
|
58
|
+
* In a compound it sorts just after the type slot: a type selector must
|
|
59
|
+
* come first even beside `&` (`div&`, never `&div`).
|
|
60
|
+
*
|
|
61
|
+
* @since 0.4.0
|
|
62
|
+
*/
|
|
63
|
+
const nest = nest$1;
|
|
64
|
+
/**
|
|
38
65
|
* Creates a type (element) selector, such as `div`.
|
|
39
66
|
*
|
|
40
67
|
* A compound may contain at most one type or universal selector; `and`
|
|
@@ -69,8 +96,8 @@ const _class = _class$1;
|
|
|
69
96
|
/**
|
|
70
97
|
* Creates a pseudo-class selector, rendered `:name`.
|
|
71
98
|
*
|
|
72
|
-
* For the functional
|
|
73
|
-
* typed selector
|
|
99
|
+
* For the functional pseudo-classes over selector lists, use `is`,
|
|
100
|
+
* `where`, `has`, or `not`, which take typed selector arguments.
|
|
74
101
|
*
|
|
75
102
|
* @param name - The pseudo-class name, without the `:` prefix. Must be non-empty.
|
|
76
103
|
* @returns A one-part `Selector`.
|
|
@@ -80,19 +107,76 @@ const _class = _class$1;
|
|
|
80
107
|
const pseudoClass = pseudoClass$1;
|
|
81
108
|
const attribute = attribute$1;
|
|
82
109
|
/**
|
|
83
|
-
* Creates a
|
|
84
|
-
*
|
|
85
|
-
*
|
|
110
|
+
* Creates a matches-any pseudo-class, rendered `:is(a, b, ...)`. The
|
|
111
|
+
* arguments form a selector list — compound or complex alike — and the
|
|
112
|
+
* part matches an element matching any of them.
|
|
86
113
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
114
|
+
* The list canonically sorts (matching is order-independent), so
|
|
115
|
+
* `is(a, b)` equals `is(b, a)`. The part's specificity is its most
|
|
116
|
+
* specific argument's. Requirements union across arguments — an `&`
|
|
117
|
+
* inside the list marks the whole selector `Parent`-requiring.
|
|
118
|
+
*
|
|
119
|
+
* @param selectors - The selector list. At least one.
|
|
120
|
+
* @returns A one-part `Selector` carrying the arguments' requirements.
|
|
121
|
+
* @throws `Error` when called with no arguments.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* Selector.render(Selector.is(Selector.nest, Selector.descendant(Selector.nest, Selector.universal)))
|
|
125
|
+
* // ':is(&, & *)'
|
|
126
|
+
* ```
|
|
127
|
+
* @since 0.4.0
|
|
128
|
+
*/
|
|
129
|
+
const is = is$1;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a zero-specificity matches-any pseudo-class, rendered
|
|
132
|
+
* `:where(a, b, ...)`. Matching is identical to `is`; the part
|
|
133
|
+
* contributes nothing to specificity regardless of its arguments.
|
|
134
|
+
*
|
|
135
|
+
* The list canonically sorts, and requirements union across arguments.
|
|
136
|
+
*
|
|
137
|
+
* @param selectors - The selector list. At least one.
|
|
138
|
+
* @returns A one-part `Selector` carrying the arguments' requirements.
|
|
139
|
+
* @throws `Error` when called with no arguments.
|
|
140
|
+
* @since 0.4.0
|
|
141
|
+
*/
|
|
142
|
+
const where = where$1;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a relational pseudo-class, rendered `:has(a, b, ...)`: the
|
|
145
|
+
* part matches an element whose subtree contains a match for any
|
|
146
|
+
* argument.
|
|
147
|
+
*
|
|
148
|
+
* Arguments are ordinary selectors — the relative forms with a leading
|
|
149
|
+
* combinator (`:has(> .x)`) are not modeled. The list canonically
|
|
150
|
+
* sorts, the part's specificity is its most specific argument's, and
|
|
151
|
+
* requirements union across arguments.
|
|
152
|
+
*
|
|
153
|
+
* @param selectors - The selector list. At least one.
|
|
154
|
+
* @returns A one-part `Selector` carrying the arguments' requirements.
|
|
155
|
+
* @throws `Error` when called with no arguments.
|
|
156
|
+
* @since 0.4.0
|
|
157
|
+
*/
|
|
158
|
+
const has = has$1;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a functional negation, rendered `:not(a, b, ...)`. The
|
|
161
|
+
* arguments form a selector list; the part matches an element matching
|
|
162
|
+
* none of them.
|
|
163
|
+
*
|
|
164
|
+
* The list canonically sorts, the part's specificity is its most
|
|
165
|
+
* specific argument's (`:not` itself contributes none), and
|
|
166
|
+
* requirements union across arguments.
|
|
167
|
+
*
|
|
168
|
+
* @param selectors - The selector list to negate. At least one.
|
|
169
|
+
* @returns A one-part `Selector` carrying the arguments' requirements.
|
|
170
|
+
* @throws `Error` when called with no arguments.
|
|
89
171
|
* @since 0.1.0
|
|
90
172
|
*/
|
|
91
173
|
const not = not$1;
|
|
92
174
|
/**
|
|
93
175
|
* Creates a pseudo-element selector, rendered `::name`.
|
|
94
176
|
*
|
|
95
|
-
* A compound may contain at most one pseudo-element; `and` enforces
|
|
177
|
+
* A compound may contain at most one pseudo-element; `and` enforces
|
|
178
|
+
* this. No combinator may follow one — the combinator constructors
|
|
179
|
+
* enforce that.
|
|
96
180
|
*
|
|
97
181
|
* @param name - The pseudo-element name, without the `::` prefix. Must be non-empty.
|
|
98
182
|
* @returns A one-part `Selector`.
|
|
@@ -108,26 +192,38 @@ const pseudoElement = pseudoElement$1;
|
|
|
108
192
|
*/
|
|
109
193
|
const root = root$1;
|
|
110
194
|
const and = and$1;
|
|
195
|
+
const descendant = descendant$1;
|
|
196
|
+
const child = child$1;
|
|
197
|
+
const nextSibling = nextSibling$1;
|
|
198
|
+
const subsequentSibling = subsequentSibling$1;
|
|
199
|
+
const under = under$1;
|
|
111
200
|
/**
|
|
112
|
-
* Computes the selector's specificity: ids into `a`;
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
201
|
+
* Computes the selector's specificity: ids into `a`; classes,
|
|
202
|
+
* attributes, and pseudo-classes into `b`; types and pseudo-elements
|
|
203
|
+
* into `c`. Compounds in a complex selector sum. `:is()`, `:has()`, and
|
|
204
|
+
* `:not()` add their most specific argument; `:where()` and the
|
|
205
|
+
* universal selector add nothing; duplicate parts count each time.
|
|
206
|
+
*
|
|
207
|
+
* Closed selectors only: an `&`-bearing selector takes its specificity
|
|
208
|
+
* from the parent rule, so the parameter rejects `Parent`-requiring
|
|
209
|
+
* selectors at compile time — resolve them with `under` first.
|
|
116
210
|
*
|
|
117
211
|
* This is what lets a consumer turn "these rules tie, so their order
|
|
118
212
|
* encodes the override direction" into something checkable.
|
|
119
213
|
*
|
|
120
|
-
* @param selector - The selector to measure.
|
|
214
|
+
* @param selector - The selector to measure. Must be closed (no `&`).
|
|
121
215
|
* @returns The computed `Specificity`.
|
|
122
216
|
* @since 0.1.0
|
|
123
217
|
*/
|
|
124
218
|
const specificity = specificity$1;
|
|
125
219
|
/**
|
|
126
|
-
* Renders the selector as CSS text: parts concatenated
|
|
127
|
-
* order — type first, then ids, classes,
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
220
|
+
* Renders the selector as CSS text: each compound's parts concatenated
|
|
221
|
+
* in canonical order — type first, then `&`, ids, classes,
|
|
222
|
+
* pseudo-classes, attributes, functional pseudo-classes, and the
|
|
223
|
+
* pseudo-element last, alphabetically within each kind — and compounds
|
|
224
|
+
* joined by their combinators in authored order. Any fixed part order
|
|
225
|
+
* matches identically; this one keeps root-scoped shapes in their
|
|
226
|
+
* conventional spelling.
|
|
131
227
|
*
|
|
132
228
|
* @param selector - The selector to render.
|
|
133
229
|
* @returns Deterministic CSS text.
|