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

View File

@@ -0,0 +1,133 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const global = globalThis ;
/**
* Whether the current browser supports `adoptedStyleSheets`.
*/
const supportsAdoptingStyleSheets = global.ShadowRoot &&
(global.ShadyCSS === undefined || global.ShadyCSS.nativeShadow) &&
'adoptedStyleSheets' in Document.prototype &&
'replace' in CSSStyleSheet.prototype;
const constructionToken = Symbol();
const cssTagCache = new WeakMap();
/**
* A container for a string of CSS text, that may be used to create a CSSStyleSheet.
*
* CSSResult is the return value of `css`-tagged template literals and
* `unsafeCSS()`. In order to ensure that CSSResults are only created via the
* `css` tag and `unsafeCSS()`, CSSResult cannot be constructed directly.
*/
class CSSResult {
constructor(cssText, strings, safeToken) {
// This property needs to remain unminified.
this['_$cssResult$'] = true;
if (safeToken !== constructionToken) {
throw new Error('CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
}
this.cssText = cssText;
this._strings = strings;
}
// This is a getter so that it's lazy. In practice, this means stylesheets
// are not created until the first element instance is made.
get styleSheet() {
// If `supportsAdoptingStyleSheets` is true then we assume CSSStyleSheet is
// constructable.
let styleSheet = this._styleSheet;
const strings = this._strings;
if (supportsAdoptingStyleSheets && styleSheet === undefined) {
const cacheable = strings !== undefined && strings.length === 1;
if (cacheable) {
styleSheet = cssTagCache.get(strings);
}
if (styleSheet === undefined) {
(this._styleSheet = styleSheet = new CSSStyleSheet()).replaceSync(this.cssText);
if (cacheable) {
cssTagCache.set(strings, styleSheet);
}
}
}
return styleSheet;
}
toString() {
return this.cssText;
}
}
const textFromCSSResult = (value) => {
// This property needs to remain unminified.
if (value['_$cssResult$'] === true) {
return value.cssText;
}
else if (typeof value === 'number') {
return value;
}
else {
throw new Error(`Value passed to 'css' function must be a 'css' function result: ` +
`${value}. Use 'unsafeCSS' to pass non-literal values, but take care ` +
`to ensure page security.`);
}
};
/**
* Wrap a value for interpolation in a {@linkcode css} tagged template literal.
*
* This is unsafe because untrusted CSS text can be used to phone home
* or exfiltrate data to an attacker controlled site. Take care to only use
* this with trusted input.
*/
const unsafeCSS = (value) => new CSSResult(typeof value === 'string' ? value : String(value), undefined, constructionToken);
/**
* A template literal tag which can be used with LitElement's
* {@linkcode LitElement.styles} property to set element styles.
*
* For security reasons, only literal string values and number may be used in
* embedded expressions. To incorporate non-literal values {@linkcode unsafeCSS}
* may be used inside an expression.
*/
const css = (strings, ...values) => {
const cssText = strings.length === 1
? strings[0]
: values.reduce((acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1], strings[0]);
return new CSSResult(cssText, strings, constructionToken);
};
/**
* Applies the given styles to a `shadowRoot`. When Shadow DOM is
* available but `adoptedStyleSheets` is not, styles are appended to the
* `shadowRoot` to [mimic spec behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).
* Note, when shimming is used, any styles that are subsequently placed into
* the shadowRoot should be placed *before* any shimmed adopted styles. This
* will match spec behavior that gives adopted sheets precedence over styles in
* shadowRoot.
*/
const adoptStyles = (renderRoot, styles) => {
if (supportsAdoptingStyleSheets) {
renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
}
else {
styles.forEach((s) => {
const style = document.createElement('style');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nonce = global['litNonce'];
if (nonce !== undefined) {
style.setAttribute('nonce', nonce);
}
style.textContent = s.cssText;
renderRoot.appendChild(style);
});
}
};
const cssResultFromStyleSheet = (sheet) => {
let cssText = '';
for (const rule of sheet.cssRules) {
cssText += rule.cssText;
}
return unsafeCSS(cssText);
};
const getCompatibleStyle = supportsAdoptingStyleSheets ||
(global.CSSStyleSheet === undefined)
? (s) => s
: (s) => s instanceof CSSStyleSheet ? cssResultFromStyleSheet(s) : s;
export { CSSResult, adoptStyles, css, getCompatibleStyle, supportsAdoptingStyleSheets, unsafeCSS };
//# sourceMappingURL=css-tag.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
export { decorateProperty, legacyPrototypeMethod, standardPrototypeMethod } from './decorators/base.js';
export { customElement } from './decorators/custom-element.js';
export { property } from './decorators/property.js';
export { state } from './decorators/state.js';
export { eventOptions } from './decorators/event-options.js';
export { query } from './decorators/query.js';
export { queryAll } from './decorators/query-all.js';
export { queryAsync } from './decorators/query-async.js';
export { queryAssignedElements } from './decorators/query-assigned-elements.js';
export { queryAssignedNodes } from './decorators/query-assigned-nodes.js';
//# sourceMappingURL=decorators.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decorators.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}

View File

@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const legacyPrototypeMethod = (descriptor, proto, name) => {
Object.defineProperty(proto, name, descriptor);
};
const standardPrototypeMethod = (descriptor, element) => ({
kind: 'method',
placement: 'prototype',
key: element.key,
descriptor,
});
/**
* Helper for decorating a property that is compatible with both TypeScript
* and Babel decorators. The optional `finisher` can be used to perform work on
* the class. The optional `descriptor` should return a PropertyDescriptor
* to install for the given property.
*
* @param finisher {function} Optional finisher method; receives the element
* constructor and property key as arguments and has no return value.
* @param descriptor {function} Optional descriptor method; receives the
* property key as an argument and returns a property descriptor to define for
* the given property.
* @returns {ClassElement|void}
*/
const decorateProperty = ({ finisher, descriptor, }) => (protoOrDescriptor, name
// Note TypeScript requires the return type to be `void|any`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => {
var _a;
// TypeScript / Babel legacy mode
if (name !== undefined) {
const ctor = protoOrDescriptor
.constructor;
if (descriptor !== undefined) {
Object.defineProperty(protoOrDescriptor, name, descriptor(name));
}
finisher === null || finisher === void 0 ? void 0 : finisher(ctor, name);
// Babel standard mode
}
else {
// Note, the @property decorator saves `key` as `originalKey`
// so try to use it here.
const key =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(_a = protoOrDescriptor.originalKey) !== null && _a !== void 0 ? _a : protoOrDescriptor.key;
const info = descriptor != undefined
? {
kind: 'method',
placement: 'prototype',
key,
descriptor: descriptor(protoOrDescriptor.key),
}
: { ...protoOrDescriptor, key };
if (finisher != undefined) {
info.finisher = function (ctor) {
finisher(ctor, key);
};
}
return info;
}
};
export { decorateProperty, legacyPrototypeMethod, standardPrototypeMethod };
//# sourceMappingURL=base.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const legacyCustomElement = (tagName, clazz) => {
customElements.define(tagName, clazz);
// Cast as any because TS doesn't recognize the return type as being a
// subtype of the decorated class when clazz is typed as
// `Constructor<HTMLElement>` for some reason.
// `Constructor<HTMLElement>` is helpful to make sure the decorator is
// applied to elements however.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return clazz;
};
const standardCustomElement = (tagName, descriptor) => {
const { kind, elements } = descriptor;
return {
kind,
elements,
// This callback is called once the class is otherwise fully defined
finisher(clazz) {
customElements.define(tagName, clazz);
},
};
};
/**
* Class decorator factory that defines the decorated class as a custom element.
*
* ```js
* @customElement('my-element')
* class MyElement extends LitElement {
* render() {
* return html``;
* }
* }
* ```
* @category Decorator
* @param tagName The tag name of the custom element to define.
*/
const customElement = (tagName) => (classOrDescriptor) => typeof classOrDescriptor === 'function'
? legacyCustomElement(tagName, classOrDescriptor)
: standardCustomElement(tagName, classOrDescriptor);
export { customElement };
//# sourceMappingURL=custom-element.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"custom-element.js","sources":["../../../src/decorators/custom-element.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\nimport {Constructor, ClassDescriptor} from './base.js';\n\n/**\n * Allow for custom element classes with private constructors\n */\ntype CustomElementClass = Omit<typeof HTMLElement, 'new'>;\n\nconst legacyCustomElement = (tagName: string, clazz: CustomElementClass) => {\n customElements.define(tagName, clazz as CustomElementConstructor);\n // Cast as any because TS doesn't recognize the return type as being a\n // subtype of the decorated class when clazz is typed as\n // `Constructor<HTMLElement>` for some reason.\n // `Constructor<HTMLElement>` is helpful to make sure the decorator is\n // applied to elements however.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return clazz as any;\n};\n\nconst standardCustomElement = (\n tagName: string,\n descriptor: ClassDescriptor\n) => {\n const {kind, elements} = descriptor;\n return {\n kind,\n elements,\n // This callback is called once the class is otherwise fully defined\n finisher(clazz: Constructor<HTMLElement>) {\n customElements.define(tagName, clazz);\n },\n };\n};\n\n/**\n * Class decorator factory that defines the decorated class as a custom element.\n *\n * ```js\n * @customElement('my-element')\n * class MyElement extends LitElement {\n * render() {\n * return html``;\n * }\n * }\n * ```\n * @category Decorator\n * @param tagName The tag name of the custom element to define.\n */\nexport const customElement =\n (tagName: string) =>\n (classOrDescriptor: CustomElementClass | ClassDescriptor) =>\n typeof classOrDescriptor === 'function'\n ? legacyCustomElement(tagName, classOrDescriptor)\n : standardCustomElement(tagName, classOrDescriptor as ClassDescriptor);\n"],"names":[],"mappings":"AAAA;;;;AAIG;AAeH,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,KAAyB,KAAI;AACzE,IAAA,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,KAAiC,CAAC,CAAC;;;;;;;AAOlE,IAAA,OAAO,KAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAC5B,OAAe,EACf,UAA2B,KACzB;AACF,IAAA,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAC,GAAG,UAAU,CAAC;IACpC,OAAO;QACL,IAAI;QACJ,QAAQ;;AAER,QAAA,QAAQ,CAAC,KAA+B,EAAA;AACtC,YAAA,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SACvC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;AAaG;AACU,MAAA,aAAa,GACxB,CAAC,OAAe,KAChB,CAAC,iBAAuD,KACtD,OAAO,iBAAiB,KAAK,UAAU;AACrC,MAAE,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC;AACjD,MAAE,qBAAqB,CAAC,OAAO,EAAE,iBAAoC;;;;"}

