@brad-frost-web/eddie-render 0.65.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/README.md +127 -0
- package/cdn/eddie-render.js +947 -0
- package/cdn/eddie-render.js.map +1 -0
- package/dist/composer/index.d.ts +75 -0
- package/dist/composer/index.d.ts.map +1 -0
- package/dist/composer/index.js +292 -0
- package/dist/composer/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +92 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +457 -0
- package/dist/render.js.map +1 -0
- package/dist/serialize.d.ts +29 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +128 -0
- package/dist/serialize.js.map +1 -0
- package/dist/spec.d.ts +59 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +364 -0
- package/dist/spec.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/validate/anti-pattern-selector.d.ts +75 -0
- package/dist/validate/anti-pattern-selector.d.ts.map +1 -0
- package/dist/validate/anti-pattern-selector.js +254 -0
- package/dist/validate/anti-pattern-selector.js.map +1 -0
- package/dist/validate/index.d.ts +36 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +334 -0
- package/dist/validate/index.js.map +1 -0
- package/package.json +50 -0
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for eddie-render (#1898, #1899, #1900).
|
|
3
|
+
*
|
|
4
|
+
* The catalog shape mirrors what `eddie-brain` writes to
|
|
5
|
+
* `.eddie-brain/catalog*.json` (an A2UI v1.0 catalog definition with Eddie's
|
|
6
|
+
* `metadata.extensions.eddie_*` keys, docs/A2UI-EDDIE.md §5). It is declared
|
|
7
|
+
* here structurally rather than imported, because this package must stay
|
|
8
|
+
* browser-safe and dependency-free; the brain consumes *this* package, not
|
|
9
|
+
* the other way round.
|
|
10
|
+
*/
|
|
11
|
+
/** Keys on a spec element that are never catalog props. */
|
|
12
|
+
export const RESERVED_KEYS = new Set(['component', 'children', 'slots', 'accessibility', 'action', 'metadata', 'catalogId', 'id']);
|
|
13
|
+
/** The built-in text node every profile carries (#1898): a text run inside a container. */
|
|
14
|
+
export const TEXT_NODE = 'Text';
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA2FH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;AAEnI,2FAA2F;AAC3F,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-pattern selectors (#1888): a deliberately small CSS-like grammar that
|
|
3
|
+
* can be evaluated on markup today and on a catalog tree (strategy Phase 1)
|
|
4
|
+
* without a DOM.
|
|
5
|
+
*
|
|
6
|
+
* selector := compound ( combinator compound )*
|
|
7
|
+
* combinator := ">" | " " child | descendant
|
|
8
|
+
* compound := (tag | "*") pseudo*
|
|
9
|
+
* tag := ed-[a-z0-9-]+ | h1..h6 | a | p | img | button | span | div | ul | ol | li
|
|
10
|
+
* pseudo := "[slot=" name "]" | ":not(" (tag | "[slot=" name "]") ")"
|
|
11
|
+
*
|
|
12
|
+
* Every seed the spec names fits this; anything outside it is rejected at
|
|
13
|
+
* `eddie-brain init`, so the dataset never carries a selector the matcher
|
|
14
|
+
* cannot evaluate. Widening the grammar is a visible diff here.
|
|
15
|
+
*
|
|
16
|
+
* The markup side is a tolerant tag-level tree, not an HTML parser: it knows
|
|
17
|
+
* open, close, self-closing and void tags, skips comments, ignores stray
|
|
18
|
+
* close tags, and leaves unclosed elements open to the end of the region.
|
|
19
|
+
* That is enough for Eddie markup and Lit templates, and it never throws.
|
|
20
|
+
*/
|
|
21
|
+
import type { AntiPattern } from '../types.js';
|
|
22
|
+
export interface Compound {
|
|
23
|
+
/** Tag name, lower-case, or `*`. */
|
|
24
|
+
tag: string;
|
|
25
|
+
/** Required `slot="…"` attribute value, if any. */
|
|
26
|
+
slot?: string;
|
|
27
|
+
/** `:not(...)` clauses: each rejects a tag or a slot value. */
|
|
28
|
+
not: Array<{
|
|
29
|
+
tag?: string;
|
|
30
|
+
slot?: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export interface Selector {
|
|
34
|
+
text: string;
|
|
35
|
+
compounds: Compound[];
|
|
36
|
+
/** `combinators[i]` joins `compounds[i]` to `compounds[i + 1]`. */
|
|
37
|
+
combinators: Array<'child' | 'descendant'>;
|
|
38
|
+
}
|
|
39
|
+
export declare class SelectorSyntaxError extends Error {
|
|
40
|
+
constructor(selector: string, detail: string);
|
|
41
|
+
}
|
|
42
|
+
/** Parse a selector string; throws `SelectorSyntaxError` on anything outside the grammar. */
|
|
43
|
+
export declare function parseSelector(text: string): Selector;
|
|
44
|
+
/** Every Eddie tag a selector names (excluding `*` and native elements), sorted and unique. */
|
|
45
|
+
export declare function selectorTags(selector: Selector): string[];
|
|
46
|
+
/** A stable id from the selector text: `ed-layout-container > ed-hero` → `layout-container-gt-hero`. */
|
|
47
|
+
export declare function selectorId(selectorText: string): string;
|
|
48
|
+
export interface MarkupNode {
|
|
49
|
+
tag: string;
|
|
50
|
+
slot?: string;
|
|
51
|
+
/** Offset of the opening tag in the region. */
|
|
52
|
+
index: number;
|
|
53
|
+
parent?: MarkupNode;
|
|
54
|
+
children: MarkupNode[];
|
|
55
|
+
}
|
|
56
|
+
/** Build a tolerant element tree from a chunk of markup. Never throws. */
|
|
57
|
+
export declare function parseMarkup(markup: string): MarkupNode[];
|
|
58
|
+
/** Depth-first walk over every node. */
|
|
59
|
+
export declare function walk(nodes: MarkupNode[]): Generator<MarkupNode>;
|
|
60
|
+
/** True when `node` is the subject (last compound) of `selector` and its ancestry satisfies the rest. */
|
|
61
|
+
export declare function matchesSelector(selector: Selector, node: MarkupNode): boolean;
|
|
62
|
+
export interface AntiPatternMatch {
|
|
63
|
+
pattern: AntiPattern;
|
|
64
|
+
/** The offending element (the selector's subject). */
|
|
65
|
+
node: MarkupNode;
|
|
66
|
+
/** Offset of its opening tag in the region. */
|
|
67
|
+
index: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* String-in core shared by `AntiPatternValidator` (markup files today) and
|
|
71
|
+
* the future `eddie_validate_spec` (a catalog tree rendered to markup or
|
|
72
|
+
* walked directly): every element that is the subject of a pattern's selector.
|
|
73
|
+
*/
|
|
74
|
+
export declare function findAntiPatterns(markup: string, patterns: AntiPattern[]): AntiPatternMatch[];
|
|
75
|
+
//# sourceMappingURL=anti-pattern-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-pattern-selector.d.ts","sourceRoot":"","sources":["../../src/validate/anti-pattern-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,MAAM,WAAW,QAAQ;IACvB,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,GAAG,EAAE,KAAK,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,QAAQ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EAAE,GAAG,gBAAgB,EAAE,CAW5F"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-pattern selectors (#1888): a deliberately small CSS-like grammar that
|
|
3
|
+
* can be evaluated on markup today and on a catalog tree (strategy Phase 1)
|
|
4
|
+
* without a DOM.
|
|
5
|
+
*
|
|
6
|
+
* selector := compound ( combinator compound )*
|
|
7
|
+
* combinator := ">" | " " child | descendant
|
|
8
|
+
* compound := (tag | "*") pseudo*
|
|
9
|
+
* tag := ed-[a-z0-9-]+ | h1..h6 | a | p | img | button | span | div | ul | ol | li
|
|
10
|
+
* pseudo := "[slot=" name "]" | ":not(" (tag | "[slot=" name "]") ")"
|
|
11
|
+
*
|
|
12
|
+
* Every seed the spec names fits this; anything outside it is rejected at
|
|
13
|
+
* `eddie-brain init`, so the dataset never carries a selector the matcher
|
|
14
|
+
* cannot evaluate. Widening the grammar is a visible diff here.
|
|
15
|
+
*
|
|
16
|
+
* The markup side is a tolerant tag-level tree, not an HTML parser: it knows
|
|
17
|
+
* open, close, self-closing and void tags, skips comments, ignores stray
|
|
18
|
+
* close tags, and leaves unclosed elements open to the end of the region.
|
|
19
|
+
* That is enough for Eddie markup and Lit templates, and it never throws.
|
|
20
|
+
*/
|
|
21
|
+
export class SelectorSyntaxError extends Error {
|
|
22
|
+
constructor(selector, detail) {
|
|
23
|
+
super(`Invalid anti-pattern selector "${selector}": ${detail}`);
|
|
24
|
+
this.name = 'SelectorSyntaxError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const TAG_RE = /^(?:ed-[a-z0-9-]+|h[1-6]|a|p|img|button|span|div|ul|ol|li)$/;
|
|
28
|
+
const SLOT_NAME_RE = /^[a-zA-Z][\w-]*$/;
|
|
29
|
+
function parseCompound(raw, selector) {
|
|
30
|
+
let rest = raw.trim();
|
|
31
|
+
const tagMatch = rest.match(/^(\*|[a-z][a-z0-9-]*)/);
|
|
32
|
+
if (!tagMatch)
|
|
33
|
+
throw new SelectorSyntaxError(selector, `expected a tag or "*" at "${rest}"`);
|
|
34
|
+
const tag = tagMatch[1];
|
|
35
|
+
if (tag !== '*' && !TAG_RE.test(tag)) {
|
|
36
|
+
throw new SelectorSyntaxError(selector, `"${tag}" is not an Eddie tag or an allowed native element`);
|
|
37
|
+
}
|
|
38
|
+
rest = rest.slice(tag.length);
|
|
39
|
+
const compound = { tag, not: [] };
|
|
40
|
+
while (rest.length > 0) {
|
|
41
|
+
const slot = rest.match(/^\[slot=([^\]]*)\]/);
|
|
42
|
+
if (slot) {
|
|
43
|
+
const name = slot[1].replace(/^["']|["']$/g, '');
|
|
44
|
+
if (!SLOT_NAME_RE.test(name))
|
|
45
|
+
throw new SelectorSyntaxError(selector, `bad slot name "${slot[1]}"`);
|
|
46
|
+
if (compound.slot)
|
|
47
|
+
throw new SelectorSyntaxError(selector, 'a compound may carry one [slot=] clause');
|
|
48
|
+
compound.slot = name;
|
|
49
|
+
rest = rest.slice(slot[0].length);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const not = rest.match(/^:not\(([^)]*)\)/);
|
|
53
|
+
if (not) {
|
|
54
|
+
const inner = not[1].trim();
|
|
55
|
+
const notSlot = inner.match(/^\[slot=([^\]]*)\]$/);
|
|
56
|
+
if (notSlot) {
|
|
57
|
+
const name = notSlot[1].replace(/^["']|["']$/g, '');
|
|
58
|
+
if (!SLOT_NAME_RE.test(name))
|
|
59
|
+
throw new SelectorSyntaxError(selector, `bad slot name in :not(): "${inner}"`);
|
|
60
|
+
compound.not.push({ slot: name });
|
|
61
|
+
}
|
|
62
|
+
else if (TAG_RE.test(inner)) {
|
|
63
|
+
compound.not.push({ tag: inner });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new SelectorSyntaxError(selector, `:not() accepts one tag or one [slot=name], got "${inner}"`);
|
|
67
|
+
}
|
|
68
|
+
rest = rest.slice(not[0].length);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
throw new SelectorSyntaxError(selector, `unexpected "${rest}"`);
|
|
72
|
+
}
|
|
73
|
+
if (compound.tag === '*' && compound.not.length === 0 && !compound.slot) {
|
|
74
|
+
throw new SelectorSyntaxError(selector, '"*" alone matches everything; qualify it with [slot=] or :not()');
|
|
75
|
+
}
|
|
76
|
+
return compound;
|
|
77
|
+
}
|
|
78
|
+
/** Parse a selector string; throws `SelectorSyntaxError` on anything outside the grammar. */
|
|
79
|
+
export function parseSelector(text) {
|
|
80
|
+
const selector = text.trim().replace(/\s+/g, ' ');
|
|
81
|
+
if (!selector)
|
|
82
|
+
throw new SelectorSyntaxError(text, 'empty selector');
|
|
83
|
+
// Tokenise on whitespace, treating ">" as its own token.
|
|
84
|
+
const tokens = selector.split(' ').filter(Boolean);
|
|
85
|
+
const compounds = [];
|
|
86
|
+
const combinators = [];
|
|
87
|
+
let pendingChild = false;
|
|
88
|
+
let expectCompound = true;
|
|
89
|
+
for (const token of tokens) {
|
|
90
|
+
if (token === '>') {
|
|
91
|
+
if (expectCompound)
|
|
92
|
+
throw new SelectorSyntaxError(selector, '">" needs a compound on both sides');
|
|
93
|
+
pendingChild = true;
|
|
94
|
+
expectCompound = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!expectCompound) {
|
|
98
|
+
// Two compounds separated only by whitespace: a descendant combinator.
|
|
99
|
+
combinators.push('descendant');
|
|
100
|
+
}
|
|
101
|
+
else if (compounds.length > 0) {
|
|
102
|
+
combinators.push(pendingChild ? 'child' : 'descendant');
|
|
103
|
+
}
|
|
104
|
+
compounds.push(parseCompound(token, selector));
|
|
105
|
+
pendingChild = false;
|
|
106
|
+
expectCompound = false;
|
|
107
|
+
}
|
|
108
|
+
if (expectCompound)
|
|
109
|
+
throw new SelectorSyntaxError(selector, 'selector ends with a combinator');
|
|
110
|
+
if (compounds.length < 2) {
|
|
111
|
+
throw new SelectorSyntaxError(selector, 'an anti-pattern describes a relationship: it needs a parent and a child');
|
|
112
|
+
}
|
|
113
|
+
return { text: selector, compounds, combinators };
|
|
114
|
+
}
|
|
115
|
+
/** Every Eddie tag a selector names (excluding `*` and native elements), sorted and unique. */
|
|
116
|
+
export function selectorTags(selector) {
|
|
117
|
+
const tags = new Set();
|
|
118
|
+
for (const c of selector.compounds) {
|
|
119
|
+
if (c.tag.startsWith('ed-'))
|
|
120
|
+
tags.add(c.tag);
|
|
121
|
+
for (const n of c.not)
|
|
122
|
+
if (n.tag?.startsWith('ed-'))
|
|
123
|
+
tags.add(n.tag);
|
|
124
|
+
}
|
|
125
|
+
return [...tags].sort();
|
|
126
|
+
}
|
|
127
|
+
/** A stable id from the selector text: `ed-layout-container > ed-hero` → `layout-container-gt-hero`. */
|
|
128
|
+
export function selectorId(selectorText) {
|
|
129
|
+
return selectorText
|
|
130
|
+
.trim()
|
|
131
|
+
.replace(/\s+/g, ' ')
|
|
132
|
+
.replace(/\bed-/g, '')
|
|
133
|
+
.replace(/\s*>\s*/g, '-gt-')
|
|
134
|
+
.replace(/:not\(\[slot=([^\]]*)\]\)/g, '-not-slot-$1')
|
|
135
|
+
.replace(/:not\(([^)]*)\)/g, '-not-$1')
|
|
136
|
+
.replace(/\[slot=([^\]]*)\]/g, '-slot-$1')
|
|
137
|
+
.replace(/\*/g, 'any')
|
|
138
|
+
.replace(/ /g, '-in-')
|
|
139
|
+
.replace(/[^a-z0-9-]/g, '')
|
|
140
|
+
.replace(/-+/g, '-')
|
|
141
|
+
.replace(/^-|-$/g, '');
|
|
142
|
+
}
|
|
143
|
+
const VOID_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
144
|
+
const TAG_TOKEN_RE = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][\w:-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)(\/?)>/g;
|
|
145
|
+
function slotAttr(attrText) {
|
|
146
|
+
const m = attrText.match(/\bslot\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i);
|
|
147
|
+
if (!m)
|
|
148
|
+
return undefined;
|
|
149
|
+
return (m[1] ?? m[2] ?? m[3]).trim();
|
|
150
|
+
}
|
|
151
|
+
/** Build a tolerant element tree from a chunk of markup. Never throws. */
|
|
152
|
+
export function parseMarkup(markup) {
|
|
153
|
+
const roots = [];
|
|
154
|
+
const stack = [];
|
|
155
|
+
TAG_TOKEN_RE.lastIndex = 0;
|
|
156
|
+
let m;
|
|
157
|
+
while ((m = TAG_TOKEN_RE.exec(markup)) !== null) {
|
|
158
|
+
if (m[0].startsWith('<!--'))
|
|
159
|
+
continue;
|
|
160
|
+
const isClose = m[1] === '/';
|
|
161
|
+
const tag = m[2].toLowerCase();
|
|
162
|
+
const attrText = m[3] ?? '';
|
|
163
|
+
const selfClosing = m[4] === '/' || VOID_ELEMENTS.has(tag);
|
|
164
|
+
if (isClose) {
|
|
165
|
+
// Pop to the nearest matching open element; ignore stray closes.
|
|
166
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
167
|
+
if (stack[i].tag === tag) {
|
|
168
|
+
stack.length = i;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const node = { tag, index: m.index, children: [] };
|
|
175
|
+
const slot = slotAttr(attrText);
|
|
176
|
+
if (slot !== undefined)
|
|
177
|
+
node.slot = slot;
|
|
178
|
+
const parent = stack[stack.length - 1];
|
|
179
|
+
if (parent) {
|
|
180
|
+
node.parent = parent;
|
|
181
|
+
parent.children.push(node);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
roots.push(node);
|
|
185
|
+
}
|
|
186
|
+
if (!selfClosing)
|
|
187
|
+
stack.push(node);
|
|
188
|
+
}
|
|
189
|
+
return roots;
|
|
190
|
+
}
|
|
191
|
+
/** Depth-first walk over every node. */
|
|
192
|
+
export function* walk(nodes) {
|
|
193
|
+
for (const n of nodes) {
|
|
194
|
+
yield n;
|
|
195
|
+
yield* walk(n.children);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// Matching
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
function compoundMatches(c, node) {
|
|
202
|
+
if (c.tag !== '*' && c.tag !== node.tag)
|
|
203
|
+
return false;
|
|
204
|
+
if (c.slot !== undefined && node.slot !== c.slot)
|
|
205
|
+
return false;
|
|
206
|
+
for (const n of c.not) {
|
|
207
|
+
if (n.tag !== undefined && node.tag === n.tag)
|
|
208
|
+
return false;
|
|
209
|
+
if (n.slot !== undefined && node.slot === n.slot)
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
/** True when `node` is the subject (last compound) of `selector` and its ancestry satisfies the rest. */
|
|
215
|
+
export function matchesSelector(selector, node) {
|
|
216
|
+
const { compounds, combinators } = selector;
|
|
217
|
+
const last = compounds.length - 1;
|
|
218
|
+
if (!compoundMatches(compounds[last], node))
|
|
219
|
+
return false;
|
|
220
|
+
const satisfy = (compoundIdx, from) => {
|
|
221
|
+
if (compoundIdx < 0)
|
|
222
|
+
return true;
|
|
223
|
+
const combinator = combinators[compoundIdx];
|
|
224
|
+
if (combinator === 'child') {
|
|
225
|
+
return !!from && compoundMatches(compounds[compoundIdx], from) && satisfy(compoundIdx - 1, from.parent);
|
|
226
|
+
}
|
|
227
|
+
// descendant: any ancestor may match, and the search continues above it.
|
|
228
|
+
for (let a = from; a; a = a.parent) {
|
|
229
|
+
if (compoundMatches(compounds[compoundIdx], a) && satisfy(compoundIdx - 1, a.parent))
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
};
|
|
234
|
+
return satisfy(last - 1, node.parent);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* String-in core shared by `AntiPatternValidator` (markup files today) and
|
|
238
|
+
* the future `eddie_validate_spec` (a catalog tree rendered to markup or
|
|
239
|
+
* walked directly): every element that is the subject of a pattern's selector.
|
|
240
|
+
*/
|
|
241
|
+
export function findAntiPatterns(markup, patterns) {
|
|
242
|
+
if (patterns.length === 0)
|
|
243
|
+
return [];
|
|
244
|
+
const parsed = patterns.map((pattern) => ({ pattern, selector: parseSelector(pattern.selector) }));
|
|
245
|
+
const matches = [];
|
|
246
|
+
for (const node of walk(parseMarkup(markup))) {
|
|
247
|
+
for (const { pattern, selector } of parsed) {
|
|
248
|
+
if (matchesSelector(selector, node))
|
|
249
|
+
matches.push({ pattern, node, index: node.index });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return matches.sort((a, b) => a.index - b.index);
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=anti-pattern-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-pattern-selector.js","sourceRoot":"","sources":["../../src/validate/anti-pattern-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAwBH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,QAAgB,EAAE,MAAc;QAC1C,KAAK,CAAC,kCAAkC,QAAQ,MAAM,MAAM,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,MAAM,GAAG,6DAA6D,CAAC;AAC7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC,SAAS,aAAa,CAAC,GAAW,EAAE,QAAgB;IAClD,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,6BAA6B,IAAI,GAAG,CAAC,CAAC;IAC7F,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CA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,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `validateSpec` (#1899): string in, verdict out. One implementation that runs
|
|
3
|
+
* in the browser before paint and on the server inside the composer's loop,
|
|
4
|
+
* and behind the Brain's `eddie_validate_spec` tool.
|
|
5
|
+
*
|
|
6
|
+
* Checks, in order: root, unknown nodes, dangling ids and cycles, containment
|
|
7
|
+
* (`allowedParents` / `allowedChildren` where the catalog declares them),
|
|
8
|
+
* props (required, enums, scalar types, unknown), named slots, the graph's
|
|
9
|
+
* anti-patterns evaluated on the expanded tree with the same selector core
|
|
10
|
+
* `eddie_validate_file` uses, and a few tree-level accessibility pre-checks.
|
|
11
|
+
*
|
|
12
|
+
* Severity policy (FEATURE-SPEC Q4): any `error` refuses; `warning` renders
|
|
13
|
+
* and is reported. Lossless fixes (`autoFix`) only relocate misplaced fields;
|
|
14
|
+
* nothing that drops content is ever applied silently.
|
|
15
|
+
*/
|
|
16
|
+
import { type Catalog, type Spec, type ValidationIssue, type ValidationResult } from '../types.js';
|
|
17
|
+
export * from './anti-pattern-selector.js';
|
|
18
|
+
export type { AntiPattern, Catalog, CatalogComponent, EddieExtensions, IssueCode, JsonSchema, Spec, SpecElement, ValidationIssue, ValidationResult, } from '../types.js';
|
|
19
|
+
export interface ValidateOptions {
|
|
20
|
+
/** Apply lossless fixes and return the fixed spec. Default false. */
|
|
21
|
+
autoFix?: boolean;
|
|
22
|
+
/** Treat dangling child ids as pending (a stream in flight) rather than errors. Default false. */
|
|
23
|
+
streaming?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function validateSpec(input: Spec | string, catalog: Catalog, options?: ValidateOptions): ValidationResult;
|
|
26
|
+
/** A2UI `error` messages for every error-severity issue, ready to send back to the agent. */
|
|
27
|
+
export declare function toA2uiErrors(issues: ValidationIssue[], surfaceId: string): Array<{
|
|
28
|
+
version: 'v1.0';
|
|
29
|
+
error: {
|
|
30
|
+
code: 'VALIDATION_FAILED' | 'UNALLOWED_PARENT' | 'UNALLOWED_CHILD';
|
|
31
|
+
surfaceId: string;
|
|
32
|
+
path?: string;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAA4B,KAAK,OAAO,EAAyB,KAAK,IAAI,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpJ,cAAc,4BAA4B,CAAC;AAC3C,YAAY,EACV,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kGAAkG;IAClG,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAID,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,GAAG,gBAAgB,CAqSpH;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe,EAAE,EACzB,SAAS,EAAE,MAAM,GAChB,KAAK,CAAC;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QAAE,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAClI,CAAC,CAYD"}
|