first commit

This commit is contained in:
becarta
2025-05-16 00:17:42 +02:00
parent ea5c866137
commit bacf566ec9
6020 changed files with 1715262 additions and 0 deletions

67
node_modules/@lit-labs/ssr-dom-shim/README.md generated vendored Normal file
View File

@@ -0,0 +1,67 @@
# @lit-labs/ssr-dom-shim
## Overview
This package provides minimal implementations of `Element`, `HTMLElement`,
`EventTarget`, `Event`, `CustomEvent`, `CustomElementRegistry`, and
`customElements`, designed to be used when Server Side Rendering (SSR) web
components from Node, including Lit components.
## Usage
### Usage from Lit
Lit itself automatically imports these shims when running in Node, so Lit users
should typically not need to directly depend on or import from this package.
See the [lit.dev SSR docs](https://lit.dev/docs/ssr/overview/) for general
information about server-side rendering with Lit.
### Usage in other contexts
Other libraries or frameworks who wish to support SSR are welcome to also depend
on these shims. (This package is planned to eventually move to
`@webcomponents/ssr-dom-shim` to better reflect this use case). There are two
main patterns for providing access to these shims to users:
1. Assigning shims to `globalThis`, ensuring that assignment occurs before
user-code runs.
2. Importing shims directly from the module that provides your base class, using
the `node` [export
condition](https://nodejs.org/api/packages.html#conditional-exports) to
ensure this only happens when running in Node, and not in the browser.
Lit takes approach #2 for all of the shims except for `customElements`, `Event`
and `CustomEvent`, so that users who have imported `lit` are able to call
`customElements.define` or `new Event(...)`/`new CustomEvent(...)` in their
components from Node.
### Exports
The main module exports the following values. Note that no globals are set by
this module.
- [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
- [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
- [`dispatchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent)
- [`removeEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener)
- [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)
- (Inherits from EventTarget)
- [`attachShadow`](https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow)
- [`shadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot)
- [`attributes`](https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes)
- [`hasAttribute`](https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute)
- [`getAttribute`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute)
- [`setAttribute`](https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute)
- [`removeAttribute`](https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute)
- [`HTMLElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement)
- (Inherits from Element)
- [`CustomElementRegistry`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry)
- [`customElements`](https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements)
- [`Event`](https://developer.mozilla.org/en-US/docs/Web/API/Event)
- [`CustomEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent)
## Contributing
Please see [CONTRIBUTING.md](../../../CONTRIBUTING.md).

12
node_modules/@lit-labs/ssr-dom-shim/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { EventTargetShimMeta } from './lib/events.js';
export { ariaMixinAttributes, ElementInternals, HYDRATE_INTERNALS_ATTR_PREFIX, } from './lib/element-internals.js';
export { CustomEvent, Event, EventTarget } from './lib/events.js';
export type HTMLElementWithEventMeta = HTMLElement & EventTargetShimMeta;
declare const ElementShimWithRealType: typeof Element;
export { ElementShimWithRealType as Element };
declare const HTMLElementShimWithRealType: typeof HTMLElement;
export { HTMLElementShimWithRealType as HTMLElement };
declare const CustomElementRegistryShimWithRealType: typeof CustomElementRegistry;
export { CustomElementRegistryShimWithRealType as CustomElementRegistry };
export declare const customElements: CustomElementRegistry;
//# sourceMappingURL=index.d.ts.map

1
node_modules/@lit-labs/ssr-dom-shim/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,WAAW,EAAE,KAAK,EAAE,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAShE,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,mBAAmB,CAAC;AA2GzE,QAAA,MAAM,uBAAuB,EAA4B,OAAO,OAAO,CAAC;AACxE,OAAO,EAAC,uBAAuB,IAAI,OAAO,EAAC,CAAC;AAG5C,QAAA,MAAM,2BAA2B,EACF,OAAO,WAAW,CAAC;AAClD,OAAO,EAAC,2BAA2B,IAAI,WAAW,EAAC,CAAC;AA4EpD,QAAA,MAAM,qCAAqC,EACF,OAAO,qBAAqB,CAAC;AACtE,OAAO,EAAC,qCAAqC,IAAI,qBAAqB,EAAC,CAAC;AAExE,eAAO,MAAM,cAAc,uBAA8C,CAAC"}

176
node_modules/@lit-labs/ssr-dom-shim/index.js generated vendored Normal file
View File

@@ -0,0 +1,176 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import { ElementInternalsShim } from './lib/element-internals.js';
import { EventTargetShim, EventShim, CustomEventShim, } from './lib/events.js';
export { ariaMixinAttributes, ElementInternals, HYDRATE_INTERNALS_ATTR_PREFIX, } from './lib/element-internals.js';
export { CustomEvent, Event, EventTarget } from './lib/events.js';
// In an empty Node.js vm, we need to patch the global context.
// TODO: Remove these globalThis assignments when we remove support
// for vm modules (--experimental-vm-modules).
globalThis.Event ??= EventShim;
globalThis.CustomEvent ??= CustomEventShim;
const attributes = new WeakMap();
const attributesForElement = (element) => {
let attrs = attributes.get(element);
if (attrs === undefined) {
attributes.set(element, (attrs = new Map()));
}
return attrs;
};
// The typings around the exports below are a little funky:
//
// 1. We want the `name` of the shim classes to match the real ones at runtime,
// hence e.g. `class Element`.
// 2. We can't shadow the global types with a simple class declaration, because
// then we can't reference the global types for casting, hence e.g.
// `const ElementShim = class Element`.
// 3. We want to export the classes typed as the real ones, hence e.g.
// `const ElementShimWithRealType = ElementShim as object as typeof Element;`.
// 4. We want the exported names to match the real ones, hence e.g.
// `export {ElementShimWithRealType as Element}`.
const ElementShim = class Element extends EventTargetShim {
constructor() {
super(...arguments);
this.__shadowRootMode = null;
this.__shadowRoot = null;
this.__internals = null;
}
get attributes() {
return Array.from(attributesForElement(this)).map(([name, value]) => ({
name,
value,
}));
}
get shadowRoot() {
if (this.__shadowRootMode === 'closed') {
return null;
}
return this.__shadowRoot;
}
get localName() {
return this.constructor.__localName;
}
get tagName() {
return this.localName?.toUpperCase();
}
setAttribute(name, value) {
// Emulate browser behavior that silently casts all values to string. E.g.
// `42` becomes `"42"` and `{}` becomes `"[object Object]""`.
attributesForElement(this).set(name, String(value));
}
removeAttribute(name) {
attributesForElement(this).delete(name);
}
toggleAttribute(name, force) {
// Steps reference https://dom.spec.whatwg.org/#dom-element-toggleattribute
if (this.hasAttribute(name)) {
// Step 5
if (force === undefined || !force) {
this.removeAttribute(name);
return false;
}
}
else {
// Step 4
if (force === undefined || force) {
// Step 4.1
this.setAttribute(name, '');
return true;
}
else {
// Step 4.2
return false;
}
}
// Step 6
return true;
}
hasAttribute(name) {
return attributesForElement(this).has(name);
}
attachShadow(init) {
const shadowRoot = { host: this };
this.__shadowRootMode = init.mode;
if (init && init.mode === 'open') {
this.__shadowRoot = shadowRoot;
}
return shadowRoot;
}
attachInternals() {
if (this.__internals !== null) {
throw new Error(`Failed to execute 'attachInternals' on 'HTMLElement': ` +
`ElementInternals for the specified element was already attached.`);
}
const internals = new ElementInternalsShim(this);
this.__internals = internals;
return internals;
}
getAttribute(name) {
const value = attributesForElement(this).get(name);
return value ?? null;
}
};
const ElementShimWithRealType = ElementShim;
export { ElementShimWithRealType as Element };
const HTMLElementShim = class HTMLElement extends ElementShim {
};
const HTMLElementShimWithRealType = HTMLElementShim;
export { HTMLElementShimWithRealType as HTMLElement };
// For convenience, we provide a global instance of a HTMLElement as an event
// target. This facilitates registering global event handlers
// (e.g. for @lit/context ContextProvider).
// We use this in in the SSR render function.
// Note, this is a bespoke element and not simply `document` or `window` since
// user code relies on these being undefined in the server environment.
globalThis.litServerRoot ??= Object.defineProperty(new HTMLElementShimWithRealType(), 'localName', {
// Patch localName (and tagName) to return a unique name.
get() {
return 'lit-server-root';
},
});
const CustomElementRegistryShim = class CustomElementRegistry {
constructor() {
this.__definitions = new Map();
}
define(name, ctor) {
if (this.__definitions.has(name)) {
if (process.env.NODE_ENV === 'development') {
console.warn(`'CustomElementRegistry' already has "${name}" defined. ` +
`This may have been caused by live reload or hot module ` +
`replacement in which case it can be safely ignored.\n` +
`Make sure to test your application with a production build as ` +
`repeat registrations will throw in production.`);
}
else {
throw new Error(`Failed to execute 'define' on 'CustomElementRegistry': ` +
`the name "${name}" has already been used with this registry`);
}
}
// Provide tagName and localName for the component.
ctor.__localName = name;
this.__definitions.set(name, {
ctor,
// Note it's important we read `observedAttributes` in case it is a getter
// with side-effects, as is the case in Lit, where it triggers class
// finalization.
//
// TODO(aomarks) To be spec compliant, we should also capture the
// registration-time lifecycle methods like `connectedCallback`. For them
// to be actually accessible to e.g. the Lit SSR element renderer, though,
// we'd need to introduce a new API for accessing them (since `get` only
// returns the constructor).
observedAttributes: ctor.observedAttributes ?? [],
});
}
get(name) {
const definition = this.__definitions.get(name);
return definition?.ctor;
}
};
const CustomElementRegistryShimWithRealType = CustomElementRegistryShim;
export { CustomElementRegistryShimWithRealType as CustomElementRegistry };
export const customElements = new CustomElementRegistryShimWithRealType();
//# sourceMappingURL=index.js.map

1
node_modules/@lit-labs/ssr-dom-shim/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,73 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
type ARIAAttributeMap = {
[K in keyof ARIAMixin]: string;
};
/**
* Map of ARIAMixin properties to attributes
*/
export declare const ariaMixinAttributes: ARIAAttributeMap;
export declare const ElementInternalsShim: {
new (_host: HTMLElement): {
ariaAtomic: string;
ariaAutoComplete: string;
ariaBrailleLabel: string;
ariaBrailleRoleDescription: string;
ariaBusy: string;
ariaChecked: string;
ariaColCount: string;
ariaColIndex: string;
ariaColSpan: string;
ariaCurrent: string;
ariaDescription: string;
ariaDisabled: string;
ariaExpanded: string;
ariaHasPopup: string;
ariaHidden: string;
ariaInvalid: string;
ariaKeyShortcuts: string;
ariaLabel: string;
ariaLevel: string;
ariaLive: string;
ariaModal: string;
ariaMultiLine: string;
ariaMultiSelectable: string;
ariaOrientation: string;
ariaPlaceholder: string;
ariaPosInSet: string;
ariaPressed: string;
ariaReadOnly: string;
ariaRequired: string;
ariaRoleDescription: string;
ariaRowCount: string;
ariaRowIndex: string;
ariaRowSpan: string;
ariaSelected: string;
ariaSetSize: string;
ariaSort: string;
ariaValueMax: string;
ariaValueMin: string;
ariaValueNow: string;
ariaValueText: string;
role: string;
__host: HTMLElement;
readonly shadowRoot: ShadowRoot;
checkValidity(): boolean;
form: null;
labels: NodeListOf<HTMLLabelElement>;
reportValidity(): boolean;
setFormValue(): void;
setValidity(): void;
states: Set<string>;
validationMessage: string;
validity: ValidityState;
willValidate: boolean;
};
};
declare const ElementInternalsShimWithRealType: typeof ElementInternals;
export { ElementInternalsShimWithRealType as ElementInternals };
export declare const HYDRATE_INTERNALS_ATTR_PREFIX = "hydrate-internals-";
//# sourceMappingURL=element-internals.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"element-internals.d.ts","sourceRoot":"","sources":["../src/lib/element-internals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,KAAK,gBAAgB,GAAG;KACrB,CAAC,IAAI,MAAM,SAAS,GAAG,MAAM;CAC/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBA0CjC,CAAC;AAOF,eAAO,MAAM,oBAAoB;gBAoDZ,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBARtB,WAAW;;;;gBAqBO,UAAU,CAAC,gBAAgB,CAAC;;wBAItC,IAAI;uBACL,IAAI;;;kBAGF,aAAa;;;CAE/B,CAAC;AAEF,QAAA,MAAM,gCAAgC,EACF,OAAO,gBAAgB,CAAC;AAC5D,OAAO,EAAC,gCAAgC,IAAI,gBAAgB,EAAC,CAAC;AAE9D,eAAO,MAAM,6BAA6B,uBAAuB,CAAC"}

View File

@@ -0,0 +1,129 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* Map of ARIAMixin properties to attributes
*/
export const ariaMixinAttributes = {
ariaAtomic: 'aria-atomic',
ariaAutoComplete: 'aria-autocomplete',
ariaBrailleLabel: 'aria-braillelabel',
ariaBrailleRoleDescription: 'aria-brailleroledescription',
ariaBusy: 'aria-busy',
ariaChecked: 'aria-checked',
ariaColCount: 'aria-colcount',
ariaColIndex: 'aria-colindex',
ariaColSpan: 'aria-colspan',
ariaCurrent: 'aria-current',
ariaDescription: 'aria-description',
ariaDisabled: 'aria-disabled',
ariaExpanded: 'aria-expanded',
ariaHasPopup: 'aria-haspopup',
ariaHidden: 'aria-hidden',
ariaInvalid: 'aria-invalid',
ariaKeyShortcuts: 'aria-keyshortcuts',
ariaLabel: 'aria-label',
ariaLevel: 'aria-level',
ariaLive: 'aria-live',
ariaModal: 'aria-modal',
ariaMultiLine: 'aria-multiline',
ariaMultiSelectable: 'aria-multiselectable',
ariaOrientation: 'aria-orientation',
ariaPlaceholder: 'aria-placeholder',
ariaPosInSet: 'aria-posinset',
ariaPressed: 'aria-pressed',
ariaReadOnly: 'aria-readonly',
ariaRequired: 'aria-required',
ariaRoleDescription: 'aria-roledescription',
ariaRowCount: 'aria-rowcount',
ariaRowIndex: 'aria-rowindex',
ariaRowSpan: 'aria-rowspan',
ariaSelected: 'aria-selected',
ariaSetSize: 'aria-setsize',
ariaSort: 'aria-sort',
ariaValueMax: 'aria-valuemax',
ariaValueMin: 'aria-valuemin',
ariaValueNow: 'aria-valuenow',
ariaValueText: 'aria-valuetext',
role: 'role',
};
// Shim the global element internals object
// Methods should be fine as noops and properties can generally
// be while on the server.
export const ElementInternalsShim = class ElementInternals {
get shadowRoot() {
// Grab the shadow root instance from the Element shim
// to ensure that the shadow root is always available
// to the internals instance even if the mode is 'closed'
return this.__host
.__shadowRoot;
}
constructor(_host) {
this.ariaAtomic = '';
this.ariaAutoComplete = '';
this.ariaBrailleLabel = '';
this.ariaBrailleRoleDescription = '';
this.ariaBusy = '';
this.ariaChecked = '';
this.ariaColCount = '';
this.ariaColIndex = '';
this.ariaColSpan = '';
this.ariaCurrent = '';
this.ariaDescription = '';
this.ariaDisabled = '';
this.ariaExpanded = '';
this.ariaHasPopup = '';
this.ariaHidden = '';
this.ariaInvalid = '';
this.ariaKeyShortcuts = '';
this.ariaLabel = '';
this.ariaLevel = '';
this.ariaLive = '';
this.ariaModal = '';
this.ariaMultiLine = '';
this.ariaMultiSelectable = '';
this.ariaOrientation = '';
this.ariaPlaceholder = '';
this.ariaPosInSet = '';
this.ariaPressed = '';
this.ariaReadOnly = '';
this.ariaRequired = '';
this.ariaRoleDescription = '';
this.ariaRowCount = '';
this.ariaRowIndex = '';
this.ariaRowSpan = '';
this.ariaSelected = '';
this.ariaSetSize = '';
this.ariaSort = '';
this.ariaValueMax = '';
this.ariaValueMin = '';
this.ariaValueNow = '';
this.ariaValueText = '';
this.role = '';
this.form = null;
this.labels = [];
this.states = new Set();
this.validationMessage = '';
this.validity = {};
this.willValidate = true;
this.__host = _host;
}
checkValidity() {
// TODO(augustjk) Consider actually implementing logic.
// See https://github.com/lit/lit/issues/3740
console.warn('`ElementInternals.checkValidity()` was called on the server.' +
'This method always returns true.');
return true;
}
reportValidity() {
return true;
}
setFormValue() { }
setValidity() { }
};
const ElementInternalsShimWithRealType = ElementInternalsShim;
export { ElementInternalsShimWithRealType as ElementInternals };
export const HYDRATE_INTERNALS_ATTR_PREFIX = 'hydrate-internals-';
//# sourceMappingURL=element-internals.js.map

File diff suppressed because one or more lines are too long

34
node_modules/@lit-labs/ssr-dom-shim/lib/events.d.ts generated vendored Normal file
View File

@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* This is a basic implementation of an EventTarget, Event and CustomEvent.
*
* This is not fully spec compliant (e.g. validation),
* but should work well enough for our use cases.
*
* @see https://dom.spec.whatwg.org/#eventtarget
* @see https://dom.spec.whatwg.org/#event
* @see https://dom.spec.whatwg.org/#customevent
*/
export interface EventTargetShimMeta {
/**
* The event target parent represents the previous event target for an event
* in capture phase and the next event target for a bubbling event.
* Note that this is not the element parent
*/
__eventTargetParent: EventTarget | undefined;
/**
* The host event target/element of this event target, if this event target
* is inside a Shadow DOM.
*/
__host: EventTarget | undefined;
}
declare const EventTargetShimWithRealType: typeof EventTarget;
export { EventTargetShimWithRealType as EventTarget, EventTargetShimWithRealType as EventTargetShim, };
declare const EventShimWithRealType: typeof Event;
declare const CustomEventShimWithRealType: typeof CustomEvent;
export { EventShimWithRealType as Event, EventShimWithRealType as EventShim, CustomEventShimWithRealType as CustomEvent, CustomEventShimWithRealType as CustomEventShim, };
//# sourceMappingURL=events.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/lib/events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,mBAAmB,EAAE,WAAW,GAAG,SAAS,CAAC;IAC7C;;;OAGG;IACH,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;CACjC;AA6PD,QAAA,MAAM,2BAA2B,EACF,OAAO,WAAW,CAAC;AAClD,OAAO,EACL,2BAA2B,IAAI,WAAW,EAC1C,2BAA2B,IAAI,eAAe,GAC/C,CAAC;AAkLF,QAAA,MAAM,qBAAqB,EAA0B,OAAO,KAAK,CAAC;AAClE,QAAA,MAAM,2BAA2B,EACF,OAAO,WAAW,CAAC;AAClD,OAAO,EACL,qBAAqB,IAAI,KAAK,EAC9B,qBAAqB,IAAI,SAAS,EAClC,2BAA2B,IAAI,WAAW,EAC1C,2BAA2B,IAAI,eAAe,GAC/C,CAAC"}

375
node_modules/@lit-labs/ssr-dom-shim/lib/events.js generated vendored Normal file
View File

@@ -0,0 +1,375 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Event_cancelable, _Event_bubbles, _Event_composed, _Event_defaultPrevented, _Event_timestamp, _Event_propagationStopped, _Event_type, _Event_target, _Event_isBeingDispatched, _a, _CustomEvent_detail, _b;
const isCaptureEventListener = (options) => (typeof options === 'boolean' ? options : options?.capture ?? false);
// Event phases
const NONE = 0;
const CAPTURING_PHASE = 1;
const AT_TARGET = 2;
const BUBBLING_PHASE = 3;
// Shim the global EventTarget object
const EventTargetShim = class EventTarget {
constructor() {
this.__eventListeners = new Map();
this.__captureEventListeners = new Map();
}
addEventListener(type, callback, options) {
if (callback === undefined || callback === null) {
return;
}
const eventListenersMap = isCaptureEventListener(options)
? this.__captureEventListeners
: this.__eventListeners;
let eventListeners = eventListenersMap.get(type);
if (eventListeners === undefined) {
eventListeners = new Map();
eventListenersMap.set(type, eventListeners);
}
else if (eventListeners.has(callback)) {
return;
}
const normalizedOptions = typeof options === 'object' && options ? options : {};
normalizedOptions.signal?.addEventListener('abort', () => this.removeEventListener(type, callback, options));
eventListeners.set(callback, normalizedOptions ?? {});
}
removeEventListener(type, callback, options) {
if (callback === undefined || callback === null) {
return;
}
const eventListenersMap = isCaptureEventListener(options)
? this.__captureEventListeners
: this.__eventListeners;
const eventListeners = eventListenersMap.get(type);
if (eventListeners !== undefined) {
eventListeners.delete(callback);
if (!eventListeners.size) {
eventListenersMap.delete(type);
}
}
}
dispatchEvent(event) {
const composedPath = [this];
let parent = this.__eventTargetParent;
if (event.composed) {
while (parent) {
composedPath.push(parent);
parent = parent.__eventTargetParent;
}
}
else {
// If the event is not composed and the event was dispatched inside
// shadow DOM, we need to stop before the host of the shadow DOM.
while (parent && parent !== this.__host) {
composedPath.push(parent);
parent = parent.__eventTargetParent;
}
}
// We need to patch various properties that would either be empty or wrong
// in this scenario.
let stopPropagation = false;
let stopImmediatePropagation = false;
let eventPhase = NONE;
let target = null;
let tmpTarget = null;
let currentTarget = null;
const originalStopPropagation = event.stopPropagation;
const originalStopImmediatePropagation = event.stopImmediatePropagation;
Object.defineProperties(event, {
target: {
get() {
return target ?? tmpTarget;
},
...enumerableProperty,
},
srcElement: {
get() {
return event.target;
},
...enumerableProperty,
},
currentTarget: {
get() {
return currentTarget;
},
...enumerableProperty,
},
eventPhase: {
get() {
return eventPhase;
},
...enumerableProperty,
},
composedPath: {
value: () => composedPath,
...enumerableProperty,
},
stopPropagation: {
value: () => {
stopPropagation = true;
originalStopPropagation.call(event);
},
...enumerableProperty,
},
stopImmediatePropagation: {
value: () => {
stopImmediatePropagation = true;
originalStopImmediatePropagation.call(event);
},
...enumerableProperty,
},
});
// An event handler can either be a function, an object with a handleEvent
// method or null. This function takes care to call the event handler
// correctly.
const invokeEventListener = (listener, options, eventListenerMap) => {
if (typeof listener === 'function') {
listener(event);
}
else if (typeof listener?.handleEvent === 'function') {
listener.handleEvent(event);
}
if (options.once) {
eventListenerMap.delete(listener);
}
};
// When an event is finished being dispatched, which can be after the event
// tree has been traversed or stopPropagation/stopImmediatePropagation has
// been called. Once that is the case, the currentTarget and eventPhase
// need to be reset and a value, representing whether the event has not
// been prevented, needs to be returned.
const finishDispatch = () => {
currentTarget = null;
eventPhase = NONE;
return !event.defaultPrevented;
};
// An event starts with the capture order, where it starts from the top.
// This is done even if bubbles is set to false, which is the default.
const captureEventPath = composedPath.slice().reverse();
// If the event target, which dispatches the event, is either in the light DOM
// or the event is not composed, the target is always itself. If that is not
// the case, the target needs to be retargeted: https://dom.spec.whatwg.org/#retarget
target = !this.__host || !event.composed ? this : null;
const retarget = (eventTargets) => {
// eslint-disable-next-line @typescript-eslint/no-this-alias
tmpTarget = this;
while (tmpTarget.__host && eventTargets.includes(tmpTarget.__host)) {
tmpTarget = tmpTarget.__host;
}
};
for (const eventTarget of captureEventPath) {
if (!target && (!tmpTarget || tmpTarget === eventTarget.__host)) {
retarget(captureEventPath.slice(captureEventPath.indexOf(eventTarget)));
}
currentTarget = eventTarget;
eventPhase = eventTarget === event.target ? AT_TARGET : CAPTURING_PHASE;
const captureEventListeners = eventTarget.__captureEventListeners.get(event.type);
if (captureEventListeners) {
for (const [listener, options] of captureEventListeners) {
invokeEventListener(listener, options, captureEventListeners);
if (stopImmediatePropagation) {
// Event.stopImmediatePropagation() stops any following invocation
// of an event handler even on the same event target.
return finishDispatch();
}
}
}
if (stopPropagation) {
// Event.stopPropagation() stops any following invocation
// of an event handler for any following event targets.
return finishDispatch();
}
}
const bubbleEventPath = event.bubbles ? composedPath : [this];
tmpTarget = null;
for (const eventTarget of bubbleEventPath) {
if (!target &&
(!tmpTarget || eventTarget === tmpTarget.__host)) {
retarget(bubbleEventPath.slice(0, bubbleEventPath.indexOf(eventTarget) + 1));
}
currentTarget = eventTarget;
eventPhase = eventTarget === event.target ? AT_TARGET : BUBBLING_PHASE;
const captureEventListeners = eventTarget.__eventListeners.get(event.type);
if (captureEventListeners) {
for (const [listener, options] of captureEventListeners) {
invokeEventListener(listener, options, captureEventListeners);
if (stopImmediatePropagation) {
// Event.stopImmediatePropagation() stops any following invocation
// of an event handler even on the same event target.
return finishDispatch();
}
}
}
if (stopPropagation) {
// Event.stopPropagation() stops any following invocation
// of an event handler for any following event targets.
return finishDispatch();
}
}
return finishDispatch();
}
};
const EventTargetShimWithRealType = EventTargetShim;
export { EventTargetShimWithRealType as EventTarget, EventTargetShimWithRealType as EventTargetShim, };
const enumerableProperty = { __proto__: null };
enumerableProperty.enumerable = true;
Object.freeze(enumerableProperty);
// TODO: Remove this when we remove support for vm modules (--experimental-vm-modules).
const EventShim = (_a = class Event {
constructor(type, options = {}) {
_Event_cancelable.set(this, false);
_Event_bubbles.set(this, false);
_Event_composed.set(this, false);
_Event_defaultPrevented.set(this, false);
_Event_timestamp.set(this, Date.now());
_Event_propagationStopped.set(this, false);
_Event_type.set(this, void 0);
_Event_target.set(this, void 0);
_Event_isBeingDispatched.set(this, void 0);
this.NONE = NONE;
this.CAPTURING_PHASE = CAPTURING_PHASE;
this.AT_TARGET = AT_TARGET;
this.BUBBLING_PHASE = BUBBLING_PHASE;
if (arguments.length === 0)
throw new Error(`The type argument must be specified`);
if (typeof options !== 'object' || !options) {
throw new Error(`The "options" argument must be an object`);
}
const { bubbles, cancelable, composed } = options;
__classPrivateFieldSet(this, _Event_cancelable, !!cancelable, "f");
__classPrivateFieldSet(this, _Event_bubbles, !!bubbles, "f");
__classPrivateFieldSet(this, _Event_composed, !!composed, "f");
__classPrivateFieldSet(this, _Event_type, `${type}`, "f");
__classPrivateFieldSet(this, _Event_target, null, "f");
__classPrivateFieldSet(this, _Event_isBeingDispatched, false, "f");
}
initEvent(_type, _bubbles, _cancelable) {
throw new Error('Method not implemented.');
}
stopImmediatePropagation() {
this.stopPropagation();
}
preventDefault() {
__classPrivateFieldSet(this, _Event_defaultPrevented, true, "f");
}
get target() {
return __classPrivateFieldGet(this, _Event_target, "f");
}
get currentTarget() {
return __classPrivateFieldGet(this, _Event_target, "f");
}
get srcElement() {
return __classPrivateFieldGet(this, _Event_target, "f");
}
get type() {
return __classPrivateFieldGet(this, _Event_type, "f");
}
get cancelable() {
return __classPrivateFieldGet(this, _Event_cancelable, "f");
}
get defaultPrevented() {
return __classPrivateFieldGet(this, _Event_cancelable, "f") && __classPrivateFieldGet(this, _Event_defaultPrevented, "f");
}
get timeStamp() {
return __classPrivateFieldGet(this, _Event_timestamp, "f");
}
composedPath() {
return __classPrivateFieldGet(this, _Event_isBeingDispatched, "f") ? [__classPrivateFieldGet(this, _Event_target, "f")] : [];
}
get returnValue() {
return !__classPrivateFieldGet(this, _Event_cancelable, "f") || !__classPrivateFieldGet(this, _Event_defaultPrevented, "f");
}
get bubbles() {
return __classPrivateFieldGet(this, _Event_bubbles, "f");
}
get composed() {
return __classPrivateFieldGet(this, _Event_composed, "f");
}
get eventPhase() {
return __classPrivateFieldGet(this, _Event_isBeingDispatched, "f") ? _a.AT_TARGET : _a.NONE;
}
get cancelBubble() {
return __classPrivateFieldGet(this, _Event_propagationStopped, "f");
}
set cancelBubble(value) {
if (value) {
__classPrivateFieldSet(this, _Event_propagationStopped, true, "f");
}
}
stopPropagation() {
__classPrivateFieldSet(this, _Event_propagationStopped, true, "f");
}
get isTrusted() {
return false;
}
},
_Event_cancelable = new WeakMap(),
_Event_bubbles = new WeakMap(),
_Event_composed = new WeakMap(),
_Event_defaultPrevented = new WeakMap(),
_Event_timestamp = new WeakMap(),
_Event_propagationStopped = new WeakMap(),
_Event_type = new WeakMap(),
_Event_target = new WeakMap(),
_Event_isBeingDispatched = new WeakMap(),
_a.NONE = NONE,
_a.CAPTURING_PHASE = CAPTURING_PHASE,
_a.AT_TARGET = AT_TARGET,
_a.BUBBLING_PHASE = BUBBLING_PHASE,
_a);
Object.defineProperties(EventShim.prototype, {
initEvent: enumerableProperty,
stopImmediatePropagation: enumerableProperty,
preventDefault: enumerableProperty,
target: enumerableProperty,
currentTarget: enumerableProperty,
srcElement: enumerableProperty,
type: enumerableProperty,
cancelable: enumerableProperty,
defaultPrevented: enumerableProperty,
timeStamp: enumerableProperty,
composedPath: enumerableProperty,
returnValue: enumerableProperty,
bubbles: enumerableProperty,
composed: enumerableProperty,
eventPhase: enumerableProperty,
cancelBubble: enumerableProperty,
stopPropagation: enumerableProperty,
isTrusted: enumerableProperty,
});
// TODO: Remove this when we remove support for vm modules (--experimental-vm-modules).
const CustomEventShim = (_b = class CustomEvent extends EventShim {
constructor(type, options = {}) {
super(type, options);
_CustomEvent_detail.set(this, void 0);
__classPrivateFieldSet(this, _CustomEvent_detail, options?.detail ?? null, "f");
}
initCustomEvent(_type, _bubbles, _cancelable, _detail) {
throw new Error('Method not implemented.');
}
get detail() {
return __classPrivateFieldGet(this, _CustomEvent_detail, "f");
}
},
_CustomEvent_detail = new WeakMap(),
_b);
Object.defineProperties(CustomEventShim.prototype, {
detail: enumerableProperty,
});
const EventShimWithRealType = EventShim;
const CustomEventShimWithRealType = CustomEventShim;
export { EventShimWithRealType as Event, EventShimWithRealType as EventShim, CustomEventShimWithRealType as CustomEvent, CustomEventShimWithRealType as CustomEventShim, };
//# sourceMappingURL=events.js.map

File diff suppressed because one or more lines are too long

64
node_modules/@lit-labs/ssr-dom-shim/package.json generated vendored Normal file
View File

@@ -0,0 +1,64 @@
{
"name": "@lit-labs/ssr-dom-shim",
"version": "1.3.0",
"publishConfig": {
"access": "public"
},
"description": "DOM shim for Lit Server Side Rendering (SSR)",
"license": "BSD-3-Clause",
"author": "Google LLC",
"homepage": "https://github.com/lit/lit/tree/main/packages/labs/ssr-dom-shim",
"repository": {
"type": "git",
"url": "https://github.com/lit/lit.git",
"directory": "packages/labs/ssr-dom-shim"
},
"main": "index.js",
"typings": "index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
}
},
"files": [
"index.{d.ts,d.ts.map,js,js.map}",
"lib/"
],
"scripts": {
"build": "wireit",
"build:ts": "wireit",
"test": "wireit"
},
"wireit": {
"build": {
"dependencies": [
"build:ts"
]
},
"build:ts": {
"command": "tsc --build --pretty",
"clean": "if-file-deleted",
"files": [
"src/**/*.ts",
"tsconfig.json"
],
"output": [
"lib/",
"index.{d.ts,d.ts.map,js,js.map}",
"tsconfig.tsbuildinfo"
]
},
"test": {
"command": "uvu test \"_test\\.js$\"",
"dependencies": [
"build"
],
"env": {
"NODE_OPTIONS": "--enable-source-maps"
},
"output": []
}
}
}