element-vir 26.12.0 → 26.12.1

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 (189) hide show
  1. package/dist/declarative-element/custom-tag-name.js +1 -0
  2. package/dist/declarative-element/declarative-element-init.d.ts +56 -0
  3. package/dist/declarative-element/declarative-element-init.js +1 -0
  4. package/dist/declarative-element/declarative-element.d.ts +114 -0
  5. package/dist/declarative-element/declarative-element.js +36 -0
  6. package/dist/declarative-element/define-element.d.ts +41 -0
  7. package/dist/declarative-element/define-element.js +248 -0
  8. package/{src/declarative-element/definition-options.ts → dist/declarative-element/definition-options.d.ts} +2 -7
  9. package/dist/declarative-element/definition-options.js +9 -0
  10. package/dist/declarative-element/directives/assign.directive.d.ts +24 -0
  11. package/dist/declarative-element/directives/assign.directive.js +34 -0
  12. package/dist/declarative-element/directives/async-prop.d.ts +61 -0
  13. package/{src/declarative-element/directives/async-prop.ts → dist/declarative-element/directives/async-prop.js} +8 -42
  14. package/dist/declarative-element/directives/attributes.directive.d.ts +30 -0
  15. package/dist/declarative-element/directives/attributes.directive.js +35 -0
  16. package/dist/declarative-element/directives/create-attribute-directive.d.ts +28 -0
  17. package/dist/declarative-element/directives/create-attribute-directive.js +41 -0
  18. package/dist/declarative-element/directives/directive-helpers.d.ts +27 -0
  19. package/dist/declarative-element/directives/directive-helpers.js +37 -0
  20. package/dist/declarative-element/directives/listen-to-activate.d.ts +15 -0
  21. package/{src/declarative-element/directives/listen-to-activate.ts → dist/declarative-element/directives/listen-to-activate.js} +3 -8
  22. package/dist/declarative-element/directives/listen.directive.d.ts +92 -0
  23. package/dist/declarative-element/directives/listen.directive.js +48 -0
  24. package/dist/declarative-element/directives/mutate.directive.d.ts +38 -0
  25. package/dist/declarative-element/directives/mutate.directive.js +45 -0
  26. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +44 -0
  27. package/dist/declarative-element/directives/on-dom-created.directive.js +51 -0
  28. package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +41 -0
  29. package/dist/declarative-element/directives/on-dom-rendered.directive.js +45 -0
  30. package/dist/declarative-element/directives/on-intersect.directive.d.ts +64 -0
  31. package/dist/declarative-element/directives/on-intersect.directive.js +89 -0
  32. package/dist/declarative-element/directives/on-resize.directive.d.ts +74 -0
  33. package/dist/declarative-element/directives/on-resize.directive.js +106 -0
  34. package/dist/declarative-element/directives/render-async.directive.d.ts +45 -0
  35. package/dist/declarative-element/directives/render-async.directive.js +33 -0
  36. package/dist/declarative-element/directives/render-if.directive.d.ts +32 -0
  37. package/{src/declarative-element/directives/render-if.directive.ts → dist/declarative-element/directives/render-if.directive.js} +3 -12
  38. package/dist/declarative-element/directives/test-id.directive.d.ts +52 -0
  39. package/{src/declarative-element/directives/test-id.directive.ts → dist/declarative-element/directives/test-id.directive.js} +2 -7
  40. package/dist/declarative-element/has-declarative-element-parent.d.ts +1 -0
  41. package/{src/declarative-element/has-declarative-element-parent.ts → dist/declarative-element/has-declarative-element-parent.js} +4 -7
  42. package/dist/declarative-element/is-declarative-element-definition.d.ts +17 -0
  43. package/{src/declarative-element/is-declarative-element-definition.ts → dist/declarative-element/is-declarative-element-definition.js} +11 -28
  44. package/dist/declarative-element/is-declarative-element.d.ts +15 -0
  45. package/{src/declarative-element/is-declarative-element.ts → dist/declarative-element/is-declarative-element.js} +5 -11
  46. package/dist/declarative-element/properties/assign-inputs.d.ts +1 -0
  47. package/dist/declarative-element/properties/assign-inputs.js +25 -0
  48. package/dist/declarative-element/properties/css-vars.d.ts +16 -0
  49. package/dist/declarative-element/properties/css-vars.js +1 -0
  50. package/dist/declarative-element/properties/element-events.d.ts +65 -0
  51. package/dist/declarative-element/properties/element-events.js +62 -0
  52. package/dist/declarative-element/properties/element-properties.js +1 -0
  53. package/dist/declarative-element/properties/host-classes.d.ts +36 -0
  54. package/dist/declarative-element/properties/host-classes.js +16 -0
  55. package/dist/declarative-element/properties/property-proxy.d.ts +22 -0
  56. package/{src/declarative-element/properties/property-proxy.ts → dist/declarative-element/properties/property-proxy.js} +21 -58
  57. package/dist/declarative-element/properties/string-names.d.ts +28 -0
  58. package/dist/declarative-element/properties/string-names.js +40 -0
  59. package/dist/declarative-element/properties/styles.d.ts +51 -0
  60. package/dist/declarative-element/properties/styles.js +41 -0
  61. package/dist/declarative-element/properties/tag-name.js +1 -0
  62. package/dist/declarative-element/render-callback.d.ts +56 -0
  63. package/dist/declarative-element/render-callback.js +27 -0
  64. package/dist/declarative-element/wrap-define-element.d.ts +36 -0
  65. package/dist/declarative-element/wrap-define-element.js +25 -0
  66. package/{src/index.ts → dist/index.d.ts} +0 -1
  67. package/dist/index.js +43 -0
  68. package/dist/lit-exports/all-lit-exports.js +2 -0
  69. package/{src/lit-exports/base-lit-exports.ts → dist/lit-exports/base-lit-exports.d.ts} +2 -10
  70. package/dist/lit-exports/base-lit-exports.js +24 -0
  71. package/{src/lit-exports/lit-repeat-fix.ts → dist/lit-exports/lit-repeat-fix.d.ts} +16 -45
  72. package/dist/lit-exports/lit-repeat-fix.js +37 -0
  73. package/dist/readme-examples/my-app.element.d.ts +1 -0
  74. package/{src/readme-examples/my-app.element.ts → dist/readme-examples/my-app.element.js} +4 -5
  75. package/dist/readme-examples/my-custom-action.event.d.ts +1 -0
  76. package/dist/readme-examples/my-custom-action.event.js +2 -0
  77. package/dist/readme-examples/my-custom-define.d.ts +4 -0
  78. package/{src/readme-examples/my-custom-define.ts → dist/readme-examples/my-custom-define.js} +4 -9
  79. package/dist/readme-examples/my-simple.element.d.ts +1 -0
  80. package/{src/readme-examples/my-simple.element.ts → dist/readme-examples/my-simple.element.js} +3 -4
  81. package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
  82. package/dist/readme-examples/my-with-assignment.element.js +15 -0
  83. package/dist/readme-examples/my-with-async-prop.element.d.ts +10 -0
  84. package/{src/readme-examples/my-with-async-prop.element.ts → dist/readme-examples/my-with-async-prop.element.js} +16 -24
  85. package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
  86. package/{src/readme-examples/my-with-cleanup-callback.element.ts → dist/readme-examples/my-with-cleanup-callback.element.js} +4 -5
  87. package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
  88. package/{src/readme-examples/my-with-css-vars.element.ts → dist/readme-examples/my-with-css-vars.element.js} +4 -5
  89. package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
  90. package/dist/readme-examples/my-with-custom-events.element.js +22 -0
  91. package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
  92. package/{src/readme-examples/my-with-event-listening.element.ts → dist/readme-examples/my-with-event-listening.element.js} +9 -10
  93. package/dist/readme-examples/my-with-events.element.d.ts +4 -0
  94. package/dist/readme-examples/my-with-events.element.js +20 -0
  95. package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
  96. package/{src/readme-examples/my-with-host-class-definition.element.ts → dist/readme-examples/my-with-host-class-definition.element.js} +6 -7
  97. package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
  98. package/{src/readme-examples/my-with-host-class-usage.element.ts → dist/readme-examples/my-with-host-class-usage.element.js} +4 -5
  99. package/dist/readme-examples/my-with-inputs.element.d.ts +4 -0
  100. package/dist/readme-examples/my-with-inputs.element.js +9 -0
  101. package/dist/readme-examples/my-with-on-dom-created.element.d.ts +1 -0
  102. package/{src/readme-examples/my-with-on-dom-created.element.ts → dist/readme-examples/my-with-on-dom-created.element.js} +6 -7
  103. package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
  104. package/dist/readme-examples/my-with-on-resize.element.js +18 -0
  105. package/dist/readme-examples/my-with-render-if.element.d.ts +3 -0
  106. package/dist/readme-examples/my-with-render-if.element.js +11 -0
  107. package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +1 -0
  108. package/{src/readme-examples/my-with-styles-and-interpolated-selector.element.ts → dist/readme-examples/my-with-styles-and-interpolated-selector.element.js} +5 -6
  109. package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
  110. package/{src/readme-examples/my-with-styles.element.ts → dist/readme-examples/my-with-styles.element.js} +4 -5
  111. package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
  112. package/{src/readme-examples/my-with-update-state.element.ts → dist/readme-examples/my-with-update-state.element.js} +7 -8
  113. package/dist/readme-examples/require-declarative-element.d.ts +1 -0
  114. package/dist/readme-examples/require-declarative-element.js +2 -0
  115. package/dist/require-declarative-element.d.ts +14 -0
  116. package/{src/require-declarative-element.ts → dist/require-declarative-element.js} +0 -1
  117. package/{src/template-transforms/minimal-element-definition.ts → dist/template-transforms/minimal-element-definition.d.ts} +7 -19
  118. package/dist/template-transforms/minimal-element-definition.js +19 -0
  119. package/dist/template-transforms/nested-mapped-templates.d.ts +6 -0
  120. package/dist/template-transforms/nested-mapped-templates.js +96 -0
  121. package/{src/template-transforms/template-transform-type.ts → dist/template-transforms/template-transform-type.d.ts} +1 -3
  122. package/dist/template-transforms/template-transform-type.js +1 -0
  123. package/dist/template-transforms/transform-template.d.ts +14 -0
  124. package/{src/template-transforms/transform-template.ts → dist/template-transforms/transform-template.js} +22 -70
  125. package/dist/template-transforms/vir-css/css-transform.d.ts +4 -0
  126. package/dist/template-transforms/vir-css/css-transform.js +15 -0
  127. package/dist/template-transforms/vir-css/vir-css.d.ts +12 -0
  128. package/dist/template-transforms/vir-css/vir-css.js +21 -0
  129. package/dist/template-transforms/vir-html/html-interpolation.d.ts +42 -0
  130. package/dist/template-transforms/vir-html/html-interpolation.js +1 -0
  131. package/dist/template-transforms/vir-html/html-transform.d.ts +5 -0
  132. package/dist/template-transforms/vir-html/html-transform.js +96 -0
  133. package/dist/template-transforms/vir-html/tag-name-keys.d.ts +7 -0
  134. package/{src/template-transforms/vir-html/tag-name-keys.ts → dist/template-transforms/vir-html/tag-name-keys.js} +1 -1
  135. package/dist/template-transforms/vir-html/vir-html.d.ts +11 -0
  136. package/{src/template-transforms/vir-html/vir-html.ts → dist/template-transforms/vir-html/vir-html.js} +5 -13
  137. package/dist/typed-event/typed-event.d.ts +55 -0
  138. package/dist/typed-event/typed-event.js +50 -0
  139. package/dist/util/array.d.ts +5 -0
  140. package/{src/util/array.ts → dist/util/array.js} +5 -18
  141. package/{src/util/increment.ts → dist/util/increment.d.ts} +5 -24
  142. package/dist/util/increment.js +1 -0
  143. package/dist/util/lit-template.d.ts +9 -0
  144. package/{src/util/lit-template.ts → dist/util/lit-template.js} +10 -30
  145. package/dist/util/map-async-value.d.ts +7 -0
  146. package/{src/util/map-async-value.ts → dist/util/map-async-value.js} +10 -12
  147. package/dist/util/type.js +1 -0
  148. package/package.json +4 -4
  149. package/src/declarative-element/declarative-element-init.ts +0 -115
  150. package/src/declarative-element/declarative-element.ts +0 -372
  151. package/src/declarative-element/define-element.ts +0 -515
  152. package/src/declarative-element/directives/assign.directive.ts +0 -89
  153. package/src/declarative-element/directives/attributes.directive.ts +0 -63
  154. package/src/declarative-element/directives/create-attribute-directive.ts +0 -47
  155. package/src/declarative-element/directives/directive-helpers.ts +0 -67
  156. package/src/declarative-element/directives/listen.directive.ts +0 -206
  157. package/src/declarative-element/directives/mutate.directive.ts +0 -78
  158. package/src/declarative-element/directives/on-dom-created.directive.ts +0 -68
  159. package/src/declarative-element/directives/on-dom-rendered.directive.ts +0 -61
  160. package/src/declarative-element/directives/on-intersect.directive.ts +0 -139
  161. package/src/declarative-element/directives/on-resize.directive.ts +0 -142
  162. package/src/declarative-element/directives/render-async.directive.ts +0 -111
  163. package/src/declarative-element/properties/assign-inputs.ts +0 -30
  164. package/src/declarative-element/properties/css-vars.ts +0 -24
  165. package/src/declarative-element/properties/element-events.ts +0 -161
  166. package/src/declarative-element/properties/host-classes.ts +0 -63
  167. package/src/declarative-element/properties/string-names.ts +0 -83
  168. package/src/declarative-element/properties/styles.ts +0 -112
  169. package/src/declarative-element/render-callback.ts +0 -196
  170. package/src/declarative-element/wrap-define-element.ts +0 -127
  171. package/src/readme-examples/my-custom-action.event.ts +0 -3
  172. package/src/readme-examples/my-with-assignment.element.ts +0 -16
  173. package/src/readme-examples/my-with-custom-events.element.ts +0 -23
  174. package/src/readme-examples/my-with-events.element.ts +0 -23
  175. package/src/readme-examples/my-with-inputs.element.ts +0 -13
  176. package/src/readme-examples/my-with-on-resize.element.ts +0 -19
  177. package/src/readme-examples/my-with-render-if.element.ts +0 -15
  178. package/src/readme-examples/require-declarative-element.ts +0 -3
  179. package/src/template-transforms/nested-mapped-templates.ts +0 -157
  180. package/src/template-transforms/vir-css/css-transform.ts +0 -30
  181. package/src/template-transforms/vir-css/vir-css.ts +0 -30
  182. package/src/template-transforms/vir-html/html-interpolation.ts +0 -103
  183. package/src/template-transforms/vir-html/html-transform.ts +0 -149
  184. package/src/typed-event/typed-event.ts +0 -90
  185. /package/{src/declarative-element/custom-tag-name.ts → dist/declarative-element/custom-tag-name.d.ts} +0 -0
  186. /package/{src/declarative-element/properties/element-properties.ts → dist/declarative-element/properties/element-properties.d.ts} +0 -0
  187. /package/{src/declarative-element/properties/tag-name.ts → dist/declarative-element/properties/tag-name.d.ts} +0 -0
  188. /package/{src/lit-exports/all-lit-exports.ts → dist/lit-exports/all-lit-exports.d.ts} +0 -0
  189. /package/{src/util/type.ts → dist/util/type.d.ts} +0 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Assigns the given id as a test id attribute to the attached element.
