@a11d/lit 0.0.6

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.
Files changed (95) hide show
  1. package/README.md +1 -0
  2. package/dist/Component/Component.d.ts +18 -0
  3. package/dist/Component/Component.js +31 -0
  4. package/dist/Component/index.d.ts +2 -0
  5. package/dist/Component/index.js +2 -0
  6. package/dist/Component/nothing.d.ts +2 -0
  7. package/dist/Component/nothing.js +2 -0
  8. package/dist/Controller/Controller.d.ts +9 -0
  9. package/dist/Controller/Controller.js +6 -0
  10. package/dist/Controller/index.d.ts +1 -0
  11. package/dist/Controller/index.js +1 -0
  12. package/dist/decorateLitElement.d.ts +7 -0
  13. package/dist/decorateLitElement.js +19 -0
  14. package/dist/event/EventDispatcher.d.ts +6 -0
  15. package/dist/event/EventDispatcher.js +1 -0
  16. package/dist/event/HTMLElementEventDispatcher.d.ts +10 -0
  17. package/dist/event/HTMLElementEventDispatcher.js +23 -0
  18. package/dist/event/PureEventDispatcher.d.ts +6 -0
  19. package/dist/event/PureEventDispatcher.js +16 -0
  20. package/dist/event/event.d.ts +1 -0
  21. package/dist/event/event.js +20 -0
  22. package/dist/event/index.d.ts +3 -0
  23. package/dist/event/index.js +3 -0
  24. package/dist/eventListener/eventListener.d.ts +13 -0
  25. package/dist/eventListener/eventListener.js +76 -0
  26. package/dist/eventListener/index.d.ts +1 -0
  27. package/dist/eventListener/index.js +1 -0
  28. package/dist/index.d.ts +29 -0
  29. package/dist/index.js +30 -0
  30. package/dist/packages/Component/Component.d.ts +18 -0
  31. package/dist/packages/Component/Component.js +31 -0
  32. package/dist/packages/Component/index.d.ts +2 -0
  33. package/dist/packages/Component/index.js +2 -0
  34. package/dist/packages/Component/nothing.d.ts +2 -0
  35. package/dist/packages/Component/nothing.js +2 -0
  36. package/dist/packages/Controller/Controller.d.ts +9 -0
  37. package/dist/packages/Controller/Controller.js +6 -0
  38. package/dist/packages/Controller/index.d.ts +1 -0
  39. package/dist/packages/Controller/index.js +1 -0
  40. package/dist/packages/decorateLitElement.d.ts +7 -0
  41. package/dist/packages/decorateLitElement.js +19 -0
  42. package/dist/packages/event/EventDispatcher.d.ts +6 -0
  43. package/dist/packages/event/EventDispatcher.js +1 -0
  44. package/dist/packages/event/HTMLElementEventDispatcher.d.ts +10 -0
  45. package/dist/packages/event/HTMLElementEventDispatcher.js +23 -0
  46. package/dist/packages/event/PureEventDispatcher.d.ts +6 -0
  47. package/dist/packages/event/PureEventDispatcher.js +16 -0
  48. package/dist/packages/event/event.d.ts +1 -0
  49. package/dist/packages/event/event.js +20 -0
  50. package/dist/packages/event/index.d.ts +3 -0
  51. package/dist/packages/event/index.js +3 -0
  52. package/dist/packages/eventListener/eventListener.d.ts +13 -0
  53. package/dist/packages/eventListener/eventListener.js +76 -0
  54. package/dist/packages/eventListener/index.d.ts +1 -0
  55. package/dist/packages/eventListener/index.js +1 -0
  56. package/dist/packages/index.d.ts +29 -0
  57. package/dist/packages/index.js +30 -0
  58. package/dist/packages/query/index.d.ts +3 -0
  59. package/dist/packages/query/index.js +3 -0
  60. package/dist/packages/query/query.d.ts +2 -0
  61. package/dist/packages/query/query.js +9 -0
  62. package/dist/packages/query/queryAll.d.ts +2 -0
  63. package/dist/packages/query/queryAll.js +9 -0
  64. package/dist/packages/query/queryAllAsNodeList.d.ts +2 -0
  65. package/dist/packages/query/queryAllAsNodeList.js +2 -0
  66. package/dist/packages/types.d.ts +2 -0
  67. package/dist/packages/types.js +1 -0
  68. package/dist/packages/updated/index.d.ts +3 -0
  69. package/dist/packages/updated/index.js +3 -0
  70. package/dist/packages/updated/property.d.ts +5 -0
  71. package/dist/packages/updated/property.js +10 -0
  72. package/dist/packages/updated/state.d.ts +6 -0
  73. package/dist/packages/updated/state.js +10 -0
  74. package/dist/packages/updated/updated.d.ts +3 -0
  75. package/dist/packages/updated/updated.js +21 -0
  76. package/dist/query/index.d.ts +3 -0
  77. package/dist/query/index.js +3 -0
  78. package/dist/query/query.d.ts +2 -0
  79. package/dist/query/query.js +9 -0
  80. package/dist/query/queryAll.d.ts +2 -0
  81. package/dist/query/queryAll.js +9 -0
  82. package/dist/query/queryAllAsNodeList.d.ts +2 -0
  83. package/dist/query/queryAllAsNodeList.js +2 -0
  84. package/dist/tsconfig.tsbuildinfo +1 -0
  85. package/dist/types.d.ts +2 -0
  86. package/dist/types.js +1 -0
  87. package/dist/updated/index.d.ts +3 -0
  88. package/dist/updated/index.js +3 -0
  89. package/dist/updated/property.d.ts +5 -0
  90. package/dist/updated/property.js +10 -0
  91. package/dist/updated/state.d.ts +6 -0
  92. package/dist/updated/state.js +10 -0
  93. package/dist/updated/updated.d.ts +3 -0
  94. package/dist/updated/updated.js +21 -0
  95. package/package.json +32 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ A thin wrapper around the Lit library.
