mol_jsx_lib 0.0.54 → 0.0.57

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/web.esm.js CHANGED
@@ -54,6 +54,34 @@ var $;
54
54
  ;
55
55
  "use strict";
56
56
  var $;
57
+ (function ($) {
58
+ function $mol_func_name(func) {
59
+ let name = func.name;
60
+ if (name?.length > 1)
61
+ return name;
62
+ for (let key in this) {
63
+ try {
64
+ if (this[key] !== func)
65
+ continue;
66
+ name = key;
67
+ Object.defineProperty(func, 'name', { value: name });
68
+ break;
69
+ }
70
+ catch { }
71
+ }
72
+ return name;
73
+ }
74
+ $.$mol_func_name = $mol_func_name;
75
+ function $mol_func_name_from(target, source) {
76
+ Object.defineProperty(target, 'name', { value: source.name });
77
+ return target;
78
+ }
79
+ $.$mol_func_name_from = $mol_func_name_from;
80
+ })($ || ($ = {}));
81
+ //mol/func/name/name.ts
82
+ ;
83
+ "use strict";
84
+ var $;
57
85
  (function ($) {
58
86
  function $mol_dom_render_children(el, childNodes) {
59
87
  const node_set = new Set(childNodes);
@@ -123,16 +151,40 @@ var $;
123
151
  $.$mol_jsx_frag = '';
124
152
  function $mol_jsx(Elem, props, ...childNodes) {
125
153
  const id = props && props.id || '';
154
+ const guid = $.$mol_jsx_prefix + id;
126
155
  if (Elem && $.$mol_jsx_booked) {
127
156
  if ($.$mol_jsx_booked.has(id)) {
128
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
157
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
129
158
  }
130
159
  else {
131
160
  $.$mol_jsx_booked.add(id);
132
161
  }
133
162
  }
134
- const guid = $.$mol_jsx_prefix + id;
135
163
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
164
+ if ($.$mol_jsx_prefix) {
165
+ const prefix_ext = $.$mol_jsx_prefix;
166
+ const booked_ext = $.$mol_jsx_booked;
167
+ for (const field in props) {
168
+ const func = props[field];
169
+ if (typeof func !== 'function')
170
+ continue;
171
+ const wrapper = function (...args) {
172
+ const prefix = $.$mol_jsx_prefix;
173
+ const booked = $.$mol_jsx_booked;
174
+ try {
175
+ $.$mol_jsx_prefix = prefix_ext;
176
+ $.$mol_jsx_booked = booked_ext;
177
+ return func.call(this, ...args);
178
+ }
179
+ finally {
180
+ $.$mol_jsx_prefix = prefix;
181
+ $.$mol_jsx_booked = booked;
182
+ }
183
+ };
184
+ $mol_func_name_from(wrapper, func);
185
+ props[field] = wrapper;
186
+ }
187
+ }
136
188
  if (typeof Elem !== 'string') {
137
189
  if ('prototype' in Elem) {
138
190
  const view = node && node[Elem] || new Elem;
@@ -1399,5 +1451,489 @@ var $;
1399
1451
  })($ || ($ = {}));
1400
1452
  //mol/jsx/view/view.tsx
1401
1453
  ;
1454
+ "use strict";
1455
+ var $;
1456
+ (function ($) {
1457
+ function $mol_wire_probe(task, next) {
1458
+ const warm = $mol_wire_fiber.warm;
1459
+ try {
1460
+ $mol_wire_fiber.warm = false;
1461
+ return task();
1462
+ }
1463
+ finally {
1464
+ $mol_wire_fiber.warm = warm;
1465
+ }
1466
+ }
1467
+ $.$mol_wire_probe = $mol_wire_probe;
1468
+ })($ || ($ = {}));
1469
+ //mol/wire/probe/probe.ts
1470
+ ;
1471
+ "use strict";
1472
+ var $;
1473
+ (function ($) {
1474
+ function $mol_wire_solid() {
1475
+ $mol_wire_auto().reap = nothing;
1476
+ }
1477
+ $.$mol_wire_solid = $mol_wire_solid;
1478
+ const nothing = () => { };
1479
+ })($ || ($ = {}));
1480
+ //mol/wire/solid/solid.ts
1481
+ ;
1482
+ "use strict";
1483
+ var $;
1484
+ (function ($) {
1485
+ function $mol_wire_watch() {
1486
+ const atom = $mol_wire_auto();
1487
+ if (atom instanceof $mol_wire_atom) {
1488
+ atom.watch();
1489
+ }
1490
+ else {
1491
+ $mol_fail(new Error('Atom is equired for watching'));
1492
+ }
1493
+ }
1494
+ $.$mol_wire_watch = $mol_wire_watch;
1495
+ })($ || ($ = {}));
1496
+ //mol/wire/watch/watch.ts
1497
+ ;
1498
+ "use strict";
1499
+ var $;
1500
+ (function ($) {
1501
+ function $mol_wire_sync(obj) {
1502
+ return new Proxy(obj, {
1503
+ get(obj, field) {
1504
+ const val = obj[field];
1505
+ if (typeof val !== 'function')
1506
+ return val;
1507
+ const temp = $mol_wire_task.getter(val);
1508
+ return function $mol_wire_sync(...args) {
1509
+ const fiber = temp(obj, args);
1510
+ return fiber.sync();
1511
+ };
1512
+ },
1513
+ apply(obj, self, args) {
1514
+ const temp = $mol_wire_task.getter(obj);
1515
+ const fiber = temp(self, args);
1516
+ return fiber.sync();
1517
+ },
1518
+ });
1519
+ }
1520
+ $.$mol_wire_sync = $mol_wire_sync;
1521
+ })($ || ($ = {}));
1522
+ //mol/wire/sync/sync.ts
1523
+ ;
1524
+ "use strict";
1525
+ var $;
1526
+ (function ($) {
1527
+ function $mol_wire_async(obj) {
1528
+ let fiber;
1529
+ const temp = $mol_wire_task.getter(obj);
1530
+ return new Proxy(obj, {
1531
+ get(obj, field) {
1532
+ const val = obj[field];
1533
+ if (typeof val !== 'function')
1534
+ return val;
1535
+ let fiber;
1536
+ const temp = $mol_wire_task.getter(val);
1537
+ return function $mol_wire_async(...args) {
1538
+ fiber?.destructor();
1539
+ fiber = temp(obj, args);
1540
+ return fiber.async();
1541
+ };
1542
+ },
1543
+ apply(obj, self, args) {
1544
+ fiber?.destructor();
1545
+ fiber = temp(self, args);
1546
+ return fiber.async();
1547
+ },
1548
+ });
1549
+ }
1550
+ $.$mol_wire_async = $mol_wire_async;
1551
+ })($ || ($ = {}));
1552
+ //mol/wire/async/async.ts
1553
+ ;
1554
+ "use strict";
1555
+ var $;
1556
+ (function ($) {
1557
+ function $mol_const(value) {
1558
+ var getter = (() => value);
1559
+ getter['()'] = value;
1560
+ getter[Symbol.toStringTag] = value;
1561
+ return getter;
1562
+ }
1563
+ $.$mol_const = $mol_const;
1564
+ })($ || ($ = {}));
1565
+ //mol/const/const.ts
1566
+ ;
1567
+ "use strict";
1568
+ var $;
1569
+ (function ($) {
1570
+ function $mol_wire_field(host, field, descr) {
1571
+ if (!descr)
1572
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1573
+ const _get = descr?.get || $mol_const(descr?.value);
1574
+ const persist = $mol_wire_atom.getter(_get, 0);
1575
+ const _set = descr?.set || function (next) {
1576
+ persist(this, []).put(next);
1577
+ };
1578
+ const sup = Reflect.getPrototypeOf(host);
1579
+ const sup_descr = Reflect.getOwnPropertyDescriptor(sup, field);
1580
+ Object.defineProperty(_get, 'name', { value: sup_descr?.get?.name ?? field });
1581
+ Object.defineProperty(_set, 'name', { value: sup_descr?.set?.name ?? field });
1582
+ function get() {
1583
+ return persist(this, []).sync();
1584
+ }
1585
+ const temp = $mol_wire_task.getter(_set);
1586
+ function set(next) {
1587
+ temp(this, [next]).sync();
1588
+ }
1589
+ Object.defineProperty(get, 'name', { value: _get.name + '$' });
1590
+ Object.defineProperty(set, 'name', { value: _set.name + '@' });
1591
+ Object.assign(get, { orig: _get });
1592
+ Object.assign(set, { orig: _set });
1593
+ const { value, writable, ...descr2 } = { ...descr, get, set };
1594
+ Reflect.defineProperty(host, field, descr2);
1595
+ return descr2;
1596
+ }
1597
+ $.$mol_wire_field = $mol_wire_field;
1598
+ })($ || ($ = {}));
1599
+ //mol/wire/field/field.ts
1600
+ ;
1601
+ "use strict";
1602
+ var $;
1603
+ (function ($) {
1604
+ function $mol_wire_patch(obj) {
1605
+ for (const field of Reflect.ownKeys(obj)) {
1606
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1607
+ if (!descr.configurable)
1608
+ continue;
1609
+ if (!descr.get)
1610
+ continue;
1611
+ const get = descr.get ?? (() => descr.value);
1612
+ const set = descr.set ?? (next => descr.value = next);
1613
+ const persist = $mol_wire_atom.getter(get, 0);
1614
+ Reflect.defineProperty(obj, field, {
1615
+ configurable: true,
1616
+ enumerable: descr.enumerable,
1617
+ get() {
1618
+ const atom = persist(obj, []);
1619
+ atom.watch();
1620
+ return atom.sync();
1621
+ },
1622
+ set(next) {
1623
+ const atom = persist(obj, []);
1624
+ set.call(this, next);
1625
+ atom.refresh();
1626
+ },
1627
+ });
1628
+ }
1629
+ }
1630
+ $.$mol_wire_patch = $mol_wire_patch;
1631
+ })($ || ($ = {}));
1632
+ //mol/wire/patch/patch.ts
1633
+ ;
1634
+ "use strict";
1635
+ var $;
1636
+ (function ($) {
1637
+ class $mol_wire_set extends Set {
1638
+ pub = new $mol_wire_pub;
1639
+ has(value) {
1640
+ this.pub.promote();
1641
+ return super.has(value);
1642
+ }
1643
+ entries() {
1644
+ this.pub.promote();
1645
+ return super.entries();
1646
+ }
1647
+ keys() {
1648
+ this.pub.promote();
1649
+ return super.keys();
1650
+ }
1651
+ values() {
1652
+ this.pub.promote();
1653
+ return super.values();
1654
+ }
1655
+ forEach(task, self) {
1656
+ this.pub.promote();
1657
+ super.forEach(task, self);
1658
+ }
1659
+ [Symbol.iterator]() {
1660
+ this.pub.promote();
1661
+ return super[Symbol.iterator]();
1662
+ }
1663
+ get size() {
1664
+ this.pub.promote();
1665
+ return super.size;
1666
+ }
1667
+ add(value) {
1668
+ if (super.has(value))
1669
+ return this;
1670
+ super.add(value);
1671
+ this.pub.emit();
1672
+ return this;
1673
+ }
1674
+ delete(value) {
1675
+ const res = super.delete(value);
1676
+ if (res)
1677
+ this.pub.emit();
1678
+ return res;
1679
+ }
1680
+ clear() {
1681
+ if (!super.size)
1682
+ return;
1683
+ super.clear();
1684
+ this.pub.emit();
1685
+ }
1686
+ item(val, next) {
1687
+ if (next === undefined)
1688
+ return this.has(val);
1689
+ if (next)
1690
+ this.add(val);
1691
+ else
1692
+ this.delete(val);
1693
+ return next;
1694
+ }
1695
+ }
1696
+ $.$mol_wire_set = $mol_wire_set;
1697
+ })($ || ($ = {}));
1698
+ //mol/wire/set/set.ts
1699
+ ;
1700
+ "use strict";
1701
+ var $;
1702
+ (function ($) {
1703
+ class $mol_wire_dict extends Map {
1704
+ pub = new $mol_wire_pub;
1705
+ has(key) {
1706
+ this.pub.promote();
1707
+ return super.has(key);
1708
+ }
1709
+ get(key) {
1710
+ this.pub.promote();
1711
+ return super.get(key);
1712
+ }
1713
+ entries() {
1714
+ this.pub.promote();
1715
+ return super.entries();
1716
+ }
1717
+ keys() {
1718
+ this.pub.promote();
1719
+ return super.keys();
1720
+ }
1721
+ values() {
1722
+ this.pub.promote();
1723
+ return super.values();
1724
+ }
1725
+ forEach(task, self) {
1726
+ this.pub.promote();
1727
+ super.forEach(task, self);
1728
+ }
1729
+ [Symbol.iterator]() {
1730
+ this.pub.promote();
1731
+ return super[Symbol.iterator]();
1732
+ }
1733
+ get size() {
1734
+ this.pub.promote();
1735
+ return super.size;
1736
+ }
1737
+ set(key, value) {
1738
+ if (super.get(key) === value)
1739
+ return this;
1740
+ super.set(key, value);
1741
+ this.pub.emit();
1742
+ return this;
1743
+ }
1744
+ delete(key) {
1745
+ const res = super.delete(key);
1746
+ if (res)
1747
+ this.pub.emit();
1748
+ return res;
1749
+ }
1750
+ clear() {
1751
+ if (!super.size)
1752
+ return;
1753
+ super.clear();
1754
+ this.pub.emit();
1755
+ }
1756
+ item(key, next) {
1757
+ if (next === undefined)
1758
+ return this.get(key) ?? null;
1759
+ if (next === null)
1760
+ this.delete(key);
1761
+ else
1762
+ this.set(key, next);
1763
+ return next;
1764
+ }
1765
+ }
1766
+ $.$mol_wire_dict = $mol_wire_dict;
1767
+ })($ || ($ = {}));
1768
+ //mol/wire/dict/dict.ts
1769
+ ;
1770
+ "use strict";
1771
+ var $;
1772
+ (function ($) {
1773
+ function $mol_promise() {
1774
+ let done;
1775
+ let fail;
1776
+ const promise = new Promise((d, f) => {
1777
+ done = d;
1778
+ fail = f;
1779
+ });
1780
+ return Object.assign(promise, {
1781
+ done,
1782
+ fail,
1783
+ });
1784
+ }
1785
+ $.$mol_promise = $mol_promise;
1786
+ })($ || ($ = {}));
1787
+ //mol/promise/promise.ts
1788
+ ;
1789
+ "use strict";
1790
+ var $;
1791
+ (function ($) {
1792
+ class $mol_after_timeout extends $mol_object2 {
1793
+ delay;
1794
+ task;
1795
+ id;
1796
+ constructor(delay, task) {
1797
+ super();
1798
+ this.delay = delay;
1799
+ this.task = task;
1800
+ this.id = setTimeout(task, delay);
1801
+ }
1802
+ destructor() {
1803
+ clearTimeout(this.id);
1804
+ }
1805
+ }
1806
+ $.$mol_after_timeout = $mol_after_timeout;
1807
+ })($ || ($ = {}));
1808
+ //mol/after/timeout/timeout.ts
1809
+ ;
1810
+ "use strict";
1811
+ var $;
1812
+ (function ($) {
1813
+ function $mol_wait_timeout_async(timeout) {
1814
+ const promise = $mol_promise();
1815
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
1816
+ return Object.assign(promise, {
1817
+ destructor: () => task.destructor()
1818
+ });
1819
+ }
1820
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
1821
+ function $mol_wait_timeout(timeout) {
1822
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
1823
+ }
1824
+ $.$mol_wait_timeout = $mol_wait_timeout;
1825
+ })($ || ($ = {}));
1826
+ //mol/wait/timeout/timeout.ts
1827
+ ;
1828
+ "use strict";
1829
+ var $;
1830
+ (function ($) {
1831
+ function $mol_log3_area_lazy(event) {
1832
+ const self = this;
1833
+ const stack = self.$mol_log3_stack;
1834
+ const deep = stack.length;
1835
+ let logged = false;
1836
+ stack.push(() => {
1837
+ logged = true;
1838
+ self.$mol_log3_area.call(self, event);
1839
+ });
1840
+ return () => {
1841
+ if (logged)
1842
+ self.console.groupEnd();
1843
+ if (stack.length > deep)
1844
+ stack.length = deep;
1845
+ };
1846
+ }
1847
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1848
+ $.$mol_log3_stack = [];
1849
+ })($ || ($ = {}));
1850
+ //mol/log3/log3.ts
1851
+ ;
1852
+ "use strict";
1853
+ //mol/type/keys/extract/extract.ts
1854
+ ;
1855
+ "use strict";
1856
+ var $;
1857
+ (function ($) {
1858
+ function $mol_log3_web_make(level, color) {
1859
+ return function $mol_log3_logger(event) {
1860
+ const pending = this.$mol_log3_stack.pop();
1861
+ if (pending)
1862
+ pending();
1863
+ let tpl = '%c';
1864
+ const chunks = Object.values(event);
1865
+ for (let i = 0; i < chunks.length; ++i) {
1866
+ tpl += (typeof chunks[i] === 'string') ? ' ⦙ %s' : ' ⦙ %o';
1867
+ }
1868
+ const style = `color:${color};font-weight:bolder`;
1869
+ this.console[level](tpl, style, ...chunks);
1870
+ const self = this;
1871
+ return () => self.console.groupEnd();
1872
+ };
1873
+ }
1874
+ $.$mol_log3_web_make = $mol_log3_web_make;
1875
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1876
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1877
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1878
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1879
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1880
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1881
+ })($ || ($ = {}));
1882
+ //mol/log3/log3.web.ts
1883
+ ;
1884
+ "use strict";
1885
+ var $;
1886
+ (function ($) {
1887
+ class $mol_wire_log extends $mol_object2 {
1888
+ static watch(task) {
1889
+ return task;
1890
+ }
1891
+ static track(fiber) {
1892
+ const prev = $mol_wire_probe(() => this.track(fiber));
1893
+ let next;
1894
+ try {
1895
+ next = fiber.sync();
1896
+ }
1897
+ finally {
1898
+ for (const pub of fiber.pub_list) {
1899
+ if (pub instanceof $mol_wire_fiber) {
1900
+ this.track(pub);
1901
+ }
1902
+ }
1903
+ }
1904
+ if (prev !== undefined && !$mol_compare_deep(prev, next)) {
1905
+ this.$.$mol_log3_rise({
1906
+ message: 'Changed',
1907
+ place: fiber,
1908
+ });
1909
+ }
1910
+ return next;
1911
+ }
1912
+ static active() {
1913
+ try {
1914
+ this.watch()?.();
1915
+ }
1916
+ finally {
1917
+ for (const pub of $mol_wire_auto().pub_list) {
1918
+ if (pub instanceof $mol_wire_fiber) {
1919
+ this.track(pub);
1920
+ }
1921
+ }
1922
+ }
1923
+ }
1924
+ }
1925
+ __decorate([
1926
+ $mol_mem
1927
+ ], $mol_wire_log, "watch", null);
1928
+ __decorate([
1929
+ $mol_mem_key
1930
+ ], $mol_wire_log, "track", null);
1931
+ __decorate([
1932
+ $mol_mem
1933
+ ], $mol_wire_log, "active", null);
1934
+ $.$mol_wire_log = $mol_wire_log;
1935
+ })($ || ($ = {}));
1936
+ //mol/wire/log/log.ts
1937
+ ;
1402
1938
  export default $
1403
1939
  //# sourceMappingURL=web.esm.js.map