@hypen-space/core 0.4.980 → 0.5.3

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 (100) hide show
  1. package/README.md +5 -8
  2. package/dist/a11y.d.ts +82 -0
  3. package/dist/app.js +13 -1168
  4. package/dist/app.js.map +3 -9
  5. package/dist/chunk-00zt3w6e.js +58 -0
  6. package/dist/chunk-00zt3w6e.js.map +10 -0
  7. package/dist/chunk-3zvyth50.js +87 -0
  8. package/dist/chunk-3zvyth50.js.map +10 -0
  9. package/dist/chunk-5gtx3pza.js +11 -0
  10. package/dist/chunk-5gtx3pza.js.map +9 -0
  11. package/dist/chunk-7222131a.js +191 -0
  12. package/dist/chunk-7222131a.js.map +10 -0
  13. package/dist/chunk-avchpwhf.js +200 -0
  14. package/dist/chunk-avchpwhf.js.map +10 -0
  15. package/dist/chunk-ec0tgy9a.js +154 -0
  16. package/dist/chunk-ec0tgy9a.js.map +10 -0
  17. package/dist/chunk-fnss4dm2.js +479 -0
  18. package/dist/chunk-fnss4dm2.js.map +10 -0
  19. package/dist/chunk-g2gz9pgg.js +133 -0
  20. package/dist/chunk-g2gz9pgg.js.map +10 -0
  21. package/dist/chunk-g72v6mmf.js +341 -0
  22. package/dist/chunk-g72v6mmf.js.map +10 -0
  23. package/dist/chunk-g7g3jxty.js +351 -0
  24. package/dist/chunk-g7g3jxty.js.map +10 -0
  25. package/dist/chunk-g830re2c.js +50 -0
  26. package/dist/chunk-g830re2c.js.map +10 -0
  27. package/dist/chunk-gtwh1sg7.js +127 -0
  28. package/dist/chunk-gtwh1sg7.js.map +10 -0
  29. package/dist/chunk-k12cwfst.js +72 -0
  30. package/dist/chunk-k12cwfst.js.map +10 -0
  31. package/dist/chunk-mbqqsz6r.js +128 -0
  32. package/dist/chunk-mbqqsz6r.js.map +10 -0
  33. package/dist/chunk-ne632swm.js +209 -0
  34. package/dist/chunk-ne632swm.js.map +10 -0
  35. package/dist/chunk-p3pj1bax.js +206 -0
  36. package/dist/chunk-p3pj1bax.js.map +10 -0
  37. package/dist/chunk-vshdk2pw.js +56 -0
  38. package/dist/chunk-vshdk2pw.js.map +10 -0
  39. package/dist/chunk-wp2ebn2m.js +51 -0
  40. package/dist/chunk-wp2ebn2m.js.map +10 -0
  41. package/dist/chunk-x4qv4jm9.js +88 -0
  42. package/dist/chunk-x4qv4jm9.js.map +10 -0
  43. package/dist/chunk-ycxp4drd.js +211 -0
  44. package/dist/chunk-ycxp4drd.js.map +10 -0
  45. package/dist/components/builtin.js +14 -1246
  46. package/dist/components/builtin.js.map +3 -10
  47. package/dist/context.js +7 -362
  48. package/dist/context.js.map +3 -6
  49. package/dist/datasource.js +5 -76
  50. package/dist/datasource.js.map +3 -4
  51. package/dist/disposable.js +20 -367
  52. package/dist/disposable.js.map +3 -5
  53. package/dist/engine-base.d.ts +38 -2
  54. package/dist/engine-base.js +45 -412
  55. package/dist/engine-base.js.map +4 -6
  56. package/dist/events.js +7 -285
  57. package/dist/events.js.map +3 -5
  58. package/dist/hypen.js +8 -71
  59. package/dist/hypen.js.map +3 -4
  60. package/dist/index.browser.js +58 -2152
  61. package/dist/index.browser.js.map +3 -16
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.js +175 -3057
  64. package/dist/index.js.map +5 -22
  65. package/dist/logger.js +16 -220
  66. package/dist/logger.js.map +3 -4
  67. package/dist/managed-router.js +12 -1367
  68. package/dist/managed-router.js.map +3 -10
  69. package/dist/portable.js +6 -70
  70. package/dist/portable.js.map +3 -4
  71. package/dist/remote/client.js +9 -1010
  72. package/dist/remote/client.js.map +3 -8
  73. package/dist/remote/index.d.ts +2 -0
  74. package/dist/remote/index.js +511 -1066
  75. package/dist/remote/index.js.map +4 -9
  76. package/dist/remote/remote-session.d.ts +245 -0
  77. package/dist/remote/session.js +5 -147
  78. package/dist/remote/session.js.map +3 -4
  79. package/dist/renderer.js +7 -271
  80. package/dist/renderer.js.map +3 -5
  81. package/dist/resolver.js +5 -484
  82. package/dist/resolver.js.map +3 -5
  83. package/dist/result.js +25 -211
  84. package/dist/result.js.map +3 -4
  85. package/dist/retry.js +10 -336
  86. package/dist/retry.js.map +3 -5
  87. package/dist/router.js +9 -807
  88. package/dist/router.js.map +3 -8
  89. package/dist/state.js +10 -274
  90. package/dist/state.js.map +3 -5
  91. package/dist/types.d.ts +129 -1
  92. package/dist/validate.d.ts +19 -0
  93. package/package.json +13 -1
  94. package/src/a11y.ts +127 -0
  95. package/src/engine-base.ts +87 -4
  96. package/src/index.ts +10 -0
  97. package/src/remote/index.ts +16 -0
  98. package/src/remote/remote-session.ts +998 -0
  99. package/src/types.ts +131 -1
  100. package/src/validate.ts +37 -0
