mol_jsx_lib 0.0.41 → 0.0.44

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/node.test.js CHANGED
@@ -38,6 +38,8 @@ var $node = new Proxy({ require }, {
38
38
  const mod = target.require('module');
39
39
  if (mod.builtinModules.indexOf(name) >= 0)
40
40
  return target.require(name);
41
+ if (name[0] === '.')
42
+ return target.require(name);
41
43
  const path = target.require('path');
42
44
  const fs = target.require('fs');
43
45
  let dir = path.resolve('.');
@@ -595,29 +597,72 @@ var $;
595
597
  ;
596
598
  "use strict";
597
599
  var $;
600
+ (function ($) {
601
+ class $mol_term_color {
602
+ static reset = this.ansi(0, 0);
603
+ static bold = this.ansi(1, 22);
604
+ static italic = this.ansi(3, 23);
605
+ static underline = this.ansi(4, 24);
606
+ static inverse = this.ansi(7, 27);
607
+ static hidden = this.ansi(8, 28);
608
+ static strike = this.ansi(9, 29);
609
+ static gray = this.ansi(90, 39);
610
+ static red = this.ansi(91, 39);
611
+ static green = this.ansi(92, 39);
612
+ static yellow = this.ansi(93, 39);
613
+ static blue = this.ansi(94, 39);
614
+ static magenta = this.ansi(95, 39);
615
+ static cyan = this.ansi(96, 39);
616
+ static white = this.ansi(97, 39);
617
+ static Red = (str) => this.inverse(this.red(str));
618
+ static Green = (str) => this.inverse(this.green(str));
619
+ static Yellow = (str) => this.inverse(this.yellow(str));
620
+ static Blue = (str) => this.inverse(this.blue(str));
621
+ static Magenta = (str) => this.inverse(this.magenta(str));
622
+ static Cyan = (str) => this.inverse(this.cyan(str));
623
+ static White = (str) => this.inverse(this.white(str));
624
+ static ansi(open, close) {
625
+ if (typeof process === 'undefined')
626
+ return String;
627
+ if (!process.stdout.isTTY)
628
+ return String;
629
+ const prefix = `\x1b[${open}m`;
630
+ const postfix = `\x1b[${close}m`;
631
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
632
+ return function colorer(str) {
633
+ str = String(str);
634
+ if (str === '')
635
+ return str;
636
+ const suffix = str.replace(suffix_regexp, prefix);
637
+ return prefix + suffix + postfix;
638
+ };
639
+ }
640
+ }
641
+ $.$mol_term_color = $mol_term_color;
642
+ })($ || ($ = {}));
643
+ //mol/term/color/color.ts
644
+ ;
645
+ "use strict";
646
+ var $;
598
647
  (function ($) {
599
648
  function $mol_log3_node_make(level, output, type, color) {
600
649
  return function $mol_log3_logger(event) {
601
650
  if (!event.time)
602
651
  event = { time: new Date().toISOString(), ...event };
603
652
  const tree = this.$mol_tree.fromJSON(event).clone({ type });
604
- let str = tree.toString();
605
- if (process[output].isTTY) {
606
- str = $node.colorette[color + 'Bright'](str);
607
- }
608
- ;
653
+ let str = color(tree.toString());
609
654
  this.console[level](str);
610
655
  const self = this;
611
656
  return () => self.console.groupEnd();
612
657
  };
613
658
  }
614
659
  $.$mol_log3_node_make = $mol_log3_node_make;
615
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
616
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
617
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
618
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
619
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
620
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
660
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
661
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
662
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
663
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
664
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
665
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
621
666
  })($ || ($ = {}));
622
667
  //mol/log3/log3.node.ts
623
668
  ;
@@ -885,7 +930,7 @@ var $;
885
930
  promote() {
886
931
  $mol_wire_auto()?.track_next(this);
887
932
  }
888
- refresh() { }
933
+ fresh() { }
889
934
  complete() { }
890
935
  emit(quant = $mol_wire_cursor.stale) {
891
936
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -1088,7 +1133,7 @@ var $;
1088
1133
  }
1089
1134
  for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1090
1135
  const pub = this.data[cursor];
1091
- pub.refresh();
1136
+ pub.fresh();
1092
1137
  }
1093
1138
  this.cursor = $mol_wire_cursor.fresh;
1094
1139
  }
