speexjs 0.2.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.
Files changed (67) hide show
  1. package/README.md +555 -0
  2. package/dist/cli/index.d.ts +1 -0
  3. package/dist/cli/index.js +1017 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/dist/client/index.d.ts +73 -0
  6. package/dist/client/index.js +927 -0
  7. package/dist/client/index.js.map +1 -0
  8. package/dist/client/signals/index.d.ts +62 -0
  9. package/dist/client/signals/index.js +248 -0
  10. package/dist/client/signals/index.js.map +1 -0
  11. package/dist/client/vdom/index.d.ts +50 -0
  12. package/dist/client/vdom/index.js +540 -0
  13. package/dist/client/vdom/index.js.map +1 -0
  14. package/dist/client/vdom/jsx-runtime.d.ts +9 -0
  15. package/dist/client/vdom/jsx-runtime.js +203 -0
  16. package/dist/client/vdom/jsx-runtime.js.map +1 -0
  17. package/dist/index-CMkhSDh7.d.ts +97 -0
  18. package/dist/index.d.ts +18 -0
  19. package/dist/index.js +6402 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/jsx-DGrnv8QB.d.ts +8 -0
  22. package/dist/response-Ca8KWK5_.d.ts +173 -0
  23. package/dist/rpc/index.d.ts +70 -0
  24. package/dist/rpc/index.js +136 -0
  25. package/dist/rpc/index.js.map +1 -0
  26. package/dist/schema/index.d.ts +231 -0
  27. package/dist/schema/index.js +1160 -0
  28. package/dist/schema/index.js.map +1 -0
  29. package/dist/server/auth/index.d.ts +61 -0
  30. package/dist/server/auth/index.js +462 -0
  31. package/dist/server/auth/index.js.map +1 -0
  32. package/dist/server/cache/index.d.ts +45 -0
  33. package/dist/server/cache/index.js +238 -0
  34. package/dist/server/cache/index.js.map +1 -0
  35. package/dist/server/container/index.d.ts +20 -0
  36. package/dist/server/container/index.js +62 -0
  37. package/dist/server/container/index.js.map +1 -0
  38. package/dist/server/controller/index.d.ts +37 -0
  39. package/dist/server/controller/index.js +139 -0
  40. package/dist/server/controller/index.js.map +1 -0
  41. package/dist/server/database/index.d.ts +461 -0
  42. package/dist/server/database/index.js +1977 -0
  43. package/dist/server/database/index.js.map +1 -0
  44. package/dist/server/events/index.d.ts +29 -0
  45. package/dist/server/events/index.js +159 -0
  46. package/dist/server/events/index.js.map +1 -0
  47. package/dist/server/gate/index.d.ts +36 -0
  48. package/dist/server/gate/index.js +169 -0
  49. package/dist/server/gate/index.js.map +1 -0
  50. package/dist/server/http/index.d.ts +45 -0
  51. package/dist/server/http/index.js +871 -0
  52. package/dist/server/http/index.js.map +1 -0
  53. package/dist/server/index.d.ts +79 -0
  54. package/dist/server/index.js +4185 -0
  55. package/dist/server/index.js.map +1 -0
  56. package/dist/server/middleware/index.d.ts +5 -0
  57. package/dist/server/middleware/index.js +416 -0
  58. package/dist/server/middleware/index.js.map +1 -0
  59. package/dist/server/router/index.d.ts +5 -0
  60. package/dist/server/router/index.js +231 -0
  61. package/dist/server/router/index.js.map +1 -0
  62. package/dist/server/storage/index.d.ts +66 -0
  63. package/dist/server/storage/index.js +244 -0
  64. package/dist/server/storage/index.js.map +1 -0
  65. package/dist/session-guard-CZeN87L9.d.ts +48 -0
  66. package/dist/types-CXH8hPei.d.ts +38 -0
  67. package/package.json +138 -0
