@arcmantle/lit-jsx 1.0.33 → 1.0.34

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 (74) hide show
  1. package/README.md +95 -145
  2. package/dist/compiler/attribute-processor.d.ts +4 -19
  3. package/dist/compiler/attribute-processor.d.ts.map +1 -1
  4. package/dist/compiler/attribute-processor.js +1 -38
  5. package/dist/compiler/attribute-processor.js.map +1 -1
  6. package/dist/compiler/babel-plugin.d.ts.map +1 -1
  7. package/dist/compiler/babel-plugin.js +2 -1
  8. package/dist/compiler/babel-plugin.js.map +1 -1
  9. package/dist/compiler/compiler-utils.d.ts +7 -0
  10. package/dist/compiler/compiler-utils.d.ts.map +1 -1
  11. package/dist/compiler/compiler-utils.js +45 -57
  12. package/dist/compiler/compiler-utils.js.map +1 -1
  13. package/dist/compiler/config.d.ts +15 -25
  14. package/dist/compiler/config.d.ts.map +1 -1
  15. package/dist/compiler/config.js +15 -25
  16. package/dist/compiler/config.js.map +1 -1
  17. package/dist/compiler/oxc-walker.d.ts +4 -4
  18. package/dist/compiler/oxc-walker.d.ts.map +1 -1
  19. package/dist/compiler/oxc-walker.js +1 -1
  20. package/dist/compiler/oxc-walker.js.map +1 -1
  21. package/dist/compiler/preprocess.d.ts +1 -0
  22. package/dist/compiler/preprocess.d.ts.map +1 -1
  23. package/dist/compiler/preprocess.js +31 -0
  24. package/dist/compiler/preprocess.js.map +1 -1
  25. package/dist/runtime/choose-component.d.ts +2 -2
  26. package/dist/runtime/choose-component.d.ts.map +1 -1
  27. package/dist/runtime/for-component.d.ts +3 -3
  28. package/dist/runtime/for-component.d.ts.map +1 -1
  29. package/dist/runtime/for-component.js.map +1 -1
  30. package/dist/runtime/lit-reexports.d.ts +11 -0
  31. package/dist/runtime/lit-reexports.d.ts.map +1 -0
  32. package/dist/runtime/lit-reexports.js +14 -0
  33. package/dist/runtime/lit-reexports.js.map +1 -0
  34. package/dist/runtime/show-component.d.ts +4 -4
  35. package/dist/runtime/show-component.d.ts.map +1 -1
  36. package/dist/runtime/type-helpers.d.ts +1 -1
  37. package/dist/runtime/type-helpers.d.ts.map +1 -1
  38. package/dist/shared/jsx-core.d.ts +83 -0
  39. package/dist/shared/jsx-core.d.ts.map +1 -0
  40. package/dist/shared/jsx-core.js +2 -0
  41. package/dist/shared/jsx-core.js.map +1 -0
  42. package/dist/shared/jsx-dom.d.ts +26 -0
  43. package/dist/shared/jsx-dom.d.ts.map +1 -0
  44. package/dist/shared/jsx-dom.js +2 -0
  45. package/dist/shared/jsx-dom.js.map +1 -0
  46. package/dist/shared/jsx-hooks.d.ts +69 -0
  47. package/dist/shared/jsx-hooks.d.ts.map +1 -0
  48. package/dist/shared/jsx-hooks.js +2 -0
  49. package/dist/shared/jsx-hooks.js.map +1 -0
  50. package/dist/shared/jsx-types.d.ts +3 -2140
  51. package/dist/shared/jsx-types.d.ts.map +1 -1
  52. package/dist/shared/jsx-types.js +3 -1
  53. package/dist/shared/jsx-types.js.map +1 -1
  54. package/dist/utils.d.ts +1 -0
  55. package/dist/utils.d.ts.map +1 -1
  56. package/dist/utils.js +3 -0
  57. package/dist/utils.js.map +1 -1
  58. package/package.json +17 -17
  59. package/src/compiler/attribute-processor.ts +5 -62
  60. package/src/compiler/babel-plugin.ts +2 -1
  61. package/src/compiler/compiler-utils.ts +60 -255
  62. package/src/compiler/config.ts +26 -37
  63. package/src/compiler/oxc-walker.ts +5 -5
  64. package/src/compiler/preprocess.ts +41 -0
  65. package/src/runtime/choose-component.ts +2 -2
  66. package/src/runtime/for-component.ts +3 -3
  67. package/src/runtime/lit-reexports.ts +16 -0
  68. package/src/runtime/show-component.ts +4 -4
  69. package/src/runtime/type-helpers.ts +1 -1
  70. package/src/shared/jsx-core.ts +123 -0
  71. package/src/shared/jsx-dom.ts +29 -0
  72. package/src/shared/jsx-hooks.ts +86 -0
  73. package/src/shared/jsx-types.ts +3 -2559
  74. package/src/utils.ts +15 -0
