jsx-framework-test-pb 0.0.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.
@@ -0,0 +1,4 @@
1
+ export type { Element, ElementProps, ElementChild, DevElement } from './types';
2
+ export declare function isElement(value: any): value is Element;
3
+ export declare function render(element: any, container: HTMLElement): void;
4
+ import type { Element } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ const ELEMENT_TYPE = Symbol.for('your.framework.element');
2
+ export function isElement(value) {
3
+ return value && value.$$typeof === ELEMENT_TYPE;
4
+ }
5
+ export function render(element, container) {
6
+ container.innerHTML = '';
7
+ const domNode = createElement(element);
8
+ if (domNode) {
9
+ container.appendChild(domNode);
10
+ }
11
+ }
12
+ function createElement(element) {
13
+ if (element === null ||
14
+ element === undefined ||
15
+ typeof element === 'boolean') {
16
+ return null;
17
+ }
18
+ if (typeof element === 'string' || typeof element === 'number') {
19
+ return document.createTextNode(String(element));
20
+ }
21
+ if (Array.isArray(element)) {
22
+ const fragment = document.createDocumentFragment();
23
+ element.forEach(child => {
24
+ const node = createElement(child);
25
+ if (node)
26
+ fragment.appendChild(node);
27
+ });
28
+ return fragment;
29
+ }
30
+ if (!isElement(element)) {
31
+ return null;
32
+ }
33
+ const { type, props } = element;
34
+ if (typeof type === 'function') {
35
+ const result = type(props);
36
+ return createElement(result);
37
+ }
38
+ if (typeof type === 'string') {
39
+ const domElement = document.createElement(type);
40
+ Object.keys(props).forEach(key => {
41
+ if (key === 'children') {
42
+ const children = Array.isArray(props.children)
43
+ ? props.children
44
+ : [props.children];
45
+ children.forEach(child => {
46
+ const childNode = createElement(child);
47
+ if (childNode) {
48
+ domElement.appendChild(childNode);
49
+ }
50
+ });
51
+ }
52
+ else if (key.startsWith('on') && typeof props[key] === 'function') {
53
+ const eventName = key.substring(2).toLowerCase();
54
+ domElement.addEventListener(eventName, props[key]);
55
+ }
56
+ else if (key === 'className') {
57
+ domElement.setAttribute('class', props[key]);
58
+ }
59
+ else if (key === 'style' && typeof props[key] === 'object') {
60
+ Object.assign(domElement.style, props[key]);
61
+ }
62
+ else if (key !== 'key') {
63
+ domElement.setAttribute(key, props[key]);
64
+ }
65
+ });
66
+ return domElement;
67
+ }
68
+ return null;
69
+ }
@@ -0,0 +1,6 @@
1
+ import type { DevElement, ElementProps } from './types';
2
+ export declare function jsxDEV(type: string | Function, props: ElementProps, key?: string, isStaticChildren?: boolean, source?: {
3
+ fileName: string;
4
+ lineNumber: number;
5
+ columnNumber: number;
6
+ }, self?: any): DevElement;
@@ -0,0 +1,11 @@
1
+ const ELEMENT_TYPE = Symbol.for('your.framework.element');
2
+ export function jsxDEV(type, props, key, isStaticChildren, source, self) {
3
+ return {
4
+ $$typeof: ELEMENT_TYPE,
5
+ type,
6
+ props,
7
+ key: key ?? null,
8
+ _source: source,
9
+ _self: self,
10
+ };
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { Element, ElementProps } from './types';
2
+ export declare function jsx(type: string | Function, props: ElementProps, key?: string): Element;
3
+ export declare const jsxs: typeof jsx;
@@ -0,0 +1,10 @@
1
+ const ELEMENT_TYPE = Symbol.for('your.framework.element');
2
+ export function jsx(type, props, key) {
3
+ return {
4
+ $$typeof: ELEMENT_TYPE,
5
+ type,
6
+ props,
7
+ key: key ?? null,
8
+ };
9
+ }
10
+ export const jsxs = jsx;
@@ -0,0 +1,48 @@
1
+ export interface Element {
2
+ $$typeof: symbol;
3
+ type: string | Function;
4
+ props: ElementProps;
5
+ key: string | null;
6
+ }
7
+ export interface DevElement extends Element {
8
+ _source?: {
9
+ fileName: string;
10
+ lineNumber: number;
11
+ columnNumber: number;
12
+ };
13
+ _self?: any;
14
+ }
15
+ export interface ElementProps {
16
+ children?: ElementChild | ElementChild[];
17
+ [key: string]: any;
18
+ }
19
+ export type ElementChild = Element | string | number | boolean | null | undefined;
20
+ declare global {
21
+ namespace JSX {
22
+ interface Element {
23
+ }
24
+ interface IntrinsicElements {
25
+ div: ElementProps;
26
+ span: ElementProps;
27
+ h1: ElementProps;
28
+ h2: ElementProps;
29
+ h3: ElementProps;
30
+ h4: ElementProps;
31
+ h5: ElementProps;
32
+ h6: ElementProps;
33
+ p: ElementProps;
34
+ button: ElementProps;
35
+ input: ElementProps;
36
+ a: ElementProps;
37
+ img: ElementProps;
38
+ ul: ElementProps;
39
+ ol: ElementProps;
40
+ li: ElementProps;
41
+ [elemName: string]: ElementProps;
42
+ }
43
+ interface ElementChildrenAttribute {
44
+ children: {};
45
+ }
46
+ }
47
+ }
48
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "jsx-framework-test-pb",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./jsx-runtime": {
14
+ "types": "./dist/jsx-runtime.d.ts",
15
+ "default": "./dist/jsx-runtime.js"
16
+ },
17
+ "./jsx-dev-runtime": {
18
+ "types": "./dist/jsx-dev-runtime.d.ts",
19
+ "default": "./dist/jsx-dev-runtime.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "dev": "tsc --watch",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.9.3"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ]
33
+ }