@a11d/lit 0.2.7 → 0.2.9

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/Component/Component.d.ts +22 -22
  3. package/dist/Component/Component.js +35 -35
  4. package/dist/Component/index.d.ts +2 -2
  5. package/dist/Component/index.js +2 -2
  6. package/dist/Component/nothing.d.ts +2 -2
  7. package/dist/Component/nothing.js +2 -2
  8. package/dist/Controller/Controller.d.ts +9 -9
  9. package/dist/Controller/Controller.js +6 -6
  10. package/dist/Controller/index.d.ts +1 -1
  11. package/dist/Controller/index.js +1 -1
  12. package/dist/event/EventDispatcher.d.ts +9 -9
  13. package/dist/event/EventDispatcher.js +1 -1
  14. package/dist/event/HTMLElementEventDispatcher.d.ts +12 -12
  15. package/dist/event/HTMLElementEventDispatcher.js +27 -27
  16. package/dist/event/PureEventDispatcher.d.ts +6 -6
  17. package/dist/event/PureEventDispatcher.js +16 -16
  18. package/dist/event/event.d.ts +1 -1
  19. package/dist/event/event.js +20 -20
  20. package/dist/event/index.d.ts +4 -4
  21. package/dist/event/index.js +4 -4
  22. package/dist/eventListener/EventListenerController.d.ts +23 -23
  23. package/dist/eventListener/EventListenerController.js +57 -57
  24. package/dist/eventListener/EventListenerTarget.d.ts +3 -3
  25. package/dist/eventListener/EventListenerTarget.js +1 -1
  26. package/dist/eventListener/eventListener.d.ts +12 -12
  27. package/dist/eventListener/eventListener.js +31 -31
  28. package/dist/eventListener/extractEventHandler.d.ts +1 -1
  29. package/dist/eventListener/extractEventHandler.js +9 -9
  30. package/dist/eventListener/index.d.ts +4 -4
  31. package/dist/eventListener/index.js +4 -4
  32. package/dist/index.d.ts +35 -35
  33. package/dist/index.js +35 -35
  34. package/dist/query/index.d.ts +3 -3
  35. package/dist/query/index.js +3 -3
  36. package/dist/query/query.d.ts +2 -2
  37. package/dist/query/query.js +9 -9
  38. package/dist/query/queryAll.d.ts +2 -2
  39. package/dist/query/queryAll.js +9 -9
  40. package/dist/query/queryAllAsNodeList.d.ts +2 -2
  41. package/dist/query/queryAllAsNodeList.js +2 -2
  42. package/dist/style/CustomPropertyStyleHandler.d.ts +5 -5
  43. package/dist/style/CustomPropertyStyleHandler.js +14 -14
  44. package/dist/style/index.d.ts +2 -2
  45. package/dist/style/index.js +2 -2
  46. package/dist/style/style.d.ts +16 -16
  47. package/dist/style/style.js +33 -32
  48. package/dist/test/ComponentTestFixture.d.ts +10 -10
  49. package/dist/test/ComponentTestFixture.js +28 -28
  50. package/dist/test/index.d.ts +1 -1
  51. package/dist/test/index.js +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/dist/types.d.ts +5 -5
  54. package/dist/types.js +1 -1
  55. package/dist/updated/index.d.ts +3 -3
  56. package/dist/updated/index.js +3 -3
  57. package/dist/updated/property.d.ts +5 -5
  58. package/dist/updated/property.js +10 -10
  59. package/dist/updated/state.d.ts +6 -6
  60. package/dist/updated/state.js +10 -10
  61. package/dist/updated/updated.d.ts +3 -3
  62. package/dist/updated/updated.js +25 -25
  63. package/package.json +1 -1