@@ -0,0 +1,927 @@
1
+ // src/client/signals/index.ts
2
+ var activeTracker = null;
3
+ var activeSources = null;
4
+ var batchDepth = 0;
5
+ var pendingUpdates = /* @__PURE__ */ new Set();
6
+ function flushPending() {
7
+ const fns = [...pendingUpdates];
8
+ pendingUpdates.clear();
9
+ for (const fn of fns) fn();
10
+ }
11
+ function trackSource(node) {
12
+ if (activeSources) activeSources.add(node);
13
+ if (activeTracker) node._subs.add(activeTracker);
14
+ }
15
+ var Signal = class {
16
+ _tag = "signal";
17
+ _subs = /* @__PURE__ */ new Set();
18
+ _value;
19
+ constructor(value) {
20
+ this._value = value;
21
+ }
22
+ get value() {
23
+ trackSource(this);
24
+ return this._value;
25
+ }
26
+ set value(val) {
27
+ if (val !== this._value) {
28
+ this._value = val;
29
+ this._notify();
30
+ }
31
+ }
32
+ peek() {
33
+ return this._value;
34
+ }
35
+ set(v) {
36
+ this.value = v;
37
+ }
38
+ update(fn) {
39
+ this.value = fn(this._value);
40
+ }
41
+ subscribe(fn) {
42
+ const cb = () => fn(this._value);
43
+ this._subs.add(cb);
44
+ return () => this._subs.delete(cb);
45
+ }
46
+ toJSON() {
47
+ return this._value;
48
+ }
49
+ toString() {
50
+ return String(this._value);
51
+ }
52
+ valueOf() {
53
+ return this._value;
54
+ }
55
+ *[Symbol.iterator]() {
56
+ yield this._value;
57
+ }
58
+ _notify() {
59
+ if (batchDepth > 0) {
60
+ for (const s of this._subs) pendingUpdates.add(s);
61
+ } else {
62
+ const subs = [...this._subs];
63
+ for (const s of subs) s();
64
+ }
65
+ }
66
+ };
67
+ var Computed = class {
68
+ _tag = "computed";
69
+ _subs = /* @__PURE__ */ new Set();
70
+ _fn;
71
+ _value;
72
+ _dirty = true;
73
+ _sources = /* @__PURE__ */ new Set();
74
+ _onDepChange = () => {
75
+ if (!this._dirty) {
76
+ this._dirty = true;
77
+ for (const s of [...this._subs]) s();
78
+ }
79
+ };
80
+ constructor(fn) {
81
+ this._fn = fn;
82
+ }
83
+ get value() {
84
+ trackSource(this);
85
+ if (this._dirty) this._eval();
86
+ return this._value;
87
+ }
88
+ peek() {
89
+ if (this._dirty) this._eval();
90
+ return this._value;
91
+ }
92
+ subscribe(fn) {
93
+ this.value;
94
+ const cb = () => fn(this._value);
95
+ this._subs.add(cb);
96
+ return () => this._subs.delete(cb);
97
+ }
98
+ toJSON() {
99
+ return this.value;
100
+ }
101
+ toString() {
102
+ return String(this.value);
103
+ }
104
+ valueOf() {
105
+ return this.value;
106
+ }
107
+ _eval() {
108
+ for (const src of this._sources) {
109
+ src._subs.delete(this._onDepChange);
110
+ }
111
+ this._sources.clear();
112
+ this._dirty = false;
113
+ const prevSources = activeSources;
114
+ const prevTracker = activeTracker;
115
+ activeSources = /* @__PURE__ */ new Set();
116
+ activeTracker = null;
117
+ try {
118
+ this._value = this._fn();
119
+ this._sources = activeSources;
120
+ } finally {
121
+ activeSources = prevSources;
122
+ activeTracker = prevTracker;
123
+ }
124
+ for (const src of this._sources) {
125
+ src._subs.add(this._onDepChange);
126
+ }
127
+ }
128
+ };
129
+ var Effect = class {
130
+ _fn;
131
+ _sources = /* @__PURE__ */ new Set();
132
+ _cleanup;
133
+ _alive = true;
134
+ constructor(fn) {
135
+ this._fn = fn;
136
+ this._run();
137
+ }
138
+ get alive() {
139
+ return this._alive;
140
+ }
141
+ stop() {
142
+ if (!this._alive) return;
143
+ this._alive = false;
144
+ this._removeSubscriptions();
145
+ if (this._cleanup) {
146
+ this._cleanup();
147
+ this._cleanup = void 0;
148
+ }
149
+ }
150
+ start() {
151
+ if (this._alive) return;
152
+ this._alive = true;
153
+ this._run();
154
+ }
155
+ _removeSubscriptions() {
156
+ for (const src of this._sources) {
157
+ src._subs.delete(this._run);
158
+ }
159
+ this._sources.clear();
160
+ }
161
+ _run = () => {
162
+ if (!this._alive) return;
163
+ this._removeSubscriptions();
164
+ if (this._cleanup) {
165
+ this._cleanup();
166
+ this._cleanup = void 0;
167
+ }
168
+ const prevTracker = activeTracker;
169
+ const prevSources = activeSources;
170
+ activeTracker = this._run;
171
+ activeSources = this._sources;
172
+ try {
173
+ const result = this._fn();
174
+ if (typeof result === "function") {
175
+ this._cleanup = result;
176
+ }
177
+ } finally {
178
+ activeTracker = prevTracker;
179
+ activeSources = prevSources;
180
+ }
181
+ };
182
+ };
183
+ function signal(initial) {
184
+ return new Signal(initial);
185
+ }
186
+ function computed(fn) {
187
+ return new Computed(fn);
188
+ }
189
+ function effect(fn) {
190
+ return new Effect(fn);
191
+ }
192
+ function untracked(fn) {
193
+ const prevTracker = activeTracker;
194
+ const prevSources = activeSources;
195
+ activeTracker = null;
196
+ activeSources = null;
197
+ try {
198
+ return fn();
199
+ } finally {
200
+ activeTracker = prevTracker;
201
+ activeSources = prevSources;
202
+ }
203
+ }
204
+ function batch(fn) {
205
+ batchDepth++;
206
+ try {
207
+ return fn();
208
+ } finally {
209
+ batchDepth--;
210
+ if (batchDepth === 0) {
211
+ flushPending();
212
+ }
213
+ }
214
+ }
215
+ function isSignal(val) {
216
+ return val instanceof Signal;
217
+ }
218
+ function isComputed(val) {
219
+ return val instanceof Computed;
220
+ }
221
+ function toSignal(value) {
222
+ if (value instanceof Signal) return value;
223
+ return signal(value);
224
+ }
225
+ function mergeSignals(signals) {
226
+ return computed(() => {
227
+ const result = {};
228
+ for (const key of Object.keys(signals)) {
229
+ result[key] = signals[key].value;
230
+ }
231
+ return result;
232
+ });
233
+ }
234
+
235
+ // src/client/vdom/index.ts
236
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
237
+ "area",
238
+ "base",
239
+ "br",
240
+ "col",
241
+ "embed",
242
+ "hr",
243
+ "img",
244
+ "input",
245
+ "link",
246
+ "meta",
247
+ "param",
248
+ "source",
249
+ "track",
250
+ "wbr"
251
+ ]);
252
+ var SVG_ELEMENTS = /* @__PURE__ */ new Set([
253
+ "svg",
254
+ "path",
255
+ "circle",
256
+ "rect",
257
+ "g",
258
+ "text",
259
+ "line",
260
+ "polyline",
261
+ "polygon",
262
+ "ellipse",
263
+ "use",
264
+ "defs",
265
+ "clipPath",
266
+ "mask",
267
+ "linearGradient",
268
+ "radialGradient",
269
+ "stop",
270
+ "tspan",
271
+ "textPath",
272
+ "image",
273
+ "foreignObject",
274
+ "marker",
275
+ "pattern",
276
+ "symbol",
277
+ "filter",
278
+ "feBlend",
279
+ "feColorMatrix",
280
+ "feComponentTransfer",
281
+ "feComposite",
282
+ "feDropShadow",
283
+ "feFlood",
284
+ "feGaussianBlur",
285
+ "feMerge",
286
+ "feOffset",
287
+ "feImage",
288
+ "feTile",
289
+ "feTurbulence"
290
+ ]);
291
+ function isSignal2(val) {
292
+ return val instanceof Signal;
293
+ }
294
+ function isComputed2(val) {
295
+ return val instanceof Computed;
296
+ }
297
+ function normalizeChild(child) {
298
+ if (child == null || typeof child === "boolean") return null;
299
+ if (isSignal2(child) || isComputed2(child)) {
300
+ return { type: "signal", signal: child };
301
+ }
302
+ if (typeof child === "string" || typeof child === "number") {
303
+ return { type: "text", text: String(child) };
304
+ }
305
+ if (Array.isArray(child)) {
306
+ const children = child.flat(Infinity).map(normalizeChild).filter(Boolean);
307
+ if (children.length === 0) return null;
308
+ if (children.length === 1) return children[0];
309
+ return { type: "fragment", children };
310
+ }
311
+ if (typeof child === "object" && child !== null && "type" in child) {
312
+ return child;
313
+ }
314
+ if (typeof child === "function") {
315
+ return { type: "component", component: child, props: {} };
316
+ }
317
+ return { type: "text", text: String(child) };
318
+ }
319
+ function h(tag, props, ...children) {
320
+ if (typeof tag === "function") {
321
+ const c = children.flat(Infinity).map(normalizeChild).filter(Boolean);
322
+ return {
323
+ type: "component",
324
+ component: tag,
325
+ props: { ...props || {}, children: c.length > 0 ? c : void 0 }
326
+ };
327
+ }
328
+ return {
329
+ type: "element",
330
+ tag,
331
+ props: props || {},
332
+ children: children.flat(Infinity).map(normalizeChild).filter(Boolean),
333
+ key: props?.key
334
+ };
335
+ }
336
+ function fragment(...children) {
337
+ const flat = children.flat(Infinity);
338
+ const normalized = flat.map(normalizeChild).filter(Boolean);
339
+ if (normalized.length === 0) return { type: "text", text: "" };
340
+ if (normalized.length === 1) return normalized[0];
341
+ return { type: "fragment", children: normalized };
342
+ }
343
+ function text(content) {
344
+ return { type: "text", text: content };
345
+ }
346
+ function createComponent(type, props, ...children) {
347
+ const c = children.flat(Infinity).map(normalizeChild).filter(Boolean);
348
+ return {
349
+ type: "component",
350
+ component: type,
351
+ props: { ...props || {}, children: c.length > 0 ? c : void 0 }
352
+ };
353
+ }
354
+ function setProp(el, key, value, oldValue) {
355
+ if (key === "key" || key === "children" || key === "ref") return;
356
+ if (isComputed2(value)) {
357
+ setProp(el, key, value.peek(), oldValue);
358
+ value.subscribe((v) => setProp(el, key, v));
359
+ return;
360
+ }
361
+ if (key.startsWith("on") && typeof value === "function") {
362
+ const event = key.slice(2).toLowerCase();
363
+ if (oldValue) el.removeEventListener(event, oldValue);
364
+ el.addEventListener(event, value);
365
+ return;
366
+ }
367
+ if (key === "style") {
368
+ if (typeof value === "string") {
369
+ el.setAttribute("style", value);
370
+ } else if (typeof value === "object" && value !== null) {
371
+ Object.assign(el.style, value);
372
+ }
373
+ return;
374
+ }
375
+ if (key === "class" || key === "className") {
376
+ if (typeof value === "string") {
377
+ el.setAttribute("class", value);
378
+ } else if (Array.isArray(value)) {
379
+ el.setAttribute("class", value.filter(Boolean).join(" "));
380
+ }
381
+ return;
382
+ }
383
+ if (key === "dangerouslySetInnerHTML" && typeof value === "object" && value?.__html) {
384
+ el.innerHTML = value.__html;
385
+ return;
386
+ }
387
+ if (key === "value" || key === "checked" || key === "disabled" || key === "selected") {
388
+ el[key] = value;
389
+ return;
390
+ }
391
+ if (key === "htmlFor") {
392
+ el.setAttribute("for", value);
393
+ return;
394
+ }
395
+ if (value === false || value === null || value === void 0) {
396
+ el.removeAttribute(key);
397
+ } else if (value === true) {
398
+ el.setAttribute(key, "");
399
+ } else {
400
+ el.setAttribute(key, String(value));
401
+ }
402
+ }
403
+ function removeProp(el, key, value) {
404
+ if (key === "key" || key === "children" || key === "ref") return;
405
+ if (key.startsWith("on") && typeof value === "function") {
406
+ el.removeEventListener(key.slice(2).toLowerCase(), value);
407
+ return;
408
+ }
409
+ if (key === "style") {
410
+ el.removeAttribute("style");
411
+ return;
412
+ }
413
+ if (key === "class" || key === "className") {
414
+ el.removeAttribute("class");
415
+ return;
416
+ }
417
+ if (key === "value" || key === "checked" || key === "disabled") {
418
+ delete el[key];
419
+ return;
420
+ }
421
+ el.removeAttribute(key);
422
+ }
423
+ function createDOM(vnode) {
424
+ switch (vnode.type) {
425
+ case "element": {
426
+ const isSVG = SVG_ELEMENTS.has(vnode.tag);
427
+ const el = isSVG ? document.createElementNS("http://www.w3.org/2000/svg", vnode.tag) : document.createElement(vnode.tag);
428
+ for (const [key, value] of Object.entries(vnode.props)) {
429
+ if (key !== "key") setProp(el, key, value);
430
+ }
431
+ for (const child of vnode.children) {
432
+ el.appendChild(createDOM(child));
433
+ }
434
+ return el;
435
+ }
436
+ case "text":
437
+ return document.createTextNode(vnode.text);
438
+ case "fragment": {
439
+ const frag = document.createDocumentFragment();
440
+ for (const child of vnode.children) frag.appendChild(createDOM(child));
441
+ return frag;
442
+ }
443
+ case "component": {
444
+ const result = vnode.component(vnode.props);
445
+ if (result instanceof Promise) {
446
+ const placeholder = document.createComment(" async ");
447
+ result.then((resolved) => {
448
+ const node = createDOM(resolved);
449
+ placeholder.parentNode?.replaceChild(node, placeholder);
450
+ });
451
+ return placeholder;
452
+ }
453
+ return createDOM(result);
454
+ }
455
+ case "signal": {
456
+ const val = vnode.signal.value;
457
+ const v = normalizeChild(val);
458
+ const node = createDOM(v ?? text(""));
459
+ vnode.signal.subscribe((newVal) => {
460
+ const newV = normalizeChild(newVal);
461
+ if (newV && node.parentNode) {
462
+ const newNode = createDOM(newV);
463
+ node.parentNode.replaceChild(newNode, node);
464
+ }
465
+ });
466
+ return node;
467
+ }
468
+ }
469
+ }
470
+ function render(vnode, container) {
471
+ container.innerHTML = "";
472
+ container.appendChild(createDOM(vnode));
473
+ }
474
+ function isSameVNodeType(a, b) {
475
+ if (a.type !== b.type) return false;
476
+ if (a.type === "element" && b.type === "element") {
477
+ return a.tag === b.tag && a.key === b.key;
478
+ }
479
+ return true;
480
+ }
481
+ function patchProps(el, oldProps, newProps) {
482
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
483
+ for (const key of allKeys) {
484
+ if (key === "key" || key === "children") continue;
485
+ const oldVal = oldProps[key];
486
+ const newVal = newProps[key];
487
+ if (oldVal === newVal) continue;
488
+ if (newVal === void 0 || newVal === null) {
489
+ removeProp(el, key, oldVal);
490
+ } else {
491
+ setProp(el, key, newVal, oldVal);
492
+ }
493
+ }
494
+ }
495
+ function patchChildren(parent, oldChildren, newChildren) {
496
+ const maxLen = Math.max(oldChildren.length, newChildren.length);
497
+ for (let i = 0; i < maxLen; i++) {
498
+ const oldChild = oldChildren[i];
499
+ const newChild = newChildren[i];
500
+ const existingNode = parent.childNodes[i];
501
+ if (!oldChild && newChild) {
502
+ parent.appendChild(createDOM(newChild));
503
+ } else if (oldChild && !newChild) {
504
+ if (existingNode) parent.removeChild(existingNode);
505
+ } else if (oldChild && newChild) {
506
+ if (isSameVNodeType(oldChild, newChild)) {
507
+ patchVNode(existingNode ?? null, oldChild, newChild);
508
+ } else {
509
+ const newNode = createDOM(newChild);
510
+ parent.replaceChild(newNode, existingNode);
511
+ }
512
+ }
513
+ }
514
+ }
515
+ function patchVNode(dom, oldVNode, newVNode) {
516
+ if (!dom) return;
517
+ if (oldVNode.type === "element" && newVNode.type === "element") {
518
+ patchProps(dom, oldVNode.props, newVNode.props);
519
+ patchChildren(dom, oldVNode.children, newVNode.children);
520
+ } else if (oldVNode.type === "text" && newVNode.type === "text") {
521
+ if (oldVNode.text !== newVNode.text) {
522
+ dom.textContent = newVNode.text;
523
+ }
524
+ } else if (oldVNode.type === "fragment" && newVNode.type === "fragment") {
525
+ patchChildren(dom.parentNode || dom, oldVNode.children, newVNode.children);
526
+ }
527
+ }
528
+ function patch(dom, oldVNode, newVNode) {
529
+ if (isSameVNodeType(oldVNode, newVNode)) {
530
+ patchVNode(dom, oldVNode, newVNode);
531
+ } else {
532
+ const parent = dom.parentNode;
533
+ if (parent) {
534
+ parent.replaceChild(createDOM(newVNode), dom);
535
+ }
536
+ }
537
+ }
538
+ function hydrate(vnode, container) {
539
+ function hydrateNode(vn, node) {
540
+ if (vn.type === "element") {
541
+ const el = node;
542
+ for (const [key, value] of Object.entries(vn.props)) {
543
+ if (key.startsWith("on") && typeof value === "function") {
544
+ el.addEventListener(key.slice(2).toLowerCase(), value);
545
+ }
546
+ }
547
+ for (let i = 0; i < Math.min(vn.children.length, el.childNodes.length); i++) {
548
+ hydrateNode(vn.children[i], el.childNodes[i]);
549
+ }
550
+ } else if (vn.type === "component") {
551
+ const result = vn.component(vn.props);
552
+ if (!(result instanceof Promise)) hydrateNode(result, node);
553
+ } else if (vn.type === "signal") {
554
+ vn.signal.subscribe((newVal) => {
555
+ const newChild = normalizeChild(newVal);
556
+ if (newChild && node.parentNode) {
557
+ node.parentNode.replaceChild(createDOM(newChild), node);
558
+ }
559
+ });
560
+ }
561
+ }
562
+ if (container.firstChild) {
563
+ hydrateNode(vnode, container.firstChild);
564
+ } else {
565
+ render(vnode, container);
566
+ }
567
+ }
568
+ var ESCAPE_MAP = {
569
+ "&": "&amp;",
570
+ "<": "&lt;",
571
+ ">": "&gt;",
572
+ '"': "&quot;",
573
+ "'": "&#39;"
574
+ };
575
+ function escapeHtml(str) {
576
+ return str.replace(/[&<>"']/g, (c) => ESCAPE_MAP[c] || c);
577
+ }
578
+ function renderProps(props) {
579
+ let out = "";
580
+ for (const [key, value] of Object.entries(props)) {
581
+ if (key === "key" || key === "children" || key === "ref") continue;
582
+ if (key.startsWith("on")) continue;
583
+ if (value === false || value === null || value === void 0) continue;
584
+ if (key === "style" && typeof value === "object") {
585
+ const styleStr = Object.entries(value).map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}:${v}`).join(";");
586
+ out += ' style="' + escapeHtml(styleStr) + '"';
587
+ continue;
588
+ }
589
+ if (key === "class" || key === "className") {
590
+ const cls = Array.isArray(value) ? value.filter(Boolean).join(" ") : value;
591
+ out += ' class="' + escapeHtml(String(cls)) + '"';
592
+ continue;
593
+ }
594
+ if (key === "htmlFor") {
595
+ out += ' for="' + escapeHtml(String(value)) + '"';
596
+ continue;
597
+ }
598
+ if (value === true) {
599
+ out += " " + key;
600
+ } else {
601
+ out += " " + key + '="' + escapeHtml(String(value)) + '"';
602
+ }
603
+ }
604
+ return out;
605
+ }
606
+ function renderVNodeToString(vnode) {
607
+ switch (vnode.type) {
608
+ case "element": {
609
+ const children = vnode.children.map(renderVNodeToString).join("");
610
+ if (VOID_ELEMENTS.has(vnode.tag)) return "<" + vnode.tag + renderProps(vnode.props) + ">";
611
+ return "<" + vnode.tag + renderProps(vnode.props) + ">" + children + "</" + vnode.tag + ">";
612
+ }
613
+ case "text":
614
+ return escapeHtml(vnode.text);
615
+ case "fragment":
616
+ return vnode.children.map(renderVNodeToString).join("");
617
+ case "component": {
618
+ const result = vnode.component(vnode.props);
619
+ if (result instanceof Promise) throw new Error("Async components must use renderToStream or ServerRenderer");
620
+ return renderVNodeToString(result);
621
+ }
622
+ case "signal":
623
+ return renderVNodeToString(normalizeChild(vnode.signal.value) ?? text(""));
624
+ }
625
+ }
626
+ function renderToString(vnode) {
627
+ return renderVNodeToString(vnode);
628
+ }
629
+ function renderToStream(vnode) {
630
+ return new ReadableStream({
631
+ start(controller) {
632
+ const html = renderToString(vnode);
633
+ controller.enqueue(html);
634
+ controller.close();
635
+ }
636
+ });
637
+ }
638
+
639
+ // src/client/vdom/jsx.ts
640
+ var emptyText = () => ({ type: "text", text: "" });
641
+ function createElement(tag, props, ...children) {
642
+ const { isSVG, ...rest } = props || {};
643
+ if (typeof tag === "function") {
644
+ const childArr = children.flat(Infinity);
645
+ const result2 = {
646
+ type: "component",
647
+ component: tag,
648
+ props: { ...rest, children: childArr.length > 0 ? childArr : void 0 }
649
+ };
650
+ return result2;
651
+ }
652
+ const childNodes = children.flat(Infinity).map((c) => {
653
+ if (c == null || typeof c === "boolean") return emptyText();
654
+ if (typeof c === "object" && c !== null && "type" in c) return c;
655
+ return { type: "text", text: String(c) };
656
+ });
657
+ const result = {
658
+ type: "element",
659
+ tag,
660
+ props: rest || {},
661
+ children: childNodes
662
+ };
663
+ return result;
664
+ }
665
+ function Fragment(props) {
666
+ const children = props?.children;
667
+ if (!children) return emptyText();
668
+ const arr = Array.isArray(children) ? children : [children];
669
+ const flat = arr.flat(Infinity).map((c) => {
670
+ if (c == null || typeof c === "boolean") return emptyText();
671
+ if (typeof c === "object" && c !== null && "type" in c) return c;
672
+ return { type: "text", text: String(c) };
673
+ });
674
+ if (flat.length === 1) return flat[0];
675
+ const result = { type: "fragment", children: flat };
676
+ return result;
677
+ }
678
+
679
+ // src/client/render/index.ts
680
+ var ServerRenderer = class {
681
+ render(component, props) {
682
+ const vnode = {
683
+ type: "component",
684
+ component,
685
+ props: props || {}
686
+ };
687
+ return Promise.resolve(renderToString(vnode));
688
+ }
689
+ renderToStream(component, props) {
690
+ const vnode = {
691
+ type: "component",
692
+ component,
693
+ props: props || {}
694
+ };
695
+ return renderToStream(vnode);
696
+ }
697
+ renderStatic(component, props) {
698
+ const vnode = {
699
+ type: "component",
700
+ component,
701
+ props: props || {}
702
+ };
703
+ return renderToString(vnode);
704
+ }
705
+ async renderServerComponent(path, props) {
706
+ const mod = await import(path);
707
+ const compKey = Object.keys(mod).find((k) => typeof mod[k] === "function");
708
+ if (!compKey) throw new Error(`No component export found in ${path}`);
709
+ const component = mod[compKey];
710
+ const result = component(props || {});
711
+ const resolved = result instanceof Promise ? await result : result;
712
+ return renderToString(resolved);
713
+ }
714
+ };
715
+ function generateHydrationScript() {
716
+ return '<script>(function(){var d=document.createElement("div");d.setAttribute("data-speedx-hydrated","");document.body.appendChild(d)})();</script>';
717
+ }
718
+
719
+ // src/client/adapters/index.ts
720
+ function defineAdapter(adapter) {
721
+ return adapter;
722
+ }
723
+
724
+ // src/client/router.ts
725
+ function parseQuery(search) {
726
+ const params = {};
727
+ const qs = search.startsWith("?") ? search.slice(1) : search;
728
+ if (!qs) return params;
729
+ for (const part of qs.split("&")) {
730
+ const [key, val] = part.split("=");
731
+ if (key) params[decodeURIComponent(key)] = val ? decodeURIComponent(val) : "";
732
+ }
733
+ return params;
734
+ }
735
+ function matchPath(routePath, urlPath) {
736
+ const routeParts = routePath.split("/");
737
+ const urlParts = urlPath.split("/");
738
+ if (routeParts.length !== urlParts.length) return null;
739
+ const params = {};
740
+ for (let i = 0; i < routeParts.length; i++) {
741
+ const rp = routeParts[i];
742
+ const up = urlParts[i];
743
+ if (rp.startsWith(":")) {
744
+ params[rp.slice(1)] = decodeURIComponent(up);
745
+ } else if (rp !== up) {
746
+ return null;
747
+ }
748
+ }
749
+ return params;
750
+ }
751
+ var ClientRouter = class {
752
+ _current;
753
+ _params;
754
+ _query;
755
+ _history = [];
756
+ _historyIndex = -1;
757
+ _routes;
758
+ _options;
759
+ constructor(routes, options) {
760
+ this._routes = routes;
761
+ this._options = {
762
+ basePath: options?.basePath ?? "",
763
+ mode: options?.mode ?? "history",
764
+ scrollRestoration: options?.scrollRestoration ?? true
765
+ };
766
+ const initialMatch = this._resolveRoute(this._getCurrentPath());
767
+ this._current = signal(initialMatch);
768
+ this._params = signal(initialMatch?.params ?? {});
769
+ this._query = signal(parseQuery(window.location.search));
770
+ if (this._options.scrollRestoration) {
771
+ history.scrollRestoration = "auto";
772
+ }
773
+ window.addEventListener("popstate", () => {
774
+ const path = this._getCurrentPath();
775
+ const match = this._resolveRoute(path);
776
+ this._current.value = match;
777
+ this._params.value = match?.params ?? {};
778
+ this._query.value = parseQuery(window.location.search);
779
+ });
780
+ }
781
+ get current() {
782
+ return this._current;
783
+ }
784
+ get params() {
785
+ return this._params;
786
+ }
787
+ get query() {
788
+ return this._query;
789
+ }
790
+ _getCurrentPath() {
791
+ if (this._options.mode === "hash") {
792
+ const hash = window.location.hash.slice(1) || "/";
793
+ return hash;
794
+ }
795
+ let path = window.location.pathname;
796
+ if (this._options.basePath && path.startsWith(this._options.basePath)) {
797
+ path = path.slice(this._options.basePath.length) || "/";
798
+ }
799
+ return path;
800
+ }
801
+ _resolveRoute(path) {
802
+ for (const route of this._routes) {
803
+ const params = matchPath(route.path, path);
804
+ if (params !== null) {
805
+ return {
806
+ path,
807
+ pattern: route.path,
808
+ component: route.component,
809
+ layout: route.layout,
810
+ loading: route.loading,
811
+ error: route.error,
812
+ params,
813
+ query: parseQuery(window.location.search)
814
+ };
815
+ }
816
+ }
817
+ return null;
818
+ }
819
+ async navigate(path) {
820
+ const from = this._getCurrentPath();
821
+ const to = path;
822
+ const route = this._routes.find((r) => matchPath(r.path, to) !== null);
823
+ if (route?.guards) {
824
+ for (const guard of route.guards) {
825
+ const allowed = await guard(to, from);
826
+ if (!allowed) throw new Error(`Navigation guard blocked: ${from} -> ${to}`);
827
+ }
828
+ }
829
+ const resolvedPath = this._options.basePath ? this._options.basePath + to : to;
830
+ if (this._options.mode === "hash") {
831
+ window.location.hash = to;
832
+ } else {
833
+ history.pushState(null, "", resolvedPath);
834
+ }
835
+ if (this._historyIndex < this._history.length - 1) {
836
+ this._history = this._history.slice(0, this._historyIndex + 1);
837
+ }
838
+ this._history.push(to);
839
+ this._historyIndex++;
840
+ const match = this._resolveRoute(to);
841
+ this._current.value = match;
842
+ this._params.value = match?.params ?? {};
843
+ this._query.value = parseQuery(window.location.search);
844
+ }
845
+ back() {
846
+ if (this._historyIndex > 0) {
847
+ this._historyIndex--;
848
+ const path = this._history[this._historyIndex];
849
+ if (this._options.mode === "hash") {
850
+ window.location.hash = path;
851
+ } else {
852
+ history.back();
853
+ }
854
+ }
855
+ }
856
+ forward() {
857
+ if (this._historyIndex < this._history.length - 1) {
858
+ this._historyIndex++;
859
+ const path = this._history[this._historyIndex];
860
+ if (this._options.mode === "hash") {
861
+ window.location.hash = path;
862
+ } else {
863
+ history.forward();
864
+ }
865
+ }
866
+ }
867
+ link(props) {
868
+ const isActive = computed(() => {
869
+ const current = this._current.value;
870
+ return current?.path === props.to;
871
+ });
872
+ const handleClick = (e) => {
873
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1) return;
874
+ e.preventDefault();
875
+ props.onClick?.(e);
876
+ this.navigate(props.to);
877
+ };
878
+ const { children, to, activeClass, ...rest } = props;
879
+ const cls = computed(() => {
880
+ const base = rest.class || "";
881
+ const active = activeClass && isActive.value ? ` ${activeClass}` : "";
882
+ return `${base}${active}`;
883
+ });
884
+ const childNodes = (Array.isArray(children) ? children : [children]).flat(Infinity).map((c) => {
885
+ if (c == null || typeof c === "boolean") return { type: "text", text: "" };
886
+ if (typeof c === "object" && "type" in c) return c;
887
+ return { type: "text", text: String(c) };
888
+ });
889
+ return {
890
+ type: "element",
891
+ tag: "a",
892
+ props: { href: this._options.basePath + to, onClick: handleClick, class: cls },
893
+ children: childNodes
894
+ };
895
+ }
896
+ };
897
+ export {
898
+ ClientRouter,
899
+ Computed,
900
+ Effect,
901
+ Fragment,
902
+ ServerRenderer,
903
+ Signal,
904
+ batch,
905
+ computed,
906
+ createComponent,
907
+ createElement,
908
+ defineAdapter,
909
+ effect,
910
+ fragment,
911
+ generateHydrationScript,
912
+ h,
913
+ hydrate,
914
+ isComputed,
915
+ isSignal,
916
+ mergeSignals,
917
+ normalizeChild,
918
+ patch,
919
+ render,
920
+ renderToStream,
921
+ renderToString,
922
+ signal,
923
+ text,
924
+ toSignal,
925
+ untracked
926
+ };
927
+ //# sourceMappingURL=index.js.map