@@ -0,0 +1,18 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ export declare const component: (tagName: string) => (classOrDescriptor: import("@lit/reactive-element/decorators/base").ClassDescriptor | {
3
+ prototype: HTMLElement;
4
+ }) => any;
5
+ export declare abstract class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ protected initialized(): void;
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ protected connected(): void;
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ protected disconnected(): void;
12
+ /** @deprecated Use template getter instead */
13
+ protected render(): import("lit-html").TemplateResult<2 | 1>;
14
+ protected get template(): import("lit-html").TemplateResult<2 | 1>;
15
+ firstUpdated(props: PropertyValues): void;
16
+ connectedCallback(): void;
17
+ disconnectedCallback(): void;
18
+ }
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { nothing } from '.';
4
+ export const component = customElement;
5
+ export class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ initialized() { }
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ connected() { }
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ disconnected() { }
12
+ /** @deprecated Use template getter instead */
13
+ render() {
14
+ return this.template;
15
+ }
16
+ get template() {
17
+ return nothing;
18
+ }
19
+ firstUpdated(props) {
20
+ super.firstUpdated(props);
21
+ this.initialized();
22
+ }
23
+ connectedCallback() {
24
+ super.connectedCallback();
25
+ this.connected();
26
+ }
27
+ disconnectedCallback() {
28
+ super.disconnectedCallback();
29
+ this.disconnected();
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './nothing';
2
+ export * from './Component';
@@ -0,0 +1,2 @@
1
+ export * from './nothing';
2
+ export * from './Component';
@@ -0,0 +1,2 @@
1
+ import { TemplateResult } from 'lit';
2
+ export declare const nothing: TemplateResult<2 | 1>;
@@ -0,0 +1,2 @@
1
+ import { nothing as litNothing } from 'lit';
2
+ export const nothing = litNothing;
@@ -0,0 +1,9 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export declare abstract class Controller implements ReactiveController {
3
+ protected readonly host: ReactiveControllerHost;
4
+ constructor(host: ReactiveControllerHost);
5
+ hostConnected?(): void;
6
+ hostDisconnected?(): void;
7
+ hostUpdate?(): void;
8
+ hostUpdated?(): void;
9
+ }
@@ -0,0 +1,6 @@
1
+ export class Controller {
2
+ constructor(host) {
3
+ this.host = host;
4
+ this.host.addController(this);
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from './Controller';
@@ -0,0 +1 @@
1
+ export * from './Controller';
@@ -0,0 +1,7 @@
1
+ import { LitElement } from 'lit';
2
+ export declare const decorateLitElement: <T>({ constructorPropertyName, prototype, initialValue, lifecycleHooks }: {
3
+ constructorPropertyName: string;
4
+ prototype: LitElement;
5
+ initialValue: T;
6
+ lifecycleHooks: Map<string, (this: LitElement, data: T, ...args: Array<any>) => any>;
7
+ }) => T;
@@ -0,0 +1,19 @@
1
+ export const decorateLitElement = ({ constructorPropertyName, prototype, initialValue, lifecycleHooks }) => {
2
+ const p = prototype;
3
+ const constructor = prototype.constructor;
4
+ const existingValue = Object.getOwnPropertyDescriptor(constructor, constructorPropertyName)?.value;
5
+ if (existingValue) {
6
+ return existingValue;
7
+ }
8
+ const inheritedValue = constructor[constructorPropertyName];
9
+ const value = inheritedValue ? Object.assign(initialValue, inheritedValue) : initialValue;
10
+ Object.defineProperty(constructor, constructorPropertyName, { value });
11
+ for (const [lifecycleName, lifecycleFunction] of lifecycleHooks) {
12
+ const originalFunction = p[lifecycleName];
13
+ p[lifecycleName] = function (...args) {
14
+ originalFunction.call(this, ...args);
15
+ lifecycleFunction.call(this, value, ...args);
16
+ };
17
+ }
18
+ return value;
19
+ };
@@ -0,0 +1,6 @@
1
+ declare type EventHandler<T> = (data: T) => void;
2
+ interface EventDispatcher<T = void> {
3
+ dispatch(value: T): void;
4
+ subscribe(handler: EventHandler<T>): void;
5
+ unsubscribe(handler: EventHandler<T>): void;
6
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,10 @@
1
+ export declare class HTMLElementEventDispatcher<T = void> implements EventDispatcher<T> {
2
+ private readonly element;
3
+ private readonly type;
4
+ private readonly options?;
5
+ private readonly handlersMap;
6
+ constructor(element: HTMLElement, type: string, options?: EventInit | undefined);
7
+ dispatch(value: T): void;
8
+ subscribe(handler: EventHandler<T>): void;
9
+ unsubscribe(handler: EventHandler<T>): void;
10
+ }
@@ -0,0 +1,23 @@
1
+ export class HTMLElementEventDispatcher {
2
+ constructor(element, type, options) {
3
+ this.element = element;
4
+ this.type = type;
5
+ this.options = options;
6
+ this.handlersMap = new Map();
7
+ }
8
+ dispatch(value) {
9
+ this.element.dispatchEvent(new CustomEvent(this.type, { detail: value, ...this.options }));
10
+ }
11
+ subscribe(handler) {
12
+ const nativeHandler = (event) => handler(event.detail);
13
+ this.element.addEventListener(this.type, nativeHandler);
14
+ this.handlersMap.set(handler, nativeHandler);
15
+ }
16
+ unsubscribe(handler) {
17
+ const nativeHandler = this.handlersMap.get(handler);
18
+ if (nativeHandler) {
19
+ this.element.removeEventListener(this.type, nativeHandler);
20
+ }
21
+ this.handlersMap.delete(handler);
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ export declare class PureEventDispatcher<T = void> implements EventDispatcher<T> {
2
+ private readonly handlers;
3
+ subscribe(handler: EventHandler<T>): void;
4
+ unsubscribe(handler: EventHandler<T>): void;
5
+ dispatch(data: T): void;
6
+ }
@@ -0,0 +1,16 @@
1
+ export class PureEventDispatcher {
2
+ constructor() {
3
+ this.handlers = new Set();
4
+ }
5
+ subscribe(handler) {
6
+ this.handlers.add(handler);
7
+ }
8
+ unsubscribe(handler) {
9
+ this.handlers.delete(handler);
10
+ }
11
+ dispatch(data) {
12
+ for (const handler of this.handlers) {
13
+ handler(data);
14
+ }
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export declare function event(options?: EventInit): (prototype: unknown, propertyKey?: string) => void;
@@ -0,0 +1,20 @@
1
+ import { HTMLElementEventDispatcher } from './HTMLElementEventDispatcher';
2
+ import { PureEventDispatcher } from './PureEventDispatcher';
3
+ export function event(options) {
4
+ return (prototype, propertyKey) => {
5
+ if (propertyKey === undefined) {
6
+ return;
7
+ }
8
+ const eventFieldName = `$${propertyKey}Event$`;
9
+ Object.defineProperty(prototype, propertyKey, {
10
+ get() {
11
+ if (!this[eventFieldName]) {
12
+ this[eventFieldName] = this instanceof HTMLElement
13
+ ? new HTMLElementEventDispatcher(this, propertyKey, options)
14
+ : new PureEventDispatcher();
15
+ }
16
+ return this[eventFieldName];
17
+ }
18
+ });
19
+ };
20
+ }
@@ -0,0 +1,3 @@
1
+ export * from './PureEventDispatcher';
2
+ export * from './HTMLElementEventDispatcher';
3
+ export * from './event';
@@ -0,0 +1,3 @@
1
+ export * from './PureEventDispatcher';
2
+ export * from './HTMLElementEventDispatcher';
3
+ export * from './event';
@@ -0,0 +1,13 @@
1
+ import { LitElement } from 'lit';
2
+ declare type ShorthandEventListenerDecoratorOptions = [type: string, options?: EventListenerOptions | boolean];
3
+ declare type FullEventListenerDecoratorOptions = [
4
+ {
5
+ type: string;
6
+ target?: EventTarget | ((this: any) => EventTarget);
7
+ options?: EventListenerOptions | boolean;
8
+ }
9
+ ];
10
+ declare type EventListenerDecoratorOptions = ShorthandEventListenerDecoratorOptions | FullEventListenerDecoratorOptions;
11
+ export declare const eventListener: (...eventListenerOptions: EventListenerDecoratorOptions) => (prototype: LitElement, propertyKey: string, descriptor?: PropertyDescriptor) => void;
12
+ export declare const extractEventHandler: <TEvent extends Event = Event>(eventListener: EventListenerOrEventListenerObject) => (event: TEvent) => void;
13
+ export {};
@@ -0,0 +1,76 @@
1
+ import { decorateLitElement } from '../decorateLitElement';
2
+ function extractArguments(args) {
3
+ const short = ((args) => typeof args[0] === 'string')(args);
4
+ return {
5
+ type: short ? args[0] : args[0].type,
6
+ target: short ? undefined : args[0].target,
7
+ options: short ? args[1] : args[0].options,
8
+ };
9
+ }
10
+ function extractEventTarget(target) {
11
+ return typeof target === 'function' ? target.call(this) : target ?? this;
12
+ }
13
+ export const eventListener = (...eventListenerOptions) => {
14
+ return (prototype, propertyKey, descriptor) => {
15
+ decorateLitElement({
16
+ prototype,
17
+ constructorPropertyName: '$eventListeners$',
18
+ initialValue: new Map,
19
+ lifecycleHooks: new Map([
20
+ ['connectedCallback', function (eventListeners) {
21
+ for (const [key, { type, target, options, descriptor, property }] of eventListeners) {
22
+ if (this.constructor.name === extractConstructorNameFromUniquePropertyKey(key)) {
23
+ defineBoundListener.call(this, property, descriptor);
24
+ extractEventTarget.call(this, target)
25
+ ?.addEventListener(type, getBoundListener.call(this, property), options);
26
+ }
27
+ }
28
+ }],
29
+ ['disconnectedCallback', function (eventListeners) {
30
+ for (const { type, target, options, property } of eventListeners.values()) {
31
+ extractEventTarget.call(this, target)
32
+ ?.removeEventListener(type, getBoundListener.call(this, property), options);
33
+ }
34
+ }],
35
+ ])
36
+ }).set(getUniquePropertyKey(prototype.constructor, propertyKey), { descriptor, property: propertyKey, ...extractArguments(eventListenerOptions) });
37
+ };
38
+ };
39
+ const getUniquePropertyKey = (constructor, property) => `${constructor.name}.${property}`;
40
+ const extractConstructorNameFromUniquePropertyKey = (uniquePropertyKey) => uniquePropertyKey.split('.')[0];
41
+ function getBoundListener(propertyKey) {
42
+ return Object.getOwnPropertyDescriptor(this, getBoundMethodKey(propertyKey))?.value;
43
+ }
44
+ function defineBoundListener(propertyKey, descriptor) {
45
+ const unboundFunction = !descriptor
46
+ ? Object.getOwnPropertyDescriptor(this, propertyKey)?.value
47
+ : typeof descriptor.get === 'function'
48
+ ? descriptor.get
49
+ : descriptor.value;
50
+ if (isEventListenerOrEventListenerObject(unboundFunction) === false) {
51
+ throw new TypeError(`${getUniquePropertyKey(this.constructor, propertyKey)} is not a function`);
52
+ }
53
+ Object.defineProperty(this, getBoundMethodKey(propertyKey), {
54
+ // eslint-disable-next-line no-restricted-syntax
55
+ value: unboundFunction.bind(this),
56
+ configurable: true,
57
+ enumerable: false,
58
+ writable: false,
59
+ });
60
+ }
61
+ const getBoundMethodKey = (method) => `$BOUND_${method}$`;
62
+ const isEventListenerOrEventListenerObject = (listener) => {
63
+ const isListener = typeof listener === 'function';
64
+ // @ts-expect-error 'in' operator seemingly does not narrow down the type
65
+ const isListenerObject = typeof listener === 'object' && listener !== null && 'handleEvent' in listener && typeof listener.handleEvent === 'function';
66
+ return isListener || isListenerObject;
67
+ };
68
+ export const extractEventHandler = (eventListener) => {
69
+ if ('_$committedValue' in eventListener) {
70
+ const eventPart = eventListener;
71
+ const handler = eventListener['_$committedValue'];
72
+ // eslint-disable-next-line no-restricted-syntax
73
+ return handler.bind(eventPart.element);
74
+ }
75
+ return typeof eventListener === 'function' ? eventListener : eventListener.handleEvent;
76
+ };
@@ -0,0 +1 @@
1
+ export * from './eventListener';
@@ -0,0 +1 @@
1
+ export * from './eventListener';
@@ -0,0 +1,29 @@
1
+ export * from 'lit';
2
+ export { InternalPropertyDeclaration, QueryAssignedElementsOptions, QueryAssignedNodesOptions, eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
3
+ export * from 'lit-html';
4
+ export * from 'lit/directive.js';
5
+ export * from 'lit/directives/repeat.js';
6
+ export * from 'lit/directives/cache.js';
7
+ export * from 'lit/directives/if-defined.js';
8
+ export * from 'lit/directives/until.js';
9
+ export * from 'lit/directives/live.js';
10
+ export * from 'lit/directives/style-map.js';
11
+ export * from 'lit/directives/class-map.js';
12
+ export * from 'lit/directives/choose.js';
13
+ export * from 'lit/directives/join.js';
14
+ export * from 'lit/directives/async-append.js';
15
+ export * from 'lit/directives/async-replace.js';
16
+ export * from 'lit/directives/ref.js';
17
+ export * from 'lit/directives/unsafe-html.js';
18
+ export * from 'lit/directives/unsafe-svg.js';
19
+ export * from 'lit/directives/when.js';
20
+ export * from 'lit/directives/async-replace';
21
+ export * from 'lit/directives/async-append';
22
+ export * from 'lit/directives/template-content';
23
+ import './types';
24
+ export { Component, nothing } from './Component';
25
+ export * from './Controller';
26
+ export * from './query';
27
+ export * from './updated';
28
+ export * from './eventListener';
29
+ export * from './event';
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /* eslint-disable import/export */
2
+ export * from 'lit';
3
+ export { eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
4
+ export * from 'lit-html';
5
+ export * from 'lit/directive.js';
6
+ export * from 'lit/directives/repeat.js';
7
+ export * from 'lit/directives/cache.js';
8
+ export * from 'lit/directives/if-defined.js';
9
+ export * from 'lit/directives/until.js';
10
+ export * from 'lit/directives/live.js';
11
+ export * from 'lit/directives/style-map.js';
12
+ export * from 'lit/directives/class-map.js';
13
+ export * from 'lit/directives/choose.js';
14
+ export * from 'lit/directives/join.js';
15
+ export * from 'lit/directives/async-append.js';
16
+ export * from 'lit/directives/async-replace.js';
17
+ export * from 'lit/directives/ref.js';
18
+ export * from 'lit/directives/unsafe-html.js';
19
+ export * from 'lit/directives/unsafe-svg.js';
20
+ export * from 'lit/directives/when.js';
21
+ export * from 'lit/directives/async-replace';
22
+ export * from 'lit/directives/async-append';
23
+ export * from 'lit/directives/template-content';
24
+ import './types';
25
+ export { Component, nothing } from './Component';
26
+ export * from './Controller';
27
+ export * from './query';
28
+ export * from './updated';
29
+ export * from './eventListener';
30
+ export * from './event';
@@ -0,0 +1,18 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ export declare const component: (tagName: string) => (classOrDescriptor: import("@lit/reactive-element/decorators/base").ClassDescriptor | {
3
+ prototype: HTMLElement;
4
+ }) => any;
5
+ export declare abstract class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ protected initialized(): void;
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ protected connected(): void;
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ protected disconnected(): void;
12
+ /** @deprecated Use template getter instead */
13
+ protected render(): import("lit-html").TemplateResult<1 | 2>;
14
+ protected get template(): import("lit-html").TemplateResult<1 | 2>;
15
+ firstUpdated(props: PropertyValues): void;
16
+ connectedCallback(): void;
17
+ disconnectedCallback(): void;
18
+ }
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { nothing } from '.';
4
+ export const component = customElement;
5
+ export class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ initialized() { }
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ connected() { }
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ disconnected() { }
12
+ /** @deprecated Use template getter instead */
13
+ render() {
14
+ return this.template;
15
+ }
16
+ get template() {
17
+ return nothing;
18
+ }
19
+ firstUpdated(props) {
20
+ super.firstUpdated(props);
21
+ this.initialized();
22
+ }
23
+ connectedCallback() {
24
+ super.connectedCallback();
25
+ this.connected();
26
+ }
27
+ disconnectedCallback() {
28
+ super.disconnectedCallback();
29
+ this.disconnected();
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './nothing';
2
+ export * from './Component';
@@ -0,0 +1,2 @@
1
+ export * from './nothing';
2
+ export * from './Component';
@@ -0,0 +1,2 @@
1
+ import { TemplateResult } from 'lit';
2
+ export declare const nothing: TemplateResult<1 | 2>;
@@ -0,0 +1,2 @@
1
+ import { nothing as litNothing } from 'lit';
2
+ export const nothing = litNothing;
@@ -0,0 +1,9 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export declare abstract class Controller implements ReactiveController {
3
+ protected readonly host: ReactiveControllerHost;
4
+ constructor(host: ReactiveControllerHost);
5
+ hostConnected?(): void;
6
+ hostDisconnected?(): void;
7
+ hostUpdate?(): void;
8
+ hostUpdated?(): void;
9
+ }
@@ -0,0 +1,6 @@
1
+ export class Controller {
2
+ constructor(host) {
3
+ this.host = host;
4
+ this.host.addController(this);
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from './Controller';
@@ -0,0 +1 @@
1
+ export * from './Controller';
@@ -0,0 +1,7 @@
1
+ import { LitElement } from 'lit';
2
+ export declare const decorateLitElement: <T>({ constructorPropertyName, prototype, initialValue, lifecycleHooks }: {
3
+ constructorPropertyName: string;
4
+ prototype: LitElement;
5
+ initialValue: T;
6
+ lifecycleHooks: Map<string, (this: LitElement, data: T, ...args: Array<any>) => any>;
7
+ }) => T;
@@ -0,0 +1,19 @@
1
+ export const decorateLitElement = ({ constructorPropertyName, prototype, initialValue, lifecycleHooks }) => {
2
+ const p = prototype;
3
+ const constructor = prototype.constructor;
4
+ const existingValue = Object.getOwnPropertyDescriptor(constructor, constructorPropertyName)?.value;
5
+ if (existingValue) {
6
+ return existingValue;
7
+ }
8
+ const inheritedValue = constructor[constructorPropertyName];
9
+ const value = inheritedValue ? Object.assign(initialValue, inheritedValue) : initialValue;
10
+ Object.defineProperty(constructor, constructorPropertyName, { value });
11
+ for (const [lifecycleName, lifecycleFunction] of lifecycleHooks) {
12
+ const originalFunction = p[lifecycleName];
13
+ p[lifecycleName] = function (...args) {
14
+ originalFunction.call(this, ...args);
15
+ lifecycleFunction.call(this, value, ...args);
16
+ };
17
+ }
18
+ return value;
19
+ };
@@ -0,0 +1,6 @@
1
+ declare type EventHandler<T> = (data: T) => void;
2
+ interface EventDispatcher<T = void> {
3
+ dispatch(value: T): void;
4
+ subscribe(handler: EventHandler<T>): void;
5
+ unsubscribe(handler: EventHandler<T>): void;
6
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,10 @@
1
+ export declare class HTMLElementEventDispatcher<T = void> implements EventDispatcher<T> {
2
+ private readonly element;
3
+ private readonly type;
4
+ private readonly options?;
5
+ private readonly handlersMap;
6
+ constructor(element: HTMLElement, type: string, options?: EventInit | undefined);
7
+ dispatch(value: T): void;
8
+ subscribe(handler: EventHandler<T>): void;
9
+ unsubscribe(handler: EventHandler<T>): void;
10
+ }
@@ -0,0 +1,23 @@
1
+ export class HTMLElementEventDispatcher {
2
+ constructor(element, type, options) {
3
+ this.element = element;
4
+ this.type = type;
5
+ this.options = options;
6
+ this.handlersMap = new Map();
7
+ }
8
+ dispatch(value) {
9
+ this.element.dispatchEvent(new CustomEvent(this.type, { detail: value, ...this.options }));
10
+ }
11
+ subscribe(handler) {
12
+ const nativeHandler = (event) => handler(event.detail);
13
+ this.element.addEventListener(this.type, nativeHandler);
14
+ this.handlersMap.set(handler, nativeHandler);
15
+ }
16
+ unsubscribe(handler) {
17
+ const nativeHandler = this.handlersMap.get(handler);
18
+ if (nativeHandler) {
19
+ this.element.removeEventListener(this.type, nativeHandler);
20
+ }
21
+ this.handlersMap.delete(handler);
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ export declare class PureEventDispatcher<T = void> implements EventDispatcher<T> {
2
+ private readonly handlers;
3
+ subscribe(handler: EventHandler<T>): void;
4
+ unsubscribe(handler: EventHandler<T>): void;
5
+ dispatch(data: T): void;
6
+ }
@@ -0,0 +1,16 @@
1
+ export class PureEventDispatcher {
2
+ constructor() {
3
+ this.handlers = new Set();
4
+ }
5
+ subscribe(handler) {
6
+ this.handlers.add(handler);
7
+ }
8
+ unsubscribe(handler) {
9
+ this.handlers.delete(handler);
10
+ }
11
+ dispatch(data) {
12
+ for (const handler of this.handlers) {
13
+ handler(data);
14
+ }
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export declare function event(options?: EventInit): (prototype: unknown, propertyKey?: string) => void;
@@ -0,0 +1,20 @@
1
+ import { HTMLElementEventDispatcher } from './HTMLElementEventDispatcher';
2
+ import { PureEventDispatcher } from './PureEventDispatcher';
3
+ export function event(options) {
4
+ return (prototype, propertyKey) => {
5
+ if (propertyKey === undefined) {
6
+ return;
7
+ }
8
+ const eventFieldName = `$${propertyKey}Event$`;
9
+ Object.defineProperty(prototype, propertyKey, {
10
+ get() {
11
+ if (!this[eventFieldName]) {
12
+ this[eventFieldName] = this instanceof HTMLElement
13
+ ? new HTMLElementEventDispatcher(this, propertyKey, options)
14
+ : new PureEventDispatcher();
15
+ }
16
+ return this[eventFieldName];
17
+ }
18
+ });
19
+ };
20
+ }
@@ -0,0 +1,3 @@
1
+ export * from './PureEventDispatcher';
2
+ export * from './HTMLElementEventDispatcher';
3
+ export * from './event';
@@ -0,0 +1,3 @@
1
+ export * from './PureEventDispatcher';
2
+ export * from './HTMLElementEventDispatcher';
3
+ export * from './event';
@@ -0,0 +1,13 @@
1
+ import { LitElement } from 'lit';
2
+ declare type ShorthandEventListenerDecoratorOptions = [type: string, options?: EventListenerOptions | boolean];
3
+ declare type FullEventListenerDecoratorOptions = [
4
+ {
5
+ type: string;
6
+ target?: EventTarget | ((this: any) => EventTarget);
7
+ options?: EventListenerOptions | boolean;
8
+ }
9
+ ];
10
+ declare type EventListenerDecoratorOptions = ShorthandEventListenerDecoratorOptions | FullEventListenerDecoratorOptions;
11
+ export declare const eventListener: (...eventListenerOptions: EventListenerDecoratorOptions) => (prototype: LitElement, propertyKey: string, descriptor?: PropertyDescriptor) => void;
12
+ export declare const extractEventHandler: <TEvent extends Event = Event>(eventListener: EventListenerOrEventListenerObject) => (event: TEvent) => void;
13
+ export {};