@whenessel/seql-js 1.1.0 → 1.2.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 CHANGED
@@ -97,27 +97,35 @@ Resolution: EID → resolve() → ResolveResult
97
97
  ### SEQL Selector Functions
98
98
 
99
99
  #### `generateSEQL(element, generatorOptions?, stringifyOptions?)`
100
+
100
101
  Convenience function: `generateEID` + `stringifySEQL`. Returns a string or `null`.
101
102
 
102
103
  #### `resolveSEQL(selector, root, options?)`
104
+
103
105
  Convenience function: `parseSEQL` + `resolve`. Returns `Element[]`.
104
106
 
105
107
  #### `parseSEQL(selector)`
108
+
106
109
  Parses a SEQL Selector into an `ElementIdentity` object.
107
110
 
108
111
  #### `stringifySEQL(eid, options?)`
112
+
109
113
  Converts an `ElementIdentity` object into a canonical SEQL Selector.
110
114
 
111
115
  ### Core Functions
112
116
 
113
117
  #### `generateEID(element, options?)`
118
+
114
119
  Generates an `ElementIdentity` (EID) from a DOM element.
120
+
115
121
  - `maxPathDepth`: Default 10.
116
122
  - `enableSvgFingerprint`: Default true.
117
123
  - `confidenceThreshold`: Default 0.1.
118
124
 
119
125
  #### `resolve(eid, root, options?)`
126
+
120
127
  Resolves an EID back to DOM element(s). Returns a `ResolveResult` object.
128
+
121
129
  - `status`: `'success' | 'ambiguous' | 'error' | 'degraded-fallback'`.
122
130
  - `elements`: `Element[]` of matches.
123
131
  - `confidence`: Match confidence score (0-1).
@@ -125,9 +133,11 @@ Resolves an EID back to DOM element(s). Returns a `ResolveResult` object.
125
133
  ### Utilities & Advanced
126
134
 
127
135
  #### `generateEIDBatch(elements, options?)`
136
+
128
137
  Optimized generation for multiple elements at once.
129
138
 
130
139
  #### `createEIDCache(options?)` / `getGlobalCache()`
140
+
131
141
  Manage the LRU cache to improve performance for frequent generations/resolutions.
132
142
 
133
143
  ## Project Structure
@@ -148,14 +158,20 @@ Manage the LRU cache to improve performance for frequent generations/resolutions
148
158
 
149
159
  ## Documentation
150
160
 
151
- - [Architecture Design](docs/specs/ARCHITECTURE.md)
152
- - [EID Specification v1.0](docs/specs/SPECIFICATION.md) (Russian)
153
- - [Developer Guidelines](CLAUDE.md)
154
- - [Migration Guide](docs/MIGRATION.md)
161
+ - **[Getting Started](docs/getting-started/)** - Installation and quick start guide
162
+ - **[API Reference](docs/api/)** - Complete API documentation
163
+ - **[Examples](docs/examples/)** - Practical code examples
164
+ - **[Specification](docs/specification/)** - EID and SEQL format specifications
165
+ - **[Architecture](docs/architecture/)** - System design and internals
166
+ - **[Guides](docs/guides/)** - Advanced topics and patterns
167
+ - **[Contributing](docs/contributing/)** - Development guide
168
+ - **[Troubleshooting](docs/troubleshooting/)** - Common issues and solutions
169
+ - **[CLAUDE.md](CLAUDE.md)** - AI agent development guidelines
155
170
 
156
171
  ## Migrating from v0.x
157
172
 
158
173
  If you are upgrading from v0.x, note these breaking changes:
174
+
159
175
  - `generateDsl()` → `generateEID()`
160
176
  - `resolveDsl()` → `resolve()`
161
177
  - `DslIdentity` → `ElementIdentity`
