@hypen-space/core 0.4.36 → 0.4.38

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 (80) hide show
  1. package/README.md +13 -14
  2. package/dist/app.js +289 -227
  3. package/dist/app.js.map +5 -5
  4. package/dist/components/builtin.js +289 -227
  5. package/dist/components/builtin.js.map +5 -5
  6. package/dist/context.js +60 -64
  7. package/dist/context.js.map +2 -2
  8. package/dist/datasource.js +80 -0
  9. package/dist/datasource.js.map +10 -0
  10. package/dist/disposable.js +60 -63
  11. package/dist/disposable.js.map +2 -2
  12. package/dist/events.js +60 -63
  13. package/dist/events.js.map +2 -2
  14. package/dist/hypen.js +78 -0
  15. package/dist/hypen.js.map +10 -0
  16. package/dist/index.browser.d.ts +2 -1
  17. package/dist/index.browser.js +303 -244
  18. package/dist/index.browser.js.map +6 -7
  19. package/dist/index.d.ts +0 -3
  20. package/dist/index.js +492 -180
  21. package/dist/index.js.map +6 -6
  22. package/dist/logger.js +60 -64
  23. package/dist/logger.js.map +2 -2
  24. package/dist/remote/client.js +243 -158
  25. package/dist/remote/client.js.map +6 -6
  26. package/dist/remote/index.d.ts +6 -5
  27. package/dist/remote/index.js +241 -1986
  28. package/dist/remote/index.js.map +6 -13
  29. package/dist/remote/session.js +151 -0
  30. package/dist/remote/session.js.map +10 -0
  31. package/dist/renderer.js +60 -63
  32. package/dist/renderer.js.map +2 -2
  33. package/dist/result.js +220 -0
  34. package/dist/result.js.map +10 -0
  35. package/dist/retry.js +329 -0
  36. package/dist/retry.js.map +11 -0
  37. package/dist/router.js +62 -70
  38. package/dist/router.js.map +2 -2
  39. package/dist/state.js +3 -8
  40. package/dist/state.js.map +2 -2
  41. package/package.json +11 -56
  42. package/src/index.browser.ts +5 -4
  43. package/src/index.ts +10 -23
  44. package/src/remote/index.ts +9 -5
  45. package/dist/discovery.d.ts +0 -90
  46. package/dist/discovery.js +0 -1334
  47. package/dist/discovery.js.map +0 -15
  48. package/dist/engine.browser.d.ts +0 -116
  49. package/dist/engine.browser.js +0 -479
  50. package/dist/engine.browser.js.map +0 -12
  51. package/dist/engine.d.ts +0 -107
  52. package/dist/engine.js +0 -543
  53. package/dist/engine.js.map +0 -12
  54. package/dist/loader.d.ts +0 -51
  55. package/dist/loader.js +0 -292
  56. package/dist/loader.js.map +0 -11
  57. package/dist/plugin.d.ts +0 -39
  58. package/dist/plugin.js +0 -685
  59. package/dist/plugin.js.map +0 -12
  60. package/dist/remote/server.d.ts +0 -188
  61. package/dist/remote/server.js +0 -2270
  62. package/dist/remote/server.js.map +0 -19
  63. package/src/discovery.ts +0 -527
  64. package/src/engine.browser.ts +0 -302
  65. package/src/engine.ts +0 -282
  66. package/src/loader.ts +0 -136
  67. package/src/plugin.ts +0 -220
  68. package/src/remote/server.ts +0 -879
  69. package/wasm-browser/README.md +0 -594
  70. package/wasm-browser/hypen_engine.d.ts +0 -389
  71. package/wasm-browser/hypen_engine.js +0 -1070
  72. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  73. package/wasm-browser/hypen_engine_bg.wasm.d.ts +0 -37
  74. package/wasm-browser/package.json +0 -24
  75. package/wasm-node/README.md +0 -594
  76. package/wasm-node/hypen_engine.d.ts +0 -327
  77. package/wasm-node/hypen_engine.js +0 -979
  78. package/wasm-node/hypen_engine_bg.wasm +0 -0
  79. package/wasm-node/hypen_engine_bg.wasm.d.ts +0 -37
  80. package/wasm-node/package.json +0 -22
