domflax 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -0
- package/dist/{chunk-4HHISSMR.js → chunk-DNHOGPYV.js} +2675 -1503
- package/dist/chunk-DNHOGPYV.js.map +1 -0
- package/dist/{chunk-ZJ2S36GY.js → chunk-DOQEBGWB.js} +33 -20
- package/dist/chunk-DOQEBGWB.js.map +1 -0
- package/dist/{chunk-77SLHRN6.js → chunk-DWLB7FRR.js} +341 -176
- package/dist/chunk-DWLB7FRR.js.map +1 -0
- package/dist/cli.cjs +2209 -774
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +234 -116
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3021 -1699
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +477 -54
- package/dist/index.d.ts +477 -54
- package/dist/index.js +49 -3
- package/dist/pattern-CV607P87.d.ts +547 -0
- package/dist/pattern-F5xBtIE-.d.cts +547 -0
- package/dist/pattern-kit.cjs +60 -39
- package/dist/pattern-kit.cjs.map +1 -1
- package/dist/pattern-kit.d.cts +3 -18
- package/dist/pattern-kit.d.ts +3 -18
- package/dist/pattern-kit.js +3 -1
- package/dist/pattern-kit.js.map +1 -1
- package/dist/{types-BQ7l6dVe.d.ts → resolve-ops-DIwEelH-.d.cts} +26 -251
- package/dist/{types-BQ7l6dVe.d.cts → resolve-ops-DIwEelH-.d.ts} +26 -251
- package/dist/verify.d.cts +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/webpack-loader.cjs +2975 -1699
- package/dist/webpack-loader.cjs.map +1 -1
- package/dist/webpack-loader.d.cts +2 -2
- package/dist/webpack-loader.d.ts +2 -2
- package/dist/webpack-loader.js +3 -3
- package/package.json +3 -6
- package/dist/chunk-4HHISSMR.js.map +0 -1
- package/dist/chunk-77SLHRN6.js.map +0 -1
- package/dist/chunk-ZJ2S36GY.js.map +0 -1
- package/dist/pattern-CX6iBzTD.d.ts +0 -237
- package/dist/pattern-P4FIKAUB.d.cts +0 -237
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { d as StyleCondition, e as ConditionKey, f as IRNamespace, g as ClassList, h as InlineStyle, S as StyleMap, A as AttrMap, I as IRNodeId, i as SourceSpan, j as NodeMeta, B as BackrefTable, k as Backref, l as IRNode, m as IRComment, F as FrontendKind, n as IRDocument, o as IRElement, p as ExprRef, q as IRExpr, r as ExprRegistry, s as IRFragment, t as IdAllocator, u as IRText, v as SafetyLevel, V as Visitor, N as NodeLike, M as MatchContext, w as Captures, P as Pattern, x as RewriteFactory, y as MatchResult, a as StyleConflictPolicy, z as PassCategory, D as PreconditionSketch, G as PatternDoc, R as RewriteOpDraft } from './types-BQ7l6dVe.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @domflax/core — runtime builders + traversal.
|
|
5
|
-
*
|
|
6
|
-
* Pure, dependency-free helpers to construct IR nodes, assemble an {@link IRDocument},
|
|
7
|
-
* and walk the tree honouring {@link VisitSignal}. No heavy third-party deps: only the
|
|
8
|
-
* type contract in `./types`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** Monotonic IRNodeId allocator. `peek` reports the id `next()` would return. */
|
|
12
|
-
declare function createIdAllocator(start?: number): IdAllocator;
|
|
13
|
-
/** Minimal in-memory ExprRegistry. */
|
|
14
|
-
declare function createExprRegistry(start?: number): ExprRegistry;
|
|
15
|
-
/** Mutable BackrefTable: frontends register backrefs as they parse. */
|
|
16
|
-
interface MutableBackrefTable extends BackrefTable {
|
|
17
|
-
set(id: IRNodeId, backref: Backref): void;
|
|
18
|
-
}
|
|
19
|
-
declare function createBackrefTable(): MutableBackrefTable;
|
|
20
|
-
/** A NodeMeta with every barrier/flag cleared. */
|
|
21
|
-
declare function defaultMeta(safetyFloor?: SafetyLevel): NodeMeta;
|
|
22
|
-
/** Canonical base style condition (`media:'' states:[] pseudoElement:''`). */
|
|
23
|
-
declare const BASE_CONDITION: StyleCondition;
|
|
24
|
-
/** Stable serialization of a StyleCondition into a ConditionKey. */
|
|
25
|
-
declare function conditionKey(c: StyleCondition): ConditionKey;
|
|
26
|
-
declare const BASE_CONDITION_KEY: ConditionKey;
|
|
27
|
-
/** An empty StyleMap (no blocks). */
|
|
28
|
-
declare function emptyStyleMap(): StyleMap;
|
|
29
|
-
/** An empty (absent) ClassList. */
|
|
30
|
-
declare function emptyClassList(): ClassList;
|
|
31
|
-
/** An empty AttrMap. */
|
|
32
|
-
declare function emptyAttrMap(): AttrMap;
|
|
33
|
-
/** An empty InlineStyle. */
|
|
34
|
-
declare function emptyInlineStyle(): InlineStyle;
|
|
35
|
-
interface ElementInit {
|
|
36
|
-
readonly tag: string;
|
|
37
|
-
readonly namespace?: IRNamespace;
|
|
38
|
-
readonly isComponent?: boolean;
|
|
39
|
-
readonly selfClosing?: boolean;
|
|
40
|
-
readonly classes?: ClassList;
|
|
41
|
-
readonly inlineStyle?: InlineStyle;
|
|
42
|
-
readonly computed?: StyleMap;
|
|
43
|
-
readonly attrs?: AttrMap;
|
|
44
|
-
readonly children?: IRNodeId[];
|
|
45
|
-
readonly parent?: IRNodeId | null;
|
|
46
|
-
readonly span?: SourceSpan | null;
|
|
47
|
-
readonly meta?: NodeMeta;
|
|
48
|
-
}
|
|
49
|
-
declare function createElement(id: IRNodeId, init: ElementInit): IRElement;
|
|
50
|
-
declare function createText(id: IRNodeId, value: string, opts?: {
|
|
51
|
-
collapsible?: boolean;
|
|
52
|
-
parent?: IRNodeId | null;
|
|
53
|
-
span?: SourceSpan | null;
|
|
54
|
-
}): IRText;
|
|
55
|
-
declare function createExpr(id: IRNodeId, expr: ExprRef, opts?: {
|
|
56
|
-
parent?: IRNodeId | null;
|
|
57
|
-
span?: SourceSpan | null;
|
|
58
|
-
}): IRExpr;
|
|
59
|
-
declare function createFragment(id: IRNodeId, opts?: {
|
|
60
|
-
children?: IRNodeId[];
|
|
61
|
-
parent?: IRNodeId | null;
|
|
62
|
-
span?: SourceSpan | null;
|
|
63
|
-
}): IRFragment;
|
|
64
|
-
declare function createComment(id: IRNodeId, value: string, opts?: {
|
|
65
|
-
parent?: IRNodeId | null;
|
|
66
|
-
span?: SourceSpan | null;
|
|
67
|
-
}): IRComment;
|
|
68
|
-
/** Build an empty document whose root is a fresh fragment. */
|
|
69
|
-
declare function createDocument(frontend: FrontendKind): IRDocument;
|
|
70
|
-
/** Returns the child id list for container nodes, or an empty array. */
|
|
71
|
-
declare function childIds(node: IRNode): readonly IRNodeId[];
|
|
72
|
-
/** Returns the node, or undefined. */
|
|
73
|
-
declare function getNode(doc: IRDocument, id: IRNodeId): IRNode | undefined;
|
|
74
|
-
/** Returns the node iff it is an element. */
|
|
75
|
-
declare function getElement(doc: IRDocument, id: IRNodeId): IRElement | undefined;
|
|
76
|
-
/** Pre-order list of every element id reachable from the root. */
|
|
77
|
-
declare function elementIds(doc: IRDocument): IRNodeId[];
|
|
78
|
-
/**
|
|
79
|
-
* Depth-first pre/post-order walk. `enter` may return `'skip'` (don't descend) or `'stop'`
|
|
80
|
-
* (abort the whole walk); `exit` may return `'stop'`. The visitor receives a live {@link IRNode}
|
|
81
|
-
* plus a {@link VisitContext} exposing depth and the parent node.
|
|
82
|
-
*/
|
|
83
|
-
declare function walk(doc: IRDocument, visitor: Visitor): void;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @domflax/pattern-kit — composable matcher vocabulary.
|
|
87
|
-
*
|
|
88
|
-
* A {@link Matcher} is a PURE predicate over a node + its {@link MatchContext}. Matchers never
|
|
89
|
-
* mutate; they only read the (DeepReadonly) IR and the precomputed targeting/selector facts the
|
|
90
|
-
* context exposes. Authors compose them with {@link and}/{@link or}/{@link not} and feed the
|
|
91
|
-
* result into a pattern's `evaluate`.
|
|
92
|
-
*
|
|
93
|
-
* Style-aware matchers (`computed`, `hasOwnVisualStyle`) reason over the NORMALIZED StyleMap via
|
|
94
|
-
* the shared normalizer in `./normalize`, so they query meaning, not raw CSS strings.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/** A pure predicate: does `node` satisfy this condition in the given match context? */
|
|
98
|
-
type Matcher = (node: NodeLike, ctx: MatchContext) => boolean;
|
|
99
|
-
/** Logical AND. Empty list ⇒ always matches. Short-circuits on the first failure. */
|
|
100
|
-
declare function and(...matchers: readonly Matcher[]): Matcher;
|
|
101
|
-
/** Logical OR. Empty list ⇒ never matches. Short-circuits on the first success. */
|
|
102
|
-
declare function or(...matchers: readonly Matcher[]): Matcher;
|
|
103
|
-
/** Logical NOT. */
|
|
104
|
-
declare function not(matcher: Matcher): Matcher;
|
|
105
|
-
/** Matches any element; with `tag`, only elements whose (case-insensitive) tag equals it. */
|
|
106
|
-
declare function isElement(tag?: string): Matcher;
|
|
107
|
-
/** Matches an element with exactly one ELEMENT child (text/expr/comment children ignored). */
|
|
108
|
-
declare const hasSingleElementChild: Matcher;
|
|
109
|
-
/**
|
|
110
|
-
* Matches when the node's computed StyleMap is a SUPERSET of `partial` — i.e. every declaration
|
|
111
|
-
* in `partial` is present in `node.computed` with an equal normalized value. Comparison is
|
|
112
|
-
* meaning-based (both sides normalized first). Empty `partial` always matches.
|
|
113
|
-
*/
|
|
114
|
-
declare function computed(partial: StyleMap): Matcher;
|
|
115
|
-
/**
|
|
116
|
-
* Matches when the element paints something of its own: a meaningful background, border, shadow,
|
|
117
|
-
* outline, filter, etc. across ANY style condition. Honours the frontend-set `meta.hasOwnVisualStyle`
|
|
118
|
-
* fast-path, then falls back to scanning the normalized computed StyleMap.
|
|
119
|
-
*/
|
|
120
|
-
declare const hasOwnVisualStyle: Matcher;
|
|
121
|
-
/** Element carries a `ref` (hard opacity barrier). */
|
|
122
|
-
declare const hasRef: Matcher;
|
|
123
|
-
/** Element has event handlers (onClick, …). */
|
|
124
|
-
declare const hasEventHandlers: Matcher;
|
|
125
|
-
/** Element has dynamic children (mapped/conditional islands). */
|
|
126
|
-
declare const hasDynamicChildren: Matcher;
|
|
127
|
-
/** Element's class list contains a dynamic segment (template/expr) → not freely rewritable. */
|
|
128
|
-
declare const hasDynamicClasses: Matcher;
|
|
129
|
-
/**
|
|
130
|
-
* Element is the subject of a combinator selector (`>`/`+`/`~`). Honours the frontend-set meta
|
|
131
|
-
* flag and the precomputed {@link SelectorIndex} in the context.
|
|
132
|
-
*/
|
|
133
|
-
declare const targetedByCombinator: Matcher;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @domflax/pattern-kit — `pattern()`: a low-boilerplate, declarative authoring surface.
|
|
137
|
-
*
|
|
138
|
-
* `pattern(config)` is pure authoring SUGAR: it compiles down to the existing
|
|
139
|
-
* {@link definePattern}/{@link Pattern} contract (it never replaces the engine). Authors describe
|
|
140
|
-
* the match as a plain DATA object and the rewrite as a named RECIPE; this module maps each key to
|
|
141
|
-
* the existing matcher combinators and op-draft factories, auto-applies the opacity-barrier and
|
|
142
|
-
* selector-safety guards that every `flatten/*` pattern must carry, and threads `doc`/`examples`
|
|
143
|
-
* through. Two escape hatches — a `match` predicate and a `rewrite` function — keep exotic patterns
|
|
144
|
-
* (e.g. ones anchored on a parent fragment) expressible.
|
|
145
|
-
*
|
|
146
|
-
* `style` blocks in the declarative match (and in `childGains`/`mergeStyle` recipes) are PLAIN
|
|
147
|
-
* objects (camelCase or kebab keys) auto-normalized into a superset StyleMap via the shared
|
|
148
|
-
* normalizer — authors never import the normalizer or hand-build a StyleMap.
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
/** A plain CSS style object: camelCase or kebab-case keys, string or number values. */
|
|
152
|
-
type PlainStyle = Readonly<Record<string, string | number>>;
|
|
153
|
-
/**
|
|
154
|
-
* Declarative match as DATA. Every key maps to one of the existing matcher combinators; an empty
|
|
155
|
-
* object matches any element. Use the `match` FUNCTION escape hatch for anything not expressible
|
|
156
|
-
* here (relational/ancestor/sibling shapes, parent-anchored patterns, …).
|
|
157
|
-
*/
|
|
158
|
-
interface DeclarativeMatch {
|
|
159
|
-
/** Restrict to a tag (case-insensitive). Omit to match any element. */
|
|
160
|
-
readonly tag?: string;
|
|
161
|
-
/** Computed style the node must be a SUPERSET of (plain object, auto-normalized). */
|
|
162
|
-
readonly style?: PlainStyle;
|
|
163
|
-
/** Require exactly one ELEMENT child. */
|
|
164
|
-
readonly onlyChild?: 'element';
|
|
165
|
-
/** Require the element to paint nothing of its own (no own visual style). */
|
|
166
|
-
readonly paintsNothing?: boolean;
|
|
167
|
-
/** Extra, hand-written predicate AND-ed into the declarative match. */
|
|
168
|
-
readonly where?: Matcher | readonly Matcher[];
|
|
169
|
-
}
|
|
170
|
-
/** Escape hatch: a raw match predicate (no auto-guards are added). */
|
|
171
|
-
type MatchFn = (node: NodeLike, ctx: MatchContext) => boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Flatten recipe: fold inherited styles onto the sole element child (default on), optionally merge
|
|
174
|
-
* `childGains` onto it, then unwrap the node (id-preserving). Mirrors the flatten exemplars.
|
|
175
|
-
*/
|
|
176
|
-
interface FlattenIntoRecipe {
|
|
177
|
-
readonly flattenInto: 'child';
|
|
178
|
-
/** Plain style merged onto the surviving child (source-wins) before unwrap. */
|
|
179
|
-
readonly childGains?: PlainStyle;
|
|
180
|
-
/** Fold inheritable declarations onto the child first. Default `true`. */
|
|
181
|
-
readonly foldInherited?: boolean;
|
|
182
|
-
}
|
|
183
|
-
/** Compress recipe: rebuild the element's class StyleMap; return `null` to decline. */
|
|
184
|
-
interface RewriteClassesRecipe {
|
|
185
|
-
readonly rewriteClasses: (computed: StyleMap, ctx: MatchContext) => StyleMap | null;
|
|
186
|
-
/** Keep opaque/selector-bound tokens verbatim. Default `true`. */
|
|
187
|
-
readonly preserveOpaque?: boolean;
|
|
188
|
-
}
|
|
189
|
-
/** Compress recipe: drop fully-overridden class tokens (provenance is pruned automatically). */
|
|
190
|
-
interface DropClassesRecipe {
|
|
191
|
-
readonly dropClasses: (computed: StyleMap, ctx: MatchContext) => Iterable<string>;
|
|
192
|
-
/** Keep opaque/selector-bound tokens verbatim. Default `true`. */
|
|
193
|
-
readonly preserveOpaque?: boolean;
|
|
194
|
-
}
|
|
195
|
-
/** Merge a literal plain style onto the matched element. */
|
|
196
|
-
interface MergeStyleRecipe {
|
|
197
|
-
readonly mergeStyle: PlainStyle;
|
|
198
|
-
readonly onConflict?: StyleConflictPolicy;
|
|
199
|
-
}
|
|
200
|
-
type RewriteRecipe = FlattenIntoRecipe | RewriteClassesRecipe | DropClassesRecipe | MergeStyleRecipe;
|
|
201
|
-
/** Escape hatch: a raw rewrite that returns op drafts (or `null`/`[]` for no-op). */
|
|
202
|
-
type RewriteFn = (ctx: MatchContext, rw: RewriteFactory) => readonly RewriteOpDraft[] | null;
|
|
203
|
-
/** A before/after positive example, or a no-match (left-unchanged) example. */
|
|
204
|
-
type Example = {
|
|
205
|
-
readonly before: string;
|
|
206
|
-
readonly after: string;
|
|
207
|
-
} | {
|
|
208
|
-
readonly name?: string;
|
|
209
|
-
readonly noMatch: string;
|
|
210
|
-
};
|
|
211
|
-
interface PatternConfig {
|
|
212
|
-
readonly name: string;
|
|
213
|
-
readonly category: PassCategory;
|
|
214
|
-
readonly safety: SafetyLevel;
|
|
215
|
-
readonly priority?: number;
|
|
216
|
-
readonly precondition?: PreconditionSketch;
|
|
217
|
-
readonly doc?: PatternDoc;
|
|
218
|
-
/** Optional worked examples consumed by the auto-test harness (`./testing`). */
|
|
219
|
-
readonly examples?: readonly Example[];
|
|
220
|
-
/** Declarative match DATA, or a raw predicate escape hatch. Defaults to "any element". */
|
|
221
|
-
readonly match?: DeclarativeMatch | MatchFn;
|
|
222
|
-
/** A named rewrite recipe, or a raw op-draft factory escape hatch. */
|
|
223
|
-
readonly rewrite: RewriteRecipe | RewriteFn;
|
|
224
|
-
}
|
|
225
|
-
/** A {@link Pattern} that also carries its authored {@link Example}s for the test harness. */
|
|
226
|
-
interface AuthoredPattern<C extends Captures = Captures> extends Pattern {
|
|
227
|
-
readonly examples?: readonly Example[];
|
|
228
|
-
evaluate(ctx: MatchContext, rw: RewriteFactory): MatchResult<C> | null;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Compile a declarative {@link PatternConfig} into a validated {@link AuthoredPattern}. The result
|
|
232
|
-
* is a normal {@link Pattern} (registerable into any {@link import('@domflax/core').Pass}) that also
|
|
233
|
-
* exposes its `examples` for the auto-test harness.
|
|
234
|
-
*/
|
|
235
|
-
declare function pattern(config: PatternConfig): AuthoredPattern;
|
|
236
|
-
|
|
237
|
-
export { type AuthoredPattern as A, BASE_CONDITION as B, createComment as C, type DeclarativeMatch as D, type Example as E, type FlattenIntoRecipe as F, createDocument as G, createElement as H, createExpr as I, createExprRegistry as J, createFragment as K, createIdAllocator as L, type MatchFn as M, createText as N, defaultMeta as O, type PatternConfig as P, elementIds as Q, type RewriteClassesRecipe as R, emptyAttrMap as S, emptyClassList as T, emptyInlineStyle as U, getElement as V, getNode as W, walk as X, type DropClassesRecipe as a, type Matcher as b, type MergeStyleRecipe as c, type PlainStyle as d, type RewriteFn as e, type RewriteRecipe as f, and as g, computed as h, emptyStyleMap as i, hasDynamicChildren as j, hasDynamicClasses as k, hasEventHandlers as l, hasOwnVisualStyle as m, hasRef as n, hasSingleElementChild as o, isElement as p, not as q, or as r, pattern as s, targetedByCombinator as t, BASE_CONDITION_KEY as u, type ElementInit as v, type MutableBackrefTable as w, childIds as x, conditionKey as y, createBackrefTable as z };
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { d as StyleCondition, e as ConditionKey, f as IRNamespace, g as ClassList, h as InlineStyle, S as StyleMap, A as AttrMap, I as IRNodeId, i as SourceSpan, j as NodeMeta, B as BackrefTable, k as Backref, l as IRNode, m as IRComment, F as FrontendKind, n as IRDocument, o as IRElement, p as ExprRef, q as IRExpr, r as ExprRegistry, s as IRFragment, t as IdAllocator, u as IRText, v as SafetyLevel, V as Visitor, N as NodeLike, M as MatchContext, w as Captures, P as Pattern, x as RewriteFactory, y as MatchResult, a as StyleConflictPolicy, z as PassCategory, D as PreconditionSketch, G as PatternDoc, R as RewriteOpDraft } from './types-BQ7l6dVe.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @domflax/core — runtime builders + traversal.
|
|
5
|
-
*
|
|
6
|
-
* Pure, dependency-free helpers to construct IR nodes, assemble an {@link IRDocument},
|
|
7
|
-
* and walk the tree honouring {@link VisitSignal}. No heavy third-party deps: only the
|
|
8
|
-
* type contract in `./types`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** Monotonic IRNodeId allocator. `peek` reports the id `next()` would return. */
|
|
12
|
-
declare function createIdAllocator(start?: number): IdAllocator;
|
|
13
|
-
/** Minimal in-memory ExprRegistry. */
|
|
14
|
-
declare function createExprRegistry(start?: number): ExprRegistry;
|
|
15
|
-
/** Mutable BackrefTable: frontends register backrefs as they parse. */
|
|
16
|
-
interface MutableBackrefTable extends BackrefTable {
|
|
17
|
-
set(id: IRNodeId, backref: Backref): void;
|
|
18
|
-
}
|
|
19
|
-
declare function createBackrefTable(): MutableBackrefTable;
|
|
20
|
-
/** A NodeMeta with every barrier/flag cleared. */
|
|
21
|
-
declare function defaultMeta(safetyFloor?: SafetyLevel): NodeMeta;
|
|
22
|
-
/** Canonical base style condition (`media:'' states:[] pseudoElement:''`). */
|
|
23
|
-
declare const BASE_CONDITION: StyleCondition;
|
|
24
|
-
/** Stable serialization of a StyleCondition into a ConditionKey. */
|
|
25
|
-
declare function conditionKey(c: StyleCondition): ConditionKey;
|
|
26
|
-
declare const BASE_CONDITION_KEY: ConditionKey;
|
|
27
|
-
/** An empty StyleMap (no blocks). */
|
|
28
|
-
declare function emptyStyleMap(): StyleMap;
|
|
29
|
-
/** An empty (absent) ClassList. */
|
|
30
|
-
declare function emptyClassList(): ClassList;
|
|
31
|
-
/** An empty AttrMap. */
|
|
32
|
-
declare function emptyAttrMap(): AttrMap;
|
|
33
|
-
/** An empty InlineStyle. */
|
|
34
|
-
declare function emptyInlineStyle(): InlineStyle;
|
|
35
|
-
interface ElementInit {
|
|
36
|
-
readonly tag: string;
|
|
37
|
-
readonly namespace?: IRNamespace;
|
|
38
|
-
readonly isComponent?: boolean;
|
|
39
|
-
readonly selfClosing?: boolean;
|
|
40
|
-
readonly classes?: ClassList;
|
|
41
|
-
readonly inlineStyle?: InlineStyle;
|
|
42
|
-
readonly computed?: StyleMap;
|
|
43
|
-
readonly attrs?: AttrMap;
|
|
44
|
-
readonly children?: IRNodeId[];
|
|
45
|
-
readonly parent?: IRNodeId | null;
|
|
46
|
-
readonly span?: SourceSpan | null;
|
|
47
|
-
readonly meta?: NodeMeta;
|
|
48
|
-
}
|
|
49
|
-
declare function createElement(id: IRNodeId, init: ElementInit): IRElement;
|
|
50
|
-
declare function createText(id: IRNodeId, value: string, opts?: {
|
|
51
|
-
collapsible?: boolean;
|
|
52
|
-
parent?: IRNodeId | null;
|
|
53
|
-
span?: SourceSpan | null;
|
|
54
|
-
}): IRText;
|
|
55
|
-
declare function createExpr(id: IRNodeId, expr: ExprRef, opts?: {
|
|
56
|
-
parent?: IRNodeId | null;
|
|
57
|
-
span?: SourceSpan | null;
|
|
58
|
-
}): IRExpr;
|
|
59
|
-
declare function createFragment(id: IRNodeId, opts?: {
|
|
60
|
-
children?: IRNodeId[];
|
|
61
|
-
parent?: IRNodeId | null;
|
|
62
|
-
span?: SourceSpan | null;
|
|
63
|
-
}): IRFragment;
|
|
64
|
-
declare function createComment(id: IRNodeId, value: string, opts?: {
|
|
65
|
-
parent?: IRNodeId | null;
|
|
66
|
-
span?: SourceSpan | null;
|
|
67
|
-
}): IRComment;
|
|
68
|
-
/** Build an empty document whose root is a fresh fragment. */
|
|
69
|
-
declare function createDocument(frontend: FrontendKind): IRDocument;
|
|
70
|
-
/** Returns the child id list for container nodes, or an empty array. */
|
|
71
|
-
declare function childIds(node: IRNode): readonly IRNodeId[];
|
|
72
|
-
/** Returns the node, or undefined. */
|
|
73
|
-
declare function getNode(doc: IRDocument, id: IRNodeId): IRNode | undefined;
|
|
74
|
-
/** Returns the node iff it is an element. */
|
|
75
|
-
declare function getElement(doc: IRDocument, id: IRNodeId): IRElement | undefined;
|
|
76
|
-
/** Pre-order list of every element id reachable from the root. */
|
|
77
|
-
declare function elementIds(doc: IRDocument): IRNodeId[];
|
|
78
|
-
/**
|
|
79
|
-
* Depth-first pre/post-order walk. `enter` may return `'skip'` (don't descend) or `'stop'`
|
|
80
|
-
* (abort the whole walk); `exit` may return `'stop'`. The visitor receives a live {@link IRNode}
|
|
81
|
-
* plus a {@link VisitContext} exposing depth and the parent node.
|
|
82
|
-
*/
|
|
83
|
-
declare function walk(doc: IRDocument, visitor: Visitor): void;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @domflax/pattern-kit — composable matcher vocabulary.
|
|
87
|
-
*
|
|
88
|
-
* A {@link Matcher} is a PURE predicate over a node + its {@link MatchContext}. Matchers never
|
|
89
|
-
* mutate; they only read the (DeepReadonly) IR and the precomputed targeting/selector facts the
|
|
90
|
-
* context exposes. Authors compose them with {@link and}/{@link or}/{@link not} and feed the
|
|
91
|
-
* result into a pattern's `evaluate`.
|
|
92
|
-
*
|
|
93
|
-
* Style-aware matchers (`computed`, `hasOwnVisualStyle`) reason over the NORMALIZED StyleMap via
|
|
94
|
-
* the shared normalizer in `./normalize`, so they query meaning, not raw CSS strings.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/** A pure predicate: does `node` satisfy this condition in the given match context? */
|
|
98
|
-
type Matcher = (node: NodeLike, ctx: MatchContext) => boolean;
|
|
99
|
-
/** Logical AND. Empty list ⇒ always matches. Short-circuits on the first failure. */
|
|
100
|
-
declare function and(...matchers: readonly Matcher[]): Matcher;
|
|
101
|
-
/** Logical OR. Empty list ⇒ never matches. Short-circuits on the first success. */
|
|
102
|
-
declare function or(...matchers: readonly Matcher[]): Matcher;
|
|
103
|
-
/** Logical NOT. */
|
|
104
|
-
declare function not(matcher: Matcher): Matcher;
|
|
105
|
-
/** Matches any element; with `tag`, only elements whose (case-insensitive) tag equals it. */
|
|
106
|
-
declare function isElement(tag?: string): Matcher;
|
|
107
|
-
/** Matches an element with exactly one ELEMENT child (text/expr/comment children ignored). */
|
|
108
|
-
declare const hasSingleElementChild: Matcher;
|
|
109
|
-
/**
|
|
110
|
-
* Matches when the node's computed StyleMap is a SUPERSET of `partial` — i.e. every declaration
|
|
111
|
-
* in `partial` is present in `node.computed` with an equal normalized value. Comparison is
|
|
112
|
-
* meaning-based (both sides normalized first). Empty `partial` always matches.
|
|
113
|
-
*/
|
|
114
|
-
declare function computed(partial: StyleMap): Matcher;
|
|
115
|
-
/**
|
|
116
|
-
* Matches when the element paints something of its own: a meaningful background, border, shadow,
|
|
117
|
-
* outline, filter, etc. across ANY style condition. Honours the frontend-set `meta.hasOwnVisualStyle`
|
|
118
|
-
* fast-path, then falls back to scanning the normalized computed StyleMap.
|
|
119
|
-
*/
|
|
120
|
-
declare const hasOwnVisualStyle: Matcher;
|
|
121
|
-
/** Element carries a `ref` (hard opacity barrier). */
|
|
122
|
-
declare const hasRef: Matcher;
|
|
123
|
-
/** Element has event handlers (onClick, …). */
|
|
124
|
-
declare const hasEventHandlers: Matcher;
|
|
125
|
-
/** Element has dynamic children (mapped/conditional islands). */
|
|
126
|
-
declare const hasDynamicChildren: Matcher;
|
|
127
|
-
/** Element's class list contains a dynamic segment (template/expr) → not freely rewritable. */
|
|
128
|
-
declare const hasDynamicClasses: Matcher;
|
|
129
|
-
/**
|
|
130
|
-
* Element is the subject of a combinator selector (`>`/`+`/`~`). Honours the frontend-set meta
|
|
131
|
-
* flag and the precomputed {@link SelectorIndex} in the context.
|
|
132
|
-
*/
|
|
133
|
-
declare const targetedByCombinator: Matcher;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @domflax/pattern-kit — `pattern()`: a low-boilerplate, declarative authoring surface.
|
|
137
|
-
*
|
|
138
|
-
* `pattern(config)` is pure authoring SUGAR: it compiles down to the existing
|
|
139
|
-
* {@link definePattern}/{@link Pattern} contract (it never replaces the engine). Authors describe
|
|
140
|
-
* the match as a plain DATA object and the rewrite as a named RECIPE; this module maps each key to
|
|
141
|
-
* the existing matcher combinators and op-draft factories, auto-applies the opacity-barrier and
|
|
142
|
-
* selector-safety guards that every `flatten/*` pattern must carry, and threads `doc`/`examples`
|
|
143
|
-
* through. Two escape hatches — a `match` predicate and a `rewrite` function — keep exotic patterns
|
|
144
|
-
* (e.g. ones anchored on a parent fragment) expressible.
|
|
145
|
-
*
|
|
146
|
-
* `style` blocks in the declarative match (and in `childGains`/`mergeStyle` recipes) are PLAIN
|
|
147
|
-
* objects (camelCase or kebab keys) auto-normalized into a superset StyleMap via the shared
|
|
148
|
-
* normalizer — authors never import the normalizer or hand-build a StyleMap.
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
/** A plain CSS style object: camelCase or kebab-case keys, string or number values. */
|
|
152
|
-
type PlainStyle = Readonly<Record<string, string | number>>;
|
|
153
|
-
/**
|
|
154
|
-
* Declarative match as DATA. Every key maps to one of the existing matcher combinators; an empty
|
|
155
|
-
* object matches any element. Use the `match` FUNCTION escape hatch for anything not expressible
|
|
156
|
-
* here (relational/ancestor/sibling shapes, parent-anchored patterns, …).
|
|
157
|
-
*/
|
|
158
|
-
interface DeclarativeMatch {
|
|
159
|
-
/** Restrict to a tag (case-insensitive). Omit to match any element. */
|
|
160
|
-
readonly tag?: string;
|
|
161
|
-
/** Computed style the node must be a SUPERSET of (plain object, auto-normalized). */
|
|
162
|
-
readonly style?: PlainStyle;
|
|
163
|
-
/** Require exactly one ELEMENT child. */
|
|
164
|
-
readonly onlyChild?: 'element';
|
|
165
|
-
/** Require the element to paint nothing of its own (no own visual style). */
|
|
166
|
-
readonly paintsNothing?: boolean;
|
|
167
|
-
/** Extra, hand-written predicate AND-ed into the declarative match. */
|
|
168
|
-
readonly where?: Matcher | readonly Matcher[];
|
|
169
|
-
}
|
|
170
|
-
/** Escape hatch: a raw match predicate (no auto-guards are added). */
|
|
171
|
-
type MatchFn = (node: NodeLike, ctx: MatchContext) => boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Flatten recipe: fold inherited styles onto the sole element child (default on), optionally merge
|
|
174
|
-
* `childGains` onto it, then unwrap the node (id-preserving). Mirrors the flatten exemplars.
|
|
175
|
-
*/
|
|
176
|
-
interface FlattenIntoRecipe {
|
|
177
|
-
readonly flattenInto: 'child';
|
|
178
|
-
/** Plain style merged onto the surviving child (source-wins) before unwrap. */
|
|
179
|
-
readonly childGains?: PlainStyle;
|
|
180
|
-
/** Fold inheritable declarations onto the child first. Default `true`. */
|
|
181
|
-
readonly foldInherited?: boolean;
|
|
182
|
-
}
|
|
183
|
-
/** Compress recipe: rebuild the element's class StyleMap; return `null` to decline. */
|
|
184
|
-
interface RewriteClassesRecipe {
|
|
185
|
-
readonly rewriteClasses: (computed: StyleMap, ctx: MatchContext) => StyleMap | null;
|
|
186
|
-
/** Keep opaque/selector-bound tokens verbatim. Default `true`. */
|
|
187
|
-
readonly preserveOpaque?: boolean;
|
|
188
|
-
}
|
|
189
|
-
/** Compress recipe: drop fully-overridden class tokens (provenance is pruned automatically). */
|
|
190
|
-
interface DropClassesRecipe {
|
|
191
|
-
readonly dropClasses: (computed: StyleMap, ctx: MatchContext) => Iterable<string>;
|
|
192
|
-
/** Keep opaque/selector-bound tokens verbatim. Default `true`. */
|
|
193
|
-
readonly preserveOpaque?: boolean;
|
|
194
|
-
}
|
|
195
|
-
/** Merge a literal plain style onto the matched element. */
|
|
196
|
-
interface MergeStyleRecipe {
|
|
197
|
-
readonly mergeStyle: PlainStyle;
|
|
198
|
-
readonly onConflict?: StyleConflictPolicy;
|
|
199
|
-
}
|
|
200
|
-
type RewriteRecipe = FlattenIntoRecipe | RewriteClassesRecipe | DropClassesRecipe | MergeStyleRecipe;
|
|
201
|
-
/** Escape hatch: a raw rewrite that returns op drafts (or `null`/`[]` for no-op). */
|
|
202
|
-
type RewriteFn = (ctx: MatchContext, rw: RewriteFactory) => readonly RewriteOpDraft[] | null;
|
|
203
|
-
/** A before/after positive example, or a no-match (left-unchanged) example. */
|
|
204
|
-
type Example = {
|
|
205
|
-
readonly before: string;
|
|
206
|
-
readonly after: string;
|
|
207
|
-
} | {
|
|
208
|
-
readonly name?: string;
|
|
209
|
-
readonly noMatch: string;
|
|
210
|
-
};
|
|
211
|
-
interface PatternConfig {
|
|
212
|
-
readonly name: string;
|
|
213
|
-
readonly category: PassCategory;
|
|
214
|
-
readonly safety: SafetyLevel;
|
|
215
|
-
readonly priority?: number;
|
|
216
|
-
readonly precondition?: PreconditionSketch;
|
|
217
|
-
readonly doc?: PatternDoc;
|
|
218
|
-
/** Optional worked examples consumed by the auto-test harness (`./testing`). */
|
|
219
|
-
readonly examples?: readonly Example[];
|
|
220
|
-
/** Declarative match DATA, or a raw predicate escape hatch. Defaults to "any element". */
|
|
221
|
-
readonly match?: DeclarativeMatch | MatchFn;
|
|
222
|
-
/** A named rewrite recipe, or a raw op-draft factory escape hatch. */
|
|
223
|
-
readonly rewrite: RewriteRecipe | RewriteFn;
|
|
224
|
-
}
|
|
225
|
-
/** A {@link Pattern} that also carries its authored {@link Example}s for the test harness. */
|
|
226
|
-
interface AuthoredPattern<C extends Captures = Captures> extends Pattern {
|
|
227
|
-
readonly examples?: readonly Example[];
|
|
228
|
-
evaluate(ctx: MatchContext, rw: RewriteFactory): MatchResult<C> | null;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Compile a declarative {@link PatternConfig} into a validated {@link AuthoredPattern}. The result
|
|
232
|
-
* is a normal {@link Pattern} (registerable into any {@link import('@domflax/core').Pass}) that also
|
|
233
|
-
* exposes its `examples` for the auto-test harness.
|
|
234
|
-
*/
|
|
235
|
-
declare function pattern(config: PatternConfig): AuthoredPattern;
|
|
236
|
-
|
|
237
|
-
export { type AuthoredPattern as A, BASE_CONDITION as B, createComment as C, type DeclarativeMatch as D, type Example as E, type FlattenIntoRecipe as F, createDocument as G, createElement as H, createExpr as I, createExprRegistry as J, createFragment as K, createIdAllocator as L, type MatchFn as M, createText as N, defaultMeta as O, type PatternConfig as P, elementIds as Q, type RewriteClassesRecipe as R, emptyAttrMap as S, emptyClassList as T, emptyInlineStyle as U, getElement as V, getNode as W, walk as X, type DropClassesRecipe as a, type Matcher as b, type MergeStyleRecipe as c, type PlainStyle as d, type RewriteFn as e, type RewriteRecipe as f, and as g, computed as h, emptyStyleMap as i, hasDynamicChildren as j, hasDynamicClasses as k, hasEventHandlers as l, hasOwnVisualStyle as m, hasRef as n, hasSingleElementChild as o, isElement as p, not as q, or as r, pattern as s, targetedByCombinator as t, BASE_CONDITION_KEY as u, type ElementInit as v, type MutableBackrefTable as w, childIds as x, conditionKey as y, createBackrefTable as z };
|