element-vir 5.1.0 → 5.4.0

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 (65) hide show
  1. package/dist/cjs/augments/array.d.ts +1 -0
  2. package/dist/cjs/augments/type.d.ts +1 -0
  3. package/dist/cjs/functional-element/define-functional-element.d.ts +4 -0
  4. package/dist/cjs/functional-element/define-functional-element.js +31 -29
  5. package/dist/cjs/functional-element/directives/assign-with-clean-up.directive.d.ts +19 -0
  6. package/dist/cjs/functional-element/directives/assign-with-clean-up.directive.js +0 -3
  7. package/dist/cjs/functional-element/directives/assign.directive.d.ts +15 -0
  8. package/dist/cjs/functional-element/directives/assign.directive.js +0 -1
  9. package/dist/cjs/functional-element/directives/directive-util.d.ts +15 -0
  10. package/dist/cjs/functional-element/directives/listen.directive.d.ts +13 -0
  11. package/dist/cjs/functional-element/directives/listen.directive.js +1 -3
  12. package/dist/cjs/functional-element/directives/on-dom-created.directive.d.ts +11 -0
  13. package/dist/cjs/functional-element/directives/on-dom-created.directive.js +0 -1
  14. package/dist/cjs/functional-element/directives/on-resize.directive.d.ts +15 -0
  15. package/dist/cjs/functional-element/directives/on-resize.directive.js +3 -4
  16. package/dist/cjs/functional-element/element-events.d.ts +10 -0
  17. package/dist/cjs/functional-element/element-properties.d.ts +16 -0
  18. package/dist/cjs/functional-element/functional-element.d.ts +42 -0
  19. package/dist/cjs/functional-element/functional-element.js +0 -2
  20. package/dist/cjs/functional-element/render-callback.d.ts +21 -0
  21. package/dist/cjs/index.d.ts +15 -0
  22. package/dist/cjs/require-functional-element.d.ts +2 -0
  23. package/dist/cjs/template-transforms/has-static-tag-name.d.ts +4 -0
  24. package/dist/cjs/template-transforms/transform-template.d.ts +16 -0
  25. package/dist/cjs/template-transforms/transform-template.js +4 -3
  26. package/dist/cjs/template-transforms/vir-css/css-transform.d.ts +7 -0
  27. package/dist/cjs/template-transforms/vir-css/vir-css.d.ts +3 -0
  28. package/dist/cjs/template-transforms/vir-html/html-transform.d.ts +3 -0
  29. package/dist/cjs/template-transforms/vir-html/html-transform.js +1 -1
  30. package/dist/cjs/template-transforms/vir-html/vir-html.d.ts +3 -0
  31. package/dist/cjs/typed-event/typed-event.d.ts +19 -0
  32. package/dist/cjs/typed-event/typed-event.js +13 -11
  33. package/dist/esm/augments/array.d.ts +1 -0
  34. package/dist/esm/augments/type.d.ts +1 -0
  35. package/dist/esm/functional-element/define-functional-element.d.ts +4 -0
  36. package/dist/esm/functional-element/define-functional-element.js +31 -29
  37. package/dist/esm/functional-element/directives/assign-with-clean-up.directive.d.ts +19 -0
  38. package/dist/esm/functional-element/directives/assign-with-clean-up.directive.js +0 -3
  39. package/dist/esm/functional-element/directives/assign.directive.d.ts +15 -0
  40. package/dist/esm/functional-element/directives/assign.directive.js +0 -1
  41. package/dist/esm/functional-element/directives/directive-util.d.ts +15 -0
  42. package/dist/esm/functional-element/directives/listen.directive.d.ts +13 -0
  43. package/dist/esm/functional-element/directives/listen.directive.js +1 -3
  44. package/dist/esm/functional-element/directives/on-dom-created.directive.d.ts +11 -0
  45. package/dist/esm/functional-element/directives/on-dom-created.directive.js +0 -1
  46. package/dist/esm/functional-element/directives/on-resize.directive.d.ts +15 -0
  47. package/dist/esm/functional-element/directives/on-resize.directive.js +3 -4
  48. package/dist/esm/functional-element/element-events.d.ts +10 -0
  49. package/dist/esm/functional-element/element-properties.d.ts +16 -0
  50. package/dist/esm/functional-element/functional-element.d.ts +42 -0
  51. package/dist/esm/functional-element/functional-element.js +0 -2
  52. package/dist/esm/functional-element/render-callback.d.ts +21 -0
  53. package/dist/esm/index.d.ts +15 -0
  54. package/dist/esm/require-functional-element.d.ts +2 -0
  55. package/dist/esm/template-transforms/has-static-tag-name.d.ts +4 -0
  56. package/dist/esm/template-transforms/transform-template.d.ts +16 -0
  57. package/dist/esm/template-transforms/transform-template.js +4 -3
  58. package/dist/esm/template-transforms/vir-css/css-transform.d.ts +7 -0
  59. package/dist/esm/template-transforms/vir-css/vir-css.d.ts +3 -0
  60. package/dist/esm/template-transforms/vir-html/html-transform.d.ts +3 -0
  61. package/dist/esm/template-transforms/vir-html/html-transform.js +1 -1
  62. package/dist/esm/template-transforms/vir-html/vir-html.d.ts +3 -0
  63. package/dist/esm/typed-event/typed-event.d.ts +19 -0
  64. package/dist/esm/typed-event/typed-event.js +13 -11
  65. package/package.json +4 -4
@@ -0,0 +1 @@
1
+ export declare function filterOutArrayIndexes<T>(array: Readonly<T[]>, indexes: Readonly<number[]>): T[];
@@ -0,0 +1 @@
1
+ export declare type NonEmptyString<T> = T extends '' ? never : T;
@@ -0,0 +1,4 @@
1
+ import { EventsInitMap } from './element-events';
2
+ import { PropertyInitMapBase } from './element-properties';
3
+ import { FunctionalElement, FunctionalElementInit } from './functional-element';
4
+ export declare function defineFunctionalElement<EventsInitGeneric extends EventsInitMap = {}, PropertyInitGeneric extends PropertyInitMapBase = {}>(functionalElementInit: FunctionalElementInit<PropertyInitGeneric, EventsInitGeneric>): FunctionalElement<PropertyInitGeneric, EventsInitGeneric>;
@@ -8,37 +8,39 @@ const element_properties_1 = require("./element-properties");
8
8
  const functional_element_1 = require("./functional-element");
9
9
  const render_callback_1 = require("./render-callback");
