element-vir 12.2.0 → 12.3.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.
@@ -0,0 +1,2 @@
1
+ export { svg } from 'lit';
2
+ export type { CompiledTemplate, CompiledTemplateResult, HTMLTemplateResult, SVGTemplateResult, TemplateResult, } from 'lit';
@@ -0,0 +1 @@
1
+ export { svg } from 'lit';
@@ -9,7 +9,7 @@ import { HostClassesInitMap } from './properties/host-classes';
9
9
  import { StylesCallback } from './properties/styles';
10
10
  import { InitCallback, RenderCallback } from './render-callback';
11
11
  export type CustomElementTagName = `${string}-${string}`;
12
- export type DeclarativeElementInit<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeysGeneric extends string, CssVarKeysGeneric extends string, RenderOutputGeneric> = {
12
+ export type DeclarativeElementInit<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeysGeneric extends string, CssVarKeysGeneric extends string, RenderOutputGeneric, InputsDefinerFunction extends ((input: any) => any) | undefined> = {
13
13
  /**
14
14
  * HTML tag name. This should not be used directly, as interpolating it with the html tagged
15
15
  * template from this package is preferred.
@@ -39,8 +39,9 @@ export type DeclarativeElementInit<TagNameGeneric extends CustomElementTagName,
39
39
  */
40
40
  cssVars?: CssVarsInitMap<CssVarKeysGeneric>;
41
41
  /** Called as part of the first renderCallback call, before the first renderCallback call. */
42
- initCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
43
- renderCallback: RequireNonVoidReturn<RenderOutputGeneric, RenderCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric>>;
44
- cleanupCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
42
+ initCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, InputsDefinerFunction>;
43
+ renderCallback: RequireNonVoidReturn<RenderOutputGeneric, RenderCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric, InputsDefinerFunction>>;
44
+ cleanupCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, InputsDefinerFunction>;
45
45
  options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
46
+ inputsDefiner?: undefined | InputsDefinerFunction;
46
47
  };
@@ -7,24 +7,30 @@ import { EventDescriptorMap, EventsInitMap } from './properties/element-events';
7
7
  import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './properties/element-properties';
8
8
  import { HostClassNamesMap } from './properties/host-classes';
9
9
  import { RenderCallback, RenderParams } from './render-callback';
10
- export type HostInstanceType<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = RequiredAndNotNullBy<DeclarativeElement<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, any>, 'shadowRoot'>;
11
- export type DeclarativeElementDefinition<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string, RenderOutputGeneric = any> = (new () => HostInstanceType<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) & StaticDeclarativeElementProperties<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric> & {
12
- instanceType: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
10
+ export type HostInstanceType<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, InputsDefinerFunction extends ((input: any) => any) | undefined = undefined> = RequiredAndNotNullBy<DeclarativeElement<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys,
11
+ /**
12
+ * Intentionally do not have a generic parameter for RenderOutputGeneric here so that
13
+ * HostInstanceType is vague enough that it can actually be used.
14
+ */
15
+ any, InputsDefinerFunction>, 'shadowRoot'>;
16
+ export type DeclarativeElementDefinition<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string, RenderOutputGeneric = any, InputsDefinerFunction extends ((input: any) => any) | undefined = undefined> = (new () => HostInstanceType<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>) & StaticDeclarativeElementProperties<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction> & {
17
+ instanceType: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>;
13
18
  };
14
- export declare abstract class DeclarativeElement<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string, RenderOutputGeneric = any> extends LitElement {
15
- static readonly tagName: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['tagName'];
16
- static readonly styles: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['styles'];
17
- static readonly isStrictInstance: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['isStrictInstance'];
18
- static readonly renderCallback: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['renderCallback'];
19
- static readonly inputsType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['inputsType'];
20
- static readonly stateType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['stateType'];
21
- static readonly events: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['events'];
22
- static readonly stateInit: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['stateInit'];
23
- static readonly init: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['init'];
24
- static readonly hostClasses: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['hostClasses'];
25
- static readonly cssVarNames: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['cssVarNames'];
26
- static readonly cssVarValues: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown>['cssVarValues'];
27
- abstract lastRenderedProps: Pick<RenderParams<any, InputsGeneric, StateInitMaybeAsyncGeneric, any, any, any>, 'inputs' | 'state'>;
19
+ export declare abstract class DeclarativeElement<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string, RenderOutputGeneric = any, InputsDefinerFunction extends ((input: any) => any) | undefined = any> extends LitElement {
20
+ static readonly tagName: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['tagName'];
21
+ static readonly styles: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['styles'];
22
+ static readonly isStrictInstance: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['isStrictInstance'];
23
+ static readonly renderCallback: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['renderCallback'];
24
+ static readonly defineInputs: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['defineInputs'];
25
+ static readonly inputsType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['inputsType'];
26
+ static readonly stateType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['stateType'];
27
+ static readonly events: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['events'];
28
+ static readonly stateInit: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['stateInit'];
29
+ static readonly init: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['init'];
30
+ static readonly hostClasses: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['hostClasses'];
31
+ static readonly cssVarNames: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['cssVarNames'];
32
+ static readonly cssVarValues: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string, unknown, any>['cssVarValues'];
33
+ abstract lastRenderedProps: Pick<RenderParams<any, InputsGeneric, StateInitMaybeAsyncGeneric, any, any, any, any>, 'inputs' | 'state'>;
28
34
  abstract render(): unknown;
29
35
  abstract readonly instanceState: MaybeAsyncStateToSync<StateInitMaybeAsyncGeneric>;
30
36
  abstract readonly asyncStateHandlerMap: AsyncStateHandlerMap<StateInitMaybeAsyncGeneric>;
@@ -32,17 +38,18 @@ export declare abstract class DeclarativeElement<TagNameGeneric extends CustomEl
32
38
  abstract assignInputs(inputs: {} extends Required<InputsGeneric> ? never : Partial<InputsGeneric>): void;
33
39
  abstract haveInputsBeenSet: boolean;
34
40
  abstract markInputsAsHavingBeenSet(): void;
35
- abstract readonly definition: DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
41
+ abstract readonly definition: DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>;
36
42
  }
37
- export interface StaticDeclarativeElementProperties<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, RenderOutputGeneric> {
43
+ export interface StaticDeclarativeElementProperties<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitMaybeAsyncGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, RenderOutputGeneric, InputsDefinerFunction extends ((input: any) => any) | undefined> {
38
44
  /** Pass through the render callback for direct unit testability */
39
- readonly renderCallback: RenderCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
45
+ readonly renderCallback: RenderCallback<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>;
46
+ readonly defineInputs: InputsDefinerFunction;
40
47
  events: EventDescriptorMap<EventsInitGeneric>;
41
48
  stateInit: ElementPropertyDescriptorMap<StateInitMaybeAsyncGeneric>;
42
- init: RequiredBy<DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>, 'stateInit' | 'events'>;
49
+ init: RequiredBy<DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>, 'stateInit' | 'events'>;
43
50
  inputsType: InputsGeneric;
44
51
  stateType: MaybeAsyncStateToSync<StateInitMaybeAsyncGeneric>;
45
- isStrictInstance: (element: unknown) => element is DeclarativeElement<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
52
+ isStrictInstance: (element: unknown) => element is DeclarativeElement<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>;
46
53
  hostClasses: HostClassNamesMap<string, HostClassKeys>;
47
54
  cssVarNames: CssVarNameOrValueMap<CssVarKeys>;
48
55
  cssVarValues: CssVarNameOrValueMap<CssVarKeys>;
@@ -2,4 +2,4 @@ import { DeclarativeElementDefinition } from './declarative-element';
2
2
  import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
3
3
  import { EventsInitMap } from './properties/element-events';
4
4
  import { PropertyInitMapBase } from './properties/element-properties';
5
- export declare function defineElementNoInputs<TagNameGeneric extends CustomElementTagName = '-', InputsGeneric extends PropertyInitMapBase = {}, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = '', CssVarKeys extends string = '', RenderOutputGeneric = any>(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>): DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
5
+ export declare function defineElementNoInputs<TagNameGeneric extends CustomElementTagName = '-', InputsGeneric extends PropertyInitMapBase = {}, StateInitMaybeAsyncGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = '', CssVarKeys extends string = '', RenderOutputGeneric = any, InputsDefinerFunction extends ((input: any) => any) | undefined = undefined>(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>): DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitMaybeAsyncGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>;
@@ -34,6 +34,8 @@ export function defineElementNoInputs(initInput) {
34
34
  ? initInput.styles(hostClassNamesToStylesInput({ hostClassNames, cssVarNames, cssVarValues }))
35
35
  : initInput.styles || css ``;
36
36
  const typedRenderCallback = initInput.renderCallback;
37
+ const typedDefineInputs = initInput.inputsDefiner ??
38
+ ((inputs) => inputs);
37
39
  const anonymousClass = (_a = class extends DeclarativeElement {
38
40
  createRenderParams() {
39
41
  return createRenderParams(this, eventsMap);
@@ -132,6 +134,7 @@ export function defineElementNoInputs(initInput) {
132
134
  _a.isStrictInstance = () => false,
133
135
  _a.events = eventsMap,
134
136
  _a.renderCallback = typedRenderCallback,
137
+ _a.defineInputs = typedDefineInputs,
135
138
  _a.hostClasses = hostClassNames,
136
139
  _a.cssVarNames = cssVarNames,
137
140
  _a.stateInit = initInput.stateInit,
@@ -1,5 +1,8 @@
1
1
  import { DeclarativeElementDefinition } from './declarative-element';
2
- import { DeclarativeElementInit } from './declarative-element-init';
2
+ import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
3
3
  import { EventsInitMap } from './properties/element-events';
4
4
  import { PropertyInitMapBase } from './properties/element-properties';
5
- export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): <TagNameGeneric extends `${string}-${string}`, StateInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeysGeneric extends string = "", CssVarKeysGeneric extends string = "", RenderOutputGeneric = any>(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric>) => DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric>;
5
+ type ElementDefiner<InputsGeneric extends PropertyInitMapBase, InputsDefinerFunction extends ((input: any) => any) | undefined> = <TagNameGeneric extends CustomElementTagName, StateInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeysGeneric extends string = '', CssVarKeysGeneric extends string = '', RenderOutputGeneric = any>(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric, InputsDefinerFunction>) => DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric, InputsDefinerFunction>;
6
+ export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): ElementDefiner<InputsGeneric, undefined>;
7
+ export declare function defineElement<InputsDefinerFunction extends (input: any) => any>(inputsDefinerFunction: InputsDefinerFunction): ElementDefiner<ReturnType<InputsDefinerFunction>, InputsDefinerFunction>;
8
+ export {};
@@ -1,13 +1,14 @@
1
1
  import { defineElementNoInputs } from './define-element-no-inputs';
2
2
  import { IgnoreInputsNotBeenSetBeforeRenderWarningSymbol } from './definition-options';
3
- export function defineElement() {
3
+ export function defineElement(inputsDefinerFunction) {
4
4
  return (initInput) => {
5
5
  return defineElementNoInputs({
6
6
  ...initInput,
7
7
  options: {
8
+ ...initInput.options,
8
9
  [IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: false,
9
10
  },
10
- ...initInput.options,
11
+ inputsDefiner: inputsDefinerFunction,
11
12
  });
12
13
  };
13
14
  }
@@ -4,15 +4,15 @@ import { CustomElementTagName } from './declarative-element-init';
4
4
  import { AsyncStateInputs, MaybeAsyncStateToSync } from './properties/async-state';
5
5
  import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './properties/element-events';
6
6
  import { PropertyInitMapBase } from './properties/element-properties';
7
- export type RenderCallback<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = any, CssVarKeys extends string = any, RenderOutputGeneric = any> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => RenderOutputGeneric;
8
- export type InitCallback<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => void;
7
+ export type RenderCallback<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = any, CssVarKeys extends string = any, RenderOutputGeneric = any, InputsDefinerFunction extends ((input: any) => any) | undefined = any> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>) => RenderOutputGeneric;
8
+ export type InitCallback<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, InputsDefinerFunction extends ((input: any) => any) | undefined> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>) => void;
9
9
  export type UpdateStateCallback<StateGeneric extends PropertyInitMapBase> = (newState: Partial<AsyncStateInputs<StateGeneric>>) => void;
10
- export type RenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
10
+ export type RenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, InputsDefinerFunction extends ((input: any) => any) | undefined> = {
11
11
  state: Readonly<MaybeAsyncStateToSync<StateInitGeneric>>;
12
12
  updateState: UpdateStateCallback<StateInitGeneric>;
13
13
  events: EventDescriptorMap<EventsInitGeneric>;
14
- host: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
14
+ host: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>;
15
15
  dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>> | Event) => boolean;
16
16
  inputs: InputsGeneric;
17
17
  };
18
- export declare function createRenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, RenderOutputGeneric>(element: DeclarativeElement<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
18
+ export declare function createRenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string, RenderOutputGeneric, InputsDefinerFunction extends ((input: any) => any) | undefined>(element: DeclarativeElement<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, RenderOutputGeneric, InputsDefinerFunction>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys, InputsDefinerFunction>;
@@ -0,0 +1,5 @@
1
+ import type { TemplateResult } from 'lit';
2
+ import type { unsafeHTML, unsafeSVG } from '../../built-in-lit-directives';
3
+ export declare function templateToString(template: TemplateResult | ReturnType<typeof unsafeSVG> | ReturnType<typeof unsafeHTML> | {
4
+ templateString: string;
5
+ }): string;
@@ -0,0 +1,39 @@
1
+ import { collapseWhiteSpace } from '@augment-vir/common';
2
+ export function templateToString(template) {
3
+ if ('templateString' in template) {
4
+ return template.templateString;
5
+ }
6
+ const { strings, values } = template;
7
+ if ((!strings || !strings?.length) && (!values || !values.length)) {
8
+ return '';
9
+ }
10
+ const valueList = [
11
+ ...(values || []),
12
+ '', // this last empty string is so it's easier to deal with indexes
13
+ ];
14
+ const stringsList = strings ?? [''];
15
+ const all = stringsList.map((stringValue, index) => {
16
+ const value = extractValue(stringValue, valueList[index]);
17
+ return `${stringValue}${value}`;
18
+ });
19
+ return collapseWhiteSpace(all.join(''));
20
+ }
21
+ function extractValue(previousString, value) {
22
+ if (value._$litType$ != undefined || value._$litDirective$ != undefined) {
23
+ // nested templates
24
+ return templateToString(value);
25
+ }
26
+ else if (Array.isArray(value)) {
27
+ // array of strings or templates.
28
+ const values = value.map((innerValue) => templateToString(innerValue));
29
+ return values.join('');
30
+ }
31
+ else {
32
+ if (previousString.endsWith('=')) {
33
+ return `"${value}"`;
34
+ }
35
+ else {
36
+ return value;
37
+ }
38
+ }
39
+ }
@@ -1,10 +1,10 @@
1
1
  import { PartialAndNullable } from '@augment-vir/common';
2
2
  import { CustomElementTagName, DeclarativeElementInit, EventsInitMap, PropertyInitMapBase } from '..';
3
- export type WrapDefineElementOptions<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = '', CssVarKeysRequirementGeneric extends string = '', RenderOutputGeneric = any> = PartialAndNullable<{
4
- assertInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputGeneric>) => void;
5
- transformInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputGeneric>) => DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputGeneric>;
3
+ export type WrapDefineElementOptions<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = '', CssVarKeysRequirementGeneric extends string = '', RenderOutputRequirementGeneric = any, InputsDefinerFunctionRequirementGeneric extends ((input: any) => any) | undefined = undefined> = PartialAndNullable<{
4
+ assertInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputRequirementGeneric, InputsDefinerFunctionRequirementGeneric>) => void;
5
+ transformInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputRequirementGeneric, InputsDefinerFunctionRequirementGeneric>) => DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric, RenderOutputRequirementGeneric, InputsDefinerFunctionRequirementGeneric>;
6
6
  }>;
7
- export declare function wrapDefineElement<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = string, CssVarKeysRequirementGeneric extends string = string, RenderOutputRequirementGeneric = any>(options?: WrapDefineElementOptions | undefined): {
8
- defineElement: <InputsGeneric extends InputsRequirementGeneric>() => <TagNameGeneric extends TagNameRequirementGeneric, StateInitGeneric extends StateInitRequirementGeneric, EventsInitGeneric extends EventsInitRequirementGeneric, HostClassKeysGeneric extends HostClassKeysRequirementGeneric, CssVarKeysGeneric extends CssVarKeysRequirementGeneric, RenderOutputGeneric extends RenderOutputRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric>;
9
- defineElementNoInputs: <TagNameGeneric_1 extends TagNameRequirementGeneric, InputsGeneric_1 extends InputsRequirementGeneric, StateInitGeneric_1 extends StateInitRequirementGeneric, EventsInitGeneric_1 extends EventsInitRequirementGeneric, HostClassKeysGeneric_1 extends HostClassKeysRequirementGeneric, CssVarKeysGeneric_1 extends CssVarKeysRequirementGeneric, RenderOutputGeneric_1 extends RenderOutputRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1, RenderOutputGeneric_1>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1, RenderOutputGeneric_1>;
7
+ export declare function wrapDefineElement<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = string, CssVarKeysRequirementGeneric extends string = string, RenderOutputRequirementGeneric = any, InputsDefinerFunctionRequirementGeneric extends ((input: any) => any) | undefined = undefined>(options?: WrapDefineElementOptions | undefined): {
8
+ defineElement: <InputsGeneric extends InputsRequirementGeneric>() => <TagNameGeneric extends TagNameRequirementGeneric, StateInitGeneric extends StateInitRequirementGeneric, EventsInitGeneric extends EventsInitRequirementGeneric, HostClassKeysGeneric extends HostClassKeysRequirementGeneric, CssVarKeysGeneric extends CssVarKeysRequirementGeneric, RenderOutputGeneric extends RenderOutputRequirementGeneric, InputsDefinerFunctionGeneric extends InputsDefinerFunctionRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric, InputsDefinerFunctionGeneric>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric, RenderOutputGeneric, undefined>;
9
+ defineElementNoInputs: <TagNameGeneric_1 extends TagNameRequirementGeneric, InputsGeneric_1 extends InputsRequirementGeneric, StateInitGeneric_1 extends StateInitRequirementGeneric, EventsInitGeneric_1 extends EventsInitRequirementGeneric, HostClassKeysGeneric_1 extends HostClassKeysRequirementGeneric, CssVarKeysGeneric_1 extends CssVarKeysRequirementGeneric, RenderOutputGeneric_1 extends RenderOutputRequirementGeneric, InputsDefinerFunctionGeneric_1 extends InputsDefinerFunctionRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1, RenderOutputGeneric_1, InputsDefinerFunctionGeneric_1>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1, RenderOutputGeneric_1, InputsDefinerFunctionGeneric_1>;
10
10
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './built-in-lit-directives';
2
+ export * from './built-in-lit-types';
2
3
  export * from './declarative-element/declarative-element';
3
4
  export * from './declarative-element/declarative-element-init';
4
5
  export * from './declarative-element/define-element';
@@ -21,6 +22,7 @@ export * from './declarative-element/properties/host-classes';
21
22
  export * from './declarative-element/properties/styles';
22
23
  export * from './declarative-element/properties/tag-name';
23
24
  export * from './declarative-element/render-callback';
25
+ export * from './declarative-element/utilities/template-string';
24
26
  export * from './declarative-element/wrap-define-element';
25
27
  export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
26
28
  export * from './template-transforms/vir-css/vir-css';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './built-in-lit-directives';
2
+ export * from './built-in-lit-types';
2
3
  export * from './declarative-element/declarative-element';
3
4
  export * from './declarative-element/declarative-element-init';
4
5
  export * from './declarative-element/define-element';
@@ -20,6 +21,7 @@ export * from './declarative-element/properties/host-classes';
20
21
  export * from './declarative-element/properties/styles';
21
22
  export * from './declarative-element/properties/tag-name';
22
23
  export * from './declarative-element/render-callback';
24
+ export * from './declarative-element/utilities/template-string';
23
25
  export * from './declarative-element/wrap-define-element';
24
26
  export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
25
27
  export * from './template-transforms/vir-css/vir-css';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "12.2.0",
3
+ "version": "12.3.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -73,8 +73,8 @@
73
73
  "ts-node": "^10.9.1",
74
74
  "type-fest": "^3.9.0",
75
75
  "typescript": "^5.0.4",
76
- "virmator": "^6.4.4",
77
- "vite": "^4.3.2",
76
+ "virmator": "^6.5.0",
77
+ "vite": "^4.3.3",
78
78
  "vite-tsconfig-paths": "^4.2.0"
79
79
  }
80
80
  }