@akashjs/runtime 0.1.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/dist/chunk-D3IR22HI.js +662 -0
- package/dist/chunk-D3IR22HI.js.map +1 -0
- package/dist/index.cjs +5429 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +4551 -0
- package/dist/index.js.map +1 -0
- package/dist/test.cjs +370 -0
- package/dist/test.cjs.map +1 -0
- package/dist/test.js +166 -0
- package/dist/test.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
// src/scheduler.ts
|
|
2
|
+
var pendingRender = /* @__PURE__ */ new Set();
|
|
3
|
+
var pendingUser = /* @__PURE__ */ new Set();
|
|
4
|
+
var flushing = false;
|
|
5
|
+
var batchDepth = 0;
|
|
6
|
+
var flushScheduled = false;
|
|
7
|
+
function flush() {
|
|
8
|
+
if (flushing) return;
|
|
9
|
+
flushing = true;
|
|
10
|
+
flushScheduled = false;
|
|
11
|
+
while (pendingRender.size > 0 || pendingUser.size > 0) {
|
|
12
|
+
if (pendingRender.size > 0) {
|
|
13
|
+
const queue = [...pendingRender].sort(byDepth);
|
|
14
|
+
pendingRender.clear();
|
|
15
|
+
for (const fx of queue) {
|
|
16
|
+
fx.run();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (pendingUser.size > 0) {
|
|
20
|
+
const queue = [...pendingUser].sort(byDepth);
|
|
21
|
+
pendingUser.clear();
|
|
22
|
+
for (const fx of queue) {
|
|
23
|
+
fx.run();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
flushing = false;
|
|
28
|
+
}
|
|
29
|
+
function scheduleEffect(fx) {
|
|
30
|
+
if (fx.isRender) {
|
|
31
|
+
pendingRender.add(fx);
|
|
32
|
+
} else {
|
|
33
|
+
pendingUser.add(fx);
|
|
34
|
+
}
|
|
35
|
+
if (batchDepth === 0 && !flushing && !flushScheduled) {
|
|
36
|
+
flushScheduled = true;
|
|
37
|
+
queueMicrotask(flush);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function batch(fn) {
|
|
41
|
+
batchDepth++;
|
|
42
|
+
try {
|
|
43
|
+
fn();
|
|
44
|
+
} finally {
|
|
45
|
+
batchDepth--;
|
|
46
|
+
if (batchDepth === 0) {
|
|
47
|
+
flush();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function byDepth(a, b) {
|
|
52
|
+
return (a.depth ?? 0) - (b.depth ?? 0);
|
|
53
|
+
}
|
|
54
|
+
function flushSync() {
|
|
55
|
+
flush();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/signals.ts
|
|
59
|
+
var currentSubscriber = null;
|
|
60
|
+
function signal(initialValue, options) {
|
|
61
|
+
const node = {
|
|
62
|
+
value: initialValue,
|
|
63
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
64
|
+
equals: options?.equals ?? Object.is
|
|
65
|
+
};
|
|
66
|
+
const read = () => {
|
|
67
|
+
trackSubscriber(node);
|
|
68
|
+
return node.value;
|
|
69
|
+
};
|
|
70
|
+
read.set = (value) => {
|
|
71
|
+
if (node.equals(node.value, value)) return;
|
|
72
|
+
node.value = value;
|
|
73
|
+
notifySubscribers(node);
|
|
74
|
+
};
|
|
75
|
+
read.update = (fn) => {
|
|
76
|
+
read.set(fn(node.value));
|
|
77
|
+
};
|
|
78
|
+
read.peek = () => node.value;
|
|
79
|
+
return read;
|
|
80
|
+
}
|
|
81
|
+
function computed(fn, options) {
|
|
82
|
+
const node = {
|
|
83
|
+
_tag: "computed",
|
|
84
|
+
fn,
|
|
85
|
+
value: void 0,
|
|
86
|
+
state: 1 /* Dirty */,
|
|
87
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
88
|
+
sources: /* @__PURE__ */ new Set(),
|
|
89
|
+
equals: options?.equals ?? Object.is
|
|
90
|
+
};
|
|
91
|
+
const read = () => {
|
|
92
|
+
if (currentSubscriber) {
|
|
93
|
+
node.subscribers.add(currentSubscriber);
|
|
94
|
+
if ("sources" in currentSubscriber) {
|
|
95
|
+
currentSubscriber.sources.add(node);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (node.state !== 0 /* Clean */) {
|
|
99
|
+
recompute(node);
|
|
100
|
+
}
|
|
101
|
+
return node.value;
|
|
102
|
+
};
|
|
103
|
+
return read;
|
|
104
|
+
}
|
|
105
|
+
function recompute(node) {
|
|
106
|
+
for (const source of node.sources) {
|
|
107
|
+
source.subscribers.delete(node);
|
|
108
|
+
}
|
|
109
|
+
node.sources.clear();
|
|
110
|
+
const prevSubscriber = currentSubscriber;
|
|
111
|
+
currentSubscriber = node;
|
|
112
|
+
try {
|
|
113
|
+
const newValue = node.fn();
|
|
114
|
+
const changed = node.value === void 0 || !node.equals(node.value, newValue);
|
|
115
|
+
node.value = newValue;
|
|
116
|
+
node.state = 0 /* Clean */;
|
|
117
|
+
if (changed) {
|
|
118
|
+
notifySubscribers(node);
|
|
119
|
+
}
|
|
120
|
+
} finally {
|
|
121
|
+
currentSubscriber = prevSubscriber;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function effect(fn, options) {
|
|
125
|
+
const node = {
|
|
126
|
+
_tag: "effect",
|
|
127
|
+
fn,
|
|
128
|
+
cleanup: null,
|
|
129
|
+
sources: /* @__PURE__ */ new Set(),
|
|
130
|
+
disposed: false,
|
|
131
|
+
isRender: options?.render ?? false,
|
|
132
|
+
run() {
|
|
133
|
+
runEffect(node);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
runEffect(node);
|
|
137
|
+
return () => {
|
|
138
|
+
node.disposed = true;
|
|
139
|
+
cleanupEffect(node);
|
|
140
|
+
for (const source of node.sources) {
|
|
141
|
+
source.subscribers.delete(node);
|
|
142
|
+
}
|
|
143
|
+
node.sources.clear();
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function runEffect(node) {
|
|
147
|
+
if (node.disposed) return;
|
|
148
|
+
if (node.sources.size > 0) {
|
|
149
|
+
let anyChanged = false;
|
|
150
|
+
for (const source of node.sources) {
|
|
151
|
+
if ("_tag" in source && source._tag === "computed") {
|
|
152
|
+
if (source.state === 1 /* Dirty */) {
|
|
153
|
+
const oldValue = source.value;
|
|
154
|
+
recompute(source);
|
|
155
|
+
if (!source.equals(oldValue, source.value)) {
|
|
156
|
+
anyChanged = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
anyChanged = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!anyChanged) return;
|
|
164
|
+
}
|
|
165
|
+
cleanupEffect(node);
|
|
166
|
+
for (const source of node.sources) {
|
|
167
|
+
source.subscribers.delete(node);
|
|
168
|
+
}
|
|
169
|
+
node.sources.clear();
|
|
170
|
+
const prevSubscriber = currentSubscriber;
|
|
171
|
+
currentSubscriber = node;
|
|
172
|
+
try {
|
|
173
|
+
const result = node.fn();
|
|
174
|
+
if (typeof result === "function") {
|
|
175
|
+
node.cleanup = result;
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
currentSubscriber = prevSubscriber;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function cleanupEffect(node) {
|
|
182
|
+
if (node.cleanup) {
|
|
183
|
+
node.cleanup();
|
|
184
|
+
node.cleanup = null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function untrack(fn) {
|
|
188
|
+
const prev = currentSubscriber;
|
|
189
|
+
currentSubscriber = null;
|
|
190
|
+
try {
|
|
191
|
+
return fn();
|
|
192
|
+
} finally {
|
|
193
|
+
currentSubscriber = prev;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function trackSubscriber(node) {
|
|
197
|
+
if (currentSubscriber) {
|
|
198
|
+
node.subscribers.add(currentSubscriber);
|
|
199
|
+
if ("sources" in currentSubscriber) {
|
|
200
|
+
currentSubscriber.sources.add(node);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function notifySubscribers(node) {
|
|
205
|
+
for (const sub of node.subscribers) {
|
|
206
|
+
if (sub._tag === "computed") {
|
|
207
|
+
sub.state = 1 /* Dirty */;
|
|
208
|
+
notifySubscribers(sub);
|
|
209
|
+
} else if (sub._tag === "effect") {
|
|
210
|
+
scheduleEffect(sub);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/errors.ts
|
|
216
|
+
var errors = {
|
|
217
|
+
// --- Context errors (AK001x) ---
|
|
218
|
+
AK0010: {
|
|
219
|
+
code: "AK0010",
|
|
220
|
+
message: "provide() called outside of component setup.",
|
|
221
|
+
hint: "provide() must be called inside defineComponent()."
|
|
222
|
+
},
|
|
223
|
+
AK0012: {
|
|
224
|
+
code: "AK0012",
|
|
225
|
+
message: "inject() called outside of component setup.",
|
|
226
|
+
hint: "inject() must be called inside defineComponent()."
|
|
227
|
+
},
|
|
228
|
+
AK0013: {
|
|
229
|
+
code: "AK0013",
|
|
230
|
+
message: "No provider found for injected context.",
|
|
231
|
+
hint: "Make sure an ancestor component calls provide() with this key."
|
|
232
|
+
},
|
|
233
|
+
// --- Lifecycle errors (AK002x) ---
|
|
234
|
+
AK0020: {
|
|
235
|
+
code: "AK0020",
|
|
236
|
+
message: "onMount() called outside of component setup.",
|
|
237
|
+
hint: "onMount() must be called inside defineComponent()."
|
|
238
|
+
},
|
|
239
|
+
AK0021: {
|
|
240
|
+
code: "AK0021",
|
|
241
|
+
message: "onUnmount() called outside of component setup.",
|
|
242
|
+
hint: "onUnmount() must be called inside defineComponent()."
|
|
243
|
+
},
|
|
244
|
+
AK0022: {
|
|
245
|
+
code: "AK0022",
|
|
246
|
+
message: "onError() called outside of component setup.",
|
|
247
|
+
hint: "onError() must be called inside defineComponent()."
|
|
248
|
+
},
|
|
249
|
+
// --- Signal errors (AK003x) ---
|
|
250
|
+
AK0030: {
|
|
251
|
+
code: "AK0030",
|
|
252
|
+
message: "Circular dependency detected in computed signal.",
|
|
253
|
+
hint: "A computed signal is reading itself, directly or via other computeds."
|
|
254
|
+
},
|
|
255
|
+
AK0031: {
|
|
256
|
+
code: "AK0031",
|
|
257
|
+
message: "Signal set() called during computation.",
|
|
258
|
+
hint: "Do not set signals inside computed() or during effect execution. Use batch() or set signals in event handlers."
|
|
259
|
+
},
|
|
260
|
+
// --- Component errors (AK004x) ---
|
|
261
|
+
AK0040: {
|
|
262
|
+
code: "AK0040",
|
|
263
|
+
message: "Component setup must return a render function.",
|
|
264
|
+
hint: "The function passed to defineComponent() must return () => AkashNode."
|
|
265
|
+
},
|
|
266
|
+
AK0041: {
|
|
267
|
+
code: "AK0041",
|
|
268
|
+
message: "Required prop is missing.",
|
|
269
|
+
hint: "Check that the parent component is passing all required props."
|
|
270
|
+
},
|
|
271
|
+
// --- Router errors (AK005x) ---
|
|
272
|
+
AK0050: {
|
|
273
|
+
code: "AK0050",
|
|
274
|
+
message: "useRoute() called outside of router context.",
|
|
275
|
+
hint: "Make sure your component is rendered inside a router provider."
|
|
276
|
+
},
|
|
277
|
+
AK0051: {
|
|
278
|
+
code: "AK0051",
|
|
279
|
+
message: "No route matched the current URL.",
|
|
280
|
+
hint: "Add a catch-all route ([...rest]) to handle unmatched paths."
|
|
281
|
+
},
|
|
282
|
+
AK0052: {
|
|
283
|
+
code: "AK0052",
|
|
284
|
+
message: "Route guard threw an error.",
|
|
285
|
+
hint: "Check the guard function for unhandled exceptions."
|
|
286
|
+
},
|
|
287
|
+
// --- Form errors (AK006x) ---
|
|
288
|
+
AK0060: {
|
|
289
|
+
code: "AK0060",
|
|
290
|
+
message: "Form submitted while invalid.",
|
|
291
|
+
hint: "The submit handler was not called because validation failed. Check form.errors()."
|
|
292
|
+
},
|
|
293
|
+
AK0061: {
|
|
294
|
+
code: "AK0061",
|
|
295
|
+
message: "Async validator timed out.",
|
|
296
|
+
hint: "The async validator did not resolve within the expected time. Check your async validation logic."
|
|
297
|
+
},
|
|
298
|
+
// --- HTTP errors (AK007x) ---
|
|
299
|
+
AK0070: {
|
|
300
|
+
code: "AK0070",
|
|
301
|
+
message: "HTTP request failed.",
|
|
302
|
+
hint: "Check the server response status and network connectivity."
|
|
303
|
+
},
|
|
304
|
+
AK0071: {
|
|
305
|
+
code: "AK0071",
|
|
306
|
+
message: "createResource() fetcher threw an error.",
|
|
307
|
+
hint: "Check the fetcher function passed to createResource()."
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var DOC_BASE = "https://akashjs.dev/errors";
|
|
311
|
+
function formatError(code, context) {
|
|
312
|
+
const def = errors[code];
|
|
313
|
+
if (!def) {
|
|
314
|
+
return `[AkashJS ${code}] Unknown error code.`;
|
|
315
|
+
}
|
|
316
|
+
let msg = `[AkashJS ${code}] ${def.message}`;
|
|
317
|
+
if (context) {
|
|
318
|
+
msg += `
|
|
319
|
+
${context}`;
|
|
320
|
+
}
|
|
321
|
+
msg += `
|
|
322
|
+
${def.hint}`;
|
|
323
|
+
msg += `
|
|
324
|
+
See: ${DOC_BASE}/${code}`;
|
|
325
|
+
return msg;
|
|
326
|
+
}
|
|
327
|
+
function akashError(code, context) {
|
|
328
|
+
return new Error(formatError(code, context));
|
|
329
|
+
}
|
|
330
|
+
function getErrorDef(code) {
|
|
331
|
+
return errors[code];
|
|
332
|
+
}
|
|
333
|
+
function getAllErrorCodes() {
|
|
334
|
+
return Object.keys(errors);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/context.ts
|
|
338
|
+
var CONTEXT_BRAND = /* @__PURE__ */ Symbol("akash.context");
|
|
339
|
+
var currentScope = null;
|
|
340
|
+
function pushScope(parent = currentScope) {
|
|
341
|
+
const scope = { values: /* @__PURE__ */ new Map(), parent };
|
|
342
|
+
currentScope = scope;
|
|
343
|
+
return scope;
|
|
344
|
+
}
|
|
345
|
+
function popScope(scope) {
|
|
346
|
+
currentScope = scope.parent;
|
|
347
|
+
}
|
|
348
|
+
function getCurrentScope() {
|
|
349
|
+
return currentScope;
|
|
350
|
+
}
|
|
351
|
+
function createContext(defaultValue) {
|
|
352
|
+
return {
|
|
353
|
+
[CONTEXT_BRAND]: true,
|
|
354
|
+
_type: void 0,
|
|
355
|
+
defaultValue,
|
|
356
|
+
id: /* @__PURE__ */ Symbol("context")
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function provide(key, value) {
|
|
360
|
+
if (!currentScope) {
|
|
361
|
+
throw akashError("AK0010");
|
|
362
|
+
}
|
|
363
|
+
currentScope.values.set(key.id, value);
|
|
364
|
+
}
|
|
365
|
+
function inject(key, fallback) {
|
|
366
|
+
if (!currentScope) {
|
|
367
|
+
throw akashError("AK0012");
|
|
368
|
+
}
|
|
369
|
+
let scope = currentScope;
|
|
370
|
+
while (scope) {
|
|
371
|
+
if (scope.values.has(key.id)) {
|
|
372
|
+
return scope.values.get(key.id);
|
|
373
|
+
}
|
|
374
|
+
scope = scope.parent;
|
|
375
|
+
}
|
|
376
|
+
if (fallback !== void 0) return fallback;
|
|
377
|
+
if (key.defaultValue !== void 0) return key.defaultValue;
|
|
378
|
+
throw akashError("AK0013");
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/dom.ts
|
|
382
|
+
function createElement(tag, attrs) {
|
|
383
|
+
const el = document.createElement(tag);
|
|
384
|
+
if (attrs) {
|
|
385
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
386
|
+
setProperty(el, key, value);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return el;
|
|
390
|
+
}
|
|
391
|
+
function createText(value) {
|
|
392
|
+
return document.createTextNode(value);
|
|
393
|
+
}
|
|
394
|
+
function cloneTemplate(html) {
|
|
395
|
+
const template = document.createElement("template");
|
|
396
|
+
template.innerHTML = html;
|
|
397
|
+
return template.content.cloneNode(true);
|
|
398
|
+
}
|
|
399
|
+
function setProperty(el, key, value) {
|
|
400
|
+
if (key === "class" || key === "className") {
|
|
401
|
+
el.className = value;
|
|
402
|
+
} else if (key === "style" && typeof value === "object" && value !== null) {
|
|
403
|
+
Object.assign(el.style, value);
|
|
404
|
+
} else if (key === "innerHTML") {
|
|
405
|
+
el.innerHTML = value;
|
|
406
|
+
} else if (key === "ref") ; else if (key.startsWith("on")) {
|
|
407
|
+
const event = key.slice(2).toLowerCase();
|
|
408
|
+
el.addEventListener(event, value);
|
|
409
|
+
} else if (key in el) {
|
|
410
|
+
el[key] = value;
|
|
411
|
+
} else if (value === false || value == null) {
|
|
412
|
+
el.removeAttribute(key);
|
|
413
|
+
} else {
|
|
414
|
+
el.setAttribute(key, value === true ? "" : String(value));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function bindText(node, fn) {
|
|
418
|
+
return effect(
|
|
419
|
+
() => {
|
|
420
|
+
node.textContent = String(fn());
|
|
421
|
+
},
|
|
422
|
+
{ render: true }
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
function bindProperty(el, key, fn) {
|
|
426
|
+
return effect(
|
|
427
|
+
() => {
|
|
428
|
+
setProperty(el, key, fn());
|
|
429
|
+
},
|
|
430
|
+
{ render: true }
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
function bindVisible(el, fn) {
|
|
434
|
+
return effect(
|
|
435
|
+
() => {
|
|
436
|
+
el.style.display = fn() ? "" : "none";
|
|
437
|
+
},
|
|
438
|
+
{ render: true }
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
function createAnchor(label = "") {
|
|
442
|
+
return document.createComment(label);
|
|
443
|
+
}
|
|
444
|
+
function renderConditional(parent, anchor, condition, trueBranch, falseBranch) {
|
|
445
|
+
let current = null;
|
|
446
|
+
const dispose = effect(
|
|
447
|
+
() => {
|
|
448
|
+
const value = condition();
|
|
449
|
+
if (current) {
|
|
450
|
+
for (const node of current.nodes) {
|
|
451
|
+
parent.removeChild(node);
|
|
452
|
+
}
|
|
453
|
+
current.dispose?.();
|
|
454
|
+
current = null;
|
|
455
|
+
}
|
|
456
|
+
const branch = value ? trueBranch : falseBranch;
|
|
457
|
+
if (branch) {
|
|
458
|
+
const fragment = branch();
|
|
459
|
+
const nodes = fragment instanceof DocumentFragment ? Array.from(fragment.childNodes) : [fragment];
|
|
460
|
+
for (const node of nodes) {
|
|
461
|
+
parent.insertBefore(node, anchor);
|
|
462
|
+
}
|
|
463
|
+
current = { nodes, dispose: null };
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
{ render: true }
|
|
467
|
+
);
|
|
468
|
+
return () => {
|
|
469
|
+
dispose();
|
|
470
|
+
if (current) {
|
|
471
|
+
for (const node of current.nodes) {
|
|
472
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
473
|
+
}
|
|
474
|
+
current.dispose?.();
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function renderList(parent, anchor, items, keyFn, renderItem) {
|
|
479
|
+
let currentItems = [];
|
|
480
|
+
const dispose = effect(
|
|
481
|
+
() => {
|
|
482
|
+
const newData = items();
|
|
483
|
+
const newItems = [];
|
|
484
|
+
const oldMap = /* @__PURE__ */ new Map();
|
|
485
|
+
for (const item of currentItems) {
|
|
486
|
+
oldMap.set(item.key, item);
|
|
487
|
+
}
|
|
488
|
+
for (let i = 0; i < newData.length; i++) {
|
|
489
|
+
const data = newData[i];
|
|
490
|
+
const key = keyFn(data, i);
|
|
491
|
+
const existing = oldMap.get(key);
|
|
492
|
+
if (existing) {
|
|
493
|
+
oldMap.delete(key);
|
|
494
|
+
existing.value = data;
|
|
495
|
+
newItems.push(existing);
|
|
496
|
+
} else {
|
|
497
|
+
const fragment = renderItem(data, i);
|
|
498
|
+
const nodes = fragment instanceof DocumentFragment ? Array.from(fragment.childNodes) : [fragment];
|
|
499
|
+
newItems.push({ key, value: data, nodes, dispose: null });
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
for (const item of oldMap.values()) {
|
|
503
|
+
for (const node of item.nodes) {
|
|
504
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
505
|
+
}
|
|
506
|
+
item.dispose?.();
|
|
507
|
+
}
|
|
508
|
+
for (const item of newItems) {
|
|
509
|
+
for (const node of item.nodes) {
|
|
510
|
+
parent.insertBefore(node, anchor);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
currentItems = newItems;
|
|
514
|
+
},
|
|
515
|
+
{ render: true }
|
|
516
|
+
);
|
|
517
|
+
return () => {
|
|
518
|
+
dispose();
|
|
519
|
+
for (const item of currentItems) {
|
|
520
|
+
for (const node of item.nodes) {
|
|
521
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
522
|
+
}
|
|
523
|
+
item.dispose?.();
|
|
524
|
+
}
|
|
525
|
+
currentItems = [];
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function Show(props) {
|
|
529
|
+
const anchor = createAnchor("show");
|
|
530
|
+
const container = document.createDocumentFragment();
|
|
531
|
+
container.appendChild(anchor);
|
|
532
|
+
renderConditional(
|
|
533
|
+
container,
|
|
534
|
+
anchor,
|
|
535
|
+
() => !!props.when,
|
|
536
|
+
() => nodeToDOM(props.children(props.when)),
|
|
537
|
+
props.fallback ? () => nodeToDOM(props.fallback()) : void 0
|
|
538
|
+
);
|
|
539
|
+
return container;
|
|
540
|
+
}
|
|
541
|
+
function For(props) {
|
|
542
|
+
const anchor = createAnchor("for");
|
|
543
|
+
const container = document.createDocumentFragment();
|
|
544
|
+
container.appendChild(anchor);
|
|
545
|
+
renderList(
|
|
546
|
+
container,
|
|
547
|
+
anchor,
|
|
548
|
+
() => props.each,
|
|
549
|
+
props.key,
|
|
550
|
+
(item, index) => nodeToDOM(props.children(item, index))
|
|
551
|
+
);
|
|
552
|
+
return container;
|
|
553
|
+
}
|
|
554
|
+
function nodeToDOM(node) {
|
|
555
|
+
if (node == null || typeof node === "boolean") {
|
|
556
|
+
return document.createTextNode("");
|
|
557
|
+
}
|
|
558
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
559
|
+
return document.createTextNode(String(node));
|
|
560
|
+
}
|
|
561
|
+
if (node instanceof Node) {
|
|
562
|
+
return node;
|
|
563
|
+
}
|
|
564
|
+
if (Array.isArray(node)) {
|
|
565
|
+
const fragment = document.createDocumentFragment();
|
|
566
|
+
for (const child of node) {
|
|
567
|
+
fragment.appendChild(nodeToDOM(child));
|
|
568
|
+
}
|
|
569
|
+
return fragment;
|
|
570
|
+
}
|
|
571
|
+
return document.createTextNode(String(node));
|
|
572
|
+
}
|
|
573
|
+
function insert(parent, node, anchor) {
|
|
574
|
+
const domNode = nodeToDOM(node);
|
|
575
|
+
if (anchor) {
|
|
576
|
+
parent.insertBefore(domNode, anchor);
|
|
577
|
+
} else {
|
|
578
|
+
parent.appendChild(domNode);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/component.ts
|
|
583
|
+
var currentHooks = null;
|
|
584
|
+
function onMount(fn) {
|
|
585
|
+
if (!currentHooks) {
|
|
586
|
+
throw akashError("AK0020");
|
|
587
|
+
}
|
|
588
|
+
currentHooks.mount.push(fn);
|
|
589
|
+
}
|
|
590
|
+
function onUnmount(fn) {
|
|
591
|
+
if (!currentHooks) {
|
|
592
|
+
throw akashError("AK0021");
|
|
593
|
+
}
|
|
594
|
+
currentHooks.unmount.push(fn);
|
|
595
|
+
}
|
|
596
|
+
function onError(fn) {
|
|
597
|
+
if (!currentHooks) {
|
|
598
|
+
throw akashError("AK0022");
|
|
599
|
+
}
|
|
600
|
+
currentHooks.error.push(fn);
|
|
601
|
+
}
|
|
602
|
+
function ref() {
|
|
603
|
+
return { current: void 0 };
|
|
604
|
+
}
|
|
605
|
+
function defineComponent(setup) {
|
|
606
|
+
const component = (rawProps) => {
|
|
607
|
+
const { children: childrenProp, ...restProps } = rawProps ?? {};
|
|
608
|
+
const props = restProps;
|
|
609
|
+
const childrenFn = typeof childrenProp === "function" ? childrenProp : () => childrenProp ?? null;
|
|
610
|
+
const ctx = {
|
|
611
|
+
props,
|
|
612
|
+
children: childrenFn
|
|
613
|
+
};
|
|
614
|
+
const hooks = { mount: [], unmount: [], error: [] };
|
|
615
|
+
const prevHooks = currentHooks;
|
|
616
|
+
currentHooks = hooks;
|
|
617
|
+
const parentScope = getCurrentScope();
|
|
618
|
+
const scope = pushScope(parentScope);
|
|
619
|
+
let renderFn;
|
|
620
|
+
let domNode;
|
|
621
|
+
try {
|
|
622
|
+
renderFn = setup(ctx);
|
|
623
|
+
const rendered = renderFn();
|
|
624
|
+
domNode = nodeToDOM(rendered);
|
|
625
|
+
} catch (err) {
|
|
626
|
+
popScope(scope);
|
|
627
|
+
currentHooks = prevHooks;
|
|
628
|
+
if (hooks.error.length > 0) {
|
|
629
|
+
for (const handler of hooks.error) {
|
|
630
|
+
handler(err instanceof Error ? err : new Error(String(err)));
|
|
631
|
+
}
|
|
632
|
+
return document.createComment("error");
|
|
633
|
+
}
|
|
634
|
+
throw err;
|
|
635
|
+
}
|
|
636
|
+
popScope(scope);
|
|
637
|
+
currentHooks = prevHooks;
|
|
638
|
+
if (hooks.mount.length > 0) {
|
|
639
|
+
queueMicrotask(() => {
|
|
640
|
+
for (const mountFn of hooks.mount) {
|
|
641
|
+
try {
|
|
642
|
+
const cleanup = mountFn();
|
|
643
|
+
if (typeof cleanup === "function") {
|
|
644
|
+
hooks.unmount.push(cleanup);
|
|
645
|
+
}
|
|
646
|
+
} catch (err) {
|
|
647
|
+
for (const handler of hooks.error) {
|
|
648
|
+
handler(err instanceof Error ? err : new Error(String(err)));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
return domNode;
|
|
655
|
+
};
|
|
656
|
+
component._akash = true;
|
|
657
|
+
return component;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export { For, Show, akashError, batch, bindProperty, bindText, bindVisible, cloneTemplate, computed, createContext, createElement, createText, defineComponent, effect, flushSync, formatError, getAllErrorCodes, getErrorDef, inject, insert, nodeToDOM, onError, onMount, onUnmount, provide, ref, renderConditional, renderList, setProperty, signal, untrack };
|
|
661
|
+
//# sourceMappingURL=chunk-D3IR22HI.js.map
|
|
662
|
+
//# sourceMappingURL=chunk-D3IR22HI.js.map
|