View File

@@ -0,0 +1,49 @@
import { decorateProperty } from './base.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* Adds event listener options to a method used as an event listener in a
* lit-html template.
*
* @param options An object that specifies event listener options as accepted by
* `EventTarget#addEventListener` and `EventTarget#removeEventListener`.
*
* Current browsers support the `capture`, `passive`, and `once` options. See:
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters
*
* ```ts
* class MyElement {
* clicked = false;
*
* render() {
* return html`
* <div @click=${this._onClick}>
* <button></button>
* </div>
* `;
* }
*
* @eventOptions({capture: true})
* _onClick(e) {
* this.clicked = true;
* }
* }
* ```
* @category Decorator
*/
function eventOptions(options) {
return decorateProperty({
finisher: (ctor, name) => {
Object.assign(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ctor.prototype[name], options);
},
});
}
export { eventOptions };
//# sourceMappingURL=event-options.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"event-options.js","sources":["../../../src/decorators/event-options.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {ReactiveElement} from '../reactive-element.js';\nimport {decorateProperty} from './base.js';\n\n/**\n * Adds event listener options to a method used as an event listener in a\n * lit-html template.\n *\n * @param options An object that specifies event listener options as accepted by\n * `EventTarget#addEventListener` and `EventTarget#removeEventListener`.\n *\n * Current browsers support the `capture`, `passive`, and `once` options. See:\n * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters\n *\n * ```ts\n * class MyElement {\n * clicked = false;\n *\n * render() {\n * return html`\n * <div @click=${this._onClick}>\n * <button></button>\n * </div>\n * `;\n * }\n *\n * @eventOptions({capture: true})\n * _onClick(e) {\n * this.clicked = true;\n * }\n * }\n * ```\n * @category Decorator\n */\nexport function eventOptions(options: AddEventListenerOptions) {\n return decorateProperty({\n finisher: (ctor: typeof ReactiveElement, name: PropertyKey) => {\n Object.assign(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ctor.prototype[name as keyof ReactiveElement] as any,\n options\n );\n },\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAYH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,YAAY,CAAC,OAAgC,EAAA;AAC3D,IAAA,OAAO,gBAAgB,CAAC;AACtB,QAAA,QAAQ,EAAE,CAAC,IAA4B,EAAE,IAAiB,KAAI;AAC5D,YAAA,MAAM,CAAC,MAAM;;YAEX,IAAI,CAAC,SAAS,CAAC,IAA6B,CAAQ,EACpD,OAAO,CACR,CAAC;SACH;AACF,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,94 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const standardProperty = (options, element) => {
// When decorating an accessor, pass it through and add property metadata.
// Note, the `hasOwnProperty` check in `createProperty` ensures we don't
// stomp over the user's accessor.
if (element.kind === 'method' &&
element.descriptor &&
!('value' in element.descriptor)) {
return {
...element,
finisher(clazz) {
clazz.createProperty(element.key, options);
},
};
}
else {
// createProperty() takes care of defining the property, but we still
// must return some kind of descriptor, so return a descriptor for an
// unused prototype field. The finisher calls createProperty().
return {
kind: 'field',
key: Symbol(),
placement: 'own',
descriptor: {},
// store the original key so subsequent decorators have access to it.
originalKey: element.key,
// When @babel/plugin-proposal-decorators implements initializers,
// do this instead of the initializer below. See:
// https://github.com/babel/babel/issues/9260 extras: [
// {
// kind: 'initializer',
// placement: 'own',
// initializer: descriptor.initializer,
// }
// ],
initializer() {
if (typeof element.initializer === 'function') {
this[element.key] = element.initializer.call(this);
}
},
finisher(clazz) {
clazz.createProperty(element.key, options);
},
};
}
};
const legacyProperty = (options, proto, name) => {
proto.constructor.createProperty(name, options);
};
/**
* A property decorator which creates a reactive property that reflects a
* corresponding attribute value. When a decorated property is set
* the element will update and render. A {@linkcode PropertyDeclaration} may
* optionally be supplied to configure property features.
*
* This decorator should only be used for public fields. As public fields,
* properties should be considered as primarily settable by element users,
* either via attribute or the property itself.
*
* Generally, properties that are changed by the element should be private or
* protected fields and should use the {@linkcode state} decorator.
*
* However, sometimes element code does need to set a public property. This
* should typically only be done in response to user interaction, and an event
* should be fired informing the user; for example, a checkbox sets its
* `checked` property when clicked and fires a `changed` event. Mutating public
* properties should typically not be done for non-primitive (object or array)
* properties. In other cases when an element needs to manage state, a private
* property decorated via the {@linkcode state} decorator should be used. When
* needed, state properties can be initialized via public properties to
* facilitate complex interactions.
*
* ```ts
* class MyElement {
* @property({ type: Boolean })
* clicked = false;
* }
* ```
* @category Decorator
* @ExportDecoratedItems
*/
function property(options) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (protoOrDescriptor, name) => name !== undefined
? legacyProperty(options, protoOrDescriptor, name)
: standardProperty(options, protoOrDescriptor);
}
export { property };
//# sourceMappingURL=property.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,46 @@
import { decorateProperty } from './base.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* A property decorator that converts a class property into a getter
* that executes a querySelectorAll on the element's renderRoot.
*
* @param selector A DOMString containing one or more selectors to match.
*
* See:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
*
* ```ts
* class MyElement {
* @queryAll('div')
* divs: NodeListOf<HTMLDivElement>;
*
* render() {
* return html`
* <div id="first"></div>
* <div id="second"></div>
* `;
* }
* }
* ```
* @category Decorator
*/
function queryAll(selector) {
return decorateProperty({
descriptor: (_name) => ({
get() {
var _a, _b;
return (_b = (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selector)) !== null && _b !== void 0 ? _b : [];
},
enumerable: true,
configurable: true,
}),
});
}
export { queryAll };
//# sourceMappingURL=query-all.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"query-all.js","sources":["../../../src/decorators/query-all.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {ReactiveElement} from '../reactive-element.js';\nimport {decorateProperty} from './base.js';\n\n/**\n * A property decorator that converts a class property into a getter\n * that executes a querySelectorAll on the element's renderRoot.\n *\n * @param selector A DOMString containing one or more selectors to match.\n *\n * See:\n * https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll\n *\n * ```ts\n * class MyElement {\n * @queryAll('div')\n * divs: NodeListOf<HTMLDivElement>;\n *\n * render() {\n * return html`\n * <div id=\"first\"></div>\n * <div id=\"second\"></div>\n * `;\n * }\n * }\n * ```\n * @category Decorator\n */\nexport function queryAll(selector: string) {\n return decorateProperty({\n descriptor: (_name: PropertyKey) => ({\n get(this: ReactiveElement) {\n return this.renderRoot?.querySelectorAll(selector) ?? [];\n },\n enumerable: true,\n configurable: true,\n }),\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAYH;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,SAAU,QAAQ,CAAC,QAAgB,EAAA;AACvC,IAAA,OAAO,gBAAgB,CAAC;AACtB,QAAA,UAAU,EAAE,CAAC,KAAkB,MAAM;YACnC,GAAG,GAAA;;AACD,gBAAA,OAAO,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,gBAAgB,CAAC,QAAQ,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,EAAE,CAAC;aAC1D;AACD,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,YAAY,EAAE,IAAI;SACnB,CAAC;AACH,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,68 @@
import { decorateProperty } from './base.js';
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
var _a;
const global = globalThis ;
/**
* A tiny module scoped polyfill for HTMLSlotElement.assignedElements.
*/
const slotAssignedElements = ((_a = global.HTMLSlotElement) === null || _a === void 0 ? void 0 : _a.prototype.assignedElements) != null
? (slot, opts) => slot.assignedElements(opts)
: (slot, opts) => slot
.assignedNodes(opts)
.filter((node) => node.nodeType === Node.ELEMENT_NODE);
/**
* A property decorator that converts a class property into a getter that
* returns the `assignedElements` of the given `slot`. Provides a declarative
* way to use
* [`HTMLSlotElement.assignedElements`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedElements).
*
* Can be passed an optional {@linkcode QueryAssignedElementsOptions} object.
*
* Example usage:
* ```ts
* class MyElement {
* @queryAssignedElements({ slot: 'list' })
* listItems!: Array<HTMLElement>;
* @queryAssignedElements()
* unnamedSlotEls!: Array<HTMLElement>;
*
* render() {
* return html`
* <slot name="list"></slot>
* <slot></slot>
* `;
* }
* }
* ```
*
* Note, the type of this property should be annotated as `Array<HTMLElement>`.
*
* @category Decorator
*/
function queryAssignedElements(options) {
const { slot, selector } = options !== null && options !== void 0 ? options : {};
return decorateProperty({
descriptor: (_name) => ({
get() {
var _a;
const slotSelector = `slot${slot ? `[name=${slot}]` : ':not([name])'}`;
const slotEl = (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector(slotSelector);
const elements = slotEl != null ? slotAssignedElements(slotEl, options) : [];
if (selector) {
return elements.filter((node) => node.matches(selector));
}
return elements;
},
enumerable: true,
configurable: true,
}),
});
}
export { queryAssignedElements };
//# sourceMappingURL=query-assigned-elements.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"query-assigned-elements.js","sources":["../../../src/decorators/query-assigned-elements.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {decorateProperty} from './base.js';\n\nimport type {ReactiveElement} from '../reactive-element.js';\nimport type {QueryAssignedNodesOptions} from './query-assigned-nodes.js';\n\nconst NODE_MODE = false;\nconst global = NODE_MODE ? globalThis : window;\n\n/**\n * A tiny module scoped polyfill for HTMLSlotElement.assignedElements.\n */\nconst slotAssignedElements =\n global.HTMLSlotElement?.prototype.assignedElements != null\n ? (slot: HTMLSlotElement, opts?: AssignedNodesOptions) =>\n slot.assignedElements(opts)\n : (slot: HTMLSlotElement, opts?: AssignedNodesOptions) =>\n slot\n .assignedNodes(opts)\n .filter(\n (node): node is Element => node.nodeType === Node.ELEMENT_NODE\n );\n\n/**\n * Options for the {@linkcode queryAssignedElements} decorator. Extends the\n * options that can be passed into\n * [HTMLSlotElement.assignedElements](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedElements).\n */\nexport interface QueryAssignedElementsOptions\n extends QueryAssignedNodesOptions {\n /**\n * CSS selector used to filter the elements returned. For example, a selector\n * of `\".item\"` will only include elements with the `item` class.\n */\n selector?: string;\n}\n\n/**\n * A property decorator that converts a class property into a getter that\n * returns the `assignedElements` of the given `slot`. Provides a declarative\n * way to use\n * [`HTMLSlotElement.assignedElements`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedElements).\n *\n * Can be passed an optional {@linkcode QueryAssignedElementsOptions} object.\n *\n * Example usage:\n * ```ts\n * class MyElement {\n * @queryAssignedElements({ slot: 'list' })\n * listItems!: Array<HTMLElement>;\n * @queryAssignedElements()\n * unnamedSlotEls!: Array<HTMLElement>;\n *\n * render() {\n * return html`\n * <slot name=\"list\"></slot>\n * <slot></slot>\n * `;\n * }\n * }\n * ```\n *\n * Note, the type of this property should be annotated as `Array<HTMLElement>`.\n *\n * @category Decorator\n */\nexport function queryAssignedElements(options?: QueryAssignedElementsOptions) {\n const {slot, selector} = options ?? {};\n return decorateProperty({\n descriptor: (_name: PropertyKey) => ({\n get(this: ReactiveElement) {\n const slotSelector = `slot${slot ? `[name=${slot}]` : ':not([name])'}`;\n const slotEl =\n this.renderRoot?.querySelector<HTMLSlotElement>(slotSelector);\n const elements =\n slotEl != null ? slotAssignedElements(slotEl, options) : [];\n if (selector) {\n return elements.filter((node) => node.matches(selector));\n }\n return elements;\n },\n enumerable: true,\n configurable: true,\n }),\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;;AAeH,MAAM,MAAM,GAAe,UAAU,CAAS,CAAC;AAE/C;;AAEG;AACH,MAAM,oBAAoB,GACxB,CAAA,CAAA,EAAA,GAAA,MAAM,CAAC,eAAe,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,SAAS,CAAC,gBAAgB,KAAI,IAAI;AACxD,MAAE,CAAC,IAAqB,EAAE,IAA2B,KACjD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;MAC7B,CAAC,IAAqB,EAAE,IAA2B,KACjD,IAAI;SACD,aAAa,CAAC,IAAI,CAAC;AACnB,SAAA,MAAM,CACL,CAAC,IAAI,KAAsB,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,CAC/D,CAAC;AAgBZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACG,SAAU,qBAAqB,CAAC,OAAsC,EAAA;AAC1E,IAAA,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAC,GAAG,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,KAAA,CAAA,GAAP,OAAO,GAAI,EAAE,CAAC;AACvC,IAAA,OAAO,gBAAgB,CAAC;AACtB,QAAA,UAAU,EAAE,CAAC,KAAkB,MAAM;YACnC,GAAG,GAAA;;AACD,gBAAA,MAAM,YAAY,GAAG,CAAO,IAAA,EAAA,IAAI,GAAG,CAAS,MAAA,EAAA,IAAI,GAAG,GAAG,cAAc,EAAE,CAAC;gBACvE,MAAM,MAAM,GACV,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,aAAa,CAAkB,YAAY,CAAC,CAAC;AAChE,gBAAA,MAAM,QAAQ,GACZ,MAAM,IAAI,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;AAC9D,gBAAA,IAAI,QAAQ,EAAE;AACZ,oBAAA,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1D,iBAAA;AACD,gBAAA,OAAO,QAAQ,CAAC;aACjB;AACD,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,YAAY,EAAE,IAAI;SACnB,CAAC;AACH,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,44 @@
import { decorateProperty } from './base.js';
import { queryAssignedElements } from './query-assigned-elements.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
function queryAssignedNodes(slotOrOptions, flatten, selector) {
// Normalize the overloaded arguments.
let slot = slotOrOptions;
let assignedNodesOptions;
if (typeof slotOrOptions === 'object') {
slot = slotOrOptions.slot;
assignedNodesOptions = slotOrOptions;
}
else {
assignedNodesOptions = { flatten };
}
// For backwards compatibility, queryAssignedNodes with a selector behaves
// exactly like queryAssignedElements with a selector.
if (selector) {
return queryAssignedElements({
slot: slot,
flatten,
selector,
});
}
return decorateProperty({
descriptor: (_name) => ({
get() {
var _a, _b;
const slotSelector = `slot${slot ? `[name=${slot}]` : ':not([name])'}`;
const slotEl = (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector(slotSelector);
return (_b = slotEl === null || slotEl === void 0 ? void 0 : slotEl.assignedNodes(assignedNodesOptions)) !== null && _b !== void 0 ? _b : [];
},
enumerable: true,
configurable: true,
}),
});
}
export { queryAssignedNodes };
//# sourceMappingURL=query-assigned-nodes.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,60 @@
import { decorateProperty } from './base.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
// Note, in the future, we may extend this decorator to support the use case
// where the queried element may need to do work to become ready to interact
// with (e.g. load some implementation code). If so, we might elect to
// add a second argument defining a function that can be run to make the
// queried element loaded/updated/ready.
/**
* A property decorator that converts a class property into a getter that
* returns a promise that resolves to the result of a querySelector on the
* element's renderRoot done after the element's `updateComplete` promise
* resolves. When the queried property may change with element state, this
* decorator can be used instead of requiring users to await the
* `updateComplete` before accessing the property.
*
* @param selector A DOMString containing one or more selectors to match.
*
* See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
*
* ```ts
* class MyElement {
* @queryAsync('#first')
* first: Promise<HTMLDivElement>;
*
* render() {
* return html`
* <div id="first"></div>
* <div id="second"></div>
* `;
* }
* }
*
* // external usage
* async doSomethingWithFirst() {
* (await aMyElement.first).doSomething();
* }
* ```
* @category Decorator
*/
function queryAsync(selector) {
return decorateProperty({
descriptor: (_name) => ({
async get() {
var _a;
await this.updateComplete;
return (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector(selector);
},
enumerable: true,
configurable: true,
}),
});
}
export { queryAsync };
//# sourceMappingURL=query-async.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"query-async.js","sources":["../../../src/decorators/query-async.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {ReactiveElement} from '../reactive-element.js';\nimport {decorateProperty} from './base.js';\n\n// Note, in the future, we may extend this decorator to support the use case\n// where the queried element may need to do work to become ready to interact\n// with (e.g. load some implementation code). If so, we might elect to\n// add a second argument defining a function that can be run to make the\n// queried element loaded/updated/ready.\n/**\n * A property decorator that converts a class property into a getter that\n * returns a promise that resolves to the result of a querySelector on the\n * element's renderRoot done after the element's `updateComplete` promise\n * resolves. When the queried property may change with element state, this\n * decorator can be used instead of requiring users to await the\n * `updateComplete` before accessing the property.\n *\n * @param selector A DOMString containing one or more selectors to match.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector\n *\n * ```ts\n * class MyElement {\n * @queryAsync('#first')\n * first: Promise<HTMLDivElement>;\n *\n * render() {\n * return html`\n * <div id=\"first\"></div>\n * <div id=\"second\"></div>\n * `;\n * }\n * }\n *\n * // external usage\n * async doSomethingWithFirst() {\n * (await aMyElement.first).doSomething();\n * }\n * ```\n * @category Decorator\n */\nexport function queryAsync(selector: string) {\n return decorateProperty({\n descriptor: (_name: PropertyKey) => ({\n async get(this: ReactiveElement) {\n await this.updateComplete;\n return this.renderRoot?.querySelector(selector);\n },\n enumerable: true,\n configurable: true,\n }),\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAYH;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACG,SAAU,UAAU,CAAC,QAAgB,EAAA;AACzC,IAAA,OAAO,gBAAgB,CAAC;AACtB,QAAA,UAAU,EAAE,CAAC,KAAkB,MAAM;AACnC,YAAA,MAAM,GAAG,GAAA;;gBACP,MAAM,IAAI,CAAC,cAAc,CAAC;gBAC1B,OAAO,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,0CAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;aACjD;AACD,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,YAAY,EAAE,IAAI;SACnB,CAAC;AACH,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,60 @@
import { decorateProperty } from './base.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* A property decorator that converts a class property into a getter that
* executes a querySelector on the element's renderRoot.
*
* @param selector A DOMString containing one or more selectors to match.
* @param cache An optional boolean which when true performs the DOM query only
* once and caches the result.
*
* See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
*
* ```ts
* class MyElement {
* @query('#first')
* first: HTMLDivElement;
*
* render() {
* return html`
* <div id="first"></div>
* <div id="second"></div>
* `;
* }
* }
* ```
* @category Decorator
*/
function query(selector, cache) {
return decorateProperty({
descriptor: (name) => {
const descriptor = {
get() {
var _a, _b;
return (_b = (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector(selector)) !== null && _b !== void 0 ? _b : null;
},
enumerable: true,
configurable: true,
};
if (cache) {
const key = typeof name === 'symbol' ? Symbol() : `__${name}`;
descriptor.get = function () {
var _a, _b;
if (this[key] === undefined) {
this[key] = (_b = (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector(selector)) !== null && _b !== void 0 ? _b : null;
}
return this[key];
};
}
return descriptor;
},
});
}
export { query };
//# sourceMappingURL=query.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"query.js","sources":["../../../src/decorators/query.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {ReactiveElement} from '../reactive-element.js';\nimport {decorateProperty} from './base.js';\n\n/**\n * A property decorator that converts a class property into a getter that\n * executes a querySelector on the element's renderRoot.\n *\n * @param selector A DOMString containing one or more selectors to match.\n * @param cache An optional boolean which when true performs the DOM query only\n * once and caches the result.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector\n *\n * ```ts\n * class MyElement {\n * @query('#first')\n * first: HTMLDivElement;\n *\n * render() {\n * return html`\n * <div id=\"first\"></div>\n * <div id=\"second\"></div>\n * `;\n * }\n * }\n * ```\n * @category Decorator\n */\nexport function query(selector: string, cache?: boolean) {\n return decorateProperty({\n descriptor: (name: PropertyKey) => {\n const descriptor = {\n get(this: ReactiveElement) {\n return this.renderRoot?.querySelector(selector) ?? null;\n },\n enumerable: true,\n configurable: true,\n };\n if (cache) {\n const key = typeof name === 'symbol' ? Symbol() : `__${name}`;\n descriptor.get = function (this: ReactiveElement) {\n if (\n (this as unknown as {[key: string]: Element | null})[\n key as string\n ] === undefined\n ) {\n (this as unknown as {[key: string]: Element | null})[\n key as string\n ] = this.renderRoot?.querySelector(selector) ?? null;\n }\n return (this as unknown as {[key: string]: Element | null})[\n key as string\n ];\n };\n }\n return descriptor;\n },\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAYH;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACa,SAAA,KAAK,CAAC,QAAgB,EAAE,KAAe,EAAA;AACrD,IAAA,OAAO,gBAAgB,CAAC;AACtB,QAAA,UAAU,EAAE,CAAC,IAAiB,KAAI;AAChC,YAAA,MAAM,UAAU,GAAG;gBACjB,GAAG,GAAA;;AACD,oBAAA,OAAO,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,IAAI,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,aAAa,CAAC,QAAQ,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,IAAI,CAAC;iBACzD;AACD,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,YAAY,EAAE,IAAI;aACnB,CAAC;AACF,YAAA,IAAI,KAAK,EAAE;AACT,gBAAA,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,MAAM,EAAE,GAAG,CAAK,EAAA,EAAA,IAAI,EAAE,CAAC;gBAC9D,UAAU,CAAC,GAAG,GAAG,YAAA;;AACf,oBAAA,IACG,IAAmD,CAClD,GAAa,CACd,KAAK,SAAS,EACf;AACC,wBAAA,IAAmD,CAClD,GAAa,CACd,GAAG,CAAA,EAAA,GAAA,MAAA,IAAI,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,aAAa,CAAC,QAAQ,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,IAAI,CAAC;AACtD,qBAAA;AACD,oBAAA,OAAQ,IAAmD,CACzD,GAAa,CACd,CAAC;AACJ,iBAAC,CAAC;AACH,aAAA;AACD,YAAA,OAAO,UAAU,CAAC;SACnB;AACF,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,26 @@
import { property } from './property.js';
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* Declares a private or protected reactive property that still triggers
* updates to the element when it changes. It does not reflect from the
* corresponding attribute.
*
* Properties declared this way must not be used from HTML or HTML templating
* systems, they're solely for properties internal to the element. These
* properties may be renamed by optimization tools like closure compiler.
* @category Decorator
*/
function state(options) {
return property({
...options,
state: true,
});
}
export { state };
//# sourceMappingURL=state.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"state.js","sources":["../../../src/decorators/state.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/*\n * IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all\n * property decorators (but not class decorators) in this file that have\n * an @ExportDecoratedItems annotation must be defined as a regular function,\n * not an arrow function.\n */\n\nimport {property} from './property.js';\n\nexport interface InternalPropertyDeclaration<Type = unknown> {\n /**\n * A function that indicates if a property should be considered changed when\n * it is set. The function should take the `newValue` and `oldValue` and\n * return `true` if an update should be requested.\n */\n hasChanged?(value: Type, oldValue: Type): boolean;\n}\n\n/**\n * Declares a private or protected reactive property that still triggers\n * updates to the element when it changes. It does not reflect from the\n * corresponding attribute.\n *\n * Properties declared this way must not be used from HTML or HTML templating\n * systems, they're solely for properties internal to the element. These\n * properties may be renamed by optimization tools like closure compiler.\n * @category Decorator\n */\nexport function state(options?: InternalPropertyDeclaration) {\n return property({\n ...options,\n state: true,\n });\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AAoBH;;;;;;;;;AASG;AACG,SAAU,KAAK,CAAC,OAAqC,EAAA;AACzD,IAAA,OAAO,QAAQ,CAAC;AACd,QAAA,GAAG,OAAO;AACV,QAAA,KAAK,EAAE,IAAI;AACZ,KAAA,CAAC,CAAC;AACL;;;;"}

View File

@@ -0,0 +1,2 @@
//# sourceMappingURL=reactive-controller.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"reactive-controller.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long