bun-plugin-stx 0.2.331 → 0.2.333

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.
@@ -988,6 +988,15 @@ function getRouterScript() {
988
988
  function isModuleRegistryScript(s){
989
989
  return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-modules'))||REGISTRY_TEXT.test(s.textContent||''));
990
990
  }
991
+ // The page's composables (resources/functions and friends), published as
992
+ // globals its templates call. Each page ships the ones it reaches, so the
993
+ // next page can need one the first never loaded: it runs right after the
994
+ // registry, before anything that calls into it. Guarded per bundle, so a
995
+ // repeat is a no-op.
996
+ var COMPOSABLES_TEXT=/__stxComposableBundles/;
997
+ function isComposablesScript(s){
998
+ return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-composables'))||COMPOSABLES_TEXT.test(s.textContent||''));
999
+ }
991
1000
  function runsAlways(declared, code){
992
1001
  if(declared==='always')return true;
993
1002
  if(declared==='once')return false;
@@ -1642,7 +1651,8 @@ else {
1642
1651
  var runDecl=(attrs.match(/data-stx-run\\s*=\\s*["']?(always|once)["']?/i)||[])[1];
1643
1652
  var ownerDecl=(attrs.match(/data-stx-owner\\s*=\\s*["']([^"']+)["']/i)||[])[1]||'';
1644
1653
  var registry=/(?:^|\\s)data-stx-modules(?:\\s|=|$)/i.test(attrs)||REGISTRY_TEXT.test(code);
1645
- fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():'',owner:ownerDecl,registry:registry});
1654
+ var composables=/(?:^|\\s)data-stx-composables(?:\\s|=|$)/i.test(attrs)||COMPOSABLES_TEXT.test(code);
1655
+ fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():'',owner:ownerDecl,registry:registry,composables:composables});
1646
1656
  // Retain scoped setup code in its inert placeholder. A placeholder
1647
1657
  // inside template.content is unreachable through document, so the
1648
1658
  // repeated component runtime must execute it for each clone.
@@ -1653,6 +1663,16 @@ else {
1653
1663
  }
1654
1664
  return '';
1655
1665
  });
1666
+ // A <style> inside a script is a string the script owns \u2014 a web
1667
+ // component's shadow-DOM CSS, typically \u2014 not a page style. Lifted into
1668
+ // <head> it restyles the whole document (its bare button rule shrank
1669
+ // every button on the page) and the component loses it. Hold scripts
1670
+ // aside while the fragment's own styles are collected.
1671
+ var heldScripts=[];
1672
+ cleanFrag=cleanFrag.replace(new RegExp('<scr'+'ipt\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/scr'+'ipt>','gi'),function(m){
1673
+ heldScripts.push(m);
1674
+ return '<!--stx-held-script-'+(heldScripts.length-1)+'-->';
1675
+ });
1656
1676
  cleanFrag=cleanFrag.replace(new RegExp('<sty'+'le\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/sty'+'le>','gi'),function(m,attrs,css){
1657
1677
  if(attrs.indexOf('data-css')!==-1){
1658
1678
  fragCss=css;
@@ -1667,6 +1687,7 @@ else {
1667
1687
  if(hrefMatch&&hrefMatch[2])fragCssHrefs.push(hrefMatch[2]);
1668
1688
  return '';
1669
1689
  });
1690
+ cleanFrag=cleanFrag.replace(new RegExp('<!--stx-held-script-(\\\\d+)-->','g'),function(m,i){return heldScripts[Number(i)]});
1670
1691
  // Remove old page styles (not css \u2014 that gets merged)
1671
1692
  document.querySelectorAll('style[data-stx-page]').forEach(function(s){s.remove()});
1672
1693
  // Merge css CSS from fragment into existing css style
@@ -1718,7 +1739,7 @@ else {
1718
1739
  // after the content it serves: a component that imports a package ran
1719
1740
  // ahead of it and threw "is not registered on this page". The full
1720
1741
  // document path orders them the same way (registryFirst, below).
1721
- function fragOrder(entry){return entry.registry?0:entry.setupName?2:1}
1742
+ function fragOrder(entry){return entry.registry?0:entry.composables?1:entry.setupName?3:2}
1722
1743
  fragScripts.sort(function(a,b){return fragOrder(a)-fragOrder(b)});
1723
1744
  function runFragScripts(){
1724
1745
  fragScripts.forEach(function(entry){
@@ -1998,7 +2019,7 @@ else {
1998
2019
  var slot='document-'+(++routedBodyScriptId);
1999
2020
  var setupName=generatedSetupName(text);
2000
2021
  if(setupName)incomingSetupName=setupName;
2001
- routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||'',registry:isModuleRegistryScript(s)});
2022
+ routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||'',registry:isModuleRegistryScript(s),composables:isComposablesScript(s)});
2002
2023
  s.textContent='';
2003
2024
  s.setAttribute('type','application/stx-pending');
2004
2025
  s.setAttribute('data-stx-route-script',slot);
@@ -2080,7 +2101,7 @@ else {
2080
2101
 
2081
2102
  var scripts=routedBodyScripts.slice();
2082
2103
  function addScript(text, runAlways, slot, owner){
2083
- scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text)});
2104
+ scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text),composables:COMPOSABLES_TEXT.test(text)});
2084
2105
  }
2085
2106
  if(isLayoutChange){
2086
2107
  // Also collect setup functions from <head>, and the page's module
@@ -2096,7 +2117,7 @@ else {
2096
2117
  if(s.hasAttribute('src'))return;
2097
2118
  if(!text.trim())return;
2098
2119
  if(isSignalsRuntimeScript(s,text))return;
2099
- if(isModuleRegistryScript(s))addScript(text,true,'','');
2120
+ if(isModuleRegistryScript(s)||isComposablesScript(s))addScript(text,true,'','');
2100
2121
  else if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
2101
2122
  });
2102
2123
  } else {
@@ -2150,7 +2171,8 @@ else {
2150
2171
  // so without this a component in the page body could run ahead of the
2151
2172
  // registry it imports from. Stable: the order within each group holds.
2152
2173
  var registryFirst=scripts.filter(function(e){return e.registry});
2153
- if(registryFirst.length)scripts=registryFirst.concat(scripts.filter(function(e){return !e.registry}));
2174
+ var composablesNext=scripts.filter(function(e){return !e.registry&&e.composables});
2175
+ if(registryFirst.length||composablesNext.length)scripts=registryFirst.concat(composablesNext,scripts.filter(function(e){return !e.registry&&!e.composables}));
2154
2176
 
2155
2177
  // Push history state (before active link updates so location.pathname is current)
2156
2178
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
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-0p4k422w.js");
9794
+ const { Router } = await import("./chunk-pg39gv16.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.331",
4
+ "version": "0.2.333",
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.331",
78
- "stx-router": "0.2.331"
77
+ "@stacksjs/stx": "0.2.333",
78
+ "stx-router": "0.2.333"
79
79
  }
80
80
  }