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,50 @@
1
+ /**
2
+ * A custom event with strict types for details and the event's `type` property.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export class TypedEvent extends CustomEvent {
7
+ _type = '';
8
+ get type() {
9
+ return this._type;
10
+ }
11
+ constructor(type, value) {
12
+ super(typeof type === 'string' ? type : type.type, {
13
+ detail: value,
14
+ bubbles: true,
15
+ composed: true,
16
+ });
17
+ }
18
+ }
19
+ /**
20
+ * Define a stand-alone typed event that can be emitted and listened to inside of HTML templates.
21
+ *
22
+ * Make sure to use currying and call this function twice! (This is required by TypeScript's type
23
+ * parameter inference system.)
24
+ *
25
+ * @category Element Definition
26
+ * @example
27
+ *
28
+ * ```ts
29
+ * import {defineTypedEvent} from 'element-vir';
30
+ *
31
+ * const myCustomEvent = defineTypedEvent<number>()('my-custom-event');
32
+ *
33
+ * const myCustomEvent2 = defineTypedEvent<// the event's `.detail` type
34
+ * number>()(
35
+ * // the event's `.type` string
36
+ * 'my-custom-event2',
37
+ * );
38
+ * ```
39
+ */
40
+ export function defineTypedEvent() {
41
+ return (eventType) => {
42
+ return class extends TypedEvent {
43
+ static type = eventType;
44
+ _type = eventType;
45
+ constructor(value) {
46
+ super(eventType, value);
47
+ }
48
+ };
49
+ };
50
+ }
@@ -0,0 +1,5 @@
1
+ export type ArrayInsertion<T> = {
2
+ index: number;
3
+ values: ReadonlyArray<T>;
4
+ };
5
+ export declare function insertAndRemoveValues<Entry>(originalArray: ReadonlyArray<Entry>, valuesToInsert: ReadonlyArray<ArrayInsertion<Entry>>, indexesToRemove: ReadonlyArray<number>): Entry[];
@@ -1,34 +1,23 @@
1
- export type ArrayInsertion<T> = {index: number; values: ReadonlyArray<T>};
2
-
3
- export function insertAndRemoveValues<Entry>(
4
- originalArray: ReadonlyArray<Entry>,
5
- valuesToInsert: ReadonlyArray<ArrayInsertion<Entry>>,
6
- indexesToRemove: ReadonlyArray<number>,
7
- ): Entry[] {
8
- const noOperations: boolean = !valuesToInsert.length && !indexesToRemove.length;
9
- const nothingToDoBecauseEmptyArray: boolean = originalArray.length
1
+ export function insertAndRemoveValues(originalArray, valuesToInsert, indexesToRemove) {
2
+ const noOperations = !valuesToInsert.length && !indexesToRemove.length;
3
+ const nothingToDoBecauseEmptyArray = originalArray.length
10
4
  ? false
11
5
  : !valuesToInsert.filter((value) => !!value.index).length;
12
-
13
6
  if (noOperations || nothingToDoBecauseEmptyArray) {
14
7
  // there's nothing to do
15
8
  return [...originalArray];
16
9
  }
17
-
18
- const arrayValues: Entry[][] = originalArray.map((entry) => {
10
+ const arrayValues = originalArray.map((entry) => {
19
11
  return [entry];
20
12
  });
21
-
22
13
  if (!arrayValues.length) {
23
14
  arrayValues[0] = [];
24
15
  }
25
-
26
16
  indexesToRemove.forEach((index) => {
27
17
  if (index >= 0 && index < originalArray.length) {
28
18
  arrayValues[index] = [];
29
19
  }
30
20
  });
31
-
32
21
  valuesToInsert.forEach((valueWrapper) => {
33
22
  const indexEntry = arrayValues[valueWrapper.index];
34
23
  if (indexEntry) {
@@ -36,8 +25,6 @@ export function insertAndRemoveValues<Entry>(
36
25
  indexEntry.splice(0, 0, ...valueWrapper.values);
37
26
  }
38
27
  });
39
-
40
- const finalArray: Entry[] = arrayValues.flat();
41
-
28
+ const finalArray = arrayValues.flat();
42
29
  return finalArray;
43
30
  }
@@ -1,6 +1,5 @@
1
- import {type ArrayElement} from '@augment-vir/common';
2
- import {type IsNever} from 'type-fest';
3
-
1
+ import { type ArrayElement } from '@augment-vir/common';
2
+ import { type IsNever } from 'type-fest';
4
3
  /**
5
4
  * The largest number in this tuple is the largest number of nestings of the same element that
6
5
  * `element-vir` will support with types (in runtime it'll support any level of nesting the same
@@ -39,36 +38,18 @@ export type Incrementable = [
39
38
  27,
40
39
  28,
41
40
  29,
42
- 30,
41
+ 30
43
42
  ];
44
-
45
43
  /**
46
44
  * Increments the given number. If an invalid type parameter is given, it is treated as `0` and this
47
45
  * will output `1`. If the upper bound of increments has been reached, this will output `never`.
48
46
  *
49
47
  * @category Internal
50
48
  */
51
- export type Increment<T> =
52
- IsNever<Extract<ArrayElement<Incrementable>, T>> extends true
53
- ? IsNever<T> extends true
54
- ? 1
55
- : never
56
- : Incrementable extends [any, ...infer Rest]
57
- ? T extends keyof Rest
58
- ? Rest[T] extends undefined
59
- ? never
60
- : Rest[T]
61
- : 1
62
- : 1;
63
-
49
+ export type Increment<T> = IsNever<Extract<ArrayElement<Incrementable>, T>> extends true ? IsNever<T> extends true ? 1 : never : Incrementable extends [any, ...infer Rest] ? T extends keyof Rest ? Rest[T] extends undefined ? never : Rest[T] : 1 : 1;
64
50
  /**
65
51
  * Decrements the given number. If an invalid type parameter is given, `never` is the output.
66
52
  *
67
53
  * @category Internal
68
54
  */
69
- export type Decrement<T> =
70
- IsNever<Extract<ArrayElement<Incrementable>, T>> extends true
71
- ? never
72
- : T extends keyof Incrementable
73
- ? [never, ...Incrementable][T]
74
- : never;
55
+ export type Decrement<T> = IsNever<Extract<ArrayElement<Incrementable>, T>> extends true ? never : T extends keyof Incrementable ? [never, ...Incrementable][T] : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { type TemplateResult, type unsafeHTML, type unsafeSVG } from '../lit-exports/all-lit-exports.js';
2
+ /**
3
+ * Converts an HTML or SVG template into a raw string.
4
+ *
5
+ * @category Util
6
+ */
7
+ export declare function convertTemplateToString(template: TemplateResult | ReturnType<typeof unsafeSVG> | ReturnType<typeof unsafeHTML> | {
8
+ templateString: string;
9
+ }): string;
@@ -1,62 +1,42 @@
1
- import {collapseWhiteSpace} from '@augment-vir/common';
2
- import {
3
- type TemplateResult,
4
- type unsafeHTML,
5
- type unsafeSVG,
6
- } from '../lit-exports/all-lit-exports.js';
7
-
1
+ import { collapseWhiteSpace } from '@augment-vir/common';
8
2
  /**
9
3
  * Converts an HTML or SVG template into a raw string.
10
4
  *
11
5
  * @category Util
12
6
  */
13
- export function convertTemplateToString(
14
- template:
15
- | TemplateResult
16
- | ReturnType<typeof unsafeSVG>
17
- | ReturnType<typeof unsafeHTML>
18
- | {templateString: string},
19
- ): string {
7
+ export function convertTemplateToString(template) {
20
8
  if ('templateString' in template) {
21
9
  return template.templateString;
22
10
  }
23
-
24
- const {strings, values} = template as
25
- | TemplateResult
26
- | {
27
- strings: undefined | string[];
28
- values: undefined | unknown[];
29
- };
30
-
11
+ const { strings, values } = template;
31
12
  if (!strings?.length && !values?.length) {
32
13
  return '';
33
14
  }
34
-
35
15
  const valueList = [
36
16
  ...(values || []),
37
17
  '', // this last empty string is so it's easier to deal with indexes
38
18
  ];
39
19
  const stringsList = strings ?? [''];
40
-
41
20
  const all = stringsList.map((stringValue, index) => {
42
21
  const value = extractValue(stringValue, valueList[index]);
43
22
  return `${stringValue}${value}`;
44
23
  });
45
-
46
24
  return collapseWhiteSpace(all.join(''));
47
25
  }
48
-
49
- function extractValue(previousString: string, value: any) {
26
+ function extractValue(previousString, value) {
50
27
  if (value._$litType$ != undefined || value._$litDirective$ != undefined) {
51
28
  // nested templates
52
29
  return convertTemplateToString(value);
53
- } else if (Array.isArray(value)) {
30
+ }
31
+ else if (Array.isArray(value)) {
54
32
  // array of strings or templates.
55
33
  const values = value.map((innerValue) => convertTemplateToString(innerValue));
56
34
  return values.join('');
57
- } else if (previousString.endsWith('=')) {
35
+ }
36
+ else if (previousString.endsWith('=')) {
58
37
  return `"${value}"`;
59
- } else {
38
+ }
39
+ else {
60
40
  return value;
61
41
  }
62
42
  }
@@ -0,0 +1,7 @@
1
+ import { type AsyncValue } from 'observavir';
2
+ /**
3
+ * Maps an async value to a new async value.
4
+ *
5
+ * @category Util
6
+ */
7
+ export declare function mapAsyncValue<const OriginalValue, const MappedValue>(asyncValue: AsyncValue<OriginalValue>, mapper: (value: NoInfer<OriginalValue>) => MappedValue): AsyncValue<MappedValue>;
@@ -1,32 +1,30 @@
1
- import {isNotNoUpdate, type AsyncValue} from 'observavir';
2
-
1
+ import { isNotNoUpdate } from 'observavir';
3
2
  /**
4
3
  * Maps an async value to a new async value.
5
4
  *
6
5
  * @category Util
7
6
  */
8
- export function mapAsyncValue<const OriginalValue, const MappedValue>(
9
- asyncValue: AsyncValue<OriginalValue>,
10
- mapper: (value: NoInfer<OriginalValue>) => MappedValue,
11
- ): AsyncValue<MappedValue> {
7
+ export function mapAsyncValue(asyncValue, mapper) {
12
8
  if (asyncValue instanceof Error) {
13
9
  return asyncValue;
14
- } else if (asyncValue instanceof Promise) {
10
+ }
11
+ else if (asyncValue instanceof Promise) {
15
12
  return asyncValue.then((value) => {
16
13
  const mapped = mapper(value);
17
-
18
14
  if (isNotNoUpdate(mapped)) {
19
15
  return mapped;
20
- } else {
16
+ }
17
+ else {
21
18
  throw new Error('Cannot map to no update.');
22
19
  }
23
20
  });
24
- } else {
21
+ }
22
+ else {
25
23
  const mapped = mapper(asyncValue);
26
-
27
24
  if (isNotNoUpdate(mapped)) {
28
25
  return mapped;
29
- } else {
26
+ }
27
+ else {
30
28
  throw new Error('Cannot map to no update.');
31
29
  }
32
30
  }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "26.12.0",
3
+ "version": "26.12.1",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "sideEffects": false,
29
29
  "type": "module",
30
- "main": "src/index.ts",
31
- "module": "src/index.ts",
32
- "types": "src/index.ts",
30
+ "main": "dist/index.js",
31
+ "module": "dist/index.js",
32
+ "types": "dist/index.d.ts",
33
33
  "scripts": {
34
34
  "build": "npm run docs",
35
35
  "compile": "virmator compile",
@@ -1,115 +0,0 @@
1
- import {type CSSResult} from '../lit-exports/base-lit-exports.js';
2
- import {type CustomElementTagName} from './custom-tag-name.js';
3
- import {type DeclarativeElementDefinitionOptions} from './definition-options.js';
4
- import {type CssVarsInitMap} from './properties/css-vars.js';
5
- import {type EventsInitMap} from './properties/element-events.js';
6
- import {type PropertyInitMapBase} from './properties/element-properties.js';
7
- import {type HostClassesInitMap} from './properties/host-classes.js';
8
- import {type BaseStringName} from './properties/string-names.js';
9
- import {type StylesCallback} from './properties/styles.js';
10
- import {type InitCallback, type RenderCallback, type RenderParams} from './render-callback.js';
11
-
12
- /**
13
- * Initialization for an element-vir declarative element. This defines all the pieces required for
14
- * rendering the element.
15
- *
16
- * @category Internal
17
- */
18
- export type DeclarativeElementInit<
19
- TagName extends CustomElementTagName,
20
- Inputs extends PropertyInitMapBase,
21
- State extends PropertyInitMapBase,
22
- EventsInit extends EventsInitMap,
23
- HostClassKeys extends BaseStringName<TagName>,
24
- CssVarKeys extends BaseStringName<TagName>,
25
- SlotNames extends ReadonlyArray<string>,
26
- TestIds extends ReadonlyArray<string>,
27
- > = {
28
- /**
29
- * HTML tag name. This should not be used directly, as interpolating it with the html tagged
30
- * template from this package is preferred.
31
- */
32
- tagName: TagName;
33
- /** Static styles. These should not and cannot change. */
34
- styles?: CSSResult | StylesCallback<TagName, HostClassKeys, CssVarKeys> | undefined;
35
- /** Events that the element can dispatch. (These can be thought of as "outputs".) */
36
- events?: EventsInit | undefined;
37
- slotNames?: SlotNames | undefined;
38
- testIds?: TestIds | undefined;
39
- /**
40
- * HTML host classes. Values can be callbacks to determine when a host class should be defined,
41
- * based on current instance state or inputs, or just false to indicate that the host class will
42
- * only be manually set.
43
- */
44
- hostClasses?: HostClassesInitMap<TagName, HostClassKeys, Inputs, State> | undefined;
45
- /**
46
- * CSS Vars for the component. Keys of this object should be kebab-case and start with the
47
- * element's tag name.
48
- *
49
- * Values of this object represent the default fallback value for the given CSS var. These are
50
- * then passed to the styles property, which must be a callback to take advantage of these.
51
- */
52
- cssVars?: CssVarsInitMap<TagName, CssVarKeys>;
53
- /**
54
- * Make sure to define this at the top of your element init object or TypeScript will fail to
55
- * infer the element's state type.
56
- *
57
- * Setup the element's initial state. This is only called once per element instance, before the
58
- * first render. The return type of this method becomes the element's state type.
59
- */
60
- state?: (
61
- params: Omit<
62
- RenderParams<
63
- TagName,
64
- Inputs,
65
- any,
66
- EventsInit,
67
- HostClassKeys,
68
- CssVarKeys,
69
- SlotNames,
70
- TestIds
71
- >,
72
- 'state' | 'updateState'
73
- >,
74
- ) => Extract<keyof State, keyof HTMLElement> extends never
75
- ? Extract<keyof State, keyof Inputs> extends never
76
- ? State
77
- : `ERROR: Cannot define an element state property that clashes with input properties: ${Extract<keyof State, keyof Inputs> extends string | number | bigint | boolean | null | undefined ? Extract<keyof State, keyof Inputs> : ''}`
78
- : `ERROR: Cannot define an element state property that clashes with native HTMLElement properties: ${Extract<keyof State, keyof HTMLElement>}`;
79
- /** Called as part of the first render call, before the first render call. */
80
- init?:
81
- | InitCallback<
82
- TagName,
83
- Inputs,
84
- State,
85
- EventsInit,
86
- HostClassKeys,
87
- CssVarKeys,
88
- SlotNames,
89
- TestIds
90
- >
91
- | undefined;
92
- render: RenderCallback<
93
- TagName,
94
- Inputs,
95
- State,
96
- EventsInit,
97
- HostClassKeys,
98
- CssVarKeys,
99
- SlotNames,
100
- TestIds
101
- >;
102
- cleanup?:
103
- | InitCallback<
104
- TagName,
105
- Inputs,
106
- State,
107
- EventsInit,
108
- HostClassKeys,
109
- CssVarKeys,
110
- SlotNames,
111
- TestIds
112
- >
113
- | undefined;
114
- options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
115
- };