package/dist/seql-js.d.ts CHANGED
@@ -11,6 +11,11 @@ export declare class AnchorFinder {
11
11
  * Finds the best anchor element for the target
12
12
  * @param target - Target element to find anchor for
13
13
  * @returns Anchor result or null if not found
14
+ * @remarks
15
+ * Special handling for root elements (html, head, body):
16
+ * - For html: returns html itself as anchor
17
+ * - For head or elements inside head: returns html as anchor
18
+ * - For body: returns html as anchor
14
19
  */
15
20
  findAnchor(target: Element): AnchorResult | null;
16
21
  /**
@@ -28,6 +33,25 @@ export declare class AnchorFinder {
28
33
  * Determines the tier of an anchor element
29
34
  */
30
35
  private getTier;
36
+ /**
37
+ * Checks if element is inside <head> section.
38
+ * Stops at <body> to avoid false positives.
39
+ * @param element - Element to check
40
+ * @returns True if element is inside head, false otherwise
41
+ * @remarks
42
+ * Traverses up the DOM tree until finding head or body.
43
+ * Returns false if body is encountered first.
44
+ * @example
45
+ * const meta = document.querySelector('meta');
46
+ * if (isInsideHead(meta)) { ... }
47
+ */
48
+ private isInsideHead;
49
+ /**
50
+ * Caches the anchor result for the target element
51
+ * @param target - Target element
52
+ * @param result - Anchor result to cache
53
+ */
54
+ private cacheResult;
31
55
  }
32
56
 
33
57
  /**
@@ -400,6 +424,20 @@ export declare class CssGenerator {
400
424
  * @returns True if element is an SVG child
401
425
  */
402
426
  private isSvgChildElement;
427
+ /**
428
+ * Builds CSS selector for elements inside <head>.
429
+ * Uses child combinator (>) for strict structure: html > head > ... > target
430
+ * @param eid - Element Identity with anchor=html and path[0]=head
431
+ * @param options - Optional uniqueness control settings
432
+ * @returns CSS selector string or BuildSelectorResult
433
+ * @remarks
434
+ * This method handles the special case where elements are inside <head>.
435
+ * The selector always uses child combinators for strict parent-child relationships.
436
+ * @example
437
+ * For <html><head><meta name="description"></head></html>
438
+ * Returns: "html > head > meta[name='description']"
439
+ */
440
+ private buildHeadSelector;
403
441
  }
404
442
 
405
443
  /**
@@ -774,6 +812,10 @@ export declare class PathBuilder {
774
812
  * @param target - Target element (end)
775
813
  * @param extractor - Semantic extractor instance
776
814
  * @returns Path build result with nodes and degradation info
815
+ * @remarks
816
+ * Special handling for root elements:
817
+ * - If anchor is html and target is head/body: returns empty path
818
+ * - If anchor is html and target is inside head: builds path through head
777
819
  */
778
820
  buildPath(anchor: Element, target: Element, extractor: SemanticExtractor): PathBuildResult;
779
821
  /**
@@ -809,6 +851,28 @@ export declare class PathBuilder {
809
851
  * Checks if element has meaningful semantic features
810
852
  */
811
853
  private hasSemanticFeatures;
854
+ /**
855
+ * Checks if element is inside <head> section.
856
+ * Stops at <body> to avoid false positives.
857
+ * @param element - Element to check
858
+ * @returns True if element is inside head, false otherwise
859
+ * @remarks
860
+ * Traverses up the DOM tree until finding head or body.
861
+ * Returns false if body is encountered first.
862
+ */
863
+ private isInsideHead;
864
+ /**
865
+ * Builds path from html to target through head element.
866
+ * Always includes head in the path for correct CSS selector generation.
867
+ * @param htmlElement - The html element (anchor)
868
+ * @param target - Target element inside head
869
+ * @param extractor - Semantic extractor instance
870
+ * @returns Path build result with head and intermediate nodes
871
+ * @example
872
+ * For <html><head><meta name="description"></head></html>
873
+ * Returns path: [head]
874
+ */
875
+ private buildHeadPath;
812
876
  }
813
877
 
814
878
  /**
@@ -1154,8 +1218,7 @@ export declare class SvgFingerprinter {
1154
1218
  /**
1155
1219
  * Target node - the element being identified
1156
1220
  */
1157
- export declare interface TargetNode extends PathNode {
1158
- }
1221
+ export declare type TargetNode = PathNode;
1159
1222
 
1160
1223
  /**
1161
1224
  * Text content with normalization