bun-plugin-stx 0.2.336 → 0.2.338
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.
|
@@ -651,6 +651,51 @@ async function runMiddleware(middlewareNames, context) {
|
|
|
651
651
|
}
|
|
652
652
|
// ../router/src/client.ts
|
|
653
653
|
var cachedRouterScript;
|
|
654
|
+
var cachedRouterScriptDev;
|
|
655
|
+
function stripRouterLogs(source) {
|
|
656
|
+
const out = [];
|
|
657
|
+
const needle = "log(";
|
|
658
|
+
let i = 0;
|
|
659
|
+
while (i < source.length) {
|
|
660
|
+
const hit = source.indexOf(needle, i);
|
|
661
|
+
if (hit === -1) {
|
|
662
|
+
out.push(source.slice(i));
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
const before = hit > 0 ? source[hit - 1] : " ";
|
|
666
|
+
const isDeclaration = /\bfunction\s+$/.test(source.slice(Math.max(0, hit - 16), hit));
|
|
667
|
+
if (/[\w$.]/.test(before) || isDeclaration) {
|
|
668
|
+
out.push(source.slice(i, hit + needle.length));
|
|
669
|
+
i = hit + needle.length;
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
out.push(source.slice(i, hit));
|
|
673
|
+
let depth = 1;
|
|
674
|
+
let j = hit + needle.length;
|
|
675
|
+
while (j < source.length && depth > 0) {
|
|
676
|
+
const character = source[j];
|
|
677
|
+
if (character === '"' || character === "'" || character === "`") {
|
|
678
|
+
const quote = character;
|
|
679
|
+
j++;
|
|
680
|
+
while (j < source.length && source[j] !== quote) {
|
|
681
|
+
if (source[j] === "\\")
|
|
682
|
+
j++;
|
|
683
|
+
j++;
|
|
684
|
+
}
|
|
685
|
+
j++;
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
if (character === "(")
|
|
689
|
+
depth++;
|
|
690
|
+
else if (character === ")")
|
|
691
|
+
depth--;
|
|
692
|
+
j++;
|
|
693
|
+
}
|
|
694
|
+
out.push("0");
|
|
695
|
+
i = j;
|
|
696
|
+
}
|
|
697
|
+
return out.join("");
|
|
698
|
+
}
|
|
654
699
|
function minifyRouterScript(source) {
|
|
655
700
|
try {
|
|
656
701
|
const transpiler = new Bun.Transpiler({ loader: "js", minifyWhitespace: true });
|
|
@@ -659,10 +704,8 @@ function minifyRouterScript(source) {
|
|
|
659
704
|
return source;
|
|
660
705
|
}
|
|
661
706
|
}
|
|
662
|
-
function
|
|
663
|
-
|
|
664
|
-
return cachedRouterScript;
|
|
665
|
-
const source = `
|
|
707
|
+
function routerSource() {
|
|
708
|
+
return `
|
|
666
709
|
;(function(){
|
|
667
710
|
'use strict';
|
|
668
711
|
var ROUTER_REV=7;
|
|
@@ -675,6 +718,17 @@ function getRouterScript() {
|
|
|
675
718
|
var debug=!!o.debug;
|
|
676
719
|
function log(){if(debug&&typeof console!=='undefined'&&console.log)console.log.apply(console,arguments)}
|
|
677
720
|
|
|
721
|
+
// Shorthands for the document-rooted queries this script makes ~33 times.
|
|
722
|
+
// Every page carries these bytes, and the budget in
|
|
723
|
+
// scripts/performance-budgets.ts is what noticed.
|
|
724
|
+
var LAYOUT_META='meta[name="stx-layout"]';
|
|
725
|
+
var LAYOUT_GROUP_META='meta[name="stx-layout-group"]';
|
|
726
|
+
var BUILD_META='meta[name="stx-build"]';
|
|
727
|
+
function qs(sel){return document.querySelector(sel)}
|
|
728
|
+
function qsa(sel){return document.querySelectorAll(sel)}
|
|
729
|
+
function ce(tag){return document.createElement(tag)}
|
|
730
|
+
function dhead(){return document.head}
|
|
731
|
+
|
|
678
732
|
// Replace, never merge: absent payloads must forget the outgoing page's data.
|
|
679
733
|
// Run at the committed swap, not during prefetch or a superseded navigation.
|
|
680
734
|
function hydrateServerData(html){
|
|
@@ -697,7 +751,7 @@ function getRouterScript() {
|
|
|
697
751
|
// Conservative on purpose: act only when BOTH ids are known. A missing id is
|
|
698
752
|
// "no information", never "mismatch", so statically hosted output (no headers)
|
|
699
753
|
// and older servers behave exactly as before.
|
|
700
|
-
var buildMeta=
|
|
754
|
+
var buildMeta=qs(BUILD_META);
|
|
701
755
|
var loadedBuild=buildMeta?(buildMeta.getAttribute('content')||''):'';
|
|
702
756
|
window.__stxBuild=loadedBuild;
|
|
703
757
|
function isBuildSkew(incoming){
|
|
@@ -845,7 +899,7 @@ function getRouterScript() {
|
|
|
845
899
|
function parseContainerAttrs(attrStr){
|
|
846
900
|
var map={};
|
|
847
901
|
if(!attrStr)return map;
|
|
848
|
-
var probe=
|
|
902
|
+
var probe=ce('div');
|
|
849
903
|
probe.innerHTML='<i '+attrStr+'></i>';
|
|
850
904
|
var src=probe.firstChild;
|
|
851
905
|
// getAttributeNames first: it is the same standard DOM answer and it is
|
|
@@ -934,7 +988,7 @@ function getRouterScript() {
|
|
|
934
988
|
}
|
|
935
989
|
|
|
936
990
|
function getContainer(){
|
|
937
|
-
return
|
|
991
|
+
return qs(containerSel)||qs('[data-stx-content]')||qs('main');
|
|
938
992
|
}
|
|
939
993
|
|
|
940
994
|
// \u2500\u2500 Navigation \u2500\u2500
|
|
@@ -1018,7 +1072,7 @@ function getRouterScript() {
|
|
|
1018
1072
|
// navigation. Scripts without an owner are unaffected.
|
|
1019
1073
|
function ownerStays(owner){
|
|
1020
1074
|
if(!owner)return false;
|
|
1021
|
-
var root=
|
|
1075
|
+
var root=qs('[data-stx-scope="'+owner+'"]');
|
|
1022
1076
|
return !root||typeof root.__stx_disposers==='function';
|
|
1023
1077
|
}
|
|
1024
1078
|
function hashScript(code){
|
|
@@ -1185,7 +1239,7 @@ function getRouterScript() {
|
|
|
1185
1239
|
if(!key||loadedExternalScripts[key])return null;
|
|
1186
1240
|
loadedExternalScripts[key]=1;
|
|
1187
1241
|
return new Promise(function(resolve){
|
|
1188
|
-
var el=
|
|
1242
|
+
var el=ce('script');
|
|
1189
1243
|
el.src=key;
|
|
1190
1244
|
// Deliberately NOT data-stx-page: both swap paths clear those on every
|
|
1191
1245
|
// navigation, which would sweep this away and \u2014 since it is never loaded
|
|
@@ -1194,12 +1248,12 @@ function getRouterScript() {
|
|
|
1194
1248
|
el.setAttribute('data-stx-external','');
|
|
1195
1249
|
el.onload=function(){resolve()};
|
|
1196
1250
|
el.onerror=function(){log('[router] container script failed:',key);resolve()};
|
|
1197
|
-
|
|
1251
|
+
dhead().appendChild(el);
|
|
1198
1252
|
});
|
|
1199
1253
|
}
|
|
1200
1254
|
|
|
1201
1255
|
// Record scripts from the initial page load
|
|
1202
|
-
|
|
1256
|
+
qsa('script').forEach(function(s){
|
|
1203
1257
|
var text=s.textContent||'';
|
|
1204
1258
|
if(s.hasAttribute('src'))rememberExternalScript(s.getAttribute('src'));
|
|
1205
1259
|
else if(text.trim())executedScriptHashes[hashScript(text)]=1;
|
|
@@ -1226,17 +1280,17 @@ function getRouterScript() {
|
|
|
1226
1280
|
return part?part.replace(/\\.stx$/i,''):'app';
|
|
1227
1281
|
}
|
|
1228
1282
|
function getCurrentLayoutGroup(){
|
|
1229
|
-
var meta=
|
|
1283
|
+
var meta=qs(LAYOUT_GROUP_META);
|
|
1230
1284
|
if(meta&&meta.getAttribute('content'))return meta.getAttribute('content');
|
|
1231
|
-
var layout=
|
|
1285
|
+
var layout=qs(LAYOUT_META);
|
|
1232
1286
|
return defaultLayoutGroup(layout?layout.getAttribute('content'):'');
|
|
1233
1287
|
}
|
|
1234
1288
|
function getDocLayoutGroup(doc,layout){
|
|
1235
|
-
var meta=doc&&doc.querySelector?doc.querySelector(
|
|
1289
|
+
var meta=doc&&doc.querySelector?doc.querySelector(LAYOUT_GROUP_META):null;
|
|
1236
1290
|
return meta&&meta.getAttribute('content')?meta.getAttribute('content'):defaultLayoutGroup(layout||'');
|
|
1237
1291
|
}
|
|
1238
1292
|
function checkLayoutChange(newLayout,targetUrl,newGroup){
|
|
1239
|
-
var currentLayout=
|
|
1293
|
+
var currentLayout=qs(LAYOUT_META);
|
|
1240
1294
|
var curLayoutName=currentLayout?currentLayout.getAttribute('content'):'';
|
|
1241
1295
|
var curGroup=getCurrentLayoutGroup();
|
|
1242
1296
|
var nextGroup=newGroup||defaultLayoutGroup(newLayout);
|
|
@@ -1289,7 +1343,7 @@ function getRouterScript() {
|
|
|
1289
1343
|
|
|
1290
1344
|
if(t.pathname===location.pathname&&t.hash){
|
|
1291
1345
|
if(pushState!==false)writeHistory(pushState,t.href);
|
|
1292
|
-
var el=
|
|
1346
|
+
var el=qs(t.hash);
|
|
1293
1347
|
if(el)el.scrollIntoView({behavior:'smooth'});
|
|
1294
1348
|
return Promise.resolve(true);
|
|
1295
1349
|
}
|
|
@@ -1434,7 +1488,7 @@ else {
|
|
|
1434
1488
|
function routeAnnouncer(){
|
|
1435
1489
|
var el=document.getElementById('stx-route-announcer');
|
|
1436
1490
|
if(el)return el;
|
|
1437
|
-
el=
|
|
1491
|
+
el=ce('div');
|
|
1438
1492
|
el.id='stx-route-announcer';
|
|
1439
1493
|
el.setAttribute('aria-live','polite');
|
|
1440
1494
|
el.setAttribute('role','status');
|
|
@@ -1467,7 +1521,7 @@ else {
|
|
|
1467
1521
|
function focusAfterNavigation(hash){
|
|
1468
1522
|
if(o.routeFocus===false)return;
|
|
1469
1523
|
var target=null;
|
|
1470
|
-
if(hash){try{target=
|
|
1524
|
+
if(hash){try{target=qs(hash)}catch(e){target=null}}
|
|
1471
1525
|
if(!target)target=getContainer();
|
|
1472
1526
|
if(!target||!target.focus)return;
|
|
1473
1527
|
// The container is not naturally focusable. tabindex="-1" makes it
|
|
@@ -1490,7 +1544,7 @@ else {
|
|
|
1490
1544
|
// be the last one, every navigation, not just the first time it is seen.
|
|
1491
1545
|
function findGeneratedCss(abs){
|
|
1492
1546
|
var found=null;
|
|
1493
|
-
|
|
1547
|
+
qsa('head link[data-css][href]').forEach(function(link){
|
|
1494
1548
|
if(new URL(link.getAttribute('href'),location.href).href!==abs)return;
|
|
1495
1549
|
// Collapse duplicates, so moving one copy to the end can never leave an
|
|
1496
1550
|
// older copy of the same sheet behind to fight it.
|
|
@@ -1519,7 +1573,7 @@ else {
|
|
|
1519
1573
|
if(link.__stxCssReady)pending.push(link.__stxCssReady);
|
|
1520
1574
|
return;
|
|
1521
1575
|
}
|
|
1522
|
-
link=
|
|
1576
|
+
link=ce('link');
|
|
1523
1577
|
link.setAttribute('data-css','generated');
|
|
1524
1578
|
link.setAttribute('rel','stylesheet');
|
|
1525
1579
|
link.setAttribute('href',new URL(href,location.href).href===abs?href:abs);
|
|
@@ -1540,7 +1594,7 @@ else {
|
|
|
1540
1594
|
link.onerror=function(){finish(true)};
|
|
1541
1595
|
});
|
|
1542
1596
|
pending.push(link.__stxCssReady);
|
|
1543
|
-
|
|
1597
|
+
dhead().appendChild(link);
|
|
1544
1598
|
});
|
|
1545
1599
|
return pending.length?Promise.all(pending).then(function(results){return results.every(function(ok){return ok!==false})}):null;
|
|
1546
1600
|
}
|
|
@@ -1576,7 +1630,7 @@ else {
|
|
|
1576
1630
|
link.removeAttribute('data-stx-css-pending');
|
|
1577
1631
|
link.removeAttribute('media');
|
|
1578
1632
|
}
|
|
1579
|
-
|
|
1633
|
+
dhead().appendChild(link);
|
|
1580
1634
|
});
|
|
1581
1635
|
}
|
|
1582
1636
|
|
|
@@ -1689,18 +1743,18 @@ else {
|
|
|
1689
1743
|
});
|
|
1690
1744
|
cleanFrag=cleanFrag.replace(new RegExp('<!--stx-held-script-(\\\\d+)-->','g'),function(m,i){return heldScripts[Number(i)]});
|
|
1691
1745
|
// Remove old page styles (not css \u2014 that gets merged)
|
|
1692
|
-
|
|
1746
|
+
qsa('style[data-stx-page]').forEach(function(s){s.remove()});
|
|
1693
1747
|
// Merge css CSS from fragment into existing css style
|
|
1694
1748
|
if(fragCss){
|
|
1695
|
-
var curCss=
|
|
1749
|
+
var curCss=qs('head style[data-css]');
|
|
1696
1750
|
if(curCss){
|
|
1697
1751
|
var merged=mergeCss(curCss.textContent||'',fragCss);
|
|
1698
1752
|
if(merged)curCss.textContent=merged;
|
|
1699
1753
|
}else{
|
|
1700
|
-
var cw=
|
|
1754
|
+
var cw=ce('style');
|
|
1701
1755
|
cw.setAttribute('data-css','generated');
|
|
1702
1756
|
cw.textContent=fragCss;
|
|
1703
|
-
|
|
1757
|
+
dhead().appendChild(cw);
|
|
1704
1758
|
}
|
|
1705
1759
|
}
|
|
1706
1760
|
// Already present ones are MOVED last, not skipped \u2014 see
|
|
@@ -1708,10 +1762,10 @@ else {
|
|
|
1708
1762
|
promoteGeneratedCss(fragCssHrefs,location.href);
|
|
1709
1763
|
// Add new page styles
|
|
1710
1764
|
fragStyles.forEach(function(s){
|
|
1711
|
-
var el=
|
|
1765
|
+
var el=ce('style');
|
|
1712
1766
|
el.textContent=s.css;
|
|
1713
1767
|
el.setAttribute('data-stx-page','');
|
|
1714
|
-
|
|
1768
|
+
dhead().appendChild(el);
|
|
1715
1769
|
});
|
|
1716
1770
|
// Swap content \u2014 apply the destination container's own attributes first
|
|
1717
1771
|
// so the incoming markup lands in a correctly-laid-out container instead
|
|
@@ -1719,11 +1773,11 @@ else {
|
|
|
1719
1773
|
applyContainerAttrs(currentContent,pendingContainerAttrs);
|
|
1720
1774
|
currentContent.innerHTML=cleanFrag;
|
|
1721
1775
|
// Remove old page scripts
|
|
1722
|
-
|
|
1776
|
+
qsa('script[data-stx-page]').forEach(function(s){s.remove()});
|
|
1723
1777
|
if(pushState!==false)writeHistory(pushState,url+(hash||''));
|
|
1724
1778
|
refreshCurrentLinks();
|
|
1725
1779
|
if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
|
|
1726
|
-
else if(hash){var el=
|
|
1780
|
+
else if(hash){var el=qs(hash);if(el)el.scrollIntoView({behavior:'smooth'})}
|
|
1727
1781
|
window.dispatchEvent(new CustomEvent('stx:navigate',{detail:{url:url}}));
|
|
1728
1782
|
// Before page scripts run, so a page that focuses its own control on
|
|
1729
1783
|
// mount still wins \u2014 its script executes after this.
|
|
@@ -1733,7 +1787,7 @@ else {
|
|
|
1733
1787
|
setTimeout(announceRoute,0);
|
|
1734
1788
|
// Execute page scripts FIRST \u2014 they define setup functions and set _latestSetup
|
|
1735
1789
|
log('[router] frag scripts:', fragScripts.length);
|
|
1736
|
-
|
|
1790
|
+
qsa('script[data-stx-page]').forEach(function(s){s.remove()});
|
|
1737
1791
|
// The page's module registry first (#1957), setups last. A fragment
|
|
1738
1792
|
// lists its scripts in document order, and the registry is emitted
|
|
1739
1793
|
// after the content it serves: a component that imports a package ran
|
|
@@ -1745,11 +1799,11 @@ else {
|
|
|
1745
1799
|
fragScripts.forEach(function(entry){
|
|
1746
1800
|
var code=entry.text;
|
|
1747
1801
|
log('[router] exec script len:', code.length, 'has __stx_setup:', code.indexOf('__stx_setup')>-1);
|
|
1748
|
-
var placeholder=
|
|
1802
|
+
var placeholder=qs('script[data-stx-route-script="'+entry.slot+'"]');
|
|
1749
1803
|
var nestedScopedTemplate=false;
|
|
1750
1804
|
var scopedLoopSetup=false;
|
|
1751
1805
|
if(entry.scoped&&placeholder){
|
|
1752
|
-
|
|
1806
|
+
qsa('template').forEach(function(template){
|
|
1753
1807
|
if(template.contains(placeholder)||(template.content&&template.content.contains(placeholder)))
|
|
1754
1808
|
nestedScopedTemplate=true;
|
|
1755
1809
|
});
|
|
@@ -1792,7 +1846,7 @@ else {
|
|
|
1792
1846
|
return;
|
|
1793
1847
|
}
|
|
1794
1848
|
executedScriptHashes[h]=1;
|
|
1795
|
-
var ns=
|
|
1849
|
+
var ns=ce('script');
|
|
1796
1850
|
var hasImport=hasStaticImport(code);
|
|
1797
1851
|
if(hasImport){
|
|
1798
1852
|
ns.type='module';
|
|
@@ -1855,7 +1909,7 @@ else {
|
|
|
1855
1909
|
var doc=parser.parseFromString(html,'text/html');
|
|
1856
1910
|
// Full documents carry the build id as a meta rather than a header, and
|
|
1857
1911
|
// this path also serves cached HTML, so check here too (#1772).
|
|
1858
|
-
var docBuildMeta=doc.querySelector(
|
|
1912
|
+
var docBuildMeta=doc.querySelector(BUILD_META);
|
|
1859
1913
|
var docBuild=docBuildMeta?(docBuildMeta.getAttribute('content')||''):'';
|
|
1860
1914
|
if(isBuildSkew(docBuild)){reloadForSkew(url,docBuild);return Promise.resolve(false)}
|
|
1861
1915
|
// Same hand-off as the fragment path, for the same reason (#1809, #1839).
|
|
@@ -1889,12 +1943,12 @@ else {
|
|
|
1889
1943
|
// \u2500\u2500 Swap <head> styles \u2500\u2500
|
|
1890
1944
|
// Inject new styles FIRST, then remove old to prevent unstyled flash
|
|
1891
1945
|
var keepIds={'stx-view-transitions':1,'stx-r-css':1};
|
|
1892
|
-
var curStyles=
|
|
1946
|
+
var curStyles=qsa('head style');
|
|
1893
1947
|
var newStyles=doc.querySelectorAll('head style');
|
|
1894
1948
|
|
|
1895
1949
|
// Merge css styles instead of replacing \u2014 persistent elements
|
|
1896
1950
|
// (nav, footer) outside <main> still need their utility classes
|
|
1897
|
-
var curCss=
|
|
1951
|
+
var curCss=qs('head style[data-css]');
|
|
1898
1952
|
var newCss=null;
|
|
1899
1953
|
newStyles.forEach(function(s){if(s.getAttribute('data-css'))newCss=s});
|
|
1900
1954
|
|
|
@@ -1906,20 +1960,20 @@ else {
|
|
|
1906
1960
|
var incoming=[];
|
|
1907
1961
|
newStyles.forEach(function(s){
|
|
1908
1962
|
if(!keepIds[s.id]&&!s.getAttribute('data-css')){
|
|
1909
|
-
var ns=
|
|
1963
|
+
var ns=ce('style');
|
|
1910
1964
|
ns.textContent=s.textContent;
|
|
1911
1965
|
ns.setAttribute('data-stx-incoming','');
|
|
1912
|
-
|
|
1966
|
+
dhead().appendChild(ns);
|
|
1913
1967
|
incoming.push(ns);
|
|
1914
1968
|
}
|
|
1915
1969
|
});
|
|
1916
1970
|
|
|
1917
1971
|
// If no existing css but new page has one, add it
|
|
1918
1972
|
if(!curCss&&newCss){
|
|
1919
|
-
var ns=
|
|
1973
|
+
var ns=ce('style');
|
|
1920
1974
|
ns.textContent=newCss.textContent;
|
|
1921
1975
|
ns.setAttribute('data-css',newCss.getAttribute('data-css'));
|
|
1922
|
-
|
|
1976
|
+
dhead().appendChild(ns);
|
|
1923
1977
|
}
|
|
1924
1978
|
|
|
1925
1979
|
// Remove old styles (except persistent ones, css, and incoming)
|
|
@@ -1946,7 +2000,7 @@ else {
|
|
|
1946
2000
|
try{docBase=new URL(url,location.href).href}catch(e){docBase=location.href}
|
|
1947
2001
|
var linkSel='link[rel="stylesheet"],link[rel="preconnect"]';
|
|
1948
2002
|
var curLinks={};
|
|
1949
|
-
|
|
2003
|
+
qsa('head '+linkSel).forEach(function(l){var h=l.getAttribute('href');if(h)curLinks[new URL(h,location.href).href]=1});
|
|
1950
2004
|
doc.querySelectorAll('head '+linkSel).forEach(function(l){
|
|
1951
2005
|
var href=l.getAttribute('href');
|
|
1952
2006
|
if(!href)return;
|
|
@@ -1956,9 +2010,9 @@ else {
|
|
|
1956
2010
|
var abs=new URL(href,docBase).href;
|
|
1957
2011
|
if(curLinks[abs])return;
|
|
1958
2012
|
curLinks[abs]=1;
|
|
1959
|
-
var nl=
|
|
2013
|
+
var nl=ce('link');
|
|
1960
2014
|
Array.from(l.attributes).forEach(function(a){nl.setAttribute(a.name,a.value)});
|
|
1961
|
-
|
|
2015
|
+
dhead().appendChild(nl);
|
|
1962
2016
|
});
|
|
1963
2017
|
// After every other stylesheet link, so the destination's complete
|
|
1964
2018
|
// utility sheet is last in the cascade.
|
|
@@ -1972,8 +2026,8 @@ else {
|
|
|
1972
2026
|
var declaredLayout=pendingLayoutDecl;
|
|
1973
2027
|
pendingLayoutDecl=null;
|
|
1974
2028
|
if(newBody){
|
|
1975
|
-
var newMeta=doc.querySelector(
|
|
1976
|
-
var curMeta=
|
|
2029
|
+
var newMeta=doc.querySelector(LAYOUT_META);
|
|
2030
|
+
var curMeta=qs(LAYOUT_META);
|
|
1977
2031
|
var curLayout=curMeta?curMeta.getAttribute('content'):'';
|
|
1978
2032
|
// The server's answer wins over the document's metas. We are only here
|
|
1979
2033
|
// because checkLayoutChange already said the group changed, based on
|
|
@@ -2041,16 +2095,16 @@ else {
|
|
|
2041
2095
|
// Copy body attributes (class, data-stx, etc.)
|
|
2042
2096
|
Array.from(newBody.attributes).forEach(function(attr){document.body.setAttribute(attr.name,attr.value)});
|
|
2043
2097
|
// Update layout meta tag
|
|
2044
|
-
var oldMeta=
|
|
2045
|
-
var freshMeta=doc.querySelector(
|
|
2098
|
+
var oldMeta=qs(LAYOUT_META);
|
|
2099
|
+
var freshMeta=doc.querySelector(LAYOUT_META);
|
|
2046
2100
|
if(oldMeta&&freshMeta)oldMeta.setAttribute('content',freshMeta.getAttribute('content')||'');
|
|
2047
|
-
else if(freshMeta){var m=
|
|
2048
|
-
var oldGroupMeta=
|
|
2049
|
-
var freshGroupMeta=doc.querySelector(
|
|
2101
|
+
else if(freshMeta){var m=ce('meta');m.name='stx-layout';m.content=freshMeta.getAttribute('content')||'';dhead().appendChild(m)}
|
|
2102
|
+
var oldGroupMeta=qs(LAYOUT_GROUP_META);
|
|
2103
|
+
var freshGroupMeta=doc.querySelector(LAYOUT_GROUP_META);
|
|
2050
2104
|
if(oldGroupMeta&&freshGroupMeta)oldGroupMeta.setAttribute('content',freshGroupMeta.getAttribute('content')||'');
|
|
2051
|
-
else if(freshGroupMeta){var gm=
|
|
2105
|
+
else if(freshGroupMeta){var gm=ce('meta');gm.name='stx-layout-group';gm.content=freshGroupMeta.getAttribute('content')||'';dhead().appendChild(gm)}
|
|
2052
2106
|
// Update container reference for script execution below
|
|
2053
|
-
currentContent=
|
|
2107
|
+
currentContent=qs(containerSel)||qs('main')||document.body;
|
|
2054
2108
|
} else {
|
|
2055
2109
|
// Same layout \u2014 swap only container content. Carry the destination
|
|
2056
2110
|
// container's attributes across too (same reason as the fragment path:
|
|
@@ -2069,7 +2123,7 @@ else {
|
|
|
2069
2123
|
|
|
2070
2124
|
// \u2500\u2500 Load new external <head> scripts \u2500\u2500
|
|
2071
2125
|
var loadedSrcs={};
|
|
2072
|
-
|
|
2126
|
+
qsa('head script[src]').forEach(function(s){loadedSrcs[s.src]=1});
|
|
2073
2127
|
var extPromises=[];
|
|
2074
2128
|
doc.querySelectorAll('head script[src]').forEach(function(s){
|
|
2075
2129
|
if(isSharedClientScript(s))return;
|
|
@@ -2079,11 +2133,11 @@ else {
|
|
|
2079
2133
|
if(loadedSrcs[src])return;
|
|
2080
2134
|
loadedSrcs[src]=1;
|
|
2081
2135
|
extPromises.push(new Promise(function(resolve,reject){
|
|
2082
|
-
var ns=
|
|
2136
|
+
var ns=ce('script');
|
|
2083
2137
|
ns.src=src;
|
|
2084
2138
|
ns.onload=resolve;
|
|
2085
2139
|
ns.onerror=reject;
|
|
2086
|
-
|
|
2140
|
+
dhead().appendChild(ns);
|
|
2087
2141
|
}));
|
|
2088
2142
|
});
|
|
2089
2143
|
|
|
@@ -2097,7 +2151,7 @@ else {
|
|
|
2097
2151
|
|
|
2098
2152
|
// \u2500\u2500 Script re-execution \u2500\u2500
|
|
2099
2153
|
// Remove previously injected page scripts
|
|
2100
|
-
|
|
2154
|
+
qsa('script[data-stx-page]').forEach(function(s){s.remove()});
|
|
2101
2155
|
|
|
2102
2156
|
var scripts=routedBodyScripts.slice();
|
|
2103
2157
|
function addScript(text, runAlways, slot, owner){
|
|
@@ -2182,7 +2236,7 @@ else {
|
|
|
2182
2236
|
|
|
2183
2237
|
// Scroll
|
|
2184
2238
|
if(o.scrollToTop&&!hash)window.scrollTo({top:0,behavior:'instant'});
|
|
2185
|
-
else if(hash){var el=
|
|
2239
|
+
else if(hash){var el=qs(hash);if(el)el.scrollIntoView({behavior:'smooth'})}
|
|
2186
2240
|
|
|
2187
2241
|
// Update title
|
|
2188
2242
|
var newTitle=doc.querySelector('title');
|
|
@@ -2243,7 +2297,7 @@ else {
|
|
|
2243
2297
|
if(!runAlways&&!isSetup&&executedScriptHashes[h])return;
|
|
2244
2298
|
executedScriptHashes[h]=1;
|
|
2245
2299
|
// Wrap scripts with import statements as modules (Bug 3 fix)
|
|
2246
|
-
var ns=
|
|
2300
|
+
var ns=ce('script');
|
|
2247
2301
|
if(hasImport){
|
|
2248
2302
|
ns.type='module';
|
|
2249
2303
|
}
|
|
@@ -2256,7 +2310,7 @@ else {
|
|
|
2256
2310
|
var alreadyScoped=runsAlways(typeof entry==='string'?'':entry.run,text);
|
|
2257
2311
|
ns.textContent=(hasImport||alreadyScoped)?text:'{'+text+'}';
|
|
2258
2312
|
ns.setAttribute('data-stx-page','');
|
|
2259
|
-
var placeholder=entry.slot?
|
|
2313
|
+
var placeholder=entry.slot?qs('script[data-stx-route-script="'+entry.slot+'"]'):null;
|
|
2260
2314
|
if(placeholder&&placeholder.parentNode){
|
|
2261
2315
|
ns.setAttribute('data-stx-positioned','');
|
|
2262
2316
|
placeholder.parentNode.replaceChild(ns,placeholder);
|
|
@@ -2614,7 +2668,7 @@ else {
|
|
|
2614
2668
|
}
|
|
2615
2669
|
|
|
2616
2670
|
function updateNav(){
|
|
2617
|
-
|
|
2671
|
+
qsa('nav a[href], #mobileNav a[href], [data-stx-nav] a[href]').forEach(function(a){
|
|
2618
2672
|
if(!a.hasAttribute('data-stx-link'))return;
|
|
2619
2673
|
var st=linkState(a.getAttribute('href'),a.getAttribute('data-stx-active-match'));
|
|
2620
2674
|
if(!st)return;
|
|
@@ -2635,7 +2689,7 @@ else {
|
|
|
2635
2689
|
|
|
2636
2690
|
function updateActiveLinks(){
|
|
2637
2691
|
// Update active classes on <stx-link> elements (and legacy data-stx-link)
|
|
2638
|
-
var links=
|
|
2692
|
+
var links=qsa('[data-stx-link]');
|
|
2639
2693
|
links.forEach(function(link){
|
|
2640
2694
|
var st=linkState(link.getAttribute('to')||link.getAttribute('href')||'',link.getAttribute('data-stx-active-match'));
|
|
2641
2695
|
if(!st)return;
|
|
@@ -2677,7 +2731,7 @@ else {
|
|
|
2677
2731
|
// the cascade, or opt out entirely with viewTransitions:false.
|
|
2678
2732
|
function injectStyles(){
|
|
2679
2733
|
if(!document.getElementById('stx-r-css')){
|
|
2680
|
-
var s=
|
|
2734
|
+
var s=ce('style');s.id='stx-r-css';
|
|
2681
2735
|
// Strip characters that could escape our CSS block and inject new
|
|
2682
2736
|
// declarations: ; { } ( ) " ' \\ < > plus whitespace control chars.
|
|
2683
2737
|
// This keeps the value safe to concat into a stylesheet even if a
|
|
@@ -2699,10 +2753,10 @@ else {
|
|
|
2699
2753
|
css+='@media (prefers-reduced-motion: reduce){::view-transition-old(root),::view-transition-new(root){animation-duration:0s;animation-name:none}}';
|
|
2700
2754
|
}
|
|
2701
2755
|
s.textContent=css;
|
|
2702
|
-
|
|
2756
|
+
dhead().appendChild(s);
|
|
2703
2757
|
}
|
|
2704
2758
|
if(o.progress&&!document.getElementById('stx-router-progress')){
|
|
2705
|
-
var el=
|
|
2759
|
+
var el=ce('div');
|
|
2706
2760
|
el.id='stx-router-progress';
|
|
2707
2761
|
el.setAttribute('role','progressbar');
|
|
2708
2762
|
el.setAttribute('aria-hidden','true');
|
|
@@ -2719,7 +2773,7 @@ else {
|
|
|
2719
2773
|
|
|
2720
2774
|
function injectViewTransitionCSS(){
|
|
2721
2775
|
if(document.getElementById('stx-view-transitions'))return;
|
|
2722
|
-
var s=
|
|
2776
|
+
var s=ce('style');s.id='stx-view-transitions';
|
|
2723
2777
|
s.textContent='::view-transition-group(root){animation:none}::view-transition-old(root){animation:none}::view-transition-new(root){animation:none}main,#app-content,[data-stx-content]{view-transition-name:stx-content}::view-transition-old(stx-content){animation:stx-fade-out .15s ease-out both}::view-transition-new(stx-content){animation:stx-fade-in .15s ease-in .1s both}@keyframes stx-fade-out{from{opacity:1}to{opacity:0}}@keyframes stx-fade-in{from{opacity:0}to{opacity:1}}::view-transition{background:transparent}::view-transition-group(stx-content){background:inherit;overflow:hidden}';
|
|
2724
2778
|
(document.head||document.documentElement).appendChild(s);
|
|
2725
2779
|
}
|
|
@@ -2777,9 +2831,19 @@ else {
|
|
|
2777
2831
|
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',init);else init();
|
|
2778
2832
|
})();
|
|
2779
2833
|
`;
|
|
2780
|
-
|
|
2834
|
+
}
|
|
2835
|
+
function getRouterScript() {
|
|
2836
|
+
if (cachedRouterScript)
|
|
2837
|
+
return cachedRouterScript;
|
|
2838
|
+
cachedRouterScript = minifyRouterScript(stripRouterLogs(routerSource()));
|
|
2781
2839
|
return cachedRouterScript;
|
|
2782
2840
|
}
|
|
2841
|
+
function getRouterScriptDev() {
|
|
2842
|
+
if (cachedRouterScriptDev)
|
|
2843
|
+
return cachedRouterScriptDev;
|
|
2844
|
+
cachedRouterScriptDev = minifyRouterScript(routerSource());
|
|
2845
|
+
return cachedRouterScriptDev;
|
|
2846
|
+
}
|
|
2783
2847
|
export {
|
|
2784
2848
|
setAppUrl,
|
|
2785
2849
|
runMiddleware,
|
|
@@ -2794,6 +2858,7 @@ export {
|
|
|
2794
2858
|
isNonPageRoutePattern,
|
|
2795
2859
|
isNonPageRoutePath,
|
|
2796
2860
|
hasMiddleware,
|
|
2861
|
+
getRouterScriptDev,
|
|
2797
2862
|
getRouterScript,
|
|
2798
2863
|
getMiddlewareNames,
|
|
2799
2864
|
getMiddleware,
|
package/dist/serve.js
CHANGED
|
@@ -9791,7 +9791,7 @@ function __stxOverlay(errs){
|
|
|
9791
9791
|
rebuildDiscoveredPagePaths(kept);
|
|
9792
9792
|
await indexPageMiddleware(kept);
|
|
9793
9793
|
try {
|
|
9794
|
-
const { Router } = await import("./chunk-
|
|
9794
|
+
const { Router } = await import("./chunk-bw4fd40r.js");
|
|
9795
9795
|
const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
|
|
9796
9796
|
const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
|
|
9797
9797
|
if (!options.quiet)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.338",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typecheck": "bun tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@stacksjs/stx": "0.2.
|
|
78
|
-
"stx-router": "0.2.
|
|
77
|
+
"@stacksjs/stx": "0.2.338",
|
|
78
|
+
"stx-router": "0.2.338"
|
|
79
79
|
}
|
|
80
80
|
}
|