@namiml/web-sdk 3.4.0-dev.202605201800 → 3.4.0-dev.202605261547
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/dist/components/NamiElement.d.ts +1 -0
- package/dist/components/Paywall.d.ts +2 -0
- package/dist/components/PaywallScreen.d.ts +3 -0
- package/dist/components/elements/Button.d.ts +3 -6
- package/dist/components/elements/PlayPauseButton.d.ts +0 -1
- package/dist/components/elements/SegmentPickerItem.d.ts +0 -1
- package/dist/components/elements/ToggleButton.d.ts +0 -1
- package/dist/components/elements/VolumeButton.d.ts +0 -1
- package/dist/legacy-support.cjs +441 -231
- package/dist/legacy-support.mjs +441 -231
- package/dist/nami-web.cjs +27 -27
- package/dist/nami-web.d.ts +7 -10
- package/dist/nami-web.mjs +27 -27
- package/dist/nami-web.umd.js +27 -27
- package/dist/utils/tts.d.ts +52 -69
- package/package.json +3 -4
- package/CHANGELOG.md +0 -400
package/dist/legacy-support.mjs
CHANGED
|
@@ -2164,217 +2164,14 @@ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) ||
|
|
|
2164
2164
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2165
2165
|
};
|
|
2166
2166
|
var _Event_cancelable, _Event_bubbles, _Event_composed, _Event_defaultPrevented, _Event_timestamp, _Event_propagationStopped, _Event_type, _Event_target, _Event_isBeingDispatched, _a$1, _CustomEvent_detail, _b;
|
|
2167
|
-
const isCaptureEventListener = (options) => (typeof options === 'boolean' ? options : (options?.capture ?? false));
|
|
2168
2167
|
// Event phases
|
|
2169
2168
|
const NONE = 0;
|
|
2170
2169
|
const CAPTURING_PHASE = 1;
|
|
2171
2170
|
const AT_TARGET = 2;
|
|
2172
2171
|
const BUBBLING_PHASE = 3;
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
this.__eventListeners = new Map();
|
|
2177
|
-
this.__captureEventListeners = new Map();
|
|
2178
|
-
}
|
|
2179
|
-
addEventListener(type, callback, options) {
|
|
2180
|
-
if (callback === undefined || callback === null) {
|
|
2181
|
-
return;
|
|
2182
|
-
}
|
|
2183
|
-
const eventListenersMap = isCaptureEventListener(options)
|
|
2184
|
-
? this.__captureEventListeners
|
|
2185
|
-
: this.__eventListeners;
|
|
2186
|
-
let eventListeners = eventListenersMap.get(type);
|
|
2187
|
-
if (eventListeners === undefined) {
|
|
2188
|
-
eventListeners = new Map();
|
|
2189
|
-
eventListenersMap.set(type, eventListeners);
|
|
2190
|
-
}
|
|
2191
|
-
else if (eventListeners.has(callback)) {
|
|
2192
|
-
return;
|
|
2193
|
-
}
|
|
2194
|
-
const normalizedOptions = typeof options === 'object' && options ? options : {};
|
|
2195
|
-
normalizedOptions.signal?.addEventListener('abort', () => this.removeEventListener(type, callback, options));
|
|
2196
|
-
eventListeners.set(callback, normalizedOptions ?? {});
|
|
2197
|
-
}
|
|
2198
|
-
removeEventListener(type, callback, options) {
|
|
2199
|
-
if (callback === undefined || callback === null) {
|
|
2200
|
-
return;
|
|
2201
|
-
}
|
|
2202
|
-
const eventListenersMap = isCaptureEventListener(options)
|
|
2203
|
-
? this.__captureEventListeners
|
|
2204
|
-
: this.__eventListeners;
|
|
2205
|
-
const eventListeners = eventListenersMap.get(type);
|
|
2206
|
-
if (eventListeners !== undefined) {
|
|
2207
|
-
eventListeners.delete(callback);
|
|
2208
|
-
if (!eventListeners.size) {
|
|
2209
|
-
eventListenersMap.delete(type);
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
dispatchEvent(event) {
|
|
2214
|
-
const composedPath = [this];
|
|
2215
|
-
let parent = this.__eventTargetParent;
|
|
2216
|
-
if (event.composed) {
|
|
2217
|
-
while (parent) {
|
|
2218
|
-
composedPath.push(parent);
|
|
2219
|
-
parent = parent.__eventTargetParent;
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
else {
|
|
2223
|
-
// If the event is not composed and the event was dispatched inside
|
|
2224
|
-
// shadow DOM, we need to stop before the host of the shadow DOM.
|
|
2225
|
-
while (parent && parent !== this.__host) {
|
|
2226
|
-
composedPath.push(parent);
|
|
2227
|
-
parent = parent.__eventTargetParent;
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
// We need to patch various properties that would either be empty or wrong
|
|
2231
|
-
// in this scenario.
|
|
2232
|
-
let stopPropagation = false;
|
|
2233
|
-
let stopImmediatePropagation = false;
|
|
2234
|
-
let eventPhase = NONE;
|
|
2235
|
-
let target = null;
|
|
2236
|
-
let tmpTarget = null;
|
|
2237
|
-
let currentTarget = null;
|
|
2238
|
-
const originalStopPropagation = event.stopPropagation;
|
|
2239
|
-
const originalStopImmediatePropagation = event.stopImmediatePropagation;
|
|
2240
|
-
Object.defineProperties(event, {
|
|
2241
|
-
target: {
|
|
2242
|
-
get() {
|
|
2243
|
-
return target ?? tmpTarget;
|
|
2244
|
-
},
|
|
2245
|
-
...enumerableProperty,
|
|
2246
|
-
},
|
|
2247
|
-
srcElement: {
|
|
2248
|
-
get() {
|
|
2249
|
-
return event.target;
|
|
2250
|
-
},
|
|
2251
|
-
...enumerableProperty,
|
|
2252
|
-
},
|
|
2253
|
-
currentTarget: {
|
|
2254
|
-
get() {
|
|
2255
|
-
return currentTarget;
|
|
2256
|
-
},
|
|
2257
|
-
...enumerableProperty,
|
|
2258
|
-
},
|
|
2259
|
-
eventPhase: {
|
|
2260
|
-
get() {
|
|
2261
|
-
return eventPhase;
|
|
2262
|
-
},
|
|
2263
|
-
...enumerableProperty,
|
|
2264
|
-
},
|
|
2265
|
-
composedPath: {
|
|
2266
|
-
value: () => composedPath,
|
|
2267
|
-
...enumerableProperty,
|
|
2268
|
-
},
|
|
2269
|
-
stopPropagation: {
|
|
2270
|
-
value: () => {
|
|
2271
|
-
stopPropagation = true;
|
|
2272
|
-
originalStopPropagation.call(event);
|
|
2273
|
-
},
|
|
2274
|
-
...enumerableProperty,
|
|
2275
|
-
},
|
|
2276
|
-
stopImmediatePropagation: {
|
|
2277
|
-
value: () => {
|
|
2278
|
-
stopImmediatePropagation = true;
|
|
2279
|
-
originalStopImmediatePropagation.call(event);
|
|
2280
|
-
},
|
|
2281
|
-
...enumerableProperty,
|
|
2282
|
-
},
|
|
2283
|
-
});
|
|
2284
|
-
// An event handler can either be a function, an object with a handleEvent
|
|
2285
|
-
// method or null. This function takes care to call the event handler
|
|
2286
|
-
// correctly.
|
|
2287
|
-
const invokeEventListener = (listener, options, eventListenerMap) => {
|
|
2288
|
-
if (typeof listener === 'function') {
|
|
2289
|
-
listener(event);
|
|
2290
|
-
}
|
|
2291
|
-
else if (typeof listener?.handleEvent === 'function') {
|
|
2292
|
-
listener.handleEvent(event);
|
|
2293
|
-
}
|
|
2294
|
-
if (options.once) {
|
|
2295
|
-
eventListenerMap.delete(listener);
|
|
2296
|
-
}
|
|
2297
|
-
};
|
|
2298
|
-
// When an event is finished being dispatched, which can be after the event
|
|
2299
|
-
// tree has been traversed or stopPropagation/stopImmediatePropagation has
|
|
2300
|
-
// been called. Once that is the case, the currentTarget and eventPhase
|
|
2301
|
-
// need to be reset and a value, representing whether the event has not
|
|
2302
|
-
// been prevented, needs to be returned.
|
|
2303
|
-
const finishDispatch = () => {
|
|
2304
|
-
currentTarget = null;
|
|
2305
|
-
eventPhase = NONE;
|
|
2306
|
-
return !event.defaultPrevented;
|
|
2307
|
-
};
|
|
2308
|
-
// An event starts with the capture order, where it starts from the top.
|
|
2309
|
-
// This is done even if bubbles is set to false, which is the default.
|
|
2310
|
-
const captureEventPath = composedPath.slice().reverse();
|
|
2311
|
-
// If the event target, which dispatches the event, is either in the light DOM
|
|
2312
|
-
// or the event is not composed, the target is always itself. If that is not
|
|
2313
|
-
// the case, the target needs to be retargeted: https://dom.spec.whatwg.org/#retarget
|
|
2314
|
-
target = !this.__host || !event.composed ? this : null;
|
|
2315
|
-
const retarget = (eventTargets) => {
|
|
2316
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2317
|
-
tmpTarget = this;
|
|
2318
|
-
while (tmpTarget.__host && eventTargets.includes(tmpTarget.__host)) {
|
|
2319
|
-
tmpTarget = tmpTarget.__host;
|
|
2320
|
-
}
|
|
2321
|
-
};
|
|
2322
|
-
for (const eventTarget of captureEventPath) {
|
|
2323
|
-
if (!target && (!tmpTarget || tmpTarget === eventTarget.__host)) {
|
|
2324
|
-
retarget(captureEventPath.slice(captureEventPath.indexOf(eventTarget)));
|
|
2325
|
-
}
|
|
2326
|
-
currentTarget = eventTarget;
|
|
2327
|
-
eventPhase = eventTarget === event.target ? AT_TARGET : CAPTURING_PHASE;
|
|
2328
|
-
const captureEventListeners = eventTarget.__captureEventListeners.get(event.type);
|
|
2329
|
-
if (captureEventListeners) {
|
|
2330
|
-
for (const [listener, options] of captureEventListeners) {
|
|
2331
|
-
invokeEventListener(listener, options, captureEventListeners);
|
|
2332
|
-
if (stopImmediatePropagation) {
|
|
2333
|
-
// Event.stopImmediatePropagation() stops any following invocation
|
|
2334
|
-
// of an event handler even on the same event target.
|
|
2335
|
-
return finishDispatch();
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
if (stopPropagation) {
|
|
2340
|
-
// Event.stopPropagation() stops any following invocation
|
|
2341
|
-
// of an event handler for any following event targets.
|
|
2342
|
-
return finishDispatch();
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
const bubbleEventPath = event.bubbles ? composedPath : [this];
|
|
2346
|
-
tmpTarget = null;
|
|
2347
|
-
for (const eventTarget of bubbleEventPath) {
|
|
2348
|
-
if (!target &&
|
|
2349
|
-
(!tmpTarget || eventTarget === tmpTarget.__host)) {
|
|
2350
|
-
retarget(bubbleEventPath.slice(0, bubbleEventPath.indexOf(eventTarget) + 1));
|
|
2351
|
-
}
|
|
2352
|
-
currentTarget = eventTarget;
|
|
2353
|
-
eventPhase = eventTarget === event.target ? AT_TARGET : BUBBLING_PHASE;
|
|
2354
|
-
const captureEventListeners = eventTarget.__eventListeners.get(event.type);
|
|
2355
|
-
if (captureEventListeners) {
|
|
2356
|
-
for (const [listener, options] of captureEventListeners) {
|
|
2357
|
-
invokeEventListener(listener, options, captureEventListeners);
|
|
2358
|
-
if (stopImmediatePropagation) {
|
|
2359
|
-
// Event.stopImmediatePropagation() stops any following invocation
|
|
2360
|
-
// of an event handler even on the same event target.
|
|
2361
|
-
return finishDispatch();
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
if (stopPropagation) {
|
|
2366
|
-
// Event.stopPropagation() stops any following invocation
|
|
2367
|
-
// of an event handler for any following event targets.
|
|
2368
|
-
return finishDispatch();
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
return finishDispatch();
|
|
2372
|
-
}
|
|
2373
|
-
}
|
|
2374
|
-
const EventTargetShimWithRealType = EventTarget;
|
|
2375
|
-
const enumerableProperty = { __proto__: null };
|
|
2376
|
-
enumerableProperty.enumerable = true;
|
|
2377
|
-
Object.freeze(enumerableProperty);
|
|
2172
|
+
const enumerableProperty$1 = { __proto__: null };
|
|
2173
|
+
enumerableProperty$1.enumerable = true;
|
|
2174
|
+
Object.freeze(enumerableProperty$1);
|
|
2378
2175
|
// TODO: Remove this when we remove support for vm modules (--experimental-vm-modules).
|
|
2379
2176
|
const EventShim = (_a$1 = class Event {
|
|
2380
2177
|
constructor(type, options = {}) {
|
|
@@ -2479,24 +2276,24 @@ const EventShim = (_a$1 = class Event {
|
|
|
2479
2276
|
_a$1.BUBBLING_PHASE = BUBBLING_PHASE,
|
|
2480
2277
|
_a$1);
|
|
2481
2278
|
Object.defineProperties(EventShim.prototype, {
|
|
2482
|
-
initEvent: enumerableProperty,
|
|
2483
|
-
stopImmediatePropagation: enumerableProperty,
|
|
2484
|
-
preventDefault: enumerableProperty,
|
|
2485
|
-
target: enumerableProperty,
|
|
2486
|
-
currentTarget: enumerableProperty,
|
|
2487
|
-
srcElement: enumerableProperty,
|
|
2488
|
-
type: enumerableProperty,
|
|
2489
|
-
cancelable: enumerableProperty,
|
|
2490
|
-
defaultPrevented: enumerableProperty,
|
|
2491
|
-
timeStamp: enumerableProperty,
|
|
2492
|
-
composedPath: enumerableProperty,
|
|
2493
|
-
returnValue: enumerableProperty,
|
|
2494
|
-
bubbles: enumerableProperty,
|
|
2495
|
-
composed: enumerableProperty,
|
|
2496
|
-
eventPhase: enumerableProperty,
|
|
2497
|
-
cancelBubble: enumerableProperty,
|
|
2498
|
-
stopPropagation: enumerableProperty,
|
|
2499
|
-
isTrusted: enumerableProperty,
|
|
2279
|
+
initEvent: enumerableProperty$1,
|
|
2280
|
+
stopImmediatePropagation: enumerableProperty$1,
|
|
2281
|
+
preventDefault: enumerableProperty$1,
|
|
2282
|
+
target: enumerableProperty$1,
|
|
2283
|
+
currentTarget: enumerableProperty$1,
|
|
2284
|
+
srcElement: enumerableProperty$1,
|
|
2285
|
+
type: enumerableProperty$1,
|
|
2286
|
+
cancelable: enumerableProperty$1,
|
|
2287
|
+
defaultPrevented: enumerableProperty$1,
|
|
2288
|
+
timeStamp: enumerableProperty$1,
|
|
2289
|
+
composedPath: enumerableProperty$1,
|
|
2290
|
+
returnValue: enumerableProperty$1,
|
|
2291
|
+
bubbles: enumerableProperty$1,
|
|
2292
|
+
composed: enumerableProperty$1,
|
|
2293
|
+
eventPhase: enumerableProperty$1,
|
|
2294
|
+
cancelBubble: enumerableProperty$1,
|
|
2295
|
+
stopPropagation: enumerableProperty$1,
|
|
2296
|
+
isTrusted: enumerableProperty$1,
|
|
2500
2297
|
});
|
|
2501
2298
|
// TODO: Remove this when we remove support for vm modules (--experimental-vm-modules).
|
|
2502
2299
|
const CustomEventShim = (_b = class CustomEvent extends EventShim {
|
|
@@ -2515,7 +2312,7 @@ const CustomEventShim = (_b = class CustomEvent extends EventShim {
|
|
|
2515
2312
|
_CustomEvent_detail = new WeakMap(),
|
|
2516
2313
|
_b);
|
|
2517
2314
|
Object.defineProperties(CustomEventShim.prototype, {
|
|
2518
|
-
detail: enumerableProperty,
|
|
2315
|
+
detail: enumerableProperty$1,
|
|
2519
2316
|
});
|
|
2520
2317
|
const EventShimWithRealType = EventShim;
|
|
2521
2318
|
const CustomEventShimWithRealType = CustomEventShim;
|
|
@@ -2588,6 +2385,7 @@ const CSSRuleShim = (_a = class CSSRule {
|
|
|
2588
2385
|
this.SUPPORTS_RULE = 12;
|
|
2589
2386
|
this.COUNTER_STYLE_RULE = 11;
|
|
2590
2387
|
this.FONT_FEATURE_VALUES_RULE = 14;
|
|
2388
|
+
this.MARGIN_RULE = 9;
|
|
2591
2389
|
this.__parentStyleSheet = null;
|
|
2592
2390
|
this.cssText = '';
|
|
2593
2391
|
}
|
|
@@ -2613,6 +2411,7 @@ const CSSRuleShim = (_a = class CSSRule {
|
|
|
2613
2411
|
_a.SUPPORTS_RULE = 12,
|
|
2614
2412
|
_a.COUNTER_STYLE_RULE = 11,
|
|
2615
2413
|
_a.FONT_FEATURE_VALUES_RULE = 14,
|
|
2414
|
+
_a.MARGIN_RULE = 9,
|
|
2616
2415
|
_a);
|
|
2617
2416
|
const CSSRuleShimWithRealType = CSSRuleShim;
|
|
2618
2417
|
const CSSRuleListShim = class CSSRuleList extends Array {
|
|
@@ -2660,6 +2459,60 @@ const CSSStyleSheetShim = class CSSStyleSheet extends StyleSheetShim {
|
|
|
2660
2459
|
};
|
|
2661
2460
|
const CSSStyleSheetShimWithRealType = CSSStyleSheetShim;
|
|
2662
2461
|
|
|
2462
|
+
/**
|
|
2463
|
+
* @license
|
|
2464
|
+
* Copyright 2024 Google LLC
|
|
2465
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
2466
|
+
*/
|
|
2467
|
+
/**
|
|
2468
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
2469
|
+
*/
|
|
2470
|
+
const MutationObserverShim = class MutationObserver {
|
|
2471
|
+
constructor(_callback) { }
|
|
2472
|
+
disconnect() { }
|
|
2473
|
+
observe(_target, _options) { }
|
|
2474
|
+
takeRecords() {
|
|
2475
|
+
return [];
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
const MutationObserverShimWithRealType = MutationObserverShim;
|
|
2479
|
+
/**
|
|
2480
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
|
|
2481
|
+
*/
|
|
2482
|
+
const ResizeObserverShim = class ResizeObserver {
|
|
2483
|
+
constructor(_callback) { }
|
|
2484
|
+
disconnect() { }
|
|
2485
|
+
observe(_target, _options) { }
|
|
2486
|
+
unobserve(_target) { }
|
|
2487
|
+
};
|
|
2488
|
+
const ResizeObserverShimWithRealType = ResizeObserverShim;
|
|
2489
|
+
/**
|
|
2490
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
|
|
2491
|
+
*/
|
|
2492
|
+
const IntersectionObserverShim = class IntersectionObserver {
|
|
2493
|
+
constructor(_callback, __options) {
|
|
2494
|
+
this.__options = __options;
|
|
2495
|
+
}
|
|
2496
|
+
get root() {
|
|
2497
|
+
return this.__options?.root ?? null;
|
|
2498
|
+
}
|
|
2499
|
+
get rootMargin() {
|
|
2500
|
+
return this.__options?.rootMargin ?? '0px 0px 0px 0px';
|
|
2501
|
+
}
|
|
2502
|
+
get thresholds() {
|
|
2503
|
+
return Array.isArray(this.__options?.threshold)
|
|
2504
|
+
? this.__options.threshold
|
|
2505
|
+
: [this.__options?.threshold ?? 0];
|
|
2506
|
+
}
|
|
2507
|
+
disconnect() { }
|
|
2508
|
+
observe(_target) { }
|
|
2509
|
+
takeRecords() {
|
|
2510
|
+
return [];
|
|
2511
|
+
}
|
|
2512
|
+
unobserve(_target) { }
|
|
2513
|
+
};
|
|
2514
|
+
const IntersectionObserverShimWithRealType = IntersectionObserverShim;
|
|
2515
|
+
|
|
2663
2516
|
/**
|
|
2664
2517
|
* @license
|
|
2665
2518
|
* Copyright 2019 Google LLC
|
|
@@ -2670,6 +2523,286 @@ const CSSStyleSheetShimWithRealType = CSSStyleSheetShim;
|
|
|
2670
2523
|
// for vm modules (--experimental-vm-modules).
|
|
2671
2524
|
globalThis.Event ??= EventShimWithRealType;
|
|
2672
2525
|
globalThis.CustomEvent ??= CustomEventShimWithRealType;
|
|
2526
|
+
const constructionToken = Symbol();
|
|
2527
|
+
const isCaptureEventListener = (options) => (typeof options === 'boolean' ? options : (options?.capture ?? false));
|
|
2528
|
+
const enumerableProperty = { __proto__: null };
|
|
2529
|
+
enumerableProperty.enumerable = true;
|
|
2530
|
+
Object.freeze(enumerableProperty);
|
|
2531
|
+
/**
|
|
2532
|
+
* This is a basic implementation of an EventTarget.
|
|
2533
|
+
*
|
|
2534
|
+
* This is not fully spec compliant (e.g. validation),
|
|
2535
|
+
* but should work well enough for our use cases.
|
|
2536
|
+
*
|
|
2537
|
+
* @see https://dom.spec.whatwg.org/#eventtarget
|
|
2538
|
+
*
|
|
2539
|
+
* Example Event Path
|
|
2540
|
+
* ------------------
|
|
2541
|
+
*
|
|
2542
|
+
* Note that this depends on the logic in `packages/labs/ssr/src/lib/render-value.ts`.
|
|
2543
|
+
* Any element that is not a custom element or a slot element is skipped in the chain.
|
|
2544
|
+
*
|
|
2545
|
+
* <main>
|
|
2546
|
+
* <my-el1>
|
|
2547
|
+
* #shadow-dom (open)
|
|
2548
|
+
* <div>
|
|
2549
|
+
* <slot></slot>
|
|
2550
|
+
* <my-el2>
|
|
2551
|
+
* #shadow-dom (closed)
|
|
2552
|
+
* <slot></slot>
|
|
2553
|
+
* <event-dispatcher3></event-dispatcher3>
|
|
2554
|
+
* <slot name="nested"></slot>
|
|
2555
|
+
* </my-el2>
|
|
2556
|
+
* </div>
|
|
2557
|
+
* <event-dispatcher1></event-dispatcher1>
|
|
2558
|
+
* <event-dispatcher2 slot="nested"></event-dispatcher2>
|
|
2559
|
+
* </my-el1>
|
|
2560
|
+
* </main>
|
|
2561
|
+
*
|
|
2562
|
+
* Given the previous structure, the event path of this shim would be as follows,
|
|
2563
|
+
* for the given dispatcher with an event that bubbles (document-fragment
|
|
2564
|
+
* represents a ShadowRoot/#shadow-dom instance):
|
|
2565
|
+
*
|
|
2566
|
+
* <event-dispatcher1>:
|
|
2567
|
+
* [event-dispatcher1, slot{my-el1}, document-fragment{my-el1}, my-el1, document]
|
|
2568
|
+
*
|
|
2569
|
+
* <event-dispatcher2>:
|
|
2570
|
+
* [
|
|
2571
|
+
* event-dispatcher2,
|
|
2572
|
+
* slot[name="nested"]{my-el1},
|
|
2573
|
+
* slot{my-el2},
|
|
2574
|
+
* document-fragment{my-el2},
|
|
2575
|
+
* my-el2,
|
|
2576
|
+
* document-fragment{my-el1},
|
|
2577
|
+
* my-el1,
|
|
2578
|
+
* document
|
|
2579
|
+
* ]
|
|
2580
|
+
*
|
|
2581
|
+
* <event-dispatcher3> (without composed):
|
|
2582
|
+
* [event-dispatcher3, document-fragment{my-el2}]
|
|
2583
|
+
*
|
|
2584
|
+
* <event-dispatcher3> (composed):
|
|
2585
|
+
* [
|
|
2586
|
+
* event-dispatcher3,
|
|
2587
|
+
* document-fragment{my-el2},
|
|
2588
|
+
* my-el2,
|
|
2589
|
+
* document-fragment{my-el1},
|
|
2590
|
+
* my-el1,
|
|
2591
|
+
* document
|
|
2592
|
+
* ]
|
|
2593
|
+
*/
|
|
2594
|
+
class EventTarget {
|
|
2595
|
+
constructor() {
|
|
2596
|
+
this.__eventListeners = new Map();
|
|
2597
|
+
this.__captureEventListeners = new Map();
|
|
2598
|
+
}
|
|
2599
|
+
addEventListener(type, callback, options) {
|
|
2600
|
+
if (callback === undefined || callback === null) {
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
const eventListenersMap = isCaptureEventListener(options)
|
|
2604
|
+
? this.__captureEventListeners
|
|
2605
|
+
: this.__eventListeners;
|
|
2606
|
+
let eventListeners = eventListenersMap.get(type);
|
|
2607
|
+
if (eventListeners === undefined) {
|
|
2608
|
+
eventListeners = new Map();
|
|
2609
|
+
eventListenersMap.set(type, eventListeners);
|
|
2610
|
+
}
|
|
2611
|
+
else if (eventListeners.has(callback)) {
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
const normalizedOptions = typeof options === 'object' && options ? options : {};
|
|
2615
|
+
normalizedOptions.signal?.addEventListener('abort', () => this.removeEventListener(type, callback, options));
|
|
2616
|
+
eventListeners.set(callback, normalizedOptions ?? {});
|
|
2617
|
+
}
|
|
2618
|
+
removeEventListener(type, callback, options) {
|
|
2619
|
+
if (callback === undefined || callback === null) {
|
|
2620
|
+
return;
|
|
2621
|
+
}
|
|
2622
|
+
const eventListenersMap = isCaptureEventListener(options)
|
|
2623
|
+
? this.__captureEventListeners
|
|
2624
|
+
: this.__eventListeners;
|
|
2625
|
+
const eventListeners = eventListenersMap.get(type);
|
|
2626
|
+
if (eventListeners !== undefined) {
|
|
2627
|
+
eventListeners.delete(callback);
|
|
2628
|
+
if (!eventListeners.size) {
|
|
2629
|
+
eventListenersMap.delete(type);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
dispatchEvent(event) {
|
|
2634
|
+
let composedPath = this.__resolveFullEventPath();
|
|
2635
|
+
if (!event.composed && this.__host) {
|
|
2636
|
+
// If the event is not composed and the event was dispatched inside
|
|
2637
|
+
// shadow DOM, we need to stop the event chain before the host of the
|
|
2638
|
+
// shadow DOM.
|
|
2639
|
+
composedPath = composedPath.slice(0, composedPath.indexOf(this.__host));
|
|
2640
|
+
}
|
|
2641
|
+
// We need to patch various properties that would either be empty or wrong
|
|
2642
|
+
// in this scenario.
|
|
2643
|
+
let stopPropagation = false;
|
|
2644
|
+
let stopImmediatePropagation = false;
|
|
2645
|
+
let eventPhase = EventShimWithRealType.NONE;
|
|
2646
|
+
let target = null;
|
|
2647
|
+
let tmpTarget = null;
|
|
2648
|
+
let currentTarget = null;
|
|
2649
|
+
const originalStopPropagation = event.stopPropagation;
|
|
2650
|
+
const originalStopImmediatePropagation = event.stopImmediatePropagation;
|
|
2651
|
+
Object.defineProperties(event, {
|
|
2652
|
+
target: {
|
|
2653
|
+
get() {
|
|
2654
|
+
return target ?? tmpTarget;
|
|
2655
|
+
},
|
|
2656
|
+
...enumerableProperty,
|
|
2657
|
+
},
|
|
2658
|
+
srcElement: {
|
|
2659
|
+
get() {
|
|
2660
|
+
return event.target;
|
|
2661
|
+
},
|
|
2662
|
+
...enumerableProperty,
|
|
2663
|
+
},
|
|
2664
|
+
currentTarget: {
|
|
2665
|
+
get() {
|
|
2666
|
+
return currentTarget;
|
|
2667
|
+
},
|
|
2668
|
+
...enumerableProperty,
|
|
2669
|
+
},
|
|
2670
|
+
eventPhase: {
|
|
2671
|
+
get() {
|
|
2672
|
+
return eventPhase;
|
|
2673
|
+
},
|
|
2674
|
+
...enumerableProperty,
|
|
2675
|
+
},
|
|
2676
|
+
composedPath: {
|
|
2677
|
+
value: () => composedPath,
|
|
2678
|
+
...enumerableProperty,
|
|
2679
|
+
},
|
|
2680
|
+
stopPropagation: {
|
|
2681
|
+
value: () => {
|
|
2682
|
+
stopPropagation = true;
|
|
2683
|
+
originalStopPropagation.call(event);
|
|
2684
|
+
},
|
|
2685
|
+
...enumerableProperty,
|
|
2686
|
+
},
|
|
2687
|
+
stopImmediatePropagation: {
|
|
2688
|
+
value: () => {
|
|
2689
|
+
stopImmediatePropagation = true;
|
|
2690
|
+
originalStopImmediatePropagation.call(event);
|
|
2691
|
+
},
|
|
2692
|
+
...enumerableProperty,
|
|
2693
|
+
},
|
|
2694
|
+
});
|
|
2695
|
+
// An event handler can either be a function, an object with a handleEvent
|
|
2696
|
+
// method or null. This function takes care to call the event handler
|
|
2697
|
+
// correctly.
|
|
2698
|
+
const invokeEventListener = (listener, options, eventListenerMap) => {
|
|
2699
|
+
if (typeof listener === 'function') {
|
|
2700
|
+
listener(event);
|
|
2701
|
+
}
|
|
2702
|
+
else if (typeof listener?.handleEvent === 'function') {
|
|
2703
|
+
listener.handleEvent(event);
|
|
2704
|
+
}
|
|
2705
|
+
if (options.once) {
|
|
2706
|
+
eventListenerMap.delete(listener);
|
|
2707
|
+
}
|
|
2708
|
+
};
|
|
2709
|
+
// When an event is finished being dispatched, which can be after the event
|
|
2710
|
+
// tree has been traversed or stopPropagation/stopImmediatePropagation has
|
|
2711
|
+
// been called. Once that is the case, the currentTarget and eventPhase
|
|
2712
|
+
// need to be reset and a value, representing whether the event has not
|
|
2713
|
+
// been prevented, needs to be returned.
|
|
2714
|
+
const finishDispatch = () => {
|
|
2715
|
+
currentTarget = null;
|
|
2716
|
+
eventPhase = EventShimWithRealType.NONE;
|
|
2717
|
+
return !event.defaultPrevented;
|
|
2718
|
+
};
|
|
2719
|
+
// An event starts with the capture order, where it starts from the top.
|
|
2720
|
+
// This is done even if bubbles is set to false, which is the default.
|
|
2721
|
+
const captureEventPath = composedPath.slice().reverse();
|
|
2722
|
+
// If the event target, which dispatches the event, is either in the light DOM
|
|
2723
|
+
// or the event is not composed, the target is always itself. If that is not
|
|
2724
|
+
// the case, the target needs to be retargeted: https://dom.spec.whatwg.org/#retarget
|
|
2725
|
+
target = !this.__host || !event.composed ? this : null;
|
|
2726
|
+
const retarget = (eventTargets) => {
|
|
2727
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2728
|
+
tmpTarget = this;
|
|
2729
|
+
while (tmpTarget.__host && eventTargets.includes(tmpTarget.__host)) {
|
|
2730
|
+
tmpTarget = tmpTarget.__host;
|
|
2731
|
+
}
|
|
2732
|
+
};
|
|
2733
|
+
for (const eventTarget of captureEventPath) {
|
|
2734
|
+
if (!target && (!tmpTarget || tmpTarget === eventTarget.__host)) {
|
|
2735
|
+
retarget(captureEventPath.slice(captureEventPath.indexOf(eventTarget)));
|
|
2736
|
+
}
|
|
2737
|
+
currentTarget = eventTarget;
|
|
2738
|
+
eventPhase =
|
|
2739
|
+
eventTarget === event.target
|
|
2740
|
+
? EventShimWithRealType.AT_TARGET
|
|
2741
|
+
: EventShimWithRealType.CAPTURING_PHASE;
|
|
2742
|
+
const captureEventListeners = eventTarget.__captureEventListeners.get(event.type);
|
|
2743
|
+
if (captureEventListeners) {
|
|
2744
|
+
for (const [listener, options] of captureEventListeners) {
|
|
2745
|
+
invokeEventListener(listener, options, captureEventListeners);
|
|
2746
|
+
if (stopImmediatePropagation) {
|
|
2747
|
+
// Event.stopImmediatePropagation() stops any following invocation
|
|
2748
|
+
// of an event handler even on the same event target.
|
|
2749
|
+
return finishDispatch();
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
if (stopPropagation) {
|
|
2754
|
+
// Event.stopPropagation() stops any following invocation
|
|
2755
|
+
// of an event handler for any following event targets.
|
|
2756
|
+
return finishDispatch();
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
const bubbleEventPath = event.bubbles ? composedPath : [this];
|
|
2760
|
+
tmpTarget = null;
|
|
2761
|
+
for (const eventTarget of bubbleEventPath) {
|
|
2762
|
+
if (!target &&
|
|
2763
|
+
(!tmpTarget || eventTarget === tmpTarget.__host)) {
|
|
2764
|
+
retarget(bubbleEventPath.slice(0, bubbleEventPath.indexOf(eventTarget) + 1));
|
|
2765
|
+
}
|
|
2766
|
+
currentTarget = eventTarget;
|
|
2767
|
+
eventPhase =
|
|
2768
|
+
eventTarget === event.target
|
|
2769
|
+
? EventShimWithRealType.AT_TARGET
|
|
2770
|
+
: EventShimWithRealType.BUBBLING_PHASE;
|
|
2771
|
+
const eventListeners = eventTarget.__eventListeners.get(event.type);
|
|
2772
|
+
if (eventListeners) {
|
|
2773
|
+
for (const [listener, options] of eventListeners) {
|
|
2774
|
+
invokeEventListener(listener, options, eventListeners);
|
|
2775
|
+
if (stopImmediatePropagation) {
|
|
2776
|
+
// Event.stopImmediatePropagation() stops any following invocation
|
|
2777
|
+
// of an event handler even on the same event target.
|
|
2778
|
+
return finishDispatch();
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
if (stopPropagation) {
|
|
2783
|
+
// Event.stopPropagation() stops any following invocation
|
|
2784
|
+
// of an event handler for any following event targets.
|
|
2785
|
+
return finishDispatch();
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
return finishDispatch();
|
|
2789
|
+
}
|
|
2790
|
+
__resolveFullEventPath() {
|
|
2791
|
+
if (this.__eventPathCache) {
|
|
2792
|
+
return this.__eventPathCache;
|
|
2793
|
+
}
|
|
2794
|
+
else if (!this.__eventTargetParent) {
|
|
2795
|
+
return (this.__eventPathCache = [this, documentShim, windowShim]);
|
|
2796
|
+
}
|
|
2797
|
+
else {
|
|
2798
|
+
return (this.__eventPathCache = [
|
|
2799
|
+
this,
|
|
2800
|
+
...this.__eventTargetParent.__resolveFullEventPath(),
|
|
2801
|
+
]);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
const EventTargetShimWithRealType = EventTarget;
|
|
2673
2806
|
const attributes = new WeakMap();
|
|
2674
2807
|
const attributesForElement = (element) => {
|
|
2675
2808
|
let attrs = attributes.get(element);
|
|
@@ -2689,7 +2822,58 @@ const attributesForElement = (element) => {
|
|
|
2689
2822
|
// `const ElementShimWithRealType = ElementShim as object as typeof Element;`.
|
|
2690
2823
|
// 4. We want the exported names to match the real ones, hence e.g.
|
|
2691
2824
|
// `export {ElementShimWithRealType as Element}`.
|
|
2692
|
-
const
|
|
2825
|
+
const NodeShim = class Node extends EventTarget {
|
|
2826
|
+
getRootNode(options) {
|
|
2827
|
+
if (options?.composed) {
|
|
2828
|
+
return document$1;
|
|
2829
|
+
}
|
|
2830
|
+
// getRootNode returns the containing ShadowRoot instance, even if that was
|
|
2831
|
+
// created in closed mode.
|
|
2832
|
+
const host = this.__host;
|
|
2833
|
+
return (host?.__shadowRoot ?? document$1);
|
|
2834
|
+
}
|
|
2835
|
+
};
|
|
2836
|
+
const NodeShimWithRealType = NodeShim;
|
|
2837
|
+
const DocumentShim = class Document extends NodeShim {
|
|
2838
|
+
get adoptedStyleSheets() {
|
|
2839
|
+
return [];
|
|
2840
|
+
}
|
|
2841
|
+
createTreeWalker() {
|
|
2842
|
+
return {};
|
|
2843
|
+
}
|
|
2844
|
+
createTextNode() {
|
|
2845
|
+
return {};
|
|
2846
|
+
}
|
|
2847
|
+
createElement() {
|
|
2848
|
+
return {};
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
const DocumentShimWithRealType = DocumentShim;
|
|
2852
|
+
const documentShim = new DocumentShim();
|
|
2853
|
+
const document$1 = documentShim;
|
|
2854
|
+
const WindowShim = class Window extends NodeShim {
|
|
2855
|
+
constructor(token) {
|
|
2856
|
+
super();
|
|
2857
|
+
if (token !== constructionToken) {
|
|
2858
|
+
throw new TypeError('Illegal constructor');
|
|
2859
|
+
}
|
|
2860
|
+
Object.assign(this, globalThis, {
|
|
2861
|
+
CustomElementRegistry,
|
|
2862
|
+
customElements,
|
|
2863
|
+
document: document$1,
|
|
2864
|
+
Document: DocumentShim,
|
|
2865
|
+
Element: ElementShim,
|
|
2866
|
+
EventTarget,
|
|
2867
|
+
HTMLElement: HTMLElementShim,
|
|
2868
|
+
Node: NodeShim,
|
|
2869
|
+
ShadowRoot: ShadowRootShim,
|
|
2870
|
+
window: this,
|
|
2871
|
+
Window: WindowShim,
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
};
|
|
2875
|
+
const WindowShimWithRealType = WindowShim;
|
|
2876
|
+
const ElementShim = class Element extends NodeShim {
|
|
2693
2877
|
constructor() {
|
|
2694
2878
|
super(...arguments);
|
|
2695
2879
|
this.__shadowRootMode = null;
|
|
@@ -2750,12 +2934,11 @@ const ElementShim = class Element extends EventTargetShimWithRealType {
|
|
|
2750
2934
|
return attributesForElement(this).has(name);
|
|
2751
2935
|
}
|
|
2752
2936
|
attachShadow(init) {
|
|
2753
|
-
const shadowRoot = { host: this };
|
|
2754
2937
|
this.__shadowRootMode = init.mode;
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
return shadowRoot;
|
|
2938
|
+
const shadowRoot = new ShadowRootShim(constructionToken, init);
|
|
2939
|
+
shadowRoot.__eventTargetParent = this;
|
|
2940
|
+
shadowRoot.__host = this;
|
|
2941
|
+
return (this.__shadowRoot = shadowRoot);
|
|
2759
2942
|
}
|
|
2760
2943
|
attachInternals() {
|
|
2761
2944
|
if (this.__internals !== null) {
|
|
@@ -2775,6 +2958,25 @@ const ElementShimWithRealType = ElementShim;
|
|
|
2775
2958
|
const HTMLElementShim = class HTMLElement extends ElementShim {
|
|
2776
2959
|
};
|
|
2777
2960
|
const HTMLElementShimWithRealType = HTMLElementShim;
|
|
2961
|
+
const HTMLSlotElementShim = class HTMLSlotElement extends HTMLElementShim {
|
|
2962
|
+
get localName() {
|
|
2963
|
+
return 'slot';
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
const HTMLSlotElementShimWithRealType = HTMLSlotElementShim;
|
|
2967
|
+
const ShadowRootShim = class ShadowRoot extends NodeShim {
|
|
2968
|
+
get host() {
|
|
2969
|
+
return this.__host;
|
|
2970
|
+
}
|
|
2971
|
+
constructor(constructionToken, init) {
|
|
2972
|
+
super();
|
|
2973
|
+
if (constructionToken !== constructionToken) {
|
|
2974
|
+
throw new TypeError('Illegal constructor');
|
|
2975
|
+
}
|
|
2976
|
+
this.mode = init.mode;
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
const ShadowRootShimWithRealType = ShadowRootShim;
|
|
2778
2980
|
// For convenience, we provide a global instance of a HTMLElement as an event
|
|
2779
2981
|
// target. This facilitates registering global event handlers
|
|
2780
2982
|
// (e.g. for @lit/context ContextProvider).
|
|
@@ -2847,6 +3049,10 @@ class CustomElementRegistry {
|
|
|
2847
3049
|
getName(ctor) {
|
|
2848
3050
|
return this.__reverseDefinitions.get(ctor) ?? null;
|
|
2849
3051
|
}
|
|
3052
|
+
initialize(_root) {
|
|
3053
|
+
throw new Error(`customElements.initialize is not currently supported in SSR. ` +
|
|
3054
|
+
`Please file a bug if you need it.`);
|
|
3055
|
+
}
|
|
2850
3056
|
upgrade(_element) {
|
|
2851
3057
|
// In SSR this doesn't make a lot of sense, so we do nothing.
|
|
2852
3058
|
throw new Error(`customElements.upgrade is not currently supported in SSR. ` +
|
|
@@ -2867,6 +3073,10 @@ class CustomElementRegistry {
|
|
|
2867
3073
|
}
|
|
2868
3074
|
const CustomElementRegistryShimWithRealType = CustomElementRegistry;
|
|
2869
3075
|
const customElements = new CustomElementRegistryShimWithRealType();
|
|
3076
|
+
// The window variable instantiation must happen after all shims
|
|
3077
|
+
// have been declared, as they will be included in the window instance.
|
|
3078
|
+
const windowShim = new WindowShim(constructionToken);
|
|
3079
|
+
const window$1 = windowShim;
|
|
2870
3080
|
|
|
2871
3081
|
if (typeof HTMLElement === 'undefined') {
|
|
2872
3082
|
globalThis.HTMLElement = HTMLElementShimWithRealType;
|