package/dist/router.js CHANGED
@@ -1,811 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true,
11
- configurable: true,
12
- set: __exportSetter.bind(all, name)
13
- });
14
- };
15
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
17
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
18
- }) : x)(function(x) {
19
- if (typeof require !== "undefined")
20
- return require.apply(this, arguments);
21
- throw Error('Dynamic require of "' + x + '" is not supported');
22
- });
23
-
24
- // src/portable.ts
25
- function notInstalled(name) {
26
- throw new Error(`[@hypen-space/core] Portable helper "${name}" called before the engine was installed. ` + `Import @hypen-space/server, @hypen-space/web-engine, or call setPortableImpl() before use.`);
27
- }
28
- var current = {
29
- diffState: () => notInstalled("diffState"),
30
- matchPath: () => notInstalled("matchPath"),
31
- pathGet: () => notInstalled("pathGet"),
32
- pathHas: () => notInstalled("pathHas"),
33
- pathSet: () => notInstalled("pathSet"),
34
- pathDelete: () => notInstalled("pathDelete"),
35
- encodeUriComponent: () => notInstalled("encodeUriComponent"),
36
- decodeUriComponent: () => notInstalled("decodeUriComponent"),
37
- parseQuery: () => notInstalled("parseQuery"),
38
- buildUrl: () => notInstalled("buildUrl")
39
- };
40
- function setPortableImpl(impl) {
41
- if (impl === null) {
42
- current = {
43
- diffState: () => notInstalled("diffState"),
44
- matchPath: () => notInstalled("matchPath"),
45
- pathGet: () => notInstalled("pathGet"),
46
- pathHas: () => notInstalled("pathHas"),
47
- pathSet: () => notInstalled("pathSet"),
48
- pathDelete: () => notInstalled("pathDelete"),
49
- encodeUriComponent: () => notInstalled("encodeUriComponent"),
50
- decodeUriComponent: () => notInstalled("decodeUriComponent"),
51
- parseQuery: () => notInstalled("parseQuery"),
52
- buildUrl: () => notInstalled("buildUrl")
53
- };
54
- return;
55
- }
56
- current = impl;
57
- }
58
- var portable = {
59
- diffState: (o, n, b) => current.diffState(o, n, b),
60
- matchPath: (p, path) => current.matchPath(p, path),
61
- pathGet: (v, p) => current.pathGet(v, p),
62
- pathHas: (v, p) => current.pathHas(v, p),
63
- pathSet: (v, p, nv) => current.pathSet(v, p, nv),
64
- pathDelete: (v, p) => current.pathDelete(v, p),
65
- encodeUriComponent: (s) => current.encodeUriComponent(s),
66
- decodeUriComponent: (s) => current.decodeUriComponent(s),
67
- parseQuery: (f) => current.parseQuery(f),
68
- buildUrl: (p, q) => current.buildUrl(p, q)
69
- };
70
-
71
- // src/state.ts
72
- var IS_PROXY = Symbol.for("hypen.isProxy");
73
- var RAW_TARGET = Symbol.for("hypen.rawTarget");
74
- function deepClone(obj) {
75
- if (obj === null || typeof obj !== "object") {
76
- return obj;
77
- }
78
- if (typeof obj === "function") {
79
- return obj;
80
- }
81
- if (typeof obj.__getSnapshot === "function") {
82
- return obj.__getSnapshot();
83
- }
84
- if (obj instanceof WeakMap || obj instanceof WeakSet) {
85
- return obj;
86
- }
87
- const visited = new WeakMap;
88
- function cloneInternal(value) {
89
- if (value === null || typeof value !== "object") {
90
- return value;
91
- }
92
- if (typeof value === "function") {
93
- return value;
94
- }
95
- if (visited.has(value)) {
96
- return visited.get(value);
97
- }
98
- if (value instanceof WeakMap || value instanceof WeakSet) {
99
- return value;
100
- }
101
- if (value instanceof Date || value instanceof RegExp || value instanceof Map || value instanceof Set || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
102
- try {
103
- return structuredClone(value);
104
- } catch {}
105
- }
106
- if (Array.isArray(value)) {
107
- const arrClone = [];
108
- visited.set(value, arrClone);
109
- for (let i = 0;i < value.length; i++) {
110
- arrClone[i] = cloneInternal(value[i]);
111
- }
112
- return arrClone;
113
- }
114
- const objClone = {};
115
- visited.set(value, objClone);
116
- for (const key in value) {
117
- if (Object.prototype.hasOwnProperty.call(value, key)) {
118
- objClone[key] = cloneInternal(value[key]);
119
- }
120
- }
121
- const symbolKeys = Object.getOwnPropertySymbols(value);
122
- for (const sym of symbolKeys) {
123
- objClone[sym] = cloneInternal(value[sym]);
124
- }
125
- return objClone;
126
- }
127
- return cloneInternal(obj);
128
- }
129
- function diffState(oldState, newState, basePath = "") {
130
- return portable.diffState(oldState, newState, basePath);
131
- }
132
- function createObservableState(initialState, options) {
133
- const opts = options || { onChange: () => {} };
134
- if (initialState === null || initialState === undefined) {
135
- initialState = {};
136
- }
137
- if (initialState instanceof Number || initialState instanceof String || initialState instanceof Boolean) {
138
- throw new TypeError("Cannot create observable state from primitive wrapper objects (Number, String, Boolean). " + "Use plain primitives or regular objects instead.");
139
- }
140
- initialState = deepClone(initialState);
141
- let lastSnapshot = deepClone(initialState);
142
- const pathPrefix = opts.pathPrefix || "";
143
- let batchDepth = 0;
144
- let pendingChange = null;
145
- function notifyChange() {
146
- if (batchDepth > 0)
147
- return;
148
- const change = diffState(lastSnapshot, state, pathPrefix);
149
- if (change.paths.length > 0) {
150
- lastSnapshot = deepClone(state);
151
- if (pendingChange) {
152
- change.paths.push(...pendingChange.paths);
153
- Object.assign(change.newValues, pendingChange.newValues);
154
- pendingChange = null;
155
- }
156
- opts.onChange(change);
157
- }
158
- }
159
- let notificationPending = false;
160
- function scheduleBatch() {
161
- if (batchDepth === 0) {
162
- if (!notificationPending) {
163
- notificationPending = true;
164
- queueMicrotask(() => {
165
- notificationPending = false;
166
- if (batchDepth === 0) {
167
- notifyChange();
168
- } else {}
169
- });
170
- }
171
- } else {
172
- pendingChange = pendingChange || { paths: [], newValues: {} };
173
- }
174
- }
175
- const proxyCache = new WeakMap;
176
- function createProxy(target, basePath) {
177
- const cached = proxyCache.get(target);
178
- if (cached)
179
- return cached;
180
- const proxy = new Proxy(target, {
181
- get(obj, prop) {
182
- if (prop === IS_PROXY)
183
- return true;
184
- if (prop === RAW_TARGET)
185
- return obj;
186
- if (prop === "__beginBatch") {
187
- return () => {
188
- batchDepth++;
189
- };
190
- }
191
- if (prop === "__endBatch") {
192
- return () => {
193
- batchDepth--;
194
- if (batchDepth === 0) {
195
- notifyChange();
196
- }
197
- };
198
- }
199
- if (prop === "__getSnapshot") {
200
- return () => deepClone(obj);
201
- }
202
- const value = obj[prop];
203
- if (value && typeof value === "object") {
204
- if (value[IS_PROXY]) {
205
- return value;
206
- }
207
- if (value instanceof Date || value instanceof RegExp || value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) {
208
- return value;
209
- }
210
- const cachedNested = proxyCache.get(value);
211
- if (cachedNested) {
212
- return cachedNested;
213
- }
214
- const nestedProxy = createProxy(value, basePath ? `${basePath}.${String(prop)}` : String(prop));
215
- return nestedProxy;
216
- }
217
- return value;
218
- },
219
- set(obj, prop, value) {
220
- const oldValue = obj[prop];
221
- if (value && typeof value === "object" && value[IS_PROXY]) {
222
- value = value[RAW_TARGET];
223
- }
224
- obj[prop] = value;
225
- if (oldValue !== value) {
226
- scheduleBatch();
227
- }
228
- return true;
229
- },
230
- deleteProperty(obj, prop) {
231
- const existed = Object.prototype.hasOwnProperty.call(obj, prop);
232
- const result = delete obj[prop];
233
- if (existed) {
234
- scheduleBatch();
235
- }
236
- return result;
237
- }
238
- });
239
- proxyCache.set(target, proxy);
240
- return proxy;
241
- }
242
- const state = createProxy(initialState, pathPrefix);
243
- return state;
244
- }
245
- function batchStateUpdates(state, fn) {
246
- const s = state;
247
- if (s.__beginBatch && s.__endBatch) {
248
- s.__beginBatch();
249
- try {
250
- fn();
251
- } finally {
252
- s.__endBatch();
253
- }
254
- } else {
255
- fn();
256
- }
257
- }
258
- function getStateSnapshot(state) {
259
- const s = state;
260
- if (s.__getSnapshot) {
261
- return s.__getSnapshot();
262
- }
263
- return deepClone(state);
264
- }
265
- function isStateProxy(value) {
266
- return value !== null && typeof value === "object" && value[IS_PROXY] === true;
267
- }
268
- function unwrapProxy(value) {
269
- if (value !== null && typeof value === "object" && value[IS_PROXY]) {
270
- return value[RAW_TARGET];
271
- }
272
- return value;
273
- }
274
-
275
- // src/logger.ts
276
- var LOG_LEVEL_ORDER = {
277
- debug: 0,
278
- info: 1,
279
- warn: 2,
280
- error: 3,
281
- none: 4
282
- };
283
- var LOG_LEVEL_COLORS = {
284
- debug: "\x1B[36m",
285
- info: "\x1B[32m",
286
- warn: "\x1B[33m",
287
- error: "\x1B[31m"
288
- };
289
- var RESET_COLOR = "\x1B[0m";
290
- function isProduction() {
291
- if (typeof process !== "undefined" && process.env) {
292
- return false;
293
- }
294
- return false;
295
- }
296
- var config = {
297
- level: isProduction() ? "error" : "info",
298
- colors: true,
299
- timestamps: false
300
- };
301
- function setLogLevel(level) {
302
- config.level = level;
303
- }
304
- function getLogLevel() {
305
- return config.level;
306
- }
307
- function configureLogger(options) {
308
- config = { ...config, ...options };
309
- }
310
- function enableLogging() {
311
- config.level = "debug";
312
- }
313
- function disableLogging() {
314
- config.level = "none";
315
- }
316
- function setDebugMode(enabled) {
317
- config.level = enabled ? "debug" : "error";
318
- }
319
- function isDebugMode() {
320
- return config.level === "debug";
321
- }
322
- function shouldLog(level) {
323
- return LOG_LEVEL_ORDER[level] >= LOG_LEVEL_ORDER[config.level];
324
- }
325
- function formatTag(tag, level) {
326
- const timestamp = config.timestamps ? `${new Date().toISOString()} ` : "";
327
- if (config.colors && level !== "none") {
328
- const color = LOG_LEVEL_COLORS[level];
329
- return `${timestamp}${color}[${tag}]${RESET_COLOR}`;
330
- }
331
- return `${timestamp}[${tag}]`;
332
- }
333
-
334
- class Logger {
335
- tag;
336
- constructor(tag) {
337
- this.tag = tag;
338
- }
339
- debug(...args) {
340
- if (!shouldLog("debug"))
341
- return;
342
- if (config.handler) {
343
- config.handler.debug(this.tag, ...args);
344
- } else {
345
- console.log(formatTag(this.tag, "debug"), ...args);
346
- }
347
- }
348
- info(...args) {
349
- if (!shouldLog("info"))
350
- return;
351
- if (config.handler) {
352
- config.handler.info(this.tag, ...args);
353
- } else {
354
- console.info(formatTag(this.tag, "info"), ...args);
355
- }
356
- }
357
- warn(...args) {
358
- if (!shouldLog("warn"))
359
- return;
360
- if (config.handler) {
361
- config.handler.warn(this.tag, ...args);
362
- } else {
363
- console.warn(formatTag(this.tag, "warn"), ...args);
364
- }
365
- }
366
- error(...args) {
367
- if (!shouldLog("error"))
368
- return;
369
- if (config.handler) {
370
- config.handler.error(this.tag, ...args);
371
- } else {
372
- console.error(formatTag(this.tag, "error"), ...args);
373
- }
374
- }
375
- time(label, fn) {
376
- if (!shouldLog("debug")) {
377
- return fn();
378
- }
379
- const start = performance.now();
380
- try {
381
- return fn();
382
- } finally {
383
- const duration = performance.now() - start;
384
- this.debug(`${label}: ${duration.toFixed(2)}ms`);
385
- }
386
- }
387
- async timeAsync(label, fn) {
388
- if (!shouldLog("debug")) {
389
- return fn();
390
- }
391
- const start = performance.now();
392
- try {
393
- return await fn();
394
- } finally {
395
- const duration = performance.now() - start;
396
- this.debug(`${label}: ${duration.toFixed(2)}ms`);
397
- }
398
- }
399
- child(subTag) {
400
- return new Logger(`${this.tag}:${subTag}`);
401
- }
402
- debugIf(condition, ...args) {
403
- if (condition)
404
- this.debug(...args);
405
- }
406
- warnIf(condition, ...args) {
407
- if (condition)
408
- this.warn(...args);
409
- }
410
- errorIf(condition, ...args) {
411
- if (condition)
412
- this.error(...args);
413
- }
414
- loggedOnce = new Set;
415
- warnOnce(key, ...args) {
416
- if (this.loggedOnce.has(key))
417
- return;
418
- this.loggedOnce.add(key);
419
- this.warn(...args);
420
- }
421
- debugOnce(key, ...args) {
422
- if (this.loggedOnce.has(key))
423
- return;
424
- this.loggedOnce.add(key);
425
- this.debug(...args);
426
- }
427
- }
428
- function createLogger(tag) {
429
- return new Logger(tag);
430
- }
431
- var logger = createLogger("Hypen");
432
- var log = {
433
- debug: (tag, ...args) => {
434
- if (!shouldLog("debug"))
435
- return;
436
- console.log(formatTag(tag, "debug"), ...args);
437
- },
438
- info: (tag, ...args) => {
439
- if (!shouldLog("info"))
440
- return;
441
- console.info(formatTag(tag, "info"), ...args);
442
- },
443
- warn: (tag, ...args) => {
444
- if (!shouldLog("warn"))
445
- return;
446
- console.warn(formatTag(tag, "warn"), ...args);
447
- },
448
- error: (tag, ...args) => {
449
- if (!shouldLog("error"))
450
- return;
451
- console.error(formatTag(tag, "error"), ...args);
452
- }
453
- };
454
- var frameworkLoggers = {
455
- hypen: createLogger("Hypen"),
456
- engine: createLogger("Engine"),
457
- router: createLogger("Router"),
458
- state: createLogger("State"),
459
- events: createLogger("Events"),
460
- remote: createLogger("Remote"),
461
- renderer: createLogger("Renderer"),
462
- module: createLogger("Module"),
463
- lifecycle: createLogger("Lifecycle"),
464
- loader: createLogger("Loader"),
465
- context: createLogger("Context"),
466
- discovery: createLogger("Discovery"),
467
- plugin: createLogger("Plugin"),
468
- canvas: createLogger("Canvas"),
469
- debug: createLogger("Debug")
470
- };
471
-
472
- // src/disposable.ts
473
- var log2 = frameworkLoggers.lifecycle;
474
- function isDisposable(obj) {
475
- return obj !== null && typeof obj === "object" && "dispose" in obj && typeof obj.dispose === "function";
476
- }
477
-
478
- class DisposableStack {
479
- stack = [];
480
- disposed = false;
481
- add(disposable) {
482
- if (this.disposed) {
483
- disposable.dispose();
484
- return disposable;
485
- }
486
- this.stack.push(disposable);
487
- return disposable;
488
- }
489
- addCallback(callback) {
490
- this.add({ dispose: callback });
491
- }
492
- addValue(value, dispose) {
493
- this.add({ dispose: () => dispose(value) });
494
- return value;
495
- }
496
- dispose() {
497
- if (this.disposed)
498
- return;
499
- this.disposed = true;
500
- while (this.stack.length > 0) {
501
- const item = this.stack.pop();
502
- try {
503
- item.dispose();
504
- } catch (error) {
505
- log2.error("Error during dispose:", error);
506
- }
507
- }
508
- }
509
- get isDisposed() {
510
- return this.disposed;
511
- }
512
- get size() {
513
- return this.stack.length;
514
- }
515
- }
516
- function disposableListener(target, event, handler, options) {
517
- target.addEventListener(event, handler, options);
518
- return {
519
- dispose: () => target.removeEventListener(event, handler, options)
520
- };
521
- }
522
- function disposableTimeout(callback, ms) {
523
- const id = setTimeout(callback, ms);
524
- return {
525
- id,
526
- dispose: () => clearTimeout(id)
527
- };
528
- }
529
- function disposableInterval(callback, ms) {
530
- const id = setInterval(callback, ms);
531
- return {
532
- id,
533
- dispose: () => clearInterval(id)
534
- };
535
- }
536
- function disposableWebSocket(ws) {
537
- return {
538
- dispose: () => {
539
- if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
540
- ws.close();
541
- }
542
- }
543
- };
544
- }
545
- function disposableAbortController() {
546
- const controller = new AbortController;
547
- return {
548
- controller,
549
- signal: controller.signal,
550
- dispose: () => controller.abort()
551
- };
552
- }
553
- function disposableSubscription(unsubscribe) {
554
- return { dispose: unsubscribe };
555
- }
556
- var ELEMENT_DISPOSABLES = Symbol("hypen.disposables");
557
- function getElementDisposables(element) {
558
- const existing = element[ELEMENT_DISPOSABLES];
559
- if (existing instanceof DisposableStack) {
560
- return existing;
561
- }
562
- const stack = new DisposableStack;
563
- element[ELEMENT_DISPOSABLES] = stack;
564
- return stack;
565
- }
566
- function disposeElement(element) {
567
- const stack = element[ELEMENT_DISPOSABLES];
568
- if (stack instanceof DisposableStack) {
569
- stack.dispose();
570
- delete element[ELEMENT_DISPOSABLES];
571
- }
572
- }
573
- function hasElementDisposables(element) {
574
- return element[ELEMENT_DISPOSABLES] instanceof DisposableStack;
575
- }
576
-
577
- class DisposableMixin {
578
- disposables = new DisposableStack;
579
- track(disposable) {
580
- return this.disposables.add(disposable);
581
- }
582
- onDispose(callback) {
583
- this.disposables.addCallback(callback);
584
- }
585
- dispose() {
586
- this.disposables.dispose();
587
- }
588
- }
589
- function compositeDisposable(...disposables) {
590
- return {
591
- dispose: () => {
592
- for (const d of disposables) {
593
- try {
594
- d.dispose();
595
- } catch (error) {
596
- log2.error("Error during dispose:", error);
597
- }
598
- }
599
- }
600
- };
601
- }
602
- async function using(resource, fn) {
603
- const r = typeof resource === "function" ? resource() : resource;
604
- try {
605
- return await fn(r);
606
- } finally {
607
- r.dispose();
608
- }
609
- }
610
- function usingSync(resource, fn) {
611
- const r = typeof resource === "function" ? resource() : resource;
612
- try {
613
- return fn(r);
614
- } finally {
615
- r.dispose();
616
- }
617
- }
618
-
619
- // src/router.ts
620
- var log3 = frameworkLoggers.router;
621
-
622
- class HypenRouter {
623
- state;
624
- subscribers = new Set;
625
- isInitialized = false;
626
- isUpdating = false;
627
- browserListeners = [];
628
- constructor() {
629
- this.state = createObservableState({
630
- currentPath: "/",
631
- params: {},
632
- query: {},
633
- previousPath: null
634
- }, {
635
- onChange: () => {
636
- this.notifySubscribers();
637
- }
638
- });
639
- if (typeof window !== "undefined") {
640
- this.initializeBrowserSync();
641
- }
642
- }
643
- initializeBrowserSync() {
644
- const initialPath = this.getPathFromBrowser();
645
- this.state.currentPath = initialPath;
646
- this.state.params = {};
647
- this.state.query = this.parseQuery();
648
- this.browserListeners.push(disposableListener(window, "popstate", () => {
649
- const newPath = this.getPathFromBrowser();
650
- this.updatePath(newPath, false);
651
- }));
652
- this.browserListeners.push(disposableListener(window, "hashchange", () => {
653
- if (this.isUpdating)
654
- return;
655
- const newPath = this.getPathFromBrowser();
656
- this.updatePath(newPath, false);
657
- }));
658
- this.isInitialized = true;
659
- log3.debug("Router initialized at:", initialPath);
660
- }
661
- getPathFromBrowser() {
662
- if (typeof window === "undefined")
663
- return "/";
664
- const hash = window.location.hash.slice(1);
665
- if (hash)
666
- return hash;
667
- return window.location.pathname;
668
- }
669
- parseQuery() {
670
- if (typeof window === "undefined")
671
- return {};
672
- const query = {};
673
- const searchParams = new URLSearchParams(window.location.search);
674
- searchParams.forEach((value, key) => {
675
- query[key] = value;
676
- });
677
- return query;
678
- }
679
- push(path) {
680
- log3.debug("push:", path);
681
- this.updatePath(path, true);
682
- }
683
- replace(path) {
684
- log3.debug("replace:", path);
685
- this.updatePath(path, true, true);
686
- }
687
- back() {
688
- log3.debug("back");
689
- if (typeof window !== "undefined") {
690
- window.history.back();
691
- }
692
- }
693
- forward() {
694
- log3.debug("forward");
695
- if (typeof window !== "undefined") {
696
- window.history.forward();
697
- }
698
- }
699
- updatePath(path, updateBrowser, replace = false) {
700
- if (this.isUpdating)
701
- return;
702
- this.isUpdating = true;
703
- try {
704
- const oldPath = this.state.currentPath;
705
- this.state.previousPath = oldPath;
706
- this.state.currentPath = path;
707
- this.state.query = this.parseQuery();
708
- this.notifySubscribers();
709
- if (updateBrowser && typeof window !== "undefined") {
710
- const url = "#" + path;
711
- if (replace) {
712
- window.history.replaceState(null, "", url);
713
- } else {
714
- window.history.pushState(null, "", url);
715
- }
716
- try {
717
- const hashChangeEvent = new HashChangeEvent("hashchange", {
718
- oldURL: window.location.href.replace(window.location.hash, "#" + oldPath),
719
- newURL: window.location.href
720
- });
721
- window.dispatchEvent(hashChangeEvent);
722
- } catch {}
723
- }
724
- } finally {
725
- this.isUpdating = false;
726
- }
727
- }
728
- getCurrentPath() {
729
- return this.state.currentPath;
730
- }
731
- getParams() {
732
- return { ...this.state.params };
733
- }
734
- getQuery() {
735
- return { ...this.state.query };
736
- }
737
- getState() {
738
- return getStateSnapshot(this.state);
739
- }
740
- matchPath(pattern, path) {
741
- if (!pattern || typeof pattern !== "string")
742
- return null;
743
- if (!path || typeof path !== "string")
744
- return null;
745
- const cleanPath = path.split("?")[0] ?? path;
746
- const result = portable.matchPath(pattern, cleanPath);
747
- if (!result)
748
- return null;
749
- const params = {};
750
- for (const [name, raw] of Object.entries(result.params)) {
751
- try {
752
- params[name] = decodeURIComponent(raw);
753
- } catch {
754
- params[name] = raw;
755
- }
756
- }
757
- return {
758
- params,
759
- query: this.state.query,
760
- path
761
- };
762
- }
763
- onNavigate(callback) {
764
- this.subscribers.add(callback);
765
- try {
766
- callback(this.getState());
767
- } catch (error) {
768
- log3.error("Error in route subscriber:", error);
769
- }
770
- return () => {
771
- this.subscribers.delete(callback);
772
- };
773
- }
774
- notifySubscribers() {
775
- const routeState = this.getState();
776
- this.subscribers.forEach((callback) => {
777
- try {
778
- callback(routeState);
779
- } catch (error) {
780
- log3.error("Error in route subscriber:", error);
781
- }
782
- });
783
- }
784
- isActive(pattern) {
785
- return this.matchPath(pattern, this.state.currentPath) !== null;
786
- }
787
- buildUrl(path, query) {
788
- if (!query || Object.keys(query).length === 0) {
789
- return path;
790
- }
791
- const queryString = new URLSearchParams(query).toString();
792
- return `${path}?${queryString}`;
793
- }
794
- dispose() {
795
- for (const listener of this.browserListeners) {
796
- listener.dispose();
797
- }
798
- this.browserListeners = [];
799
- this.subscribers.clear();
800
- this.isInitialized = false;
801
- log3.debug("Router disposed");
802
- }
803
- [Symbol.dispose]() {
804
- this.dispose();
805
- }
806
- }
1
+ import {
2
+ HypenRouter
3
+ } from "./chunk-p3pj1bax.js";
4
+ import"./chunk-ec0tgy9a.js";
5
+ import"./chunk-ycxp4drd.js";
6
+ import"./chunk-g830re2c.js";
7
+ import"./chunk-avchpwhf.js";
8
+ import"./chunk-5gtx3pza.js";
807
9
  export {
808
10
  HypenRouter
809
11
  };
810
12
 
811
- //# debugId=CEA53EC44554BDE164756E2164756E21
13
+ //# debugId=7BB8F71DFCC1D5F964756E2164756E21