@lmjs/core 2.6.3 → 2.7.0

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/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@lmjs/core",
3
- "version": "2.6.3",
3
+ "version": "2.7.0",
4
4
  "description": "LumenJS reactive core runtime — the reactive engine, HTML/JS AST compiler, realtime socket client, and delegated event listeners powering LumenJS applications.",
5
5
  "files": [
6
6
  "dist/",
7
+ "cdn/",
7
8
  "src/",
8
9
  "build/",
9
10
  "vendor/"
@@ -73,6 +74,7 @@
73
74
  },
74
75
  "scripts": {
75
76
  "build": "node build/bundle.js",
77
+ "cdn": "node build/cdn.js",
76
78
  "pretest": "npm run build",
77
79
  "test": "node test/run.js"
78
80
  }
package/src/_re.js CHANGED
@@ -3576,6 +3576,77 @@ async function _renderSectionNow(tx, doc, par, k, sectionsData) {
3576
3576
  // `lm build` omits empty HST fields (fcs.js compactHstReplacer); walk() and every effect reads them unconditionally,
3577
3577
  // so restore them once per payload, in place: attrs/ax/evs/ex {}, isV false, children [] on element/section nodes,
3578
3578
  // mss [] on text nodes.
3579
+ // 2.7.0, views loaded when first opened. A production build (lm build) may move big views out of the main bundle into
3580
+ // js/v/<name>.<hash>.js files and list them in the manifest `_vcLazy` = { <fileKey>: [url, [sub-view fileKeys]] }.
3581
+ // Each file calls _lmViewLoaded(fileKey, entry). A view is fetched the first time renderView() needs it; its static
3582
+ // sub-views are prefetched as soon as it renders, and the page view of an internal link when the pointer reaches it.
3583
+ var _lmViewNavSeq = 0;
3584
+ var _lmViewLoads = {};
3585
+ function _lmLazyUrl(fileKey) {
3586
+ const m = typeof _vcLazy !== 'undefined' && _vcLazy ? _vcLazy[fileKey] : null;
3587
+ return m ? m[0] : '';
3588
+ }
3589
+ function _lmViewLoaded(fileKey, entry) {
3590
+ let payload = (typeof _vcData !== 'undefined' && _vcData) || null;
3591
+ if (!payload || !entry) return;
3592
+ if (!payload.views) payload.views = {};
3593
+ _lmHstDefaults({ views: { [fileKey]: entry } });
3594
+ payload.views[fileKey] = entry;
3595
+ const w = _lmViewLoads[fileKey];
3596
+ if (w && w.done) w.done();
3597
+ }
3598
+ function _lmLoadView(fileKey, tries) {
3599
+ const url = _lmLazyUrl(fileKey);
3600
+ if (!url) return Promise.resolve();
3601
+ let payload = (typeof _vcData !== 'undefined' && _vcData) || null;
3602
+ if (payload && payload.views && payload.views.hasOwnProperty(fileKey)) return Promise.resolve();
3603
+ if (_lmViewLoads[fileKey] && _lmViewLoads[fileKey].p) return _lmViewLoads[fileKey].p;
3604
+ const w = (_lmViewLoads[fileKey] = {});
3605
+ w.p = new Promise(function (resolve, reject) {
3606
+ w.done = resolve;
3607
+ const s = document.createElement('script');
3608
+ s.src = url;
3609
+ s.async = true;
3610
+ s.onerror = function () {
3611
+ s.remove();
3612
+ delete _lmViewLoads[fileKey];
3613
+ // one retry (a dropped connection), then the error is reported by renderView()
3614
+ if (!tries) _lmLoadView(fileKey, 1).then(resolve, reject);
3615
+ else reject(new Error('HTTP error loading ' + url));
3616
+ };
3617
+ s.onload = function () {
3618
+ // the file ran without registering itself (wrong file, an old cache): don't wait forever
3619
+ if (!(payload && payload.views && payload.views.hasOwnProperty(fileKey))) {
3620
+ delete _lmViewLoads[fileKey];
3621
+ reject(new Error(url + ' did not register its view'));
3622
+ }
3623
+ };
3624
+ document.head.appendChild(s);
3625
+ });
3626
+ return w.p;
3627
+ }
3628
+ function _lmPrefetchFor(fileKey) {
3629
+ const m = typeof _vcLazy !== 'undefined' && _vcLazy ? _vcLazy[fileKey] : null;
3630
+ let subs = m ? m[1] : (typeof _vcSubs !== 'undefined' && _vcSubs ? _vcSubs[fileKey] : null);
3631
+ if (!subs || !subs.length) return;
3632
+ const go = function () { subs.forEach(function (k) { _lmLoadView(k).catch(function () { }); }); };
3633
+ if (typeof requestIdleCallback === 'function') requestIdleCallback(go, { timeout: 2000 }); else setTimeout(go, 200);
3634
+ }
3635
+ function _lmPrefetchLink(ev) {
3636
+ if (typeof _vcLazy === 'undefined' || !_vcLazy) return;
3637
+ const a = ev.target && ev.target.closest ? ev.target.closest('a[href]') : null;
3638
+ if (!a || a.target === '_blank' || a.origin !== location.origin) return;
3639
+ let seg = a.pathname.replace(/^\/+/, '').split('/')[0];
3640
+ if (!seg) seg = (typeof appSettings !== 'undefined' && appSettings && appSettings.defaultView) || 'home';
3641
+ let key;
3642
+ try { key = btoa('src/views/' + seg + '.view'); } catch (e) { return; }
3643
+ if (_vcLazy[key]) _lmLoadView(key).catch(function () { });
3644
+ }
3645
+ if (typeof document !== 'undefined' && document.addEventListener) {
3646
+ document.addEventListener('pointerover', _lmPrefetchLink, { passive: true, capture: true });
3647
+ document.addEventListener('touchstart', _lmPrefetchLink, { passive: true, capture: true });
3648
+ }
3649
+
3579
3650
  function _lmHstDefaults(payload) {
3580
3651
  function fix(n) {
3581
3652
  if (!n || typeof n !== 'object') return;
@@ -3744,8 +3815,24 @@ async function renderView(n, isSub, d, type = 'views', viewsArr, scopeBase = ["V
3744
3815
  }
3745
3816
  }
3746
3817
 
3818
+ // 2.7.0: a production build can ship big views as separate files, loaded the first time they are opened
3819
+ // (manifest `_vcLazy`, see _lmLoadView()). A page render overtaken by a newer navigation while its view was
3820
+ // loading stops here; a sub-view's host is checked further down (_lmPageOf).
3821
+ if (_payload && type === 'views' && !_payload.views.hasOwnProperty(fileKey) && _lmLazyUrl(fileKey)) {
3822
+ const navSeq = isSub ? 0 : ++_lmViewNavSeq;
3823
+ try {
3824
+ await _lmLoadView(fileKey);
3825
+ } catch (e) {
3826
+ reportLumenError({ stage: 'view-load', error: new Error('could not load view "' + n + '": ' + (e && e.message ? e.message : e)) });
3827
+ }
3828
+ if (!isSub && navSeq !== _lmViewNavSeq) return;
3829
+ } else if (!isSub && type === 'views') {
3830
+ ++_lmViewNavSeq;
3831
+ }
3832
+
3747
3833
  if ((_payload && _payload[type].hasOwnProperty(fileKey)) /*&& _jswacrk.isStarted()*/ && _csswrk.isStarted()) {
3748
3834
  if (isSub) cl("Rendering", n, fileKey);
3835
+ if (type === 'views') _lmPrefetchFor(fileKey);
3749
3836
  var hst = _payload[type][fileKey];
3750
3837
  // var mxes = hst.mxes;
3751
3838
  // hst = hst.hst;
@@ -1394,8 +1394,15 @@ var prevNodes = [];
1394
1394
  function goToNode(d) {
1395
1395
  if (_initialized) {
1396
1396
  prevNodes = clone(nodes);
1397
+ var _fromRoute = _lumenRouteKey;
1397
1398
  nodes = getURLNodes();
1398
- Promise.resolve(renderView(nodes[0], null, d)).then(_lumenScrollToHash);
1399
+ // 2026-10-31 (owner): a page change starts at the top, like a new page. A `#fragment` scrolls to its
1400
+ // target instead; the first render and a re-render of the same route keep their position.
1401
+ var _newPage = _fromRoute !== null && _fromRoute !== _lumenRouteKey;
1402
+ Promise.resolve(renderView(nodes[0], null, d)).then(function () {
1403
+ if (location.hash && location.hash.length > 1) _lumenScrollToHash();
1404
+ else if (_newPage) st(0);
1405
+ });
1399
1406
  } else {
1400
1407
  setTimeout(function () {
1401
1408
  goToNode(d);