3
+ *
4
+ * @category Test
5
+ * @example
6
+ *
7
+ * ```ts
8
+ * import {html, defineElement, testId} from 'element-vir';
9
+ *
10
+ * const MyElement = defineElement()({
11
+ * tagName: 'my-element',
12
+ * render() {
13
+ * return html`
14
+ * <div ${testId('my-test')}>Some div</div>
15
+ * `;
16
+ * },
17
+ * });
18
+ * ```
19
+ */
20
+ export declare const testId: (this: void, attributeValue: string) => import("lit-html/directive.js").DirectiveResult<{
21
+ new (partInfo: import("lit-html/directive.js").PartInfo): {
22
+ readonly element: Element;
23
+ render(attributeValue: string): symbol;
24
+ get _$isConnected(): boolean;
25
+ update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
26
+ };
27
+ }>;
28
+ /**
29
+ * Construct an attribute selector for the given test id.
30
+ *
31
+ * @category Test
32
+ * @example
33
+ *
34
+ * ```ts
35
+ * import {html, selectTestId} from 'element-vir';
36
+ * import {testWeb} from '@augment-vir/test';
37
+ * import {assert} from '@augment-vir/assert';
38
+ *
39
+ * const instance = testWeb.render(html`
40
+ * <${MyElement}></${MyElement}>
41
+ * `);
42
+ * assert.instanceOf(instance, MyElement);
43
+ * instance.shadowRoot.querySelector(selectTestId('my-test'));
44
+ * ```
45
+ */
46
+ export declare const testIdSelector: (this: void, attributeValue: string) => string;
47
+ /**
48
+ * The test id attribute name.
49
+ *
50
+ * @category Test
51
+ */
52
+ export declare const testIdAttributeName: string;
@@ -1,8 +1,5 @@
1
- import {createAttributeDirective} from './create-attribute-directive.js';
2
-
3
- const {attributeDirective, attributeSelector, attributeName} =
4
- createAttributeDirective('data-test-id');
5
-
1
+ import { createAttributeDirective } from './create-attribute-directive.js';
2
+ const { attributeDirective, attributeSelector, attributeName } = createAttributeDirective('data-test-id');
6
3
  /**
7
4
  * Assigns the given id as a test id attribute to the attached element.
8
5
  *
@@ -23,7 +20,6 @@ const {attributeDirective, attributeSelector, attributeName} =
23
20
  * ```
24
21
  */
