assign-gingerly 0.0.54 → 0.0.55
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 +143 -2
- package/assignFrom.js +37 -18
- package/assignFrom.ts +62 -3
- package/assignGingerly.js +34 -1
- package/assignGingerly.ts +54 -1
- package/beVigilant.js +73 -0
- package/beVigilant.ts +85 -0
- package/enhanceAll.js +106 -0
- package/enhanceAll.ts +138 -0
- package/handlers/join.js +74 -0
- package/handlers/join.ts +80 -0
- package/handlers/lazyLoad.js +212 -0
- package/handlers/lazyLoad.ts +307 -0
- package/handlers/lazyLoadSwitch.js +58 -0
- package/handlers/lazyLoadSwitch.ts +63 -0
- package/handlers/microDataJoin.js +184 -0
- package/handlers/microDataJoin.ts +270 -0
- package/inferencer/.gitmodules +3 -0
- package/inferencer/.vscode/settings.json +2 -0
- package/inferencer/InferencedPropagator.js +230 -0
- package/inferencer/InferencedPropagator.ts +269 -0
- package/inferencer/LICENSE +21 -0
- package/inferencer/README.md +524 -0
- package/inferencer/Requirements/SupportForPropagator.md +368 -0
- package/inferencer/imports.html +7 -0
- package/inferencer/inferencer.js +254 -0
- package/inferencer/inferencer.ts +292 -0
- package/inferencer/package-lock.json +129 -0
- package/inferencer/package.json +60 -0
- package/inferencer/playwright-report/data/507ad515125e13390ea07de92f22331c913fa068.md +55 -0
- package/inferencer/playwright-report/index.html +90 -0
- package/inferencer/playwright.config.ts +54 -0
- package/inferencer/test-results/.last-run.json +6 -0
- package/inferencer/test-results/inferencer-Inferencer-Enha-535bc-inferencer-tests-in-browser-chromium/error-context.md +55 -0
- package/inferencer/tests/inferencedPropagator.html +428 -0
- package/inferencer/tests/inferencedPropagator.spec.ts +18 -0
- package/inferencer/tests/inferencer.html +355 -0
- package/inferencer/tests/inferencer.spec.ts +19 -0
- package/inferencer/tsconfig.json +19 -0
- package/inferencer/types/.kiro/specs/conversion-template/README.md +128 -0
- package/inferencer/types/.kiro/specs/conversion-template/design.md +360 -0
- package/inferencer/types/.kiro/specs/conversion-template/requirements.md +191 -0
- package/inferencer/types/.kiro/specs/conversion-template/tasks.md +174 -0
- package/inferencer/types/.kiro/steering/coding-standards.md +53 -0
- package/inferencer/types/.kiro/steering/conversion-guide.md +108 -0
- package/inferencer/types/.kiro/steering/declarative-configuration.md +108 -0
- package/inferencer/types/.kiro/steering/emc-json-serializability.md +306 -0
- package/inferencer/types/EnhancementConversionInstructions.md +1854 -0
- package/inferencer/types/LICENSE +21 -0
- package/inferencer/types/NewCustomElement.md +388 -0
- package/inferencer/types/NewCustomElementFeature.md +683 -0
- package/inferencer/types/NewEnhancementInstructions.md +705 -0
- package/inferencer/types/README.md +2 -0
- package/inferencer/types/agrace/types.d.ts +11 -0
- package/inferencer/types/assign-gingerly/types.d.ts +572 -0
- package/inferencer/types/be-a-beacon/types.d.ts +17 -0
- package/inferencer/types/be-bound/types.d.ts +66 -0
- package/inferencer/types/be-buttoned-up/types.d.ts +19 -0
- package/inferencer/types/be-calculating/types.d.ts +54 -0
- package/inferencer/types/be-clonable/types.d.ts +38 -0
- package/inferencer/types/be-committed/types.d.ts +22 -0
- package/inferencer/types/be-consoling/types.d.ts +24 -0
- package/inferencer/types/be-decked-with/types.d.ts +26 -0
- package/inferencer/types/be-delible/types.d.ts +27 -0
- package/inferencer/types/be-dispatching/types.d.ts +34 -0
- package/inferencer/types/be-evanescent/types.d.ts +20 -0
- package/inferencer/types/be-flashy/types.d.ts +21 -0
- package/inferencer/types/be-gone/types.d.ts +25 -0
- package/inferencer/types/be-observing/types.d.ts +55 -0
- package/inferencer/types/be-reflective/types.d.ts +78 -0
- package/inferencer/types/be-reformable/types.d.ts +49 -0
- package/inferencer/types/be-render-neutral/types.d.ts +32 -0
- package/inferencer/types/be-switched/types.d.ts +146 -0
- package/inferencer/types/be-typed/types.d.ts +32 -0
- package/inferencer/types/be-valued/types.d.ts +22 -0
- package/inferencer/types/data-props/types.d.ts +34 -0
- package/inferencer/types/do-inc/types.d.ts +56 -0
- package/inferencer/types/do-invoke/types.d.ts +38 -0
- package/inferencer/types/do-merge/types.d.ts +28 -0
- package/inferencer/types/do-toggle/types.d.ts +31 -0
- package/inferencer/types/face-up/types.d.ts +100 -0
- package/inferencer/types/fetch-for/types.d.ts +36 -0
- package/inferencer/types/folder-picker/types.d.ts +21 -0
- package/inferencer/types/global.d.ts +29 -0
- package/inferencer/types/id-generation/types.d.ts +26 -0
- package/inferencer/types/inferencer/types.d.ts +46 -0
- package/inferencer/types/mount-observer/types.d.ts +363 -0
- package/inferencer/types/nested-regex-groups/types.d.ts +107 -0
- package/inferencer/types/pipe-in/types.d.ts +52 -0
- package/inferencer/types/roundabout/types.d.ts +268 -0
- package/inferencer/types/soak-up/types.d.ts +40 -0
- package/inferencer/types/templ-maker/types.d.ts +43 -0
- package/inferencer/types/time-ticker/types.d.ts +62 -0
- package/inferencer/types/truth-sourcer/types.d.ts +44 -0
- package/inferencer/upSearch.js +27 -0
- package/inferencer/upSearch.ts +26 -0
- package/inferencer/withScopePerimeter.js +27 -0
- package/inferencer/withScopePerimeter.ts +33 -0
- package/inferredAssignments.js +38 -0
- package/inferredAssignments.ts +65 -0
- package/isAllowedImportPath.js +42 -0
- package/isAllowedImportPath.ts +53 -0
- package/package.json +27 -1
- package/paths.js +49 -1
- package/paths.ts +80 -1
- package/processHandlerCommands.js +19 -19
- package/processHandlerCommands.ts +10 -13
- package/resolveIdRef.js +144 -125
- package/resolveIdRef.ts +30 -0
- package/types/assign-gingerly/types.d.ts +12 -0
package/resolveIdRef.js
CHANGED
|
@@ -1,125 +1,144 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* resolveIdRef.
|
|
3
|
-
*
|
|
4
|
-
* Dynamically imported by assignFrom when `withIds` is provided or `#[x]` patterns are detected.
|
|
5
|
-
* Provides lazy, WeakRef-cached element lookups keyed by variable name.
|
|
6
|
-
*
|
|
7
|
-
* First access: runs the query against the target, auto-assigns an ID if needed, caches via WeakRef.
|
|
8
|
-
* Subsequent access: WeakRef.deref() (~10ns) or getElementById fallback (~20-100ns).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
1
|
+
/**
|
|
2
|
+
* resolveIdRef.ts — Cached element resolution via #[x] syntax.
|
|
3
|
+
*
|
|
4
|
+
* Dynamically imported by assignFrom when `withIds` is provided or `#[x]` patterns are detected.
|
|
5
|
+
* Provides lazy, WeakRef-cached element lookups keyed by variable name.
|
|
6
|
+
*
|
|
7
|
+
* First access: runs the query against the target, auto-assigns an ID if needed, caches via WeakRef.
|
|
8
|
+
* Subsequent access: WeakRef.deref() (~10ns) or getElementById fallback (~20-100ns).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Module-level cache: rootNode → Map<varName, { id, WeakRef }>
|
|
12
|
+
* WeakMap ensures cleanup when rootNode is GC'd.
|
|
13
|
+
*/
|
|
14
|
+
const idCacheMap = new WeakMap();
|
|
15
|
+
/**
|
|
16
|
+
* Counter per rootNode for generating unique IDs.
|
|
17
|
+
*/
|
|
18
|
+
const idCounterMap = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Generate a unique ID within a rootNode.
|
|
21
|
+
* Format: _ag0, _ag1, _ag2, ...
|
|
22
|
+
*/
|
|
23
|
+
function generateUniqueId(rootNode) {
|
|
24
|
+
let counter = idCounterMap.get(rootNode) ?? 0;
|
|
25
|
+
let id;
|
|
26
|
+
// Ensure uniqueness (skip if ID already exists in the document)
|
|
27
|
+
do {
|
|
28
|
+
id = `_ag${counter}`;
|
|
29
|
+
counter++;
|
|
30
|
+
} while (rootNode.getElementById?.(id));
|
|
31
|
+
idCounterMap.set(rootNode, counter);
|
|
32
|
+
return id;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve a single #[varName] reference lazily.
|
|
36
|
+
*
|
|
37
|
+
* @param varName - The variable name (e.g., 'x' from '#[x]')
|
|
38
|
+
* @param target - The target element to query against
|
|
39
|
+
* @param withIds - The withIds configuration map
|
|
40
|
+
* @returns The resolved element, or undefined if not found
|
|
41
|
+
*/
|
|
42
|
+
export function resolveIdVariable(varName, target, withIds) {
|
|
43
|
+
const config = withIds[varName];
|
|
44
|
+
if (config === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const rootNode = target.getRootNode?.() ?? target;
|
|
47
|
+
// Get or create cache for this rootNode
|
|
48
|
+
let cache = idCacheMap.get(rootNode);
|
|
49
|
+
if (!cache) {
|
|
50
|
+
cache = new Map();
|
|
51
|
+
idCacheMap.set(rootNode, cache);
|
|
52
|
+
}
|
|
53
|
+
// Check cache first
|
|
54
|
+
const cached = cache.get(varName);
|
|
55
|
+
if (cached) {
|
|
56
|
+
const el = cached.ref.deref();
|
|
57
|
+
if (el)
|
|
58
|
+
return el;
|
|
59
|
+
// WeakRef was collected — try getElementById fallback
|
|
60
|
+
const el2 = rootNode.getElementById?.(cached.id);
|
|
61
|
+
if (el2) {
|
|
62
|
+
cache.set(varName, { id: cached.id, ref: new WeakRef(el2) });
|
|
63
|
+
return el2;
|
|
64
|
+
}
|
|
65
|
+
// Element no longer exists — fall through to re-query
|
|
66
|
+
}
|
|
67
|
+
// First time or cache miss — resolve the element
|
|
68
|
+
let el = null;
|
|
69
|
+
if (typeof config === 'string') {
|
|
70
|
+
// String form: existing ID — use getElementById directly
|
|
71
|
+
el = rootNode.getElementById?.(config) ?? null;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Object form: { qry } — run querySelector against target
|
|
75
|
+
el = target.querySelector?.(config.qry) ?? null;
|
|
76
|
+
}
|
|
77
|
+
if (!el)
|
|
78
|
+
return undefined;
|
|
79
|
+
// Ensure the element has an ID
|
|
80
|
+
let id = el.id;
|
|
81
|
+
if (!id) {
|
|
82
|
+
id = generateUniqueId(rootNode);
|
|
83
|
+
el.id = id;
|
|
84
|
+
}
|
|
85
|
+
// Cache it
|
|
86
|
+
cache.set(varName, { id, ref: new WeakRef(el) });
|
|
87
|
+
return el;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if a key starts with #[...] syntax.
|
|
91
|
+
*/
|
|
92
|
+
export function hasIdRef(key) {
|
|
93
|
+
return key.startsWith('#[');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Extract the variable name and remaining path from a #[x]... key.
|
|
97
|
+
* Returns [varName, remainingPath] or null if not a valid #[x] reference.
|
|
98
|
+
*
|
|
99
|
+
* Examples:
|
|
100
|
+
* '#[x]' → ['x', '']
|
|
101
|
+
* '#[x] =>' → ['x', ''] (handler suffix handled separately)
|
|
102
|
+
* '#[x]?.querySelector?..child' → ['x', '?.querySelector?..child']
|
|
103
|
+
* '#[x]?.textContent =>' → ['x', '?.textContent'] (handler suffix handled separately)
|
|
104
|
+
*/
|
|
105
|
+
export function parseIdRef(key) {
|
|
106
|
+
const closeIdx = key.indexOf(']');
|
|
107
|
+
if (closeIdx === -1)
|
|
108
|
+
return null;
|
|
109
|
+
const varName = key.substring(2, closeIdx); // skip '#['
|
|
110
|
+
if (!varName)
|
|
111
|
+
return null;
|
|
112
|
+
let remainingPath = key.substring(closeIdx + 1);
|
|
113
|
+
// Remove handler suffix if present (caller handles it separately)
|
|
114
|
+
if (remainingPath.endsWith(' =>')) {
|
|
115
|
+
remainingPath = remainingPath.substring(0, remainingPath.length - 3);
|
|
116
|
+
}
|
|
117
|
+
return { varName, remainingPath };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Register an element in the WeakRef cache for fast subsequent access.
|
|
121
|
+
* Auto-assigns an ID if the element doesn't have one.
|
|
122
|
+
*
|
|
123
|
+
* Used by beVigilant to cache newly discovered elements so that future
|
|
124
|
+
* assignFrom calls can resolve them via getElementById/WeakRef.
|
|
125
|
+
*
|
|
126
|
+
* @param target - The target element (used to determine rootNode)
|
|
127
|
+
* @param varName - The cache key (typically the itemprop name)
|
|
128
|
+
* @param element - The element to cache
|
|
129
|
+
*/
|
|
130
|
+
export function registerInCache(target, varName, element) {
|
|
131
|
+
const rootNode = target.getRootNode?.() ?? target;
|
|
132
|
+
let cache = idCacheMap.get(rootNode);
|
|
133
|
+
if (!cache) {
|
|
134
|
+
cache = new Map();
|
|
135
|
+
idCacheMap.set(rootNode, cache);
|
|
136
|
+
}
|
|
137
|
+
// Ensure the element has an ID
|
|
138
|
+
let id = element.id;
|
|
139
|
+
if (!id) {
|
|
140
|
+
id = generateUniqueId(rootNode);
|
|
141
|
+
element.id = id;
|
|
142
|
+
}
|
|
143
|
+
cache.set(varName, { id, ref: new WeakRef(element) });
|
|
144
|
+
}
|
package/resolveIdRef.ts
CHANGED
|
@@ -138,3 +138,33 @@ export function parseIdRef(key: string): { varName: string; remainingPath: strin
|
|
|
138
138
|
|
|
139
139
|
return { varName, remainingPath };
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Register an element in the WeakRef cache for fast subsequent access.
|
|
144
|
+
* Auto-assigns an ID if the element doesn't have one.
|
|
145
|
+
*
|
|
146
|
+
* Used by beVigilant to cache newly discovered elements so that future
|
|
147
|
+
* assignFrom calls can resolve them via getElementById/WeakRef.
|
|
148
|
+
*
|
|
149
|
+
* @param target - The target element (used to determine rootNode)
|
|
150
|
+
* @param varName - The cache key (typically the itemprop name)
|
|
151
|
+
* @param element - The element to cache
|
|
152
|
+
*/
|
|
153
|
+
export function registerInCache(target: any, varName: string, element: Element): void {
|
|
154
|
+
const rootNode = target.getRootNode?.() ?? target;
|
|
155
|
+
|
|
156
|
+
let cache = idCacheMap.get(rootNode);
|
|
157
|
+
if (!cache) {
|
|
158
|
+
cache = new Map();
|
|
159
|
+
idCacheMap.set(rootNode, cache);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Ensure the element has an ID
|
|
163
|
+
let id = element.id;
|
|
164
|
+
if (!id) {
|
|
165
|
+
id = generateUniqueId(rootNode);
|
|
166
|
+
element.id = id;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
cache.set(varName, { id, ref: new WeakRef(element) });
|
|
170
|
+
}
|
|
@@ -64,6 +64,12 @@ export interface EnhancementConfig<T = any, Obj = Element> extends EnhancementCo
|
|
|
64
64
|
|
|
65
65
|
//only applicable when spawning from a DOM Element reference
|
|
66
66
|
enhKey?: EnhKey;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Optional features to associate with the spawn class.
|
|
70
|
+
* Calls assignFeatures(spawn, features) automatically on registration.
|
|
71
|
+
*/
|
|
72
|
+
features?: FeatureConfigsMap;
|
|
67
73
|
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -300,6 +306,12 @@ export interface ItemscopeManagerConfig<T = any> {
|
|
|
300
306
|
dispose?: string | symbol;
|
|
301
307
|
resolved?: string | symbol;
|
|
302
308
|
};
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Optional features to associate with the manager class.
|
|
312
|
+
* Calls assignFeatures(manager, features) automatically on registration.
|
|
313
|
+
*/
|
|
314
|
+
features?: FeatureConfigsMap;
|
|
303
315
|
}
|
|
304
316
|
|
|
305
317
|
/**
|