@@ -1,31 +1,31 @@
1
- import { EventListenerController } from './EventListenerController.js';
2
- export function extractOptions(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
- export const eventListener = (...eventListenerOptions) => {
11
- return (prototype, propertyKey, descriptor) => {
12
- const Constructor = prototype.constructor;
13
- Constructor.addInitializer(element => {
14
- element.addController(new class extends EventListenerController {
15
- constructor() {
16
- const { type, target, options } = extractOptions(eventListenerOptions);
17
- super(element, { type, target, options, listener: undefined });
18
- }
19
- hostConnected() {
20
- const unboundListener = !descriptor
21
- ? Object.getOwnPropertyDescriptor(element, propertyKey)?.value
22
- : typeof descriptor.get === 'function'
23
- ? descriptor.get
24
- : descriptor.value;
25
- this.options.listener = unboundListener.bind(element);
26
- return super.hostConnected();
27
- }
28
- });
29
- });
30
- };
31
- };
1
+ import { EventListenerController } from './EventListenerController.js';
2
+ export function extractOptions(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
+ export const eventListener = (...eventListenerOptions) => {
11
+ return (prototype, propertyKey, descriptor) => {
12
+ const Constructor = prototype.constructor;
13
+ Constructor.addInitializer(element => {
14
+ element.addController(new class extends EventListenerController {
15
+ constructor() {
16
+ const { type, target, options } = extractOptions(eventListenerOptions);
17
+ super(element, { type, target, options, listener: undefined });
18
+ }
19
+ hostConnected() {
20
+ const unboundListener = !descriptor
21
+ ? Object.getOwnPropertyDescriptor(element, propertyKey)?.value
22
+ : typeof descriptor.get === 'function'
23
+ ? descriptor.get
24
+ : descriptor.value;
25
+ this.options.listener = unboundListener.bind(element);
26
+ return super.hostConnected();
27
+ }
28
+ });
29
+ });
30
+ };
31
+ };
@@ -1 +1 @@
1
- export declare const extractEventHandler: <TEvent extends Event = Event>(eventListener: EventListenerOrEventListenerObject) => (event: TEvent) => void;
1
+ export declare const extractEventHandler: <TEvent extends Event = Event>(eventListener: EventListenerOrEventListenerObject) => (event: TEvent) => void;
@@ -1,9 +1,9 @@
1
- export const extractEventHandler = (eventListener) => {
2
- return eventListener.type === 5
3
- // @ts-expect-error - _$committedValue does actually exist on EventPart
4
- // eslint-disable-next-line no-restricted-syntax
5
- ? eventListener._$committedValue.bind(eventListener.element)
6
- : typeof eventListener === 'function'
7
- ? eventListener
8
- : eventListener.handleEvent;
9
- };
1
+ export const extractEventHandler = (eventListener) => {
2
+ return eventListener.type === 5
3
+ // @ts-expect-error - _$committedValue does actually exist on EventPart
4
+ // eslint-disable-next-line no-restricted-syntax
5
+ ? eventListener._$committedValue.bind(eventListener.element)
6
+ : typeof eventListener === 'function'
7
+ ? eventListener
8
+ : eventListener.handleEvent;
9
+ };
@@ -1,4 +1,4 @@
1
- export * from './EventListenerTarget.js';
2
- export * from './eventListener.js';
3
- export * from './extractEventHandler.js';
4
- export * from './EventListenerController.js';
1
+ export * from './EventListenerTarget.js';
2
+ export * from './eventListener.js';
3
+ export * from './extractEventHandler.js';
4
+ export * from './EventListenerController.js';
@@ -1,4 +1,4 @@
1
- export * from './EventListenerTarget.js';
2
- export * from './eventListener.js';
3
- export * from './extractEventHandler.js';
4
- export * from './EventListenerController.js';
1
+ export * from './EventListenerTarget.js';
2
+ export * from './eventListener.js';
3
+ export * from './extractEventHandler.js';
4
+ export * from './EventListenerController.js';
package/dist/index.d.ts CHANGED
@@ -1,35 +1,35 @@
1
- export * from 'lit';
2
- export { InternalPropertyDeclaration, QueryAssignedElementsOptions, QueryAssignedNodesOptions, eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
3
- export { withStatic, literal, unsafeStatic, html as staticHtml, svg as staticSvg } from 'lit/static-html.js';
4
- export * from 'lit-html';
5
- export * from 'lit-html/directive-helpers.js';
6
- export * from 'lit-html/directive.js';
7
- export * from 'lit-html/async-directive.js';
8
- export * from 'lit-html/directives/async-append.js';
9
- export * from 'lit-html/directives/async-replace.js';
10
- export * from 'lit-html/directives/cache.js';
11
- export * from 'lit-html/directives/choose.js';
12
- export * from 'lit-html/directives/class-map.js';
13
- export * from 'lit-html/directives/guard.js';
14
- export * from 'lit-html/directives/if-defined.js';
15
- export * from 'lit-html/directives/join.js';
16
- export * from 'lit-html/directives/keyed.js';
17
- export * from 'lit-html/directives/live.js';
18
- export * from 'lit-html/directives/map.js';
19
- export * from 'lit-html/directives/range.js';
20
- export * from 'lit-html/directives/ref.js';
21
- export * from 'lit-html/directives/repeat.js';
22
- export * from 'lit-html/directives/style-map.js';
23
- export * from 'lit-html/directives/template-content.js';
24
- export * from 'lit-html/directives/unsafe-html.js';
25
- export * from 'lit-html/directives/unsafe-svg.js';
26
- export * from 'lit-html/directives/until.js';
27
- export * from 'lit-html/directives/when.js';
28
- import './types.js';
29
- export { Component, nothing, component } from './Component/index.js';
30
- export * from './Controller/index.js';
31
- export * from './query/index.js';
32
- export * from './style/index.js';
33
- export * from './updated/index.js';
34
- export * from './eventListener/index.js';
35
- export * from './event/index.js';
1
+ export * from 'lit';
2
+ export { InternalPropertyDeclaration, QueryAssignedElementsOptions, QueryAssignedNodesOptions, eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
3
+ export { withStatic, literal, unsafeStatic, html as staticHtml, svg as staticSvg } from 'lit/static-html.js';
4
+ export * from 'lit-html';
5
+ export * from 'lit-html/directive-helpers.js';
6
+ export * from 'lit-html/directive.js';
7
+ export * from 'lit-html/async-directive.js';
8
+ export * from 'lit-html/directives/async-append.js';
9
+ export * from 'lit-html/directives/async-replace.js';
10
+ export * from 'lit-html/directives/cache.js';
11
+ export * from 'lit-html/directives/choose.js';
12
+ export * from 'lit-html/directives/class-map.js';
13
+ export * from 'lit-html/directives/guard.js';
14
+ export * from 'lit-html/directives/if-defined.js';
15
+ export * from 'lit-html/directives/join.js';
16
+ export * from 'lit-html/directives/keyed.js';
17
+ export * from 'lit-html/directives/live.js';
18
+ export * from 'lit-html/directives/map.js';
19
+ export * from 'lit-html/directives/range.js';
20
+ export * from 'lit-html/directives/ref.js';
21
+ export * from 'lit-html/directives/repeat.js';
22
+ export * from 'lit-html/directives/style-map.js';
23
+ export * from 'lit-html/directives/template-content.js';
24
+ export * from 'lit-html/directives/unsafe-html.js';
25
+ export * from 'lit-html/directives/unsafe-svg.js';
26
+ export * from 'lit-html/directives/until.js';
27
+ export * from 'lit-html/directives/when.js';
28
+ import './types.js';
29
+ export { Component, nothing, component } from './Component/index.js';
30
+ export * from './Controller/index.js';
31
+ export * from './query/index.js';
32
+ export * from './style/index.js';
33
+ export * from './updated/index.js';
34
+ export * from './eventListener/index.js';
35
+ export * from './event/index.js';
package/dist/index.js CHANGED
@@ -1,35 +1,35 @@
1
- export * from 'lit';
2
- export { eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
3
- export { withStatic, literal, unsafeStatic, html as staticHtml, svg as staticSvg } from 'lit/static-html.js';
4
- export * from 'lit-html';
5
- export * from 'lit-html/directive-helpers.js';
6
- export * from 'lit-html/directive.js';
7
- export * from 'lit-html/async-directive.js';
8
- export * from 'lit-html/directives/async-append.js';
9
- export * from 'lit-html/directives/async-replace.js';
10
- export * from 'lit-html/directives/cache.js';
11
- export * from 'lit-html/directives/choose.js';
12
- export * from 'lit-html/directives/class-map.js';
13
- export * from 'lit-html/directives/guard.js';
14
- export * from 'lit-html/directives/if-defined.js';
15
- export * from 'lit-html/directives/join.js';
16
- export * from 'lit-html/directives/keyed.js';
17
- export * from 'lit-html/directives/live.js';
18
- export * from 'lit-html/directives/map.js';
19
- export * from 'lit-html/directives/range.js';
20
- export * from 'lit-html/directives/ref.js';
21
- export * from 'lit-html/directives/repeat.js';
22
- export * from 'lit-html/directives/style-map.js';
23
- export * from 'lit-html/directives/template-content.js';
24
- export * from 'lit-html/directives/unsafe-html.js';
25
- export * from 'lit-html/directives/unsafe-svg.js';
26
- export * from 'lit-html/directives/until.js';
27
- export * from 'lit-html/directives/when.js';
28
- import './types.js';
29
- export { Component, nothing, component } from './Component/index.js';
30
- export * from './Controller/index.js';
31
- export * from './query/index.js';
32
- export * from './style/index.js';
33
- export * from './updated/index.js';
34
- export * from './eventListener/index.js';
35
- export * from './event/index.js';
1
+ export * from 'lit';
2
+ export { eventOptions, queryAssignedElements, queryAssignedNodes, queryAsync } from 'lit/decorators.js';
3
+ export { withStatic, literal, unsafeStatic, html as staticHtml, svg as staticSvg } from 'lit/static-html.js';
4
+ export * from 'lit-html';
5
+ export * from 'lit-html/directive-helpers.js';
6
+ export * from 'lit-html/directive.js';
7
+ export * from 'lit-html/async-directive.js';
8
+ export * from 'lit-html/directives/async-append.js';
9
+ export * from 'lit-html/directives/async-replace.js';
10
+ export * from 'lit-html/directives/cache.js';
11
+ export * from 'lit-html/directives/choose.js';
12
+ export * from 'lit-html/directives/class-map.js';
13
+ export * from 'lit-html/directives/guard.js';
14
+ export * from 'lit-html/directives/if-defined.js';
15
+ export * from 'lit-html/directives/join.js';
16
+ export * from 'lit-html/directives/keyed.js';
17
+ export * from 'lit-html/directives/live.js';
18
+ export * from 'lit-html/directives/map.js';
19
+ export * from 'lit-html/directives/range.js';
20
+ export * from 'lit-html/directives/ref.js';
21
+ export * from 'lit-html/directives/repeat.js';
22
+ export * from 'lit-html/directives/style-map.js';
23
+ export * from 'lit-html/directives/template-content.js';
24
+ export * from 'lit-html/directives/unsafe-html.js';
25
+ export * from 'lit-html/directives/unsafe-svg.js';
26
+ export * from 'lit-html/directives/until.js';
27
+ export * from 'lit-html/directives/when.js';
28
+ import './types.js';
29
+ export { Component, nothing, component } from './Component/index.js';
30
+ export * from './Controller/index.js';
31
+ export * from './query/index.js';
32
+ export * from './style/index.js';
33
+ export * from './updated/index.js';
34
+ export * from './eventListener/index.js';
35
+ export * from './event/index.js';
@@ -1,3 +1,3 @@
1
- export * from './query.js';
2
- export * from './queryAll.js';
3
- export * from './queryAllAsNodeList.js';
1
+ export * from './query.js';
2
+ export * from './queryAll.js';
3
+ export * from './queryAllAsNodeList.js';
@@ -1,3 +1,3 @@
1
- export * from './query.js';
2
- export * from './queryAll.js';
3
- export * from './queryAllAsNodeList.js';
1
+ export * from './query.js';
2
+ export * from './queryAll.js';
3
+ export * from './queryAllAsNodeList.js';
@@ -1,2 +1,2 @@
1
- import type { ReactiveElement } from 'lit';
2
- export declare const query: (selector: string) => (prototype: ReactiveElement, propertyKey: PropertyKey) => void;
1
+ import type { ReactiveElement } from 'lit';
2
+ export declare const query: (selector: string) => (prototype: ReactiveElement, propertyKey: PropertyKey) => void;
@@ -1,9 +1,9 @@
1
- export const query = (selector) => {
2
- return (prototype, propertyKey) => {
3
- Object.defineProperty(prototype, propertyKey, {
4
- get() {
5
- return this.renderRoot?.querySelector(selector) ?? undefined;
6
- }
7
- });
8
- };
9
- };
1
+ export const query = (selector) => {
2
+ return (prototype, propertyKey) => {
3
+ Object.defineProperty(prototype, propertyKey, {
4
+ get() {
5
+ return this.renderRoot?.querySelector(selector) ?? undefined;
6
+ }
7
+ });
8
+ };
9
+ };
@@ -1,2 +1,2 @@
1
- import type { ReactiveElement } from 'lit';
2
- export declare const queryAll: (selector: string) => (prototype: ReactiveElement, propertyKey: PropertyKey) => void;
1
+ import type { ReactiveElement } from 'lit';
2
+ export declare const queryAll: (selector: string) => (prototype: ReactiveElement, propertyKey: PropertyKey) => void;
@@ -1,9 +1,9 @@
1
- export const queryAll = (selector) => {
2
- return (prototype, propertyKey) => {
3
- Object.defineProperty(prototype, propertyKey, {
4
- get() {
5
- return [...this.renderRoot?.querySelectorAll(selector) ?? []];
6
- }
7
- });
8
- };
9
- };
1
+ export const queryAll = (selector) => {
2
+ return (prototype, propertyKey) => {
3
+ Object.defineProperty(prototype, propertyKey, {
4
+ get() {
5
+ return [...this.renderRoot?.querySelectorAll(selector) ?? []];
6
+ }
7
+ });
8
+ };
9
+ };
@@ -1,2 +1,2 @@
1
- import { queryAll as litQueryAll } from 'lit/decorators.js';
2
- export declare const queryAllAsNodeList: typeof litQueryAll;
1
+ import { queryAll as litQueryAll } from 'lit/decorators.js';
2
+ export declare const queryAllAsNodeList: typeof litQueryAll;
@@ -1,2 +1,2 @@
1
- import { queryAll as litQueryAll } from 'lit/decorators.js';
2
- export const queryAllAsNodeList = litQueryAll;
1
+ import { queryAll as litQueryAll } from 'lit/decorators.js';
2
+ export const queryAllAsNodeList = litQueryAll;
@@ -1,5 +1,5 @@
1
- import { StyleEntry, StyleHandler } from './style.js';
2
- export declare class CustomPropertyStyleHandler implements StyleHandler {
3
- handles(_: HTMLElement, [key]: StyleEntry): boolean;
4
- apply(element: HTMLElement, [key, value]: StyleEntry): void;
5
- }
1
+ import { StyleEntry, StyleHandler } from './style.js';
2
+ export declare class CustomPropertyStyleHandler implements StyleHandler {
3
+ handles(_: HTMLElement, [key]: StyleEntry): boolean;
4
+ apply(element: HTMLElement, [key, value]: StyleEntry): void;
5
+ }
@@ -1,14 +1,14 @@
1
- import { __decorate } from "tslib";
2
- import { styleHandler } from './style.js';
3
- let CustomPropertyStyleHandler = class CustomPropertyStyleHandler {
4
- handles(_, [key]) {
5
- return key.startsWith('--');
6
- }
7
- apply(element, [key, value]) {
8
- element.style.setProperty(key, value);
9
- }
10
- };
11
- CustomPropertyStyleHandler = __decorate([
12
- styleHandler()
13
- ], CustomPropertyStyleHandler);
14
- export { CustomPropertyStyleHandler };
1
+ import { __decorate } from "tslib";
2
+ import { styleHandler } from './style.js';
3
+ let CustomPropertyStyleHandler = class CustomPropertyStyleHandler {
4
+ handles(_, [key]) {
5
+ return key.startsWith('--');
6
+ }
7
+ apply(element, [key, value]) {
8
+ element.style.setProperty(key, value);
9
+ }
10
+ };
11
+ CustomPropertyStyleHandler = __decorate([
12
+ styleHandler()
13
+ ], CustomPropertyStyleHandler);
14
+ export { CustomPropertyStyleHandler };
@@ -1,2 +1,2 @@
1
- export * from './style.js';
2
- export * from './CustomPropertyStyleHandler.js';
1
+ export * from './style.js';
2
+ export * from './CustomPropertyStyleHandler.js';
@@ -1,2 +1,2 @@
1
- export * from './style.js';
2
- export * from './CustomPropertyStyleHandler.js';
1
+ export * from './style.js';
2
+ export * from './CustomPropertyStyleHandler.js';
@@ -1,16 +1,16 @@
1
- import { Directive, PartInfo } from '../index.js';
2
- import type { StandardProperties } from 'csstype';
3
- export type StyleEntry = [key: string, value: string];
4
- export interface StyleHandler {
5
- handles(element: HTMLElement, entry: StyleEntry): boolean;
6
- apply(element: HTMLElement, entry: StyleEntry): void;
7
- }
8
- export declare const styleHandler: () => (Constructor: Constructor<StyleHandler>) => void;
9
- export declare class StyleDirective extends Directive {
10
- static readonly handlers: Set<StyleHandler>;
11
- private static readonly defaultHandler;
12
- private readonly element;
13
- constructor(partInfo: PartInfo);
14
- render(styles: StandardProperties | (Record<string, string> & {})): void;
15
- }
16
- export declare const style: (styles: StandardProperties<0 | (string & {}), string & {}> | Record<string, string>) => import("lit-html/directive.js").DirectiveResult<typeof StyleDirective>;
1
+ import { Directive, PartInfo } from '../index.js';
2
+ import type { StandardProperties } from 'csstype';
3
+ export type StyleEntry = [key: string, value: string];
4
+ export interface StyleHandler {
5
+ handles(element: HTMLElement, entry: StyleEntry): boolean;
6
+ apply(element: HTMLElement, entry: StyleEntry): void;
7
+ }
8
+ export declare const styleHandler: () => (Constructor: Constructor<StyleHandler>) => void;
9
+ export declare class StyleDirective extends Directive {
10
+ static readonly handlers: Set<StyleHandler>;
11
+ private static readonly defaultHandler;
12
+ private readonly element;
13
+ constructor(partInfo: PartInfo);
14
+ render(styles: StandardProperties | (Record<string, string> & {})): void;
15
+ }
16
+ export declare const style: (styles: StandardProperties<0 | (string & {}), string & {}> | Record<string, string>) => import("lit-html/directive.js").DirectiveResult<typeof StyleDirective>;
@@ -1,32 +1,33 @@
1
- import { Directive, directive, PartType } from '../index.js';
2
- export const styleHandler = () => {
3
- return (Constructor) => {
4
- const handler = new Constructor();
5
- StyleDirective.handlers.add(handler);
6
- };
7
- };
8
- export class StyleDirective extends Directive {
9
- constructor(partInfo) {
10
- super(partInfo);
11
- if (partInfo.type !== PartType.ELEMENT) {
12
- throw new Error('style directive can only be used on an element');
13
- }
14
- const part = partInfo;
15
- this.element = part.element;
16
- }
17
- // eslint-disable-next-line @typescript-eslint/ban-types
18
- render(styles) {
19
- for (const [key, value] of Object.entries(styles)) {
20
- const handler = [...StyleDirective.handlers].find(handler => handler.handles(this.element, [key, value])) ?? StyleDirective.defaultHandler;
21
- handler.apply(this.element, [key, value]);
22
- }
23
- }
24
- }
25
- StyleDirective.handlers = new Set();
26
- StyleDirective.defaultHandler = new class {
27
- handles() { return true; }
28
- apply(element, [key, value]) {
29
- element.style[key] = value === null || value === undefined ? '' : value;
30
- }
31
- };
32
- export const style = directive(StyleDirective);
1
+ import { Directive, directive, PartType } from '../index.js';
2
+ export const styleHandler = () => {
3
+ return (Constructor) => {
4
+ const handler = new Constructor();
5
+ StyleDirective.handlers.add(handler);
6
+ };
7
+ };
8
+ class StyleDirective extends Directive {
9
+ constructor(partInfo) {
10
+ super(partInfo);
11
+ if (partInfo.type !== PartType.ELEMENT) {
12
+ throw new Error('style directive can only be used on an element');
13
+ }
14
+ const part = partInfo;
15
+ this.element = part.element;
16
+ }
17
+ // eslint-disable-next-line @typescript-eslint/ban-types
18
+ render(styles) {
19
+ for (const [key, value] of Object.entries(styles)) {
20
+ const handler = [...StyleDirective.handlers].find(handler => handler.handles(this.element, [key, value])) ?? StyleDirective.defaultHandler;
21
+ handler.apply(this.element, [key, value]);
22
+ }
23
+ }
24
+ }
25
+ StyleDirective.handlers = new Set();
26
+ StyleDirective.defaultHandler = new class {
27
+ handles() { return true; }
28
+ apply(element, [key, value]) {
29
+ element.style[key] = value === null || value === undefined ? '' : value;
30
+ }
31
+ };
32
+ export { StyleDirective };
33
+ export const style = directive(StyleDirective);
@@ -1,10 +1,10 @@
1
- export declare class ComponentTestFixture<TComponent extends import('lit').LitElement> {
2
- private readonly constructComponentOrTagName;
3
- private _component?;
4
- get component(): TComponent;
5
- constructor(constructComponentOrTagName: string | (() => TComponent));
6
- initialize(): Promise<TComponent>;
7
- get updateComplete(): Promise<boolean> | undefined;
8
- requestUpdate(): void;
9
- update(): Promise<void>;
10
- }
1
+ export declare class ComponentTestFixture<TComponent extends import('lit').LitElement> {
2
+ private readonly constructComponentOrTagName;
3
+ private _component?;
4
+ get component(): TComponent;
5
+ constructor(constructComponentOrTagName: string | (() => TComponent));
6
+ initialize(): Promise<TComponent>;
7
+ get updateComplete(): Promise<boolean> | undefined;
8
+ requestUpdate(): void;
9
+ update(): Promise<void>;
10
+ }
@@ -1,28 +1,28 @@
1
- export class ComponentTestFixture {
2
- get component() { return this._component; }
3
- constructor(constructComponentOrTagName) {
4
- this.constructComponentOrTagName = constructComponentOrTagName;
5
- beforeEach(() => this.initialize());
6
- afterEach(() => this._component?.remove());
7
- }
8
- async initialize() {
9
- this._component?.remove();
10
- const constructComponent = typeof this.constructComponentOrTagName === 'string'
11
- ? () => document.createElement(this.constructComponentOrTagName)
12
- : this.constructComponentOrTagName;
13
- this._component = constructComponent();
14
- document.body.appendChild(this._component);
15
- await this._component.updateComplete;
16
- return this._component;
17
- }
18
- get updateComplete() {
19
- return this._component?.updateComplete;
20
- }
21
- requestUpdate() {
22
- this._component?.requestUpdate();
23
- }
24
- async update() {
25
- this.requestUpdate();
26
- await this.updateComplete;
27
- }
28
- }
1
+ export class ComponentTestFixture {
2
+ get component() { return this._component; }
3
+ constructor(constructComponentOrTagName) {
4
+ this.constructComponentOrTagName = constructComponentOrTagName;
5
+ beforeEach(() => this.initialize());
6
+ afterEach(() => this._component?.remove());
7
+ }
8
+ async initialize() {
9
+ this._component?.remove();
10
+ const constructComponent = typeof this.constructComponentOrTagName === 'string'
11
+ ? () => document.createElement(this.constructComponentOrTagName)
12
+ : this.constructComponentOrTagName;
13
+ this._component = constructComponent();
14
+ document.body.appendChild(this._component);
15
+ await this._component.updateComplete;
16
+ return this._component;
17
+ }
18
+ get updateComplete() {
19
+ return this._component?.updateComplete;
20
+ }
21
+ requestUpdate() {
22
+ this._component?.requestUpdate();
23
+ }
24
+ async update() {
25
+ this.requestUpdate();
26
+ await this.updateComplete;
27
+ }
28
+ }
@@ -1 +1 @@
1
- export * from './ComponentTestFixture.js';
1
+ export * from './ComponentTestFixture.js';
@@ -1 +1 @@
1
- export * from './ComponentTestFixture.js';
1
+ export * from './ComponentTestFixture.js';