mount-observer 0.1.15 → 0.1.17
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/ElementMountExtension.js +5 -2
- package/ElementMountExtension.ts +7 -2
- package/MountObserver.js +3 -0
- package/MountObserver.ts +3 -0
- package/RegistryMountCoordinator.js +5 -5
- package/RegistryMountCoordinator.ts +8 -6
- package/handlers/EnhanceMountedElement.js +10 -0
- package/handlers/EnhanceMountedElement.ts +10 -0
- package/handlers/GenIds.js +2 -1
- package/handlers/GenIds.ts +2 -1
- package/handlers/HTMLInclude.js +2 -1
- package/handlers/HTMLInclude.ts +3 -1
- package/handlers/HoistTemplate.js +2 -1
- package/handlers/HoistTemplate.ts +3 -1
- package/handlers/MountObserverScript.js +4 -3
- package/handlers/MountObserverScript.ts +6 -3
- package/handlers/ScriptExport.js +2 -1
- package/handlers/ScriptExport.ts +3 -1
- package/package.json +1 -1
- package/types/mount-observer/types.d.ts +2 -0
- package/EnhanceMountedElementHandler.js +0 -96
- package/handlers/Events.js +0 -110
- package/handlers/EvtRt.js +0 -59
- package/handlers/MountObserver.js +0 -941
- package/handlers/SharedMutationObserver.js +0 -78
- package/handlers/arr.js +0 -16
- package/handlers/connectionMonitor.js +0 -122
- package/handlers/emitEvents.js +0 -187
- package/handlers/getRegistryRoot.js +0 -52
- package/handlers/loadImports.js +0 -129
- package/handlers/mediaQuery.js +0 -90
- package/handlers/rootSizeObserver.js +0 -131
- package/handlers/upShadowSearch.js +0 -70
- package/handlers/withScopePerimeter.js +0 -22
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Manages shared MutationObserver instances for multiple MountObserver instances
|
|
4
|
-
* observing the same root node. This reduces overhead when multiple observers
|
|
5
|
-
* are watching the same DOM fragment.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.registerSharedObserver = registerSharedObserver;
|
|
9
|
-
exports.unregisterSharedObserver = unregisterSharedObserver;
|
|
10
|
-
/**
|
|
11
|
-
* Global registry of shared observers, keyed by root node
|
|
12
|
-
*/
|
|
13
|
-
var sharedObservers = new WeakMap();
|
|
14
|
-
/**
|
|
15
|
-
* Registers a callback with the shared MutationObserver for the given root node.
|
|
16
|
-
* Creates a new shared observer if one doesn't exist for this root.
|
|
17
|
-
*/
|
|
18
|
-
function registerSharedObserver(rootNode, callback, config) {
|
|
19
|
-
var sharedData = sharedObservers.get(rootNode);
|
|
20
|
-
if (!sharedData) {
|
|
21
|
-
// Create shared data structure first
|
|
22
|
-
sharedData = {
|
|
23
|
-
observer: null, // Will be set immediately below
|
|
24
|
-
callbacks: new Set(),
|
|
25
|
-
config: config
|
|
26
|
-
};
|
|
27
|
-
// Create new shared observer for this root node
|
|
28
|
-
var observer = new MutationObserver(function (mutations) {
|
|
29
|
-
// Distribute mutations to all registered callbacks
|
|
30
|
-
var callbacks = sharedData.callbacks;
|
|
31
|
-
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
|
|
32
|
-
var cb = callbacks_1[_i];
|
|
33
|
-
cb(mutations);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
sharedData.observer = observer;
|
|
37
|
-
sharedObservers.set(rootNode, sharedData);
|
|
38
|
-
// Start observing after everything is set up
|
|
39
|
-
observer.observe(rootNode, config);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// Verify config matches (for safety)
|
|
43
|
-
// In practice, all MountObservers should use the same config
|
|
44
|
-
if (!configsMatch(sharedData.config, config)) {
|
|
45
|
-
console.warn('MutationObserver config mismatch detected. Using existing config.');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Register the callback
|
|
49
|
-
sharedData.callbacks.add(callback);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Unregisters a callback from the shared MutationObserver.
|
|
53
|
-
* If this was the last callback, disconnects and removes the shared observer.
|
|
54
|
-
*/
|
|
55
|
-
function unregisterSharedObserver(rootNode, callback) {
|
|
56
|
-
var sharedData = sharedObservers.get(rootNode);
|
|
57
|
-
if (!sharedData) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Remove the callback
|
|
61
|
-
sharedData.callbacks.delete(callback);
|
|
62
|
-
// If no more callbacks, disconnect and cleanup
|
|
63
|
-
if (sharedData.callbacks.size === 0) {
|
|
64
|
-
sharedData.observer.disconnect();
|
|
65
|
-
sharedObservers.delete(rootNode);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Checks if two MutationObserverInit configs are equivalent
|
|
70
|
-
*/
|
|
71
|
-
function configsMatch(a, b) {
|
|
72
|
-
return a.childList === b.childList &&
|
|
73
|
-
a.subtree === b.subtree &&
|
|
74
|
-
a.attributes === b.attributes &&
|
|
75
|
-
a.attributeOldValue === b.attributeOldValue &&
|
|
76
|
-
a.characterData === b.characterData &&
|
|
77
|
-
a.characterDataOldValue === b.characterDataOldValue;
|
|
78
|
-
}
|
package/handlers/arr.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arr = arr;
|
|
4
|
-
/**
|
|
5
|
-
* Utility function to normalize a value to an array.
|
|
6
|
-
* - If undefined, returns empty array
|
|
7
|
-
* - If already an array, returns as-is
|
|
8
|
-
* - Otherwise, wraps the value in an array
|
|
9
|
-
*
|
|
10
|
-
* @param inp - Value to normalize to array
|
|
11
|
-
* @returns Array containing the value(s)
|
|
12
|
-
*/
|
|
13
|
-
function arr(inp) {
|
|
14
|
-
return inp === undefined ? []
|
|
15
|
-
: Array.isArray(inp) ? inp : [inp];
|
|
16
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupConnectionMonitor = setupConnectionMonitor;
|
|
4
|
-
var Events_js_1 = require("./Events.js");
|
|
5
|
-
function setupConnectionMonitor(init, rootNodeRef, mountedElements, modules, observer, processNode) {
|
|
6
|
-
var whereConnectionHas = init.whereConnectionHas;
|
|
7
|
-
if (!whereConnectionHas) {
|
|
8
|
-
throw new Error('whereConnectionHas is required');
|
|
9
|
-
}
|
|
10
|
-
// Get connection object with vendor prefixes
|
|
11
|
-
var nav = navigator;
|
|
12
|
-
var connection = nav.connection || nav.mozConnection || nav.webkitConnection;
|
|
13
|
-
// If Network Information API is not supported, warn and pass the condition
|
|
14
|
-
if (!connection) {
|
|
15
|
-
console.warn('Network Information API is not supported in this browser. whereConnectionHas condition will be ignored.');
|
|
16
|
-
return {
|
|
17
|
-
conditionMatches: true,
|
|
18
|
-
cleanup: function () { }
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// Check initial condition
|
|
22
|
-
var conditionMatches = evaluateConnectionCondition(connection, whereConnectionHas);
|
|
23
|
-
// Set up change listener
|
|
24
|
-
var changeHandler = function () {
|
|
25
|
-
var previousMatches = conditionMatches;
|
|
26
|
-
conditionMatches = evaluateConnectionCondition(connection, whereConnectionHas);
|
|
27
|
-
if (conditionMatches && !previousMatches) {
|
|
28
|
-
// Connection now matches - process elements
|
|
29
|
-
handleConditionMatch();
|
|
30
|
-
}
|
|
31
|
-
else if (!conditionMatches && previousMatches) {
|
|
32
|
-
// Connection no longer matches - dismount all elements
|
|
33
|
-
handleConditionUnmatch();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
function handleConditionMatch() {
|
|
37
|
-
// Process all elements in the observed node
|
|
38
|
-
var rootNode = rootNodeRef.deref();
|
|
39
|
-
if (rootNode) {
|
|
40
|
-
processNode(rootNode);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function handleConditionUnmatch() {
|
|
44
|
-
// Dismount all currently mounted elements
|
|
45
|
-
var rootNode = rootNodeRef.deref();
|
|
46
|
-
if (!rootNode) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
var context = {
|
|
50
|
-
modules: modules,
|
|
51
|
-
observer: observer,
|
|
52
|
-
rootNode: rootNode,
|
|
53
|
-
mountConfig: init
|
|
54
|
-
};
|
|
55
|
-
// Get all mounted elements from the WeakDual setWeak
|
|
56
|
-
var mountedElementsList = [];
|
|
57
|
-
for (var _i = 0, _a = mountedElements.setWeak; _i < _a.length; _i++) {
|
|
58
|
-
var ref = _a[_i];
|
|
59
|
-
var element = ref.deref();
|
|
60
|
-
if (element) {
|
|
61
|
-
mountedElementsList.push(element);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Dismount each element
|
|
65
|
-
for (var _b = 0, mountedElementsList_1 = mountedElementsList; _b < mountedElementsList_1.length; _b++) {
|
|
66
|
-
var element = mountedElementsList_1[_b];
|
|
67
|
-
// Remove from both structures
|
|
68
|
-
mountedElements.weakSet.delete(element);
|
|
69
|
-
for (var _c = 0, _d = mountedElements.setWeak; _c < _d.length; _c++) {
|
|
70
|
-
var ref = _d[_c];
|
|
71
|
-
if (ref.deref() === element) {
|
|
72
|
-
mountedElements.setWeak.delete(ref);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Dispatch dismount event with reason
|
|
77
|
-
observer.dispatchEvent(new Events_js_1.DismountEvent(element, 'connection-failed', init));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Listen for connection changes
|
|
81
|
-
connection.addEventListener('change', changeHandler);
|
|
82
|
-
return {
|
|
83
|
-
conditionMatches: conditionMatches,
|
|
84
|
-
cleanup: function () {
|
|
85
|
-
connection.removeEventListener('change', changeHandler);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Evaluate if the current connection meets the specified conditions
|
|
91
|
-
*/
|
|
92
|
-
function evaluateConnectionCondition(connection, condition) {
|
|
93
|
-
// Check effectiveType (e.g., 'slow-2g', '2g', '3g', '4g')
|
|
94
|
-
if (condition.effectiveTypeIn && condition.effectiveTypeIn.length > 0) {
|
|
95
|
-
var effectiveType = connection.effectiveType;
|
|
96
|
-
if (!effectiveType || !condition.effectiveTypeIn.includes(effectiveType)) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// Check downlink (bandwidth in Mbps)
|
|
101
|
-
if (condition.downlinkMin !== undefined) {
|
|
102
|
-
var downlink = connection.downlink;
|
|
103
|
-
if (downlink === undefined || downlink < condition.downlinkMin) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (condition.downlinkMax !== undefined) {
|
|
108
|
-
var downlink = connection.downlink;
|
|
109
|
-
if (downlink === undefined || downlink > condition.downlinkMax) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Check RTT (round-trip time in ms)
|
|
114
|
-
if (condition.rttMax !== undefined) {
|
|
115
|
-
var rtt = connection.rtt;
|
|
116
|
-
if (rtt === undefined || rtt > condition.rttMax) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// All conditions passed
|
|
121
|
-
return true;
|
|
122
|
-
}
|
package/handlers/emitEvents.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
58
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
exports.emitMountedElementEvents = emitMountedElementEvents;
|
|
60
|
-
/**
|
|
61
|
-
* Emits events from a mounted element based on the mountedElemEmits configuration.
|
|
62
|
-
* This module is dynamically loaded only when mountedElemEmits is configured.
|
|
63
|
-
*/
|
|
64
|
-
function emitMountedElementEvents(element, MountConfig, processedEventsForElement) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var configs, _i, configs_1, config;
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0:
|
|
70
|
-
configs = Array.isArray(MountConfig.mountedElemEmits)
|
|
71
|
-
? MountConfig.mountedElemEmits
|
|
72
|
-
: [MountConfig.mountedElemEmits];
|
|
73
|
-
_i = 0, configs_1 = configs;
|
|
74
|
-
_a.label = 1;
|
|
75
|
-
case 1:
|
|
76
|
-
if (!(_i < configs_1.length)) return [3 /*break*/, 4];
|
|
77
|
-
config = configs_1[_i];
|
|
78
|
-
return [4 /*yield*/, emitSingleEvent(element, MountConfig, config, processedEventsForElement)];
|
|
79
|
-
case 2:
|
|
80
|
-
_a.sent();
|
|
81
|
-
_a.label = 3;
|
|
82
|
-
case 3:
|
|
83
|
-
_i++;
|
|
84
|
-
return [3 /*break*/, 1];
|
|
85
|
-
case 4: return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function emitSingleEvent(element, MountConfig, config, processedEventsForElement) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
-
var eventId, processedEvents, EventCtor, processedArgs, event, options, assignGingerly, processedProps;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0:
|
|
96
|
-
// Check if this event should only fire once per element
|
|
97
|
-
if (config.oncePerMountedElement) {
|
|
98
|
-
eventId = getEventId(config);
|
|
99
|
-
processedEvents = processedEventsForElement.get(element);
|
|
100
|
-
if (!processedEvents) {
|
|
101
|
-
processedEvents = new Set();
|
|
102
|
-
processedEventsForElement.set(element, processedEvents);
|
|
103
|
-
}
|
|
104
|
-
if (processedEvents.has(eventId)) {
|
|
105
|
-
return [2 /*return*/]; // Already emitted for this element
|
|
106
|
-
}
|
|
107
|
-
processedEvents.add(eventId);
|
|
108
|
-
}
|
|
109
|
-
EventCtor = resolveEventConstructor(config.event);
|
|
110
|
-
processedArgs = config.args !== undefined
|
|
111
|
-
? processMagicStrings(config.args, element, MountConfig)
|
|
112
|
-
: undefined;
|
|
113
|
-
if (processedArgs === undefined) {
|
|
114
|
-
event = new EventCtor();
|
|
115
|
-
}
|
|
116
|
-
else if (Array.isArray(processedArgs)) {
|
|
117
|
-
// For array args, ensure bubbles is set if second arg is an options object
|
|
118
|
-
if (processedArgs.length === 2 && typeof processedArgs[0] === 'string' && typeof processedArgs[1] === 'object' && processedArgs[1] !== null) {
|
|
119
|
-
options = __assign({ bubbles: true }, processedArgs[1]);
|
|
120
|
-
event = new EventCtor(processedArgs[0], options);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
event = new (EventCtor.bind.apply(EventCtor, __spreadArray([void 0], processedArgs, false)))();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// Single arg - if it's a string (event name), add bubbles: true by default
|
|
128
|
-
if (typeof processedArgs === 'string') {
|
|
129
|
-
event = new EventCtor(processedArgs, { bubbles: true });
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
event = new EventCtor(processedArgs);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!config.eventProps) return [3 /*break*/, 2];
|
|
136
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require('assign-gingerly/assignGingerly.js'); })];
|
|
137
|
-
case 1:
|
|
138
|
-
assignGingerly = (_a.sent()).assignGingerly;
|
|
139
|
-
processedProps = processMagicStrings(config.eventProps, element, MountConfig);
|
|
140
|
-
assignGingerly(event, processedProps);
|
|
141
|
-
_a.label = 2;
|
|
142
|
-
case 2:
|
|
143
|
-
// Dispatch the event from the mounted element
|
|
144
|
-
element.dispatchEvent(event);
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function resolveEventConstructor(event) {
|
|
151
|
-
if (typeof event === 'string') {
|
|
152
|
-
var EventCtor = globalThis[event];
|
|
153
|
-
if (!EventCtor || typeof EventCtor !== 'function') {
|
|
154
|
-
throw new Error("Event constructor \"".concat(event, "\" not found in globalThis"));
|
|
155
|
-
}
|
|
156
|
-
return EventCtor;
|
|
157
|
-
}
|
|
158
|
-
return event;
|
|
159
|
-
}
|
|
160
|
-
function getEventId(config) {
|
|
161
|
-
var eventName = typeof config.event === 'string' ? config.event : config.event.name;
|
|
162
|
-
var argsStr = JSON.stringify(config.args || '');
|
|
163
|
-
return "".concat(eventName, ":").concat(argsStr);
|
|
164
|
-
}
|
|
165
|
-
function processMagicStrings(value, element, MountConfig) {
|
|
166
|
-
if (typeof value === 'string') {
|
|
167
|
-
if (value === '{{mountedElement}}') {
|
|
168
|
-
return element;
|
|
169
|
-
}
|
|
170
|
-
if (value === '{{MountConfig}}') {
|
|
171
|
-
return MountConfig;
|
|
172
|
-
}
|
|
173
|
-
return value;
|
|
174
|
-
}
|
|
175
|
-
if (Array.isArray(value)) {
|
|
176
|
-
return value.map(function (item) { return processMagicStrings(item, element, MountConfig); });
|
|
177
|
-
}
|
|
178
|
-
if (value && typeof value === 'object') {
|
|
179
|
-
var processed = {};
|
|
180
|
-
for (var _i = 0, _a = Object.entries(value); _i < _a.length; _i++) {
|
|
181
|
-
var _b = _a[_i], key = _b[0], val = _b[1];
|
|
182
|
-
processed[key] = processMagicStrings(val, element, MountConfig);
|
|
183
|
-
}
|
|
184
|
-
return processed;
|
|
185
|
-
}
|
|
186
|
-
return value;
|
|
187
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRegistryRoot = getRegistryRoot;
|
|
4
|
-
/**
|
|
5
|
-
* Recursively traverses up the DOM tree to find the highest node
|
|
6
|
-
* that shares the same customElementRegistry as the passed in node.
|
|
7
|
-
* This is useful for scoped custom element registries where we want to observe within the correct scope.
|
|
8
|
-
*
|
|
9
|
-
* @param node - The starting node to check
|
|
10
|
-
* @returns The highest node with matching customElementRegistry, or null if node is invalid
|
|
11
|
-
*/
|
|
12
|
-
function getRegistryRoot(node) {
|
|
13
|
-
if (!node) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
// Quick check: if root node has the same registry, return it immediately
|
|
17
|
-
var rn = node.getRootNode();
|
|
18
|
-
var customElementRegistry = node.customElementRegistry;
|
|
19
|
-
if (rn.customElementRegistry === customElementRegistry) {
|
|
20
|
-
return rn;
|
|
21
|
-
}
|
|
22
|
-
var startRegistry = node.customElementRegistry;
|
|
23
|
-
var currentNode = node;
|
|
24
|
-
var highestMatch = node;
|
|
25
|
-
while (currentNode) {
|
|
26
|
-
// Check if current node has matching customElementRegistry
|
|
27
|
-
if (currentNode.customElementRegistry === startRegistry) {
|
|
28
|
-
highestMatch = currentNode;
|
|
29
|
-
}
|
|
30
|
-
// Try to get parent element first
|
|
31
|
-
var parent_1 = currentNode.parentElement;
|
|
32
|
-
if (parent_1) {
|
|
33
|
-
currentNode = parent_1;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
// If no parent element, check for rootNode (shadow root case)
|
|
37
|
-
var root = currentNode.getRootNode();
|
|
38
|
-
if (root && root !== currentNode) {
|
|
39
|
-
// If it's a shadow root (not document), return it
|
|
40
|
-
if (root !== document) {
|
|
41
|
-
return root;
|
|
42
|
-
}
|
|
43
|
-
// If it's the document, check if it has the same registry
|
|
44
|
-
if (root.customElementRegistry === startRegistry) {
|
|
45
|
-
return root;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Reached the top
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return highestMatch;
|
|
52
|
-
}
|
package/handlers/loadImports.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Dynamic import loading utilities
|
|
3
|
-
// Only loaded when MountConfig.import is specified
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
15
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
-
function step(op) {
|
|
18
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
-
switch (op[0]) {
|
|
23
|
-
case 0: case 1: t = op; break;
|
|
24
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
-
default:
|
|
28
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
-
if (t[2]) _.ops.pop();
|
|
33
|
-
_.trys.pop(); continue;
|
|
34
|
-
}
|
|
35
|
-
op = body.call(thisArg, _);
|
|
36
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.loadImports = loadImports;
|
|
42
|
-
var arr_js_1 = require("./arr.js");
|
|
43
|
-
function loadImports(imports) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
var importArray, promises;
|
|
46
|
-
return __generator(this, function (_a) {
|
|
47
|
-
importArray = (0, arr_js_1.arr)(imports);
|
|
48
|
-
promises = importArray.map(function (imp) { return loadSingleImport(imp); });
|
|
49
|
-
return [2 /*return*/, Promise.all(promises)];
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function loadSingleImport(imp) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var url, type;
|
|
56
|
-
var _a;
|
|
57
|
-
return __generator(this, function (_b) {
|
|
58
|
-
type = 'js';
|
|
59
|
-
if (typeof imp === 'string') {
|
|
60
|
-
url = imp;
|
|
61
|
-
}
|
|
62
|
-
else if (Array.isArray(imp)) {
|
|
63
|
-
url = imp[0];
|
|
64
|
-
type = ((_a = imp[1]) === null || _a === void 0 ? void 0 : _a.type) || 'js';
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
url = imp.url;
|
|
68
|
-
type = imp.type || 'js';
|
|
69
|
-
}
|
|
70
|
-
switch (type) {
|
|
71
|
-
case 'css':
|
|
72
|
-
return [2 /*return*/, loadCSS(url)];
|
|
73
|
-
case 'json':
|
|
74
|
-
return [2 /*return*/, loadJSON(url)];
|
|
75
|
-
case 'html':
|
|
76
|
-
return [2 /*return*/, loadHTML(url)];
|
|
77
|
-
default:
|
|
78
|
-
return [2 /*return*/, Promise.resolve("".concat(url)).then(function (s) { return require(s); })];
|
|
79
|
-
}
|
|
80
|
-
return [2 /*return*/];
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function loadCSS(url) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var response, text, sheet;
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0: return [4 /*yield*/, fetch(url)];
|
|
90
|
-
case 1:
|
|
91
|
-
response = _a.sent();
|
|
92
|
-
return [4 /*yield*/, response.text()];
|
|
93
|
-
case 2:
|
|
94
|
-
text = _a.sent();
|
|
95
|
-
sheet = new CSSStyleSheet();
|
|
96
|
-
return [4 /*yield*/, sheet.replace(text)];
|
|
97
|
-
case 3:
|
|
98
|
-
_a.sent();
|
|
99
|
-
return [2 /*return*/, sheet];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function loadJSON(url) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
-
var response;
|
|
107
|
-
return __generator(this, function (_a) {
|
|
108
|
-
switch (_a.label) {
|
|
109
|
-
case 0: return [4 /*yield*/, fetch(url)];
|
|
110
|
-
case 1:
|
|
111
|
-
response = _a.sent();
|
|
112
|
-
return [2 /*return*/, response.json()];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function loadHTML(url) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var response;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0: return [4 /*yield*/, fetch(url)];
|
|
123
|
-
case 1:
|
|
124
|
-
response = _a.sent();
|
|
125
|
-
return [2 /*return*/, response.text()];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
}
|
package/handlers/mediaQuery.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupMediaQuery = setupMediaQuery;
|
|
4
|
-
var Events_js_1 = require("./Events.js");
|
|
5
|
-
function setupMediaQuery(init, rootNodeRef, mountedElements, modules, observer, processNode) {
|
|
6
|
-
var withMediaMatching = init.withMediaMatching;
|
|
7
|
-
// Create or use MediaQueryList
|
|
8
|
-
var mediaQueryList;
|
|
9
|
-
if (typeof withMediaMatching === 'string') {
|
|
10
|
-
mediaQueryList = window.matchMedia(withMediaMatching);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
mediaQueryList = withMediaMatching;
|
|
14
|
-
}
|
|
15
|
-
// Track current state
|
|
16
|
-
var mediaMatches = mediaQueryList.matches;
|
|
17
|
-
// Set up change listener
|
|
18
|
-
var mediaChangeHandler = function (e) {
|
|
19
|
-
var previousMatches = mediaMatches;
|
|
20
|
-
mediaMatches = e.matches;
|
|
21
|
-
if (e.matches && !previousMatches) {
|
|
22
|
-
// Media query now matches - wake up and process elements
|
|
23
|
-
handleMediaMatch();
|
|
24
|
-
}
|
|
25
|
-
else if (!e.matches && previousMatches) {
|
|
26
|
-
// Media query no longer matches - dismount all elements
|
|
27
|
-
handleMediaUnmatch();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
function handleMediaMatch() {
|
|
31
|
-
// Dispatch mediamatch event if requested
|
|
32
|
-
if (init.getPlayByPlay) {
|
|
33
|
-
observer.dispatchEvent(new Events_js_1.MediaMatchEvent(init));
|
|
34
|
-
}
|
|
35
|
-
// Process all elements in the observed node
|
|
36
|
-
var rootNode = rootNodeRef.deref();
|
|
37
|
-
if (rootNode) {
|
|
38
|
-
processNode(rootNode);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function handleMediaUnmatch() {
|
|
42
|
-
// Dispatch mediaunmatch event if requested
|
|
43
|
-
if (init.getPlayByPlay) {
|
|
44
|
-
observer.dispatchEvent(new Events_js_1.MediaUnmatchEvent(init));
|
|
45
|
-
}
|
|
46
|
-
// Dismount all currently mounted elements
|
|
47
|
-
var rootNode = rootNodeRef.deref();
|
|
48
|
-
if (!rootNode) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
var context = {
|
|
52
|
-
modules: modules,
|
|
53
|
-
observer: observer,
|
|
54
|
-
rootNode: rootNode,
|
|
55
|
-
mountConfig: init
|
|
56
|
-
};
|
|
57
|
-
// Get all mounted elements from the WeakDual setWeak
|
|
58
|
-
var mountedElementsList = [];
|
|
59
|
-
for (var _i = 0, _a = mountedElements.setWeak; _i < _a.length; _i++) {
|
|
60
|
-
var ref = _a[_i];
|
|
61
|
-
var element = ref.deref();
|
|
62
|
-
if (element) {
|
|
63
|
-
mountedElementsList.push(element);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Dismount each element
|
|
67
|
-
for (var _b = 0, mountedElementsList_1 = mountedElementsList; _b < mountedElementsList_1.length; _b++) {
|
|
68
|
-
var element = mountedElementsList_1[_b];
|
|
69
|
-
// Remove from both structures
|
|
70
|
-
mountedElements.weakSet.delete(element);
|
|
71
|
-
for (var _c = 0, _d = mountedElements.setWeak; _c < _d.length; _c++) {
|
|
72
|
-
var ref = _d[_c];
|
|
73
|
-
if (ref.deref() === element) {
|
|
74
|
-
mountedElements.setWeak.delete(ref);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// Dispatch dismount event with reason
|
|
79
|
-
observer.dispatchEvent(new Events_js_1.DismountEvent(element, 'media-query-failed', init));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
mediaQueryList.addEventListener('change', mediaChangeHandler);
|
|
83
|
-
return {
|
|
84
|
-
mediaQueryList: mediaQueryList,
|
|
85
|
-
mediaMatches: mediaMatches,
|
|
86
|
-
cleanup: function () {
|
|
87
|
-
mediaQueryList.removeEventListener('change', mediaChangeHandler);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|