@@ -1218,10 +1263,13 @@ var $;
1218
1263
  }
1219
1264
  static sync() {
1220
1265
  while (this.planning.size) {
1221
- const fibers = this.planning;
1222
- this.planning = new Set;
1223
- for (const fiber of fibers) {
1224
- fiber.refresh();
1266
+ for (const fiber of this.planning) {
1267
+ this.planning.delete(fiber);
1268
+ if (fiber.cursor >= 0)
1269
+ continue;
1270
+ if (fiber.cursor === $mol_wire_cursor.final)
1271
+ continue;
1272
+ fiber.fresh();
1225
1273
  }
1226
1274
  }
1227
1275
  while (this.reaping.size) {
@@ -1248,12 +1296,13 @@ var $;
1248
1296
  field() {
1249
1297
  return this.task.name + '()';
1250
1298
  }
1251
- constructor(id, task, host, ...args) {
1299
+ constructor(id, task, host, args) {
1252
1300
  super();
1253
1301
  this.task = task;
1254
1302
  this.host = host;
1255
- this.data.push(...args);
1256
- this.pub_from = this.sub_from = args.length;
1303
+ if (args)
1304
+ this.data.push(...args);
1305
+ this.pub_from = this.sub_from = args?.length ?? 0;
1257
1306
  this[Symbol.toStringTag] = id;
1258
1307
  }
1259
1308
  plan() {
@@ -1288,7 +1337,7 @@ var $;
1288
1337
  else
1289
1338
  super.emit(quant);
1290
1339
  }
1291
- refresh() {
1340
+ fresh() {
1292
1341
  if (this.cursor === $mol_wire_cursor.fresh)
1293
1342
  return;
1294
1343
  if (this.cursor === $mol_wire_cursor.final)
@@ -1296,7 +1345,7 @@ var $;
1296
1345
  check: if (this.cursor === $mol_wire_cursor.doubt) {
1297
1346
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
1298
1347
  ;
1299
- this.data[i]?.refresh();
1348
+ this.data[i]?.fresh();
1300
1349
  if (this.cursor !== $mol_wire_cursor.doubt)
1301
1350
  break check;
1302
1351
  }
@@ -1314,7 +1363,7 @@ var $;
1314
1363
  result = this.task.call(this.host, this.data[0]);
1315
1364
  break;
1316
1365
  default:
1317
- result = this.task.call(this.host, ...this.data.slice(0, this.pub_from));
1366
+ result = this.task.call(this.host, ...this.args);
1318
1367
  break;
1319
1368
  }
1320
1369
  if (result instanceof Promise) {
@@ -1352,12 +1401,16 @@ var $;
1352
1401
  this.track_off(bu);
1353
1402
  this.put(result);
1354
1403
  }
1404
+ refresh() {
1405
+ this.cursor = $mol_wire_cursor.stale;
1406
+ this.fresh();
1407
+ }
1355
1408
  sync() {
1356
1409
  if (!$mol_wire_fiber.warm) {
1357
1410
  return this.result();
1358
1411
  }
1359
1412
  this.promote();
1360
- this.refresh();
1413
+ this.fresh();
1361
1414
  if (this.cache instanceof Error) {
1362
1415
  return $mol_fail_hidden(this.cache);
1363
1416
  }
@@ -1368,7 +1421,7 @@ var $;
1368
1421
  }
1369
1422
  async async() {
1370
1423
  while (true) {
1371
- this.refresh();
1424
+ this.fresh();
1372
1425
  if (this.cache instanceof Error) {
1373
1426
  $mol_fail_hidden(this.cache);
1374
1427
  }
@@ -1580,7 +1633,7 @@ var $;
1580
1633
  break reuse;
1581
1634
  return existen;
1582
1635
  }
1583
- return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
1636
+ return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1584
1637
  };
1585
1638
  }
1586
1639
  complete() {
@@ -1653,7 +1706,7 @@ var $;
1653
1706
  else {
1654
1707
  dict = (host ?? task)[field] = new Map();
1655
1708
  }
1656
- fiber = new $mol_wire_atom(key, task, host, ...args);
1709
+ fiber = new $mol_wire_atom(key, task, host, args);
1657
1710
  dict.set(key, fiber);
1658
1711
  return fiber;
1659
1712
  };
@@ -1664,13 +1717,29 @@ var $;
1664
1717
  if (existen)
1665
1718
  return existen;
1666
1719
  const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
1667
- const fiber = new $mol_wire_atom(key, task, host, ...args);
1720
+ const fiber = new $mol_wire_atom(key, task, host, args);
1668
1721
  (host ?? task)[field] = fiber;
1669
1722
  return fiber;
1670
1723
  };
1671
1724
  }
1672
1725
  }
1673
- resync(...args) {
1726
+ static watching = new Set();
1727
+ static watch() {
1728
+ new $mol_after_frame($mol_wire_atom.watch);
1729
+ for (const atom of $mol_wire_atom.watching) {
1730
+ if (atom.cursor === $mol_wire_cursor.final) {
1731
+ $mol_wire_atom.watching.delete(atom);
1732
+ }
1733
+ else {
1734
+ atom.cursor = $mol_wire_cursor.stale;
1735
+ atom.fresh();
1736
+ }
1737
+ }
1738
+ }
1739
+ watch() {
1740
+ $mol_wire_atom.watching.add(this);
1741
+ }
1742
+ resync(args) {
1674
1743
  return this.put(this.task.call(this.host, ...args));
1675
1744
  }
1676
1745
  once() {
@@ -1724,6 +1793,7 @@ var $;
1724
1793
  $mol_wire_method
1725
1794
  ], $mol_wire_atom.prototype, "once", null);
1726
1795
  $.$mol_wire_atom = $mol_wire_atom;
1796
+ $mol_wire_atom.watch();
1727
1797
  })($ || ($ = {}));
