@bromscandium/runtime 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/hooks.d.ts +99 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +145 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-runtime.d.ts +77 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +90 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/lifecycle.d.ts +87 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +116 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/renderer.d.ts +65 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +539 -0
- package/dist/renderer.js.map +1 -0
- package/dist/vnode.d.ts +111 -0
- package/dist/vnode.d.ts.map +1 -0
- package/dist/vnode.js +83 -0
- package/dist/vnode.js.map +1 -0
- package/package.json +49 -0
- package/src/env.d.ts +11 -0
- package/src/hooks.ts +166 -0
- package/src/index.ts +56 -0
- package/src/jsx-runtime.ts +132 -0
- package/src/jsx.d.ts +373 -0
- package/src/lifecycle.ts +133 -0
- package/src/renderer.ts +655 -0
- package/src/vnode.ts +159 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component lifecycle hook system.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
let currentInstance = null;
|
|
6
|
+
/**
|
|
7
|
+
* Sets the currently rendering component instance.
|
|
8
|
+
* Used internally by the renderer.
|
|
9
|
+
*
|
|
10
|
+
* @param instance - The component instance or null
|
|
11
|
+
*/
|
|
12
|
+
export function setCurrentInstance(instance) {
|
|
13
|
+
currentInstance = instance;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the currently rendering component instance.
|
|
17
|
+
* Used internally by hooks to access component state.
|
|
18
|
+
*
|
|
19
|
+
* @returns The current component instance or null if outside a component
|
|
20
|
+
*/
|
|
21
|
+
export function getCurrentInstance() {
|
|
22
|
+
return currentInstance;
|
|
23
|
+
}
|
|
24
|
+
function registerLifecycleHook(type, fn) {
|
|
25
|
+
if (!currentInstance) {
|
|
26
|
+
if (import.meta.env?.DEV) {
|
|
27
|
+
console.warn(`${type} hook called outside of component setup. ` +
|
|
28
|
+
`Lifecycle hooks can only be used inside a component function.`);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
currentInstance[type].push(fn);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Registers a callback to be invoked after the component is mounted to the DOM.
|
|
36
|
+
* The callback runs after the initial render and DOM insertion.
|
|
37
|
+
*
|
|
38
|
+
* @param fn - The callback function to invoke on mount
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* function MyComponent() {
|
|
43
|
+
* onMounted(() => {
|
|
44
|
+
* console.log('Component mounted!');
|
|
45
|
+
* // DOM is available here
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* return <div>Hello</div>;
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function onMounted(fn) {
|
|
53
|
+
registerLifecycleHook('mounted', fn);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Registers a callback to be invoked before the component is unmounted.
|
|
57
|
+
* Use this to clean up side effects like timers, subscriptions, or event listeners.
|
|
58
|
+
*
|
|
59
|
+
* @param fn - The callback function to invoke on unmount
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* function MyComponent() {
|
|
64
|
+
* const timer = setInterval(() => {}, 1000);
|
|
65
|
+
*
|
|
66
|
+
* onUnmounted(() => {
|
|
67
|
+
* clearInterval(timer);
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* return <div>Hello</div>;
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function onUnmounted(fn) {
|
|
75
|
+
registerLifecycleHook('unmounted', fn);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers a callback to be invoked after the component updates.
|
|
79
|
+
* The callback runs after each re-render caused by reactive state changes.
|
|
80
|
+
*
|
|
81
|
+
* @param fn - The callback function to invoke after updates
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* function MyComponent() {
|
|
86
|
+
* const count = ref(0);
|
|
87
|
+
*
|
|
88
|
+
* onUpdated(() => {
|
|
89
|
+
* console.log('Component updated, count is now:', count.value);
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* return <button onClick={() => count.value++}>{count.value}</button>;
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function onUpdated(fn) {
|
|
97
|
+
registerLifecycleHook('updated', fn);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Invokes an array of lifecycle hook callbacks with error handling.
|
|
101
|
+
* Used internally by the renderer.
|
|
102
|
+
*
|
|
103
|
+
* @param hooks - Array of callback functions to invoke
|
|
104
|
+
* @param errorContext - Description of the hook type for error messages
|
|
105
|
+
*/
|
|
106
|
+
export function invokeLifecycleHooks(hooks, errorContext) {
|
|
107
|
+
hooks.forEach(hook => {
|
|
108
|
+
try {
|
|
109
|
+
hook();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error(`Error in ${errorContext || 'lifecycle hook'}:`, error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":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I,gBAAgB,GAAG,EAAE,KAAK,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM Renderer with virtual DOM reconciliation and diffing.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { VNode, ComponentFunction } from './vnode.js';
|
|
6
|
+
/**
|
|
7
|
+
* Renders a virtual DOM tree into a container element.
|
|
8
|
+
* Handles mounting, updating, and unmounting based on the previous state.
|
|
9
|
+
*
|
|
10
|
+
* @param vnode - The virtual node to render, or null to unmount
|
|
11
|
+
* @param container - The DOM element to render into
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const vnode = h('div', { className: 'app' }, 'Hello');
|
|
16
|
+
* render(vnode, document.getElementById('root')!);
|
|
17
|
+
*
|
|
18
|
+
* // Update
|
|
19
|
+
* render(h('div', { className: 'app' }, 'Updated'), container);
|
|
20
|
+
*
|
|
21
|
+
* // Unmount
|
|
22
|
+
* render(null, container);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function render(vnode: VNode | null, container: Element): void;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration options for creating a Bromium application.
|
|
28
|
+
*/
|
|
29
|
+
export interface AppConfig {
|
|
30
|
+
/** Path to the favicon image */
|
|
31
|
+
favicon?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new Bromium application instance.
|
|
35
|
+
*
|
|
36
|
+
* @param rootComponent - The root component function to render
|
|
37
|
+
* @param config - Optional application configuration
|
|
38
|
+
* @returns An app instance with mount and unmount methods
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* function App() {
|
|
43
|
+
* return <div>Hello, Bromium!</div>;
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* const app = createApp(App, { favicon: '/icon.png' });
|
|
47
|
+
* app.mount('#app');
|
|
48
|
+
*
|
|
49
|
+
* // Later: app.unmount();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createApp(rootComponent: ComponentFunction, config?: AppConfig): {
|
|
53
|
+
/**
|
|
54
|
+
* Mounts the application to a DOM element.
|
|
55
|
+
*
|
|
56
|
+
* @param selector - A CSS selector string or DOM Element to mount to
|
|
57
|
+
* @returns The app instance for chaining
|
|
58
|
+
*/
|
|
59
|
+
mount(selector: string | Element): /*elided*/ any;
|
|
60
|
+
/**
|
|
61
|
+
* Unmounts the application and cleans up resources.
|
|
62
|
+
*/
|
|
63
|
+
unmount(): void;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAkB,iBAAiB,EAAqB,MAAM,YAAY,CAAC;AAuBzF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAcpE;AA2eD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAsBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,aAAa,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,SAAS;IAU1E;;;;;OAKG;oBACa,MAAM,GAAG,OAAO;IA0BhC;;OAEG;;EAWN"}
|