@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/src/jsx.d.ts ADDED
@@ -0,0 +1,373 @@
1
+ // JSX Type Declarations for BromiumJS
2
+
3
+ import { VNode } from './vnode.js';
4
+
5
+ type Child = VNode | string | number | boolean | null | undefined;
6
+ type Children = Child | Child[];
7
+
8
+ interface HTMLAttributes<T = Element> {
9
+ // Standard HTML attributes
10
+ className?: string;
11
+ id?: string;
12
+ style?: string | Record<string, string | number>;
13
+ title?: string;
14
+ tabIndex?: number;
15
+ role?: string;
16
+ hidden?: boolean;
17
+ 'aria-label'?: string;
18
+ 'aria-hidden'?: boolean;
19
+ 'data-testid'?: string;
20
+
21
+ // Event handlers
22
+ onClick?: (e: MouseEvent) => void;
23
+ onDblClick?: (e: MouseEvent) => void;
24
+ onMouseDown?: (e: MouseEvent) => void;
25
+ onMouseUp?: (e: MouseEvent) => void;
26
+ onMouseEnter?: (e: MouseEvent) => void;
27
+ onMouseLeave?: (e: MouseEvent) => void;
28
+ onMouseMove?: (e: MouseEvent) => void;
29
+ onMouseOver?: (e: MouseEvent) => void;
30
+ onMouseOut?: (e: MouseEvent) => void;
31
+
32
+ onKeyDown?: (e: KeyboardEvent) => void;
33
+ onKeyUp?: (e: KeyboardEvent) => void;
34
+ onKeyPress?: (e: KeyboardEvent) => void;
35
+
36
+ onFocus?: (e: FocusEvent) => void;
37
+ onBlur?: (e: FocusEvent) => void;
38
+
39
+ onInput?: (e: Event) => void;
40
+ onChange?: (e: Event) => void;
41
+ onSubmit?: (e: SubmitEvent) => void;
42
+
43
+ onScroll?: (e: Event) => void;
44
+ onWheel?: (e: WheelEvent) => void;
45
+
46
+ onDrag?: (e: DragEvent) => void;
47
+ onDragStart?: (e: DragEvent) => void;
48
+ onDragEnd?: (e: DragEvent) => void;
49
+ onDragEnter?: (e: DragEvent) => void;
50
+ onDragLeave?: (e: DragEvent) => void;
51
+ onDragOver?: (e: DragEvent) => void;
52
+ onDrop?: (e: DragEvent) => void;
53
+
54
+ onTouchStart?: (e: TouchEvent) => void;
55
+ onTouchMove?: (e: TouchEvent) => void;
56
+ onTouchEnd?: (e: TouchEvent) => void;
57
+ onTouchCancel?: (e: TouchEvent) => void;
58
+
59
+ onAnimationStart?: (e: AnimationEvent) => void;
60
+ onAnimationEnd?: (e: AnimationEvent) => void;
61
+ onAnimationIteration?: (e: AnimationEvent) => void;
62
+
63
+ onTransitionEnd?: (e: TransitionEvent) => void;
64
+
65
+ onLoad?: (e: Event) => void;
66
+ onError?: (e: Event) => void;
67
+
68
+ // Children
69
+ children?: Children;
70
+
71
+ // Allow any other attribute
72
+ [key: string]: any;
73
+ }
74
+
75
+ interface InputHTMLAttributes<T = HTMLInputElement> extends HTMLAttributes<T> {
76
+ type?: 'text' | 'password' | 'email' | 'number' | 'tel' | 'url' | 'search' | 'checkbox' | 'radio' | 'file' | 'hidden' | 'submit' | 'reset' | 'button' | 'date' | 'datetime-local' | 'month' | 'week' | 'time' | 'color' | 'range';
77
+ value?: string | number;
78
+ defaultValue?: string | number;
79
+ placeholder?: string;
80
+ disabled?: boolean;
81
+ readOnly?: boolean;
82
+ required?: boolean;
83
+ autoFocus?: boolean;
84
+ autoComplete?: string;
85
+ name?: string;
86
+ min?: number | string;
87
+ max?: number | string;
88
+ step?: number | string;
89
+ pattern?: string;
90
+ checked?: boolean;
91
+ defaultChecked?: boolean;
92
+ multiple?: boolean;
93
+ accept?: string;
94
+ maxLength?: number;
95
+ minLength?: number;
96
+ }
97
+
98
+ interface TextareaHTMLAttributes<T = HTMLTextAreaElement> extends HTMLAttributes<T> {
99
+ value?: string;
100
+ defaultValue?: string;
101
+ placeholder?: string;
102
+ disabled?: boolean;
103
+ readOnly?: boolean;
104
+ required?: boolean;
105
+ autoFocus?: boolean;
106
+ name?: string;
107
+ rows?: number;
108
+ cols?: number;
109
+ maxLength?: number;
110
+ minLength?: number;
111
+ wrap?: 'hard' | 'soft' | 'off';
112
+ }
113
+
114
+ interface SelectHTMLAttributes<T = HTMLSelectElement> extends HTMLAttributes<T> {
115
+ value?: string | string[];
116
+ defaultValue?: string | string[];
117
+ disabled?: boolean;
118
+ required?: boolean;
119
+ autoFocus?: boolean;
120
+ name?: string;
121
+ multiple?: boolean;
122
+ size?: number;
123
+ }
124
+
125
+ interface ButtonHTMLAttributes<T = HTMLButtonElement> extends HTMLAttributes<T> {
126
+ type?: 'submit' | 'reset' | 'button';
127
+ disabled?: boolean;
128
+ name?: string;
129
+ value?: string;
130
+ autoFocus?: boolean;
131
+ }
132
+
133
+ interface AnchorHTMLAttributes<T = HTMLAnchorElement> extends HTMLAttributes<T> {
134
+ href?: string;
135
+ target?: '_blank' | '_self' | '_parent' | '_top';
136
+ rel?: string;
137
+ download?: boolean | string;
138
+ }
139
+
140
+ interface ImgHTMLAttributes<T = HTMLImageElement> extends HTMLAttributes<T> {
141
+ src?: string;
142
+ alt?: string;
143
+ width?: number | string;
144
+ height?: number | string;
145
+ loading?: 'lazy' | 'eager';
146
+ decoding?: 'sync' | 'async' | 'auto';
147
+ crossOrigin?: 'anonymous' | 'use-credentials';
148
+ }
149
+
150
+ interface FormHTMLAttributes<T = HTMLFormElement> extends HTMLAttributes<T> {
151
+ action?: string;
152
+ method?: 'get' | 'post';
153
+ encType?: string;
154
+ target?: string;
155
+ autoComplete?: 'on' | 'off';
156
+ noValidate?: boolean;
157
+ }
158
+
159
+ interface LabelHTMLAttributes<T = HTMLLabelElement> extends HTMLAttributes<T> {
160
+ htmlFor?: string;
161
+ }
162
+
163
+ interface OptionHTMLAttributes<T = HTMLOptionElement> extends HTMLAttributes<T> {
164
+ value?: string | number;
165
+ disabled?: boolean;
166
+ selected?: boolean;
167
+ label?: string;
168
+ }
169
+
170
+ interface SVGAttributes extends HTMLAttributes {
171
+ viewBox?: string;
172
+ xmlns?: string;
173
+ width?: number | string;
174
+ height?: number | string;
175
+ fill?: string;
176
+ stroke?: string;
177
+ strokeWidth?: number | string;
178
+ strokeLinecap?: 'butt' | 'round' | 'square';
179
+ strokeLinejoin?: 'miter' | 'round' | 'bevel';
180
+ d?: string;
181
+ cx?: number | string;
182
+ cy?: number | string;
183
+ r?: number | string;
184
+ x?: number | string;
185
+ y?: number | string;
186
+ x1?: number | string;
187
+ y1?: number | string;
188
+ x2?: number | string;
189
+ y2?: number | string;
190
+ rx?: number | string;
191
+ ry?: number | string;
192
+ points?: string;
193
+ transform?: string;
194
+ textAnchor?: 'start' | 'middle' | 'end';
195
+ fontFamily?: string;
196
+ fontWeight?: string | number;
197
+ fontSize?: number | string;
198
+ }
199
+
200
+ declare global {
201
+ namespace JSX {
202
+ interface Element extends VNode {}
203
+
204
+ interface ElementAttributesProperty {
205
+ props: {};
206
+ }
207
+
208
+ interface ElementChildrenAttribute {
209
+ children: {};
210
+ }
211
+
212
+ interface IntrinsicAttributes {
213
+ key?: string | number | null;
214
+ }
215
+
216
+ interface IntrinsicElements {
217
+ // Document metadata
218
+ head: HTMLAttributes;
219
+ title: HTMLAttributes;
220
+ base: HTMLAttributes;
221
+ link: HTMLAttributes & { href?: string; rel?: string; type?: string };
222
+ meta: HTMLAttributes & { name?: string; content?: string; charset?: string };
223
+ style: HTMLAttributes & { type?: string };
224
+
225
+ // Sectioning root
226
+ body: HTMLAttributes;
227
+
228
+ // Content sectioning
229
+ address: HTMLAttributes;
230
+ article: HTMLAttributes;
231
+ aside: HTMLAttributes;
232
+ footer: HTMLAttributes;
233
+ header: HTMLAttributes;
234
+ h1: HTMLAttributes;
235
+ h2: HTMLAttributes;
236
+ h3: HTMLAttributes;
237
+ h4: HTMLAttributes;
238
+ h5: HTMLAttributes;
239
+ h6: HTMLAttributes;
240
+ main: HTMLAttributes;
241
+ nav: HTMLAttributes;
242
+ section: HTMLAttributes;
243
+
244
+ // Text content
245
+ blockquote: HTMLAttributes & { cite?: string };
246
+ dd: HTMLAttributes;
247
+ div: HTMLAttributes;
248
+ dl: HTMLAttributes;
249
+ dt: HTMLAttributes;
250
+ figcaption: HTMLAttributes;
251
+ figure: HTMLAttributes;
252
+ hr: HTMLAttributes;
253
+ li: HTMLAttributes & { value?: number };
254
+ ol: HTMLAttributes & { reversed?: boolean; start?: number; type?: '1' | 'a' | 'A' | 'i' | 'I' };
255
+ p: HTMLAttributes;
256
+ pre: HTMLAttributes;
257
+ ul: HTMLAttributes;
258
+
259
+ // Inline text semantics
260
+ a: AnchorHTMLAttributes;
261
+ abbr: HTMLAttributes;
262
+ b: HTMLAttributes;
263
+ bdi: HTMLAttributes;
264
+ bdo: HTMLAttributes & { dir?: 'ltr' | 'rtl' };
265
+ br: HTMLAttributes;
266
+ cite: HTMLAttributes;
267
+ code: HTMLAttributes;
268
+ data: HTMLAttributes & { value?: string };
269
+ dfn: HTMLAttributes;
270
+ em: HTMLAttributes;
271
+ i: HTMLAttributes;
272
+ kbd: HTMLAttributes;
273
+ mark: HTMLAttributes;
274
+ q: HTMLAttributes & { cite?: string };
275
+ rp: HTMLAttributes;
276
+ rt: HTMLAttributes;
277
+ ruby: HTMLAttributes;
278
+ s: HTMLAttributes;
279
+ samp: HTMLAttributes;
280
+ small: HTMLAttributes;
281
+ span: HTMLAttributes;
282
+ strong: HTMLAttributes;
283
+ sub: HTMLAttributes;
284
+ sup: HTMLAttributes;
285
+ time: HTMLAttributes & { dateTime?: string };
286
+ u: HTMLAttributes;
287
+ var: HTMLAttributes;
288
+ wbr: HTMLAttributes;
289
+
290
+ // Image and multimedia
291
+ area: HTMLAttributes & { alt?: string; coords?: string; download?: boolean | string; href?: string; shape?: string; target?: string };
292
+ audio: HTMLAttributes & { src?: string; autoPlay?: boolean; controls?: boolean; loop?: boolean; muted?: boolean; preload?: 'none' | 'metadata' | 'auto' };
293
+ img: ImgHTMLAttributes;
294
+ map: HTMLAttributes & { name?: string };
295
+ track: HTMLAttributes & { default?: boolean; kind?: string; label?: string; src?: string; srcLang?: string };
296
+ video: HTMLAttributes & { src?: string; poster?: string; autoPlay?: boolean; controls?: boolean; loop?: boolean; muted?: boolean; playsInline?: boolean; preload?: 'none' | 'metadata' | 'auto'; width?: number | string; height?: number | string };
297
+
298
+ // Embedded content
299
+ embed: HTMLAttributes & { src?: string; type?: string; width?: number | string; height?: number | string };
300
+ iframe: HTMLAttributes & { src?: string; srcdoc?: string; name?: string; sandbox?: string; allow?: string; allowFullScreen?: boolean; width?: number | string; height?: number | string; loading?: 'lazy' | 'eager' };
301
+ object: HTMLAttributes & { data?: string; type?: string; name?: string; width?: number | string; height?: number | string };
302
+ picture: HTMLAttributes;
303
+ source: HTMLAttributes & { src?: string; srcSet?: string; media?: string; sizes?: string; type?: string };
304
+
305
+ // Scripting
306
+ canvas: HTMLAttributes & { width?: number | string; height?: number | string };
307
+ noscript: HTMLAttributes;
308
+ script: HTMLAttributes & { src?: string; type?: string; async?: boolean; defer?: boolean; crossOrigin?: 'anonymous' | 'use-credentials' };
309
+
310
+ // Demarcating edits
311
+ del: HTMLAttributes & { cite?: string; dateTime?: string };
312
+ ins: HTMLAttributes & { cite?: string; dateTime?: string };
313
+
314
+ // Table content
315
+ caption: HTMLAttributes;
316
+ col: HTMLAttributes & { span?: number };
317
+ colgroup: HTMLAttributes & { span?: number };
318
+ table: HTMLAttributes;
319
+ tbody: HTMLAttributes;
320
+ td: HTMLAttributes & { colSpan?: number; rowSpan?: number; headers?: string };
321
+ tfoot: HTMLAttributes;
322
+ th: HTMLAttributes & { colSpan?: number; rowSpan?: number; headers?: string; scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' };
323
+ thead: HTMLAttributes;
324
+ tr: HTMLAttributes;
325
+
326
+ // Forms
327
+ button: ButtonHTMLAttributes;
328
+ datalist: HTMLAttributes;
329
+ fieldset: HTMLAttributes & { disabled?: boolean; name?: string };
330
+ form: FormHTMLAttributes;
331
+ input: InputHTMLAttributes;
332
+ label: LabelHTMLAttributes;
333
+ legend: HTMLAttributes;
334
+ meter: HTMLAttributes & { value?: number; min?: number; max?: number; low?: number; high?: number; optimum?: number };
335
+ optgroup: HTMLAttributes & { disabled?: boolean; label?: string };
336
+ option: OptionHTMLAttributes;
337
+ output: HTMLAttributes & { htmlFor?: string; name?: string };
338
+ progress: HTMLAttributes & { value?: number; max?: number };
339
+ select: SelectHTMLAttributes;
340
+ textarea: TextareaHTMLAttributes;
341
+
342
+ // Interactive elements
343
+ details: HTMLAttributes & { open?: boolean };
344
+ dialog: HTMLAttributes & { open?: boolean };
345
+ summary: HTMLAttributes;
346
+
347
+ // Web Components
348
+ slot: HTMLAttributes & { name?: string };
349
+ template: HTMLAttributes;
350
+
351
+ // SVG elements
352
+ svg: SVGAttributes;
353
+ path: SVGAttributes;
354
+ circle: SVGAttributes;
355
+ rect: SVGAttributes;
356
+ line: SVGAttributes;
357
+ polyline: SVGAttributes;
358
+ polygon: SVGAttributes;
359
+ text: SVGAttributes;
360
+ g: SVGAttributes;
361
+ defs: SVGAttributes;
362
+ use: SVGAttributes & { href?: string; xlinkHref?: string };
363
+ clipPath: SVGAttributes;
364
+ mask: SVGAttributes;
365
+ pattern: SVGAttributes;
366
+ linearGradient: SVGAttributes;
367
+ radialGradient: SVGAttributes;
368
+ stop: SVGAttributes & { offset?: string; stopColor?: string; stopOpacity?: number | string };
369
+ }
370
+ }
371
+ }
372
+
373
+ export {};
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Component lifecycle hook system.
3
+ * @module
4
+ */
5
+
6
+ import { ComponentInstance } from './vnode.js';
7
+
8
+ let currentInstance: ComponentInstance | null = null;
9
+
10
+ /**
11
+ * Sets the currently rendering component instance.
12
+ * Used internally by the renderer.
13
+ *
14
+ * @param instance - The component instance or null
15
+ */
16
+ export function setCurrentInstance(instance: ComponentInstance | null): void {
17
+ currentInstance = instance;
18
+ }
19
+
20
+ /**
21
+ * Returns the currently rendering component instance.
22
+ * Used internally by hooks to access component state.
23
+ *
24
+ * @returns The current component instance or null if outside a component
25
+ */
26
+ export function getCurrentInstance(): ComponentInstance | null {
27
+ return currentInstance;
28
+ }
29
+
30
+ function registerLifecycleHook(
31
+ type: 'mounted' | 'unmounted' | 'updated',
32
+ fn: () => void
33
+ ): void {
34
+ if (!currentInstance) {
35
+ if (import.meta.env?.DEV) {
36
+ console.warn(
37
+ `${type} hook called outside of component setup. ` +
38
+ `Lifecycle hooks can only be used inside a component function.`
39
+ );
40
+ }
41
+ return;
42
+ }
43
+
44
+ currentInstance[type].push(fn);
45
+ }
46
+
47
+ /**
48
+ * Registers a callback to be invoked after the component is mounted to the DOM.
49
+ * The callback runs after the initial render and DOM insertion.
50
+ *
51
+ * @param fn - The callback function to invoke on mount
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * function MyComponent() {
56
+ * onMounted(() => {
57
+ * console.log('Component mounted!');
58
+ * // DOM is available here
59
+ * });
60
+ *
61
+ * return <div>Hello</div>;
62
+ * }
63
+ * ```
64
+ */
65
+ export function onMounted(fn: () => void): void {
66
+ registerLifecycleHook('mounted', fn);
67
+ }
68
+
69
+ /**
70
+ * Registers a callback to be invoked before the component is unmounted.
71
+ * Use this to clean up side effects like timers, subscriptions, or event listeners.
72
+ *
73
+ * @param fn - The callback function to invoke on unmount
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * function MyComponent() {
78
+ * const timer = setInterval(() => {}, 1000);
79
+ *
80
+ * onUnmounted(() => {
81
+ * clearInterval(timer);
82
+ * });
83
+ *
84
+ * return <div>Hello</div>;
85
+ * }
86
+ * ```
87
+ */
88
+ export function onUnmounted(fn: () => void): void {
89
+ registerLifecycleHook('unmounted', fn);
90
+ }
91
+
92
+ /**
93
+ * Registers a callback to be invoked after the component updates.
94
+ * The callback runs after each re-render caused by reactive state changes.
95
+ *
96
+ * @param fn - The callback function to invoke after updates
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * function MyComponent() {
101
+ * const count = ref(0);
102
+ *
103
+ * onUpdated(() => {
104
+ * console.log('Component updated, count is now:', count.value);
105
+ * });
106
+ *
107
+ * return <button onClick={() => count.value++}>{count.value}</button>;
108
+ * }
109
+ * ```
110
+ */
111
+ export function onUpdated(fn: () => void): void {
112
+ registerLifecycleHook('updated', fn);
113
+ }
114
+
115
+ /**
116
+ * Invokes an array of lifecycle hook callbacks with error handling.
117
+ * Used internally by the renderer.
118
+ *
119
+ * @param hooks - Array of callback functions to invoke
120
+ * @param errorContext - Description of the hook type for error messages
121
+ */
122
+ export function invokeLifecycleHooks(
123
+ hooks: Array<() => void>,
124
+ errorContext?: string
125
+ ): void {
126
+ hooks.forEach(hook => {
127
+ try {
128
+ hook();
129
+ } catch (error) {
130
+ console.error(`Error in ${errorContext || 'lifecycle hook'}:`, error);
131
+ }
132
+ });
133
+ }