1728
1798
  //mol/wire/atom/atom.ts
1729
1799
  ;
@@ -1756,7 +1826,7 @@ var $;
1756
1826
  let atom = persist(this, args.slice(0, keys));
1757
1827
  if (args.length <= keys || args[keys] === undefined) {
1758
1828
  if (!$mol_wire_fiber.warm)
1759
- return atom.sync();
1829
+ return atom.result();
1760
1830
  if ($mol_wire_auto() instanceof $mol_wire_task) {
1761
1831
  return atom.once();
1762
1832
  }
@@ -1764,7 +1834,7 @@ var $;
1764
1834
  return atom.sync();
1765
1835
  }
1766
1836
  }
1767
- return atom.resync(...args);
1837
+ return atom.resync(args);
1768
1838
  };
1769
1839
  Object.defineProperty(wrapper, 'name', { value: func.name + ' ' });
1770
1840
  Object.assign(wrapper, { orig: func });
@@ -1934,6 +2004,20 @@ var $;
1934
2004
  ;
1935
2005
  "use strict";
1936
2006
  var $;
2007
+ (function ($_1) {
2008
+ $mol_test_mocks.push($ => {
2009
+ $.$mol_log3_come = () => { };
2010
+ $.$mol_log3_done = () => { };
2011
+ $.$mol_log3_fail = () => { };
2012
+ $.$mol_log3_warn = () => { };
2013
+ $.$mol_log3_rise = () => { };
2014
+ $.$mol_log3_area = () => () => { };
2015
+ });
2016
+ })($ || ($ = {}));
2017
+ //mol/log3/log3.test.ts
2018
+ ;
2019
+ "use strict";
2020
+ var $;
1937
2021
  (function ($) {
1938
2022
  function $mol_dom_serialize(node) {
1939
2023
  const serializer = new $mol_dom_context.XMLSerializer;
@@ -2089,20 +2173,6 @@ var $;
2089
2173
  ;
2090
2174
  "use strict";
2091
2175
  var $;
2092
- (function ($_1) {
2093
- $mol_test_mocks.push($ => {
2094
- $.$mol_log3_come = () => { };
2095
- $.$mol_log3_done = () => { };
2096
- $.$mol_log3_fail = () => { };
2097
- $.$mol_log3_warn = () => { };
2098
- $.$mol_log3_rise = () => { };
2099
- $.$mol_log3_area = () => () => { };
2100
- });
2101
- })($ || ($ = {}));
2102
- //mol/log3/log3.test.ts
2103
- ;
2104
- "use strict";
2105
- var $;
2106
2176
  (function ($) {
2107
2177
  $mol_test({
2108
2178
  'get'() {
@@ -2323,6 +2393,25 @@ var $;
2323
2393
  ;
2324
2394
  "use strict";
2325
2395
  var $;
2396
+ (function ($) {
2397
+ function $mol_promise() {
2398
+ let done;
2399
+ let fail;
2400
+ const promise = new Promise((d, f) => {
2401
+ done = d;
2402
+ fail = f;
2403
+ });
2404
+ return Object.assign(promise, {
2405
+ done,
2406
+ fail,
2407
+ });
2408
+ }
2409
+ $.$mol_promise = $mol_promise;
2410
+ })($ || ($ = {}));
2411
+ //mol/promise/promise.ts
2412
+ ;
2413
+ "use strict";
2414
+ var $;
2326
2415
  (function ($) {
2327
2416
  $.$mol_after_mock_queue = [];
2328
2417
  function $mol_after_mock_warp() {
@@ -2361,6 +2450,59 @@ var $;
2361
2450
  ;
2362
2451
  "use strict";
2363
2452
  var $;
2453
+ (function ($_1) {
2454
+ $mol_test_mocks.push($ => {
2455
+ $.$mol_after_timeout = $mol_after_mock_timeout;
2456
+ });
2457
+ })($ || ($ = {}));
2458
+ //mol/after/timeout/timeout.test.ts
2459
+ ;
2460
+ "use strict";
2461
+ var $;
2462
+ (function ($) {
2463
+ function $mol_wire_sync(obj) {
2464
+ return new Proxy(obj, {
2465
+ get(obj, field) {
2466
+ const val = obj[field];
2467
+ if (typeof val !== 'function')
2468
+ return val;
2469
+ const temp = $mol_wire_task.getter(val);
2470
+ return function $mol_wire_sync(...args) {
2471
+ const fiber = temp(obj, args);
2472
+ return fiber.sync();
2473
+ };
2474
+ },
2475
+ apply(obj, self, args) {
2476
+ const temp = $mol_wire_task.getter(obj);
2477
+ const fiber = temp(self, args);
2478
+ return fiber.sync();
2479
+ },
2480
+ });
2481
+ }
2482
+ $.$mol_wire_sync = $mol_wire_sync;
2483
+ })($ || ($ = {}));
2484
+ //mol/wire/sync/sync.ts
2485
+ ;
2486
+ "use strict";
2487
+ var $;
2488
+ (function ($) {
2489
+ function $mol_wait_timeout_async(timeout) {
2490
+ const promise = $mol_promise();
2491
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
2492
+ return Object.assign(promise, {
2493
+ destructor: () => task.destructor()
2494
+ });
2495
+ }
2496
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
2497
+ function $mol_wait_timeout(timeout) {
2498
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2499
+ }
2500
+ $.$mol_wait_timeout = $mol_wait_timeout;
2501
+ })($ || ($ = {}));
2502
+ //mol/wait/timeout/timeout.ts
2503
+ ;
2504
+ "use strict";
2505
+ var $;
2364
2506
  (function ($_1) {
2365
2507
  $mol_test({
2366
2508
  async 'Latest Calls Wins on Concurrency'($) {
@@ -2382,6 +2524,15 @@ var $;
2382
2524
  $mol_assert_like(NameLogger.first, ['john', 'jin']);
2383
2525
  $mol_assert_like(NameLogger.last, ['jin']);
2384
2526
  },
2527
+ async 'Wrap function'($) {
2528
+ const name = $mol_wire_async(function (name) {
2529
+ $.$mol_wait_timeout(0);
2530
+ return name;
2531
+ });
2532
+ const promise = name('jin');
2533
+ $.$mol_after_mock_warp();
2534
+ $mol_assert_like(await promise, 'jin');
2535
+ },
2385
2536
  });
2386
2537
  })($ || ($ = {}));
2387
2538
  //mol/wire/async/async.test.ts
@@ -2402,7 +2553,12 @@ var $;
2402
2553
  fiber = temp(obj, args);
2403
2554
  return fiber.async();
2404
2555
  };
2405
- }
2556
+ },
2557
+ apply(obj, self, args) {
2558
+ const temp = $mol_wire_task.getter(obj);
2559
+ const fiber = temp(self, args);
2560
+ return fiber.async();
2561
+ },
2406
2562
  });
2407
2563
  }
2408
2564
  $.$mol_wire_async = $mol_wire_async;
@@ -2469,15 +2625,6 @@ var $;
2469
2625
  ;
2470
2626
  "use strict";
2471
2627
  var $;
2472
- (function ($_1) {
2473
- $mol_test_mocks.push($ => {
2474
- $.$mol_after_timeout = $mol_after_mock_timeout;
2475
- });
2476
- })($ || ($ = {}));
2477
- //mol/after/timeout/timeout.test.ts
2478
- ;
2479
- "use strict";
2480
- var $;
2481
2628
  (function ($_1) {
2482
2629
  $mol_test_mocks.push($ => {
2483
2630
  $.$mol_after_frame = $mol_after_mock_commmon;
@@ -2664,64 +2811,6 @@ var $;
2664
2811
  ;
2665
2812
  "use strict";
2666
2813
  var $;
2667
- (function ($) {
2668
- function $mol_wire_sync(obj) {
2669
- return new Proxy(obj, {
2670
- get(obj, field) {
2671
- const val = obj[field];
2672
- if (typeof val !== 'function')
2673
- return val;
2674
- const temp = $mol_wire_task.getter(val);
2675
- return function $mol_wire_sync(...args) {
2676
- const fiber = temp(obj, args);
2677
- return fiber.sync();
2678
- };
2679
- }
2680
- });
2681
- }
2682
- $.$mol_wire_sync = $mol_wire_sync;
2683
- })($ || ($ = {}));
2684
- //mol/wire/sync/sync.ts
2685
- ;
2686
- "use strict";
2687
- var $;
2688
- (function ($) {
2689
- function $mol_promise() {
2690
- let done;
2691
- let fail;
2692
- const promise = new Promise((d, f) => {
2693
- done = d;
2694
- fail = f;
2695
- });
2696
- return Object.assign(promise, {
2697
- done,
2698
- fail,
2699
- });
2700
- }
2701
- $.$mol_promise = $mol_promise;
2702
- })($ || ($ = {}));
2703
- //mol/promise/promise.ts
2704
- ;
2705
- "use strict";
2706
- var $;
2707
- (function ($) {
2708
- function $mol_wait_timeout_async(timeout) {
2709
- const promise = $mol_promise();
2710
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
2711
- return Object.assign(promise, {
2712
- destructor: () => task.destructor()
2713
- });
2714
- }
2715
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
2716
- function $mol_wait_timeout(timeout) {
2717
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2718
- }
2719
- $.$mol_wait_timeout = $mol_wait_timeout;
2720
- })($ || ($ = {}));
2721
- //mol/wait/timeout/timeout.ts
2722
- ;
2723
- "use strict";
2724
- var $;
2725
2814
  (function ($_1) {
2726
2815
  $mol_test({
2727
2816
  'Cached channel'($) {