@@ -0,0 +1,123 @@
1
+ import type { TemplateResult } from 'lit-html';
2
+ import type { DirectiveResult } from 'lit-html/async-directive.js';
3
+ import type { RefOrCallback } from 'lit-html/directives/ref.js';
4
+
5
+
6
+ declare global {
7
+ namespace LitJSX {
8
+ type HTMLElementAssignableProps<T extends object & Record<string, any>> =
9
+ Partial<TrimReadonly<T>>;
10
+
11
+ type HTMLElementProps = HTMLElementAssignableProps<HTMLElement>;
12
+
13
+ type JSXElementProps<T extends object> = HTMLElementAssignableProps<T> & {
14
+ children?: LitJSX.Child;
15
+ ref?: RefOrCallback<HTMLElementAssignableProps<T>>;
16
+ classList?: { [k: string]: boolean | undefined; };
17
+ styleList?: CSSProperties;
18
+
19
+ /**
20
+ * This property takes in one or more element directives.
21
+ * This is akin to applying a directive through `<div ${myDirective()}></div>`.
22
+ */
23
+ directive?: DirectiveResult<any> | DirectiveResult<any>[];
24
+ } & {
25
+ [key: `data-${ string }`]: string | undefined;
26
+ };
27
+
28
+ type ElementMapToJSXElements<T extends object & Record<string, any>> = {
29
+ [K in keyof T]: JSXElementProps<T[K]>;
30
+ };
31
+
32
+ type IfEquals<X, Y, A = X> =
33
+ (<T>() => T extends X ? 1 : 2) extends
34
+ (<T>() => T extends Y ? 1 : 2) ? A : never;
35
+
36
+ type WritableKeys<T> = {
37
+ [P in keyof T]-?: IfEquals<
38
+ { [Q in P]: T[P] },
39
+ { -readonly [Q in P]: T[P] },
40
+ P
41
+ >
42
+ }[keyof T];
43
+
44
+ type TrimReadonly<T> = Pick<T, WritableKeys<T>>;
45
+
46
+ type TrimHTMLElement<T extends object> = TrimReadonly<Omit<T, keyof HTMLElement | 'constructor'>>;
47
+
48
+ type JSXProps<T extends object> =
49
+ & TrimHTMLElement<T>
50
+ & Omit<HTMLElementProps, keyof TrimHTMLElement<T>>;
51
+
52
+ type Child = unknown;
53
+
54
+ type Element = TemplateResult<any>;
55
+
56
+ type AnyTagName = string & Record<never, never>;
57
+
58
+ interface IntrinsicElements extends
59
+ NativeHTMLElements,
60
+ NativeSVGElements,
61
+ NativeMathMLElements,
62
+ SemanticTags {}
63
+
64
+ type TagName = keyof IntrinsicElements | AnyTagName;
65
+
66
+ type DynamicTagProps<Tag extends string> = Tag extends keyof IntrinsicElements
67
+ ? IntrinsicElements[Tag]
68
+ : (Tag extends keyof HTMLElementTagNameMap
69
+ ? JSXElementProps<HTMLElementTagNameMap[Tag]>
70
+ : JSXElementProps<HTMLElement>);
71
+
72
+ type IntrinsicElementProps<Tag extends keyof IntrinsicElements> = IntrinsicElements[Tag];
73
+
74
+ type DynamicTag<Tag extends TagName> = ((props: DynamicTagProps<Tag> & StaticMarker) => Element);
75
+
76
+ interface StaticMarker {
77
+ /**
78
+ * Opt into the lit-jsx custom-element transform. \
79
+ * Example: `<MyElement static />`
80
+ */
81
+ static: true;
82
+ }
83
+
84
+ type Component<P extends object = {}> = (props: P) => Element;
85
+ type ClassComponent<Instance extends object = any> = abstract new (...args: any[]) => Instance;
86
+
87
+ type ComponentLike<P extends object = object> =
88
+ | Component<P>
89
+ | ClassComponent<any>;
90
+
91
+ type ComponentProps<T> =
92
+ T extends Component<infer P> ? P :
93
+ T extends ClassComponent<infer I> ? JSXProps<Extract<I, object>> :
94
+ T extends abstract new (...args: any[]) => infer I ? JSXProps<Extract<I, object>> :
95
+ {};
96
+ }
97
+
98
+ // eslint-disable-next-line no-var
99
+ var as: {
100
+ /**
101
+ * Informs the compiler that the value should be bound as a property value.\
102
+ * This binds the expression value as a property, using the `.` syntax e.g `.key=${value}`\
103
+ * This function call is removed during compilation, therefore it has no runtime effect.
104
+ */
105
+ prop: <T>(value: T) => T;
106
+ /**
107
+ * Informs the compiler that the value should be bound as a boolean attribute.\
108
+ * This allows the template to bind the value using the `?` syntax, e.g. `?disabled=${true}`\
109
+ * This function call is removed during compilation, therefore it has no runtime effect.
110
+ */
111
+ bool: (value: boolean) => boolean;
112
+ /**
113
+ * Creates a component-like value for an intrinsic tag, so it can be used in
114
+ * JSX as a dynamic tag identifier.
115
+ *
116
+ * The returned component requires `static`.
117
+ * Example:
118
+ * const Tag = as.tag('a');
119
+ * <Tag static href="..." />
120
+ */
121
+ tag: <Tag extends LitJSX.TagName>(tag: Tag) => LitJSX.DynamicTag<Tag>;
122
+ };
123
+ }
@@ -0,0 +1,29 @@
1
+ import type * as csstype from 'csstype';
2
+
3
+
4
+ declare global {
5
+ namespace LitJSX {
6
+
7
+ interface CSSProperties extends csstype.Properties { }
8
+
9
+ /**
10
+ * Interface for native HTML elements
11
+ */
12
+ type NativeHTMLElements = ElementMapToJSXElements<HTMLElementTagNameMap>;
13
+
14
+ /**
15
+ * Interface for native SVG elements
16
+ */
17
+ type NativeSVGElements = ElementMapToJSXElements<Omit<SVGElementTagNameMap, keyof HTMLElementTagNameMap>>;
18
+
19
+ /**
20
+ * Interface for native MathML elements
21
+ */
22
+ type NativeMathMLElements = ElementMapToJSXElements<Omit<MathMLElementTagNameMap, keyof HTMLElementTagNameMap>>;
23
+
24
+ /**
25
+ * Interface for semantic tags that start with "s-".
26
+ */
27
+ interface SemanticTags { [key: `s-${ string }`]: JSXElementProps<HTMLElement>; }
28
+ }
29
+ }
@@ -0,0 +1,86 @@
1
+ export {};
2
+
3
+
4
+ /**
5
+ * TSX hook declarations for lit-jsx.
6
+ */
7
+
8
+ declare global {
9
+ //#region JSX hooks (TypeScript special names)
10
+ // These names are *looked up by TypeScript* when type-checking TSX.
11
+ namespace JSX {
12
+ /**
13
+ * TSX hook: the type produced by any JSX expression.
14
+ *
15
+ * In lit-jsx we return a lit `TemplateResult`, so `<div />` has this type.
16
+ */
17
+ type Element = LitJSX.Element;
18
+
19
+ /**
20
+ * TSX hook: what values are allowed as JSX tags.
21
+ *
22
+ * Note: this intentionally references tag/component helper types declared in
23
+ * `jsx-core.ts`.
24
+ */
25
+ type ElementType
26
+ = keyof LitJSX.IntrinsicElements
27
+ | (string & {})
28
+ | LitJSX.ComponentLike<any>;
29
+
30
+ /**
31
+ * TSX hook: computes the attribute (props) type for a JSX tag.
32
+ *
33
+ * lit-jsx uses this to:
34
+ * - require `static: true` for class-based component tags
35
+ * - preserve TSX generic arguments on class instances (avoid `unknown` props)
36
+ */
37
+ type LibraryManagedAttributes<C, P>
38
+ = C extends abstract new (...args: any[]) => infer I
39
+ ? (P extends I
40
+ ? LitJSX.JSXProps<Extract<P, object>> & LitJSX.StaticMarker
41
+ : LitJSX.ComponentProps<C> & LitJSX.StaticMarker)
42
+ : (C extends keyof LitJSX.IntrinsicElements
43
+ ? LitJSX.IntrinsicElementProps<C>
44
+ : LitJSX.ComponentProps<C>);
45
+
46
+ /**
47
+ * TSX hook: controls the instance type used for class components.
48
+ *
49
+ * We keep this empty because we don’t require any particular base class.
50
+ */
51
+ interface ElementClass {}
52
+
53
+ /**
54
+ * TSX hook: which property name TypeScript should read for “props”.
55
+ *
56
+ * Leaving it empty means TS uses its default behavior.
57
+ */
58
+ interface ElementAttributesProperty {}
59
+
60
+ /**
61
+ * TSX hook: which property name represents “children”.
62
+ */
63
+ interface ElementChildrenAttribute { children: {}; }
64
+
65
+ /** TSX hook: attributes allowed on *all* JSX elements (e.g. React's `key`). */
66
+ interface IntrinsicAttributes {}
67
+
68
+ /** TSX hook: attributes allowed on class components specifically (often `ref`-like). */
69
+ interface IntrinsicClassAttributes<_T> {}
70
+
71
+ /** TSX hook: base attribute bag TypeScript may intersect into component props. */
72
+ interface Attributes {}
73
+
74
+ /** TSX hook: fragment typing for `<>...</>` */
75
+ type Fragment = Element;
76
+
77
+ /**
78
+ * TSX hook: mapping of intrinsic tag names to their attribute types.
79
+ *
80
+ * Note: this intentionally depends on DOM typings declared in `jsx-dom.ts`
81
+ * (e.g. `HTMLElementTags`, `SVGElementTags`, ...).
82
+ */
83
+ interface IntrinsicElements extends LitJSX.IntrinsicElements {}
84
+ }
85
+ //#endregion
86
+ }