@endge/native-dom 0.1.3 → 0.1.8
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/dist/native-dom.js +80 -57
- package/package.json +20 -16
package/dist/native-dom.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { ENDGE_SFC_RENDER_ADAPTER_PROTOCOL_VERSION as
|
|
2
|
-
function
|
|
1
|
+
import { ENDGE_SFC_RENDER_ADAPTER_PROTOCOL_VERSION as y, ENDGE_SFC_RENDER_ADAPTER_PROTOCOL as b } from "@endge/core";
|
|
2
|
+
function n(e, r, t) {
|
|
3
3
|
const o = e.document.createElement(r);
|
|
4
|
-
return
|
|
4
|
+
return S(o, e.attrs), o.classList.add(t), h(o, e.props), m(o, e.children), o;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function m(e, r) {
|
|
7
7
|
for (const t of r) {
|
|
8
|
-
if (t == null || t === !1)
|
|
8
|
+
if (t == null || t === !1)
|
|
9
|
+
continue;
|
|
9
10
|
const o = typeof t == "object" && "nodeType" in t;
|
|
10
11
|
e.append(o ? t : String(t));
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function S(e, r) {
|
|
14
15
|
for (const [t, o] of Object.entries(r))
|
|
15
16
|
if (!(o == null || o === !1 || t === "key")) {
|
|
16
17
|
if (t === "class") {
|
|
17
|
-
|
|
18
|
+
u(o).forEach((s) => e.classList.add(s));
|
|
18
19
|
continue;
|
|
19
20
|
}
|
|
20
21
|
if (t === "style" && o && typeof o == "object") {
|
|
@@ -24,105 +25,127 @@ function u(e, r) {
|
|
|
24
25
|
t.startsWith("on") || e.setAttribute(t, o === !0 ? "" : String(o));
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
const t =
|
|
28
|
+
function h(e, r) {
|
|
29
|
+
const t = d(r.colStart, r.colSpan), o = d(r.rowStart, r.rowSpan);
|
|
29
30
|
t && (e.style.gridColumn = t), o && (e.style.gridRow = o);
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
-
if (e == null || e === !1)
|
|
33
|
-
|
|
32
|
+
function i(e, r = 1) {
|
|
33
|
+
if (e == null || e === !1)
|
|
34
|
+
return "";
|
|
35
|
+
if (typeof e == "number")
|
|
36
|
+
return `${e * r}px`;
|
|
34
37
|
const t = String(e).trim();
|
|
35
38
|
return /^-?\d+(\.\d+)?$/.test(t) ? `${Number(t) * r}px` : t;
|
|
36
39
|
}
|
|
37
|
-
function
|
|
40
|
+
function p(e, r) {
|
|
38
41
|
if (e == null || e === !1 || String(e).trim() === "")
|
|
39
42
|
return r ? `repeat(${r}, minmax(0, 1fr))` : "";
|
|
40
43
|
const t = String(e).trim();
|
|
41
44
|
return /^\d+$/.test(t) && Number(t) > 0 ? `repeat(${Number(t)}, minmax(0, 1fr))` : t;
|
|
42
45
|
}
|
|
43
|
-
function
|
|
44
|
-
const t =
|
|
46
|
+
function d(e, r) {
|
|
47
|
+
const t = f(e), o = f(r);
|
|
45
48
|
return t != null && o != null ? `${t} / span ${o}` : t != null ? String(t) : o != null ? `span ${o}` : "";
|
|
46
49
|
}
|
|
47
|
-
function
|
|
48
|
-
if (e == null || e === !1 || e === "")
|
|
50
|
+
function f(e) {
|
|
51
|
+
if (e == null || e === !1 || e === "")
|
|
52
|
+
return null;
|
|
49
53
|
const r = Number(e);
|
|
50
54
|
return Number.isInteger(r) && r > 0 ? r : null;
|
|
51
55
|
}
|
|
52
|
-
function
|
|
53
|
-
return Array.isArray(e) ? e.flatMap(
|
|
56
|
+
function u(e) {
|
|
57
|
+
return Array.isArray(e) ? e.flatMap(u) : e && typeof e == "object" ? Object.entries(e).filter(([, r]) => !!r).map(([r]) => r) : String(e ?? "").trim().split(/\s+/).filter(Boolean);
|
|
54
58
|
}
|
|
55
|
-
const
|
|
56
|
-
Text: (e) =>
|
|
59
|
+
const x = {
|
|
60
|
+
Text: (e) => n(e, "span", "endge-sfc-text"),
|
|
57
61
|
DateTime: (e) => {
|
|
58
|
-
const r =
|
|
59
|
-
return e.props.value != null && e.children.length === 0 && (r.
|
|
62
|
+
const r = n(e, "time", "endge-sfc-datetime");
|
|
63
|
+
return e.props.value != null && e.children.length === 0 && (r.dateTime = String(e.props.value), r.textContent = w(
|
|
64
|
+
e.props.value,
|
|
65
|
+
e.props.format,
|
|
66
|
+
e.props.timezone
|
|
67
|
+
)), r;
|
|
60
68
|
},
|
|
61
69
|
Number: (e) => {
|
|
62
|
-
const r =
|
|
70
|
+
const r = n(e, "span", "endge-sfc-number");
|
|
63
71
|
return e.props.value != null && e.children.length === 0 && (r.textContent = String(e.props.value)), r;
|
|
64
72
|
},
|
|
65
73
|
Icon: (e) => {
|
|
66
|
-
const r =
|
|
74
|
+
const r = n(e, "span", "endge-sfc-icon");
|
|
67
75
|
return r.setAttribute("aria-hidden", e.props.label == null ? "true" : "false"), e.props.label != null && r.setAttribute("aria-label", String(e.props.label)), e.props.name != null && e.children.length === 0 && (r.textContent = String(e.props.name)), r;
|
|
68
76
|
},
|
|
69
|
-
Badge: (e) =>
|
|
77
|
+
Badge: (e) => n(e, "span", "endge-sfc-badge"),
|
|
70
78
|
Dot: (e) => {
|
|
71
|
-
const r =
|
|
79
|
+
const r = n(e, "span", "endge-sfc-dot"), t = i(e.props.size, 1) || "8px";
|
|
72
80
|
return r.style.display = "inline-block", r.style.width = t, r.style.height = t, r.style.borderRadius = "9999px", r;
|
|
73
81
|
},
|
|
74
|
-
Box: (e) =>
|
|
82
|
+
Box: (e) => n(e, "div", "endge-sfc-box"),
|
|
75
83
|
Flex: (e) => {
|
|
76
|
-
const r =
|
|
77
|
-
return r.style.display = "flex", r.style.flexDirection = t ? "column" : "row", r.style.gap =
|
|
84
|
+
const r = n(e, "div", "endge-sfc-flex"), t = e.props.col === !0 || e.props.direction === "column";
|
|
85
|
+
return r.style.display = "flex", r.style.flexDirection = t ? "column" : "row", r.style.gap = i(e.props.gap, 4), e.props.align != null && (r.style.alignItems = String(e.props.align)), e.props.justify != null && (r.style.justifyContent = String(e.props.justify)), (e.props.wrap === !0 || e.props.wrap === "wrap") && (r.style.flexWrap = "wrap"), r;
|
|
78
86
|
},
|
|
79
87
|
Grid: (e) => {
|
|
80
|
-
const r =
|
|
81
|
-
return r.style.display = "grid", r.style.gridTemplateColumns =
|
|
88
|
+
const r = n(e, "div", "endge-sfc-grid");
|
|
89
|
+
return r.style.display = "grid", r.style.gridTemplateColumns = p(e.props.columns, 12), r.style.gridTemplateRows = p(e.props.rows), r.style.gridAutoRows = i(e.props.autoRows), e.props.autoFlow != null && (r.style.gridAutoFlow = String(e.props.autoFlow)), r.style.gap = i(e.props.gap, 4), r.style.columnGap = i(e.props.columnGap, 4), r.style.rowGap = i(e.props.rowGap, 4), e.props.align != null && (r.style.alignItems = String(e.props.align)), e.props.justify != null && (r.style.justifyItems = String(e.props.justify)), r;
|
|
82
90
|
},
|
|
83
|
-
Divider: (e) =>
|
|
91
|
+
Divider: (e) => n(e, "hr", "endge-sfc-divider"),
|
|
84
92
|
Input: (e) => {
|
|
85
|
-
const r =
|
|
93
|
+
const r = n({ ...e, children: [] }, "input", "endge-sfc-input");
|
|
86
94
|
return e.props.type != null && (r.type = String(e.props.type).toLowerCase()), e.props.value != null && (r.value = String(e.props.value)), e.props.placeholder != null && (r.placeholder = String(e.props.placeholder)), e.props.disabled === !0 && (r.disabled = !0), r;
|
|
87
95
|
},
|
|
88
96
|
Textarea: (e) => {
|
|
89
|
-
const r =
|
|
97
|
+
const r = n({ ...e, children: [] }, "textarea", "endge-sfc-textarea");
|
|
90
98
|
return e.props.value != null && (r.value = String(e.props.value)), e.props.placeholder != null && (r.placeholder = String(e.props.placeholder)), e.props.rows != null && (r.rows = Math.max(1, Number(e.props.rows) || 1)), e.props.disabled === !0 && (r.disabled = !0), r;
|
|
91
99
|
},
|
|
92
100
|
Checkbox: (e) => {
|
|
93
|
-
const r =
|
|
94
|
-
return t.type = "checkbox", t.checked = e.props.checked === !0, t.disabled = e.props.disabled === !0, r.append(t), e.props.label != null && r.append(String(e.props.label)),
|
|
101
|
+
const r = n({ ...e, children: [] }, "label", "endge-sfc-checkbox"), t = e.document.createElement("input");
|
|
102
|
+
return t.type = "checkbox", t.checked = e.props.checked === !0, t.disabled = e.props.disabled === !0, r.append(t), e.props.label != null && r.append(String(e.props.label)), m(r, e.children), r;
|
|
95
103
|
},
|
|
96
104
|
Select: (e) => {
|
|
97
|
-
const r =
|
|
105
|
+
const r = n({ ...e, children: [] }, "select", "endge-sfc-select");
|
|
98
106
|
r.multiple = e.props.multiple === !0, r.disabled = e.props.disabled === !0;
|
|
99
107
|
const t = Array.isArray(e.props.options) ? e.props.options : [];
|
|
100
108
|
for (const o of t) {
|
|
101
|
-
const
|
|
109
|
+
const s = e.document.createElement("option");
|
|
102
110
|
if (o && typeof o == "object") {
|
|
103
|
-
const
|
|
104
|
-
|
|
111
|
+
const l = o;
|
|
112
|
+
s.value = String(l.value ?? ""), s.textContent = String(l.label ?? l.value ?? "");
|
|
105
113
|
} else
|
|
106
|
-
|
|
107
|
-
r.append(
|
|
114
|
+
s.value = String(o ?? ""), s.textContent = String(o ?? "");
|
|
115
|
+
r.append(s);
|
|
108
116
|
}
|
|
109
117
|
return r;
|
|
110
118
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
};
|
|
120
|
+
function w(e, r, t) {
|
|
121
|
+
const o = String(e ?? "").trim(), s = r === "HH:mm" ? o.match(/^(\d{2}):(\d{2})(?::\d{2})?$/) : null;
|
|
122
|
+
if (s)
|
|
123
|
+
return `${s[1]}:${s[2]}`;
|
|
124
|
+
const l = new Date(o);
|
|
125
|
+
if (Number.isNaN(l.getTime()))
|
|
126
|
+
return o;
|
|
127
|
+
const a = String(t ?? "").trim(), g = !a || a === "local" ? void 0 : a, c = r === "HH:mm" ? { hour: "2-digit", minute: "2-digit", hour12: !1 } : r === "date" ? {} : { dateStyle: "medium", timeStyle: "short" };
|
|
128
|
+
try {
|
|
129
|
+
return new Intl.DateTimeFormat(void 0, { ...c, timeZone: g }).format(l);
|
|
130
|
+
} catch {
|
|
131
|
+
return new Intl.DateTimeFormat(void 0, c).format(l);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const D = "native-dom", v = {
|
|
135
|
+
id: D,
|
|
136
|
+
protocol: b,
|
|
137
|
+
protocolVersion: y,
|
|
115
138
|
renderer: "native-dom",
|
|
116
|
-
renderers:
|
|
139
|
+
renderers: x
|
|
117
140
|
};
|
|
118
141
|
export {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
D as NATIVE_DOM_SFC_ADAPTER_ID,
|
|
143
|
+
v as NativeDOMSFCAdapter,
|
|
144
|
+
x as NativeDOMVisualRenderers,
|
|
145
|
+
m as appendNativeDOMChildren,
|
|
146
|
+
S as applyNativeDOMAttrs,
|
|
147
|
+
h as applyNativeDOMGridPlacement,
|
|
148
|
+
n as createNativeDOMElement,
|
|
149
|
+
i as normalizeNativeDOMLength,
|
|
150
|
+
p as normalizeNativeDOMTracks
|
|
128
151
|
};
|
package/package.json
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@endge/native-dom",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.8",
|
|
4
5
|
"private": false,
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./dist/native-dom.js",
|
|
8
|
-
"module": "./dist/native-dom.js",
|
|
9
|
-
"types": "./dist/main.d.ts",
|
|
10
7
|
"exports": {
|
|
11
8
|
".": {
|
|
12
9
|
"types": "./dist/main.d.ts",
|
|
13
10
|
"import": "./dist/native-dom.js"
|
|
14
11
|
}
|
|
15
12
|
},
|
|
13
|
+
"main": "./dist/native-dom.js",
|
|
14
|
+
"module": "./dist/native-dom.js",
|
|
15
|
+
"types": "./dist/main.d.ts",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"lint-check": "eslint . --cache",
|
|
25
|
+
"lint-fix": "eslint . --fix --cache"
|
|
26
|
+
},
|
|
19
27
|
"peerDependencies": {
|
|
20
|
-
"@endge/core": "^1.2.9"
|
|
28
|
+
"@endge/core": "^1.2.9 || ^2.0.2 || ^3.0.0 || ^4.0.0"
|
|
21
29
|
},
|
|
22
30
|
"devDependencies": {
|
|
23
|
-
"@
|
|
31
|
+
"@antfu/eslint-config": "9.3.0",
|
|
32
|
+
"@endge/core": "^4.0.0",
|
|
33
|
+
"eslint": "10.9.1",
|
|
24
34
|
"jsdom": "^26.1.0",
|
|
25
35
|
"rimraf": "^6.0.1",
|
|
26
|
-
"typescript": "
|
|
36
|
+
"typescript": "~6.0.3",
|
|
37
|
+
"unplugin-dts": "^1.0.3",
|
|
27
38
|
"vite": "^6.1.0",
|
|
28
|
-
"vite-plugin-dts": "^4.5.0",
|
|
29
39
|
"vitest": "^2.1.9"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
33
|
-
"build": "vite build",
|
|
34
|
-
"test": "vitest",
|
|
35
|
-
"typecheck": "tsc --noEmit"
|
|
36
40
|
}
|
|
37
|
-
}
|
|
41
|
+
}
|