10
10
  function defineFunctionalElement(functionalElementInit) {
11
+ var _a;
11
12
  const eventsMap = (0, element_events_1.createEventDescriptorMap)(functionalElementInit.events);
12
- const anonymousClass = class extends functional_element_1.FunctionalElementBaseClass {
13
- static tagName = functionalElementInit.tagName;
14
- static styles = functionalElementInit.styles || (0, lit_1.css) ``;
15
- createRenderParams() {
16
- return (0, render_callback_1.createRenderParams)(this, eventsMap);
17
- }
18
- static initInput = functionalElementInit;
19
- static events = eventsMap;
20
- static renderCallback = functionalElementInit.renderCallback;
21
- static props = (0, element_properties_1.createPropertyDescriptorMap)(functionalElementInit.props);
22
- initCalled = false;
23
- render() {
24
- const renderParams = this.createRenderParams();
25
- if (!this.initCalled && functionalElementInit.initCallback) {
26
- this.initCalled = true;
27
- functionalElementInit.initCallback(renderParams);
13
+ const anonymousClass = (_a = class extends functional_element_1.FunctionalElementBaseClass {
14
+ constructor() {
15
+ super();
16
+ this.initCalled = false;
17
+ this.instanceProps = (0, element_properties_1.createPropertyProxy)(functionalElementInit.props, this);
18
+ const initProps = functionalElementInit.props || {};
19
+ Object.keys(initProps).forEach((propName) => {
20
+ const functionalElementInstance = this;
21
+ (0, decorators_js_1.property)()(functionalElementInstance, propName);
22
+ functionalElementInstance[propName] = initProps[propName];
23
+ });
28
24
  }
29
- return functionalElementInit.renderCallback(renderParams);
30
- }
31
- instanceProps = (0, element_properties_1.createPropertyProxy)(functionalElementInit.props, this);
32
- constructor() {
33
- super();
34
- const initProps = functionalElementInit.props || {};
35
- Object.keys(initProps).forEach((propName) => {
36
- const functionalElementInstance = this;
37
- (0, decorators_js_1.property)()(functionalElementInstance, propName);
38
- functionalElementInstance[propName] = initProps[propName];
39
- });
40
- }
41
- };
25
+ createRenderParams() {
26
+ return (0, render_callback_1.createRenderParams)(this, eventsMap);
27
+ }
28
+ render() {
29
+ const renderParams = this.createRenderParams();
30
+ if (!this.initCalled && functionalElementInit.initCallback) {
31
+ this.initCalled = true;
32
+ functionalElementInit.initCallback(renderParams);
33
+ }
34
+ return functionalElementInit.renderCallback(renderParams);
35
+ }
36
+ },
37
+ _a.tagName = functionalElementInit.tagName,
38
+ _a.styles = functionalElementInit.styles || (0, lit_1.css) ``,
39
+ _a.initInput = functionalElementInit,
40
+ _a.events = eventsMap,
41
+ _a.renderCallback = functionalElementInit.renderCallback,
42
+ _a.props = (0, element_properties_1.createPropertyDescriptorMap)(functionalElementInit.props),
43
+ _a);
42
44
  window.customElements.define(functionalElementInit.tagName, anonymousClass);
43
45
  return anonymousClass;
44
46
  }
@@ -0,0 +1,19 @@
1
+ import { AsyncDirective } from 'lit/async-directive.js';
2
+ import { PartInfo } from 'lit/directive.js';
3
+ import { StaticElementPropertyDescriptor } from '../element-properties';
4
+ /**
5
+ * The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
6
+ * the directive call is wrapped in this function.
7
+ */
8
+ export declare function assignWithCleanup<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue'], cleanupCallback: CleanupCallback<typeof propertyDescriptor['initValue']>): import("lit-html/directive").DirectiveResult<typeof AssignWithCleanupDirectiveClass>;
9
+ export declare type CleanupCallback<T> = (oldValue: T) => void;
10
+ export declare type EqualityCheckCallback<T> = (oldValue: T, newValue: T) => boolean;
11
+ declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
12
+ private readonly element;
13
+ private lastValue;
14
+ private lastCallback;
15
+ constructor(partInfo: PartInfo);
16
+ disconnected(): void;
17
+ render(propName: string, value: unknown, cleanupCallback: CleanupCallback<any>, equalityCheck?: EqualityCheckCallback<any>): symbol;
18
+ }
19
+ export {};
@@ -14,9 +14,6 @@ function assignWithCleanup(propertyDescriptor, value, cleanupCallback) {
14
14
  }
15
15
  exports.assignWithCleanup = assignWithCleanup;
