sibujs 1.2.0 → 1.4.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/README.md +29 -25
- package/dist/browser.cjs +804 -2
- package/dist/browser.d.cts +591 -1
- package/dist/browser.d.ts +591 -1
- package/dist/browser.js +50 -8
- package/dist/build.cjs +655 -237
- package/dist/build.js +15 -93
- package/dist/cdn.global.js +188 -7
- package/dist/chunk-2BYQDGN3.js +742 -0
- package/dist/chunk-32DY64NT.js +282 -0
- package/dist/chunk-3AIRKM3B.js +1263 -0
- package/dist/chunk-3X2YG6YM.js +505 -0
- package/dist/chunk-5X6PP2UK.js +28 -0
- package/dist/chunk-77L6NL3X.js +1097 -0
- package/dist/chunk-BGN5ZMP4.js +26 -0
- package/dist/chunk-BTU3TJDS.js +365 -0
- package/dist/chunk-CHF5OHIA.js +61 -0
- package/dist/chunk-CMBFNA7L.js +27 -0
- package/dist/chunk-CNZ35WI2.js +178 -0
- package/dist/chunk-DAHRH4ON.js +331 -0
- package/dist/chunk-EBGIRKQY.js +616 -0
- package/dist/chunk-EUZND3CB.js +27 -0
- package/dist/chunk-F3FA4F32.js +292 -0
- package/dist/chunk-JAKHTMQU.js +1000 -0
- package/dist/chunk-JCI5M6U6.js +956 -0
- package/dist/chunk-KQPDEVVS.js +398 -0
- package/dist/chunk-M4NLBH4I.js +725 -0
- package/dist/chunk-NEKUBFPT.js +60 -0
- package/dist/chunk-NYVAC6P5.js +37 -0
- package/dist/chunk-PTQJDMRT.js +146 -0
- package/dist/chunk-QWZG56ET.js +2744 -0
- package/dist/chunk-TSOKIX5Z.js +654 -0
- package/dist/chunk-UHNL42EF.js +2730 -0
- package/dist/chunk-VRW3FULF.js +725 -0
- package/dist/chunk-WZSPOOER.js +84 -0
- package/dist/chunk-YT6HQ6AM.js +14 -0
- package/dist/chunk-ZD6OAMTH.js +277 -0
- package/dist/chunk-ZWKZCBO6.js +317 -0
- package/dist/contracts-DDrwxvJ-.d.cts +245 -0
- package/dist/contracts-DDrwxvJ-.d.ts +245 -0
- package/dist/contracts-xo5ckdRP.d.cts +240 -0
- package/dist/contracts-xo5ckdRP.d.ts +240 -0
- package/dist/data.cjs +35 -2
- package/dist/data.d.cts +7 -0
- package/dist/data.d.ts +7 -0
- package/dist/data.js +9 -8
- package/dist/devtools.cjs +122 -0
- package/dist/devtools.d.cts +69 -461
- package/dist/devtools.d.ts +69 -461
- package/dist/devtools.js +127 -6
- package/dist/ecosystem.cjs +23 -6
- package/dist/ecosystem.d.cts +1 -1
- package/dist/ecosystem.d.ts +1 -1
- package/dist/ecosystem.js +10 -9
- package/dist/extras.cjs +1208 -88
- package/dist/extras.d.cts +6 -6
- package/dist/extras.d.ts +6 -6
- package/dist/extras.js +70 -33
- package/dist/index.cjs +663 -158
- package/dist/index.d.cts +398 -40
- package/dist/index.d.ts +398 -40
- package/dist/index.js +39 -21
- package/dist/introspect-BumjnBKr.d.cts +477 -0
- package/dist/introspect-CZrlcaYy.d.ts +477 -0
- package/dist/introspect-Cb0zgpi2.d.cts +477 -0
- package/dist/introspect-Y2xNXGSf.d.ts +477 -0
- package/dist/motion.js +4 -4
- package/dist/patterns.cjs +51 -24
- package/dist/patterns.d.cts +19 -57
- package/dist/patterns.d.ts +19 -57
- package/dist/patterns.js +8 -16
- package/dist/performance.js +4 -4
- package/dist/plugins.cjs +429 -82
- package/dist/plugins.d.cts +27 -4
- package/dist/plugins.d.ts +27 -4
- package/dist/plugins.js +156 -37
- package/dist/ssr-4PBXAOO3.js +40 -0
- package/dist/ssr-Do_SiVoL.d.cts +201 -0
- package/dist/ssr-Do_SiVoL.d.ts +201 -0
- package/dist/ssr.cjs +312 -60
- package/dist/ssr.d.cts +10 -1
- package/dist/ssr.d.ts +10 -1
- package/dist/ssr.js +13 -10
- package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
- package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
- package/dist/testing.cjs +233 -2
- package/dist/testing.d.cts +42 -1
- package/dist/testing.d.ts +42 -1
- package/dist/testing.js +129 -2
- package/dist/ui.cjs +374 -8
- package/dist/ui.d.cts +252 -2
- package/dist/ui.d.ts +252 -2
- package/dist/ui.js +329 -11
- package/dist/widgets.js +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,2744 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__resetIdCounter,
|
|
3
|
+
createId
|
|
4
|
+
} from "./chunk-YT6HQ6AM.js";
|
|
5
|
+
import {
|
|
6
|
+
a,
|
|
7
|
+
abbr,
|
|
8
|
+
address,
|
|
9
|
+
area,
|
|
10
|
+
article,
|
|
11
|
+
aside,
|
|
12
|
+
audio,
|
|
13
|
+
b,
|
|
14
|
+
base,
|
|
15
|
+
bdi,
|
|
16
|
+
bdo,
|
|
17
|
+
blockquote,
|
|
18
|
+
body,
|
|
19
|
+
br,
|
|
20
|
+
button,
|
|
21
|
+
canvas,
|
|
22
|
+
caption,
|
|
23
|
+
center,
|
|
24
|
+
circle,
|
|
25
|
+
cite,
|
|
26
|
+
clipPath,
|
|
27
|
+
code,
|
|
28
|
+
col,
|
|
29
|
+
colgroup,
|
|
30
|
+
customElement,
|
|
31
|
+
data,
|
|
32
|
+
datalist,
|
|
33
|
+
dd,
|
|
34
|
+
defs,
|
|
35
|
+
del,
|
|
36
|
+
details,
|
|
37
|
+
dfn,
|
|
38
|
+
dialog,
|
|
39
|
+
div,
|
|
40
|
+
dl,
|
|
41
|
+
dt,
|
|
42
|
+
ellipse,
|
|
43
|
+
em,
|
|
44
|
+
embed,
|
|
45
|
+
fieldset,
|
|
46
|
+
figcaption,
|
|
47
|
+
figure,
|
|
48
|
+
font,
|
|
49
|
+
footer,
|
|
50
|
+
form,
|
|
51
|
+
g,
|
|
52
|
+
h1,
|
|
53
|
+
h2,
|
|
54
|
+
h3,
|
|
55
|
+
h4,
|
|
56
|
+
h5,
|
|
57
|
+
h6,
|
|
58
|
+
head,
|
|
59
|
+
header,
|
|
60
|
+
hr,
|
|
61
|
+
i,
|
|
62
|
+
iframe,
|
|
63
|
+
img,
|
|
64
|
+
input,
|
|
65
|
+
ins,
|
|
66
|
+
kbd,
|
|
67
|
+
label,
|
|
68
|
+
legend,
|
|
69
|
+
li,
|
|
70
|
+
line,
|
|
71
|
+
linearGradient,
|
|
72
|
+
link,
|
|
73
|
+
main,
|
|
74
|
+
map,
|
|
75
|
+
mark,
|
|
76
|
+
marker,
|
|
77
|
+
marquee,
|
|
78
|
+
mask,
|
|
79
|
+
math,
|
|
80
|
+
menu,
|
|
81
|
+
meta,
|
|
82
|
+
meter,
|
|
83
|
+
nav,
|
|
84
|
+
noscript,
|
|
85
|
+
object,
|
|
86
|
+
ol,
|
|
87
|
+
optgroup,
|
|
88
|
+
option,
|
|
89
|
+
output,
|
|
90
|
+
p,
|
|
91
|
+
param,
|
|
92
|
+
path,
|
|
93
|
+
pattern,
|
|
94
|
+
picture,
|
|
95
|
+
polygon,
|
|
96
|
+
polyline,
|
|
97
|
+
portal,
|
|
98
|
+
pre,
|
|
99
|
+
progress,
|
|
100
|
+
q,
|
|
101
|
+
radialGradient,
|
|
102
|
+
rect,
|
|
103
|
+
rp,
|
|
104
|
+
rt,
|
|
105
|
+
ruby,
|
|
106
|
+
s,
|
|
107
|
+
samp,
|
|
108
|
+
script,
|
|
109
|
+
section,
|
|
110
|
+
select,
|
|
111
|
+
slot,
|
|
112
|
+
small,
|
|
113
|
+
source,
|
|
114
|
+
span,
|
|
115
|
+
stop,
|
|
116
|
+
strong,
|
|
117
|
+
style,
|
|
118
|
+
sub,
|
|
119
|
+
summary,
|
|
120
|
+
sup,
|
|
121
|
+
svg,
|
|
122
|
+
symbol,
|
|
123
|
+
table,
|
|
124
|
+
tbody,
|
|
125
|
+
td,
|
|
126
|
+
template,
|
|
127
|
+
text,
|
|
128
|
+
textarea,
|
|
129
|
+
tfoot,
|
|
130
|
+
th,
|
|
131
|
+
thead,
|
|
132
|
+
time,
|
|
133
|
+
title,
|
|
134
|
+
tr,
|
|
135
|
+
track as track2,
|
|
136
|
+
tspan,
|
|
137
|
+
u,
|
|
138
|
+
ul,
|
|
139
|
+
use,
|
|
140
|
+
var_,
|
|
141
|
+
video
|
|
142
|
+
} from "./chunk-32DY64NT.js";
|
|
143
|
+
import {
|
|
144
|
+
watch
|
|
145
|
+
} from "./chunk-NYVAC6P5.js";
|
|
146
|
+
import {
|
|
147
|
+
context
|
|
148
|
+
} from "./chunk-BGN5ZMP4.js";
|
|
149
|
+
import {
|
|
150
|
+
SVG_NS,
|
|
151
|
+
bindChildNode,
|
|
152
|
+
tagFactory
|
|
153
|
+
} from "./chunk-F3FA4F32.js";
|
|
154
|
+
import {
|
|
155
|
+
bindAttribute,
|
|
156
|
+
bindDynamic,
|
|
157
|
+
checkLeaks,
|
|
158
|
+
dispose,
|
|
159
|
+
registerDisposer
|
|
160
|
+
} from "./chunk-PTQJDMRT.js";
|
|
161
|
+
import {
|
|
162
|
+
derived
|
|
163
|
+
} from "./chunk-NEKUBFPT.js";
|
|
164
|
+
import {
|
|
165
|
+
isUrlAttribute,
|
|
166
|
+
sanitizeUrl
|
|
167
|
+
} from "./chunk-CMBFNA7L.js";
|
|
168
|
+
import {
|
|
169
|
+
effect,
|
|
170
|
+
on
|
|
171
|
+
} from "./chunk-CHF5OHIA.js";
|
|
172
|
+
import {
|
|
173
|
+
disableSSR,
|
|
174
|
+
enableSSR,
|
|
175
|
+
isSSR,
|
|
176
|
+
withSSR
|
|
177
|
+
} from "./chunk-EUZND3CB.js";
|
|
178
|
+
import {
|
|
179
|
+
batch,
|
|
180
|
+
enqueueBatchedSignal,
|
|
181
|
+
isBatching,
|
|
182
|
+
signal
|
|
183
|
+
} from "./chunk-WZSPOOER.js";
|
|
184
|
+
import {
|
|
185
|
+
notifySubscribers,
|
|
186
|
+
recordDependency,
|
|
187
|
+
track,
|
|
188
|
+
untracked
|
|
189
|
+
} from "./chunk-ZD6OAMTH.js";
|
|
190
|
+
import {
|
|
191
|
+
__export,
|
|
192
|
+
devAssert,
|
|
193
|
+
devWarn,
|
|
194
|
+
isDev
|
|
195
|
+
} from "./chunk-5X6PP2UK.js";
|
|
196
|
+
|
|
197
|
+
// index.ts
|
|
198
|
+
var index_exports = {};
|
|
199
|
+
__export(index_exports, {
|
|
200
|
+
DynamicComponent: () => DynamicComponent,
|
|
201
|
+
ErrorBoundary: () => ErrorBoundary,
|
|
202
|
+
ErrorDisplay: () => ErrorDisplay,
|
|
203
|
+
Fragment: () => Fragment,
|
|
204
|
+
KeepAlive: () => KeepAlive,
|
|
205
|
+
Loading: () => Loading,
|
|
206
|
+
Portal: () => Portal,
|
|
207
|
+
SVG_NS: () => SVG_NS,
|
|
208
|
+
Suspense: () => Suspense,
|
|
209
|
+
__resetIdCounter: () => __resetIdCounter,
|
|
210
|
+
a: () => a,
|
|
211
|
+
abbr: () => abbr,
|
|
212
|
+
action: () => action,
|
|
213
|
+
address: () => address,
|
|
214
|
+
area: () => area,
|
|
215
|
+
array: () => array,
|
|
216
|
+
article: () => article,
|
|
217
|
+
aside: () => aside,
|
|
218
|
+
asyncDerived: () => asyncDerived,
|
|
219
|
+
audio: () => audio,
|
|
220
|
+
autoResize: () => autoResize,
|
|
221
|
+
b: () => b,
|
|
222
|
+
base: () => base,
|
|
223
|
+
batch: () => batch,
|
|
224
|
+
bdi: () => bdi,
|
|
225
|
+
bdo: () => bdo,
|
|
226
|
+
bindDynamic: () => bindDynamic,
|
|
227
|
+
blockquote: () => blockquote,
|
|
228
|
+
body: () => body,
|
|
229
|
+
br: () => br,
|
|
230
|
+
button: () => button,
|
|
231
|
+
canvas: () => canvas,
|
|
232
|
+
caption: () => caption,
|
|
233
|
+
catchError: () => catchError,
|
|
234
|
+
catchErrorAsync: () => catchErrorAsync,
|
|
235
|
+
center: () => center,
|
|
236
|
+
checkLeaks: () => checkLeaks,
|
|
237
|
+
circle: () => circle,
|
|
238
|
+
cite: () => cite,
|
|
239
|
+
clickOutside: () => clickOutside,
|
|
240
|
+
clipPath: () => clipPath,
|
|
241
|
+
code: () => code,
|
|
242
|
+
col: () => col,
|
|
243
|
+
colgroup: () => colgroup,
|
|
244
|
+
context: () => context,
|
|
245
|
+
copyOnClick: () => copyOnClick,
|
|
246
|
+
createId: () => createId,
|
|
247
|
+
customElement: () => customElement,
|
|
248
|
+
data: () => data,
|
|
249
|
+
datalist: () => datalist,
|
|
250
|
+
dd: () => dd,
|
|
251
|
+
deepEqual: () => deepEqual,
|
|
252
|
+
deepSignal: () => deepSignal,
|
|
253
|
+
defer: () => defer,
|
|
254
|
+
defs: () => defs,
|
|
255
|
+
del: () => del,
|
|
256
|
+
derived: () => derived,
|
|
257
|
+
details: () => details,
|
|
258
|
+
dfn: () => dfn,
|
|
259
|
+
dialog: () => dialog,
|
|
260
|
+
disableSSR: () => disableSSR,
|
|
261
|
+
dispose: () => dispose,
|
|
262
|
+
div: () => div,
|
|
263
|
+
dl: () => dl,
|
|
264
|
+
dt: () => dt,
|
|
265
|
+
each: () => each,
|
|
266
|
+
effect: () => effect,
|
|
267
|
+
ellipse: () => ellipse,
|
|
268
|
+
em: () => em,
|
|
269
|
+
embed: () => embed,
|
|
270
|
+
enableSSR: () => enableSSR,
|
|
271
|
+
enqueueBatchedSignal: () => enqueueBatchedSignal,
|
|
272
|
+
fieldset: () => fieldset,
|
|
273
|
+
figcaption: () => figcaption,
|
|
274
|
+
figure: () => figure,
|
|
275
|
+
font: () => font,
|
|
276
|
+
footer: () => footer,
|
|
277
|
+
form: () => form,
|
|
278
|
+
g: () => g,
|
|
279
|
+
getSlot: () => getSlot,
|
|
280
|
+
h1: () => h1,
|
|
281
|
+
h2: () => h2,
|
|
282
|
+
h3: () => h3,
|
|
283
|
+
h4: () => h4,
|
|
284
|
+
h5: () => h5,
|
|
285
|
+
h6: () => h6,
|
|
286
|
+
head: () => head,
|
|
287
|
+
header: () => header,
|
|
288
|
+
hr: () => hr,
|
|
289
|
+
html: () => html,
|
|
290
|
+
i: () => i,
|
|
291
|
+
iframe: () => iframe,
|
|
292
|
+
img: () => img,
|
|
293
|
+
input: () => input,
|
|
294
|
+
ins: () => ins,
|
|
295
|
+
isBatching: () => isBatching,
|
|
296
|
+
isSSR: () => isSSR,
|
|
297
|
+
kbd: () => kbd,
|
|
298
|
+
label: () => label,
|
|
299
|
+
lazy: () => lazy,
|
|
300
|
+
legend: () => legend,
|
|
301
|
+
li: () => li,
|
|
302
|
+
line: () => line,
|
|
303
|
+
linearGradient: () => linearGradient,
|
|
304
|
+
link: () => link,
|
|
305
|
+
longPress: () => longPress,
|
|
306
|
+
main: () => main,
|
|
307
|
+
map: () => map,
|
|
308
|
+
mark: () => mark,
|
|
309
|
+
marker: () => marker,
|
|
310
|
+
marquee: () => marquee,
|
|
311
|
+
mask: () => mask,
|
|
312
|
+
match: () => match,
|
|
313
|
+
math: () => math,
|
|
314
|
+
memo: () => memo,
|
|
315
|
+
memoFn: () => memoFn,
|
|
316
|
+
menu: () => menu,
|
|
317
|
+
meta: () => meta,
|
|
318
|
+
meter: () => meter,
|
|
319
|
+
mount: () => mount,
|
|
320
|
+
nav: () => nav,
|
|
321
|
+
nextTick: () => nextTick,
|
|
322
|
+
noscript: () => noscript,
|
|
323
|
+
object: () => object,
|
|
324
|
+
ol: () => ol,
|
|
325
|
+
on: () => on,
|
|
326
|
+
onCleanup: () => onCleanup,
|
|
327
|
+
onMount: () => onMount,
|
|
328
|
+
onUnmount: () => onUnmount,
|
|
329
|
+
optgroup: () => optgroup,
|
|
330
|
+
option: () => option,
|
|
331
|
+
output: () => output,
|
|
332
|
+
p: () => p,
|
|
333
|
+
param: () => param,
|
|
334
|
+
path: () => path,
|
|
335
|
+
pattern: () => pattern,
|
|
336
|
+
picture: () => picture,
|
|
337
|
+
polygon: () => polygon,
|
|
338
|
+
polyline: () => polyline,
|
|
339
|
+
portal: () => portal,
|
|
340
|
+
pre: () => pre,
|
|
341
|
+
progress: () => progress,
|
|
342
|
+
q: () => q,
|
|
343
|
+
radialGradient: () => radialGradient,
|
|
344
|
+
reactiveArray: () => reactiveArray,
|
|
345
|
+
rect: () => rect,
|
|
346
|
+
ref: () => ref,
|
|
347
|
+
registerComponent: () => registerComponent,
|
|
348
|
+
registerDisposer: () => registerDisposer,
|
|
349
|
+
resolveComponent: () => resolveComponent,
|
|
350
|
+
rp: () => rp,
|
|
351
|
+
rt: () => rt,
|
|
352
|
+
ruby: () => ruby,
|
|
353
|
+
s: () => s,
|
|
354
|
+
samp: () => samp,
|
|
355
|
+
script: () => script,
|
|
356
|
+
section: () => section,
|
|
357
|
+
select: () => select,
|
|
358
|
+
setGlobalErrorHandler: () => setGlobalErrorHandler,
|
|
359
|
+
show: () => show,
|
|
360
|
+
signal: () => signal,
|
|
361
|
+
slot: () => slot,
|
|
362
|
+
small: () => small,
|
|
363
|
+
source: () => source,
|
|
364
|
+
span: () => span,
|
|
365
|
+
stop: () => stop,
|
|
366
|
+
store: () => store,
|
|
367
|
+
strict: () => strict,
|
|
368
|
+
strictEffect: () => strictEffect,
|
|
369
|
+
strong: () => strong,
|
|
370
|
+
style: () => style,
|
|
371
|
+
sub: () => sub,
|
|
372
|
+
summary: () => summary,
|
|
373
|
+
sup: () => sup,
|
|
374
|
+
svg: () => svg,
|
|
375
|
+
symbol: () => symbol,
|
|
376
|
+
table: () => table,
|
|
377
|
+
tagFactory: () => tagFactory,
|
|
378
|
+
tbody: () => tbody,
|
|
379
|
+
td: () => td,
|
|
380
|
+
template: () => template,
|
|
381
|
+
text: () => text,
|
|
382
|
+
textarea: () => textarea,
|
|
383
|
+
tfoot: () => tfoot,
|
|
384
|
+
th: () => th,
|
|
385
|
+
thead: () => thead,
|
|
386
|
+
time: () => time,
|
|
387
|
+
title: () => title,
|
|
388
|
+
tr: () => tr,
|
|
389
|
+
track: () => track2,
|
|
390
|
+
transition: () => transition,
|
|
391
|
+
trapFocus: () => trapFocus,
|
|
392
|
+
tspan: () => tspan,
|
|
393
|
+
u: () => u,
|
|
394
|
+
ul: () => ul,
|
|
395
|
+
unregisterComponent: () => unregisterComponent,
|
|
396
|
+
untracked: () => untracked,
|
|
397
|
+
use: () => use,
|
|
398
|
+
var_: () => var_,
|
|
399
|
+
video: () => video,
|
|
400
|
+
watch: () => watch,
|
|
401
|
+
when: () => when,
|
|
402
|
+
withSSR: () => withSSR,
|
|
403
|
+
writable: () => writable
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// src/core/rendering/htm.ts
|
|
407
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
408
|
+
"area",
|
|
409
|
+
"base",
|
|
410
|
+
"br",
|
|
411
|
+
"col",
|
|
412
|
+
"embed",
|
|
413
|
+
"hr",
|
|
414
|
+
"img",
|
|
415
|
+
"input",
|
|
416
|
+
"link",
|
|
417
|
+
"meta",
|
|
418
|
+
"param",
|
|
419
|
+
"source",
|
|
420
|
+
"track",
|
|
421
|
+
"wbr"
|
|
422
|
+
]);
|
|
423
|
+
var SVG_TAGS = /* @__PURE__ */ new Set([
|
|
424
|
+
"svg",
|
|
425
|
+
"circle",
|
|
426
|
+
"ellipse",
|
|
427
|
+
"g",
|
|
428
|
+
"line",
|
|
429
|
+
"path",
|
|
430
|
+
"polygon",
|
|
431
|
+
"polyline",
|
|
432
|
+
"rect",
|
|
433
|
+
"text",
|
|
434
|
+
"tspan",
|
|
435
|
+
"defs",
|
|
436
|
+
"clipPath",
|
|
437
|
+
"mask",
|
|
438
|
+
"pattern",
|
|
439
|
+
"linearGradient",
|
|
440
|
+
"radialGradient",
|
|
441
|
+
"stop",
|
|
442
|
+
"use",
|
|
443
|
+
"symbol",
|
|
444
|
+
"marker"
|
|
445
|
+
]);
|
|
446
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
447
|
+
function parseTemplate(strings) {
|
|
448
|
+
const exprCount = strings.length - 1;
|
|
449
|
+
let template2 = strings[0];
|
|
450
|
+
for (let i2 = 0; i2 < exprCount; i2++) {
|
|
451
|
+
template2 += `\0${i2}\0${strings[i2 + 1]}`;
|
|
452
|
+
}
|
|
453
|
+
let pos = 0;
|
|
454
|
+
const len = template2.length;
|
|
455
|
+
function skipWs() {
|
|
456
|
+
while (pos < len && (template2[pos] === " " || template2[pos] === " " || template2[pos] === "\n" || template2[pos] === "\r"))
|
|
457
|
+
pos++;
|
|
458
|
+
}
|
|
459
|
+
function tryExprIdx() {
|
|
460
|
+
if (template2.charCodeAt(pos) !== 0) return -1;
|
|
461
|
+
const start = pos;
|
|
462
|
+
pos++;
|
|
463
|
+
let idx = 0;
|
|
464
|
+
while (pos < len && template2.charCodeAt(pos) !== 0) {
|
|
465
|
+
idx = idx * 10 + (template2.charCodeAt(pos) - 48);
|
|
466
|
+
pos++;
|
|
467
|
+
}
|
|
468
|
+
if (pos < len) pos++;
|
|
469
|
+
if (idx < 0 || idx >= exprCount) {
|
|
470
|
+
pos = start;
|
|
471
|
+
return -1;
|
|
472
|
+
}
|
|
473
|
+
return idx;
|
|
474
|
+
}
|
|
475
|
+
function readTagName() {
|
|
476
|
+
const start = pos;
|
|
477
|
+
while (pos < len) {
|
|
478
|
+
const c = template2.charCodeAt(pos);
|
|
479
|
+
if (c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45) {
|
|
480
|
+
pos++;
|
|
481
|
+
} else break;
|
|
482
|
+
}
|
|
483
|
+
return template2.slice(start, pos);
|
|
484
|
+
}
|
|
485
|
+
function parseAttrValue() {
|
|
486
|
+
skipWs();
|
|
487
|
+
if (template2[pos] !== "=") return { kind: "bool" };
|
|
488
|
+
pos++;
|
|
489
|
+
skipWs();
|
|
490
|
+
const exprIdx = tryExprIdx();
|
|
491
|
+
if (exprIdx >= 0) return { kind: "expr", idx: exprIdx };
|
|
492
|
+
const quote = template2[pos];
|
|
493
|
+
if (quote === '"' || quote === "'") {
|
|
494
|
+
pos++;
|
|
495
|
+
const statics = [];
|
|
496
|
+
const exprs = [];
|
|
497
|
+
let current = "";
|
|
498
|
+
while (pos < len && template2[pos] !== quote) {
|
|
499
|
+
const innerIdx = tryExprIdx();
|
|
500
|
+
if (innerIdx >= 0) {
|
|
501
|
+
statics.push(current);
|
|
502
|
+
current = "";
|
|
503
|
+
exprs.push(innerIdx);
|
|
504
|
+
} else {
|
|
505
|
+
current += template2[pos++];
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (pos < len) pos++;
|
|
509
|
+
statics.push(current);
|
|
510
|
+
if (exprs.length === 0) {
|
|
511
|
+
return { kind: "static", value: statics[0] };
|
|
512
|
+
}
|
|
513
|
+
return { kind: "mixed", statics, exprs };
|
|
514
|
+
}
|
|
515
|
+
const valStart = pos;
|
|
516
|
+
while (pos < len) {
|
|
517
|
+
const c = template2.charCodeAt(pos);
|
|
518
|
+
if (c === 32 || c === 9 || c === 10 || c === 13 || c === 62 || c === 47) break;
|
|
519
|
+
pos++;
|
|
520
|
+
}
|
|
521
|
+
const val = template2.slice(valStart, pos);
|
|
522
|
+
return { kind: "static", value: val };
|
|
523
|
+
}
|
|
524
|
+
function parseAttrs() {
|
|
525
|
+
const attrs = [];
|
|
526
|
+
while (pos < len) {
|
|
527
|
+
skipWs();
|
|
528
|
+
if (template2[pos] === ">" || template2[pos] === "/") break;
|
|
529
|
+
const attrStart = pos;
|
|
530
|
+
while (pos < len) {
|
|
531
|
+
const c = template2.charCodeAt(pos);
|
|
532
|
+
if (c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 58 || c === 95 || c === 46) {
|
|
533
|
+
pos++;
|
|
534
|
+
} else break;
|
|
535
|
+
}
|
|
536
|
+
const attrName = template2.slice(attrStart, pos);
|
|
537
|
+
if (!attrName) break;
|
|
538
|
+
const val = parseAttrValue();
|
|
539
|
+
if (attrName.startsWith("on:")) {
|
|
540
|
+
if (val.kind === "expr") {
|
|
541
|
+
attrs.push({ t: 3, name: attrName.slice(3), idx: val.idx });
|
|
542
|
+
}
|
|
543
|
+
} else if (val.kind === "bool") {
|
|
544
|
+
attrs.push({ t: 4, name: attrName });
|
|
545
|
+
} else if (val.kind === "static") {
|
|
546
|
+
attrs.push({ t: 0, name: attrName, value: val.value });
|
|
547
|
+
} else if (val.kind === "expr") {
|
|
548
|
+
attrs.push({ t: 1, name: attrName, idx: val.idx });
|
|
549
|
+
} else if (val.kind === "mixed") {
|
|
550
|
+
attrs.push({ t: 2, name: attrName, statics: val.statics, exprs: val.exprs });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return attrs;
|
|
554
|
+
}
|
|
555
|
+
function collapseWs(s2) {
|
|
556
|
+
return s2.replace(/\s+/g, " ");
|
|
557
|
+
}
|
|
558
|
+
function parseTextChildren(children) {
|
|
559
|
+
let text2 = "";
|
|
560
|
+
while (pos < len && template2[pos] !== "<") {
|
|
561
|
+
const idx = tryExprIdx();
|
|
562
|
+
if (idx >= 0) {
|
|
563
|
+
const collapsed2 = collapseWs(text2);
|
|
564
|
+
if (collapsed2) children.push({ t: 1, value: collapsed2 });
|
|
565
|
+
text2 = "";
|
|
566
|
+
children.push({ t: 2, idx });
|
|
567
|
+
} else {
|
|
568
|
+
text2 += template2[pos++];
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const collapsed = collapseWs(text2);
|
|
572
|
+
if (collapsed) children.push({ t: 1, value: collapsed });
|
|
573
|
+
}
|
|
574
|
+
function parseChildren() {
|
|
575
|
+
const children = [];
|
|
576
|
+
while (pos < len) {
|
|
577
|
+
if (template2[pos] === "<" && pos + 1 < len && template2[pos + 1] === "/") break;
|
|
578
|
+
if (template2[pos] === "<") {
|
|
579
|
+
pos++;
|
|
580
|
+
const tag = readTagName();
|
|
581
|
+
const attrs = parseAttrs();
|
|
582
|
+
skipWs();
|
|
583
|
+
const isVoid = VOID_ELEMENTS.has(tag);
|
|
584
|
+
const isSelfClosing = template2[pos] === "/";
|
|
585
|
+
if (isSelfClosing) pos++;
|
|
586
|
+
if (pos < len) pos++;
|
|
587
|
+
if (isVoid || isSelfClosing) {
|
|
588
|
+
children.push({ t: 0, el: { tag, svg: SVG_TAGS.has(tag), attrs, children: [] } });
|
|
589
|
+
} else {
|
|
590
|
+
const inner = parseChildren();
|
|
591
|
+
if (template2[pos] === "<" && pos + 1 < len && template2[pos + 1] === "/") {
|
|
592
|
+
pos += 2;
|
|
593
|
+
readTagName();
|
|
594
|
+
skipWs();
|
|
595
|
+
if (pos < len && template2[pos] === ">") pos++;
|
|
596
|
+
}
|
|
597
|
+
children.push({ t: 0, el: { tag, svg: SVG_TAGS.has(tag), attrs, children: inner } });
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
parseTextChildren(children);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return children;
|
|
604
|
+
}
|
|
605
|
+
return parseChildren();
|
|
606
|
+
}
|
|
607
|
+
function executeElement(tmpl, values) {
|
|
608
|
+
const el = tmpl.svg ? document.createElementNS(SVG_NS, tmpl.tag) : document.createElement(tmpl.tag);
|
|
609
|
+
for (let i2 = 0; i2 < tmpl.attrs.length; i2++) {
|
|
610
|
+
const attr = tmpl.attrs[i2];
|
|
611
|
+
switch (attr.t) {
|
|
612
|
+
case 0:
|
|
613
|
+
el.setAttribute(attr.name, attr.value);
|
|
614
|
+
break;
|
|
615
|
+
case 1: {
|
|
616
|
+
const name = attr.name;
|
|
617
|
+
if (name[0] === "o" && name[1] === "n") break;
|
|
618
|
+
const val = values[attr.idx];
|
|
619
|
+
if (typeof val === "function") {
|
|
620
|
+
registerDisposer(el, bindAttribute(el, name, val));
|
|
621
|
+
} else if (val != null) {
|
|
622
|
+
const str = String(val);
|
|
623
|
+
el.setAttribute(name, isUrlAttribute(name) ? sanitizeUrl(str) : str);
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
case 2: {
|
|
628
|
+
let val = attr.statics[0];
|
|
629
|
+
for (let j = 0; j < attr.exprs.length; j++) {
|
|
630
|
+
val += String(values[attr.exprs[j]]) + attr.statics[j + 1];
|
|
631
|
+
}
|
|
632
|
+
el.setAttribute(attr.name, val);
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
case 3:
|
|
636
|
+
el.addEventListener(attr.name, values[attr.idx]);
|
|
637
|
+
break;
|
|
638
|
+
case 4:
|
|
639
|
+
el.setAttribute(attr.name, "");
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
for (let i2 = 0; i2 < tmpl.children.length; i2++) {
|
|
644
|
+
const child = tmpl.children[i2];
|
|
645
|
+
switch (child.t) {
|
|
646
|
+
case 0:
|
|
647
|
+
el.appendChild(executeElement(child.el, values));
|
|
648
|
+
break;
|
|
649
|
+
case 1:
|
|
650
|
+
el.appendChild(document.createTextNode(child.value));
|
|
651
|
+
break;
|
|
652
|
+
case 2: {
|
|
653
|
+
const val = values[child.idx];
|
|
654
|
+
if (typeof val === "function") {
|
|
655
|
+
const ph = document.createComment("");
|
|
656
|
+
el.appendChild(ph);
|
|
657
|
+
registerDisposer(el, bindChildNode(ph, val));
|
|
658
|
+
} else if (val instanceof Node) {
|
|
659
|
+
el.appendChild(val);
|
|
660
|
+
} else if (Array.isArray(val)) {
|
|
661
|
+
for (let j = 0; j < val.length; j++) {
|
|
662
|
+
const item = val[j];
|
|
663
|
+
if (item instanceof Node) {
|
|
664
|
+
el.appendChild(item);
|
|
665
|
+
} else if (item != null && typeof item !== "boolean") {
|
|
666
|
+
el.appendChild(document.createTextNode(String(item)));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
} else if (val != null && typeof val !== "boolean") {
|
|
670
|
+
el.appendChild(document.createTextNode(String(val)));
|
|
671
|
+
}
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return el;
|
|
677
|
+
}
|
|
678
|
+
function html(strings, ...values) {
|
|
679
|
+
let tmpl = cache.get(strings);
|
|
680
|
+
if (!tmpl) {
|
|
681
|
+
tmpl = parseTemplate(strings);
|
|
682
|
+
cache.set(strings, tmpl);
|
|
683
|
+
}
|
|
684
|
+
if (tmpl.length === 1 && tmpl[0].t === 0) {
|
|
685
|
+
return executeElement(tmpl[0].el, values);
|
|
686
|
+
}
|
|
687
|
+
const wrapper = document.createElement("div");
|
|
688
|
+
for (let i2 = 0; i2 < tmpl.length; i2++) {
|
|
689
|
+
const child = tmpl[i2];
|
|
690
|
+
switch (child.t) {
|
|
691
|
+
case 0:
|
|
692
|
+
wrapper.appendChild(executeElement(child.el, values));
|
|
693
|
+
break;
|
|
694
|
+
case 1:
|
|
695
|
+
wrapper.appendChild(document.createTextNode(child.value));
|
|
696
|
+
break;
|
|
697
|
+
case 2: {
|
|
698
|
+
const val = values[child.idx];
|
|
699
|
+
if (val instanceof Node) {
|
|
700
|
+
wrapper.appendChild(val);
|
|
701
|
+
} else if (typeof val === "function") {
|
|
702
|
+
const ph = document.createComment("bind:htm");
|
|
703
|
+
wrapper.appendChild(ph);
|
|
704
|
+
registerDisposer(wrapper, bindChildNode(ph, val));
|
|
705
|
+
} else if (Array.isArray(val)) {
|
|
706
|
+
for (let j = 0; j < val.length; j++) {
|
|
707
|
+
const item = val[j];
|
|
708
|
+
if (item instanceof Node) {
|
|
709
|
+
wrapper.appendChild(item);
|
|
710
|
+
} else if (item != null && typeof item !== "boolean") {
|
|
711
|
+
wrapper.appendChild(document.createTextNode(String(item)));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
} else if (val != null && typeof val !== "boolean") {
|
|
715
|
+
wrapper.appendChild(document.createTextNode(String(val)));
|
|
716
|
+
}
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (wrapper.childNodes.length === 1 && wrapper.firstChild instanceof Element) {
|
|
722
|
+
return wrapper.firstChild;
|
|
723
|
+
}
|
|
724
|
+
return wrapper;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// src/core/rendering/mount.ts
|
|
728
|
+
function mount(component, container) {
|
|
729
|
+
if (!container) {
|
|
730
|
+
throw new Error(
|
|
731
|
+
"[Sibu] mount: container element not found. Make sure the DOM element exists before calling mount()."
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
devAssert(
|
|
735
|
+
typeof component === "function" || component instanceof Node,
|
|
736
|
+
"mount: first argument must be a component function or a DOM Node."
|
|
737
|
+
);
|
|
738
|
+
const startTime = typeof performance !== "undefined" ? performance.now() : 0;
|
|
739
|
+
const node = typeof component === "function" ? component() : component;
|
|
740
|
+
const duration = typeof performance !== "undefined" ? performance.now() - startTime : 0;
|
|
741
|
+
container.appendChild(node);
|
|
742
|
+
const hook = globalThis.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
|
|
743
|
+
if (hook) {
|
|
744
|
+
hook.emit("app:init", { rootElement: node, container, duration });
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
node,
|
|
748
|
+
unmount() {
|
|
749
|
+
if (hook) hook.emit("app:unmount", { rootElement: node });
|
|
750
|
+
dispose(node);
|
|
751
|
+
if (node.parentNode) {
|
|
752
|
+
node.parentNode.removeChild(node);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/core/rendering/each.ts
|
|
759
|
+
var _isDev = isDev();
|
|
760
|
+
function resolveNodeChild(child) {
|
|
761
|
+
if (typeof child === "function") {
|
|
762
|
+
return resolveNodeChild(child());
|
|
763
|
+
}
|
|
764
|
+
if (child instanceof Node) {
|
|
765
|
+
return child;
|
|
766
|
+
}
|
|
767
|
+
return document.createTextNode(String(child));
|
|
768
|
+
}
|
|
769
|
+
function longestIncreasingSubsequence(arr, len) {
|
|
770
|
+
if (len === 0) return [];
|
|
771
|
+
const tails = [];
|
|
772
|
+
const predecessor = new Array(len);
|
|
773
|
+
for (let i2 = 0; i2 < len; i2++) {
|
|
774
|
+
const val = arr[i2];
|
|
775
|
+
let lo = 0;
|
|
776
|
+
let hi = tails.length;
|
|
777
|
+
while (lo < hi) {
|
|
778
|
+
const mid = lo + hi >> 1;
|
|
779
|
+
if (arr[tails[mid]] < val) {
|
|
780
|
+
lo = mid + 1;
|
|
781
|
+
} else {
|
|
782
|
+
hi = mid;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
tails[lo] = i2;
|
|
786
|
+
predecessor[i2] = lo > 0 ? tails[lo - 1] : -1;
|
|
787
|
+
}
|
|
788
|
+
const lisLength = tails.length;
|
|
789
|
+
const result = new Array(lisLength);
|
|
790
|
+
let k = tails[lisLength - 1];
|
|
791
|
+
for (let i2 = lisLength - 1; i2 >= 0; i2--) {
|
|
792
|
+
result[i2] = k;
|
|
793
|
+
k = predecessor[k];
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
function each(getArray, render, options) {
|
|
798
|
+
devAssert(typeof getArray === "function", "each: first argument must be a function that returns an array.");
|
|
799
|
+
devAssert(typeof render === "function", "each: second argument must be a render function.");
|
|
800
|
+
devAssert(
|
|
801
|
+
options && typeof options.key === "function",
|
|
802
|
+
"each: options.key must be a function that returns a unique key per item."
|
|
803
|
+
);
|
|
804
|
+
const anchor = document.createComment("each:anchor");
|
|
805
|
+
const end = document.createComment("each:end");
|
|
806
|
+
const oldKeysBufA = [];
|
|
807
|
+
const oldKeysBufB = [];
|
|
808
|
+
let oldKeys = oldKeysBufA;
|
|
809
|
+
let oldLen = 0;
|
|
810
|
+
let nodeMap = /* @__PURE__ */ new Map();
|
|
811
|
+
let workMap = /* @__PURE__ */ new Map();
|
|
812
|
+
let newNodes = [];
|
|
813
|
+
let newKeysBuf = [];
|
|
814
|
+
let isStableBuf = new Uint8Array(0);
|
|
815
|
+
const oldKeyIndex = /* @__PURE__ */ new Map();
|
|
816
|
+
let reusedNewBuf = [];
|
|
817
|
+
let reusedOldBuf = [];
|
|
818
|
+
const keyIndexMap = /* @__PURE__ */ new Map();
|
|
819
|
+
let initialized = false;
|
|
820
|
+
let sentinelInserted = false;
|
|
821
|
+
const keyFn = options.key;
|
|
822
|
+
const update = () => {
|
|
823
|
+
const arr = getArray();
|
|
824
|
+
const newLen = arr.length;
|
|
825
|
+
const parent = anchor.parentNode;
|
|
826
|
+
if (!parent) return;
|
|
827
|
+
if (!sentinelInserted) {
|
|
828
|
+
parent.insertBefore(end, anchor.nextSibling);
|
|
829
|
+
sentinelInserted = true;
|
|
830
|
+
}
|
|
831
|
+
if (newKeysBuf.length < newLen) {
|
|
832
|
+
newKeysBuf = new Array(newLen);
|
|
833
|
+
}
|
|
834
|
+
for (let i2 = 0; i2 < newLen; i2++) {
|
|
835
|
+
newKeysBuf[i2] = keyFn(arr[i2]);
|
|
836
|
+
}
|
|
837
|
+
const newKeys = newKeysBuf;
|
|
838
|
+
if (newNodes.length < newLen) {
|
|
839
|
+
newNodes = new Array(newLen);
|
|
840
|
+
}
|
|
841
|
+
workMap.clear();
|
|
842
|
+
keyIndexMap.clear();
|
|
843
|
+
for (let i2 = 0; i2 < newLen; i2++) {
|
|
844
|
+
keyIndexMap.set(newKeys[i2], i2);
|
|
845
|
+
}
|
|
846
|
+
for (let i2 = 0; i2 < newLen; i2++) {
|
|
847
|
+
const key = newKeys[i2];
|
|
848
|
+
const existing = nodeMap.get(key);
|
|
849
|
+
let node;
|
|
850
|
+
if (existing !== void 0) {
|
|
851
|
+
node = existing;
|
|
852
|
+
} else {
|
|
853
|
+
const itemKey = key;
|
|
854
|
+
const itemGetter = () => getArray()[keyIndexMap.get(itemKey)];
|
|
855
|
+
const indexGetter = () => keyIndexMap.get(itemKey);
|
|
856
|
+
try {
|
|
857
|
+
node = resolveNodeChild(render(itemGetter, indexGetter));
|
|
858
|
+
} catch (err) {
|
|
859
|
+
if (_isDev) {
|
|
860
|
+
devWarn(
|
|
861
|
+
`each: render threw for item at index ${i2} (key="${newKeys[i2]}"): ${err instanceof Error ? err.message : String(err)}`
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
node = document.createComment(`each:error:${i2}`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
workMap.set(key, node);
|
|
868
|
+
newNodes[i2] = node;
|
|
869
|
+
}
|
|
870
|
+
for (const [key, node] of nodeMap) {
|
|
871
|
+
if (!workMap.has(key)) {
|
|
872
|
+
dispose(node);
|
|
873
|
+
if (node.parentNode) {
|
|
874
|
+
parent.removeChild(node);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (newLen === 0) {
|
|
879
|
+
oldLen = 0;
|
|
880
|
+
const tmp2 = nodeMap;
|
|
881
|
+
nodeMap = workMap;
|
|
882
|
+
workMap = tmp2;
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
oldKeyIndex.clear();
|
|
886
|
+
for (let i2 = 0; i2 < oldLen; i2++) {
|
|
887
|
+
oldKeyIndex.set(oldKeys[i2], i2);
|
|
888
|
+
}
|
|
889
|
+
if (reusedNewBuf.length < newLen) {
|
|
890
|
+
reusedNewBuf = new Array(newLen);
|
|
891
|
+
reusedOldBuf = new Array(newLen);
|
|
892
|
+
}
|
|
893
|
+
let reusedCount = 0;
|
|
894
|
+
for (let i2 = 0; i2 < newLen; i2++) {
|
|
895
|
+
const oldIdx = oldKeyIndex.get(newKeys[i2]);
|
|
896
|
+
if (oldIdx !== void 0) {
|
|
897
|
+
reusedNewBuf[reusedCount] = i2;
|
|
898
|
+
reusedOldBuf[reusedCount] = oldIdx;
|
|
899
|
+
reusedCount++;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const lisIndices = longestIncreasingSubsequence(reusedOldBuf, reusedCount);
|
|
903
|
+
if (isStableBuf.length < newLen) {
|
|
904
|
+
isStableBuf = new Uint8Array(newLen);
|
|
905
|
+
} else {
|
|
906
|
+
isStableBuf.fill(0, 0, newLen);
|
|
907
|
+
}
|
|
908
|
+
for (let i2 = 0; i2 < lisIndices.length; i2++) {
|
|
909
|
+
isStableBuf[reusedNewBuf[lisIndices[i2]]] = 1;
|
|
910
|
+
}
|
|
911
|
+
let nextRef = end;
|
|
912
|
+
for (let i2 = newLen - 1; i2 >= 0; i2--) {
|
|
913
|
+
const node = newNodes[i2];
|
|
914
|
+
if (isStableBuf[i2]) {
|
|
915
|
+
nextRef = node;
|
|
916
|
+
} else {
|
|
917
|
+
if (node.nextSibling !== nextRef) {
|
|
918
|
+
parent.insertBefore(node, nextRef);
|
|
919
|
+
}
|
|
920
|
+
nextRef = node;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const nextOld = oldKeys === oldKeysBufA ? oldKeysBufB : oldKeysBufA;
|
|
924
|
+
if (nextOld.length < newLen) nextOld.length = newLen;
|
|
925
|
+
for (let i2 = 0; i2 < newLen; i2++) nextOld[i2] = newKeys[i2];
|
|
926
|
+
oldKeys = nextOld;
|
|
927
|
+
oldLen = newLen;
|
|
928
|
+
const tmp = nodeMap;
|
|
929
|
+
nodeMap = workMap;
|
|
930
|
+
workMap = tmp;
|
|
931
|
+
initialized = true;
|
|
932
|
+
};
|
|
933
|
+
track(update);
|
|
934
|
+
if (!initialized) {
|
|
935
|
+
queueMicrotask(() => {
|
|
936
|
+
if (!initialized && anchor.parentNode) {
|
|
937
|
+
update();
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
return anchor;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/core/rendering/fragment.ts
|
|
945
|
+
function Fragment(nodes) {
|
|
946
|
+
const frag = document.createDocumentFragment();
|
|
947
|
+
for (const child of nodes) {
|
|
948
|
+
if (child == null || typeof child === "boolean") continue;
|
|
949
|
+
if (Array.isArray(child)) {
|
|
950
|
+
for (const nested of child) {
|
|
951
|
+
if (nested == null || typeof nested === "boolean") continue;
|
|
952
|
+
frag.appendChild(resolveChild(nested));
|
|
953
|
+
}
|
|
954
|
+
} else {
|
|
955
|
+
frag.appendChild(resolveChild(child));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return frag;
|
|
959
|
+
}
|
|
960
|
+
function resolveChild(child) {
|
|
961
|
+
if (child == null) {
|
|
962
|
+
return document.createTextNode("");
|
|
963
|
+
}
|
|
964
|
+
if (child instanceof Node) {
|
|
965
|
+
return child;
|
|
966
|
+
}
|
|
967
|
+
if (typeof child === "function") {
|
|
968
|
+
const result = child();
|
|
969
|
+
if (result instanceof Node) return result;
|
|
970
|
+
return document.createTextNode(String(result ?? ""));
|
|
971
|
+
}
|
|
972
|
+
return document.createTextNode(String(child));
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/core/rendering/portal.ts
|
|
976
|
+
function Portal(nodes, target) {
|
|
977
|
+
const anchor = document.createComment("portal");
|
|
978
|
+
const container = target || document.body;
|
|
979
|
+
let portalContent = null;
|
|
980
|
+
queueMicrotask(() => {
|
|
981
|
+
try {
|
|
982
|
+
portalContent = nodes();
|
|
983
|
+
container.appendChild(portalContent);
|
|
984
|
+
} catch (err) {
|
|
985
|
+
console.error("[Portal] Render error:", err);
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
const observer = new MutationObserver(() => {
|
|
989
|
+
if (!anchor.isConnected && portalContent) {
|
|
990
|
+
portalContent.remove();
|
|
991
|
+
portalContent = null;
|
|
992
|
+
observer.disconnect();
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
queueMicrotask(() => {
|
|
996
|
+
if (anchor.parentNode) {
|
|
997
|
+
observer.observe(anchor.parentNode, { childList: true });
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
return anchor;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// src/core/rendering/dynamic.ts
|
|
1004
|
+
var componentRegistry = /* @__PURE__ */ new Map();
|
|
1005
|
+
function registerComponent(name, component) {
|
|
1006
|
+
componentRegistry.set(name, component);
|
|
1007
|
+
}
|
|
1008
|
+
function unregisterComponent(name) {
|
|
1009
|
+
componentRegistry.delete(name);
|
|
1010
|
+
}
|
|
1011
|
+
function resolveComponent(name) {
|
|
1012
|
+
const component = componentRegistry.get(name);
|
|
1013
|
+
if (component) {
|
|
1014
|
+
return component();
|
|
1015
|
+
}
|
|
1016
|
+
return div({ nodes: `[Component "${name}" not found]` });
|
|
1017
|
+
}
|
|
1018
|
+
function DynamicComponent(is) {
|
|
1019
|
+
const container = div({ class: "sibu-dynamic" });
|
|
1020
|
+
function render() {
|
|
1021
|
+
const target = is();
|
|
1022
|
+
let el;
|
|
1023
|
+
if (typeof target === "function") {
|
|
1024
|
+
el = target();
|
|
1025
|
+
} else {
|
|
1026
|
+
el = resolveComponent(target);
|
|
1027
|
+
}
|
|
1028
|
+
for (const child of Array.from(container.childNodes)) {
|
|
1029
|
+
dispose(child);
|
|
1030
|
+
}
|
|
1031
|
+
container.replaceChildren(el);
|
|
1032
|
+
}
|
|
1033
|
+
track(render);
|
|
1034
|
+
return container;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// src/core/rendering/slots.ts
|
|
1038
|
+
function getSlot(slots, name = "default") {
|
|
1039
|
+
return slots?.[name];
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// src/core/rendering/directives.ts
|
|
1043
|
+
function show(condition, element) {
|
|
1044
|
+
const update = () => {
|
|
1045
|
+
element.style.display = condition() ? "" : "none";
|
|
1046
|
+
};
|
|
1047
|
+
track(update);
|
|
1048
|
+
return element;
|
|
1049
|
+
}
|
|
1050
|
+
function when(condition, thenBranch, elseBranch) {
|
|
1051
|
+
const anchor = document.createComment("when");
|
|
1052
|
+
let currentNode = null;
|
|
1053
|
+
let lastCondition;
|
|
1054
|
+
let initialized = false;
|
|
1055
|
+
const update = () => {
|
|
1056
|
+
const show2 = condition();
|
|
1057
|
+
const parent = anchor.parentNode;
|
|
1058
|
+
if (!parent) return;
|
|
1059
|
+
if (initialized && show2 === lastCondition) return;
|
|
1060
|
+
lastCondition = show2;
|
|
1061
|
+
if (currentNode?.parentNode) {
|
|
1062
|
+
dispose(currentNode);
|
|
1063
|
+
currentNode.parentNode.removeChild(currentNode);
|
|
1064
|
+
currentNode = null;
|
|
1065
|
+
}
|
|
1066
|
+
const result = show2 ? thenBranch() : elseBranch ? elseBranch() : null;
|
|
1067
|
+
if (result != null) {
|
|
1068
|
+
const node = result instanceof Node ? result : document.createTextNode(String(result));
|
|
1069
|
+
parent.insertBefore(node, anchor.nextSibling);
|
|
1070
|
+
currentNode = node;
|
|
1071
|
+
}
|
|
1072
|
+
initialized = true;
|
|
1073
|
+
};
|
|
1074
|
+
track(update);
|
|
1075
|
+
if (!initialized) {
|
|
1076
|
+
queueMicrotask(() => {
|
|
1077
|
+
if (!initialized && anchor.parentNode) update();
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
return anchor;
|
|
1081
|
+
}
|
|
1082
|
+
function match(value, cases, fallback) {
|
|
1083
|
+
const anchor = document.createComment("match");
|
|
1084
|
+
let currentNode = null;
|
|
1085
|
+
let lastKey;
|
|
1086
|
+
let initialized = false;
|
|
1087
|
+
const update = () => {
|
|
1088
|
+
const key = String(value());
|
|
1089
|
+
const parent = anchor.parentNode;
|
|
1090
|
+
if (!parent) return;
|
|
1091
|
+
if (initialized && key === lastKey) return;
|
|
1092
|
+
lastKey = key;
|
|
1093
|
+
if (currentNode?.parentNode) {
|
|
1094
|
+
dispose(currentNode);
|
|
1095
|
+
currentNode.parentNode.removeChild(currentNode);
|
|
1096
|
+
currentNode = null;
|
|
1097
|
+
}
|
|
1098
|
+
const renderFn = cases[key] || fallback;
|
|
1099
|
+
if (renderFn) {
|
|
1100
|
+
const result = renderFn();
|
|
1101
|
+
if (result != null) {
|
|
1102
|
+
const node = result instanceof Node ? result : document.createTextNode(String(result));
|
|
1103
|
+
parent.insertBefore(node, anchor.nextSibling);
|
|
1104
|
+
currentNode = node;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
initialized = true;
|
|
1108
|
+
};
|
|
1109
|
+
track(update);
|
|
1110
|
+
if (!initialized) {
|
|
1111
|
+
queueMicrotask(() => {
|
|
1112
|
+
if (!initialized && anchor.parentNode) update();
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
return anchor;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/core/rendering/keepAlive.ts
|
|
1119
|
+
function KeepAlive(activeKey, cases, options) {
|
|
1120
|
+
const anchor = document.createComment("keep-alive");
|
|
1121
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
1122
|
+
const lruOrder = [];
|
|
1123
|
+
const max = options?.max ?? 0;
|
|
1124
|
+
let currentKey;
|
|
1125
|
+
let currentNode = null;
|
|
1126
|
+
let initialized = false;
|
|
1127
|
+
const update = () => {
|
|
1128
|
+
const key = activeKey();
|
|
1129
|
+
const parent = anchor.parentNode;
|
|
1130
|
+
if (!parent) return;
|
|
1131
|
+
if (initialized && key === currentKey) return;
|
|
1132
|
+
if (currentNode?.parentNode) {
|
|
1133
|
+
parent.removeChild(currentNode);
|
|
1134
|
+
}
|
|
1135
|
+
currentKey = key;
|
|
1136
|
+
let node = cache2.get(key);
|
|
1137
|
+
if (!node) {
|
|
1138
|
+
const factory = cases[key];
|
|
1139
|
+
if (!factory) {
|
|
1140
|
+
currentNode = null;
|
|
1141
|
+
initialized = true;
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
node = factory();
|
|
1145
|
+
cache2.set(key, node);
|
|
1146
|
+
lruOrder.push(key);
|
|
1147
|
+
if (max > 0 && lruOrder.length > max) {
|
|
1148
|
+
const evictKey = lruOrder.shift();
|
|
1149
|
+
const evictNode = cache2.get(evictKey);
|
|
1150
|
+
if (evictNode) {
|
|
1151
|
+
dispose(evictNode);
|
|
1152
|
+
if (evictNode.parentNode) evictNode.parentNode.removeChild(evictNode);
|
|
1153
|
+
cache2.delete(evictKey);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
} else {
|
|
1157
|
+
const idx = lruOrder.indexOf(key);
|
|
1158
|
+
if (idx !== -1) {
|
|
1159
|
+
lruOrder.splice(idx, 1);
|
|
1160
|
+
lruOrder.push(key);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
parent.insertBefore(node, anchor.nextSibling);
|
|
1164
|
+
currentNode = node;
|
|
1165
|
+
initialized = true;
|
|
1166
|
+
};
|
|
1167
|
+
track(update);
|
|
1168
|
+
if (!initialized) {
|
|
1169
|
+
queueMicrotask(() => {
|
|
1170
|
+
if (!initialized && anchor.parentNode) update();
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
return anchor;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// src/core/rendering/action.ts
|
|
1177
|
+
function action(element, actionFn, param2) {
|
|
1178
|
+
const cleanup = actionFn(element, param2);
|
|
1179
|
+
if (typeof cleanup === "function") {
|
|
1180
|
+
registerDisposer(element, cleanup);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
var clickOutside = (element, callback) => {
|
|
1184
|
+
const handler = (e) => {
|
|
1185
|
+
if (!element.contains(e.target)) {
|
|
1186
|
+
callback();
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
document.addEventListener("pointerdown", handler, true);
|
|
1190
|
+
return () => document.removeEventListener("pointerdown", handler, true);
|
|
1191
|
+
};
|
|
1192
|
+
var longPress = (element, options) => {
|
|
1193
|
+
const duration = options.duration ?? 500;
|
|
1194
|
+
let timer = null;
|
|
1195
|
+
const start = () => {
|
|
1196
|
+
timer = setTimeout(() => {
|
|
1197
|
+
options.callback();
|
|
1198
|
+
timer = null;
|
|
1199
|
+
}, duration);
|
|
1200
|
+
};
|
|
1201
|
+
const cancel = () => {
|
|
1202
|
+
if (timer !== null) {
|
|
1203
|
+
clearTimeout(timer);
|
|
1204
|
+
timer = null;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
element.addEventListener("pointerdown", start);
|
|
1208
|
+
element.addEventListener("pointerup", cancel);
|
|
1209
|
+
element.addEventListener("pointerleave", cancel);
|
|
1210
|
+
return () => {
|
|
1211
|
+
cancel();
|
|
1212
|
+
element.removeEventListener("pointerdown", start);
|
|
1213
|
+
element.removeEventListener("pointerup", cancel);
|
|
1214
|
+
element.removeEventListener("pointerleave", cancel);
|
|
1215
|
+
};
|
|
1216
|
+
};
|
|
1217
|
+
var copyOnClick = (element, getText) => {
|
|
1218
|
+
const handler = () => {
|
|
1219
|
+
const text2 = typeof getText === "function" ? getText() : element.textContent ?? "";
|
|
1220
|
+
navigator.clipboard.writeText(text2);
|
|
1221
|
+
};
|
|
1222
|
+
element.addEventListener("click", handler);
|
|
1223
|
+
return () => element.removeEventListener("click", handler);
|
|
1224
|
+
};
|
|
1225
|
+
var autoResize = (element) => {
|
|
1226
|
+
const resize = () => {
|
|
1227
|
+
element.style.overflow = "hidden";
|
|
1228
|
+
element.style.height = "auto";
|
|
1229
|
+
element.style.height = `${element.scrollHeight}px`;
|
|
1230
|
+
};
|
|
1231
|
+
resize();
|
|
1232
|
+
element.addEventListener("input", resize);
|
|
1233
|
+
return () => element.removeEventListener("input", resize);
|
|
1234
|
+
};
|
|
1235
|
+
var trapFocus = (element) => {
|
|
1236
|
+
const focusable = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
1237
|
+
const handler = (e) => {
|
|
1238
|
+
if (e.key !== "Tab") return;
|
|
1239
|
+
const elements = Array.from(element.querySelectorAll(focusable));
|
|
1240
|
+
if (elements.length === 0) return;
|
|
1241
|
+
const first = elements[0];
|
|
1242
|
+
const last = elements[elements.length - 1];
|
|
1243
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
1244
|
+
e.preventDefault();
|
|
1245
|
+
last.focus();
|
|
1246
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
1247
|
+
e.preventDefault();
|
|
1248
|
+
first.focus();
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
element.addEventListener("keydown", handler);
|
|
1252
|
+
return () => element.removeEventListener("keydown", handler);
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
// src/core/rendering/catch.ts
|
|
1256
|
+
var globalErrorHandler = null;
|
|
1257
|
+
function catchError(fn, onError) {
|
|
1258
|
+
try {
|
|
1259
|
+
const result = fn();
|
|
1260
|
+
if (result && typeof result.then === "function") {
|
|
1261
|
+
result.catch((err) => {
|
|
1262
|
+
if (onError) {
|
|
1263
|
+
onError(err, "async");
|
|
1264
|
+
} else if (globalErrorHandler) {
|
|
1265
|
+
globalErrorHandler(err, "async");
|
|
1266
|
+
} else {
|
|
1267
|
+
console.error("Unhandled async error in Sibu.catchError:", err);
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
return result;
|
|
1272
|
+
} catch (err) {
|
|
1273
|
+
if (onError) {
|
|
1274
|
+
onError(err, "sync");
|
|
1275
|
+
} else if (globalErrorHandler) {
|
|
1276
|
+
globalErrorHandler(err, "sync");
|
|
1277
|
+
} else {
|
|
1278
|
+
console.error("Unhandled error in Sibu.catchError:", err);
|
|
1279
|
+
}
|
|
1280
|
+
return null;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
async function catchErrorAsync(fn, onError) {
|
|
1284
|
+
try {
|
|
1285
|
+
return await fn();
|
|
1286
|
+
} catch (err) {
|
|
1287
|
+
if (onError) {
|
|
1288
|
+
onError(err, "async");
|
|
1289
|
+
} else if (globalErrorHandler) {
|
|
1290
|
+
globalErrorHandler(err, "async");
|
|
1291
|
+
} else {
|
|
1292
|
+
console.error("Unhandled async error in Sibu.catchErrorAsync:", err);
|
|
1293
|
+
}
|
|
1294
|
+
return null;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function setGlobalErrorHandler(handler) {
|
|
1298
|
+
globalErrorHandler = handler;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// src/core/signals/store.ts
|
|
1302
|
+
function store(initialState) {
|
|
1303
|
+
devAssert(
|
|
1304
|
+
initialState !== null && typeof initialState === "object" && !Array.isArray(initialState),
|
|
1305
|
+
"store: argument must be a plain object. For arrays, use array() instead."
|
|
1306
|
+
);
|
|
1307
|
+
const signals = {};
|
|
1308
|
+
Object.keys(initialState).forEach((key) => {
|
|
1309
|
+
const [getter, setter] = signal(initialState[key]);
|
|
1310
|
+
signals[key] = [getter, setter];
|
|
1311
|
+
});
|
|
1312
|
+
const store2 = new Proxy({}, {
|
|
1313
|
+
get(_, prop) {
|
|
1314
|
+
if (prop in signals) {
|
|
1315
|
+
const getter = signals[prop][0];
|
|
1316
|
+
return getter();
|
|
1317
|
+
}
|
|
1318
|
+
return void 0;
|
|
1319
|
+
},
|
|
1320
|
+
set() {
|
|
1321
|
+
throw new Error(
|
|
1322
|
+
"[Sibu] store: Direct mutation is not allowed. Use actions.setState() to update store properties."
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
const getSnapshot = () => {
|
|
1327
|
+
const snapshot = {};
|
|
1328
|
+
Object.keys(signals).forEach((key) => {
|
|
1329
|
+
snapshot[key] = signals[key][0]();
|
|
1330
|
+
});
|
|
1331
|
+
return snapshot;
|
|
1332
|
+
};
|
|
1333
|
+
const setState = (patch) => {
|
|
1334
|
+
const current = getSnapshot();
|
|
1335
|
+
const nextState = typeof patch === "function" ? patch(current) : patch;
|
|
1336
|
+
Object.entries(nextState).forEach(([key, value]) => {
|
|
1337
|
+
if (key in signals) {
|
|
1338
|
+
signals[key][1](value);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
};
|
|
1342
|
+
const reset = () => {
|
|
1343
|
+
Object.keys(initialState).forEach((key) => {
|
|
1344
|
+
const setter = signals[key][1];
|
|
1345
|
+
setter(initialState[key]);
|
|
1346
|
+
});
|
|
1347
|
+
};
|
|
1348
|
+
const subscribe = (callback) => {
|
|
1349
|
+
let first = true;
|
|
1350
|
+
return effect(() => {
|
|
1351
|
+
const snapshot = getSnapshot();
|
|
1352
|
+
if (first) {
|
|
1353
|
+
first = false;
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
callback(snapshot);
|
|
1357
|
+
});
|
|
1358
|
+
};
|
|
1359
|
+
const subscribeKey = (key, callback) => {
|
|
1360
|
+
let prev;
|
|
1361
|
+
let first = true;
|
|
1362
|
+
return effect(() => {
|
|
1363
|
+
const current = signals[key][0]();
|
|
1364
|
+
if (first) {
|
|
1365
|
+
prev = current;
|
|
1366
|
+
first = false;
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (!Object.is(current, prev)) {
|
|
1370
|
+
const oldPrev = prev;
|
|
1371
|
+
prev = current;
|
|
1372
|
+
callback(current, oldPrev);
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
};
|
|
1376
|
+
return [store2, { setState, reset, subscribe, subscribeKey, getSnapshot }];
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// src/core/signals/ref.ts
|
|
1380
|
+
function ref(initial) {
|
|
1381
|
+
const [get, set] = signal(initial);
|
|
1382
|
+
return {
|
|
1383
|
+
get current() {
|
|
1384
|
+
return get();
|
|
1385
|
+
},
|
|
1386
|
+
set current(value) {
|
|
1387
|
+
set(value);
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/core/signals/memo.ts
|
|
1393
|
+
function memo(factory) {
|
|
1394
|
+
return derived(factory);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/core/signals/memoFn.ts
|
|
1398
|
+
function memoFn(callback) {
|
|
1399
|
+
return derived(callback);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// src/core/signals/array.ts
|
|
1403
|
+
function array(initial = []) {
|
|
1404
|
+
const [arr, setArr] = signal([...initial]);
|
|
1405
|
+
const actions = {
|
|
1406
|
+
push(...items) {
|
|
1407
|
+
setArr((prev) => [...prev, ...items]);
|
|
1408
|
+
},
|
|
1409
|
+
pop() {
|
|
1410
|
+
let removed;
|
|
1411
|
+
setArr((prev) => {
|
|
1412
|
+
const copy = [...prev];
|
|
1413
|
+
removed = copy.pop();
|
|
1414
|
+
return copy;
|
|
1415
|
+
});
|
|
1416
|
+
return removed;
|
|
1417
|
+
},
|
|
1418
|
+
shift() {
|
|
1419
|
+
let removed;
|
|
1420
|
+
setArr((prev) => {
|
|
1421
|
+
const copy = [...prev];
|
|
1422
|
+
removed = copy.shift();
|
|
1423
|
+
return copy;
|
|
1424
|
+
});
|
|
1425
|
+
return removed;
|
|
1426
|
+
},
|
|
1427
|
+
unshift(...items) {
|
|
1428
|
+
setArr((prev) => [...items, ...prev]);
|
|
1429
|
+
},
|
|
1430
|
+
splice(start, deleteCount = 0, ...items) {
|
|
1431
|
+
let removed = [];
|
|
1432
|
+
setArr((prev) => {
|
|
1433
|
+
const copy = [...prev];
|
|
1434
|
+
removed = copy.splice(start, deleteCount, ...items);
|
|
1435
|
+
return copy;
|
|
1436
|
+
});
|
|
1437
|
+
return removed;
|
|
1438
|
+
},
|
|
1439
|
+
remove(index) {
|
|
1440
|
+
setArr((prev) => prev.filter((_, i2) => i2 !== index));
|
|
1441
|
+
},
|
|
1442
|
+
removeWhere(predicate) {
|
|
1443
|
+
setArr((prev) => {
|
|
1444
|
+
const idx = prev.findIndex(predicate);
|
|
1445
|
+
if (idx === -1) return prev;
|
|
1446
|
+
return prev.filter((_, i2) => i2 !== idx);
|
|
1447
|
+
});
|
|
1448
|
+
},
|
|
1449
|
+
set(items) {
|
|
1450
|
+
setArr([...items]);
|
|
1451
|
+
},
|
|
1452
|
+
update(index, value) {
|
|
1453
|
+
setArr((prev) => prev.map((item, i2) => i2 === index ? value : item));
|
|
1454
|
+
},
|
|
1455
|
+
updateWhere(predicate, updater) {
|
|
1456
|
+
setArr((prev) => prev.map((item) => predicate(item) ? updater(item) : item));
|
|
1457
|
+
},
|
|
1458
|
+
sort(compareFn) {
|
|
1459
|
+
setArr((prev) => [...prev].sort(compareFn));
|
|
1460
|
+
},
|
|
1461
|
+
reverse() {
|
|
1462
|
+
setArr((prev) => [...prev].reverse());
|
|
1463
|
+
},
|
|
1464
|
+
filter(predicate) {
|
|
1465
|
+
setArr((prev) => prev.filter(predicate));
|
|
1466
|
+
},
|
|
1467
|
+
map(transform) {
|
|
1468
|
+
setArr((prev) => prev.map(transform));
|
|
1469
|
+
},
|
|
1470
|
+
clear() {
|
|
1471
|
+
setArr([]);
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
return [arr, actions];
|
|
1475
|
+
}
|
|
1476
|
+
function reactiveArray(initial = []) {
|
|
1477
|
+
let data2 = [...initial];
|
|
1478
|
+
let snapshot = null;
|
|
1479
|
+
const signal2 = {};
|
|
1480
|
+
function notify() {
|
|
1481
|
+
snapshot = null;
|
|
1482
|
+
if (!enqueueBatchedSignal(signal2)) {
|
|
1483
|
+
notifySubscribers(signal2);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
function get() {
|
|
1487
|
+
recordDependency(signal2);
|
|
1488
|
+
if (snapshot === null) {
|
|
1489
|
+
snapshot = Object.freeze([...data2]);
|
|
1490
|
+
}
|
|
1491
|
+
return snapshot;
|
|
1492
|
+
}
|
|
1493
|
+
const actions = {
|
|
1494
|
+
push(...items) {
|
|
1495
|
+
if (items.length === 0) return;
|
|
1496
|
+
data2.push(...items);
|
|
1497
|
+
notify();
|
|
1498
|
+
},
|
|
1499
|
+
pop() {
|
|
1500
|
+
if (data2.length === 0) return void 0;
|
|
1501
|
+
const removed = data2.pop();
|
|
1502
|
+
notify();
|
|
1503
|
+
return removed;
|
|
1504
|
+
},
|
|
1505
|
+
shift() {
|
|
1506
|
+
if (data2.length === 0) return void 0;
|
|
1507
|
+
const removed = data2.shift();
|
|
1508
|
+
notify();
|
|
1509
|
+
return removed;
|
|
1510
|
+
},
|
|
1511
|
+
unshift(...items) {
|
|
1512
|
+
if (items.length === 0) return;
|
|
1513
|
+
data2.unshift(...items);
|
|
1514
|
+
notify();
|
|
1515
|
+
},
|
|
1516
|
+
splice(start, deleteCount = 0, ...items) {
|
|
1517
|
+
const removed = data2.splice(start, deleteCount, ...items);
|
|
1518
|
+
if (removed.length > 0 || items.length > 0) {
|
|
1519
|
+
notify();
|
|
1520
|
+
}
|
|
1521
|
+
return removed;
|
|
1522
|
+
},
|
|
1523
|
+
remove(index) {
|
|
1524
|
+
if (index < 0 || index >= data2.length) return;
|
|
1525
|
+
data2.splice(index, 1);
|
|
1526
|
+
notify();
|
|
1527
|
+
},
|
|
1528
|
+
removeWhere(predicate) {
|
|
1529
|
+
const idx = data2.findIndex(predicate);
|
|
1530
|
+
if (idx === -1) return;
|
|
1531
|
+
data2.splice(idx, 1);
|
|
1532
|
+
notify();
|
|
1533
|
+
},
|
|
1534
|
+
set(items) {
|
|
1535
|
+
data2 = [...items];
|
|
1536
|
+
notify();
|
|
1537
|
+
},
|
|
1538
|
+
update(index, value) {
|
|
1539
|
+
if (index < 0 || index >= data2.length) return;
|
|
1540
|
+
if (Object.is(data2[index], value)) return;
|
|
1541
|
+
data2[index] = value;
|
|
1542
|
+
notify();
|
|
1543
|
+
},
|
|
1544
|
+
updateWhere(predicate, updater) {
|
|
1545
|
+
let changed = false;
|
|
1546
|
+
for (let i2 = 0; i2 < data2.length; i2++) {
|
|
1547
|
+
if (predicate(data2[i2])) {
|
|
1548
|
+
const updated = updater(data2[i2]);
|
|
1549
|
+
if (!Object.is(data2[i2], updated)) {
|
|
1550
|
+
data2[i2] = updated;
|
|
1551
|
+
changed = true;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
if (changed) notify();
|
|
1556
|
+
},
|
|
1557
|
+
sort(compareFn) {
|
|
1558
|
+
if (data2.length <= 1) return;
|
|
1559
|
+
data2.sort(compareFn);
|
|
1560
|
+
notify();
|
|
1561
|
+
},
|
|
1562
|
+
reverse() {
|
|
1563
|
+
if (data2.length <= 1) return;
|
|
1564
|
+
data2.reverse();
|
|
1565
|
+
notify();
|
|
1566
|
+
},
|
|
1567
|
+
filter(predicate) {
|
|
1568
|
+
const filtered = data2.filter(predicate);
|
|
1569
|
+
if (filtered.length === data2.length) return;
|
|
1570
|
+
data2 = filtered;
|
|
1571
|
+
notify();
|
|
1572
|
+
},
|
|
1573
|
+
map(transform) {
|
|
1574
|
+
let changed = false;
|
|
1575
|
+
for (let i2 = 0; i2 < data2.length; i2++) {
|
|
1576
|
+
const transformed = transform(data2[i2], i2);
|
|
1577
|
+
if (!Object.is(data2[i2], transformed)) {
|
|
1578
|
+
data2[i2] = transformed;
|
|
1579
|
+
changed = true;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (changed) notify();
|
|
1583
|
+
},
|
|
1584
|
+
clear() {
|
|
1585
|
+
if (data2.length === 0) return;
|
|
1586
|
+
data2 = [];
|
|
1587
|
+
notify();
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
return [get, actions];
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// src/core/signals/deepSignal.ts
|
|
1594
|
+
function deepEqual(a2, b2, seen) {
|
|
1595
|
+
if (Object.is(a2, b2)) return true;
|
|
1596
|
+
if (a2 == null || b2 == null) return false;
|
|
1597
|
+
if (typeof a2 !== typeof b2) return false;
|
|
1598
|
+
if (typeof a2 !== "object") return false;
|
|
1599
|
+
if (a2 instanceof Date && b2 instanceof Date) return a2.getTime() === b2.getTime();
|
|
1600
|
+
if (a2 instanceof RegExp && b2 instanceof RegExp) return a2.toString() === b2.toString();
|
|
1601
|
+
if (!seen) seen = /* @__PURE__ */ new Set();
|
|
1602
|
+
if (seen.has(a2)) return true;
|
|
1603
|
+
seen.add(a2);
|
|
1604
|
+
if (Array.isArray(a2)) {
|
|
1605
|
+
if (!Array.isArray(b2)) return false;
|
|
1606
|
+
if (a2.length !== b2.length) return false;
|
|
1607
|
+
return a2.every((val, i2) => deepEqual(val, b2[i2], seen));
|
|
1608
|
+
}
|
|
1609
|
+
const keysA = Object.keys(a2);
|
|
1610
|
+
const keysB = Object.keys(b2);
|
|
1611
|
+
if (keysA.length !== keysB.length) return false;
|
|
1612
|
+
return keysA.every(
|
|
1613
|
+
(key) => deepEqual(a2[key], b2[key], seen)
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
function deepSignal(initial) {
|
|
1617
|
+
return signal(initial, { equals: (a2, b2) => deepEqual(a2, b2) });
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
// src/core/signals/writable.ts
|
|
1621
|
+
function writable(get, set, options) {
|
|
1622
|
+
const getter = derived(get, options);
|
|
1623
|
+
const setter = (value) => {
|
|
1624
|
+
batch(() => set(value));
|
|
1625
|
+
};
|
|
1626
|
+
return [getter, setter];
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// src/core/signals/asyncDerived.ts
|
|
1630
|
+
function asyncDerived(factory, initial) {
|
|
1631
|
+
const [value, setValue] = signal(initial);
|
|
1632
|
+
const [loading, setLoading] = signal(false);
|
|
1633
|
+
const [error, setError] = signal(null);
|
|
1634
|
+
const [tick, setTick] = signal(0);
|
|
1635
|
+
let runId = 0;
|
|
1636
|
+
effect(() => {
|
|
1637
|
+
tick();
|
|
1638
|
+
const currentRun = ++runId;
|
|
1639
|
+
setLoading(true);
|
|
1640
|
+
setError(null);
|
|
1641
|
+
let promise;
|
|
1642
|
+
try {
|
|
1643
|
+
promise = factory();
|
|
1644
|
+
} catch (err) {
|
|
1645
|
+
setError(err);
|
|
1646
|
+
setLoading(false);
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
promise.then(
|
|
1650
|
+
(result) => {
|
|
1651
|
+
if (currentRun !== runId) return;
|
|
1652
|
+
setValue(result);
|
|
1653
|
+
setLoading(false);
|
|
1654
|
+
},
|
|
1655
|
+
(err) => {
|
|
1656
|
+
if (currentRun !== runId) return;
|
|
1657
|
+
setError(err);
|
|
1658
|
+
setLoading(false);
|
|
1659
|
+
}
|
|
1660
|
+
);
|
|
1661
|
+
});
|
|
1662
|
+
return {
|
|
1663
|
+
value,
|
|
1664
|
+
loading,
|
|
1665
|
+
error,
|
|
1666
|
+
refresh: () => setTick((n) => n + 1)
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// src/core/rendering/lifecycle.ts
|
|
1671
|
+
function safeCall(cb, hookName) {
|
|
1672
|
+
try {
|
|
1673
|
+
cb();
|
|
1674
|
+
} catch (err) {
|
|
1675
|
+
devWarn(`${hookName}: callback threw: ${err instanceof Error ? err.message : String(err)}`);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
function onMount(callback, element) {
|
|
1679
|
+
if (typeof document === "undefined") return;
|
|
1680
|
+
if (element) {
|
|
1681
|
+
if (element.isConnected) {
|
|
1682
|
+
queueMicrotask(() => {
|
|
1683
|
+
safeCall(callback, "onMount");
|
|
1684
|
+
});
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
const observer = new MutationObserver(() => {
|
|
1688
|
+
if (element.isConnected) {
|
|
1689
|
+
observer.disconnect();
|
|
1690
|
+
safeCall(callback, "onMount");
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
queueMicrotask(() => {
|
|
1694
|
+
if (element.isConnected) {
|
|
1695
|
+
safeCall(callback, "onMount");
|
|
1696
|
+
} else {
|
|
1697
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
1698
|
+
}
|
|
1699
|
+
});
|
|
1700
|
+
} else {
|
|
1701
|
+
queueMicrotask(() => {
|
|
1702
|
+
safeCall(callback, "onMount");
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
function onUnmount(callback, element) {
|
|
1707
|
+
const startObserving = () => {
|
|
1708
|
+
const observer = new MutationObserver(() => {
|
|
1709
|
+
if (!element.isConnected) {
|
|
1710
|
+
observer.disconnect();
|
|
1711
|
+
safeCall(callback, "onUnmount");
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
1715
|
+
};
|
|
1716
|
+
if (element.isConnected) {
|
|
1717
|
+
startObserving();
|
|
1718
|
+
} else {
|
|
1719
|
+
onMount(() => {
|
|
1720
|
+
startObserving();
|
|
1721
|
+
return void 0;
|
|
1722
|
+
}, element);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function onCleanup(callback, element) {
|
|
1726
|
+
registerDisposer(element, callback);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// src/core/strict.ts
|
|
1730
|
+
function strict(fn) {
|
|
1731
|
+
const result = fn();
|
|
1732
|
+
if (isDev()) {
|
|
1733
|
+
queueMicrotask(() => {
|
|
1734
|
+
try {
|
|
1735
|
+
fn();
|
|
1736
|
+
} catch (err) {
|
|
1737
|
+
console.warn("[Sibu strict] second run threw:", err);
|
|
1738
|
+
}
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
return result;
|
|
1742
|
+
}
|
|
1743
|
+
function strictEffect(fn) {
|
|
1744
|
+
if (!isDev()) {
|
|
1745
|
+
return effect(fn);
|
|
1746
|
+
}
|
|
1747
|
+
const firstTeardown = effect(fn);
|
|
1748
|
+
let secondTeardown = null;
|
|
1749
|
+
queueMicrotask(() => {
|
|
1750
|
+
try {
|
|
1751
|
+
secondTeardown = effect(fn);
|
|
1752
|
+
} catch (err) {
|
|
1753
|
+
console.warn("[Sibu strictEffect] second run threw:", err);
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
return () => {
|
|
1757
|
+
firstTeardown();
|
|
1758
|
+
if (secondTeardown) secondTeardown();
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
// src/reactivity/nextTick.ts
|
|
1763
|
+
function nextTick() {
|
|
1764
|
+
return new Promise((resolve) => {
|
|
1765
|
+
queueMicrotask(() => {
|
|
1766
|
+
if (typeof requestAnimationFrame === "function") {
|
|
1767
|
+
requestAnimationFrame(() => resolve());
|
|
1768
|
+
} else {
|
|
1769
|
+
resolve();
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
// src/reactivity/concurrent.ts
|
|
1776
|
+
function defer(getter) {
|
|
1777
|
+
const [value, setValue] = signal(getter());
|
|
1778
|
+
let pending = false;
|
|
1779
|
+
let latest = value();
|
|
1780
|
+
const flush = () => {
|
|
1781
|
+
pending = false;
|
|
1782
|
+
setValue(latest);
|
|
1783
|
+
};
|
|
1784
|
+
const schedule = () => {
|
|
1785
|
+
if (pending) return;
|
|
1786
|
+
pending = true;
|
|
1787
|
+
queueMicrotask(() => {
|
|
1788
|
+
if (typeof requestAnimationFrame === "function") {
|
|
1789
|
+
requestAnimationFrame(flush);
|
|
1790
|
+
} else {
|
|
1791
|
+
flush();
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
};
|
|
1795
|
+
track(() => {
|
|
1796
|
+
latest = getter();
|
|
1797
|
+
schedule();
|
|
1798
|
+
});
|
|
1799
|
+
return value;
|
|
1800
|
+
}
|
|
1801
|
+
var IDLE_FALLBACK_MS = 16;
|
|
1802
|
+
function scheduleIdle(fn) {
|
|
1803
|
+
const g2 = globalThis;
|
|
1804
|
+
if (typeof g2.requestIdleCallback === "function") {
|
|
1805
|
+
g2.requestIdleCallback(fn, { timeout: IDLE_FALLBACK_MS * 4 });
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
if (typeof requestAnimationFrame === "function") {
|
|
1809
|
+
requestAnimationFrame(() => fn());
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
setTimeout(fn, IDLE_FALLBACK_MS);
|
|
1813
|
+
}
|
|
1814
|
+
function transition() {
|
|
1815
|
+
const [pending, setPending] = signal(false);
|
|
1816
|
+
function start(fn) {
|
|
1817
|
+
setPending(true);
|
|
1818
|
+
scheduleIdle(() => {
|
|
1819
|
+
let result;
|
|
1820
|
+
try {
|
|
1821
|
+
result = fn();
|
|
1822
|
+
} catch {
|
|
1823
|
+
setPending(false);
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
if (result && typeof result.then === "function") {
|
|
1827
|
+
result.then(
|
|
1828
|
+
() => setPending(false),
|
|
1829
|
+
() => setPending(false)
|
|
1830
|
+
);
|
|
1831
|
+
} else {
|
|
1832
|
+
setPending(false);
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
return { pending, start };
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
// src/core/rendering/lazy.ts
|
|
1840
|
+
function lazy(importFn) {
|
|
1841
|
+
let cached = null;
|
|
1842
|
+
return function LazyComponent() {
|
|
1843
|
+
if (cached) {
|
|
1844
|
+
return cached();
|
|
1845
|
+
}
|
|
1846
|
+
const [_status, setStatus] = signal("loading");
|
|
1847
|
+
const [_error, setError] = signal(null);
|
|
1848
|
+
const container = div({ class: "sibu-lazy" });
|
|
1849
|
+
importFn().then((mod) => {
|
|
1850
|
+
cached = mod.default;
|
|
1851
|
+
const rendered = cached();
|
|
1852
|
+
container.replaceChildren(rendered);
|
|
1853
|
+
setStatus("loaded");
|
|
1854
|
+
}).catch((err) => {
|
|
1855
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1856
|
+
setError(errorObj);
|
|
1857
|
+
setStatus("error");
|
|
1858
|
+
container.replaceChildren(
|
|
1859
|
+
div({
|
|
1860
|
+
class: "sibu-lazy-error",
|
|
1861
|
+
nodes: `Failed to load component: ${errorObj.message}`
|
|
1862
|
+
})
|
|
1863
|
+
);
|
|
1864
|
+
});
|
|
1865
|
+
container.appendChild(span({ class: "sibu-lazy-loading", nodes: "Loading..." }));
|
|
1866
|
+
return container;
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
function Suspense({ nodes, fallback }) {
|
|
1870
|
+
const container = div({ class: "sibu-suspense" });
|
|
1871
|
+
const fallbackEl = fallback();
|
|
1872
|
+
container.appendChild(fallbackEl);
|
|
1873
|
+
queueMicrotask(() => {
|
|
1874
|
+
try {
|
|
1875
|
+
const childEl = nodes();
|
|
1876
|
+
if (childEl.classList.contains("sibu-lazy")) {
|
|
1877
|
+
const observer = new MutationObserver(() => {
|
|
1878
|
+
const loading = childEl.querySelector(".sibu-lazy-loading");
|
|
1879
|
+
if (!loading) {
|
|
1880
|
+
observer.disconnect();
|
|
1881
|
+
container.replaceChildren(childEl);
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
observer.observe(childEl, { childList: true, subtree: true });
|
|
1885
|
+
if (!childEl.querySelector(".sibu-lazy-loading")) {
|
|
1886
|
+
container.replaceChildren(childEl);
|
|
1887
|
+
}
|
|
1888
|
+
} else {
|
|
1889
|
+
container.replaceChildren(childEl);
|
|
1890
|
+
}
|
|
1891
|
+
} catch {
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
return container;
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// src/components/ErrorDisplay.ts
|
|
1898
|
+
var _isDev2 = isDev();
|
|
1899
|
+
var STYLES = `
|
|
1900
|
+
.sibu-error-display {
|
|
1901
|
+
border: 1px solid var(--sibu-err-border, #e5484d);
|
|
1902
|
+
border-radius: 10px;
|
|
1903
|
+
margin: 12px 0;
|
|
1904
|
+
background: #0f0f1a;
|
|
1905
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
|
1906
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
1907
|
+
color: #e5e7eb;
|
|
1908
|
+
overflow: hidden;
|
|
1909
|
+
}
|
|
1910
|
+
.sibu-error-display[data-severity="warning"] { --sibu-err-border: #d97706; --sibu-err-accent: #d97706; }
|
|
1911
|
+
.sibu-error-display[data-severity="info"] { --sibu-err-border: #3b82f6; --sibu-err-accent: #3b82f6; }
|
|
1912
|
+
.sibu-error-display { --sibu-err-accent: #e5484d; }
|
|
1913
|
+
|
|
1914
|
+
.sibu-error-display .sibu-err-header {
|
|
1915
|
+
display: flex;
|
|
1916
|
+
align-items: center;
|
|
1917
|
+
gap: 10px;
|
|
1918
|
+
padding: 12px 18px;
|
|
1919
|
+
background: var(--sibu-err-accent);
|
|
1920
|
+
color: white;
|
|
1921
|
+
user-select: none;
|
|
1922
|
+
}
|
|
1923
|
+
.sibu-error-display .sibu-err-icon {
|
|
1924
|
+
font-family: 'SF Mono', 'JetBrains Mono', 'Fira Code', monospace;
|
|
1925
|
+
font-weight: bold;
|
|
1926
|
+
font-size: 1.05em;
|
|
1927
|
+
padding: 2px 8px;
|
|
1928
|
+
background: rgba(0, 0, 0, 0.22);
|
|
1929
|
+
border-radius: 4px;
|
|
1930
|
+
letter-spacing: 0.02em;
|
|
1931
|
+
}
|
|
1932
|
+
.sibu-error-display .sibu-err-title {
|
|
1933
|
+
margin: 0;
|
|
1934
|
+
font-size: 0.98em;
|
|
1935
|
+
font-weight: 600;
|
|
1936
|
+
flex: 1;
|
|
1937
|
+
text-overflow: ellipsis;
|
|
1938
|
+
overflow: hidden;
|
|
1939
|
+
white-space: nowrap;
|
|
1940
|
+
}
|
|
1941
|
+
.sibu-error-display .sibu-err-timestamp {
|
|
1942
|
+
font-size: 0.75em;
|
|
1943
|
+
opacity: 0.85;
|
|
1944
|
+
font-family: 'SF Mono', 'JetBrains Mono', monospace;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
.sibu-error-display .sibu-err-body {
|
|
1948
|
+
padding: 16px 18px;
|
|
1949
|
+
}
|
|
1950
|
+
.sibu-error-display .sibu-err-message {
|
|
1951
|
+
font-family: 'SF Mono', 'JetBrains Mono', 'Fira Code', monospace;
|
|
1952
|
+
margin: 0 0 14px;
|
|
1953
|
+
color: #fecaca;
|
|
1954
|
+
word-break: break-word;
|
|
1955
|
+
font-size: 0.9em;
|
|
1956
|
+
line-height: 1.55;
|
|
1957
|
+
padding: 10px 12px;
|
|
1958
|
+
background: rgba(229, 72, 77, 0.08);
|
|
1959
|
+
border-left: 3px solid var(--sibu-err-accent);
|
|
1960
|
+
border-radius: 4px;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
.sibu-error-display .sibu-err-section {
|
|
1964
|
+
margin-top: 14px;
|
|
1965
|
+
border-radius: 6px;
|
|
1966
|
+
border: 1px solid #2a2a3e;
|
|
1967
|
+
background: #0a0a14;
|
|
1968
|
+
overflow: hidden;
|
|
1969
|
+
}
|
|
1970
|
+
.sibu-error-display .sibu-err-section-head {
|
|
1971
|
+
display: flex;
|
|
1972
|
+
align-items: center;
|
|
1973
|
+
justify-content: space-between;
|
|
1974
|
+
padding: 6px 12px;
|
|
1975
|
+
background: #16162a;
|
|
1976
|
+
border-bottom: 1px solid #2a2a3e;
|
|
1977
|
+
font-size: 0.72em;
|
|
1978
|
+
color: #8b8fa3;
|
|
1979
|
+
text-transform: uppercase;
|
|
1980
|
+
letter-spacing: 0.08em;
|
|
1981
|
+
font-weight: 600;
|
|
1982
|
+
}
|
|
1983
|
+
.sibu-error-display .sibu-err-copy-btn {
|
|
1984
|
+
background: transparent;
|
|
1985
|
+
border: 1px solid #3a3a4e;
|
|
1986
|
+
border-radius: 4px;
|
|
1987
|
+
color: #a0a3b8;
|
|
1988
|
+
cursor: pointer;
|
|
1989
|
+
padding: 2px 10px;
|
|
1990
|
+
font-size: 0.95em;
|
|
1991
|
+
font-family: inherit;
|
|
1992
|
+
transition: all 0.12s ease;
|
|
1993
|
+
}
|
|
1994
|
+
.sibu-error-display .sibu-err-copy-btn:hover {
|
|
1995
|
+
background: #2a2a3e;
|
|
1996
|
+
color: #e5e7eb;
|
|
1997
|
+
border-color: #4a4a5e;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
.sibu-error-display .sibu-err-stack {
|
|
2001
|
+
margin: 0;
|
|
2002
|
+
padding: 10px 12px;
|
|
2003
|
+
overflow-x: auto;
|
|
2004
|
+
font-family: 'SF Mono', 'JetBrains Mono', monospace;
|
|
2005
|
+
font-size: 0.8em;
|
|
2006
|
+
line-height: 1.7;
|
|
2007
|
+
}
|
|
2008
|
+
.sibu-error-display .sibu-err-frame {
|
|
2009
|
+
display: flex;
|
|
2010
|
+
gap: 10px;
|
|
2011
|
+
padding: 1px 0;
|
|
2012
|
+
}
|
|
2013
|
+
.sibu-error-display .sibu-err-line {
|
|
2014
|
+
display: inline-block;
|
|
2015
|
+
min-width: 2.2ch;
|
|
2016
|
+
color: #4b5066;
|
|
2017
|
+
text-align: right;
|
|
2018
|
+
user-select: none;
|
|
2019
|
+
flex-shrink: 0;
|
|
2020
|
+
}
|
|
2021
|
+
.sibu-error-display .sibu-err-fn {
|
|
2022
|
+
color: #7dd3fc;
|
|
2023
|
+
font-weight: 500;
|
|
2024
|
+
}
|
|
2025
|
+
.sibu-error-display .sibu-err-loc {
|
|
2026
|
+
color: #6b7280;
|
|
2027
|
+
white-space: nowrap;
|
|
2028
|
+
}
|
|
2029
|
+
.sibu-error-display .sibu-err-cause-label {
|
|
2030
|
+
margin: 12px 0 6px;
|
|
2031
|
+
color: #a0a3b8;
|
|
2032
|
+
font-size: 0.75em;
|
|
2033
|
+
text-transform: uppercase;
|
|
2034
|
+
letter-spacing: 0.05em;
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
.sibu-error-display .sibu-err-meta {
|
|
2038
|
+
margin: 0;
|
|
2039
|
+
padding: 10px 12px;
|
|
2040
|
+
font-family: 'SF Mono', 'JetBrains Mono', monospace;
|
|
2041
|
+
font-size: 0.78em;
|
|
2042
|
+
color: #a0a3b8;
|
|
2043
|
+
display: grid;
|
|
2044
|
+
grid-template-columns: minmax(120px, auto) 1fr;
|
|
2045
|
+
gap: 4px 16px;
|
|
2046
|
+
}
|
|
2047
|
+
.sibu-error-display .sibu-err-meta dt { color: #6b7280; }
|
|
2048
|
+
.sibu-error-display .sibu-err-meta dd { margin: 0; color: #d1d5db; word-break: break-word; }
|
|
2049
|
+
|
|
2050
|
+
.sibu-error-display .sibu-err-actions {
|
|
2051
|
+
display: flex;
|
|
2052
|
+
gap: 8px;
|
|
2053
|
+
margin-top: 16px;
|
|
2054
|
+
}
|
|
2055
|
+
.sibu-error-display .sibu-err-btn {
|
|
2056
|
+
display: inline-flex;
|
|
2057
|
+
align-items: center;
|
|
2058
|
+
gap: 6px;
|
|
2059
|
+
padding: 8px 18px;
|
|
2060
|
+
border: none;
|
|
2061
|
+
border-radius: 6px;
|
|
2062
|
+
cursor: pointer;
|
|
2063
|
+
font-size: 13px;
|
|
2064
|
+
font-weight: 500;
|
|
2065
|
+
transition: all 0.12s ease;
|
|
2066
|
+
font-family: inherit;
|
|
2067
|
+
}
|
|
2068
|
+
.sibu-error-display .sibu-err-btn-retry {
|
|
2069
|
+
background: var(--sibu-err-accent);
|
|
2070
|
+
color: white;
|
|
2071
|
+
}
|
|
2072
|
+
.sibu-error-display .sibu-err-btn-retry:hover { filter: brightness(1.1); }
|
|
2073
|
+
.sibu-error-display .sibu-err-btn-reload {
|
|
2074
|
+
background: #1f2133;
|
|
2075
|
+
color: #d1d5db;
|
|
2076
|
+
border: 1px solid #3a3a4e;
|
|
2077
|
+
}
|
|
2078
|
+
.sibu-error-display .sibu-err-btn-reload:hover { background: #2a2b40; }
|
|
2079
|
+
`;
|
|
2080
|
+
var _stylesInjected = false;
|
|
2081
|
+
function injectStyles() {
|
|
2082
|
+
if (_stylesInjected || typeof document === "undefined") return;
|
|
2083
|
+
const el = style({ nodes: STYLES });
|
|
2084
|
+
document.head.appendChild(el);
|
|
2085
|
+
_stylesInjected = true;
|
|
2086
|
+
}
|
|
2087
|
+
function parseStack(stack) {
|
|
2088
|
+
const frames = [];
|
|
2089
|
+
const lines = stack.split("\n");
|
|
2090
|
+
for (const raw of lines) {
|
|
2091
|
+
const line2 = raw.trim();
|
|
2092
|
+
const chrome = line2.match(/^at\s+(?:(.+?)\s+\((.+)\)|(.+))$/);
|
|
2093
|
+
if (chrome) {
|
|
2094
|
+
frames.push({ fn: chrome[1] || "(anonymous)", loc: chrome[2] || chrome[3] || "" });
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
const ff = line2.match(/^(.+?)@(.+)$/);
|
|
2098
|
+
if (ff) {
|
|
2099
|
+
frames.push({ fn: ff[1] || "(anonymous)", loc: ff[2] || "" });
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return frames;
|
|
2103
|
+
}
|
|
2104
|
+
function normalizeError(err) {
|
|
2105
|
+
if (err instanceof Error) {
|
|
2106
|
+
const code2 = err.code ?? err.name ?? "ERROR";
|
|
2107
|
+
const message = err.message || "Unknown error";
|
|
2108
|
+
const stack = err.stack ?? "";
|
|
2109
|
+
const frames = parseStack(stack);
|
|
2110
|
+
const rawCause = err.cause;
|
|
2111
|
+
const cause = rawCause != null ? normalizeError(rawCause) : null;
|
|
2112
|
+
return { code: code2, message, stack, frames, cause };
|
|
2113
|
+
}
|
|
2114
|
+
return {
|
|
2115
|
+
code: "NON_ERROR",
|
|
2116
|
+
message: typeof err === "string" ? err : JSON.stringify(err),
|
|
2117
|
+
stack: "",
|
|
2118
|
+
frames: [],
|
|
2119
|
+
cause: null
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function buildCopyText(err, meta2) {
|
|
2123
|
+
const lines = [];
|
|
2124
|
+
lines.push(`[${err.code}] ${err.message}`);
|
|
2125
|
+
if (err.stack) {
|
|
2126
|
+
lines.push("");
|
|
2127
|
+
lines.push(err.stack);
|
|
2128
|
+
}
|
|
2129
|
+
if (err.cause) {
|
|
2130
|
+
lines.push("");
|
|
2131
|
+
lines.push("Caused by:");
|
|
2132
|
+
lines.push(` [${err.cause.code}] ${err.cause.message}`);
|
|
2133
|
+
if (err.cause.stack) {
|
|
2134
|
+
const indented = err.cause.stack.split("\n").map((l) => ` ${l}`).join("\n");
|
|
2135
|
+
lines.push(indented);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
if (meta2 && Object.keys(meta2).length > 0) {
|
|
2139
|
+
lines.push("");
|
|
2140
|
+
lines.push("Metadata:");
|
|
2141
|
+
for (const [k, v] of Object.entries(meta2)) {
|
|
2142
|
+
lines.push(` ${k}: ${String(v)}`);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
lines.push("");
|
|
2146
|
+
lines.push(`At: ${(/* @__PURE__ */ new Date()).toISOString()}`);
|
|
2147
|
+
if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
2148
|
+
lines.push(`UA: ${navigator.userAgent}`);
|
|
2149
|
+
}
|
|
2150
|
+
return lines.join("\n");
|
|
2151
|
+
}
|
|
2152
|
+
function renderFrames(frames) {
|
|
2153
|
+
const rows = frames.map(
|
|
2154
|
+
(f, i2) => div({
|
|
2155
|
+
class: "sibu-err-frame",
|
|
2156
|
+
nodes: [
|
|
2157
|
+
span({ class: "sibu-err-line", nodes: String(i2 + 1) }),
|
|
2158
|
+
span({ class: "sibu-err-fn", nodes: f.fn }),
|
|
2159
|
+
span({ class: "sibu-err-loc", nodes: ` \u2014 ${f.loc}` })
|
|
2160
|
+
]
|
|
2161
|
+
})
|
|
2162
|
+
);
|
|
2163
|
+
return pre({ class: "sibu-err-stack", nodes: rows });
|
|
2164
|
+
}
|
|
2165
|
+
function renderCauseChain(cause) {
|
|
2166
|
+
if (!cause) return [];
|
|
2167
|
+
return [
|
|
2168
|
+
div({ class: "sibu-err-cause-label", nodes: "Caused by" }),
|
|
2169
|
+
div({
|
|
2170
|
+
class: "sibu-err-section",
|
|
2171
|
+
nodes: [
|
|
2172
|
+
div({
|
|
2173
|
+
class: "sibu-err-section-head",
|
|
2174
|
+
nodes: [span({ nodes: `[${cause.code}] ${cause.message}` }), span({ nodes: "" })]
|
|
2175
|
+
}),
|
|
2176
|
+
cause.frames.length > 0 ? renderFrames(cause.frames) : div({ class: "sibu-err-stack", nodes: "(no stack)" })
|
|
2177
|
+
]
|
|
2178
|
+
}),
|
|
2179
|
+
...renderCauseChain(cause.cause)
|
|
2180
|
+
];
|
|
2181
|
+
}
|
|
2182
|
+
function renderMetadata(meta2) {
|
|
2183
|
+
const rows = [];
|
|
2184
|
+
for (const [k, v] of Object.entries(meta2)) {
|
|
2185
|
+
rows.push(document.createElement("dt"));
|
|
2186
|
+
rows[rows.length - 1].textContent = k;
|
|
2187
|
+
const dd2 = document.createElement("dd");
|
|
2188
|
+
dd2.textContent = v == null ? "(null)" : String(v);
|
|
2189
|
+
rows.push(dd2);
|
|
2190
|
+
}
|
|
2191
|
+
const dl2 = document.createElement("dl");
|
|
2192
|
+
dl2.className = "sibu-err-meta";
|
|
2193
|
+
for (const r of rows) dl2.appendChild(r);
|
|
2194
|
+
return dl2;
|
|
2195
|
+
}
|
|
2196
|
+
function ErrorDisplay(props) {
|
|
2197
|
+
injectStyles();
|
|
2198
|
+
const severity = props.severity ?? "error";
|
|
2199
|
+
const normalized = normalizeError(props.error);
|
|
2200
|
+
const showDetails = props.alwaysShowDetails ?? _isDev2;
|
|
2201
|
+
const headline = props.title ?? normalized.message;
|
|
2202
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
|
|
2203
|
+
const [copyLabel, setCopyLabel] = signal("Copy");
|
|
2204
|
+
const copyBtn = button({
|
|
2205
|
+
class: "sibu-err-copy-btn",
|
|
2206
|
+
nodes: () => copyLabel(),
|
|
2207
|
+
on: {
|
|
2208
|
+
click: () => {
|
|
2209
|
+
const text2 = buildCopyText(normalized, props.metadata);
|
|
2210
|
+
if (typeof navigator !== "undefined" && navigator.clipboard) {
|
|
2211
|
+
navigator.clipboard.writeText(text2).then(
|
|
2212
|
+
() => {
|
|
2213
|
+
setCopyLabel("Copied!");
|
|
2214
|
+
setTimeout(() => setCopyLabel("Copy"), 1500);
|
|
2215
|
+
},
|
|
2216
|
+
() => {
|
|
2217
|
+
setCopyLabel("Copy failed");
|
|
2218
|
+
setTimeout(() => setCopyLabel("Copy"), 1500);
|
|
2219
|
+
}
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
const header2 = div({
|
|
2226
|
+
class: "sibu-err-header",
|
|
2227
|
+
nodes: [
|
|
2228
|
+
code({ class: "sibu-err-icon", nodes: normalized.code }),
|
|
2229
|
+
h3({ class: "sibu-err-title", nodes: headline }),
|
|
2230
|
+
span({ class: "sibu-err-timestamp", nodes: timestamp })
|
|
2231
|
+
]
|
|
2232
|
+
});
|
|
2233
|
+
const bodyChildren = [p({ class: "sibu-err-message", nodes: normalized.message })];
|
|
2234
|
+
if (showDetails && normalized.frames.length > 0) {
|
|
2235
|
+
bodyChildren.push(
|
|
2236
|
+
div({
|
|
2237
|
+
class: "sibu-err-section",
|
|
2238
|
+
nodes: [
|
|
2239
|
+
div({
|
|
2240
|
+
class: "sibu-err-section-head",
|
|
2241
|
+
nodes: [span({ nodes: "Stack Trace" }), copyBtn]
|
|
2242
|
+
}),
|
|
2243
|
+
renderFrames(normalized.frames)
|
|
2244
|
+
]
|
|
2245
|
+
})
|
|
2246
|
+
);
|
|
2247
|
+
} else if (showDetails) {
|
|
2248
|
+
bodyChildren.push(
|
|
2249
|
+
div({
|
|
2250
|
+
class: "sibu-err-section",
|
|
2251
|
+
nodes: [
|
|
2252
|
+
div({
|
|
2253
|
+
class: "sibu-err-section-head",
|
|
2254
|
+
nodes: [span({ nodes: "Details" }), copyBtn]
|
|
2255
|
+
}),
|
|
2256
|
+
div({ class: "sibu-err-stack", nodes: "(no stack available)" })
|
|
2257
|
+
]
|
|
2258
|
+
})
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
if (showDetails) {
|
|
2262
|
+
bodyChildren.push(...renderCauseChain(normalized.cause));
|
|
2263
|
+
}
|
|
2264
|
+
if (showDetails && props.metadata && Object.keys(props.metadata).length > 0) {
|
|
2265
|
+
bodyChildren.push(
|
|
2266
|
+
div({
|
|
2267
|
+
class: "sibu-err-section",
|
|
2268
|
+
nodes: [
|
|
2269
|
+
div({ class: "sibu-err-section-head", nodes: [span({ nodes: "Metadata" })] }),
|
|
2270
|
+
renderMetadata(props.metadata)
|
|
2271
|
+
]
|
|
2272
|
+
})
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
if (showDetails && typeof navigator !== "undefined" && navigator.userAgent) {
|
|
2276
|
+
bodyChildren.push(
|
|
2277
|
+
div({
|
|
2278
|
+
class: "sibu-err-section",
|
|
2279
|
+
nodes: [
|
|
2280
|
+
div({ class: "sibu-err-section-head", nodes: [span({ nodes: "Environment" })] }),
|
|
2281
|
+
div({
|
|
2282
|
+
class: "sibu-err-meta",
|
|
2283
|
+
nodes: (() => {
|
|
2284
|
+
const dl2 = document.createElement("dl");
|
|
2285
|
+
dl2.className = "sibu-err-meta";
|
|
2286
|
+
const entries = [
|
|
2287
|
+
["User Agent", navigator.userAgent],
|
|
2288
|
+
["URL", typeof location !== "undefined" ? location.href : "(n/a)"],
|
|
2289
|
+
["Timestamp", (/* @__PURE__ */ new Date()).toISOString()]
|
|
2290
|
+
];
|
|
2291
|
+
for (const [k, v] of entries) {
|
|
2292
|
+
const dt2 = document.createElement("dt");
|
|
2293
|
+
dt2.textContent = k;
|
|
2294
|
+
const dd2 = document.createElement("dd");
|
|
2295
|
+
dd2.textContent = v;
|
|
2296
|
+
dl2.appendChild(dt2);
|
|
2297
|
+
dl2.appendChild(dd2);
|
|
2298
|
+
}
|
|
2299
|
+
return dl2;
|
|
2300
|
+
})()
|
|
2301
|
+
})
|
|
2302
|
+
]
|
|
2303
|
+
})
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
const actionButtons = [];
|
|
2307
|
+
if (props.onRetry) {
|
|
2308
|
+
actionButtons.push(
|
|
2309
|
+
button({
|
|
2310
|
+
class: "sibu-err-btn sibu-err-btn-retry",
|
|
2311
|
+
nodes: props.retryLabel ?? "Retry",
|
|
2312
|
+
on: { click: props.onRetry }
|
|
2313
|
+
})
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
if (!props.hideReload && typeof location !== "undefined") {
|
|
2317
|
+
actionButtons.push(
|
|
2318
|
+
button({
|
|
2319
|
+
class: "sibu-err-btn sibu-err-btn-reload",
|
|
2320
|
+
nodes: "Reload Page",
|
|
2321
|
+
on: { click: () => location.reload() }
|
|
2322
|
+
})
|
|
2323
|
+
);
|
|
2324
|
+
}
|
|
2325
|
+
if (actionButtons.length > 0) {
|
|
2326
|
+
bodyChildren.push(div({ class: "sibu-err-actions", nodes: actionButtons }));
|
|
2327
|
+
}
|
|
2328
|
+
const body2 = div({ class: "sibu-err-body", nodes: bodyChildren });
|
|
2329
|
+
return div({
|
|
2330
|
+
class: "sibu-error-display",
|
|
2331
|
+
"data-severity": severity,
|
|
2332
|
+
nodes: [header2, body2]
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// src/components/ErrorBoundary.ts
|
|
2337
|
+
var errorBoundaryStyles = `
|
|
2338
|
+
.sibu-error-boundary {
|
|
2339
|
+
position: relative;
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
.sibu-error-fallback {
|
|
2343
|
+
border: 1px solid #e5484d;
|
|
2344
|
+
border-radius: 8px;
|
|
2345
|
+
padding: 0;
|
|
2346
|
+
margin: 10px 0;
|
|
2347
|
+
background: #1a1a2e;
|
|
2348
|
+
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
|
|
2349
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
2350
|
+
color: #e1e1e6;
|
|
2351
|
+
overflow: hidden;
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
.sibu-error-fallback .sibu-error-header {
|
|
2355
|
+
display: flex;
|
|
2356
|
+
align-items: center;
|
|
2357
|
+
gap: 8px;
|
|
2358
|
+
padding: 12px 16px;
|
|
2359
|
+
background: #e5484d;
|
|
2360
|
+
color: white;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
.sibu-error-fallback .sibu-error-title {
|
|
2364
|
+
margin: 0;
|
|
2365
|
+
font-size: 0.95em;
|
|
2366
|
+
font-weight: 600;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
.sibu-error-fallback .sibu-error-source {
|
|
2370
|
+
margin-left: auto;
|
|
2371
|
+
font-size: 0.8em;
|
|
2372
|
+
opacity: 0.9;
|
|
2373
|
+
font-family: 'SF Mono', 'Fira Code', 'Roboto Mono', monospace;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
.sibu-error-fallback .sibu-error-body {
|
|
2377
|
+
padding: 16px;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
.sibu-error-fallback .sibu-error-message {
|
|
2381
|
+
font-family: 'SF Mono', 'Fira Code', 'Roboto Mono', monospace;
|
|
2382
|
+
margin: 0 0 12px 0;
|
|
2383
|
+
color: #f1a9a0;
|
|
2384
|
+
word-break: break-word;
|
|
2385
|
+
font-size: 0.9em;
|
|
2386
|
+
line-height: 1.5;
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
.sibu-error-fallback .sibu-error-stack-container {
|
|
2390
|
+
position: relative;
|
|
2391
|
+
margin: 0 0 12px 0;
|
|
2392
|
+
border-radius: 6px;
|
|
2393
|
+
border: 1px solid #2a2a3e;
|
|
2394
|
+
background: #12121f;
|
|
2395
|
+
overflow: hidden;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
.sibu-error-fallback .sibu-error-stack-label {
|
|
2399
|
+
display: flex;
|
|
2400
|
+
align-items: center;
|
|
2401
|
+
justify-content: space-between;
|
|
2402
|
+
padding: 6px 12px;
|
|
2403
|
+
background: #1e1e32;
|
|
2404
|
+
border-bottom: 1px solid #2a2a3e;
|
|
2405
|
+
font-size: 0.75em;
|
|
2406
|
+
color: #888;
|
|
2407
|
+
text-transform: uppercase;
|
|
2408
|
+
letter-spacing: 0.05em;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
.sibu-error-fallback .sibu-error-copy-btn {
|
|
2412
|
+
background: transparent;
|
|
2413
|
+
border: 1px solid #3a3a4e;
|
|
2414
|
+
border-radius: 4px;
|
|
2415
|
+
color: #888;
|
|
2416
|
+
cursor: pointer;
|
|
2417
|
+
padding: 2px 8px;
|
|
2418
|
+
font-size: 1em;
|
|
2419
|
+
transition: all 0.15s ease;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
.sibu-error-fallback .sibu-error-copy-btn:hover {
|
|
2423
|
+
background: #2a2a3e;
|
|
2424
|
+
color: #ccc;
|
|
2425
|
+
border-color: #4a4a5e;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
.sibu-error-fallback .sibu-error-stack pre {
|
|
2429
|
+
margin: 0;
|
|
2430
|
+
padding: 12px;
|
|
2431
|
+
overflow-x: auto;
|
|
2432
|
+
font-family: 'SF Mono', 'Fira Code', 'Roboto Mono', monospace;
|
|
2433
|
+
font-size: 0.82em;
|
|
2434
|
+
line-height: 1.6;
|
|
2435
|
+
color: #a0a0b0;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
.sibu-error-fallback .sibu-error-stack .sibu-line-num {
|
|
2439
|
+
display: inline-block;
|
|
2440
|
+
width: 3ch;
|
|
2441
|
+
margin-right: 12px;
|
|
2442
|
+
color: #555;
|
|
2443
|
+
text-align: right;
|
|
2444
|
+
user-select: none;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
.sibu-error-fallback .sibu-error-stack .sibu-stack-fn {
|
|
2448
|
+
color: #7ec8e3;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
.sibu-error-fallback .sibu-error-stack .sibu-stack-loc {
|
|
2452
|
+
color: #666;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
.sibu-error-fallback .sibu-error-actions {
|
|
2456
|
+
display: flex;
|
|
2457
|
+
gap: 8px;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
.sibu-error-fallback .sibu-error-btn {
|
|
2461
|
+
display: inline-flex;
|
|
2462
|
+
align-items: center;
|
|
2463
|
+
gap: 6px;
|
|
2464
|
+
padding: 8px 18px;
|
|
2465
|
+
border: none;
|
|
2466
|
+
border-radius: 6px;
|
|
2467
|
+
cursor: pointer;
|
|
2468
|
+
font-size: 13px;
|
|
2469
|
+
font-weight: 500;
|
|
2470
|
+
transition: all 0.15s ease;
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
.sibu-error-fallback .sibu-error-btn-retry {
|
|
2474
|
+
background: #e5484d;
|
|
2475
|
+
color: white;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
.sibu-error-fallback .sibu-error-btn-retry:hover {
|
|
2479
|
+
background: #d13438;
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
.sibu-error-fallback .sibu-error-btn-reload {
|
|
2483
|
+
background: #2a2a3e;
|
|
2484
|
+
color: #ccc;
|
|
2485
|
+
border: 1px solid #3a3a4e;
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
.sibu-error-fallback .sibu-error-btn-reload:hover {
|
|
2489
|
+
background: #3a3a4e;
|
|
2490
|
+
}
|
|
2491
|
+
`;
|
|
2492
|
+
var stylesInjected = false;
|
|
2493
|
+
function injectStyles2() {
|
|
2494
|
+
if (!stylesInjected && typeof document !== "undefined") {
|
|
2495
|
+
const styleElement = style({ nodes: errorBoundaryStyles });
|
|
2496
|
+
document.head.appendChild(styleElement);
|
|
2497
|
+
stylesInjected = true;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
var fallbackCache = /* @__PURE__ */ new WeakMap();
|
|
2501
|
+
function getMemoizedFallback(fallbackFn, error, retry) {
|
|
2502
|
+
let cache2 = fallbackCache.get(fallbackFn);
|
|
2503
|
+
if (!cache2) {
|
|
2504
|
+
cache2 = /* @__PURE__ */ new Map();
|
|
2505
|
+
fallbackCache.set(fallbackFn, cache2);
|
|
2506
|
+
}
|
|
2507
|
+
const key = error.message;
|
|
2508
|
+
if (!cache2.has(key)) {
|
|
2509
|
+
cache2.set(key, fallbackFn(error, retry));
|
|
2510
|
+
}
|
|
2511
|
+
return cache2.get(key);
|
|
2512
|
+
}
|
|
2513
|
+
function ErrorBoundary({ nodes, fallback, onError, resetKeys }) {
|
|
2514
|
+
injectStyles2();
|
|
2515
|
+
const [error, setError] = signal(null);
|
|
2516
|
+
const retry = () => {
|
|
2517
|
+
if (fallback) {
|
|
2518
|
+
fallbackCache.delete(fallback);
|
|
2519
|
+
}
|
|
2520
|
+
setError(null);
|
|
2521
|
+
};
|
|
2522
|
+
if (resetKeys && resetKeys.length > 0) {
|
|
2523
|
+
let initialized = false;
|
|
2524
|
+
effect(() => {
|
|
2525
|
+
for (const k of resetKeys) {
|
|
2526
|
+
try {
|
|
2527
|
+
k();
|
|
2528
|
+
} catch {
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
if (!initialized) {
|
|
2532
|
+
initialized = true;
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
if (error() !== null) retry();
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
const handleError = (e) => {
|
|
2539
|
+
const errorObj = e instanceof Error ? e : new Error(String(e));
|
|
2540
|
+
setError(errorObj);
|
|
2541
|
+
onError?.(errorObj);
|
|
2542
|
+
return errorObj;
|
|
2543
|
+
};
|
|
2544
|
+
const defaultFallback = (err, retryFn) => {
|
|
2545
|
+
return ErrorDisplay({ error: err, severity: "error", onRetry: retryFn });
|
|
2546
|
+
};
|
|
2547
|
+
const tryRenderFallback = (err) => {
|
|
2548
|
+
const fn = fallback || defaultFallback;
|
|
2549
|
+
try {
|
|
2550
|
+
return getMemoizedFallback(fn, err, retry);
|
|
2551
|
+
} catch (fallbackError) {
|
|
2552
|
+
const propagateError = fallbackError instanceof Error ? fallbackError : new Error(String(fallbackError));
|
|
2553
|
+
queueMicrotask(() => {
|
|
2554
|
+
if (container.parentNode) {
|
|
2555
|
+
container.dispatchEvent(
|
|
2556
|
+
new CustomEvent("sibu:error-propagate", {
|
|
2557
|
+
bubbles: true,
|
|
2558
|
+
detail: { error: propagateError }
|
|
2559
|
+
})
|
|
2560
|
+
);
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
return document.createComment("error-boundary-failed");
|
|
2564
|
+
}
|
|
2565
|
+
};
|
|
2566
|
+
const container = div({
|
|
2567
|
+
class: "sibu-error-boundary",
|
|
2568
|
+
nodes: () => {
|
|
2569
|
+
const currentError = error();
|
|
2570
|
+
if (currentError) {
|
|
2571
|
+
return tryRenderFallback(currentError);
|
|
2572
|
+
}
|
|
2573
|
+
try {
|
|
2574
|
+
const result = nodes();
|
|
2575
|
+
if (result && typeof result.then === "function") {
|
|
2576
|
+
const asyncContainer = div({ class: "sibu-error-async" });
|
|
2577
|
+
asyncContainer.appendChild(span({ class: "sibu-lazy-loading", nodes: "Loading..." }));
|
|
2578
|
+
result.then((el) => {
|
|
2579
|
+
asyncContainer.replaceChildren(el);
|
|
2580
|
+
}).catch((e) => {
|
|
2581
|
+
const err = handleError(e);
|
|
2582
|
+
asyncContainer.replaceChildren(tryRenderFallback(err));
|
|
2583
|
+
});
|
|
2584
|
+
return asyncContainer;
|
|
2585
|
+
}
|
|
2586
|
+
return result;
|
|
2587
|
+
} catch (e) {
|
|
2588
|
+
const errorObj = handleError(e);
|
|
2589
|
+
return tryRenderFallback(errorObj);
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
container.addEventListener("sibu:error-propagate", (e) => {
|
|
2594
|
+
if (error()) return;
|
|
2595
|
+
e.stopPropagation();
|
|
2596
|
+
const customEvent = e;
|
|
2597
|
+
const propagatedError = customEvent.detail?.error;
|
|
2598
|
+
if (propagatedError) {
|
|
2599
|
+
handleError(propagatedError);
|
|
2600
|
+
}
|
|
2601
|
+
});
|
|
2602
|
+
return container;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
// src/components/Loading.ts
|
|
2606
|
+
var loadingStyles = `
|
|
2607
|
+
@keyframes sibu-spin {
|
|
2608
|
+
to { transform: rotate(360deg); }
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
@keyframes sibu-pulse {
|
|
2612
|
+
0%, 100% { opacity: 1; }
|
|
2613
|
+
50% { opacity: 0.4; }
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
.sibu-loading {
|
|
2617
|
+
display: flex;
|
|
2618
|
+
align-items: center;
|
|
2619
|
+
justify-content: center;
|
|
2620
|
+
padding: 20px;
|
|
2621
|
+
gap: 10px;
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
.sibu-loading-spinner {
|
|
2625
|
+
width: 24px;
|
|
2626
|
+
height: 24px;
|
|
2627
|
+
border: 3px solid #e0e0e0;
|
|
2628
|
+
border-top-color: #3b82f6;
|
|
2629
|
+
border-radius: 50%;
|
|
2630
|
+
animation: sibu-spin 0.8s linear infinite;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
.sibu-loading-dots {
|
|
2634
|
+
display: flex;
|
|
2635
|
+
gap: 4px;
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
.sibu-loading-dot {
|
|
2639
|
+
width: 8px;
|
|
2640
|
+
height: 8px;
|
|
2641
|
+
border-radius: 50%;
|
|
2642
|
+
background-color: #3b82f6;
|
|
2643
|
+
animation: sibu-pulse 1.2s ease-in-out infinite;
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
.sibu-loading-dot:nth-child(2) { animation-delay: 0.2s; }
|
|
2647
|
+
.sibu-loading-dot:nth-child(3) { animation-delay: 0.4s; }
|
|
2648
|
+
|
|
2649
|
+
.sibu-loading-text {
|
|
2650
|
+
color: #6b7280;
|
|
2651
|
+
font-size: 14px;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
.sibu-loading-sm .sibu-loading-spinner { width: 16px; height: 16px; border-width: 2px; }
|
|
2655
|
+
.sibu-loading-sm .sibu-loading-dot { width: 6px; height: 6px; }
|
|
2656
|
+
.sibu-loading-lg .sibu-loading-spinner { width: 40px; height: 40px; border-width: 4px; }
|
|
2657
|
+
.sibu-loading-lg .sibu-loading-dot { width: 12px; height: 12px; }
|
|
2658
|
+
.sibu-loading-lg .sibu-loading-dots { gap: 6px; }
|
|
2659
|
+
`;
|
|
2660
|
+
var loadingStylesInjected = false;
|
|
2661
|
+
function injectLoadingStyles() {
|
|
2662
|
+
if (!loadingStylesInjected && typeof document !== "undefined") {
|
|
2663
|
+
document.head.appendChild(style({ nodes: loadingStyles }));
|
|
2664
|
+
loadingStylesInjected = true;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
function Loading(props = {}) {
|
|
2668
|
+
injectLoadingStyles();
|
|
2669
|
+
const { text: text2, variant = "spinner", size = "md" } = props;
|
|
2670
|
+
const sizeClass = size !== "md" ? ` sibu-loading-${size}` : "";
|
|
2671
|
+
if (variant === "dots") {
|
|
2672
|
+
return div({
|
|
2673
|
+
class: `sibu-loading${sizeClass}`,
|
|
2674
|
+
nodes: [
|
|
2675
|
+
div({
|
|
2676
|
+
class: "sibu-loading-dots",
|
|
2677
|
+
nodes: [
|
|
2678
|
+
span({ class: "sibu-loading-dot" }),
|
|
2679
|
+
span({ class: "sibu-loading-dot" }),
|
|
2680
|
+
span({ class: "sibu-loading-dot" })
|
|
2681
|
+
]
|
|
2682
|
+
}),
|
|
2683
|
+
text2 ? span({ class: "sibu-loading-text", nodes: text2 }) : null
|
|
2684
|
+
].filter(Boolean)
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
return div({
|
|
2688
|
+
class: `sibu-loading${sizeClass}`,
|
|
2689
|
+
nodes: [
|
|
2690
|
+
div({ class: "sibu-loading-spinner" }),
|
|
2691
|
+
text2 ? span({ class: "sibu-loading-text", nodes: text2 }) : null
|
|
2692
|
+
].filter(Boolean)
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
export {
|
|
2697
|
+
html,
|
|
2698
|
+
mount,
|
|
2699
|
+
each,
|
|
2700
|
+
Fragment,
|
|
2701
|
+
Portal,
|
|
2702
|
+
registerComponent,
|
|
2703
|
+
unregisterComponent,
|
|
2704
|
+
resolveComponent,
|
|
2705
|
+
DynamicComponent,
|
|
2706
|
+
getSlot,
|
|
2707
|
+
show,
|
|
2708
|
+
when,
|
|
2709
|
+
match,
|
|
2710
|
+
KeepAlive,
|
|
2711
|
+
action,
|
|
2712
|
+
clickOutside,
|
|
2713
|
+
longPress,
|
|
2714
|
+
copyOnClick,
|
|
2715
|
+
autoResize,
|
|
2716
|
+
trapFocus,
|
|
2717
|
+
catchError,
|
|
2718
|
+
catchErrorAsync,
|
|
2719
|
+
setGlobalErrorHandler,
|
|
2720
|
+
store,
|
|
2721
|
+
ref,
|
|
2722
|
+
memo,
|
|
2723
|
+
memoFn,
|
|
2724
|
+
array,
|
|
2725
|
+
reactiveArray,
|
|
2726
|
+
deepEqual,
|
|
2727
|
+
deepSignal,
|
|
2728
|
+
writable,
|
|
2729
|
+
asyncDerived,
|
|
2730
|
+
onMount,
|
|
2731
|
+
onUnmount,
|
|
2732
|
+
onCleanup,
|
|
2733
|
+
strict,
|
|
2734
|
+
strictEffect,
|
|
2735
|
+
nextTick,
|
|
2736
|
+
defer,
|
|
2737
|
+
transition,
|
|
2738
|
+
lazy,
|
|
2739
|
+
Suspense,
|
|
2740
|
+
ErrorDisplay,
|
|
2741
|
+
ErrorBoundary,
|
|
2742
|
+
Loading,
|
|
2743
|
+
index_exports
|
|
2744
|
+
};
|