@teacss/classes 0.10.13 → 0.10.14
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/cache.js +0 -2
- package/dist/generated/merge-policy.js +0 -3
- package/dist/merge.d.ts +0 -1
- package/dist/merge.js +1 -22
- package/dist/recipe.js +0 -10
- package/dist/syntax/group.d.ts +0 -15
- package/dist/syntax/group.js +0 -23
- package/dist/syntax/literal.js +0 -9
- package/dist/syntax/token.d.ts +0 -26
- package/dist/syntax/token.js +0 -38
- package/package.json +1 -1
package/dist/cache.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Private FIFO caches: hits do not rewrite insertion order. */
|
|
2
1
|
import { setOwnArrayIndex } from "./input.js";
|
|
3
2
|
export class StringCache {
|
|
4
3
|
max;
|
|
@@ -62,7 +61,6 @@ export class TupleCache {
|
|
|
62
61
|
bytes += args[index].length * 2;
|
|
63
62
|
if (bytes > 65536)
|
|
64
63
|
return;
|
|
65
|
-
// Only successful misses enter here; an existing arity terminal is not rewritten.
|
|
66
64
|
if (this.get(args) !== undefined)
|
|
67
65
|
return;
|
|
68
66
|
while (this.entries.size >= 64 || this.bytes + bytes > 65536) {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// Generated by packages/classes/scripts/gen-merge-policy.mjs from crates/teacss-engine/tests/snapshots/main__merge_policy__policy.snap. Do not edit.
|
|
2
|
-
// E: same importance, later deletes earlier. I: important deletes ordinary.
|
|
3
|
-
// Every descriptor's self edge is implicit. Row zero is empty.
|
|
4
1
|
function numbers(value) {
|
|
5
2
|
return value ? value.split(",").map((item) => Number.parseInt(item, 36)) : [];
|
|
6
3
|
}
|
package/dist/merge.d.ts
CHANGED
package/dist/merge.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Fixed declaration policy and Official numbered typography grouping. */
|
|
2
1
|
import { StringCache, TupleCache } from "./cache.js";
|
|
3
2
|
import { equalRows, finalizerFlags, importantRows, prefixes, rows, typographyNames } from "./generated/merge-policy.js";
|
|
4
3
|
import { appendOwnArrayValue, normalizeInput, toClassString } from "./input.js";
|
|
@@ -31,7 +30,7 @@ for (let group = 0; group < dimensionFamilies.length; group++) {
|
|
|
31
30
|
const unsafeFragment = /[{}[\]()\\'"\x60]|\/\*/;
|
|
32
31
|
const namedLanguage = /^!?lang-[a-zA-Z]+(?:-[a-zA-Z0-9]+)*$/;
|
|
33
32
|
const stateCount = prefixes.length * 2;
|
|
34
|
-
const MAX_SCRATCH = 4096;
|
|
33
|
+
const MAX_SCRATCH = 4096;
|
|
35
34
|
function tokenWeight(key, token) {
|
|
36
35
|
return 2 * (key.length + token.raw.length + token.condition.length + token.identity.length);
|
|
37
36
|
}
|
|
@@ -109,7 +108,6 @@ export function conditionRoles(condition) {
|
|
|
109
108
|
return PREFIX;
|
|
110
109
|
if (targetGuards.has(value))
|
|
111
110
|
return COMBINATOR;
|
|
112
|
-
// Media features, at-rules, containers and breakpoints, including configured names.
|
|
113
111
|
return PARENT;
|
|
114
112
|
}
|
|
115
113
|
function conditionKey(conditions) {
|
|
@@ -117,9 +115,6 @@ function conditionKey(conditions) {
|
|
|
117
115
|
return "";
|
|
118
116
|
if (conditions.length === 1)
|
|
119
117
|
return "\0" + conditionIdentity(conditions[0]);
|
|
120
|
-
// The engine assembles each role in authored order, so only the order across roles is free,
|
|
121
|
-
// and the order within a run of target guards: they all land on the same compound as
|
|
122
|
-
// `:is(X, X *)`, which commute, while a combinator between them moves the later ones.
|
|
123
118
|
const identities = conditions.map(conditionIdentity);
|
|
124
119
|
const roles = conditions.map(conditionRoles);
|
|
125
120
|
const guards = [];
|
|
@@ -143,7 +138,6 @@ function conditionKey(conditions) {
|
|
|
143
138
|
return key;
|
|
144
139
|
}
|
|
145
140
|
function conditionIdentity(condition) {
|
|
146
|
-
// Only named language tags are case-insensitive; preserve selector text and order.
|
|
147
141
|
return namedLanguage.test(condition) ? condition.toLowerCase() : condition;
|
|
148
142
|
}
|
|
149
143
|
function classify(raw) {
|
|
@@ -155,8 +149,6 @@ function classify(raw) {
|
|
|
155
149
|
id,
|
|
156
150
|
important: +important,
|
|
157
151
|
condition: conditionKey(conditions),
|
|
158
|
-
// This fixed keyword group replaces all three typography metrics. Other
|
|
159
|
-
// shortcuts keep their own identity; their declarations are never expanded.
|
|
160
152
|
identity: keyword ? (typographyNames.has(prefix) ? "t" : "k" + prefix) : id < 0 ? "d" + prefix : "",
|
|
161
153
|
family: id >= 0 ? finalizerFlags[id] : 0,
|
|
162
154
|
};
|
|
@@ -175,8 +167,6 @@ export function createRuntime(options = {}) {
|
|
|
175
167
|
const cached = persistent ? descriptors?.get(raw) : undefined;
|
|
176
168
|
if (cached !== undefined)
|
|
177
169
|
return cached;
|
|
178
|
-
// A short slice must not pin its entire class-list parent in a persistent cache.
|
|
179
|
-
// Splitting UTF-16 units and joining detaches storage without changing lone surrogates.
|
|
180
170
|
const owned = persistent && descriptors ? raw.split("").join("") : raw;
|
|
181
171
|
const token = classify(owned);
|
|
182
172
|
if (persistent)
|
|
@@ -200,8 +190,6 @@ export function createRuntime(options = {}) {
|
|
|
200
190
|
const work = active || size > MAX_SCRATCH ? createScratch(size) : scratch;
|
|
201
191
|
const previousActive = active;
|
|
202
192
|
active = true;
|
|
203
|
-
// Large and reentrant calls already have exact capacity; only shared
|
|
204
|
-
// scratch grows here, with size bounded by the power-of-two MAX_SCRATCH.
|
|
205
193
|
if (work.dropped.length < size)
|
|
206
194
|
work.dropped = new Uint8Array(2 ** Math.ceil(Math.log2(size)));
|
|
207
195
|
const dropped = work.dropped;
|
|
@@ -215,9 +203,7 @@ export function createRuntime(options = {}) {
|
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
205
|
function bucket(indices) {
|
|
218
|
-
// Callers already exclude empty and single-token buckets.
|
|
219
206
|
const length = indices?.length ?? size;
|
|
220
|
-
// A two-item bucket needs only one compiled verdict and no sequence workspace.
|
|
221
207
|
if (length === 2) {
|
|
222
208
|
const first = indices ? indices[0] : 0;
|
|
223
209
|
const second = indices ? indices[1] : 1;
|
|
@@ -239,7 +225,6 @@ export function createRuntime(options = {}) {
|
|
|
239
225
|
}
|
|
240
226
|
const components = new Uint8Array(5);
|
|
241
227
|
const barriers = new Int32Array(5).fill(-1);
|
|
242
|
-
// Finalizers observe the original sequence, before any pair deletion.
|
|
243
228
|
for (let position = length - 1; position >= 0; position--) {
|
|
244
229
|
const index = indices ? indices[position] : position;
|
|
245
230
|
const token = tokens[index];
|
|
@@ -273,7 +258,6 @@ export function createRuntime(options = {}) {
|
|
|
273
258
|
}
|
|
274
259
|
}
|
|
275
260
|
const { blocked, expanded } = work;
|
|
276
|
-
// An earlier important token may delete a later ordinary token.
|
|
277
261
|
let epoch = nextEpoch(work);
|
|
278
262
|
for (let position = 0; position < length; position++) {
|
|
279
263
|
const index = indices ? indices[position] : position;
|
|
@@ -292,7 +276,6 @@ export function createRuntime(options = {}) {
|
|
|
292
276
|
expanded[token.id] = epoch;
|
|
293
277
|
}
|
|
294
278
|
}
|
|
295
|
-
// Later equal-importance tokens and important tokens delete earlier items.
|
|
296
279
|
epoch = nextEpoch(work);
|
|
297
280
|
for (let position = length - 1; position >= 0; position--) {
|
|
298
281
|
const index = indices ? indices[position] : position;
|
|
@@ -314,11 +297,8 @@ export function createRuntime(options = {}) {
|
|
|
314
297
|
for (let edge = 0; edge < strong.length; edge++)
|
|
315
298
|
blocked[strong[edge] * 2] = epoch;
|
|
316
299
|
}
|
|
317
|
-
// Pair-deleted tokens still contribute their full adjacency row.
|
|
318
300
|
expanded[state] = epoch;
|
|
319
301
|
}
|
|
320
|
-
// A combined sizing token survives a single-axis override. Remove it
|
|
321
|
-
// only when the two axes have independent winning declarations.
|
|
322
302
|
let hasCombination = false;
|
|
323
303
|
for (let position = 0; position < length; position++) {
|
|
324
304
|
const index = indices ? indices[position] : position;
|
|
@@ -382,7 +362,6 @@ export function createRuntime(options = {}) {
|
|
|
382
362
|
function parse(input) {
|
|
383
363
|
const raws = splitClassTokens(expandClassGroups(input).trim());
|
|
384
364
|
const tokens = [];
|
|
385
|
-
// Bypass persistent substring caching when the parent input can exceed the budget.
|
|
386
365
|
const persistent = input.length * 2 <= 524288;
|
|
387
366
|
for (let index = 0; index < raws.length; index++)
|
|
388
367
|
appendOwnArrayValue(tokens, read(raws[index], persistent));
|
package/dist/recipe.js
CHANGED
|
@@ -92,8 +92,6 @@ function appendFragment(target, index, fragment) {
|
|
|
92
92
|
target[index] = existing === undefined ? [fragment] : [...existing, fragment];
|
|
93
93
|
}
|
|
94
94
|
function createDenseSlots(length) {
|
|
95
|
-
// Own elements at every index, like Array.from, without its per-slot
|
|
96
|
-
// callback; the `in` check keeps density under Array.prototype pollution.
|
|
97
95
|
const slots = new Array(length);
|
|
98
96
|
for (let index = 0; index < length; index++) {
|
|
99
97
|
if (index in slots) {
|
|
@@ -108,7 +106,6 @@ function createDenseSlots(length) {
|
|
|
108
106
|
function createInlineBuffer() {
|
|
109
107
|
return [undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined];
|
|
110
108
|
}
|
|
111
|
-
// Own slots keep the measured common path fast; larger vectors fall back to explicit own-property creation.
|
|
112
109
|
const INLINE_BUFFER_CAPACITY = /* @__PURE__ */ createInlineBuffer().length;
|
|
113
110
|
function setBufferedArrayIndex(target, index, value) {
|
|
114
111
|
if (index < INLINE_BUFFER_CAPACITY || !(index in target)) {
|
|
@@ -530,10 +527,6 @@ function resolveSlotStyle(plan, slotIndex, captured, props, propsBoundary, merge
|
|
|
530
527
|
inputs.length = inputCount;
|
|
531
528
|
return merge(inputs, callerClassName);
|
|
532
529
|
}
|
|
533
|
-
// The snapshot objects keep `Object.prototype` so the public
|
|
534
|
-
// `Readonly<Record<…>>` typing holds (`hasOwnProperty` etc. work); axis names
|
|
535
|
-
// that collide with prototype members — including `__proto__` — are written
|
|
536
|
-
// with `defineProperty`, which creates own data properties unconditionally.
|
|
537
530
|
function setIntrospectionField(target, key, value) {
|
|
538
531
|
Object.defineProperty(target, key, { value, configurable: true, enumerable: true, writable: true });
|
|
539
532
|
}
|
|
@@ -573,8 +566,6 @@ function createRecipe(plan, merge) {
|
|
|
573
566
|
writable: false,
|
|
574
567
|
});
|
|
575
568
|
}
|
|
576
|
-
// Source-only construction supports cache-isolated correctness and benchmark adapters.
|
|
577
|
-
// The public entry exports the singleton below; it never exposes this factory.
|
|
578
569
|
export function createRecipeRuntime(runtime) {
|
|
579
570
|
const registry = new WeakMap();
|
|
580
571
|
return ((definition) => {
|
|
@@ -584,7 +575,6 @@ export function createRecipeRuntime(runtime) {
|
|
|
584
575
|
return result;
|
|
585
576
|
});
|
|
586
577
|
}
|
|
587
|
-
// Ownership follows the physical classes module, including facade re-exports.
|
|
588
578
|
const registry = new WeakMap();
|
|
589
579
|
export const recipe = ((definition) => {
|
|
590
580
|
const plan = compileDefinition(definition, registry, prepareFragment);
|
package/dist/syntax/group.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Grouping `{decl;decl;…}@cond`.
|
|
3
|
-
*
|
|
4
|
-
* A pure, textual expansion run before the whitespace split: a `{ }` group is
|
|
5
|
-
* local DRY sugar that expands to individual atomic tokens and itself emits no
|
|
6
|
-
* CSS. Declarations inside are `;`-separated; any `@cond` immediately following
|
|
7
|
-
* the closing `}` is distributed to every declaration.
|
|
8
|
-
*
|
|
9
|
-
* {bg:red;c:white;p:4}@hover → bg:red@hover c:white@hover p:4@hover
|
|
10
|
-
* {bg:red;c:white} → bg:red c:white
|
|
11
|
-
*
|
|
12
|
-
* `()` and `[]` inside the group are literal regions: `;`, `}`, `@` inside
|
|
13
|
-
* them do not terminate the group or a declaration. Text outside groups is kept
|
|
14
|
-
* verbatim, so this is safe to run over whole source strings.
|
|
15
|
-
*/
|
|
16
1
|
/**
|
|
17
2
|
* A group body may hold another group. One pass expands the inner one and
|
|
18
3
|
* leaves the outer `{` in place, because a `{` inside a body ends the candidate
|
package/dist/syntax/group.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
// Ported from teacss-ts `packages-engine/core/src/group.ts` (0.10.1). Only `expandClassGroups` and what it reaches are kept.
|
|
2
|
-
/**
|
|
3
|
-
* Grouping `{decl;decl;…}@cond`.
|
|
4
|
-
*
|
|
5
|
-
* A pure, textual expansion run before the whitespace split: a `{ }` group is
|
|
6
|
-
* local DRY sugar that expands to individual atomic tokens and itself emits no
|
|
7
|
-
* CSS. Declarations inside are `;`-separated; any `@cond` immediately following
|
|
8
|
-
* the closing `}` is distributed to every declaration.
|
|
9
|
-
*
|
|
10
|
-
* {bg:red;c:white;p:4}@hover → bg:red@hover c:white@hover p:4@hover
|
|
11
|
-
* {bg:red;c:white} → bg:red c:white
|
|
12
|
-
*
|
|
13
|
-
* `()` and `[]` inside the group are literal regions: `;`, `}`, `@` inside
|
|
14
|
-
* them do not terminate the group or a declaration. Text outside groups is kept
|
|
15
|
-
* verbatim, so this is safe to run over whole source strings.
|
|
16
|
-
*/
|
|
17
1
|
import { defineArrayAppend as appendOwn, attachedBracketRanges } from "./literal.js";
|
|
18
|
-
/** Consume CSS escapes, or delimiter/string characters protected inside `()` / `[]`. */
|
|
19
2
|
function consumeLiteral(code, index, state) {
|
|
20
3
|
const ch = code[index];
|
|
21
4
|
if (state.blockComment) {
|
|
@@ -51,7 +34,6 @@ function consumeLiteral(code, index, state) {
|
|
|
51
34
|
return index;
|
|
52
35
|
}
|
|
53
36
|
}
|
|
54
|
-
/** Find the next group boundary, respecting `()`/`[]` literal regions. */
|
|
55
37
|
function findClassGroupBoundary(code, open, limit = code.length) {
|
|
56
38
|
const state = { closers: [] };
|
|
57
39
|
for (let i = open + 1; i < limit; i++) {
|
|
@@ -75,11 +57,9 @@ function isTrailingConditionBoundary(code, index) {
|
|
|
75
57
|
const ch = code[index];
|
|
76
58
|
return trailingConditionBoundaryRE.test(ch) || (ch === "/" && (code[index + 1] === "/" || code[index + 1] === "*"));
|
|
77
59
|
}
|
|
78
|
-
/** A `!` right after a group's `}` and before its conditions makes every member important. */
|
|
79
60
|
function isGroupImportance(code, from) {
|
|
80
61
|
return code[from] === "!" && (from + 1 === code.length || code[from + 1] === "@" || isTrailingConditionBoundary(code, from + 1));
|
|
81
62
|
}
|
|
82
|
-
/** The member with `!` before its own conditions, as `p:4@md` becomes `p:4!@md`. */
|
|
83
63
|
function importantMember(member) {
|
|
84
64
|
const state = { closers: [] };
|
|
85
65
|
let index = 0;
|
|
@@ -96,7 +76,6 @@ function importantMember(member) {
|
|
|
96
76
|
const declaration = member.slice(0, declarationEnd);
|
|
97
77
|
return `${declaration}${declaration.endsWith("!") ? "" : "!"}${member.slice(declarationEnd)}`;
|
|
98
78
|
}
|
|
99
|
-
/** Read the `@cond` run immediately after `}`, stopping at a host boundary. */
|
|
100
79
|
function readTrailingConditions(code, from, limit = code.length) {
|
|
101
80
|
if (code[from] !== "@")
|
|
102
81
|
return { conds: "", end: from };
|
|
@@ -116,7 +95,6 @@ function readTrailingConditions(code, from, limit = code.length) {
|
|
|
116
95
|
}
|
|
117
96
|
return { conds: code.slice(from, i), end: i };
|
|
118
97
|
}
|
|
119
|
-
/** Keep host classification semicolon-only; expansion also splits settled inner members. */
|
|
120
98
|
function splitDeclarations(body, includeWhitespace = false) {
|
|
121
99
|
const out = [];
|
|
122
100
|
const state = { closers: [] };
|
|
@@ -227,7 +205,6 @@ function attachedClassFunctionRanges(code) {
|
|
|
227
205
|
export function expandClassGroups(code) {
|
|
228
206
|
const nesting = { seen: false };
|
|
229
207
|
let expanded = expandClassGroupPass(code, nesting);
|
|
230
|
-
// Each pass re-reads the attached literals, so a nested group settles here.
|
|
231
208
|
for (let depth = 1; depth < MAX_GROUP_NESTING && nesting.seen; depth++) {
|
|
232
209
|
nesting.seen = false;
|
|
233
210
|
const next = expandClassGroupPass(expanded, nesting);
|
package/dist/syntax/literal.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
// Ported from teacss-ts `packages-engine/core/src/literal.ts`, `literal-internal.ts` and `array-internal.ts` (0.10.1).
|
|
2
|
-
// Only `splitClassTokens` and the helpers `token.ts` and `group.ts` reach are kept.
|
|
3
1
|
export function appendOwnArrayValue(target, value) {
|
|
4
2
|
const index = target.length;
|
|
5
|
-
// Own index properties always sit below `length`, so `in` here can only see the
|
|
6
|
-
// prototype chain. A clean chain lets plain assignment create the identical own
|
|
7
|
-
// data property; only a polluted one needs the define path, which never consults
|
|
8
|
-
// prototype accessors.
|
|
9
3
|
if (index in target) {
|
|
10
4
|
Object.defineProperty(target, index, {
|
|
11
5
|
configurable: true,
|
|
@@ -37,9 +31,6 @@ export function attachedBracketRanges(input) {
|
|
|
37
31
|
outerQuote = undefined;
|
|
38
32
|
}
|
|
39
33
|
else if (char === '"' || char === "'") {
|
|
40
|
-
// Quotes remain ordinary token characters. Track them only to avoid
|
|
41
|
-
// treating bracket-shaped text inside one whitespace token as a
|
|
42
|
-
// literal range.
|
|
43
34
|
outerQuote = outerQuote === char ? undefined : (outerQuote ?? char);
|
|
44
35
|
}
|
|
45
36
|
else if (!outerQuote && char === "[") {
|
package/dist/syntax/token.d.ts
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token parsing primitives.
|
|
3
|
-
*
|
|
4
|
-
* Splits a single TeaCSS class token into its stable structural parts so every
|
|
5
|
-
* later stage (the `@` condition axis, escaping, rules) can build on one source
|
|
6
|
-
* of truth. This module is pure structure: it does not resolve rules, variants,
|
|
7
|
-
* or CSS. The current token shape is documented in
|
|
8
|
-
* `docs/proposals/v00-teacss.md`.
|
|
9
|
-
*
|
|
10
|
-
* Token shape:
|
|
11
|
-
*
|
|
12
|
-
* ```txt
|
|
13
|
-
* (property:value | keyword)[!](@cond)*
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* - A declaration is either `property:value` (split on the first depth-0 `:`) or
|
|
17
|
-
* a bare keyword (no depth-0 `:`, e.g. `relative`, `sticky`, `text-truncate`).
|
|
18
|
-
* - `()` and `[]` are literal regions; operators inside them (`:` `!` `@` …) do
|
|
19
|
-
* not participate in parsing.
|
|
20
|
-
* - `!` immediately after the value (before any `@`) is `!important`.
|
|
21
|
-
* - The declaration ends at the first depth-0 `@` or the token's end. Only a
|
|
22
|
-
* trailing depth-0 `!` is stripped; other bangs remain for later validation.
|
|
23
|
-
* - Zero or more `@cond` segments follow; each is captured verbatim (without its
|
|
24
|
-
* leading `@`). Interpreting a condition (pseudo / target / media / NOT `!…` …)
|
|
25
|
-
* belongs to the condition pipeline.
|
|
26
|
-
*/
|
|
27
1
|
export interface ParsedClassToken {
|
|
28
2
|
/** The full original token, unchanged. */
|
|
29
3
|
raw: string;
|
package/dist/syntax/token.js
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
// Ported from teacss-ts `packages-engine/core/src/token.ts` (0.10.1).
|
|
2
|
-
/**
|
|
3
|
-
* Token parsing primitives.
|
|
4
|
-
*
|
|
5
|
-
* Splits a single TeaCSS class token into its stable structural parts so every
|
|
6
|
-
* later stage (the `@` condition axis, escaping, rules) can build on one source
|
|
7
|
-
* of truth. This module is pure structure: it does not resolve rules, variants,
|
|
8
|
-
* or CSS. The current token shape is documented in
|
|
9
|
-
* `docs/proposals/v00-teacss.md`.
|
|
10
|
-
*
|
|
11
|
-
* Token shape:
|
|
12
|
-
*
|
|
13
|
-
* ```txt
|
|
14
|
-
* (property:value | keyword)[!](@cond)*
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* - A declaration is either `property:value` (split on the first depth-0 `:`) or
|
|
18
|
-
* a bare keyword (no depth-0 `:`, e.g. `relative`, `sticky`, `text-truncate`).
|
|
19
|
-
* - `()` and `[]` are literal regions; operators inside them (`:` `!` `@` …) do
|
|
20
|
-
* not participate in parsing.
|
|
21
|
-
* - `!` immediately after the value (before any `@`) is `!important`.
|
|
22
|
-
* - The declaration ends at the first depth-0 `@` or the token's end. Only a
|
|
23
|
-
* trailing depth-0 `!` is stripped; other bangs remain for later validation.
|
|
24
|
-
* - Zero or more `@cond` segments follow; each is captured verbatim (without its
|
|
25
|
-
* leading `@`). Interpreting a condition (pseudo / target / media / NOT `!…` …)
|
|
26
|
-
* belongs to the condition pipeline.
|
|
27
|
-
*/
|
|
28
1
|
import { appendOwnArrayValue } from "./literal.js";
|
|
29
2
|
/**
|
|
30
3
|
* Parse a single class token into its structural parts.
|
|
@@ -34,8 +7,6 @@ import { appendOwnArrayValue } from "./literal.js";
|
|
|
34
7
|
* left to the rule layer.
|
|
35
8
|
*/
|
|
36
9
|
export function parseClassToken(raw) {
|
|
37
|
-
// Single left-to-right scan tracking literal-region depth, recording the first
|
|
38
|
-
// depth-0 `:` (declaration split) and every depth-0 `@` (condition boundaries).
|
|
39
10
|
let closers = "";
|
|
40
11
|
let quote;
|
|
41
12
|
let firstColon = -1;
|
|
@@ -51,7 +22,6 @@ export function parseClassToken(raw) {
|
|
|
51
22
|
quote = undefined;
|
|
52
23
|
continue;
|
|
53
24
|
}
|
|
54
|
-
// Conditions carry CSS selectors, whose escapes/comments also apply outside brackets.
|
|
55
25
|
if ((closers.length > 0 || firstAt !== -1) && ch === "\\") {
|
|
56
26
|
i++;
|
|
57
27
|
continue;
|
|
@@ -81,7 +51,6 @@ export function parseClassToken(raw) {
|
|
|
81
51
|
}
|
|
82
52
|
else if (firstAt === -1) {
|
|
83
53
|
if (ch === ":" && firstColon === -1) {
|
|
84
|
-
// Only the first depth-0 `:` that appears before any `@` splits the declaration.
|
|
85
54
|
firstColon = i;
|
|
86
55
|
}
|
|
87
56
|
else if (ch === "!") {
|
|
@@ -90,26 +59,19 @@ export function parseClassToken(raw) {
|
|
|
90
59
|
}
|
|
91
60
|
}
|
|
92
61
|
}
|
|
93
|
-
// The declaration segment ends at the first depth-0 `@` (or the token's end).
|
|
94
62
|
const declEnd = firstAt === -1 ? raw.length : firstAt;
|
|
95
63
|
let declaration = raw.slice(0, declEnd);
|
|
96
|
-
// Trailing depth-0 `!` on the declaration segment = `!important`.
|
|
97
|
-
// (A literal `!` in the value must be inside `[]`, so it stays at depth > 0.)
|
|
98
|
-
// `declEnd > 0` keeps an `@`-leading token (empty declaration) from
|
|
99
|
-
// matching the `-1` "no bang" sentinel.
|
|
100
64
|
let important = false;
|
|
101
65
|
if (declEnd > 0 && lastDepthZeroBang === declEnd - 1) {
|
|
102
66
|
important = true;
|
|
103
67
|
declaration = declaration.slice(0, -1);
|
|
104
68
|
}
|
|
105
|
-
// Split conditions on each depth-0 `@`, stripping the leading `@` from each.
|
|
106
69
|
const conditions = [];
|
|
107
70
|
for (let k = 0; k < atPositions.length; k++) {
|
|
108
71
|
const start = atPositions[k] + 1;
|
|
109
72
|
const end = k + 1 < atPositions.length ? atPositions[k + 1] : raw.length;
|
|
110
73
|
appendOwnArrayValue(conditions, raw.slice(start, end));
|
|
111
74
|
}
|
|
112
|
-
// Declaration form: `property:value` (depth-0 `:` exists) or bare keyword.
|
|
113
75
|
const hasColon = firstColon !== -1 && firstColon < declEnd;
|
|
114
76
|
if (hasColon) {
|
|
115
77
|
return {
|
package/package.json
CHANGED