16
16
  class AssignWithCleanupDirectiveClass extends async_directive_js_1.AsyncDirective {
17
- element;
18
- lastValue;
19
- lastCallback;
20
17
  constructor(partInfo) {
21
18
  super(partInfo);
22
19
  this.element = (0, directive_util_1.extractFunctionalElement)(partInfo, 'assign');
@@ -0,0 +1,15 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ import { PropertyInitMapBase, StaticElementPropertyDescriptor } from '../element-properties';
3
+ import { FunctionalElementInstance } from '../functional-element';
4
+ /**
5
+ * The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
6
+ * the directive call is wrapped in this function.
7
+ */
8
+ export declare function assign<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue']): import("lit-html/directive").DirectiveResult<{
9
+ new (partInfo: PartInfo): {
10
+ readonly element: FunctionalElementInstance<PropertyInitMapBase>;
11
+ render(propName: string, value: unknown): symbol;
12
+ readonly _$isConnected: boolean;
13
+ update(_part: import("lit-html").Part, props: unknown[]): unknown;
14
+ };
15
+ }>;
@@ -13,7 +13,6 @@ function assign(propertyDescriptor, value) {
13
13
  }
14
14
  exports.assign = assign;
15
15
  const assignDirective = (0, directive_js_1.directive)(class extends directive_js_1.Directive {
16
- element;
17
16
  constructor(partInfo) {
18
17
  super(partInfo);
19
18
  this.element = (0, directive_util_1.extractFunctionalElement)(partInfo, 'assign');
@@ -0,0 +1,15 @@
1
+ import { ElementPartInfo, PartInfo } from 'lit/directive.js';
2
+ import { PropertyInitMapBase } from '../element-properties';
3
+ import { FunctionalElementInstance } from '../functional-element';
4
+ /** For some reason these aren't defined in lit's types already. */
5
+ export declare type ExtraPartInfoProperties = {
6
+ element: Element;
7
+ options: {
8
+ host: Element;
9
+ renderBefore: Element;
10
+ isConnected: boolean;
11
+ };
12
+ };
13
+ export declare function extractFunctionalElement<PropertyInitGeneric extends PropertyInitMapBase>(partInfo: PartInfo, directiveName: string): FunctionalElementInstance<PropertyInitGeneric>;
14
+ export declare function extractElement<ElementType = HTMLElement>(partInfo: PartInfo, directiveName: string, constructorClass: (new () => ElementType) | (abstract new () => ElementType)): ElementType;
15
+ export declare function assertsIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
@@ -0,0 +1,13 @@
1
+ import { DirectiveResult } from 'lit/directive.js';
2
+ import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
3
+ /**
4
+ * Listen to events. These can be native DOM events (use a string for the inputType argument) or
5
+ * typed events (pass in a return value from defineTypedEvent).
6
+ *
7
+ * @param definedTypedEvent Needs to come either from a functional element (like
8
+ * MyFunctionalElement.events.eventName) or from a typed event created via the defineTypedEvent function.
9
+ * @param listener The callback to fire when an event is caught. Assuming the definedTypedEvent
10
+ * input is properly typed, the event given to this callback will also be typed.
11
+ */
12
+ export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: DefinedTypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>, listener: (event: TypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>) => void): DirectiveResult<any>;
13
+ export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: NativeElementEventNameGeneric, listener: (event: HTMLElementEventMap[NativeElementEventNameGeneric]) => void): DirectiveResult<any>;
@@ -13,8 +13,6 @@ exports.listen = listen;
13
13
  * call is wrapped in the function above.
14
14
  */
15
15
  const listenDirective = (0, directive_js_1.directive)(class extends directive_js_1.Directive {
16
- element;
17
- lastListenerMetaData;
18
16
  constructor(partInfo) {
19
17
  super(partInfo);
20
18
  this.element = (0, directive_util_1.extractElement)(partInfo, 'listen', HTMLElement);
@@ -30,7 +28,7 @@ const listenDirective = (0, directive_js_1.directive)(class extends directive_js
30
28
  return {
31
29
  eventType,
32
30
  callback,
33
- listener: (event) => this.lastListenerMetaData?.callback(event),
31
+ listener: (event) => { var _a; return (_a = this.lastListenerMetaData) === null || _a === void 0 ? void 0 : _a.callback(event); },
34
32
  };
35
33
  }
36
34
  render(eventTypeInput, callback) {
@@ -0,0 +1,11 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ export declare type OnDomCreatedCallback = (element: Element) => void;
3
+ /** Only fires once, when the element has been created. */
4
+ export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("lit-html/directive").DirectiveResult<{
5
+ new (partInfo: PartInfo): {
6
+ element: Element | undefined;
7
+ update(partInfo: PartInfo, [callback]: [OnDomCreatedCallback]): undefined;
8
+ render(callback: OnDomCreatedCallback): undefined;
9
+ readonly _$isConnected: boolean;
10
+ };
11
+ }>;
@@ -6,7 +6,6 @@ const directive_util_1 = require("./directive-util");
6
6
  const directiveName = 'onDomCreated';
7
7
  /** Only fires once, when the element has been created. */
8
8
  exports.onDomCreated = (0, directive_js_1.directive)(class extends directive_js_1.Directive {
9
- element;
10
9
  constructor(partInfo) {
11
10
  super(partInfo);
12
11
  (0, directive_util_1.assertsIsElementPartInfo)(partInfo, directiveName);
@@ -0,0 +1,15 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ export declare type OnResizeCallback = (
3
+ /** Only these two properties are supported in all major modern browsers */
4
+ entry: Readonly<Pick<ResizeObserverEntry, 'target' | 'contentRect'>>) => void;
5
+ export declare const onResize: (callback: OnResizeCallback) => import("lit-html/directive").DirectiveResult<{
6
+ new (partInfo: PartInfo): {
7
+ element: Element | undefined;
8
+ readonly resizeObserver: ResizeObserver;
9
+ callback: OnResizeCallback | undefined;
10
+ fireCallback(entries: ResizeObserverEntry[]): void;
11
+ update(partInfo: PartInfo, [callback]: [OnResizeCallback]): undefined;
12
+ render(callback: OnResizeCallback): undefined;
13
+ readonly _$isConnected: boolean;
14
+ };
15
+ }>;
@@ -5,20 +5,19 @@ const directive_js_1 = require("lit/directive.js");
5
5
  const directive_util_1 = require("./directive-util");
6
6
  const directiveName = 'onResize';
7
7
  exports.onResize = (0, directive_js_1.directive)(class extends directive_js_1.Directive {
8
- element;
9
- resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
10
- callback;
11
8
  constructor(partInfo) {
12
9
  super(partInfo);
10
+ this.resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
13
11
  (0, directive_util_1.assertsIsElementPartInfo)(partInfo, directiveName);
14
12
  }
15
13
  fireCallback(entries) {
14
+ var _a;
16
15
  const resizeEntry = entries[0];
17
16
  if (!resizeEntry) {
18
17
  console.error(entries);
19
18
  throw new Error(`${directiveName} observation triggered but the first entry was empty.`);
20
19
  }
21
- this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect });
20
+ (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, { target: resizeEntry.target, contentRect: resizeEntry.contentRect });
22
21
  }
23
22
  update(partInfo, [callback]) {
24
23
  (0, directive_util_1.assertsIsElementPartInfo)(partInfo, directiveName);
@@ -0,0 +1,10 @@
1
+ import { DefinedTypedEvent, DefinedTypedEventNameDefinition, TypedEvent } from '../typed-event/typed-event';
2
+ export declare type EventsInitMap = Record<string, DefinedTypedEventNameDefinition<any>>;
3
+ export declare function defineElementEvent<EventDetailGeneric>(): DefinedTypedEventNameDefinition<EventDetailGeneric>;
4
+ export declare type EventInitMapEventDetailExtractor<EventTypeNameGeneric extends keyof EventsInitGeneric, EventsInitGeneric extends EventsInitMap> = EventsInitGeneric[EventTypeNameGeneric] extends DefinedTypedEventNameDefinition<infer R> ? R : never;
5
+ export declare type EventDescriptorMap<EventsInitGeneric extends EventsInitMap> = {
6
+ [CurrentEventTypeName in keyof EventsInitGeneric]: DefinedTypedEvent<CurrentEventTypeName extends string ? CurrentEventTypeName : never, EventInitMapEventDetailExtractor<CurrentEventTypeName, EventsInitGeneric>>;
7
+ };
8
+ export declare type EventObjectEventDetailExtractor<EventObjectGeneric extends DefinedTypedEvent<any, any>> = EventObjectGeneric extends DefinedTypedEvent<string, infer R> ? R : never;
9
+ export declare type ElementEventDetailExtractor<ElementEventGeneric extends TypedEvent<any, any>> = ElementEventGeneric extends TypedEvent<string, infer R> ? R : never;
10
+ export declare function createEventDescriptorMap<EventsInitGeneric extends EventsInitMap>(eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<EventsInitGeneric>;
@@ -0,0 +1,16 @@
1
+ import { FunctionalElementInstance } from './functional-element';
2
+ export declare type PropertyInitMapBase = Record<string, unknown>;
3
+ export declare type ElementProperty<KeyGeneric extends string | number | symbol, ValueGeneric> = {
4
+ name: KeyGeneric;
5
+ setProp(value: ValueGeneric): void;
6
+ getProp(): ValueGeneric;
7
+ };
8
+ export declare type StaticElementPropertyDescriptor<PropName extends string, PropValue> = {
9
+ propName: PropName;
10
+ initValue: PropValue;
11
+ };
12
+ export declare type ElementPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase> = {
13
+ [Property in keyof PropertyInitGeneric]: StaticElementPropertyDescriptor<string, PropertyInitGeneric[Property]>;
14
+ };
15
+ export declare function createPropertyProxy<PropertyInitGeneric extends PropertyInitMapBase>(propsInitMap: PropertyInitGeneric | undefined, element: FunctionalElementInstance<PropertyInitGeneric>): PropertyInitGeneric;
16
+ export declare function createPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase>(propertyInit: PropertyInitGeneric | undefined): ElementPropertyDescriptorMap<PropertyInitGeneric>;
@@ -0,0 +1,42 @@
1
+ import { CSSResult, LitElement, TemplateResult } from 'lit';
2
+ import { EventDescriptorMap, EventsInitMap } from './element-events';
3
+ import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './element-properties';
4
+ import { InitCallback, RenderCallback } from './render-callback';
5
+ export declare type CustomElementTagName = `${string}-${string}`;
6
+ export declare type FunctionalElementInit<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
7
+ /**
8
+ * HTML tag name. This should not be used directly, as interpolating it with the html tagged
9
+ * template from this package is preferred.
10
+ */
11
+ tagName: CustomElementTagName;
12
+ /** Static styles. These should not and cannot change. */
13
+ styles?: CSSResult | undefined;
14
+ /** Initializer for element properties. (These can be thought of as "inputs".) */
15
+ props?: PropertyInitGeneric | undefined;
16
+ /** Initializer for events that the element can dispatch. (These can be thought of as "outputs".) */
17
+ events?: EventsInitGeneric | undefined;
18
+ /** Called as part of the first renderCallback call, before the first renderCallback call. */
19
+ initCallback?: InitCallback<PropertyInitGeneric, EventsInitGeneric>;
20
+ renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
21
+ };
22
+ export declare abstract class FunctionalElementBaseClass<PropertyInitGeneric extends PropertyInitMapBase> extends LitElement {
23
+ static readonly tagName: string;
24
+ static readonly styles: CSSResult;
25
+ abstract render(): TemplateResult | Promise<TemplateResult>;
26
+ abstract readonly instanceProps: PropertyInitGeneric;
27
+ }
28
+ export declare type FunctionalElementInstance<PropertyInitGeneric extends PropertyInitMapBase = {}> = FunctionalElementBaseClass<PropertyInitGeneric> & PropertyInitGeneric;
29
+ export declare type FunctionalElement<PropertyInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any> = (new () => FunctionalElementInstance<PropertyInitGeneric>) & ExtraStaticFunctionalElementProperties<PropertyInitGeneric, EventsInitGeneric>;
30
+ export declare type ExtraStaticFunctionalElementProperties<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = Readonly<{
31
+ /** Pass through the render callback for direct unit testability */
32
+ renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
33
+ events: EventDescriptorMap<EventsInitGeneric>;
34
+ props: ElementPropertyDescriptorMap<PropertyInitGeneric>;
35
+ initInput: FunctionalElementInit<PropertyInitGeneric, EventsInitGeneric>;
36
+ /**
37
+ * Static properties have to be copied here cause they get nuked in the "new () =>
38
+ * FunctionalElementInstance<PropertyInitGeneric>" type.
39
+ */
40
+ tagName: string;
41
+ styles: CSSResult;
42
+ }>;
@@ -3,7 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunctionalElementBaseClass = void 0;
4
4
  const lit_1 = require("lit");
5
5
  class FunctionalElementBaseClass extends lit_1.LitElement {
6
- static tagName;
7
- static styles;
8
6
  }
9
7
  exports.FunctionalElementBaseClass = FunctionalElementBaseClass;
@@ -0,0 +1,21 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { TypedEvent } from '../typed-event/typed-event';
3
+ import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './element-events';
4
+ import { PropertyInitMapBase } from './element-properties';
5
+ import { FunctionalElementInstance } from './functional-element';
6
+ export declare type RenderCallback<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (params: RenderParams<PropertyInitGeneric, EventsInitGeneric>) => TemplateResult;
7
+ export declare type InitCallback<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (params: RenderParams<PropertyInitGeneric, EventsInitGeneric>) => void;
8
+ export declare type SetPropCallback<PropertyInitGeneric extends PropertyInitMapBase> = (props: Partial<PropertyInitGeneric>) => void;
9
+ export declare type RenderParams<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
10
+ props: Readonly<PropertyInitGeneric>;
11
+ setProps: SetPropCallback<PropertyInitGeneric>;
12
+ events: EventDescriptorMap<EventsInitGeneric>;
13
+ host: FunctionalElementInstance<PropertyInitGeneric>;
14
+ dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>>) => boolean;
15
+ /**
16
+ * Same as dispatchElementEvent but without the extra types. This allows you to emit any events,
17
+ * even events from other custom elements.
18
+ */
19
+ genericDispatch: (event: Event) => boolean;
20
+ };
21
+ export declare function createRenderParams<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap>(element: FunctionalElementInstance<PropertyInitGeneric>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<PropertyInitGeneric, EventsInitGeneric>;
@@ -0,0 +1,15 @@
1
+ export * from './functional-element/define-functional-element';
2
+ export * from './functional-element/directives/assign-with-clean-up.directive';
3
+ export * from './functional-element/directives/assign.directive';
4
+ export * from './functional-element/directives/directive-util';
5
+ export * from './functional-element/directives/listen.directive';
6
+ export * from './functional-element/directives/on-dom-created.directive';
7
+ export * from './functional-element/directives/on-resize.directive';
8
+ export * from './functional-element/element-events';
9
+ export * from './functional-element/element-properties';
10
+ export * from './functional-element/functional-element';
11
+ export * from './functional-element/render-callback';
12
+ export { requireAllCustomElementsToBeFunctionalElement } from './require-functional-element';
13
+ export * from './template-transforms/vir-css/vir-css';
14
+ export * from './template-transforms/vir-html/vir-html';
15
+ export * from './typed-event/typed-event';
@@ -0,0 +1,2 @@
1
+ export declare let functionalElementRequired: boolean;
2
+ export declare function requireAllCustomElementsToBeFunctionalElement(): void;
@@ -0,0 +1,4 @@
1
+ export declare type ConstructorWithTagName = Function & {
2
+ tagName: string;
3
+ };
4
+ export declare function hasStaticTagName(value: unknown): value is ConstructorWithTagName;
@@ -0,0 +1,16 @@
1
+ export declare type TemplateTransform = {
2
+ templateStrings: TemplateStringsArray;
3
+ valueIndexDeletions: number[];
4
+ };
5
+ export declare type ValueTransform = (value: unknown) => unknown;
6
+ export declare type CheckAndTransform<T> = {
7
+ check: (lastNewString: string, currentLitString: string, currentValue: unknown) => currentValue is T;
8
+ transform: (value: T) => unknown;
9
+ name: string;
10
+ };
11
+ export declare function makeCheckTransform<T>(name: string, check: (lastNewString: string, currentLitString: string, currentValue: unknown) => currentValue is T, transform: (value: T) => unknown): CheckAndTransform<T>;
12
+ export declare function getTransformedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[], fallbackTransform: () => TemplateTransform): {
13
+ strings: TemplateStringsArray;
14
+ values: PossibleValues[];
15
+ };
16
+ export declare function transformTemplate<TransformsGeneric extends CheckAndTransform<any>[], PossibleValues>(inputTemplateStrings: TemplateStringsArray, inputValues: PossibleValues[], checksAndTransforms: TransformsGeneric, assertValidString?: (templateStringPart: string) => void): TemplateTransform;
@@ -21,7 +21,7 @@ exports.makeCheckTransform = makeCheckTransform;
21
21
  const transformedTemplateStrings = new WeakMap();
22
22
  function getTransformedTemplate(templateStringsKey, values, fallbackTransform) {
23
23
  const alreadyTransformedTemplateStrings = transformedTemplateStrings.get(templateStringsKey);
24
- const templateTransform = alreadyTransformedTemplateStrings ?? fallbackTransform();
24
+ const templateTransform = alreadyTransformedTemplateStrings !== null && alreadyTransformedTemplateStrings !== void 0 ? alreadyTransformedTemplateStrings : fallbackTransform();
25
25
  if (!alreadyTransformedTemplateStrings) {
26
26
  transformedTemplateStrings.set(templateStringsKey, templateTransform);
27
27
  }
@@ -34,6 +34,7 @@ function transformTemplate(inputTemplateStrings, inputValues, checksAndTransform
34
34
  const newRaws = [];
35
35
  const valueDeletions = [];
36
36
  inputTemplateStrings.forEach((currentTemplateString, index) => {
37
+ var _a;
37
38
  const lastNewStringsIndex = newStrings.length - 1;
38
39
  const lastNewString = newStrings[lastNewStringsIndex];
39
40
  const currentValueIndex = index - 1;
@@ -41,9 +42,9 @@ function transformTemplate(inputTemplateStrings, inputValues, checksAndTransform
41
42
  let validTransform;
42
43
  assertValidString && assertValidString(currentTemplateString);
43
44
  if (typeof lastNewString === 'string') {
44
- validTransform = checksAndTransforms.find((checkAndTransform) => {
45
+ validTransform = (_a = checksAndTransforms.find((checkAndTransform) => {
45
46
  return checkAndTransform.check(lastNewString, currentTemplateString, currentValue);
46
- })?.transform;
47
+ })) === null || _a === void 0 ? void 0 : _a.transform;
47
48
  if (validTransform) {
48
49
  newStrings[lastNewStringsIndex] =
49
50
  lastNewString + validTransform(currentValue) + currentTemplateString;
@@ -0,0 +1,7 @@
1
+ import { CSSResultGroup } from 'lit';
2
+ import { FunctionalElement } from '../../functional-element/functional-element';
3
+ export declare type CssTemplateTransform = {
4
+ templateStrings: TemplateStringsArray;
5
+ valueIndexDeletions: number[];
6
+ };
7
+ export declare function transformCssTemplate(inputTemplateStrings: TemplateStringsArray, inputValues: (number | CSSResultGroup | FunctionalElement)[]): CssTemplateTransform;
@@ -0,0 +1,3 @@
1
+ import { CSSResult, CSSResultGroup } from 'lit';
2
+ import { FunctionalElement } from '../../functional-element/functional-element';
3
+ export declare function css(inputTemplateStrings: TemplateStringsArray, ...inputValues: (number | CSSResultGroup | FunctionalElement)[]): CSSResult;
@@ -0,0 +1,3 @@
1
+ import { HTMLTemplateResult } from 'lit';
2
+ import { TemplateTransform } from '../transform-template';
3
+ export declare function transformHtmlTemplate(litTemplate: HTMLTemplateResult): TemplateTransform;
@@ -8,7 +8,7 @@ const transform_template_1 = require("../transform-template");
8
8
  const htmlChecksAndTransforms = [
9
9
  (0, transform_template_1.makeCheckTransform)('tag name interpolation', (lastNewString, currentLitString, currentValue) => {
10
10
  const shouldHaveTagNameHere = (lastNewString.trim().endsWith('<') && !!currentLitString.match(/^[\s\n>]/)) ||
11
- (lastNewString?.trim().endsWith('</') && currentLitString.trim().startsWith('>'));
11
+ ((lastNewString === null || lastNewString === void 0 ? void 0 : lastNewString.trim().endsWith('</')) && currentLitString.trim().startsWith('>'));
12
12
  const staticTagName = (0, has_static_tag_name_1.hasStaticTagName)(currentValue);
13
13
  if (shouldHaveTagNameHere && !staticTagName) {
14
14
  console.error({
@@ -0,0 +1,3 @@
1
+ import { HTMLTemplateResult } from 'lit';
2
+ /** Enables interpolation of FunctionalElement tag names */
3
+ export declare function html(inputTemplateStrings: TemplateStringsArray, ...inputValues: unknown[]): HTMLTemplateResult;
@@ -0,0 +1,19 @@
1
+ import { NonEmptyString } from '../augments/type';
2
+ export declare class TypedEvent<EventTypeNameGeneric extends string = '', EventDetailGeneric = undefined> extends CustomEvent<EventDetailGeneric> {
3
+ readonly _type: EventTypeNameGeneric;
4
+ get type(): EventTypeNameGeneric;
5
+ constructor(type: EventTypeNameGeneric | {
6
+ type: EventTypeNameGeneric;
7
+ }, value: EventDetailGeneric);
8
+ }
9
+ export declare type DefinedTypedEventNameDefinition<EventDetailGeneric> = <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
10
+ export declare type DefinedTypedEvent<EventTypeNameGeneric extends string, EventDetailGeneric> = (new (eventValue: EventDetailGeneric) => TypedEvent<EventTypeNameGeneric, EventDetailGeneric>) & {
11
+ type: EventTypeNameGeneric;
12
+ };
13
+ /**
14
+ * Defined a typed event. Make sure to use currying and call this function twice! Typescript's
15
+ * generic restrictions require this setup to get the types right without excessive verbosity.
16
+ *
17
+ * Example: const myCustomEvent = defineTypedEvent<number>()('my-custom-event')
18
+ */
19
+ export declare function defineTypedEvent<EventDetailGeneric>(): <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineTypedEvent = exports.TypedEvent = void 0;
4
4
  class TypedEvent extends CustomEvent {
5
- _type = '';
6
- get type() {
7
- return this._type;
8
- }
9
5
  constructor(type, value) {
10
6
  super(typeof type === 'string' ? type : type.type, {
11
7
  detail: value,
12
8
  bubbles: true,
13
9
  composed: true,
14
10
  });
11
+ this._type = '';
12
+ }
13
+ get type() {
14
+ return this._type;
15
15
  }
16
16
  }
17
17
  exports.TypedEvent = TypedEvent;
@@ -23,13 +23,15 @@ exports.TypedEvent = TypedEvent;
23
23
  */
24
24
  function defineTypedEvent() {
25
25
  return (eventType) => {
26
- return class extends TypedEvent {
27
- static type = eventType;
28
- _type = eventType;
29
- constructor(value) {
30
- super(eventType, value);
31
- }
32
- };
26
+ var _a;
27
+ return _a = class extends TypedEvent {
28
+ constructor(value) {
29
+ super(eventType, value);
30
+ this._type = eventType;
31
+ }
32
+ },
33
+ _a.type = eventType,
34
+ _a;
33
35
  };
34
36
  }
35
37
  exports.defineTypedEvent = defineTypedEvent;
@@ -0,0 +1 @@
1
+ export declare function filterOutArrayIndexes<T>(array: Readonly<T[]>, indexes: Readonly<number[]>): T[];
@@ -0,0 +1 @@
1
+ export declare type NonEmptyString<T> = T extends '' ? never : T;
@@ -0,0 +1,4 @@
1
+ import { EventsInitMap } from './element-events';
2
+ import { PropertyInitMapBase } from './element-properties';
3
+ import { FunctionalElement, FunctionalElementInit } from './functional-element';
4
+ export declare function defineFunctionalElement<EventsInitGeneric extends EventsInitMap = {}, PropertyInitGeneric extends PropertyInitMapBase = {}>(functionalElementInit: FunctionalElementInit<PropertyInitGeneric, EventsInitGeneric>): FunctionalElement<PropertyInitGeneric, EventsInitGeneric>;
@@ -5,37 +5,39 @@ import { createPropertyDescriptorMap, createPropertyProxy, } from './element-pro
5
5
  import { FunctionalElementBaseClass, } from './functional-element';
6
6
  import { createRenderParams } from './render-callback';
7
7
  export function defineFunctionalElement(functionalElementInit) {
8
+ var _a;
8
9
  const eventsMap = createEventDescriptorMap(functionalElementInit.events);
9
- const anonymousClass = class extends FunctionalElementBaseClass {
10
- static tagName = functionalElementInit.tagName;
11
- static styles = functionalElementInit.styles || css ``;
12
- createRenderParams() {
13
- return createRenderParams(this, eventsMap);
14
- }
15
- static initInput = functionalElementInit;
16
- static events = eventsMap;
17
- static renderCallback = functionalElementInit.renderCallback;
18
- static props = createPropertyDescriptorMap(functionalElementInit.props);
19
- initCalled = false;
20
- render() {
21
- const renderParams = this.createRenderParams();
22
- if (!this.initCalled && functionalElementInit.initCallback) {
23
- this.initCalled = true;
24
- functionalElementInit.initCallback(renderParams);
10
+ const anonymousClass = (_a = class extends FunctionalElementBaseClass {
11
+ constructor() {
12
+ super();
13
+ this.initCalled = false;
14
+ this.instanceProps = createPropertyProxy(functionalElementInit.props, this);
15
+ const initProps = functionalElementInit.props || {};
16
+ Object.keys(initProps).forEach((propName) => {
17
+ const functionalElementInstance = this;
18
+ property()(functionalElementInstance, propName);
19
+ functionalElementInstance[propName] = initProps[propName];
20
+ });
25
21
  }
26
- return functionalElementInit.renderCallback(renderParams);
27
- }
28
- instanceProps = createPropertyProxy(functionalElementInit.props, this);
29
- constructor() {
30
- super();
31
- const initProps = functionalElementInit.props || {};
32
- Object.keys(initProps).forEach((propName) => {
33
- const functionalElementInstance = this;
34
- property()(functionalElementInstance, propName);
35
- functionalElementInstance[propName] = initProps[propName];
36
- });
37
- }
38
- };
22
+ createRenderParams() {
23
+ return createRenderParams(this, eventsMap);
24
+ }
25
+ render() {
26
+ const renderParams = this.createRenderParams();
27
+ if (!this.initCalled && functionalElementInit.initCallback) {
28
+ this.initCalled = true;
29
+ functionalElementInit.initCallback(renderParams);
30
+ }
31
+ return functionalElementInit.renderCallback(renderParams);
32
+ }
33
+ },
34
+ _a.tagName = functionalElementInit.tagName,
35
+ _a.styles = functionalElementInit.styles || css ``,
36
+ _a.initInput = functionalElementInit,
37
+ _a.events = eventsMap,
38
+ _a.renderCallback = functionalElementInit.renderCallback,
39
+ _a.props = createPropertyDescriptorMap(functionalElementInit.props),
40
+ _a);
39
41
  window.customElements.define(functionalElementInit.tagName, anonymousClass);
40
42
  return anonymousClass;
41
43
  }
@@ -0,0 +1,19 @@
1
+ import { AsyncDirective } from 'lit/async-directive.js';
2
+ import { PartInfo } from 'lit/directive.js';
3
+ import { StaticElementPropertyDescriptor } from '../element-properties';
4
+ /**
5
+ * The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
6
+ * the directive call is wrapped in this function.
7
+ */
8
+ export declare function assignWithCleanup<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue'], cleanupCallback: CleanupCallback<typeof propertyDescriptor['initValue']>): import("lit-html/directive").DirectiveResult<typeof AssignWithCleanupDirectiveClass>;
9
+ export declare type CleanupCallback<T> = (oldValue: T) => void;
10
+ export declare type EqualityCheckCallback<T> = (oldValue: T, newValue: T) => boolean;
11
+ declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
12
+ private readonly element;
13
+ private lastValue;
14
+ private lastCallback;
15
+ constructor(partInfo: PartInfo);
16
+ disconnected(): void;
17
+ render(propName: string, value: unknown, cleanupCallback: CleanupCallback<any>, equalityCheck?: EqualityCheckCallback<any>): symbol;
18
+ }
19
+ export {};
@@ -10,9 +10,6 @@ export function assignWithCleanup(propertyDescriptor, value, cleanupCallback) {
10
10
  return assignWithCleanupDirective(propertyDescriptor.propName, value, cleanupCallback);
11
11
  }
12
12
  class AssignWithCleanupDirectiveClass extends AsyncDirective {
13
- element;
14
- lastValue;
15
- lastCallback;
16
13
  constructor(partInfo) {
17
14
  super(partInfo);
18
15
  this.element = extractFunctionalElement(partInfo, 'assign');
@@ -0,0 +1,15 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ import { PropertyInitMapBase, StaticElementPropertyDescriptor } from '../element-properties';
3
+ import { FunctionalElementInstance } from '../functional-element';
4
+ /**
5
+ * The directive generics (in listenDirective) are not strong enough to maintain their values. Thus,
6
+ * the directive call is wrapped in this function.
7
+ */
8
+ export declare function assign<PropName extends string, PropValue>(propertyDescriptor: StaticElementPropertyDescriptor<PropName, PropValue>, value: typeof propertyDescriptor['initValue']): import("lit-html/directive").DirectiveResult<{
9
+ new (partInfo: PartInfo): {
10
+ readonly element: FunctionalElementInstance<PropertyInitMapBase>;
11
+ render(propName: string, value: unknown): symbol;
12
+ readonly _$isConnected: boolean;
13
+ update(_part: import("lit-html").Part, props: unknown[]): unknown;
14
+ };
15
+ }>;
@@ -9,7 +9,6 @@ export function assign(propertyDescriptor, value) {
9
9
  return assignDirective(propertyDescriptor.propName, value);
10
10
  }
11
11
  const assignDirective = directive(class extends Directive {
12
- element;
13
12
  constructor(partInfo) {
14
13
  super(partInfo);
15
14
  this.element = extractFunctionalElement(partInfo, 'assign');
@@ -0,0 +1,15 @@
1
+ import { ElementPartInfo, PartInfo } from 'lit/directive.js';
2
+ import { PropertyInitMapBase } from '../element-properties';
3
+ import { FunctionalElementInstance } from '../functional-element';
4
+ /** For some reason these aren't defined in lit's types already. */
5
+ export declare type ExtraPartInfoProperties = {
6
+ element: Element;
7
+ options: {
8
+ host: Element;
9
+ renderBefore: Element;
10
+ isConnected: boolean;
11
+ };
12
+ };
13
+ export declare function extractFunctionalElement<PropertyInitGeneric extends PropertyInitMapBase>(partInfo: PartInfo, directiveName: string): FunctionalElementInstance<PropertyInitGeneric>;
14
+ export declare function extractElement<ElementType = HTMLElement>(partInfo: PartInfo, directiveName: string, constructorClass: (new () => ElementType) | (abstract new () => ElementType)): ElementType;
15
+ export declare function assertsIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
@@ -0,0 +1,13 @@
1
+ import { DirectiveResult } from 'lit/directive.js';
2
+ import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
3
+ /**
4
+ * Listen to events. These can be native DOM events (use a string for the inputType argument) or
5
+ * typed events (pass in a return value from defineTypedEvent).
6
+ *
7
+ * @param definedTypedEvent Needs to come either from a functional element (like
8
+ * MyFunctionalElement.events.eventName) or from a typed event created via the defineTypedEvent function.
9
+ * @param listener The callback to fire when an event is caught. Assuming the definedTypedEvent
10
+ * input is properly typed, the event given to this callback will also be typed.
11
+ */
12
+ export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: DefinedTypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>, listener: (event: TypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>) => void): DirectiveResult<any>;
13
+ export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: NativeElementEventNameGeneric, listener: (event: HTMLElementEventMap[NativeElementEventNameGeneric]) => void): DirectiveResult<any>;
@@ -9,8 +9,6 @@ export function listen(eventType, listener) {
9
9
  * call is wrapped in the function above.
10
10
  */
11
11
  const listenDirective = directive(class extends Directive {
12
- element;
13
- lastListenerMetaData;
14
12
  constructor(partInfo) {
15
13
  super(partInfo);
16
14
  this.element = extractElement(partInfo, 'listen', HTMLElement);
@@ -26,7 +24,7 @@ const listenDirective = directive(class extends Directive {
26
24
  return {
27
25
  eventType,
28
26
  callback,
29
- listener: (event) => this.lastListenerMetaData?.callback(event),
27
+ listener: (event) => { var _a; return (_a = this.lastListenerMetaData) === null || _a === void 0 ? void 0 : _a.callback(event); },
30
28
  };
31
29
  }
32
30
  render(eventTypeInput, callback) {
@@ -0,0 +1,11 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ export declare type OnDomCreatedCallback = (element: Element) => void;
3
+ /** Only fires once, when the element has been created. */
4
+ export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("lit-html/directive").DirectiveResult<{
5
+ new (partInfo: PartInfo): {
6
+ element: Element | undefined;
7
+ update(partInfo: PartInfo, [callback]: [OnDomCreatedCallback]): undefined;
8
+ render(callback: OnDomCreatedCallback): undefined;
9
+ readonly _$isConnected: boolean;
10
+ };
11
+ }>;
@@ -3,7 +3,6 @@ import { assertsIsElementPartInfo } from './directive-util';
3
3
  const directiveName = 'onDomCreated';
4
4
  /** Only fires once, when the element has been created. */
5
5
  export const onDomCreated = directive(class extends Directive {
6
- element;
7
6
  constructor(partInfo) {
8
7
  super(partInfo);
9
8
  assertsIsElementPartInfo(partInfo, directiveName);
@@ -0,0 +1,15 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ export declare type OnResizeCallback = (
3
+ /** Only these two properties are supported in all major modern browsers */
4
+ entry: Readonly<Pick<ResizeObserverEntry, 'target' | 'contentRect'>>) => void;
5
+ export declare const onResize: (callback: OnResizeCallback) => import("lit-html/directive").DirectiveResult<{
6
+ new (partInfo: PartInfo): {
7
+ element: Element | undefined;
8
+ readonly resizeObserver: ResizeObserver;
9
+ callback: OnResizeCallback | undefined;
10
+ fireCallback(entries: ResizeObserverEntry[]): void;
11
+ update(partInfo: PartInfo, [callback]: [OnResizeCallback]): undefined;
12
+ render(callback: OnResizeCallback): undefined;
13
+ readonly _$isConnected: boolean;
14
+ };
15
+ }>;
@@ -2,20 +2,19 @@ import { directive, Directive } from 'lit/directive.js';
2
2
  import { assertsIsElementPartInfo } from './directive-util';
3
3
  const directiveName = 'onResize';
4
4
  export const onResize = directive(class extends Directive {
5
- element;
6
- resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
7
- callback;
8
5
  constructor(partInfo) {
9
6
  super(partInfo);
7
+ this.resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
10
8
  assertsIsElementPartInfo(partInfo, directiveName);
11
9
  }
12
10
  fireCallback(entries) {
11
+ var _a;
13
12
  const resizeEntry = entries[0];
14
13
  if (!resizeEntry) {
15
14
  console.error(entries);
16
15
  throw new Error(`${directiveName} observation triggered but the first entry was empty.`);
17
16
  }
18
- this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect });
17
+ (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, { target: resizeEntry.target, contentRect: resizeEntry.contentRect });
19
18
  }
20
19
  update(partInfo, [callback]) {
21
20
  assertsIsElementPartInfo(partInfo, directiveName);
@@ -0,0 +1,10 @@
1
+ import { DefinedTypedEvent, DefinedTypedEventNameDefinition, TypedEvent } from '../typed-event/typed-event';
2
+ export declare type EventsInitMap = Record<string, DefinedTypedEventNameDefinition<any>>;
3
+ export declare function defineElementEvent<EventDetailGeneric>(): DefinedTypedEventNameDefinition<EventDetailGeneric>;
4
+ export declare type EventInitMapEventDetailExtractor<EventTypeNameGeneric extends keyof EventsInitGeneric, EventsInitGeneric extends EventsInitMap> = EventsInitGeneric[EventTypeNameGeneric] extends DefinedTypedEventNameDefinition<infer R> ? R : never;
5
+ export declare type EventDescriptorMap<EventsInitGeneric extends EventsInitMap> = {
6
+ [CurrentEventTypeName in keyof EventsInitGeneric]: DefinedTypedEvent<CurrentEventTypeName extends string ? CurrentEventTypeName : never, EventInitMapEventDetailExtractor<CurrentEventTypeName, EventsInitGeneric>>;
7
+ };
8
+ export declare type EventObjectEventDetailExtractor<EventObjectGeneric extends DefinedTypedEvent<any, any>> = EventObjectGeneric extends DefinedTypedEvent<string, infer R> ? R : never;
9
+ export declare type ElementEventDetailExtractor<ElementEventGeneric extends TypedEvent<any, any>> = ElementEventGeneric extends TypedEvent<string, infer R> ? R : never;
10
+ export declare function createEventDescriptorMap<EventsInitGeneric extends EventsInitMap>(eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<EventsInitGeneric>;
@@ -0,0 +1,16 @@
1
+ import { FunctionalElementInstance } from './functional-element';
2
+ export declare type PropertyInitMapBase = Record<string, unknown>;
3
+ export declare type ElementProperty<KeyGeneric extends string | number | symbol, ValueGeneric> = {
4
+ name: KeyGeneric;
5
+ setProp(value: ValueGeneric): void;
6
+ getProp(): ValueGeneric;
7
+ };
8
+ export declare type StaticElementPropertyDescriptor<PropName extends string, PropValue> = {
9
+ propName: PropName;
10
+ initValue: PropValue;
11
+ };
12
+ export declare type ElementPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase> = {
13
+ [Property in keyof PropertyInitGeneric]: StaticElementPropertyDescriptor<string, PropertyInitGeneric[Property]>;
14
+ };
15
+ export declare function createPropertyProxy<PropertyInitGeneric extends PropertyInitMapBase>(propsInitMap: PropertyInitGeneric | undefined, element: FunctionalElementInstance<PropertyInitGeneric>): PropertyInitGeneric;
16
+ export declare function createPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase>(propertyInit: PropertyInitGeneric | undefined): ElementPropertyDescriptorMap<PropertyInitGeneric>;
@@ -0,0 +1,42 @@
1
+ import { CSSResult, LitElement, TemplateResult } from 'lit';
2
+ import { EventDescriptorMap, EventsInitMap } from './element-events';
3
+ import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './element-properties';
4
+ import { InitCallback, RenderCallback } from './render-callback';
5
+ export declare type CustomElementTagName = `${string}-${string}`;
6
+ export declare type FunctionalElementInit<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
7
+ /**
8
+ * HTML tag name. This should not be used directly, as interpolating it with the html tagged
9
+ * template from this package is preferred.
10
+ */
11
+ tagName: CustomElementTagName;
12
+ /** Static styles. These should not and cannot change. */
13
+ styles?: CSSResult | undefined;
14
+ /** Initializer for element properties. (These can be thought of as "inputs".) */
15
+ props?: PropertyInitGeneric | undefined;
16
+ /** Initializer for events that the element can dispatch. (These can be thought of as "outputs".) */
17
+ events?: EventsInitGeneric | undefined;
18
+ /** Called as part of the first renderCallback call, before the first renderCallback call. */
19
+ initCallback?: InitCallback<PropertyInitGeneric, EventsInitGeneric>;
20
+ renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
21
+ };
22
+ export declare abstract class FunctionalElementBaseClass<PropertyInitGeneric extends PropertyInitMapBase> extends LitElement {
23
+ static readonly tagName: string;
24
+ static readonly styles: CSSResult;
25
+ abstract render(): TemplateResult | Promise<TemplateResult>;
26
+ abstract readonly instanceProps: PropertyInitGeneric;
27
+ }
28
+ export declare type FunctionalElementInstance<PropertyInitGeneric extends PropertyInitMapBase = {}> = FunctionalElementBaseClass<PropertyInitGeneric> & PropertyInitGeneric;
29
+ export declare type FunctionalElement<PropertyInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any> = (new () => FunctionalElementInstance<PropertyInitGeneric>) & ExtraStaticFunctionalElementProperties<PropertyInitGeneric, EventsInitGeneric>;
30
+ export declare type ExtraStaticFunctionalElementProperties<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = Readonly<{
31
+ /** Pass through the render callback for direct unit testability */
32
+ renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
33
+ events: EventDescriptorMap<EventsInitGeneric>;
34
+ props: ElementPropertyDescriptorMap<PropertyInitGeneric>;
35
+ initInput: FunctionalElementInit<PropertyInitGeneric, EventsInitGeneric>;
36
+ /**
37
+ * Static properties have to be copied here cause they get nuked in the "new () =>
38
+ * FunctionalElementInstance<PropertyInitGeneric>" type.
39
+ */
40
+ tagName: string;
41
+ styles: CSSResult;
42
+ }>;
@@ -1,5 +1,3 @@
1
1
  import { LitElement } from 'lit';
2
2
  export class FunctionalElementBaseClass extends LitElement {
3
- static tagName;
4
- static styles;
5
3
  }
@@ -0,0 +1,21 @@
1
+ import { TemplateResult } from 'lit';
2
+ import { TypedEvent } from '../typed-event/typed-event';
3
+ import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './element-events';
4
+ import { PropertyInitMapBase } from './element-properties';
5
+ import { FunctionalElementInstance } from './functional-element';
6
+ export declare type RenderCallback<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (params: RenderParams<PropertyInitGeneric, EventsInitGeneric>) => TemplateResult;
7
+ export declare type InitCallback<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (params: RenderParams<PropertyInitGeneric, EventsInitGeneric>) => void;
8
+ export declare type SetPropCallback<PropertyInitGeneric extends PropertyInitMapBase> = (props: Partial<PropertyInitGeneric>) => void;
9
+ export declare type RenderParams<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
10
+ props: Readonly<PropertyInitGeneric>;
11
+ setProps: SetPropCallback<PropertyInitGeneric>;
12
+ events: EventDescriptorMap<EventsInitGeneric>;
13
+ host: FunctionalElementInstance<PropertyInitGeneric>;
14
+ dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>>) => boolean;
15
+ /**
16
+ * Same as dispatchElementEvent but without the extra types. This allows you to emit any events,
17
+ * even events from other custom elements.
18
+ */
19
+ genericDispatch: (event: Event) => boolean;
20
+ };
21
+ export declare function createRenderParams<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap>(element: FunctionalElementInstance<PropertyInitGeneric>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<PropertyInitGeneric, EventsInitGeneric>;
@@ -0,0 +1,15 @@
1
+ export * from './functional-element/define-functional-element';
2
+ export * from './functional-element/directives/assign-with-clean-up.directive';
3
+ export * from './functional-element/directives/assign.directive';
4
+ export * from './functional-element/directives/directive-util';
5
+ export * from './functional-element/directives/listen.directive';
6
+ export * from './functional-element/directives/on-dom-created.directive';
7
+ export * from './functional-element/directives/on-resize.directive';
8
+ export * from './functional-element/element-events';
9
+ export * from './functional-element/element-properties';
10
+ export * from './functional-element/functional-element';
11
+ export * from './functional-element/render-callback';
12
+ export { requireAllCustomElementsToBeFunctionalElement } from './require-functional-element';
13
+ export * from './template-transforms/vir-css/vir-css';
14
+ export * from './template-transforms/vir-html/vir-html';
15
+ export * from './typed-event/typed-event';
@@ -0,0 +1,2 @@
1
+ export declare let functionalElementRequired: boolean;
2
+ export declare function requireAllCustomElementsToBeFunctionalElement(): void;
@@ -0,0 +1,4 @@
1
+ export declare type ConstructorWithTagName = Function & {
2
+ tagName: string;
3
+ };
4
+ export declare function hasStaticTagName(value: unknown): value is ConstructorWithTagName;
@@ -0,0 +1,16 @@
1
+ export declare type TemplateTransform = {
2
+ templateStrings: TemplateStringsArray;
3
+ valueIndexDeletions: number[];
4
+ };
5
+ export declare type ValueTransform = (value: unknown) => unknown;
6
+ export declare type CheckAndTransform<T> = {
7
+ check: (lastNewString: string, currentLitString: string, currentValue: unknown) => currentValue is T;
8
+ transform: (value: T) => unknown;
9
+ name: string;
10
+ };
11
+ export declare function makeCheckTransform<T>(name: string, check: (lastNewString: string, currentLitString: string, currentValue: unknown) => currentValue is T, transform: (value: T) => unknown): CheckAndTransform<T>;
12
+ export declare function getTransformedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[], fallbackTransform: () => TemplateTransform): {
13
+ strings: TemplateStringsArray;
14
+ values: PossibleValues[];
15
+ };
16
+ export declare function transformTemplate<TransformsGeneric extends CheckAndTransform<any>[], PossibleValues>(inputTemplateStrings: TemplateStringsArray, inputValues: PossibleValues[], checksAndTransforms: TransformsGeneric, assertValidString?: (templateStringPart: string) => void): TemplateTransform;
@@ -17,7 +17,7 @@ export function makeCheckTransform(name, check, transform) {
17
17
  const transformedTemplateStrings = new WeakMap();
18
18
  export function getTransformedTemplate(templateStringsKey, values, fallbackTransform) {
19
19
  const alreadyTransformedTemplateStrings = transformedTemplateStrings.get(templateStringsKey);
20
- const templateTransform = alreadyTransformedTemplateStrings ?? fallbackTransform();
20
+ const templateTransform = alreadyTransformedTemplateStrings !== null && alreadyTransformedTemplateStrings !== void 0 ? alreadyTransformedTemplateStrings : fallbackTransform();
21
21
  if (!alreadyTransformedTemplateStrings) {
22
22
  transformedTemplateStrings.set(templateStringsKey, templateTransform);
23
23
  }
@@ -29,6 +29,7 @@ export function transformTemplate(inputTemplateStrings, inputValues, checksAndTr
29
29
  const newRaws = [];
30
30
  const valueDeletions = [];
31
31
  inputTemplateStrings.forEach((currentTemplateString, index) => {
32
+ var _a;
32
33
  const lastNewStringsIndex = newStrings.length - 1;
33
34
  const lastNewString = newStrings[lastNewStringsIndex];
34
35
  const currentValueIndex = index - 1;
@@ -36,9 +37,9 @@ export function transformTemplate(inputTemplateStrings, inputValues, checksAndTr
36
37
  let validTransform;
37
38
  assertValidString && assertValidString(currentTemplateString);
38
39
  if (typeof lastNewString === 'string') {
39
- validTransform = checksAndTransforms.find((checkAndTransform) => {
40
+ validTransform = (_a = checksAndTransforms.find((checkAndTransform) => {
40
41
  return checkAndTransform.check(lastNewString, currentTemplateString, currentValue);
41
- })?.transform;
42
+ })) === null || _a === void 0 ? void 0 : _a.transform;
42
43
  if (validTransform) {
43
44
  newStrings[lastNewStringsIndex] =
44
45
  lastNewString + validTransform(currentValue) + currentTemplateString;
@@ -0,0 +1,7 @@
1
+ import { CSSResultGroup } from 'lit';
2
+ import { FunctionalElement } from '../../functional-element/functional-element';
3
+ export declare type CssTemplateTransform = {
4
+ templateStrings: TemplateStringsArray;
5
+ valueIndexDeletions: number[];
6
+ };
7
+ export declare function transformCssTemplate(inputTemplateStrings: TemplateStringsArray, inputValues: (number | CSSResultGroup | FunctionalElement)[]): CssTemplateTransform;
@@ -0,0 +1,3 @@
1
+ import { CSSResult, CSSResultGroup } from 'lit';
2
+ import { FunctionalElement } from '../../functional-element/functional-element';
3
+ export declare function css(inputTemplateStrings: TemplateStringsArray, ...inputValues: (number | CSSResultGroup | FunctionalElement)[]): CSSResult;
@@ -0,0 +1,3 @@
1
+ import { HTMLTemplateResult } from 'lit';
2
+ import { TemplateTransform } from '../transform-template';
3
+ export declare function transformHtmlTemplate(litTemplate: HTMLTemplateResult): TemplateTransform;
@@ -5,7 +5,7 @@ import { makeCheckTransform, transformTemplate, } from '../transform-template';
5
5
  const htmlChecksAndTransforms = [
6
6
  makeCheckTransform('tag name interpolation', (lastNewString, currentLitString, currentValue) => {
7
7
  const shouldHaveTagNameHere = (lastNewString.trim().endsWith('<') && !!currentLitString.match(/^[\s\n>]/)) ||
8
- (lastNewString?.trim().endsWith('</') && currentLitString.trim().startsWith('>'));
8
+ ((lastNewString === null || lastNewString === void 0 ? void 0 : lastNewString.trim().endsWith('</')) && currentLitString.trim().startsWith('>'));
9
9
  const staticTagName = hasStaticTagName(currentValue);
10
10
  if (shouldHaveTagNameHere && !staticTagName) {
11
11
  console.error({
@@ -0,0 +1,3 @@
1
+ import { HTMLTemplateResult } from 'lit';
2
+ /** Enables interpolation of FunctionalElement tag names */
3
+ export declare function html(inputTemplateStrings: TemplateStringsArray, ...inputValues: unknown[]): HTMLTemplateResult;
@@ -0,0 +1,19 @@
1
+ import { NonEmptyString } from '../augments/type';
2
+ export declare class TypedEvent<EventTypeNameGeneric extends string = '', EventDetailGeneric = undefined> extends CustomEvent<EventDetailGeneric> {
3
+ readonly _type: EventTypeNameGeneric;
4
+ get type(): EventTypeNameGeneric;
5
+ constructor(type: EventTypeNameGeneric | {
6
+ type: EventTypeNameGeneric;
7
+ }, value: EventDetailGeneric);
8
+ }
9
+ export declare type DefinedTypedEventNameDefinition<EventDetailGeneric> = <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
10
+ export declare type DefinedTypedEvent<EventTypeNameGeneric extends string, EventDetailGeneric> = (new (eventValue: EventDetailGeneric) => TypedEvent<EventTypeNameGeneric, EventDetailGeneric>) & {
11
+ type: EventTypeNameGeneric;
12
+ };
13
+ /**
14
+ * Defined a typed event. Make sure to use currying and call this function twice! Typescript's
15
+ * generic restrictions require this setup to get the types right without excessive verbosity.
16
+ *
17
+ * Example: const myCustomEvent = defineTypedEvent<number>()('my-custom-event')
18
+ */
19
+ export declare function defineTypedEvent<EventDetailGeneric>(): <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
@@ -1,14 +1,14 @@
1
1
  export class TypedEvent extends CustomEvent {
2
- _type = '';
3
- get type() {
4
- return this._type;
5
- }
6
2
  constructor(type, value) {
7
3
  super(typeof type === 'string' ? type : type.type, {
8
4
  detail: value,
9
5
  bubbles: true,
10
6
  composed: true,
11
7
  });
8
+ this._type = '';
9
+ }
10
+ get type() {
11
+ return this._type;
12
12
  }
13
13
  }
14
14
  /**
@@ -19,12 +19,14 @@ export class TypedEvent extends CustomEvent {
19
19
  */
20
20
  export function defineTypedEvent() {
21
21
  return (eventType) => {
22
- return class extends TypedEvent {
23
- static type = eventType;
24
- _type = eventType;
25
- constructor(value) {
26
- super(eventType, value);
27
- }
28
- };
22
+ var _a;
23
+ return _a = class extends TypedEvent {
24
+ constructor(value) {
25
+ super(eventType, value);
26
+ this._type = eventType;
27
+ }
28
+ },
29
+ _a.type = eventType,
30
+ _a;
29
31
  };
30
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "5.1.0",
3
+ "version": "5.4.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -31,7 +31,7 @@
31
31
  "module": "dist/esm/index.js",
32
32
  "types": "dist/types/index.d.ts",
33
33
  "scripts": {
34
- "compile": "rm -rf dist && tsc --project tsconfig.json && tsc --project tsconfig.cjs.json",
34
+ "compile": "rm -rf dist && tsc --project tsconfig.json && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
35
35
  "format": "virmator format write",
36
36
  "jest": "jest --config ./src/jest/jest.config.ts",
37
37
  "prepublishOnly": "npm run compile && npm run test:full",
@@ -43,11 +43,11 @@
43
43
  "update-docs": "virmator code-in-markdown README.md --index src/index.ts"
44
44
  },
45
45
  "dependencies": {
46
- "augment-vir": "2.1.0",
46
+ "augment-vir": "2.1.1",
47
47
  "lit": "2.2.3"
48
48
  },
49
49
  "devDependencies": {
50
- "jest-environment-jsdom": "28.0.2",
50
+ "jest-environment-jsdom": "28.1.0",
51
51
  "virmator": "2.0.7",
52
52
  "vite": "2.9.8"
53
53
  }