airx 0.7.0 → 0.7.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.
- package/output/app/app.d.ts +32 -2
- package/output/app/app.d.ts.map +1 -1
- package/output/app/app.js +51 -0
- package/output/app/app.js.map +1 -0
- package/output/app/index.d.ts +1 -1
- package/output/app/index.d.ts.map +1 -1
- package/output/app/index.js +2 -0
- package/output/app/index.js.map +1 -0
- package/output/element/element.d.ts +67 -8
- package/output/element/element.d.ts.map +1 -1
- package/output/element/element.js +106 -0
- package/output/element/element.js.map +1 -0
- package/output/element/index.d.ts +1 -1
- package/output/element/index.d.ts.map +1 -1
- package/output/element/index.js +2 -0
- package/output/element/index.js.map +1 -0
- package/output/index.d.ts +39 -5
- package/output/index.d.ts.map +1 -1
- package/output/index.js +36 -711
- package/output/index.js.map +1 -0
- package/output/jsx-dev-runtime.d.ts +4 -0
- package/output/jsx-dev-runtime.d.ts.map +1 -0
- package/output/jsx-dev-runtime.js +9 -0
- package/output/jsx-dev-runtime.js.map +1 -0
- package/output/jsx-runtime.d.ts +23 -0
- package/output/jsx-runtime.d.ts.map +1 -0
- package/output/jsx-runtime.js +24 -0
- package/output/jsx-runtime.js.map +1 -0
- package/output/logger/index.d.ts +1 -1
- package/output/logger/index.d.ts.map +1 -1
- package/output/logger/index.js +2 -0
- package/output/logger/index.js.map +1 -0
- package/output/logger/logger.js +17 -0
- package/output/logger/logger.js.map +1 -0
- package/output/render/basic/common.d.ts +3 -3
- package/output/render/basic/common.d.ts.map +1 -1
- package/output/render/basic/common.js +436 -0
- package/output/render/basic/common.js.map +1 -0
- package/output/render/basic/hooks/hooks.d.ts +51 -1
- package/output/render/basic/hooks/hooks.d.ts.map +1 -1
- package/output/render/basic/hooks/hooks.js +72 -0
- package/output/render/basic/hooks/hooks.js.map +1 -0
- package/output/render/basic/hooks/index.d.ts +1 -1
- package/output/render/basic/hooks/index.d.ts.map +1 -1
- package/output/render/basic/hooks/index.js +2 -0
- package/output/render/basic/hooks/index.js.map +1 -0
- package/output/render/basic/index.d.ts +1 -1
- package/output/render/basic/index.d.ts.map +1 -1
- package/output/render/basic/index.js +2 -0
- package/output/render/basic/index.js.map +1 -0
- package/output/render/basic/plugins/context/context.d.ts +1 -1
- package/output/render/basic/plugins/context/context.d.ts.map +1 -1
- package/output/render/basic/plugins/context/context.js +12 -0
- package/output/render/basic/plugins/context/context.js.map +1 -0
- package/output/render/basic/plugins/context/index.d.ts +1 -1
- package/output/render/basic/plugins/context/index.d.ts.map +1 -1
- package/output/render/basic/plugins/context/index.js +2 -0
- package/output/render/basic/plugins/context/index.js.map +1 -0
- package/output/render/basic/plugins/index.d.ts +2 -2
- package/output/render/basic/plugins/index.d.ts.map +1 -1
- package/output/render/basic/plugins/index.js +2 -0
- package/output/render/basic/plugins/index.js.map +1 -0
- package/output/render/basic/plugins/internal/basic/basic.d.ts +3 -3
- package/output/render/basic/plugins/internal/basic/basic.d.ts.map +1 -1
- package/output/render/basic/plugins/internal/basic/basic.js +158 -0
- package/output/render/basic/plugins/internal/basic/basic.js.map +1 -0
- package/output/render/basic/plugins/internal/basic/index.d.ts +1 -1
- package/output/render/basic/plugins/internal/basic/index.d.ts.map +1 -1
- package/output/render/basic/plugins/internal/basic/index.js +2 -0
- package/output/render/basic/plugins/internal/basic/index.js.map +1 -0
- package/output/render/basic/plugins/internal/inject/index.d.ts +1 -1
- package/output/render/basic/plugins/internal/inject/index.d.ts.map +1 -1
- package/output/render/basic/plugins/internal/inject/index.js +2 -0
- package/output/render/basic/plugins/internal/inject/index.js.map +1 -0
- package/output/render/basic/plugins/internal/inject/inject.d.ts +2 -2
- package/output/render/basic/plugins/internal/inject/inject.d.ts.map +1 -1
- package/output/render/basic/plugins/internal/inject/inject.js +25 -0
- package/output/render/basic/plugins/internal/inject/inject.js.map +1 -0
- package/output/render/basic/plugins/plugin.d.ts +2 -2
- package/output/render/basic/plugins/plugin.d.ts.map +1 -1
- package/output/render/basic/plugins/plugin.js +2 -0
- package/output/render/basic/plugins/plugin.js.map +1 -0
- package/output/render/browser/browser.d.ts +3 -3
- package/output/render/browser/browser.d.ts.map +1 -1
- package/output/render/browser/browser.js +218 -0
- package/output/render/browser/browser.js.map +1 -0
- package/output/render/browser/index.d.ts +1 -1
- package/output/render/browser/index.d.ts.map +1 -1
- package/output/render/browser/index.js +2 -0
- package/output/render/browser/index.js.map +1 -0
- package/output/render/index.d.ts +4 -4
- package/output/render/index.d.ts.map +1 -1
- package/output/render/index.js +5 -0
- package/output/render/index.js.map +1 -0
- package/output/render/server/index.d.ts +1 -1
- package/output/render/server/index.d.ts.map +1 -1
- package/output/render/server/index.js +2 -0
- package/output/render/server/index.js.map +1 -0
- package/output/render/server/server.d.ts +2 -2
- package/output/render/server/server.d.ts.map +1 -1
- package/output/render/server/server.js +314 -0
- package/output/render/server/server.js.map +1 -0
- package/output/signal/index.d.ts +2 -2
- package/output/signal/index.d.ts.map +1 -1
- package/output/signal/index.js +2 -0
- package/output/signal/index.js.map +1 -0
- package/output/signal/signal.d.ts +1 -1
- package/output/signal/signal.js +46 -0
- package/output/signal/signal.js.map +1 -0
- package/output/symbol/index.js +2 -0
- package/output/symbol/index.js.map +1 -0
- package/output/types/index.d.ts +1 -1
- package/output/types/index.d.ts.map +1 -1
- package/output/types/index.js +2 -0
- package/output/types/index.js.map +1 -0
- package/output/types/types.d.ts +2 -2
- package/output/types/types.d.ts.map +1 -1
- package/output/types/types.js +2 -0
- package/output/types/types.js.map +1 -0
- package/package.json +17 -14
- package/output/app/app.test.d.ts +0 -2
- package/output/app/app.test.d.ts.map +0 -1
- package/output/element/element.test.d.ts +0 -2
- package/output/element/element.test.d.ts.map +0 -1
- package/output/index.umd.cjs +0 -1
- package/output/logger/logger.test.d.ts +0 -2
- package/output/logger/logger.test.d.ts.map +0 -1
- package/output/render/basic/common.test.d.ts +0 -2
- package/output/render/basic/common.test.d.ts.map +0 -1
- package/output/render/basic/hooks/hooks.test.d.ts +0 -2
- package/output/render/basic/hooks/hooks.test.d.ts.map +0 -1
- package/output/render/basic/plugins/context/context.test.d.ts +0 -2
- package/output/render/basic/plugins/context/context.test.d.ts.map +0 -1
- package/output/render/basic/plugins/internal/basic/basic.test.d.ts +0 -2
- package/output/render/basic/plugins/internal/basic/basic.test.d.ts.map +0 -1
- package/output/render/basic/plugins/internal/inject/inject.test.d.ts +0 -2
- package/output/render/basic/plugins/internal/inject/inject.test.d.ts.map +0 -1
- package/output/render/basic/plugins/plugin.test.d.ts +0 -2
- package/output/render/basic/plugins/plugin.test.d.ts.map +0 -1
- package/output/render/browser/browser.test.d.ts +0 -2
- package/output/render/browser/browser.test.d.ts.map +0 -1
- package/output/render/server/server.test.d.ts +0 -2
- package/output/render/server/server.test.d.ts.map +0 -1
- package/output/signal/signal.test.d.ts +0 -5
- package/output/signal/signal.test.d.ts.map +0 -1
package/output/index.js
CHANGED
|
@@ -1,711 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
function J(l) {
|
|
39
|
-
const e = K();
|
|
40
|
-
return new e.subtle.Watcher(l);
|
|
41
|
-
}
|
|
42
|
-
function Y(l, e) {
|
|
43
|
-
const n = K();
|
|
44
|
-
return new n.Computed(l, e);
|
|
45
|
-
}
|
|
46
|
-
function Z(l) {
|
|
47
|
-
const e = K();
|
|
48
|
-
return l instanceof e.State;
|
|
49
|
-
}
|
|
50
|
-
const G = /* @__PURE__ */ Symbol("airx-element");
|
|
51
|
-
function F(l, e, ...n) {
|
|
52
|
-
const i = [];
|
|
53
|
-
return n.length > 0 ? i.push(...n) : e && e.children && i.push(e.children), {
|
|
54
|
-
type: l,
|
|
55
|
-
props: {
|
|
56
|
-
...e,
|
|
57
|
-
children: i
|
|
58
|
-
},
|
|
59
|
-
[G]: !0
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function T(l) {
|
|
63
|
-
return typeof l == "object" && l !== null && Reflect.get(l, G) === !0;
|
|
64
|
-
}
|
|
65
|
-
function ce(l) {
|
|
66
|
-
return () => l.children;
|
|
67
|
-
}
|
|
68
|
-
function ue(l) {
|
|
69
|
-
return l;
|
|
70
|
-
}
|
|
71
|
-
function $(l) {
|
|
72
|
-
console.error(l);
|
|
73
|
-
const e = () => {
|
|
74
|
-
console.error(l);
|
|
75
|
-
}, n = () => l == null ? "Unknown rendering error" : l instanceof Error ? l.message : JSON.stringify(l), i = {
|
|
76
|
-
padding: "8px",
|
|
77
|
-
fontSize: "20px",
|
|
78
|
-
color: "rgb(255,255,255)",
|
|
79
|
-
backgroundColor: "rgb(255, 0, 0)"
|
|
80
|
-
};
|
|
81
|
-
return () => F("div", { style: i, onClick: e }, n());
|
|
82
|
-
}
|
|
83
|
-
class M {
|
|
84
|
-
instance;
|
|
85
|
-
disposers = /* @__PURE__ */ new Set();
|
|
86
|
-
providedMap = /* @__PURE__ */ new Map();
|
|
87
|
-
injectedMap = /* @__PURE__ */ new Map();
|
|
88
|
-
mountListeners = /* @__PURE__ */ new Set();
|
|
89
|
-
unmountedListeners = /* @__PURE__ */ new Set();
|
|
90
|
-
triggerMounted() {
|
|
91
|
-
this.mountListeners.forEach((e) => {
|
|
92
|
-
let n;
|
|
93
|
-
try {
|
|
94
|
-
n = e();
|
|
95
|
-
} catch (i) {
|
|
96
|
-
console.error(i, e);
|
|
97
|
-
}
|
|
98
|
-
typeof n == "function" && this.addDisposer(n);
|
|
99
|
-
}), this.mountListeners.clear();
|
|
100
|
-
}
|
|
101
|
-
triggerUnmounted() {
|
|
102
|
-
this.instance?.child != null && this.instance.child.context.triggerUnmounted(), this.unmountedListeners.forEach((e) => {
|
|
103
|
-
try {
|
|
104
|
-
e();
|
|
105
|
-
} catch (n) {
|
|
106
|
-
console.error(n, e);
|
|
107
|
-
}
|
|
108
|
-
}), this.instance?.sibling != null && this.instance.sibling.context.triggerUnmounted(), this.dispose();
|
|
109
|
-
}
|
|
110
|
-
onMounted(e) {
|
|
111
|
-
this.mountListeners.add(e);
|
|
112
|
-
}
|
|
113
|
-
onUnmounted(e) {
|
|
114
|
-
this.unmountedListeners.add(e);
|
|
115
|
-
}
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
-
provide(e, n) {
|
|
118
|
-
return this.providedMap.set(e, n), (i) => {
|
|
119
|
-
if (typeof i == "function") {
|
|
120
|
-
const o = this.providedMap.get(e), m = i;
|
|
121
|
-
this.providedMap.set(e, m(o));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.providedMap.set(e, i);
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
inject(e) {
|
|
129
|
-
const n = (o, m) => {
|
|
130
|
-
if (o && o.context) {
|
|
131
|
-
const a = o.context.providedMap.get(m);
|
|
132
|
-
if (a != null) return a;
|
|
133
|
-
if (o.parent) return n(o.parent, m);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
if (!this.instance || !this.instance.parent)
|
|
137
|
-
return this.injectedMap.get(e);
|
|
138
|
-
const i = n(this.instance.parent, e);
|
|
139
|
-
return this.injectedMap.set(e, i), this.injectedMap.get(e);
|
|
140
|
-
}
|
|
141
|
-
addDisposer(...e) {
|
|
142
|
-
e.forEach((n) => {
|
|
143
|
-
this.disposers.add(n);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
dispose() {
|
|
147
|
-
this.disposers.forEach(
|
|
148
|
-
(e) => {
|
|
149
|
-
try {
|
|
150
|
-
e();
|
|
151
|
-
} catch (n) {
|
|
152
|
-
console.error(n, e);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
), this.disposers.clear(), this.injectedMap.clear(), this.providedMap.clear(), this.mountListeners.clear(), this.unmountedListeners.clear();
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 当 context 传递给外部消费时,隐藏内部实现,仅暴露接口定义的内容
|
|
159
|
-
* @returns 和 AirxComponentContext 接口完全一致的对象
|
|
160
|
-
*/
|
|
161
|
-
getSafeContext() {
|
|
162
|
-
return {
|
|
163
|
-
inject: (e) => this.inject(e),
|
|
164
|
-
provide: (e, n) => this.provide(e, n),
|
|
165
|
-
onMounted: (e) => this.onMounted(e),
|
|
166
|
-
onUnmounted: (e) => this.onUnmounted(e)
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function U(l, e, n) {
|
|
171
|
-
const i = O("reconcileChildren");
|
|
172
|
-
i.debug("reconcileChildren", e, n);
|
|
173
|
-
function o(s) {
|
|
174
|
-
return `airx-element-inner-key:${s}`;
|
|
175
|
-
}
|
|
176
|
-
function m(s) {
|
|
177
|
-
let c = 0, t = s;
|
|
178
|
-
const u = /* @__PURE__ */ new Map();
|
|
179
|
-
for (; t; )
|
|
180
|
-
t.element?.props.key != null ? u.set(t.element?.props.key, t) : u.set(o(c), t), t = t.sibling, c += 1;
|
|
181
|
-
return u;
|
|
182
|
-
}
|
|
183
|
-
const a = [], b = m(e.child);
|
|
184
|
-
function y(s, c) {
|
|
185
|
-
if (s.props.key != null) {
|
|
186
|
-
const d = s.props.key;
|
|
187
|
-
return [b.get(d) || null, () => b.delete(d)];
|
|
188
|
-
}
|
|
189
|
-
const t = o(c);
|
|
190
|
-
return [b.get(t) || null, () => b.delete(t)];
|
|
191
|
-
}
|
|
192
|
-
function g(s, c) {
|
|
193
|
-
for (const t of l.plugins)
|
|
194
|
-
if (typeof t.isReuseInstance == "function" && t.isReuseInstance(s, c) === !1)
|
|
195
|
-
return !1;
|
|
196
|
-
return !0;
|
|
197
|
-
}
|
|
198
|
-
function w(s) {
|
|
199
|
-
if (s.element != null) {
|
|
200
|
-
if (s.memoProps == null && (s.memoProps = {}), s.memoProps != null)
|
|
201
|
-
for (const c in s.memoProps)
|
|
202
|
-
delete s.memoProps[c];
|
|
203
|
-
for (const c in s.element.props) {
|
|
204
|
-
const t = s.element.props[c];
|
|
205
|
-
s.memoProps[c] = t;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function C(s) {
|
|
210
|
-
for (const c of l.plugins)
|
|
211
|
-
if (typeof c.isReRender == "function" && c.isReRender(s) === !0)
|
|
212
|
-
return !0;
|
|
213
|
-
return !1;
|
|
214
|
-
}
|
|
215
|
-
function v(s) {
|
|
216
|
-
const c = Object.keys(s.props).filter((t) => t === "xmlns" || t.startsWith("xmlns:")).sort((t, u) => t.length - u.length);
|
|
217
|
-
return c.length > 1 ? (console.log("airx currently does not support setting multiple xmlns"), "") : c.some((t) => t.startsWith("xmlns:")) ? (console.log("airx does not currently support setting named namespaces,only supports default"), "") : s.props[c[0]];
|
|
218
|
-
}
|
|
219
|
-
for (let s = 0; s < n.length; s++) {
|
|
220
|
-
const c = n[s], [t, u] = y(c, s);
|
|
221
|
-
if (t && g(t, c))
|
|
222
|
-
u(), a.push(t), t.beforeElement = t.element, t.element = c, w(t), t.needReRender !== !0 && typeof c.type == "function" && (t.needReRender = e.needReRender || C(t));
|
|
223
|
-
else {
|
|
224
|
-
const d = new M(), r = v(c), h = { element: c, context: d, elementNamespace: r };
|
|
225
|
-
a.push(h), d.instance = h, w(h), "ref" in h.memoProps && d.onMounted(() => {
|
|
226
|
-
const f = h.memoProps.ref;
|
|
227
|
-
if (h.domRef) {
|
|
228
|
-
if (Z(f))
|
|
229
|
-
return f.set(h.domRef), () => f.set(void 0);
|
|
230
|
-
if (typeof f == "function")
|
|
231
|
-
return f(h.domRef), () => f(void 0);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
for (let s = 0; s < a.length; s++) {
|
|
237
|
-
const c = a[s];
|
|
238
|
-
c.parent = e, s === 0 && (e.child = c), s > 0 && (a[s - 1].sibling = c), s === a.length - 1 && delete c.sibling, !c.elementNamespace && c.parent?.elementNamespace && c.parent.element?.type !== "foreignObject" && (c.elementNamespace = c.parent.elementNamespace);
|
|
239
|
-
}
|
|
240
|
-
b.size > 0 && (e.deletions == null && (e.deletions = /* @__PURE__ */ new Set()), b.forEach((s) => {
|
|
241
|
-
e.deletions?.add(s);
|
|
242
|
-
})), i.debug("parentInstance", e);
|
|
243
|
-
}
|
|
244
|
-
function z(l, e, n) {
|
|
245
|
-
const i = e.element;
|
|
246
|
-
function o(a) {
|
|
247
|
-
const b = Array.isArray(a) ? a : [a];
|
|
248
|
-
function y(g) {
|
|
249
|
-
return g === "" || g == null || g === !1;
|
|
250
|
-
}
|
|
251
|
-
return b.flat(3).map((g) => {
|
|
252
|
-
if (T(g)) return g;
|
|
253
|
-
const w = y(g) ? "comment" : "text", C = g === "" ? "empty-string" : String(g);
|
|
254
|
-
return F(w, { textContent: C });
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (typeof i?.type == "function") {
|
|
258
|
-
if (e.componentReturnValue == null) {
|
|
259
|
-
const a = i.type, b = L.current;
|
|
260
|
-
L.current = e.context.getSafeContext();
|
|
261
|
-
let y;
|
|
262
|
-
try {
|
|
263
|
-
y = a(e.memoProps);
|
|
264
|
-
} catch (g) {
|
|
265
|
-
y = $(g);
|
|
266
|
-
}
|
|
267
|
-
if (L.current = b, e.componentReturnValue = y, T(y)) {
|
|
268
|
-
const g = o(y);
|
|
269
|
-
U(l, e, g);
|
|
270
|
-
}
|
|
271
|
-
if (typeof y == "function") {
|
|
272
|
-
if (e.signalWatcher == null) {
|
|
273
|
-
const C = J(async () => {
|
|
274
|
-
e.needReRender = !0, n?.(e), queueMicrotask(() => {
|
|
275
|
-
C.watch();
|
|
276
|
-
const v = C.getPending();
|
|
277
|
-
for (const s of v) s.get();
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
e.signalWatcher = C, e.context.addDisposer(() => C.unwatch());
|
|
281
|
-
}
|
|
282
|
-
const g = Y(() => {
|
|
283
|
-
try {
|
|
284
|
-
if (typeof y == "function")
|
|
285
|
-
return y();
|
|
286
|
-
} catch (C) {
|
|
287
|
-
return $(C)();
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
e.signalWatcher.watch(g);
|
|
291
|
-
const w = g.get();
|
|
292
|
-
U(l, e, o(w));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (e.needReRender) {
|
|
296
|
-
let a;
|
|
297
|
-
try {
|
|
298
|
-
T(e.componentReturnValue) ? a = e.componentReturnValue : a = e.componentReturnValue();
|
|
299
|
-
} catch (b) {
|
|
300
|
-
a = $(b)();
|
|
301
|
-
}
|
|
302
|
-
U(l, e, o(a)), delete e.needReRender;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
if (typeof i?.type == "string" && "children" in i.props && Array.isArray(i.props.children) && U(l, e, o(i.props.children)), e.child)
|
|
306
|
-
return e.child;
|
|
307
|
-
function m(a) {
|
|
308
|
-
return a.sibling ? a.sibling : a.parent ? m(a.parent) : null;
|
|
309
|
-
}
|
|
310
|
-
return m(e);
|
|
311
|
-
}
|
|
312
|
-
function Q(l) {
|
|
313
|
-
return l.replace(/([A-Z])/g, (e, n, i) => i === 0 ? n.toLowerCase() : "-" + n.toLowerCase());
|
|
314
|
-
}
|
|
315
|
-
class S {
|
|
316
|
-
constructor(e) {
|
|
317
|
-
this.nodeName = e, this.style = {}, this.content = "", this.children = [], this.className = "", this.attributes = /* @__PURE__ */ new Map();
|
|
318
|
-
}
|
|
319
|
-
static createTextNode(e) {
|
|
320
|
-
const n = new S("#text");
|
|
321
|
-
return n.content = e, n;
|
|
322
|
-
}
|
|
323
|
-
static createComment(e) {
|
|
324
|
-
const n = new S("#comment");
|
|
325
|
-
return n.content = e, n;
|
|
326
|
-
}
|
|
327
|
-
static createElement(e) {
|
|
328
|
-
return new S(e);
|
|
329
|
-
}
|
|
330
|
-
firstChild;
|
|
331
|
-
nextSibling;
|
|
332
|
-
parentNode;
|
|
333
|
-
className;
|
|
334
|
-
style;
|
|
335
|
-
content;
|
|
336
|
-
children;
|
|
337
|
-
attributes;
|
|
338
|
-
removeChild(e) {
|
|
339
|
-
const n = this.children.findIndex((i) => i === e);
|
|
340
|
-
n != -1 && this.children.splice(n, 1), this.firstChild = void 0, this.nextSibling = void 0, this.parentNode = void 0;
|
|
341
|
-
}
|
|
342
|
-
appendChild(e) {
|
|
343
|
-
e.parentNode = this, this.children.length > 0 && (this.children[this.children.length - 1].nextSibling = e), this.firstChild = this.children[0], this.children.push(e);
|
|
344
|
-
}
|
|
345
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
346
|
-
setAttribute(e, n) {
|
|
347
|
-
if (n === "") return this.attributes.delete(e);
|
|
348
|
-
if (e === "class") return this.className = n;
|
|
349
|
-
if (e === "style") return this.style = n;
|
|
350
|
-
this.attributes.set(e, n);
|
|
351
|
-
}
|
|
352
|
-
removeAttribute(e) {
|
|
353
|
-
this.attributes.delete(e);
|
|
354
|
-
}
|
|
355
|
-
toString() {
|
|
356
|
-
if (this.nodeName === "#text") return this.content;
|
|
357
|
-
if (this.nodeName === "#comment") return this.content;
|
|
358
|
-
const e = Object.entries(this.style).map(([o, m]) => `${Q(o)}:${m}`).join(";"), n = [...this.attributes.entries()];
|
|
359
|
-
e.length > 0 && n.push(["style", e]), this.className.length > 0 && n.push(["class", this.className]);
|
|
360
|
-
const i = n.map(([o, m]) => ` ${o}="${m}"`).join("");
|
|
361
|
-
return `<${this.nodeName}${i}>${this.children.map((o) => o.toString()).join("")}</${this.nodeName}>`;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function P(l, e, n) {
|
|
365
|
-
const i = {
|
|
366
|
-
domRef: S.createElement("div"),
|
|
367
|
-
context: new M()
|
|
368
|
-
};
|
|
369
|
-
i.context.instance = i;
|
|
370
|
-
const o = {
|
|
371
|
-
rootInstance: i,
|
|
372
|
-
nextUnitOfWork: null
|
|
373
|
-
}, m = {
|
|
374
|
-
element: e,
|
|
375
|
-
parent: o.rootInstance,
|
|
376
|
-
memoProps: { ...e.props },
|
|
377
|
-
context: new M()
|
|
378
|
-
};
|
|
379
|
-
m.context.instance = m, o.rootInstance.child = m, o.nextUnitOfWork = m;
|
|
380
|
-
function a(b, y) {
|
|
381
|
-
O("commitDom").debug("commitDom", b);
|
|
382
|
-
function w(t, u, d = {}) {
|
|
383
|
-
const r = (p) => p === "key", h = (p) => p === "ref", f = (p) => p === "style", R = (p) => p === "class", N = (p) => p.startsWith("on"), E = (p) => p === "children", k = (p, j) => (D) => !(D in j), _ = (p, j) => (D) => p[D] !== j[D], q = (p) => !E(p) && !N(p) && !f(p) && !R(p) && !r(p) && !h(p);
|
|
384
|
-
if (t.nodeName === "#text" || t.nodeName === "#comment") {
|
|
385
|
-
const p = t;
|
|
386
|
-
p.nodeValue !== u.textContent && (p.nodeValue = String(u.textContent));
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
const V = d?.style;
|
|
390
|
-
typeof V == "object" && V != null && Object.keys(V).forEach((p) => {
|
|
391
|
-
delete t.style[p];
|
|
392
|
-
});
|
|
393
|
-
const W = u?.style;
|
|
394
|
-
typeof W == "object" && W != null && Object.keys(W).forEach((p) => {
|
|
395
|
-
const j = W?.[p];
|
|
396
|
-
t.style[p] = j ?? "";
|
|
397
|
-
}), t.className !== u?.class && (u?.class ? typeof u?.class == "string" && t.setAttribute("class", u?.class) : t.removeAttribute("class")), Object.keys(d).filter(q).filter(k(d, u)).forEach((p) => t.removeAttribute(p)), Object.keys(u).filter(q).filter(_(d, u)).forEach((p) => t.setAttribute(p, u[p]));
|
|
398
|
-
}
|
|
399
|
-
function C(t) {
|
|
400
|
-
if (t.parent?.domRef != null)
|
|
401
|
-
return t.parent.domRef;
|
|
402
|
-
if (t.parent)
|
|
403
|
-
return C(t.parent);
|
|
404
|
-
throw new Error("Cant find dom");
|
|
405
|
-
}
|
|
406
|
-
function v(t) {
|
|
407
|
-
const u = [], d = [t];
|
|
408
|
-
for (; d.length > 0; ) {
|
|
409
|
-
const r = d.pop();
|
|
410
|
-
r?.domRef != null && u.push(r.domRef), r?.domRef == null && r?.child != null && d.push(r.child), r?.sibling != null && d.push(r.sibling);
|
|
411
|
-
}
|
|
412
|
-
return u;
|
|
413
|
-
}
|
|
414
|
-
function s(t, u) {
|
|
415
|
-
if (t.deletions) {
|
|
416
|
-
for (const d of t.deletions) {
|
|
417
|
-
const r = v(d);
|
|
418
|
-
for (let h = 0; h < r.length; h++) {
|
|
419
|
-
const f = r[h];
|
|
420
|
-
f && f.parentNode && f.parentNode.removeChild(f);
|
|
421
|
-
}
|
|
422
|
-
d.context.triggerUnmounted();
|
|
423
|
-
}
|
|
424
|
-
t.deletions.clear();
|
|
425
|
-
}
|
|
426
|
-
if (t.domRef == null) {
|
|
427
|
-
if (t.element == null) throw new Error("???");
|
|
428
|
-
if (typeof t.element.type == "string")
|
|
429
|
-
if (t.element.type === "text") {
|
|
430
|
-
const d = t.element.props.textContent;
|
|
431
|
-
t.domRef = S.createTextNode(d);
|
|
432
|
-
} else if (t.element.type === "comment") {
|
|
433
|
-
const d = t.element.props.textContent;
|
|
434
|
-
t.domRef = S.createComment(d);
|
|
435
|
-
} else
|
|
436
|
-
t.domRef = S.createElement(t.element.type);
|
|
437
|
-
}
|
|
438
|
-
t.domRef != null && t.element != null && w(
|
|
439
|
-
t.domRef,
|
|
440
|
-
t.element.props,
|
|
441
|
-
t.beforeElement?.props
|
|
442
|
-
), t.domRef != null && u !== t.domRef && (t.domRef.parentNode && t.domRef.parentNode.removeChild(t.domRef), C(t).appendChild(t.domRef));
|
|
443
|
-
}
|
|
444
|
-
function c(t, u) {
|
|
445
|
-
const d = [[t, u]];
|
|
446
|
-
for (; d.length > 0; ) {
|
|
447
|
-
const r = d.pop();
|
|
448
|
-
if (typeof r == "function") {
|
|
449
|
-
r();
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
const [h, f] = r;
|
|
453
|
-
if (s(h, f), d.push(() => h.context.triggerMounted()), h.sibling != null) {
|
|
454
|
-
const R = h.domRef ? h.domRef.nextSibling : f?.nextSibling;
|
|
455
|
-
d.push([h.sibling, R || void 0]);
|
|
456
|
-
}
|
|
457
|
-
if (h.child != null) {
|
|
458
|
-
const R = h.domRef ? h.domRef.firstChild : f;
|
|
459
|
-
d.push([h.child, R || void 0]);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
c(b, y);
|
|
464
|
-
}
|
|
465
|
-
for (; o.nextUnitOfWork; )
|
|
466
|
-
o.nextUnitOfWork = z(
|
|
467
|
-
l,
|
|
468
|
-
o.nextUnitOfWork
|
|
469
|
-
);
|
|
470
|
-
a(
|
|
471
|
-
o.rootInstance.child,
|
|
472
|
-
o.rootInstance.domRef?.firstChild || void 0
|
|
473
|
-
), n(o.rootInstance.domRef?.toString() || "");
|
|
474
|
-
}
|
|
475
|
-
function B() {
|
|
476
|
-
return {
|
|
477
|
-
didTimeout: !1,
|
|
478
|
-
timeRemaining: () => Number.MAX_SAFE_INTEGER
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
function I(l) {
|
|
482
|
-
if (typeof globalThis.requestIdleCallback == "function") {
|
|
483
|
-
globalThis.requestIdleCallback(l);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
globalThis.setTimeout(() => l(B()), 0);
|
|
487
|
-
}
|
|
488
|
-
function ee(l, e, n) {
|
|
489
|
-
const i = {
|
|
490
|
-
domRef: n,
|
|
491
|
-
context: new M()
|
|
492
|
-
};
|
|
493
|
-
i.context.instance = i;
|
|
494
|
-
const o = {
|
|
495
|
-
rootInstance: i,
|
|
496
|
-
nextUnitOfWork: null,
|
|
497
|
-
needCommitDom: !1,
|
|
498
|
-
isWorkLoopScheduled: !1
|
|
499
|
-
}, m = {
|
|
500
|
-
element: e,
|
|
501
|
-
parent: o.rootInstance,
|
|
502
|
-
memoProps: { ...e.props },
|
|
503
|
-
context: new M()
|
|
504
|
-
};
|
|
505
|
-
m.context.instance = m, o.rootInstance.child = m, o.nextUnitOfWork = m;
|
|
506
|
-
function a(w, C) {
|
|
507
|
-
O("commitDom").debug("commitDom", w);
|
|
508
|
-
function s(r, h, f = {}) {
|
|
509
|
-
for (const R of l.plugins)
|
|
510
|
-
R.updateDom && R.updateDom(r, h, f);
|
|
511
|
-
}
|
|
512
|
-
function c(r) {
|
|
513
|
-
if (r.parent?.domRef != null)
|
|
514
|
-
return r.parent.domRef;
|
|
515
|
-
if (r.parent)
|
|
516
|
-
return c(r.parent);
|
|
517
|
-
throw new Error("Cant find dom");
|
|
518
|
-
}
|
|
519
|
-
function t(r) {
|
|
520
|
-
const h = [], f = [r];
|
|
521
|
-
for (; f.length > 0; ) {
|
|
522
|
-
const R = f.pop();
|
|
523
|
-
R?.domRef != null && h.push(R.domRef), R?.domRef == null && R?.child != null && f.push(R.child), R?.sibling != null && f.push(R.sibling);
|
|
524
|
-
}
|
|
525
|
-
return h;
|
|
526
|
-
}
|
|
527
|
-
function u(r, h) {
|
|
528
|
-
if (r.deletions) {
|
|
529
|
-
for (const f of r.deletions) {
|
|
530
|
-
const R = t(f);
|
|
531
|
-
for (let N = 0; N < R.length; N++) {
|
|
532
|
-
const E = R[N];
|
|
533
|
-
E && E.parentNode && E.parentNode.removeChild(E);
|
|
534
|
-
}
|
|
535
|
-
f.context.triggerUnmounted();
|
|
536
|
-
}
|
|
537
|
-
r.deletions.clear();
|
|
538
|
-
}
|
|
539
|
-
if (r.domRef == null) {
|
|
540
|
-
if (r.element == null) throw new Error("???");
|
|
541
|
-
if (typeof r.element.type == "string") {
|
|
542
|
-
if (r.element.type === "text") {
|
|
543
|
-
const f = r.element.props.textContent;
|
|
544
|
-
r.domRef = document.createTextNode(f);
|
|
545
|
-
} else if (r.element.type === "comment") {
|
|
546
|
-
const f = r.element.props.textContent;
|
|
547
|
-
r.domRef = document.createComment(f);
|
|
548
|
-
} else
|
|
549
|
-
r.domRef = r.elementNamespace ? document.createElementNS(r.elementNamespace, r.element.type) : document.createElement(r.element.type);
|
|
550
|
-
r.domRef && (r.domRef.airxInstance = r);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
r.domRef != null && r.element != null && s(
|
|
554
|
-
r.domRef,
|
|
555
|
-
r.element.props,
|
|
556
|
-
r.beforeElement?.props
|
|
557
|
-
), r.domRef != null && h !== r.domRef && (r.domRef.parentNode && r.domRef.parentNode.removeChild(r.domRef), c(r).appendChild(r.domRef));
|
|
558
|
-
}
|
|
559
|
-
function d(r, h) {
|
|
560
|
-
const f = [[r, h]];
|
|
561
|
-
for (; f.length > 0; ) {
|
|
562
|
-
const R = f.pop();
|
|
563
|
-
if (typeof R == "function") {
|
|
564
|
-
R();
|
|
565
|
-
continue;
|
|
566
|
-
}
|
|
567
|
-
const [N, E] = R;
|
|
568
|
-
if (u(N, E), f.push(() => N.context.triggerMounted()), N.sibling != null) {
|
|
569
|
-
const k = N.domRef ? N.domRef.nextSibling : E?.nextSibling;
|
|
570
|
-
f.push([N.sibling, k || void 0]);
|
|
571
|
-
}
|
|
572
|
-
if (N.child != null) {
|
|
573
|
-
const k = N.domRef ? N.domRef.firstChild : E;
|
|
574
|
-
f.push([N.child, k || void 0]);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
d(w, C);
|
|
579
|
-
}
|
|
580
|
-
function b() {
|
|
581
|
-
o.isWorkLoopScheduled || o.nextUnitOfWork == null || (o.isWorkLoopScheduled = !0, I((w) => {
|
|
582
|
-
o.isWorkLoopScheduled = !1, g(w);
|
|
583
|
-
}));
|
|
584
|
-
}
|
|
585
|
-
function y() {
|
|
586
|
-
o.nextUnitOfWork == null && o.rootInstance.child && (o.nextUnitOfWork = o.rootInstance.child), b();
|
|
587
|
-
}
|
|
588
|
-
function g(w = B()) {
|
|
589
|
-
let C = !1;
|
|
590
|
-
const v = O("workLoop");
|
|
591
|
-
for (; o.nextUnitOfWork && !C; )
|
|
592
|
-
v.debug("nextUnitOfWork", o.nextUnitOfWork), o.nextUnitOfWork = z(l, o.nextUnitOfWork, y), o.nextUnitOfWork == null && (o.needCommitDom = !0), w && (C = w.timeRemaining() < 1);
|
|
593
|
-
o.needCommitDom && o.rootInstance.child && (a(
|
|
594
|
-
o.rootInstance.child,
|
|
595
|
-
o.rootInstance.domRef?.firstChild || void 0
|
|
596
|
-
), o.needCommitDom = !1), b();
|
|
597
|
-
}
|
|
598
|
-
return g(), o.rootInstance;
|
|
599
|
-
}
|
|
600
|
-
class te {
|
|
601
|
-
logger = O("basicLogicPlugin");
|
|
602
|
-
isSameProps(e, n) {
|
|
603
|
-
if (Object.is(n, e))
|
|
604
|
-
return !0;
|
|
605
|
-
if (typeof e != "object" || typeof n != "object" || e === null || n === null)
|
|
606
|
-
return this.logger.debug("props must be an object"), !1;
|
|
607
|
-
const i = Object.keys(e);
|
|
608
|
-
for (let o = 0; o < i.length; o++) {
|
|
609
|
-
const m = i[o];
|
|
610
|
-
if (m !== "children" && m !== "key" && (!Object.hasOwn(n, m) || !Object.is(e[m], n[m])))
|
|
611
|
-
return !1;
|
|
612
|
-
if (m === "children") {
|
|
613
|
-
const a = e.children, b = n.children;
|
|
614
|
-
if (a.length === 0 && b.length === 0) return !0;
|
|
615
|
-
for (let y = 0; y < a.length; y++) {
|
|
616
|
-
const g = a[y], w = b[y];
|
|
617
|
-
if (g !== w || typeof g != typeof w) return !1;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
return !0;
|
|
621
|
-
}
|
|
622
|
-
return !1;
|
|
623
|
-
}
|
|
624
|
-
isReRender(e) {
|
|
625
|
-
const n = e.element?.props, i = e.beforeElement?.props;
|
|
626
|
-
if (!this.isSameProps(i, n)) return !0;
|
|
627
|
-
}
|
|
628
|
-
updateDom(e, n, i = {}) {
|
|
629
|
-
this.logger.debug("updateDom", e, n, i);
|
|
630
|
-
const o = (t) => t === "key", m = (t) => t === "ref", a = (t) => t === "style", b = (t) => t === "class", y = (t) => t.startsWith("on"), g = (t) => t === "children", w = (t, u) => (d) => !(d in u), C = (t, u) => (d) => t[d] !== u[d], v = (t) => !g(t) && !y(t) && !a(t) && !b(t) && !o(t) && !m(t);
|
|
631
|
-
if (e.nodeName === "#text" || e.nodeName === "#comment") {
|
|
632
|
-
const t = e;
|
|
633
|
-
t.nodeValue !== n.textContent && (t.nodeValue = String(n.textContent));
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
const s = i?.style;
|
|
637
|
-
if (typeof s == "object" && s != null) {
|
|
638
|
-
if (!("style" in e) || !e.style) return;
|
|
639
|
-
Object.keys(s).forEach((t) => {
|
|
640
|
-
"style" in e && e.style && delete e.style[t];
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
const c = n?.style;
|
|
644
|
-
if (typeof c == "object" && c != null) {
|
|
645
|
-
if (!("style" in e) || !e.style) return;
|
|
646
|
-
Object.keys(c).forEach((t) => {
|
|
647
|
-
const u = c?.[t];
|
|
648
|
-
e.style[t] = u ?? "";
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
e.className !== n?.class && (n?.class ? typeof n?.class == "string" && e.setAttribute("class", n?.class) : e.removeAttribute("class")), Object.keys(i).filter(y).filter(
|
|
652
|
-
(t) => !(t in n) || C(i, n)(t)
|
|
653
|
-
).forEach((t) => {
|
|
654
|
-
const u = t.toLowerCase().substring(2);
|
|
655
|
-
i[t] != null && (typeof i[t] != "function" ? console.error("EventListener is not a function") : e.removeEventListener(u, i[t]));
|
|
656
|
-
}), Object.keys(n).filter(y).filter(C(i, n)).forEach((t) => {
|
|
657
|
-
const u = t.toLowerCase().substring(2);
|
|
658
|
-
n[t] != null && (typeof n[t] != "function" ? console.error("EventListener is not a function") : e.addEventListener(u, n[t]));
|
|
659
|
-
}), Object.keys(i).filter(v).filter(w(i, n)).forEach((t) => e.removeAttribute(t)), Object.keys(n).filter(v).filter(C(i, n)).forEach((t) => e.setAttribute(t, n[t]));
|
|
660
|
-
}
|
|
661
|
-
isReuseInstance(e, n) {
|
|
662
|
-
if (e && e.element && e.element.type !== n.type)
|
|
663
|
-
return !1;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
class ne {
|
|
667
|
-
getProvideValueForParent(e, n) {
|
|
668
|
-
if (e && e.context) {
|
|
669
|
-
const i = e.context.providedMap.get(n);
|
|
670
|
-
if (i != null) return i;
|
|
671
|
-
if (e.parent)
|
|
672
|
-
return this.getProvideValueForParent(e.parent, n);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
isReuseInstance(e) {
|
|
676
|
-
const n = [...e.context.injectedMap.keys()];
|
|
677
|
-
for (let i = 0; i < n.length; i++) {
|
|
678
|
-
const o = n[i], m = e.context.injectedMap.get(o);
|
|
679
|
-
if (this.getProvideValueForParent(e.parent, o) !== m) return !1;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
class oe {
|
|
684
|
-
plugins = [
|
|
685
|
-
new te(),
|
|
686
|
-
new ne()
|
|
687
|
-
];
|
|
688
|
-
registerPlugin(...e) {
|
|
689
|
-
this.plugins.push(...e);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
function fe(l) {
|
|
693
|
-
const e = new oe(), n = (o) => typeof o == "function" ? F(o, {}) : o, i = {
|
|
694
|
-
plugin: (...o) => (e.registerPlugin(...o), i),
|
|
695
|
-
mount: (o) => (o.innerHTML = "", ee(e, n(l), o), i),
|
|
696
|
-
renderToHTML: () => new Promise((o) => {
|
|
697
|
-
P(e, n(l), o);
|
|
698
|
-
})
|
|
699
|
-
};
|
|
700
|
-
return i;
|
|
701
|
-
}
|
|
702
|
-
export {
|
|
703
|
-
ce as Fragment,
|
|
704
|
-
ue as component,
|
|
705
|
-
fe as createApp,
|
|
706
|
-
F as createElement,
|
|
707
|
-
le as inject,
|
|
708
|
-
ie as onMounted,
|
|
709
|
-
re as onUnmounted,
|
|
710
|
-
se as provide
|
|
711
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* JSX/DOM 属性类型定义。
|
|
3
|
+
*/
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* 应用入口 API。
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { createApp } from 'airx'
|
|
10
|
+
* import { App } from './App.js'
|
|
11
|
+
*
|
|
12
|
+
* createApp(App).mount(document.getElementById('root')!)
|
|
13
|
+
*/
|
|
14
|
+
export { createApp } from './app/index.js';
|
|
15
|
+
/**
|
|
16
|
+
* 节点和组件 API。
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* import { createElement, component } from 'airx'
|
|
20
|
+
*
|
|
21
|
+
* const Title = component((props: { text: string }) => {
|
|
22
|
+
* return () => createElement('h1', null as never, props.text)
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
export { Fragment, component, createElement } from './element/index.js';
|
|
26
|
+
/**
|
|
27
|
+
* 组件上下文 Hook API。
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* import { provide, inject } from 'airx'
|
|
31
|
+
*
|
|
32
|
+
* provide('lang', 'en')
|
|
33
|
+
* const lang = inject<string>('lang')
|
|
34
|
+
*/
|
|
35
|
+
export { inject, provide, onMounted, onUnmounted } from './render/index.js';
|
|
36
|
+
//# sourceMappingURL=index.js.map
|