25
22
  export const testId = attributeDirective;
26
-
27
23
  /**
28
24
  * Construct an attribute selector for the given test id.
29
25
  *
@@ -43,7 +39,6 @@ export const testId = attributeDirective;
43
39
  * ```
44
40
  */
45
41
  export const testIdSelector = attributeSelector;
46
-
47
42
  /**
48
43
  * The test id attribute name.
49
44
  *
@@ -0,0 +1 @@
1
+ export declare function hasDeclarativeElementParent(input: Element): boolean;
@@ -1,19 +1,16 @@
1
- import {DeclarativeElement} from './declarative-element.js';
2
-
3
- export function hasDeclarativeElementParent(input: Element): boolean {
1
+ import { DeclarativeElement } from './declarative-element.js';
2
+ export function hasDeclarativeElementParent(input) {
4
3
  const rootNode = input.getRootNode();
5
-
6
4
  if (!(rootNode instanceof ShadowRoot)) {
7
5
  // declarative elements all use shadow DOM, so if a shadow root doesn't exist then we're not
8
6
  // in a declarative element.
9
7
  return false;
10
8
  }
11
-
12
9
  const host = rootNode.host;
13
-
14
10
  if (host instanceof DeclarativeElement) {
15
11
  return true;
16
- } else {
12
+ }
13
+ else {
17
14
  return hasDeclarativeElementParent(host);
18
15
  }
19
16
  }
@@ -0,0 +1,17 @@
1
+ import { type DeclarativeElementDefinition } from './declarative-element.js';
2
+ /**
3
+ * Asserts that the given input is a declarative element definition.
4
+ *
5
+ * @category Util
6
+ * @see
7
+ * - {@link isDeclarativeElementDefinition}
8
+ */
9
+ export declare function assertDeclarativeElementDefinition(input: unknown, failMessage?: string | undefined): asserts input is DeclarativeElementDefinition;
10
+ /**
11
+ * Checks that the given input is a declarative element definition.
12
+ *
13
+ * @category Util
14
+ * @see
15
+ * - {@link assertDeclarativeElementDefinition}
16
+ */
17
+ export declare function isDeclarativeElementDefinition(input: unknown): input is DeclarativeElementDefinition;
@@ -1,10 +1,5 @@
1
- import {AssertionError, check} from '@augment-vir/assert';
2
- import {getObjectTypedKeys, wrapInTry} from '@augment-vir/common';
3
- import {
4
- type DeclarativeElementDefinition,
5
- type StaticDeclarativeElementProperties,
6
- } from './declarative-element.js';
7
-
1
+ import { AssertionError, check } from '@augment-vir/assert';
2
+ import { getObjectTypedKeys, wrapInTry } from '@augment-vir/common';
8
3
  const expectedStaticProperties = getObjectTypedKeys({
9
4
  assign: '',
10
5
  assignedInputs: '',
@@ -21,10 +16,7 @@ const expectedStaticProperties = getObjectTypedKeys({
21
16
  styles: '',
22
17
  tagName: '',
23
18
  UpdateStateType: '',
24
- } satisfies Readonly<
25
- Record<keyof StaticDeclarativeElementProperties<any, any, any, any, any, any, any, any>, ''>
26
- >);
27
-
19
+ });
28
20
  /**
29
21
  * Asserts that the given input is a declarative element definition.
30
22
  *
@@ -32,10 +24,7 @@ const expectedStaticProperties = getObjectTypedKeys({
32
24
  * @see
33
25
  * - {@link isDeclarativeElementDefinition}
34
26
  */