package/dist/plugin.js DELETED
@@ -1,685 +0,0 @@
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/logger.ts
25
- function isProduction() {
26
- if (typeof process !== "undefined" && process.env) {
27
- return false;
28
- }
29
- return false;
30
- }
31
- function setLogLevel(level) {
32
- config.level = level;
33
- }
34
- function getLogLevel() {
35
- return config.level;
36
- }
37
- function configureLogger(options) {
38
- config = { ...config, ...options };
39
- }
40
- function enableLogging() {
41
- config.level = "debug";
42
- }
43
- function disableLogging() {
44
- config.level = "none";
45
- }
46
- function setDebugMode(enabled) {
47
- config.level = enabled ? "debug" : "error";
48
- }
49
- function isDebugMode() {
50
- return config.level === "debug";
51
- }
52
- function shouldLog(level) {
53
- return LOG_LEVEL_ORDER[level] >= LOG_LEVEL_ORDER[config.level];
54
- }
55
- function formatTag(tag, level) {
56
- const timestamp = config.timestamps ? `${new Date().toISOString()} ` : "";
57
- if (config.colors && level !== "none") {
58
- const color = LOG_LEVEL_COLORS[level];
59
- return `${timestamp}${color}[${tag}]${RESET_COLOR}`;
60
- }
61
- return `${timestamp}[${tag}]`;
62
- }
63
-
64
- class Logger {
65
- tag;
66
- constructor(tag) {
67
- this.tag = tag;
68
- }
69
- debug(...args) {
70
- if (!shouldLog("debug"))
71
- return;
72
- if (config.handler) {
73
- config.handler.debug(this.tag, ...args);
74
- } else {
75
- console.log(formatTag(this.tag, "debug"), ...args);
76
- }
77
- }
78
- info(...args) {
79
- if (!shouldLog("info"))
80
- return;
81
- if (config.handler) {
82
- config.handler.info(this.tag, ...args);
83
- } else {
84
- console.info(formatTag(this.tag, "info"), ...args);
85
- }
86
- }
87
- warn(...args) {
88
- if (!shouldLog("warn"))
89
- return;
90
- if (config.handler) {
91
- config.handler.warn(this.tag, ...args);
92
- } else {
93
- console.warn(formatTag(this.tag, "warn"), ...args);
94
- }
95
- }
96
- error(...args) {
97
- if (!shouldLog("error"))
98
- return;
99
- if (config.handler) {
100
- config.handler.error(this.tag, ...args);
101
- } else {
102
- console.error(formatTag(this.tag, "error"), ...args);
103
- }
104
- }
105
- time(label, fn) {
106
- if (!shouldLog("debug")) {
107
- return fn();
108
- }
109
- const start = performance.now();
110
- try {
111
- return fn();
112
- } finally {
113
- const duration = performance.now() - start;
114
- this.debug(`${label}: ${duration.toFixed(2)}ms`);
115
- }
116
- }
117
- async timeAsync(label, fn) {
118
- if (!shouldLog("debug")) {
119
- return fn();
120
- }
121
- const start = performance.now();
122
- try {
123
- return await fn();
124
- } finally {
125
- const duration = performance.now() - start;
126
- this.debug(`${label}: ${duration.toFixed(2)}ms`);
127
- }
128
- }
129
- child(subTag) {
130
- return new Logger(`${this.tag}:${subTag}`);
131
- }
132
- debugIf(condition, ...args) {
133
- if (condition)
134
- this.debug(...args);
135
- }
136
- warnIf(condition, ...args) {
137
- if (condition)
138
- this.warn(...args);
139
- }
140
- errorIf(condition, ...args) {
141
- if (condition)
142
- this.error(...args);
143
- }
144
- loggedOnce = new Set;
145
- warnOnce(key, ...args) {
146
- if (this.loggedOnce.has(key))
147
- return;
148
- this.loggedOnce.add(key);
149
- this.warn(...args);
150
- }
151
- debugOnce(key, ...args) {
152
- if (this.loggedOnce.has(key))
153
- return;
154
- this.loggedOnce.add(key);
155
- this.debug(...args);
156
- }
157
- }
158
- function createLogger(tag) {
159
- return new Logger(tag);
160
- }
161
- var LOG_LEVEL_ORDER, LOG_LEVEL_COLORS, RESET_COLOR = "\x1B[0m", config, logger, log, frameworkLoggers;
162
- var init_logger = __esm(() => {
163
- LOG_LEVEL_ORDER = {
164
- debug: 0,
165
- info: 1,
166
- warn: 2,
167
- error: 3,
168
- none: 4
169
- };
170
- LOG_LEVEL_COLORS = {
171
- debug: "\x1B[36m",
172
- info: "\x1B[32m",
173
- warn: "\x1B[33m",
174
- error: "\x1B[31m"
175
- };
176
- config = {
177
- level: isProduction() ? "error" : "info",
178
- colors: true,
179
- timestamps: false
180
- };
181
- logger = createLogger("Hypen");
182
- log = {
183
- debug: (tag, ...args) => {
184
- if (!shouldLog("debug"))
185
- return;
186
- console.log(formatTag(tag, "debug"), ...args);
187
- },
188
- info: (tag, ...args) => {
189
- if (!shouldLog("info"))
190
- return;
191
- console.info(formatTag(tag, "info"), ...args);
192
- },
193
- warn: (tag, ...args) => {
194
- if (!shouldLog("warn"))
195
- return;
196
- console.warn(formatTag(tag, "warn"), ...args);
197
- },
198
- error: (tag, ...args) => {
199
- if (!shouldLog("error"))
200
- return;
201
- console.error(formatTag(tag, "error"), ...args);
202
- }
203
- };
204
- frameworkLoggers = {
205
- hypen: createLogger("Hypen"),
206
- engine: createLogger("Engine"),
207
- router: createLogger("Router"),
208
- state: createLogger("State"),
209
- events: createLogger("Events"),
210
- remote: createLogger("Remote"),
211
- renderer: createLogger("Renderer"),
212
- module: createLogger("Module"),
213
- lifecycle: createLogger("Lifecycle"),
214
- loader: createLogger("Loader"),
215
- context: createLogger("Context"),
216
- discovery: createLogger("Discovery"),
217
- plugin: createLogger("Plugin"),
218
- canvas: createLogger("Canvas"),
219
- debug: createLogger("Debug")
220
- };
221
- });
222
-
223
- // node:path
224
- var exports_path = {};
225
- __export(exports_path, {
226
- sep: () => sep,
227
- resolve: () => resolve,
228
- relative: () => relative,
229
- posix: () => posix,
230
- parse: () => parse,
231
- normalize: () => normalize,
232
- join: () => join,
233
- isAbsolute: () => isAbsolute,
234
- format: () => format,
235
- extname: () => extname,
236
- dirname: () => dirname,
237
- delimiter: () => delimiter,
238
- default: () => path_default,
239
- basename: () => basename,
240
- _makeLong: () => _makeLong
241
- });
242
- function assertPath(path) {
243
- if (typeof path !== "string")
244
- throw TypeError("Path must be a string. Received " + JSON.stringify(path));
245
- }
246
- function normalizeStringPosix(path, allowAboveRoot) {
247
- var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
248
- for (var i = 0;i <= path.length; ++i) {
249
- if (i < path.length)
250
- code = path.charCodeAt(i);
251
- else if (code === 47)
252
- break;
253
- else
254
- code = 47;
255
- if (code === 47) {
256
- if (lastSlash === i - 1 || dots === 1)
257
- ;
258
- else if (lastSlash !== i - 1 && dots === 2) {
259
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
260
- if (res.length > 2) {
261
- var lastSlashIndex = res.lastIndexOf("/");
262
- if (lastSlashIndex !== res.length - 1) {
263
- if (lastSlashIndex === -1)
264
- res = "", lastSegmentLength = 0;
265
- else
266
- res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
267
- lastSlash = i, dots = 0;
268
- continue;
269
- }
270
- } else if (res.length === 2 || res.length === 1) {
271
- res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
272
- continue;
273
- }
274
- }
275
- if (allowAboveRoot) {
276
- if (res.length > 0)
277
- res += "/..";
278
- else
279
- res = "..";
280
- lastSegmentLength = 2;
281
- }
282
- } else {
283
- if (res.length > 0)
284
- res += "/" + path.slice(lastSlash + 1, i);
285
- else
286
- res = path.slice(lastSlash + 1, i);
287
- lastSegmentLength = i - lastSlash - 1;
288
- }
289
- lastSlash = i, dots = 0;
290
- } else if (code === 46 && dots !== -1)
291
- ++dots;
292
- else
293
- dots = -1;
294
- }
295
- return res;
296
- }
297
- function _format(sep, pathObject) {
298
- var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
299
- if (!dir)
300
- return base;
301
- if (dir === pathObject.root)
302
- return dir + base;
303
- return dir + sep + base;
304
- }
305
- function resolve() {
306
- var resolvedPath = "", resolvedAbsolute = false, cwd;
307
- for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
308
- var path;
309
- if (i >= 0)
310
- path = arguments[i];
311
- else {
312
- if (cwd === undefined)
313
- cwd = process.cwd();
314
- path = cwd;
315
- }
316
- if (assertPath(path), path.length === 0)
317
- continue;
318
- resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
319
- }
320
- if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
321
- if (resolvedPath.length > 0)
322
- return "/" + resolvedPath;
323
- else
324
- return "/";
325
- else if (resolvedPath.length > 0)
326
- return resolvedPath;
327
- else
328
- return ".";
329
- }
330
- function normalize(path) {
331
- if (assertPath(path), path.length === 0)
332
- return ".";
333
- var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
334
- if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
335
- path = ".";
336
- if (path.length > 0 && trailingSeparator)
337
- path += "/";
338
- if (isAbsolute)
339
- return "/" + path;
340
- return path;
341
- }
342
- function isAbsolute(path) {
343
- return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
344
- }
345
- function join() {
346
- if (arguments.length === 0)
347
- return ".";
348
- var joined;
349
- for (var i = 0;i < arguments.length; ++i) {
350
- var arg = arguments[i];
351
- if (assertPath(arg), arg.length > 0)
352
- if (joined === undefined)
353
- joined = arg;
354
- else
355
- joined += "/" + arg;
356
- }
357
- if (joined === undefined)
358
- return ".";
359
- return normalize(joined);
360
- }
361
- function relative(from, to) {
362
- if (assertPath(from), assertPath(to), from === to)
363
- return "";
364
- if (from = resolve(from), to = resolve(to), from === to)
365
- return "";
366
- var fromStart = 1;
367
- for (;fromStart < from.length; ++fromStart)
368
- if (from.charCodeAt(fromStart) !== 47)
369
- break;
370
- var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
371
- for (;toStart < to.length; ++toStart)
372
- if (to.charCodeAt(toStart) !== 47)
373
- break;
374
- var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
375
- for (;i <= length; ++i) {
376
- if (i === length) {
377
- if (toLen > length) {
378
- if (to.charCodeAt(toStart + i) === 47)
379
- return to.slice(toStart + i + 1);
380
- else if (i === 0)
381
- return to.slice(toStart + i);
382
- } else if (fromLen > length) {
383
- if (from.charCodeAt(fromStart + i) === 47)
384
- lastCommonSep = i;
385
- else if (i === 0)
386
- lastCommonSep = 0;
387
- }
388
- break;
389
- }
390
- var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
391
- if (fromCode !== toCode)
392
- break;
393
- else if (fromCode === 47)
394
- lastCommonSep = i;
395
- }
396
- var out = "";
397
- for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
398
- if (i === fromEnd || from.charCodeAt(i) === 47)
399
- if (out.length === 0)
400
- out += "..";
401
- else
402
- out += "/..";
403
- if (out.length > 0)
404
- return out + to.slice(toStart + lastCommonSep);
405
- else {
406
- if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
407
- ++toStart;
408
- return to.slice(toStart);
409
- }
410
- }
411
- function _makeLong(path) {
412
- return path;
413
- }
414
- function dirname(path) {
415
- if (assertPath(path), path.length === 0)
416
- return ".";
417
- var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
418
- for (var i = path.length - 1;i >= 1; --i)
419
- if (code = path.charCodeAt(i), code === 47) {
420
- if (!matchedSlash) {
421
- end = i;
422
- break;
423
- }
424
- } else
425
- matchedSlash = false;
426
- if (end === -1)
427
- return hasRoot ? "/" : ".";
428
- if (hasRoot && end === 1)
429
- return "//";
430
- return path.slice(0, end);
431
- }
432
- function basename(path, ext) {
433
- if (ext !== undefined && typeof ext !== "string")
434
- throw TypeError('"ext" argument must be a string');
435
- assertPath(path);
436
- var start = 0, end = -1, matchedSlash = true, i;
437
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
438
- if (ext.length === path.length && ext === path)
439
- return "";
440
- var extIdx = ext.length - 1, firstNonSlashEnd = -1;
441
- for (i = path.length - 1;i >= 0; --i) {
442
- var code = path.charCodeAt(i);
443
- if (code === 47) {
444
- if (!matchedSlash) {
445
- start = i + 1;
446
- break;
447
- }
448
- } else {
449
- if (firstNonSlashEnd === -1)
450
- matchedSlash = false, firstNonSlashEnd = i + 1;
451
- if (extIdx >= 0)
452
- if (code === ext.charCodeAt(extIdx)) {
453
- if (--extIdx === -1)
454
- end = i;
455
- } else
456
- extIdx = -1, end = firstNonSlashEnd;
457
- }
458
- }
459
- if (start === end)
460
- end = firstNonSlashEnd;
461
- else if (end === -1)
462
- end = path.length;
463
- return path.slice(start, end);
464
- } else {
465
- for (i = path.length - 1;i >= 0; --i)
466
- if (path.charCodeAt(i) === 47) {
467
- if (!matchedSlash) {
468
- start = i + 1;
469
- break;
470
- }
471
- } else if (end === -1)
472
- matchedSlash = false, end = i + 1;
473
- if (end === -1)
474
- return "";
475
- return path.slice(start, end);
476
- }
477
- }
478
- function extname(path) {
479
- assertPath(path);
480
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
481
- for (var i = path.length - 1;i >= 0; --i) {
482
- var code = path.charCodeAt(i);
483
- if (code === 47) {
484
- if (!matchedSlash) {
485
- startPart = i + 1;
486
- break;
487
- }
488
- continue;
489
- }
490
- if (end === -1)
491
- matchedSlash = false, end = i + 1;
492
- if (code === 46) {
493
- if (startDot === -1)
494
- startDot = i;
495
- else if (preDotState !== 1)
496
- preDotState = 1;
497
- } else if (startDot !== -1)
498
- preDotState = -1;
499
- }
500
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
501
- return "";
502
- return path.slice(startDot, end);
503
- }
504
- function format(pathObject) {
505
- if (pathObject === null || typeof pathObject !== "object")
506
- throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
507
- return _format("/", pathObject);
508
- }
509
- function parse(path) {
510
- assertPath(path);
511
- var ret = { root: "", dir: "", base: "", ext: "", name: "" };
512
- if (path.length === 0)
513
- return ret;
514
- var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
515
- if (isAbsolute2)
516
- ret.root = "/", start = 1;
517
- else
518
- start = 0;
519
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
520
- for (;i >= start; --i) {
521
- if (code = path.charCodeAt(i), code === 47) {
522
- if (!matchedSlash) {
523
- startPart = i + 1;
524
- break;
525
- }
526
- continue;
527
- }
528
- if (end === -1)
529
- matchedSlash = false, end = i + 1;
530
- if (code === 46) {
531
- if (startDot === -1)
532
- startDot = i;
533
- else if (preDotState !== 1)
534
- preDotState = 1;
535
- } else if (startDot !== -1)
536
- preDotState = -1;
537
- }
538
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
539
- if (end !== -1)
540
- if (startPart === 0 && isAbsolute2)
541
- ret.base = ret.name = path.slice(1, end);
542
- else
543
- ret.base = ret.name = path.slice(startPart, end);
544
- } else {
545
- if (startPart === 0 && isAbsolute2)
546
- ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
547
- else
548
- ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
549
- ret.ext = path.slice(startDot, end);
550
- }
551
- if (startPart > 0)
552
- ret.dir = path.slice(0, startPart - 1);
553
- else if (isAbsolute2)
554
- ret.dir = "/";
555
- return ret;
556
- }
557
- var sep = "/", delimiter = ":", posix, path_default;
558
- var init_path = __esm(() => {
559
- posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
560
- path_default = posix;
561
- });
562
-
563
- // src/plugin.ts
564
- init_path();
565
- init_logger();
566
- var {readFileSync, existsSync} = (() => ({}));
567
- function findModulePath(hypenPath, patterns) {
568
- const dir = dirname(hypenPath);
569
- const baseName = basename(hypenPath, ".hypen");
570
- const parentDir = dirname(dir);
571
- const folderName = basename(dir);
572
- for (const pattern of patterns) {
573
- let candidatePath = null;
574
- switch (pattern) {
575
- case "sibling":
576
- candidatePath = join(dir, `${baseName}.ts`);
577
- break;
578
- case "component":
579
- if (baseName === "component") {
580
- candidatePath = join(dir, "component.ts");
581
- }
582
- break;
583
- case "index":
584
- if (baseName === "index") {
585
- candidatePath = join(dir, "index.ts");
586
- }
587
- break;
588
- }
589
- if (candidatePath && existsSync(candidatePath)) {
590
- return candidatePath;
591
- }
592
- }
593
- return null;
594
- }
595
- function getComponentName(hypenPath) {
596
- const baseName = basename(hypenPath, ".hypen");
597
- if (baseName === "component" || baseName === "index") {
598
- return basename(dirname(hypenPath));
599
- }
600
- return baseName;
601
- }
602
- function parseImports(text) {
603
- const imports = [];
604
- const importRegex = /import\s+(?:\{([^}]+)\}|(\w+))\s+from\s+["']([^"']+)["']/g;
605
- let match;
606
- while ((match = importRegex.exec(text)) !== null) {
607
- const [, namedImports, defaultImport, source] = match;
608
- if (!source)
609
- continue;
610
- let names;
611
- if (namedImports) {
612
- names = namedImports.split(",").map((n) => n.trim()).filter((n) => n.length > 0);
613
- } else if (defaultImport) {
614
- names = [defaultImport];
615
- } else {
616
- continue;
617
- }
618
- imports.push({ names, source });
619
- }
620
- return imports;
621
- }
622
- function removeImports(text) {
623
- return text.replace(/import\s+(?:\{[^}]+\}|\w+)\s+from\s+["'][^"']+["']\s*/g, "");
624
- }
625
- function hypenPlugin(options = {}) {
626
- const { debug = false, patterns = ["sibling", "component", "index"] } = options;
627
- const log2 = debug ? (...args) => frameworkLoggers.plugin.debug(...args) : () => {};
628
- return {
629
- name: "hypen-loader",
630
- async setup(build) {
631
- build.onLoad({ filter: /\.hypen$/ }, async (args) => {
632
- const hypenPath = resolve(args.path);
633
- log2("Loading:", hypenPath);
634
- const templateRaw = readFileSync(hypenPath, "utf-8");
635
- const imports = parseImports(templateRaw);
636
- const template = removeImports(templateRaw).trim();
637
- if (imports.length > 0) {
638
- log2("Found imports:", imports);
639
- }
640
- const componentName = getComponentName(hypenPath);
641
- log2("Component name:", componentName);
642
- const modulePath = findModulePath(hypenPath, patterns);
643
- log2("Module path:", modulePath);
644
- let contents;
645
- if (modulePath) {
646
- const relativeModulePath = modulePath.replace(/\.ts$/, ".js");
647
- contents = `
648
- import _module from "${relativeModulePath}";
649
- export const module = _module;
650
- export const template = ${JSON.stringify(template)};
651
- export const name = ${JSON.stringify(componentName)};
652
- export default { module: _module, template: ${JSON.stringify(template)}, name: ${JSON.stringify(componentName)} };
653
- `;
654
- } else {
655
- log2("No module found, creating stateless component");
656
- contents = `
657
- import { app } from "@hypen-space/core";
658
- const _module = app.defineState({}).build();
659
- export const module = _module;
660
- export const template = ${JSON.stringify(template)};
661
- export const name = ${JSON.stringify(componentName)};
662
- export default { module: _module, template: ${JSON.stringify(template)}, name: ${JSON.stringify(componentName)} };
663
- `;
664
- }
665
- return {
666
- contents,
667
- loader: "js"
668
- };
669
- });
670
- }
671
- };
672
- }
673
- var defaultHypenPlugin = hypenPlugin();
674
- function registerHypenPlugin(options) {
675
- Bun.plugin(hypenPlugin(options));
676
- }
677
- var plugin_default = hypenPlugin;
678
- export {
679
- registerHypenPlugin,
680
- hypenPlugin,
681
- defaultHypenPlugin,
682
- plugin_default as default
683
- };
684
-
685
- //# debugId=BA65C05D9C01500364756E2164756E21