mount-observer 0.1.13 → 0.1.15
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/Events.js +9 -0
- package/Events.ts +12 -0
- package/MountObserver.js +21 -0
- package/MountObserver.ts +27 -0
- package/README.md +406 -69
- package/{DefineCustomElementHandler.js → handlers/DefineCustomElement.js} +103 -99
- package/handlers/DefineCustomElement.ts +123 -0
- package/handlers/EnhanceMountedElement.js +99 -0
- package/handlers/EnhanceMountedElement.ts +116 -0
- package/handlers/Events.js +110 -0
- package/handlers/EvtRt.js +59 -0
- package/handlers/GenIds.js +37 -0
- package/handlers/GenIds.ts +45 -0
- package/handlers/HTMLInclude.js +393 -0
- package/handlers/HTMLInclude.ts +453 -0
- package/handlers/HoistTemplate.js +77 -0
- package/handlers/HoistTemplate.ts +89 -0
- package/handlers/MountObserver.js +941 -0
- package/handlers/MountObserverScript.js +78 -0
- package/handlers/MountObserverScript.ts +89 -0
- package/handlers/ScriptExport.js +83 -0
- package/handlers/ScriptExport.ts +97 -0
- package/handlers/SharedMutationObserver.js +78 -0
- package/handlers/arr.js +16 -0
- package/handlers/connectionMonitor.js +122 -0
- package/handlers/elementIntersection.js +73 -0
- package/handlers/emitEvents.js +187 -0
- package/handlers/getRegistryRoot.js +52 -0
- package/handlers/loadImports.js +129 -0
- package/handlers/mediaQuery.js +90 -0
- package/handlers/rootSizeObserver.js +131 -0
- package/handlers/upShadowSearch.js +70 -0
- package/handlers/withScopePerimeter.js +22 -0
- package/index.js +2 -2
- package/index.ts +2 -2
- package/package.json +13 -3
- package/types/assign-gingerly/types.d.ts +244 -0
- package/types/be-a-beacon/types.d.ts +3 -0
- package/types/global.d.ts +29 -0
- package/types/id-generation/types.d.ts +26 -0
- package/types/mount-observer/types.d.ts +330 -0
- package/upShadowSearch.js +6 -3
- package/upShadowSearch.ts +6 -3
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { arr } from './arr.js';
|
|
|
6
6
|
export { EvtRt } from './EvtRt.js';
|
|
7
7
|
export { DefineCustomElementHandler, DefineScopedCustomElementHandler } from './handlers/DefineCustomElement.js';
|
|
8
8
|
export { EnhanceMountedElementHandler } from './handlers/EnhanceMountedElement.js';
|
|
9
|
-
export {
|
|
9
|
+
export { ScriptExportHandler } from './handlers/ScriptExport.js';
|
|
10
10
|
export { MountObserverScriptHandler } from './handlers/MountObserverScript.js';
|
|
11
11
|
export { HoistTemplateHandler } from './handlers/HoistTemplate.js';
|
|
12
12
|
export { HTMLIncludeHandler } from './handlers/HTMLInclude.js';
|
|
@@ -17,7 +17,7 @@ import './EvtRt.js';
|
|
|
17
17
|
import './handlers/DefineCustomElement.js';
|
|
18
18
|
import './handlers/EnhanceMountedElement.js';
|
|
19
19
|
import './handlers/GenIds.js'; // Temporarily disabled due to missing dependency
|
|
20
|
-
import './handlers/
|
|
20
|
+
import './handlers/ScriptExport.js';
|
|
21
21
|
import './handlers/MountObserverScript.js';
|
|
22
22
|
import './handlers/HoistTemplate.js';
|
|
23
23
|
import './handlers/HTMLInclude.js';
|
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { arr } from './arr.js';
|
|
|
6
6
|
export { EvtRt } from './EvtRt.js';
|
|
7
7
|
export { DefineCustomElementHandler, DefineScopedCustomElementHandler } from './handlers/DefineCustomElement.js';
|
|
8
8
|
export { EnhanceMountedElementHandler } from './handlers/EnhanceMountedElement.js';
|
|
9
|
-
export {
|
|
9
|
+
export { ScriptExportHandler } from './handlers/ScriptExport.js';
|
|
10
10
|
export { MountObserverScriptHandler } from './handlers/MountObserverScript.js';
|
|
11
11
|
export { HoistTemplateHandler } from './handlers/HoistTemplate.js';
|
|
12
12
|
export { HTMLIncludeHandler } from './handlers/HTMLInclude.js';
|
|
@@ -35,7 +35,7 @@ import './EvtRt.js';
|
|
|
35
35
|
import './handlers/DefineCustomElement.js';
|
|
36
36
|
import './handlers/EnhanceMountedElement.js';
|
|
37
37
|
import './handlers/GenIds.js'; // Temporarily disabled due to missing dependency
|
|
38
|
-
import './handlers/
|
|
38
|
+
import './handlers/ScriptExport.js';
|
|
39
39
|
import './handlers/MountObserverScript.js';
|
|
40
40
|
import './handlers/HoistTemplate.js';
|
|
41
41
|
import './handlers/HTMLInclude.js';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"assign-gingerly": "0.0.
|
|
8
|
+
"assign-gingerly": "0.0.23",
|
|
9
9
|
"id-generation": "0.0.4"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
@@ -48,11 +48,21 @@
|
|
|
48
48
|
"./upShadowSearch.js": {
|
|
49
49
|
"default": "./upShadowSearch.js",
|
|
50
50
|
"types": "./upShadowSearch.ts"
|
|
51
|
+
},
|
|
52
|
+
"./handlers/*": {
|
|
53
|
+
"default": "./handlers/*"
|
|
51
54
|
}
|
|
52
55
|
},
|
|
53
56
|
"files": [
|
|
54
57
|
"*.js",
|
|
55
|
-
"*.ts"
|
|
58
|
+
"*.ts",
|
|
59
|
+
"handlers/**/*.js",
|
|
60
|
+
"handlers/**/*.ts",
|
|
61
|
+
"types/**/*.d.ts",
|
|
62
|
+
"refid/**/*.js",
|
|
63
|
+
"refid/**/*.ts",
|
|
64
|
+
"slotkin/**/*.js",
|
|
65
|
+
"slotkin/**/*.ts"
|
|
56
66
|
],
|
|
57
67
|
"types": "./types/mount-observer/types.d.ts",
|
|
58
68
|
"scripts": {
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
export type EnhKey = string | symbol;
|
|
2
|
+
|
|
3
|
+
// type NoUnderscore<T extends string> = T extends `_${string}` ? never : T;
|
|
4
|
+
|
|
5
|
+
// type YesUnderscore = `_${string}`;
|
|
6
|
+
|
|
7
|
+
// export type StringWithAutocompleteOptions<TOptions> =
|
|
8
|
+
// | (string & {})
|
|
9
|
+
// | TOptions;
|
|
10
|
+
|
|
11
|
+
// export type StringNotStartWithUnderscoreAutocompleteOptions<TOptions> =
|
|
12
|
+
// | (NoUnderscore<string> & {})
|
|
13
|
+
// | TOptions;
|
|
14
|
+
|
|
15
|
+
// export type StringStartWithUnderscoreAutocompleteOptions<TOptions> =
|
|
16
|
+
// | (YesUnderscore & {})
|
|
17
|
+
// | TOptions;
|
|
18
|
+
|
|
19
|
+
//used by mount-observer, not by assign-gingerly
|
|
20
|
+
type DisposeEvent =
|
|
21
|
+
| 'disconnect'
|
|
22
|
+
| 'dismount'
|
|
23
|
+
// cannot polyfill
|
|
24
|
+
| 'exit' // element moved outside customElementRegistry
|
|
25
|
+
//reference count outside any enhancements goes to zero
|
|
26
|
+
| 'dispose'
|
|
27
|
+
|
|
28
|
+
export type Spawner<T = any, Obj = Element> = {
|
|
29
|
+
new (obj?: Obj, ctx?: SpawnContext<T>, initVals?: Partial<T>): T;
|
|
30
|
+
canSpawn?: (obj: any, ctx?: SpawnContext<T>) => boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration for enhancing elements with class instances
|
|
35
|
+
* Defines how to spawn and initialize enhancement classes
|
|
36
|
+
*/
|
|
37
|
+
export interface EnhancementConfig<T = any, Obj = Element> {
|
|
38
|
+
|
|
39
|
+
spawn: Spawner<T, Obj>;
|
|
40
|
+
|
|
41
|
+
//Applicable to passing in the initVals during the spawn lifecycle event
|
|
42
|
+
withAttrs?: AttrPatterns<T>;
|
|
43
|
+
|
|
44
|
+
//Allow unprefixed attributes for custom elements and SVG when element tag name matches pattern
|
|
45
|
+
allowUnprefixed?: string | RegExp;
|
|
46
|
+
|
|
47
|
+
//keys of type symbol are used for dependency injection
|
|
48
|
+
//and are used by assign-gingerly
|
|
49
|
+
symlinks?: { [key: symbol]: keyof T };
|
|
50
|
+
//only applicable when spawning from a DOM Element reference
|
|
51
|
+
enhKey?: EnhKey;
|
|
52
|
+
lifecycleKeys?:
|
|
53
|
+
| true // Use standard names: "dispose" method, "resolved" property/event
|
|
54
|
+
| {
|
|
55
|
+
dispose?: string | symbol,
|
|
56
|
+
resolved?: string | symbol
|
|
57
|
+
}
|
|
58
|
+
//used by mount-observer, not by assign-gingerly
|
|
59
|
+
//impossible to polyfill, but will always be disposed
|
|
60
|
+
//when oElement's reference count goes to zero
|
|
61
|
+
disposeOn?: DisposeEvent | DisposeEvent[]
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type Constructor = new (...args: any[]) => any;
|
|
66
|
+
|
|
67
|
+
export type pathString = `?.${string}`;
|
|
68
|
+
|
|
69
|
+
export type CustomElementName = string;
|
|
70
|
+
export type CustomElementConstructorStaticMethodName = string;
|
|
71
|
+
|
|
72
|
+
export interface AttrConfig<T = any> {
|
|
73
|
+
/**
|
|
74
|
+
* Type of the property value (JSON-serializable string format)
|
|
75
|
+
*/
|
|
76
|
+
instanceOf?: 'Object' | 'String' | 'Number' | 'Boolean' | 'Array'
|
|
77
|
+
| typeof Object | typeof String | typeof Number | typeof Boolean | typeof Array;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Property name on the spawned class instance to map to
|
|
82
|
+
* Use '.' to map to the root object using assignGingerly
|
|
83
|
+
* Is optional.
|
|
84
|
+
* If not specified, we assume it is the key without the underscore first
|
|
85
|
+
* character, unless the key is _base in which case it assume mapsTo = "."
|
|
86
|
+
*/
|
|
87
|
+
mapsTo?:
|
|
88
|
+
| '.'
|
|
89
|
+
| keyof T
|
|
90
|
+
| pathString
|
|
91
|
+
| `${pathString} +=`
|
|
92
|
+
| `${pathString} =!`
|
|
93
|
+
| `${pathString} -=`
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parser to transform attribute string value
|
|
97
|
+
* - Function: Inline parser function (not JSON serializable)
|
|
98
|
+
* - String: Named parser reference (JSON serializable) - looks up in global parser registry (e.g., 'timestamp', 'csv')
|
|
99
|
+
* - Tuple: [CustomElementName, StaticMethodName] - looks up static method on custom element constructor (e.g., ['my-widget', 'parseSpecial'])
|
|
100
|
+
*/
|
|
101
|
+
parser?:
|
|
102
|
+
| ((attrValue: string | null) => any)
|
|
103
|
+
| string
|
|
104
|
+
| [CustomElementName, CustomElementConstructorStaticMethodName]
|
|
105
|
+
;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Default value to use when attribute is missing
|
|
109
|
+
* If defined, bypasses parser when attribute is not present
|
|
110
|
+
* If undefined, property is not added to initVals when attribute is missing
|
|
111
|
+
*/
|
|
112
|
+
valIfNull?: any;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Enable caching of parsed attribute values
|
|
116
|
+
* - 'shared': Cache and reuse the same parsed object (fast, but enhancements must not mutate)
|
|
117
|
+
* - 'cloned': Cache and return a structural clone (safer, but slower)
|
|
118
|
+
* Note: Parsers should be pure functions when using caching
|
|
119
|
+
*/
|
|
120
|
+
parseCache?: 'shared' | 'cloned';
|
|
121
|
+
|
|
122
|
+
// /**
|
|
123
|
+
// * Whether to only read the initial value (true) or continue observing changes (false)
|
|
124
|
+
// * Defaults to true (initial read only)
|
|
125
|
+
// */
|
|
126
|
+
// initialOnly?: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type AttrPatterns<T = any> = {
|
|
130
|
+
/**
|
|
131
|
+
* Base prefix for attribute names
|
|
132
|
+
*/
|
|
133
|
+
base: string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Configuration for the base pattern
|
|
137
|
+
*/
|
|
138
|
+
_base?: AttrConfig<T>;
|
|
139
|
+
} & {
|
|
140
|
+
// Provide autocomplete for all properties of T (optional)
|
|
141
|
+
[K in keyof T]?: string | AttrConfig<T>;
|
|
142
|
+
} & {
|
|
143
|
+
// Provide autocomplete for underscore-prefixed config keys
|
|
144
|
+
[K in keyof T as `_${string & K}`]?: AttrConfig<T>;
|
|
145
|
+
} & {
|
|
146
|
+
// Allow any other string keys for custom patterns
|
|
147
|
+
[key: string]: string | AttrConfig<T>;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
export interface SpawnContext<T = any, TMountContext = any> {
|
|
152
|
+
config: EnhancementConfig<T>;
|
|
153
|
+
mountCtx?: TMountContext;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use EnhancementConfig instead
|
|
158
|
+
*/
|
|
159
|
+
export type IEnhancementRegistryItem<T = any> = EnhancementConfig<T>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Interface for the options passed to assignGingerly
|
|
163
|
+
*/
|
|
164
|
+
export interface IAssignGingerlyOptions {
|
|
165
|
+
registry?: typeof EnhancementRegistry | EnhancementRegistry;
|
|
166
|
+
bypassChecks?: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Event dispatched when enhancement configs are registered
|
|
171
|
+
*/
|
|
172
|
+
export declare class EnhancementRegisteredEvent extends Event {
|
|
173
|
+
static eventName: string;
|
|
174
|
+
config: EnhancementConfig | EnhancementConfig[];
|
|
175
|
+
constructor(config: EnhancementConfig | EnhancementConfig[]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Base registry class for managing enhancement configurations
|
|
180
|
+
* Extends EventTarget to dispatch events when configs are registered
|
|
181
|
+
*/
|
|
182
|
+
export declare class EnhancementRegistry extends EventTarget {
|
|
183
|
+
private items;
|
|
184
|
+
push(items: EnhancementConfig | EnhancementConfig[]): void;
|
|
185
|
+
getItems(): EnhancementConfig[];
|
|
186
|
+
findBySymbol(symbol: symbol | string): EnhancementConfig | undefined;
|
|
187
|
+
findByEnhKey(enhKey: string | symbol): EnhancementConfig | undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Constructor signature for ItemScope Manager classes
|
|
192
|
+
*/
|
|
193
|
+
export type ItemscopeManager<T = any> = {
|
|
194
|
+
new (element: HTMLElement, initVals?: Partial<T>): T;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Configuration for ItemScope Manager registration
|
|
199
|
+
*/
|
|
200
|
+
export interface ItemscopeManagerConfig<T = any> {
|
|
201
|
+
/**
|
|
202
|
+
* Manager class constructor
|
|
203
|
+
*/
|
|
204
|
+
manager: ItemscopeManager<T>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Optional lifecycle method keys
|
|
208
|
+
* - dispose: Method name to call when manager is disposed
|
|
209
|
+
* - resolved: Property/event name indicating manager is ready
|
|
210
|
+
*/
|
|
211
|
+
lifecycleKeys?: {
|
|
212
|
+
dispose?: string | symbol;
|
|
213
|
+
resolved?: string | symbol;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Registry for ItemScope Manager configurations
|
|
219
|
+
* Extends EventTarget to support lazy registration via events
|
|
220
|
+
*/
|
|
221
|
+
export declare class ItemscopeRegistry extends EventTarget {
|
|
222
|
+
define(name: string, config: ItemscopeManagerConfig): void;
|
|
223
|
+
get(name: string): ItemscopeManagerConfig | undefined;
|
|
224
|
+
whenDefined(name: string): Promise<void>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Main assignGingerly function
|
|
229
|
+
*/
|
|
230
|
+
export declare function assignGingerly(
|
|
231
|
+
target: any,
|
|
232
|
+
source: Record<string | symbol, any>,
|
|
233
|
+
options?: IAssignGingerlyOptions
|
|
234
|
+
): any;
|
|
235
|
+
|
|
236
|
+
export default assignGingerly;
|
|
237
|
+
|
|
238
|
+
export declare class ElementEnhancementGateway{
|
|
239
|
+
enh: ElementEnhancement;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface ElementEnhancement{
|
|
243
|
+
dispose(regItem: EnhancementConfig): void;
|
|
244
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Type declarations for Map.prototype.getOrInsertComputed and WeakMap.prototype.getOrInsertComputed
|
|
2
|
+
// Feature is now supported in all modern browsers (Chrome 146+, Firefox 134+, Safari 18.2+)
|
|
3
|
+
// See: https://web-platform-dx.github.io/web-features-explorer/features/getorinsert/
|
|
4
|
+
|
|
5
|
+
interface Map<K, V> {
|
|
6
|
+
/**
|
|
7
|
+
* Returns the value associated with the key if it exists, otherwise inserts
|
|
8
|
+
* the value returned by the insert callback and returns it.
|
|
9
|
+
* @param key The key to look up
|
|
10
|
+
* @param insert A callback that returns the value to insert if the key doesn't exist
|
|
11
|
+
* @returns The existing or newly inserted value
|
|
12
|
+
*/
|
|
13
|
+
getOrInsertComputed(key: K, insert: () => V): V;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface WeakMap<K extends object, V> {
|
|
17
|
+
/**
|
|
18
|
+
* Returns the value associated with the key if it exists, otherwise inserts
|
|
19
|
+
* the value returned by the insert callback and returns it.
|
|
20
|
+
* @param key The key to look up
|
|
21
|
+
* @param insert A callback that returns the value to insert if the key doesn't exist
|
|
22
|
+
* @returns The existing or newly inserted value
|
|
23
|
+
*/
|
|
24
|
+
getOrInsertComputed(key: K, insert: () => V): V;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface HTMLTemplateElement {
|
|
28
|
+
remoteContent?: Node;
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Type definitions for id-generation
|
|
2
|
+
|
|
3
|
+
export interface GenIdsOptions {
|
|
4
|
+
//startCounter?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ParsedDataId {
|
|
8
|
+
name: string;
|
|
9
|
+
setName: boolean;
|
|
10
|
+
setItemprop: boolean;
|
|
11
|
+
setClass: boolean;
|
|
12
|
+
setPart: boolean;
|
|
13
|
+
setItemscope: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ScopeInfo {
|
|
17
|
+
scopeElement: Element;
|
|
18
|
+
elementsToProcess: Element[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AttributeReplacement {
|
|
22
|
+
element: Element;
|
|
23
|
+
attributeName: string;
|
|
24
|
+
oldValue: string;
|
|
25
|
+
newValue: string;
|
|
26
|
+
}
|