35
- export function assertDeclarativeElementDefinition(
36
- input: unknown,
37
- failMessage?: string | undefined,
38
- ): asserts input is DeclarativeElementDefinition {
27
+ export function assertDeclarativeElementDefinition(input, failMessage) {
39
28
  if (!check.isFunction(input)) {
40
29
  throw new AssertionError('Input is not a declarative element constructor', failMessage);
41
30
  }
@@ -45,7 +34,6 @@ export function assertDeclarativeElementDefinition(
45
34
  }
46
35
  });
47
36
  }
48
-
49
37
  /**
50
38
  * Checks that the given input is a declarative element definition.
51
39
  *
@@ -53,16 +41,11 @@ export function assertDeclarativeElementDefinition(
53
41
  * @see
54
42
  * - {@link assertDeclarativeElementDefinition}
55
43
  */
56
- export function isDeclarativeElementDefinition(
57
- input: unknown,
58
- ): input is DeclarativeElementDefinition {
59
- return wrapInTry(
60
- () => {
61
- assertDeclarativeElementDefinition(input);
62
- return true;
63
- },
64
- {
65
- fallbackValue: false,
66
- },
67
- );
44
+ export function isDeclarativeElementDefinition(input) {
45
+ return wrapInTry(() => {
46
+ assertDeclarativeElementDefinition(input);
47
+ return true;
48
+ }, {
49
+ fallbackValue: false,
50
+ });
68
51
  }
@@ -0,0 +1,15 @@
1
+ import { type DeclarativeElement } from './declarative-element.js';
2
+ /**
3
+ * Checks if the input is an instance of a DeclarativeElement, the super class of all custom
4
+ * elements defined with element-vir.
5
+ *
6
+ * @category Util
7
+ */
8
+ export declare function isDeclarativeElement(input: unknown): input is DeclarativeElement;
9
+ /**
10
+ * Checks if the input is an instance of a DeclarativeElement, the super class of all custom
11
+ * elements defined with element-vir.
12
+ *
13
+ * @category Util
14
+ */
15
+ export declare function assertIsDeclarativeElement(input: unknown): asserts input is DeclarativeElement;
@@ -1,14 +1,12 @@
1
- import {check} from '@augment-vir/assert';
2
- import {type DeclarativeElement} from './declarative-element.js';
3
-
1
+ import { check } from '@augment-vir/assert';
4
2
  /**
5
3
  * Checks if the input is an instance of a DeclarativeElement, the super class of all custom
6
4
  * elements defined with element-vir.
7
5
  *
8
6
  * @category Util
9
7
  */
10
- export function isDeclarativeElement(input: unknown): input is DeclarativeElement {
11
- const markerProperties: ReadonlyArray<keyof DeclarativeElement> = [
8
+ export function isDeclarativeElement(input) {
9
+ const markerProperties = [
12
10
  'instanceInputs',
13
11
  'instanceState',
14
12
  'definition',
@@ -21,13 +19,9 @@ export function isDeclarativeElement(input: unknown): input is DeclarativeElemen
21
19
  *
22
20
  * @category Util
23
21
  */
24
- export function assertIsDeclarativeElement(input: unknown): asserts input is DeclarativeElement {
22
+ export function assertIsDeclarativeElement(input) {
25
23
  if (!isDeclarativeElement(input)) {
26
24
  console.error('this is not a declarative element:', input);
27
- throw new Error(
28
- `${String(
29
- check.hasKey(input, 'tagName') ? input.tagName : input,
30
- )} is not a declarative element.`,
31
- );
25
+ throw new Error(`${String(check.hasKey(input, 'tagName') ? input.tagName : input)} is not a declarative element.`);
32
26
  }
33
27
  }
@@ -0,0 +1 @@
1
+ export declare function assignInputs(element: Element, inputs: object): void;
@@ -0,0 +1,25 @@
1
+ import { getObjectTypedKeys } from '@augment-vir/common';
2
+ export function assignInputs(element, inputs) {
3
+ const instanceState = element.instanceState;
4
+ getObjectTypedKeys(inputs).forEach((newInputKey) => {
5
+ if (instanceState && newInputKey in instanceState) {
6
+ throw new Error(`Cannot set input '${String(newInputKey)}' on '${element.tagName}'. '${element.tagName}' already has a state property with the same name.`);
7
+ }
8
+ if ('instanceInputs' in element) {
9
+ element.instanceInputs[newInputKey] =
10
+ inputs[newInputKey];
11
+ }
12
+ else {
13
+ element[newInputKey] = inputs[newInputKey];
14
+ }
15
+ });
16
+ /** Wipe out all inputs that weren't set to undefined (as expected) */
17
+ if ('instanceInputs' in element) {
18
+ getObjectTypedKeys(element.instanceInputs).forEach((existingKey) => {
19
+ if (!(existingKey in inputs)) {
20
+ element.instanceInputs[existingKey] =
21
+ undefined;
22
+ }
23
+ });
24
+ }
25
+ }
@@ -0,0 +1,16 @@
1
+ import { type Values } from '@augment-vir/common';
2
+ import { type CssVarDefinitions, type CssVarsSetup } from 'lit-css-vars';
3
+ import { type CustomElementTagName } from '../custom-tag-name.js';
4
+ import { type BaseStringName } from './string-names.js';
5
+ /**
6
+ * Base type for a declarative element definition's CSS vars.
7
+ *
8
+ * @category Internal
9
+ */
10
+ export type CssVarsInitMap<ElementTagName extends CustomElementTagName, CssVarKeys extends BaseStringName<ElementTagName>> = Readonly<Record<CssVarKeys, Values<CssVarsSetup>>>;
11
+ /**
12
+ * CSS vars ready for use within a declarative element's `render` or `styles` method.
13
+ *
14
+ * @category Internal
15
+ */
16
+ export type CssVars<ElementTagName extends CustomElementTagName, CssVarKeys extends BaseStringName<ElementTagName>> = CssVarDefinitions<CssVarsInitMap<ElementTagName, CssVarKeys>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import { type DefinedTypedEvent, type DefineEvent, type TypedEvent } from '../../typed-event/typed-event.js';
2
+ import { type CustomElementTagName } from '../custom-tag-name.js';
3
+ /**
4
+ * Base type for defining element events inside of an element definition.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export type EventsInitMap = Record<string, DefineEvent<any>>;
9
+ /**
10
+ * Used to define element events, with a type.
11
+ *
12
+ * @category Element Definition
13
+ * @example
14
+ *
15
+ * ```ts
16
+ * import {html, defineElement, defineElementEvent, listen} from 'element-vir';
17
+ *
18
+ * const MyElement = defineElement()({
19
+ * tagName: 'my-element',
20
+ * events: {
21
+ * myOutput: defineElementEvent<number>(),
22
+ * },
23
+ * render({events, dispatch}) {
24
+ * return html`
25
+ * <div
26
+ * ${listen('click', () => {
27
+ * dispatch(new events.myOutput(1));
28
+ * })}
29
+ * >
30
+ * Some div
31
+ * </div>
32
+ * `;
33
+ * },
34
+ * });
35
+ * ```
36
+ */
37
+ export declare function defineElementEvent<EventDetailGeneric>(): DefineEvent<EventDetailGeneric>;
38
+ /**
39
+ * Extracts the detail type of the given event name from the given event init map.
40
+ *
41
+ * @category Internal
42
+ */
43
+ export type EventInitMapEventDetailExtractor<EventTypeNameGeneric extends keyof EventsInitGeneric, EventsInitGeneric extends EventsInitMap> = EventsInitGeneric[EventTypeNameGeneric] extends DefineEvent<infer Detail> ? Detail : never;
44
+ /**
45
+ * Maps the given element tag name and map of event names to their run-time event type strings.
46
+ *
47
+ * @category Internal
48
+ */
49
+ export type EventDescriptorMap<TagName extends CustomElementTagName, EventsInitGeneric extends EventsInitMap> = {
50
+ [CurrentEventTypeName in keyof EventsInitGeneric]: DefinedTypedEvent<CurrentEventTypeName extends string ? `${TagName}-${CurrentEventTypeName}` : never, EventInitMapEventDetailExtractor<CurrentEventTypeName, EventsInitGeneric>>;
51
+ };
52
+ /**
53
+ * Extract the event detail type from a {@link TypedEvent}, {@link DefinedTypedEvent}, or
54
+ * `CustomEvent.
55
+ *
56
+ * @category Internal
57
+ */
58
+ export type EventDetail<ElementEvent extends TypedEvent<any, any> | DefinedTypedEvent<any, any> | CustomEvent> = ElementEvent extends TypedEvent<string, infer Detail> ? Detail : ElementEvent extends DefinedTypedEvent<any, infer Detail> ? Detail : ElementEvent extends CustomEvent<infer Detail> ? Detail : 'TYPE ERROR: failed to extract event detail type';
59
+ /**
60
+ * Maps an element definition initialization's tag name and event map to a map of ready-to-construct
61
+ * event classes. This also verifies that the input event init map has valid keys.
62
+ *
63
+ * @category Internal
64
+ */
65
+ export declare function createEventDescriptorMap<TagName extends CustomElementTagName, EventsInitGeneric extends EventsInitMap>(tagName: CustomElementTagName, eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<TagName, EventsInitGeneric>;
@@ -0,0 +1,62 @@
1
+ import { defineTypedEvent, } from '../../typed-event/typed-event.js';
2
+ /**
3
+ * Used to define element events, with a type.
4
+ *
5
+ * @category Element Definition
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {html, defineElement, defineElementEvent, listen} from 'element-vir';
10
+ *
11
+ * const MyElement = defineElement()({
12
+ * tagName: 'my-element',
13
+ * events: {
14
+ * myOutput: defineElementEvent<number>(),
15
+ * },
16
+ * render({events, dispatch}) {
17
+ * return html`
18
+ * <div
19
+ * ${listen('click', () => {
20
+ * dispatch(new events.myOutput(1));
21
+ * })}
22
+ * >
23
+ * Some div
24
+ * </div>
25
+ * `;
26
+ * },
27
+ * });
28
+ * ```
29
+ */
30
+ export function defineElementEvent() {
31
+ return defineTypedEvent();
32
+ }
33
+ /**
34
+ * Maps an element definition initialization's tag name and event map to a map of ready-to-construct
35
+ * event classes. This also verifies that the input event init map has valid keys.
36
+ *
37
+ * @category Internal
38
+ */
39
+ export function createEventDescriptorMap(tagName, eventsInit) {
40
+ if (!eventsInit) {
41
+ return {};
42
+ }
43
+ return (Object.keys(eventsInit)
44
+ /** Verify event keys. */
45
+ .filter((currentElementEventKey) => {
46
+ if (typeof currentElementEventKey !== 'string') {
47
+ throw new TypeError(`Expected event key of type string but got type '${typeof currentElementEventKey}' for key ${String(currentElementEventKey)}`);
48
+ }
49
+ else if (currentElementEventKey === '') {
50
+ throw new Error(`Got empty string for events key.`);
51
+ }
52
+ return true;
53
+ })
54
+ .reduce((accum, currentElementEventKey) => {
55
+ const eventObject = defineTypedEvent()([
56
+ tagName,
57
+ currentElementEventKey,
58
+ ].join('-'));
59
+ accum[currentElementEventKey] = eventObject;
60
+ return accum;
61
+ }, {}));
62
+ }
@@ -0,0 +1,36 @@
1
+ import { type CustomElementTagName } from '../custom-tag-name.js';
2
+ import { type PropertyInitMapBase } from './element-properties.js';
3
+ import { type BaseStringName } from './string-names.js';
4
+ import { type WithTagName } from './tag-name.js';
5
+ /**
6
+ * Base init map for defining host classes in an element definition.
7
+ *
8
+ * @category Internal
9
+ */
10
+ export type HostClassesInitMap<TagName extends CustomElementTagName, HostClassKeys extends BaseStringName<TagName>, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase> = Record<HostClassKeys,
11
+ /**
12
+ * Callback to determine when host class should be enabled (based on current inputs and state),
13
+ * or just undefined to mark that this host class name will only be manually applied.
14
+ */
15
+ ((inputs: {
16
+ state: Readonly<State>;
17
+ inputs: Readonly<Inputs>;
18
+ }) => boolean) | false>;
19
+ /**
20
+ * Creates a mapping of host class keys (as defined in an element definition) to their runtime host
21
+ * class names.
22
+ *
23
+ * @category Internal
24
+ */
25
+ export type HostClassNamesMap<TagName extends string, HostClassKeys extends string> = Record<HostClassKeys, WithTagName<TagName, string>>;
26
+ /**
27
+ * Maps element definition host class definitions to their runtime host class name equivalents.
28
+ *
29
+ * @category Internal
30
+ */
31
+ export declare function createHostClassNamesMap<TagName extends CustomElementTagName, HostClassKeys extends BaseStringName<TagName>, HostClassesInit extends HostClassesInitMap<TagName, HostClassKeys,
32
+ /**
33
+ * We can use any here because we don't care what the state or input names are, we just care
34
+ * what the host class names are
35
+ */
36
+ any, any>>(hostClassesInit?: HostClassesInit): HostClassNamesMap<TagName, HostClassKeys>;
@@ -0,0 +1,16 @@
1
+ import { mapObjectValues } from '@augment-vir/common';
2
+ /**
3
+ * Maps element definition host class definitions to their runtime host class name equivalents.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export function createHostClassNamesMap(hostClassesInit) {
8
+ if (hostClassesInit) {
9
+ return mapObjectValues(hostClassesInit, (key) => {
10
+ return key;
11
+ });
12
+ }
13
+ else {
14
+ return {};
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ import { type ObservableListener } from 'observavir';
2
+ import { type DeclarativeElement } from '../declarative-element.js';
3
+ import { type PropertyInitMapBase } from './element-properties.js';
4
+ /**
5
+ * Used for a map of all observables registered to an element instance.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export type ObservableListenerMap<OriginalPropertyMap extends PropertyInitMapBase> = Partial<Record<keyof OriginalPropertyMap, ObservableListener<any> | undefined>>;
10
+ /**
11
+ * Binds the given property key as a reactive property on the given element.
12
+ *
13
+ * @category Internal
14
+ */
15
+ export declare function bindReactiveProperty(element: HTMLElement, propertyKey: PropertyKey): void;
16
+ /**
17
+ * Creates an internal proxy for setting inputs and state properties and then updating them on the
18
+ * element itself so they will trigger lit's change detection.
19
+ *
20
+ * @category Internal
21
+ */
22
+ export declare function createElementPropertyProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, shouldAlreadyExist: boolean): PropertyInitGeneric;
@@ -1,85 +1,54 @@
1
- import {type ObservableListener, isObservableBase} from 'observavir';
2
- import {property} from '../../lit-exports/base-lit-exports.js';
3
- import {type DeclarativeElement} from '../declarative-element.js';
4
- import {type PropertyInitMapBase} from './element-properties.js';
5
-
6
- /**
7
- * Used for a map of all observables registered to an element instance.
8
- *
9
- * @category Internal
10
- */
11
- export type ObservableListenerMap<OriginalPropertyMap extends PropertyInitMapBase> = Partial<
12
- Record<keyof OriginalPropertyMap, ObservableListener<any> | undefined>
13
- >;
14
-
1
+ import { isObservableBase } from 'observavir';
2
+ import { property } from '../../lit-exports/base-lit-exports.js';
15
3
  /**
16
4
  * Binds the given property key as a reactive property on the given element.
17
5
  *
18
6
  * @category Internal
19
7
  */
20
- export function bindReactiveProperty(element: HTMLElement, propertyKey: PropertyKey) {
8
+ export function bindReactiveProperty(element, propertyKey) {
21
9
  if (!(propertyKey in element)) {
22
10
  property()(element, propertyKey);
23
11
  }
24
12
  }
25
-
26
- function assertValidPropertyName<PropertyInitGeneric extends PropertyInitMapBase>(
27
- propKey: any,
28
- element: DeclarativeElement,
29
- elementTagName: string,
30
- ): asserts propKey is keyof PropertyInitGeneric {
13
+ function assertValidPropertyName(propKey, element, elementTagName) {
31
14
  if (typeof propKey !== 'string' && typeof propKey !== 'number' && typeof propKey !== 'symbol') {
32
- throw new TypeError(
33
- `Property name must be a string, got type '${typeof propKey}' from: '${String(
34
- propKey,
35
- )}' for '${elementTagName.toLowerCase()}'`,
36
- );
15
+ throw new TypeError(`Property name must be a string, got type '${typeof propKey}' from: '${String(propKey)}' for '${elementTagName.toLowerCase()}'`);
37
16
  }
38
17
  if (!(propKey in element)) {
39
- throw new Error(
40
- `Property '${String(propKey)}' does not exist on '${elementTagName.toLowerCase()}'.`,
41
- );
18
+ throw new Error(`Property '${String(propKey)}' does not exist on '${elementTagName.toLowerCase()}'.`);
42
19
  }
43
20
  }
44
-
45
21
  /**
46
22
  * Creates an internal proxy for setting inputs and state properties and then updating them on the
47
23
  * element itself so they will trigger lit's change detection.
48
24
  *
49
25
  * @category Internal
50
26
  */
51
- export function createElementPropertyProxy<PropertyInitGeneric extends PropertyInitMapBase>(
52
- element: DeclarativeElement,
53
- shouldAlreadyExist: boolean,
54
- ): PropertyInitGeneric {
27
+ export function createElementPropertyProxy(element, shouldAlreadyExist) {
55
28
  /**
56
29
  * Lit element updates state and inputs by setting them directly on the element, so we must do
57
30
  * that here. DeclarativeElement's types, however, do not expose this behavior, so we add that
58
31
  * back in here.
59
32
  */
60
- const elementAsProps = element as DeclarativeElement & PropertyInitGeneric;
61
-
62
- function verifyProperty(propertyKey: PropertyKey) {
33
+ const elementAsProps = element;
34
+ function verifyProperty(propertyKey) {
63
35
  if (shouldAlreadyExist) {
64
36
  assertValidPropertyName(propertyKey, element, element.tagName);
65
- } else {
37
+ }
38
+ else {
66
39
  bindReactiveProperty(element, propertyKey);
67
40
  }
68
41
  }
69
-
70
- function valueGetter(target: any, propertyKey: keyof PropertyInitGeneric | symbol) {
42
+ function valueGetter(target, propertyKey) {
71
43
  verifyProperty(propertyKey);
72
-
73
44
  return elementAsProps[propertyKey];
74
45
  }
75
-
76
- const propsProxy = new Proxy({} as Record<PropertyKey, unknown>, {
46
+ const propsProxy = new Proxy({}, {
77
47
  get: valueGetter,
78
- set(target, propertyKey: keyof PropertyInitGeneric | symbol, newValue) {
48
+ set(target, propertyKey, newValue) {
79
49
  verifyProperty(propertyKey);
80
50
  const oldValue = elementAsProps[propertyKey];
81
-
82
- function setValueOnElement(value: typeof newValue) {
51
+ function setValueOnElement(value) {
83
52
  /**
84
53
  * We need to at least set the property on target so we can detect it in "ownKeys"
85
54
  * and "getOwnPropertyDescriptor". We don't need duplicates of the values stored in
@@ -88,33 +57,29 @@ export function createElementPropertyProxy<PropertyInitGeneric extends PropertyI
88
57
  target[propertyKey] = value;
89
58
  elementAsProps[propertyKey] = value;
90
59
  }
91
-
92
- const existingPropertyListener: ObservableListener<any> | undefined =
93
- element.observablePropertyListenerMap[propertyKey];
94
-
60
+ const existingPropertyListener = element.observablePropertyListenerMap[propertyKey];
95
61
  if (oldValue !== newValue && isObservableBase(oldValue) && existingPropertyListener) {
96
62
  /** Stop listening to the old value now that we have a new value */
97
63
  oldValue.removeListener(existingPropertyListener);
98
64
  }
99
-
100
65
  if (isObservableBase(newValue)) {
101
66
  /** If we're using an existing observable property */
102
67
  if (existingPropertyListener) {
103
68
  newValue.listen(false, existingPropertyListener);
104
- } else {
69
+ }
70
+ else {
105
71
  function newListener() {
106
72
  element.requestUpdate();
107
73
  }
108
74
  element.observablePropertyListenerMap[propertyKey] = newListener;
109
75
  newValue.listen(false, newListener);
110
76
  }
111
- } else if (isObservableBase(oldValue)) {
77
+ }
78
+ else if (isObservableBase(oldValue)) {
112
79
  /** Clear out old listener that is no longer used. */
113
80
  element.observablePropertyListenerMap[propertyKey] = undefined;
114
81
  }
115
-
116
82
  setValueOnElement(newValue);
117
-
118
83
  return true;
119
84
  },
120
85
  ownKeys(target) {
@@ -130,13 +95,11 @@ export function createElementPropertyProxy<PropertyInitGeneric extends PropertyI
130
95
  enumerable: true,
131
96
  };
132
97
  }
133
-
134
98
  return undefined;
135
99
  },
136
100
  has(target, propertyName) {
137
101
  return Reflect.has(target, propertyName);
138
102
  },
139
103
  });
140
-
141
- return propsProxy as PropertyInitGeneric;
104
+ return propsProxy;
142
105
  }