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