@hypen-space/core 0.4.37 → 0.4.39
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 +13 -14
- package/dist/app.js +304 -227
- package/dist/app.js.map +5 -5
- package/dist/components/builtin.d.ts +17 -0
- package/dist/components/builtin.js +336 -256
- package/dist/components/builtin.js.map +6 -6
- package/dist/context.d.ts +11 -20
- package/dist/context.js +69 -101
- package/dist/context.js.map +3 -3
- package/dist/datasource.js +80 -0
- package/dist/datasource.js.map +10 -0
- package/dist/disposable.js +60 -63
- package/dist/disposable.js.map +2 -2
- package/dist/events.js +60 -63
- package/dist/events.js.map +2 -2
- package/dist/hypen.js +78 -0
- package/dist/hypen.js.map +10 -0
- package/dist/index.browser.d.ts +2 -1
- package/dist/index.browser.js +327 -281
- package/dist/index.browser.js.map +7 -8
- package/dist/index.d.ts +0 -3
- package/dist/index.js +547 -246
- package/dist/index.js.map +9 -9
- package/dist/logger.js +60 -64
- package/dist/logger.js.map +2 -2
- package/dist/remote/client.js +258 -158
- package/dist/remote/client.js.map +6 -6
- package/dist/remote/index.d.ts +6 -5
- package/dist/remote/index.js +255 -1985
- package/dist/remote/index.js.map +6 -13
- package/dist/remote/session.js +151 -0
- package/dist/remote/session.js.map +10 -0
- package/dist/renderer.js +60 -63
- package/dist/renderer.js.map +2 -2
- package/dist/result.js +235 -0
- package/dist/result.js.map +10 -0
- package/dist/retry.js +344 -0
- package/dist/retry.js.map +11 -0
- package/dist/router.js +62 -70
- package/dist/router.js.map +2 -2
- package/dist/state.js +3 -8
- package/dist/state.js.map +2 -2
- package/package.json +11 -56
- package/src/components/builtin.ts +78 -56
- package/src/context.ts +22 -65
- package/src/index.browser.ts +5 -4
- package/src/index.ts +10 -23
- package/src/remote/index.ts +9 -5
- package/src/result.ts +11 -0
- package/dist/discovery.d.ts +0 -90
- package/dist/discovery.js +0 -1334
- package/dist/discovery.js.map +0 -15
- package/dist/engine.browser.d.ts +0 -116
- package/dist/engine.browser.js +0 -479
- package/dist/engine.browser.js.map +0 -12
- package/dist/engine.d.ts +0 -107
- package/dist/engine.js +0 -543
- package/dist/engine.js.map +0 -12
- package/dist/loader.d.ts +0 -51
- package/dist/loader.js +0 -292
- package/dist/loader.js.map +0 -11
- package/dist/plugin.d.ts +0 -39
- package/dist/plugin.js +0 -685
- package/dist/plugin.js.map +0 -12
- package/dist/remote/server.d.ts +0 -188
- package/dist/remote/server.js +0 -2270
- package/dist/remote/server.js.map +0 -19
- package/src/discovery.ts +0 -527
- package/src/engine.browser.ts +0 -302
- package/src/engine.ts +0 -282
- package/src/loader.ts +0 -136
- package/src/plugin.ts +0 -220
- package/src/remote/server.ts +0 -879
- package/wasm-browser/README.md +0 -594
- package/wasm-browser/hypen_engine.d.ts +0 -389
- package/wasm-browser/hypen_engine.js +0 -1070
- package/wasm-browser/hypen_engine_bg.wasm +0 -0
- package/wasm-browser/hypen_engine_bg.wasm.d.ts +0 -37
- package/wasm-browser/package.json +0 -24
- package/wasm-node/README.md +0 -594
- package/wasm-node/hypen_engine.d.ts +0 -327
- package/wasm-node/hypen_engine.js +0 -979
- package/wasm-node/hypen_engine_bg.wasm +0 -0
- package/wasm-node/hypen_engine_bg.wasm.d.ts +0 -37
- package/wasm-node/package.json +0 -22
|
@@ -21,7 +21,250 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
21
21
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
// src/result.ts
|
|
25
|
+
function Ok(value) {
|
|
26
|
+
return { ok: true, value };
|
|
27
|
+
}
|
|
28
|
+
function Err(error) {
|
|
29
|
+
return { ok: false, error };
|
|
30
|
+
}
|
|
31
|
+
function isOk(result) {
|
|
32
|
+
return result.ok;
|
|
33
|
+
}
|
|
34
|
+
function isErr(result) {
|
|
35
|
+
return !result.ok;
|
|
36
|
+
}
|
|
37
|
+
async function fromPromise(promise, mapError) {
|
|
38
|
+
try {
|
|
39
|
+
const value = await promise;
|
|
40
|
+
return Ok(value);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (mapError) {
|
|
43
|
+
return Err(mapError(e));
|
|
44
|
+
}
|
|
45
|
+
return Err(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function fromTry(fn, mapError) {
|
|
49
|
+
try {
|
|
50
|
+
return Ok(fn());
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (mapError) {
|
|
53
|
+
return Err(mapError(e));
|
|
54
|
+
}
|
|
55
|
+
return Err(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function map(result, fn) {
|
|
59
|
+
if (result.ok) {
|
|
60
|
+
return Ok(fn(result.value));
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function mapErr(result, fn) {
|
|
65
|
+
if (!result.ok) {
|
|
66
|
+
return Err(fn(result.error));
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function flatMap(result, fn) {
|
|
71
|
+
if (result.ok) {
|
|
72
|
+
return fn(result.value);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function unwrap(result) {
|
|
77
|
+
if (result.ok) {
|
|
78
|
+
return result.value;
|
|
79
|
+
}
|
|
80
|
+
throw result.error;
|
|
81
|
+
}
|
|
82
|
+
function unwrapOr(result, defaultValue) {
|
|
83
|
+
if (result.ok) {
|
|
84
|
+
return result.value;
|
|
85
|
+
}
|
|
86
|
+
return defaultValue;
|
|
87
|
+
}
|
|
88
|
+
function unwrapOrElse(result, fn) {
|
|
89
|
+
if (result.ok) {
|
|
90
|
+
return result.value;
|
|
91
|
+
}
|
|
92
|
+
return fn(result.error);
|
|
93
|
+
}
|
|
94
|
+
function match(result, handlers) {
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
return handlers.ok(result.value);
|
|
97
|
+
}
|
|
98
|
+
return handlers.err(result.error);
|
|
99
|
+
}
|
|
100
|
+
function all(results) {
|
|
101
|
+
const values = [];
|
|
102
|
+
for (const result of results) {
|
|
103
|
+
if (!result.ok) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
values.push(result.value);
|
|
107
|
+
}
|
|
108
|
+
return Ok(values);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class HypenError extends Error {
|
|
112
|
+
code;
|
|
113
|
+
context;
|
|
114
|
+
cause;
|
|
115
|
+
constructor(code, message, options) {
|
|
116
|
+
super(message);
|
|
117
|
+
this.name = "HypenError";
|
|
118
|
+
this.code = code;
|
|
119
|
+
this.context = options?.context;
|
|
120
|
+
this.cause = options?.cause;
|
|
121
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class ActionError extends HypenError {
|
|
126
|
+
actionName;
|
|
127
|
+
constructor(actionName, cause) {
|
|
128
|
+
super("ACTION_ERROR", `Action handler "${actionName}" failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
129
|
+
context: { actionName },
|
|
130
|
+
cause: cause instanceof Error ? cause : undefined
|
|
131
|
+
});
|
|
132
|
+
this.name = "ActionError";
|
|
133
|
+
this.actionName = actionName;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
class ConnectionError extends HypenError {
|
|
138
|
+
url;
|
|
139
|
+
attempt;
|
|
140
|
+
constructor(url, cause, attempt) {
|
|
141
|
+
super("CONNECTION_ERROR", `Connection to "${url}" failed${attempt ? ` (attempt ${attempt})` : ""}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
142
|
+
context: { url, attempt },
|
|
143
|
+
cause: cause instanceof Error ? cause : undefined
|
|
144
|
+
});
|
|
145
|
+
this.name = "ConnectionError";
|
|
146
|
+
this.url = url;
|
|
147
|
+
this.attempt = attempt;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class StateError extends HypenError {
|
|
152
|
+
path;
|
|
153
|
+
constructor(message, path, cause) {
|
|
154
|
+
super("STATE_ERROR", message, {
|
|
155
|
+
context: { path },
|
|
156
|
+
cause: cause instanceof Error ? cause : undefined
|
|
157
|
+
});
|
|
158
|
+
this.name = "StateError";
|
|
159
|
+
this.path = path;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class ParseError extends HypenError {
|
|
164
|
+
source;
|
|
165
|
+
constructor(message, source, cause) {
|
|
166
|
+
super("PARSE_ERROR", message, {
|
|
167
|
+
context: { source },
|
|
168
|
+
cause: cause instanceof Error ? cause : undefined
|
|
169
|
+
});
|
|
170
|
+
this.name = "ParseError";
|
|
171
|
+
this.source = source;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class RenderError extends HypenError {
|
|
176
|
+
constructor(message, cause) {
|
|
177
|
+
super("RENDER_ERROR", message, {
|
|
178
|
+
cause: cause instanceof Error ? cause : undefined
|
|
179
|
+
});
|
|
180
|
+
this.name = "RenderError";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function classifyEngineError(err) {
|
|
184
|
+
if (err && typeof err === "object" && "message" in err && "type" in err) {
|
|
185
|
+
const structured = err;
|
|
186
|
+
switch (structured.type) {
|
|
187
|
+
case "parseError":
|
|
188
|
+
return new ParseError(structured.message);
|
|
189
|
+
case "stateError":
|
|
190
|
+
return new StateError(structured.message);
|
|
191
|
+
case "renderError":
|
|
192
|
+
return new RenderError(structured.message);
|
|
193
|
+
case "actionError":
|
|
194
|
+
return new HypenError("ACTION_ERROR", structured.message);
|
|
195
|
+
default:
|
|
196
|
+
return new HypenError("UNKNOWN_ERROR", structured.message);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
200
|
+
if (message.startsWith("Parse error:")) {
|
|
201
|
+
return new ParseError(message);
|
|
202
|
+
}
|
|
203
|
+
if (message.startsWith("Invalid state:") || message.startsWith("Invalid state patch:")) {
|
|
204
|
+
return new StateError(message);
|
|
205
|
+
}
|
|
206
|
+
if (message.startsWith("Parent node not found:")) {
|
|
207
|
+
return new RenderError(message);
|
|
208
|
+
}
|
|
209
|
+
return new RenderError(message);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/datasource.ts
|
|
213
|
+
class DataSourceManager {
|
|
214
|
+
plugins = new Map;
|
|
215
|
+
configs = new Map;
|
|
216
|
+
state = new Map;
|
|
217
|
+
engine;
|
|
218
|
+
constructor(engine) {
|
|
219
|
+
this.engine = engine;
|
|
220
|
+
}
|
|
221
|
+
async use(plugin, config) {
|
|
222
|
+
const { name } = plugin;
|
|
223
|
+
this.state.set(name, {});
|
|
224
|
+
this.plugins.set(name, plugin);
|
|
225
|
+
this.configs.set(name, config);
|
|
226
|
+
await plugin.connect(config, (change) => {
|
|
227
|
+
const current = this.state.get(name) ?? {};
|
|
228
|
+
for (const path of change.paths) {
|
|
229
|
+
if (path in change.values) {
|
|
230
|
+
current[path] = change.values[path];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
this.state.set(name, current);
|
|
234
|
+
this.engine.setContext(name, current);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
get(name) {
|
|
238
|
+
return this.plugins.get(name);
|
|
239
|
+
}
|
|
240
|
+
has(name) {
|
|
241
|
+
return this.plugins.has(name);
|
|
242
|
+
}
|
|
243
|
+
getNames() {
|
|
244
|
+
return Array.from(this.plugins.keys());
|
|
245
|
+
}
|
|
246
|
+
getStatus(name) {
|
|
247
|
+
return this.plugins.get(name)?.status;
|
|
248
|
+
}
|
|
249
|
+
async remove(name) {
|
|
250
|
+
const plugin = this.plugins.get(name);
|
|
251
|
+
if (plugin) {
|
|
252
|
+
await plugin.disconnect();
|
|
253
|
+
this.plugins.delete(name);
|
|
254
|
+
this.configs.delete(name);
|
|
255
|
+
this.state.delete(name);
|
|
256
|
+
this.engine.removeContext(name);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async disconnectAll() {
|
|
260
|
+
const names = Array.from(this.plugins.keys());
|
|
261
|
+
await Promise.all(names.map((name) => this.remove(name)));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
24
265
|
// src/state.ts
|
|
266
|
+
var IS_PROXY = Symbol.for("hypen.isProxy");
|
|
267
|
+
var RAW_TARGET = Symbol.for("hypen.rawTarget");
|
|
25
268
|
function deepClone(obj) {
|
|
26
269
|
if (obj === null || typeof obj !== "object") {
|
|
27
270
|
return obj;
|
|
@@ -266,19 +509,33 @@ function unwrapProxy(value) {
|
|
|
266
509
|
}
|
|
267
510
|
return value;
|
|
268
511
|
}
|
|
269
|
-
var IS_PROXY, RAW_TARGET;
|
|
270
|
-
var init_state = __esm(() => {
|
|
271
|
-
IS_PROXY = Symbol.for("hypen.isProxy");
|
|
272
|
-
RAW_TARGET = Symbol.for("hypen.rawTarget");
|
|
273
|
-
});
|
|
274
512
|
|
|
275
513
|
// src/logger.ts
|
|
514
|
+
var LOG_LEVEL_ORDER = {
|
|
515
|
+
debug: 0,
|
|
516
|
+
info: 1,
|
|
517
|
+
warn: 2,
|
|
518
|
+
error: 3,
|
|
519
|
+
none: 4
|
|
520
|
+
};
|
|
521
|
+
var LOG_LEVEL_COLORS = {
|
|
522
|
+
debug: "\x1B[36m",
|
|
523
|
+
info: "\x1B[32m",
|
|
524
|
+
warn: "\x1B[33m",
|
|
525
|
+
error: "\x1B[31m"
|
|
526
|
+
};
|
|
527
|
+
var RESET_COLOR = "\x1B[0m";
|
|
276
528
|
function isProduction() {
|
|
277
529
|
if (typeof process !== "undefined" && process.env) {
|
|
278
530
|
return false;
|
|
279
531
|
}
|
|
280
532
|
return false;
|
|
281
533
|
}
|
|
534
|
+
var config = {
|
|
535
|
+
level: isProduction() ? "error" : "info",
|
|
536
|
+
colors: true,
|
|
537
|
+
timestamps: false
|
|
538
|
+
};
|
|
282
539
|
function setLogLevel(level) {
|
|
283
540
|
config.level = level;
|
|
284
541
|
}
|
|
@@ -409,220 +666,49 @@ class Logger {
|
|
|
409
666
|
function createLogger(tag) {
|
|
410
667
|
return new Logger(tag);
|
|
411
668
|
}
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
debug
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
log = {
|
|
434
|
-
debug: (tag, ...args) => {
|
|
435
|
-
if (!shouldLog("debug"))
|
|
436
|
-
return;
|
|
437
|
-
console.log(formatTag(tag, "debug"), ...args);
|
|
438
|
-
},
|
|
439
|
-
info: (tag, ...args) => {
|
|
440
|
-
if (!shouldLog("info"))
|
|
441
|
-
return;
|
|
442
|
-
console.info(formatTag(tag, "info"), ...args);
|
|
443
|
-
},
|
|
444
|
-
warn: (tag, ...args) => {
|
|
445
|
-
if (!shouldLog("warn"))
|
|
446
|
-
return;
|
|
447
|
-
console.warn(formatTag(tag, "warn"), ...args);
|
|
448
|
-
},
|
|
449
|
-
error: (tag, ...args) => {
|
|
450
|
-
if (!shouldLog("error"))
|
|
451
|
-
return;
|
|
452
|
-
console.error(formatTag(tag, "error"), ...args);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
frameworkLoggers = {
|
|
456
|
-
hypen: createLogger("Hypen"),
|
|
457
|
-
engine: createLogger("Engine"),
|
|
458
|
-
router: createLogger("Router"),
|
|
459
|
-
state: createLogger("State"),
|
|
460
|
-
events: createLogger("Events"),
|
|
461
|
-
remote: createLogger("Remote"),
|
|
462
|
-
renderer: createLogger("Renderer"),
|
|
463
|
-
module: createLogger("Module"),
|
|
464
|
-
lifecycle: createLogger("Lifecycle"),
|
|
465
|
-
loader: createLogger("Loader"),
|
|
466
|
-
context: createLogger("Context"),
|
|
467
|
-
discovery: createLogger("Discovery"),
|
|
468
|
-
plugin: createLogger("Plugin"),
|
|
469
|
-
canvas: createLogger("Canvas"),
|
|
470
|
-
debug: createLogger("Debug")
|
|
471
|
-
};
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
// src/result.ts
|
|
475
|
-
function Ok(value) {
|
|
476
|
-
return { ok: true, value };
|
|
477
|
-
}
|
|
478
|
-
function Err(error) {
|
|
479
|
-
return { ok: false, error };
|
|
480
|
-
}
|
|
481
|
-
function classifyEngineError(err) {
|
|
482
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
483
|
-
if (message.startsWith("Parse error:")) {
|
|
484
|
-
return new ParseError(message);
|
|
485
|
-
}
|
|
486
|
-
if (message.startsWith("Invalid state:") || message.startsWith("Invalid state patch:")) {
|
|
487
|
-
return new StateError(message);
|
|
488
|
-
}
|
|
489
|
-
if (message.startsWith("Parent node not found:")) {
|
|
490
|
-
return new RenderError(message);
|
|
491
|
-
}
|
|
492
|
-
return new RenderError(message);
|
|
493
|
-
}
|
|
494
|
-
var HypenError, ActionError, ConnectionError, StateError, ParseError, RenderError;
|
|
495
|
-
var init_result = __esm(() => {
|
|
496
|
-
HypenError = class HypenError extends Error {
|
|
497
|
-
code;
|
|
498
|
-
context;
|
|
499
|
-
cause;
|
|
500
|
-
constructor(code, message, options) {
|
|
501
|
-
super(message);
|
|
502
|
-
this.name = "HypenError";
|
|
503
|
-
this.code = code;
|
|
504
|
-
this.context = options?.context;
|
|
505
|
-
this.cause = options?.cause;
|
|
506
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
ActionError = class ActionError extends HypenError {
|
|
510
|
-
actionName;
|
|
511
|
-
constructor(actionName, cause) {
|
|
512
|
-
super("ACTION_ERROR", `Action handler "${actionName}" failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
513
|
-
context: { actionName },
|
|
514
|
-
cause: cause instanceof Error ? cause : undefined
|
|
515
|
-
});
|
|
516
|
-
this.name = "ActionError";
|
|
517
|
-
this.actionName = actionName;
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
ConnectionError = class ConnectionError extends HypenError {
|
|
521
|
-
url;
|
|
522
|
-
attempt;
|
|
523
|
-
constructor(url, cause, attempt) {
|
|
524
|
-
super("CONNECTION_ERROR", `Connection to "${url}" failed${attempt ? ` (attempt ${attempt})` : ""}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
525
|
-
context: { url, attempt },
|
|
526
|
-
cause: cause instanceof Error ? cause : undefined
|
|
527
|
-
});
|
|
528
|
-
this.name = "ConnectionError";
|
|
529
|
-
this.url = url;
|
|
530
|
-
this.attempt = attempt;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
StateError = class StateError extends HypenError {
|
|
534
|
-
path;
|
|
535
|
-
constructor(message, path, cause) {
|
|
536
|
-
super("STATE_ERROR", message, {
|
|
537
|
-
context: { path },
|
|
538
|
-
cause: cause instanceof Error ? cause : undefined
|
|
539
|
-
});
|
|
540
|
-
this.name = "StateError";
|
|
541
|
-
this.path = path;
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
ParseError = class ParseError extends HypenError {
|
|
545
|
-
source;
|
|
546
|
-
constructor(message, source, cause) {
|
|
547
|
-
super("PARSE_ERROR", message, {
|
|
548
|
-
context: { source },
|
|
549
|
-
cause: cause instanceof Error ? cause : undefined
|
|
550
|
-
});
|
|
551
|
-
this.name = "ParseError";
|
|
552
|
-
this.source = source;
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
RenderError = class RenderError extends HypenError {
|
|
556
|
-
constructor(message, cause) {
|
|
557
|
-
super("RENDER_ERROR", message, {
|
|
558
|
-
cause: cause instanceof Error ? cause : undefined
|
|
559
|
-
});
|
|
560
|
-
this.name = "RenderError";
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
// src/datasource.ts
|
|
566
|
-
class DataSourceManager {
|
|
567
|
-
plugins = new Map;
|
|
568
|
-
configs = new Map;
|
|
569
|
-
state = new Map;
|
|
570
|
-
engine;
|
|
571
|
-
constructor(engine) {
|
|
572
|
-
this.engine = engine;
|
|
573
|
-
}
|
|
574
|
-
async use(plugin, config2) {
|
|
575
|
-
const { name } = plugin;
|
|
576
|
-
this.state.set(name, {});
|
|
577
|
-
this.plugins.set(name, plugin);
|
|
578
|
-
this.configs.set(name, config2);
|
|
579
|
-
await plugin.connect(config2, (change) => {
|
|
580
|
-
const current = this.state.get(name) ?? {};
|
|
581
|
-
for (const path of change.paths) {
|
|
582
|
-
if (path in change.values) {
|
|
583
|
-
current[path] = change.values[path];
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
this.state.set(name, current);
|
|
587
|
-
this.engine.setContext(name, current);
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
get(name) {
|
|
591
|
-
return this.plugins.get(name);
|
|
592
|
-
}
|
|
593
|
-
has(name) {
|
|
594
|
-
return this.plugins.has(name);
|
|
595
|
-
}
|
|
596
|
-
getNames() {
|
|
597
|
-
return Array.from(this.plugins.keys());
|
|
598
|
-
}
|
|
599
|
-
getStatus(name) {
|
|
600
|
-
return this.plugins.get(name)?.status;
|
|
601
|
-
}
|
|
602
|
-
async remove(name) {
|
|
603
|
-
const plugin = this.plugins.get(name);
|
|
604
|
-
if (plugin) {
|
|
605
|
-
await plugin.disconnect();
|
|
606
|
-
this.plugins.delete(name);
|
|
607
|
-
this.configs.delete(name);
|
|
608
|
-
this.state.delete(name);
|
|
609
|
-
this.engine.removeContext(name);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
async disconnectAll() {
|
|
613
|
-
const names = Array.from(this.plugins.keys());
|
|
614
|
-
await Promise.all(names.map((name) => this.remove(name)));
|
|
669
|
+
var logger = createLogger("Hypen");
|
|
670
|
+
var log = {
|
|
671
|
+
debug: (tag, ...args) => {
|
|
672
|
+
if (!shouldLog("debug"))
|
|
673
|
+
return;
|
|
674
|
+
console.log(formatTag(tag, "debug"), ...args);
|
|
675
|
+
},
|
|
676
|
+
info: (tag, ...args) => {
|
|
677
|
+
if (!shouldLog("info"))
|
|
678
|
+
return;
|
|
679
|
+
console.info(formatTag(tag, "info"), ...args);
|
|
680
|
+
},
|
|
681
|
+
warn: (tag, ...args) => {
|
|
682
|
+
if (!shouldLog("warn"))
|
|
683
|
+
return;
|
|
684
|
+
console.warn(formatTag(tag, "warn"), ...args);
|
|
685
|
+
},
|
|
686
|
+
error: (tag, ...args) => {
|
|
687
|
+
if (!shouldLog("error"))
|
|
688
|
+
return;
|
|
689
|
+
console.error(formatTag(tag, "error"), ...args);
|
|
615
690
|
}
|
|
616
|
-
}
|
|
691
|
+
};
|
|
692
|
+
var frameworkLoggers = {
|
|
693
|
+
hypen: createLogger("Hypen"),
|
|
694
|
+
engine: createLogger("Engine"),
|
|
695
|
+
router: createLogger("Router"),
|
|
696
|
+
state: createLogger("State"),
|
|
697
|
+
events: createLogger("Events"),
|
|
698
|
+
remote: createLogger("Remote"),
|
|
699
|
+
renderer: createLogger("Renderer"),
|
|
700
|
+
module: createLogger("Module"),
|
|
701
|
+
lifecycle: createLogger("Lifecycle"),
|
|
702
|
+
loader: createLogger("Loader"),
|
|
703
|
+
context: createLogger("Context"),
|
|
704
|
+
discovery: createLogger("Discovery"),
|
|
705
|
+
plugin: createLogger("Plugin"),
|
|
706
|
+
canvas: createLogger("Canvas"),
|
|
707
|
+
debug: createLogger("Debug")
|
|
708
|
+
};
|
|
617
709
|
|
|
618
710
|
// src/app.ts
|
|
619
|
-
var
|
|
620
|
-
__export(exports_app, {
|
|
621
|
-
app: () => app,
|
|
622
|
-
HypenModuleInstance: () => HypenModuleInstance,
|
|
623
|
-
HypenAppBuilder: () => HypenAppBuilder,
|
|
624
|
-
HypenApp: () => HypenApp
|
|
625
|
-
});
|
|
711
|
+
var log2 = createLogger("ModuleInstance");
|
|
626
712
|
|
|
627
713
|
class HypenAppBuilder {
|
|
628
714
|
initialState;
|
|
@@ -746,6 +832,7 @@ class HypenApp {
|
|
|
746
832
|
this._registry.clear();
|
|
747
833
|
}
|
|
748
834
|
}
|
|
835
|
+
var app = new HypenApp;
|
|
749
836
|
|
|
750
837
|
class HypenModuleInstance {
|
|
751
838
|
engine;
|
|
@@ -949,19 +1036,38 @@ class HypenModuleInstance {
|
|
|
949
1036
|
Object.assign(this.state, patch);
|
|
950
1037
|
}
|
|
951
1038
|
}
|
|
952
|
-
var log2, app;
|
|
953
|
-
var init_app = __esm(() => {
|
|
954
|
-
init_result();
|
|
955
|
-
init_state();
|
|
956
|
-
init_logger();
|
|
957
|
-
log2 = createLogger("ModuleInstance");
|
|
958
|
-
app = new HypenApp;
|
|
959
|
-
});
|
|
960
1039
|
|
|
961
1040
|
// src/components/builtin.ts
|
|
962
|
-
init_app();
|
|
963
|
-
init_logger();
|
|
964
1041
|
var log3 = frameworkLoggers.router;
|
|
1042
|
+
async function updateRouteVisibility(currentPath, engine, doc) {
|
|
1043
|
+
const targetDoc = doc ?? document;
|
|
1044
|
+
const routeElements = targetDoc.querySelectorAll('[data-hypen-type="route"]');
|
|
1045
|
+
let matchFound = false;
|
|
1046
|
+
for (let index = 0;index < routeElements.length; index++) {
|
|
1047
|
+
const routeEl = routeElements[index];
|
|
1048
|
+
const htmlEl = routeEl;
|
|
1049
|
+
const routePath = htmlEl.dataset.routePath || "/";
|
|
1050
|
+
const isMatch = routePath === currentPath;
|
|
1051
|
+
htmlEl.style.display = isMatch ? "flex" : "none";
|
|
1052
|
+
if (isMatch) {
|
|
1053
|
+
matchFound = true;
|
|
1054
|
+
const componentName = htmlEl.dataset.routeComponent;
|
|
1055
|
+
const isLazy = htmlEl.dataset.routeLazy === "true";
|
|
1056
|
+
const hasContent = htmlEl.children.length > 0;
|
|
1057
|
+
const shouldRender = componentName && engine && (isLazy || !hasContent);
|
|
1058
|
+
if (shouldRender) {
|
|
1059
|
+
try {
|
|
1060
|
+
await engine.renderLazyRoute(routePath, componentName, htmlEl);
|
|
1061
|
+
} catch (err) {
|
|
1062
|
+
log3.error(`Failed to render route ${routePath}:`, err);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (!matchFound) {
|
|
1068
|
+
log3.warn(`No route matched path: ${currentPath}. Available routes:`, Array.from(routeElements).map((el) => el.dataset.routePath));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
965
1071
|
var Router = app.defineState({
|
|
966
1072
|
currentPath: "/",
|
|
967
1073
|
matchedRoute: null,
|
|
@@ -977,40 +1083,13 @@ var Router = app.defineState({
|
|
|
977
1083
|
return;
|
|
978
1084
|
}
|
|
979
1085
|
const hypenEngine = context.__hypenEngine;
|
|
980
|
-
const updateRouteVisibility = async (currentPath) => {
|
|
981
|
-
const routeElements = document.querySelectorAll('[data-hypen-type="route"]');
|
|
982
|
-
let matchFound = false;
|
|
983
|
-
for (let index = 0;index < routeElements.length; index++) {
|
|
984
|
-
const routeEl = routeElements[index];
|
|
985
|
-
const htmlEl = routeEl;
|
|
986
|
-
const routePath = htmlEl.dataset.routePath || "/";
|
|
987
|
-
const isMatch = routePath === currentPath;
|
|
988
|
-
htmlEl.style.display = isMatch ? "flex" : "none";
|
|
989
|
-
if (isMatch) {
|
|
990
|
-
matchFound = true;
|
|
991
|
-
const componentName = htmlEl.dataset.routeComponent;
|
|
992
|
-
const isLazy = htmlEl.dataset.routeLazy === "true";
|
|
993
|
-
const hasContent = htmlEl.children.length > 0;
|
|
994
|
-
if (componentName && !hasContent && hypenEngine) {
|
|
995
|
-
try {
|
|
996
|
-
await hypenEngine.renderLazyRoute(routePath, componentName, htmlEl);
|
|
997
|
-
} catch (err) {
|
|
998
|
-
log3.error(`Failed to render route ${routePath}:`, err);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
if (!matchFound) {
|
|
1004
|
-
log3.warn(`No route matched path: ${currentPath}. Available routes:`, Array.from(routeElements).map((el) => el.dataset.routePath));
|
|
1005
|
-
}
|
|
1006
|
-
};
|
|
1007
1086
|
setTimeout(() => {
|
|
1008
|
-
updateRouteVisibility(state.currentPath);
|
|
1087
|
+
updateRouteVisibility(state.currentPath, hypenEngine);
|
|
1009
1088
|
}, 100);
|
|
1010
1089
|
router.onNavigate((routeState) => {
|
|
1011
1090
|
state.currentPath = routeState.currentPath;
|
|
1012
1091
|
state.routeParams = routeState.params;
|
|
1013
|
-
updateRouteVisibility(routeState.currentPath);
|
|
1092
|
+
updateRouteVisibility(routeState.currentPath, hypenEngine);
|
|
1014
1093
|
});
|
|
1015
1094
|
}).build();
|
|
1016
1095
|
var Route = app.defineState({}, { name: "__Route" }).build();
|
|
@@ -1036,9 +1115,10 @@ var Link = app.defineState({
|
|
|
1036
1115
|
}
|
|
1037
1116
|
}).build();
|
|
1038
1117
|
export {
|
|
1118
|
+
updateRouteVisibility,
|
|
1039
1119
|
Router,
|
|
1040
1120
|
Route,
|
|
1041
1121
|
Link
|
|
1042
1122
|
};
|
|
1043
1123
|
|
|
1044
|
-
//# debugId=
|
|
1124
|
+
//# debugId=DECBF5369AD4A4FF64756E2164756E21
|