@bromscandium/runtime 1.0.0 → 1.0.2
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.
- package/LICENSE +20 -20
- package/README.md +91 -91
- package/package.json +49 -49
- package/src/index.ts +56 -56
- package/src/jsx-runtime.ts +132 -132
- package/src/jsx.d.ts +373 -373
- package/src/lifecycle.ts +133 -133
- package/src/renderer.ts +655 -655
- package/src/vnode.ts +159 -159
package/src/jsx-runtime.ts
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSX Runtime for TypeScript/Vite.
|
|
3
|
-
* Configure in tsconfig.json: "jsx": "react-jsx", "jsxImportSource": "@bromscandium/runtime"
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {createVNode, Fragment, VNode, VNodeType} from './vnode.js';
|
|
8
|
-
|
|
9
|
-
export { Fragment };
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* JSX element type alias for VNode.
|
|
13
|
-
*/
|
|
14
|
-
export interface JSXElement extends VNode {}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a virtual node from JSX syntax (React 17+ automatic runtime).
|
|
18
|
-
* This is called automatically by the TypeScript/Babel JSX transform.
|
|
19
|
-
*
|
|
20
|
-
* @param type - Element type (tag name or component function)
|
|
21
|
-
* @param props - Props object including children
|
|
22
|
-
* @param key - Optional key for list reconciliation
|
|
23
|
-
* @returns A virtual node
|
|
24
|
-
*/
|
|
25
|
-
export function jsx(
|
|
26
|
-
type: VNodeType,
|
|
27
|
-
props: Record<string, any> | null,
|
|
28
|
-
key?: string | number | null
|
|
29
|
-
): VNode {
|
|
30
|
-
const { children, ...restProps } = props || {};
|
|
31
|
-
|
|
32
|
-
return createVNode(
|
|
33
|
-
type,
|
|
34
|
-
{...restProps, key: key ?? restProps?.key},
|
|
35
|
-
children
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a virtual node with static children (optimization hint).
|
|
41
|
-
* Functionally identical to jsx() but indicates children won't change.
|
|
42
|
-
*
|
|
43
|
-
* @param type - Element type (tag name or component function)
|
|
44
|
-
* @param props - Props object including children
|
|
45
|
-
* @param key - Optional key for list reconciliation
|
|
46
|
-
* @returns A virtual node
|
|
47
|
-
*/
|
|
48
|
-
export function jsxs(
|
|
49
|
-
type: VNodeType,
|
|
50
|
-
props: Record<string, any> | null,
|
|
51
|
-
key?: string | number | null
|
|
52
|
-
): VNode {
|
|
53
|
-
return jsx(type, props, key);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Development version of jsx() with extra validation and warnings.
|
|
58
|
-
* Only performs validation when import.meta.env.DEV is true.
|
|
59
|
-
*
|
|
60
|
-
* @param type - Element type (tag name or component function)
|
|
61
|
-
* @param props - Props object including children
|
|
62
|
-
* @param key - Optional key for list reconciliation
|
|
63
|
-
* @param _isStatic - Unused static children hint
|
|
64
|
-
* @param _source - Source location for error messages
|
|
65
|
-
* @param _self - Component reference for error messages
|
|
66
|
-
* @returns A virtual node
|
|
67
|
-
*/
|
|
68
|
-
export function jsxDEV(
|
|
69
|
-
type: VNodeType,
|
|
70
|
-
props: Record<string, any> | null,
|
|
71
|
-
key?: string | number | null,
|
|
72
|
-
_isStatic?: boolean,
|
|
73
|
-
_source?: { fileName: string; lineNumber: number; columnNumber: number },
|
|
74
|
-
_self?: any
|
|
75
|
-
): VNode {
|
|
76
|
-
if (import.meta.env?.DEV) {
|
|
77
|
-
if (typeof type === 'string' && type !== type.toLowerCase() && !type.includes('-')) {
|
|
78
|
-
console.warn(
|
|
79
|
-
`Invalid element type: "${type}". HTML elements must be lowercase. ` +
|
|
80
|
-
`Did you mean to use a component? Components should start with uppercase.`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (props) {
|
|
85
|
-
if ('class' in props && !('className' in props)) {
|
|
86
|
-
console.warn(
|
|
87
|
-
`Invalid prop "class" detected. Use "className" instead.`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return jsx(type, props, key);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates a virtual node using classic createElement syntax.
|
|
98
|
-
* Use this for manual VNode creation without JSX.
|
|
99
|
-
*
|
|
100
|
-
* @param type - Element type (tag name or component function)
|
|
101
|
-
* @param props - Props object (without children)
|
|
102
|
-
* @param children - Child elements as rest parameters
|
|
103
|
-
* @returns A virtual node
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* const vnode = createElement('div', { className: 'app' },
|
|
108
|
-
* createElement('h1', null, 'Hello'),
|
|
109
|
-
* createElement('p', null, 'World')
|
|
110
|
-
* );
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export function createElement(
|
|
114
|
-
type: VNodeType,
|
|
115
|
-
props: Record<string, any> | null,
|
|
116
|
-
...children: any[]
|
|
117
|
-
): VNode {
|
|
118
|
-
const normalizedProps = props || {};
|
|
119
|
-
const flatChildren = children.length === 1 ? children[0] : children;
|
|
120
|
-
|
|
121
|
-
return createVNode(type, normalizedProps, flatChildren);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Alias for createElement, providing a shorter hyperscript-style API.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
* const vnode = h('div', { className: 'app' }, h('span', null, 'Hello'));
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export const h = createElement;
|
|
1
|
+
/**
|
|
2
|
+
* JSX Runtime for TypeScript/Vite.
|
|
3
|
+
* Configure in tsconfig.json: "jsx": "react-jsx", "jsxImportSource": "@bromscandium/runtime"
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {createVNode, Fragment, VNode, VNodeType} from './vnode.js';
|
|
8
|
+
|
|
9
|
+
export { Fragment };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* JSX element type alias for VNode.
|
|
13
|
+
*/
|
|
14
|
+
export interface JSXElement extends VNode {}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a virtual node from JSX syntax (React 17+ automatic runtime).
|
|
18
|
+
* This is called automatically by the TypeScript/Babel JSX transform.
|
|
19
|
+
*
|
|
20
|
+
* @param type - Element type (tag name or component function)
|
|
21
|
+
* @param props - Props object including children
|
|
22
|
+
* @param key - Optional key for list reconciliation
|
|
23
|
+
* @returns A virtual node
|
|
24
|
+
*/
|
|
25
|
+
export function jsx(
|
|
26
|
+
type: VNodeType,
|
|
27
|
+
props: Record<string, any> | null,
|
|
28
|
+
key?: string | number | null
|
|
29
|
+
): VNode {
|
|
30
|
+
const { children, ...restProps } = props || {};
|
|
31
|
+
|
|
32
|
+
return createVNode(
|
|
33
|
+
type,
|
|
34
|
+
{...restProps, key: key ?? restProps?.key},
|
|
35
|
+
children
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a virtual node with static children (optimization hint).
|
|
41
|
+
* Functionally identical to jsx() but indicates children won't change.
|
|
42
|
+
*
|
|
43
|
+
* @param type - Element type (tag name or component function)
|
|
44
|
+
* @param props - Props object including children
|
|
45
|
+
* @param key - Optional key for list reconciliation
|
|
46
|
+
* @returns A virtual node
|
|
47
|
+
*/
|
|
48
|
+
export function jsxs(
|
|
49
|
+
type: VNodeType,
|
|
50
|
+
props: Record<string, any> | null,
|
|
51
|
+
key?: string | number | null
|
|
52
|
+
): VNode {
|
|
53
|
+
return jsx(type, props, key);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Development version of jsx() with extra validation and warnings.
|
|
58
|
+
* Only performs validation when import.meta.env.DEV is true.
|
|
59
|
+
*
|
|
60
|
+
* @param type - Element type (tag name or component function)
|
|
61
|
+
* @param props - Props object including children
|
|
62
|
+
* @param key - Optional key for list reconciliation
|
|
63
|
+
* @param _isStatic - Unused static children hint
|
|
64
|
+
* @param _source - Source location for error messages
|
|
65
|
+
* @param _self - Component reference for error messages
|
|
66
|
+
* @returns A virtual node
|
|
67
|
+
*/
|
|
68
|
+
export function jsxDEV(
|
|
69
|
+
type: VNodeType,
|
|
70
|
+
props: Record<string, any> | null,
|
|
71
|
+
key?: string | number | null,
|
|
72
|
+
_isStatic?: boolean,
|
|
73
|
+
_source?: { fileName: string; lineNumber: number; columnNumber: number },
|
|
74
|
+
_self?: any
|
|
75
|
+
): VNode {
|
|
76
|
+
if (import.meta.env?.DEV) {
|
|
77
|
+
if (typeof type === 'string' && type !== type.toLowerCase() && !type.includes('-')) {
|
|
78
|
+
console.warn(
|
|
79
|
+
`Invalid element type: "${type}". HTML elements must be lowercase. ` +
|
|
80
|
+
`Did you mean to use a component? Components should start with uppercase.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (props) {
|
|
85
|
+
if ('class' in props && !('className' in props)) {
|
|
86
|
+
console.warn(
|
|
87
|
+
`Invalid prop "class" detected. Use "className" instead.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return jsx(type, props, key);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a virtual node using classic createElement syntax.
|
|
98
|
+
* Use this for manual VNode creation without JSX.
|
|
99
|
+
*
|
|
100
|
+
* @param type - Element type (tag name or component function)
|
|
101
|
+
* @param props - Props object (without children)
|
|
102
|
+
* @param children - Child elements as rest parameters
|
|
103
|
+
* @returns A virtual node
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const vnode = createElement('div', { className: 'app' },
|
|
108
|
+
* createElement('h1', null, 'Hello'),
|
|
109
|
+
* createElement('p', null, 'World')
|
|
110
|
+
* );
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function createElement(
|
|
114
|
+
type: VNodeType,
|
|
115
|
+
props: Record<string, any> | null,
|
|
116
|
+
...children: any[]
|
|
117
|
+
): VNode {
|
|
118
|
+
const normalizedProps = props || {};
|
|
119
|
+
const flatChildren = children.length === 1 ? children[0] : children;
|
|
120
|
+
|
|
121
|
+
return createVNode(type, normalizedProps, flatChildren);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Alias for createElement, providing a shorter hyperscript-style API.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* const vnode = h('div', { className: 'app' }, h('span', null, 'Hello'));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export const h = createElement;
|