@endge/native-dom 0.1.2 → 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.
Files changed (2) hide show
  1. package/dist/native-dom.js +80 -57
  2. package/package.json +20 -16
@@ -1,20 +1,21 @@
1
- import { ENDGE_SFC_RENDER_ADAPTER_PROTOCOL_VERSION as g, ENDGE_SFC_RENDER_ADAPTER_PROTOCOL as m } from "@endge/core";
2
- function s(e, r, t) {
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 u(o, e.attrs), o.classList.add(t), y(o, e.props), d(o, e.children), o;
4
+ return S(o, e.attrs), o.classList.add(t), h(o, e.props), m(o, e.children), o;
5
5
  }
6
- function d(e, r) {
6
+ function m(e, r) {
7
7
  for (const t of r) {
8
- if (t == null || t === !1) continue;
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 u(e, r) {
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
- f(o).forEach((l) => e.classList.add(l));
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 y(e, r) {
28
- const t = c(r.colStart, r.colSpan), o = c(r.rowStart, r.rowSpan);
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 n(e, r = 1) {
32
- if (e == null || e === !1) return "";
33
- if (typeof e == "number") return `${e * r}px`;
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 i(e, r) {
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 c(e, r) {
44
- const t = p(e), o = p(r);
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 p(e) {
48
- if (e == null || e === !1 || e === "") return null;
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 f(e) {
53
- return Array.isArray(e) ? e.flatMap(f) : e && typeof e == "object" ? Object.entries(e).filter(([, r]) => !!r).map(([r]) => r) : String(e ?? "").trim().split(/\s+/).filter(Boolean);
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 b = {
56
- Text: (e) => s(e, "span", "endge-sfc-text"),
59
+ const x = {
60
+ Text: (e) => n(e, "span", "endge-sfc-text"),
57
61
  DateTime: (e) => {
58
- const r = s(e, "time", "endge-sfc-datetime");
59
- return e.props.value != null && e.children.length === 0 && (r.textContent = String(e.props.value)), 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 = s(e, "span", "endge-sfc-number");
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 = s(e, "span", "endge-sfc-icon");
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) => s(e, "span", "endge-sfc-badge"),
77
+ Badge: (e) => n(e, "span", "endge-sfc-badge"),
70
78
  Dot: (e) => {
71
- const r = s(e, "span", "endge-sfc-dot"), t = n(e.props.size, 1) || "8px";
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) => s(e, "div", "endge-sfc-box"),
82
+ Box: (e) => n(e, "div", "endge-sfc-box"),
75
83
  Flex: (e) => {
76
- const r = s(e, "div", "endge-sfc-flex"), t = e.props.col === !0 || e.props.direction === "column";
77
- return r.style.display = "flex", r.style.flexDirection = t ? "column" : "row", r.style.gap = n(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;
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 = s(e, "div", "endge-sfc-grid");
81
- return r.style.display = "grid", r.style.gridTemplateColumns = i(e.props.columns, 12), r.style.gridTemplateRows = i(e.props.rows), r.style.gridAutoRows = n(e.props.autoRows), e.props.autoFlow != null && (r.style.gridAutoFlow = String(e.props.autoFlow)), r.style.gap = n(e.props.gap, 4), r.style.columnGap = n(e.props.columnGap, 4), r.style.rowGap = n(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;
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) => s(e, "hr", "endge-sfc-divider"),
91
+ Divider: (e) => n(e, "hr", "endge-sfc-divider"),
84
92
  Input: (e) => {
85
- const r = s({ ...e, children: [] }, "input", "endge-sfc-input");
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 = s({ ...e, children: [] }, "textarea", "endge-sfc-textarea");
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 = s({ ...e, children: [] }, "label", "endge-sfc-checkbox"), t = e.document.createElement("input");
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)), d(r, e.children), r;
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 = s({ ...e, children: [] }, "select", "endge-sfc-select");
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 l = e.document.createElement("option");
109
+ const s = e.document.createElement("option");
102
110
  if (o && typeof o == "object") {
103
- const a = o;
104
- l.value = String(a.value ?? ""), l.textContent = String(a.label ?? a.value ?? "");
111
+ const l = o;
112
+ s.value = String(l.value ?? ""), s.textContent = String(l.label ?? l.value ?? "");
105
113
  } else
106
- l.value = String(o ?? ""), l.textContent = String(o ?? "");
107
- r.append(l);
114
+ s.value = String(o ?? ""), s.textContent = String(o ?? "");
115
+ r.append(s);
108
116
  }
109
117
  return r;
110
118
  }
111
- }, S = "native-dom", x = {
112
- id: S,
113
- protocol: m,
114
- protocolVersion: g,
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: b
139
+ renderers: x
117
140
  };
118
141
  export {
119
- S as NATIVE_DOM_SFC_ADAPTER_ID,
120
- x as NativeDOMSFCAdapter,
121
- b as NativeDOMVisualRenderers,
122
- d as appendNativeDOMChildren,
123
- u as applyNativeDOMAttrs,
124
- y as applyNativeDOMGridPlacement,
125
- s as createNativeDOMElement,
126
- n as normalizeNativeDOMLength,
127
- i as normalizeNativeDOMTracks
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
- "version": "0.1.2",
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.7"
28
+ "@endge/core": "^1.2.9 || ^2.0.2 || ^3.0.0 || ^4.0.0"
21
29
  },
22
30
  "devDependencies": {
23
- "@endge/core": "link:../@endge-core",
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": "^5.5.4",
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
+ }