@zeus-js/zeus 0.0.2 → 0.1.0-beta.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/jsx-runtime.js CHANGED
@@ -1 +1,80 @@
1
- export { Fragment, jsx, jsxs, jsxDEV } from '@zeus-js/runtime-dom'
1
+ import {
2
+ createComponent,
3
+ insert,
4
+ } from '@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js'
5
+
6
+ const Fragment = Symbol.for('zeus.fragment')
7
+
8
+ function jsx(type, props) {
9
+ return createJSXNode(type, props)
10
+ }
11
+
12
+ function jsxs(type, props) {
13
+ return createJSXNode(type, props)
14
+ }
15
+
16
+ function jsxDEV(type, props) {
17
+ return createJSXNode(type, props)
18
+ }
19
+
20
+ function createJSXNode(type, props) {
21
+ if (type === Fragment) {
22
+ return props?.children
23
+ }
24
+
25
+ if (typeof type === 'function') {
26
+ return createComponent(type, props ?? {})
27
+ }
28
+
29
+ if (typeof type !== 'string') {
30
+ return null
31
+ }
32
+
33
+ const el = document.createElement(type)
34
+
35
+ if (props) {
36
+ const children = props.children
37
+
38
+ for (const key of Object.keys(props)) {
39
+ if (key === 'children') continue
40
+
41
+ const value = props[key]
42
+
43
+ if (key.startsWith('on') && typeof value === 'function') {
44
+ el.addEventListener(key.slice(2).toLowerCase(), value)
45
+ } else if (key === 'ref') {
46
+ setFallbackRef(value, el)
47
+ } else if (value != null && value !== false) {
48
+ el.setAttribute(key === 'className' ? 'class' : key, String(value))
49
+ }
50
+ }
51
+
52
+ if (children !== undefined) {
53
+ insert(el, children)
54
+ }
55
+ }
56
+
57
+ return el
58
+ }
59
+
60
+ function setFallbackRef(target, el) {
61
+ if (target == null) return
62
+
63
+ if (typeof target === 'function') {
64
+ target(el)
65
+ return
66
+ }
67
+
68
+ if (typeof target === 'object') {
69
+ if ('value' in target) {
70
+ target.value = el
71
+ return
72
+ }
73
+
74
+ if ('current' in target) {
75
+ target.current = el
76
+ }
77
+ }
78
+ }
79
+
80
+ export { Fragment, jsx, jsxs, jsxDEV }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeus-js/zeus",
3
- "version": "0.0.2",
3
+ "version": "0.1.0-beta.0",
4
4
  "description": "@zeus-js/zeus",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -46,7 +46,7 @@
46
46
  "repository": {
47
47
  "type": "git",
48
48
  "url": "git+https://github.com/baicie/zeus.git",
49
- "directory": "packages/zeus"
49
+ "directory": "packages/core/zeus"
50
50
  },
51
51
  "buildOptions": {
52
52
  "name": "Zeus",
@@ -65,9 +65,9 @@
65
65
  "bugs": {
66
66
  "url": "https://github.com/baicie/zeus/issues"
67
67
  },
68
- "homepage": "https://github.com/baicie/zeus/tree/main/packages/zeus#readme",
68
+ "homepage": "https://github.com/baicie/zeus/tree/main/packages/core/zeus#readme",
69
69
  "dependencies": {
70
- "@zeus-js/signal": "0.0.2",
71
- "@zeus-js/runtime-dom": "0.0.2"
70
+ "@zeus-js/runtime-dom": "0.1.0-beta.0",
71
+ "@zeus-js/signal": "0.1.0-beta.0"
72
72
  }
73
73
  }
package/src/jsx.d.ts CHANGED
@@ -63,6 +63,7 @@ type HTMLAttributes<T extends HTMLElement> = CommonDOMAttributes<T> & {
63
63
  [key: `data-${string}`]: PrimitiveAttr
64
64
  [key: `aria-${string}`]: PrimitiveAttr
65
65
  [key: `prop:${string}`]: unknown
66
+ [key: string]: unknown
66
67
  type?: string
67
68
  checked?: boolean
68
69
  value?: string | number