bun-plugin-stx 0.2.133 → 0.2.134

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.
@@ -1007,6 +1007,7 @@ else {
1007
1007
  var fragScripts=[];
1008
1008
  var fragScriptId=0;
1009
1009
  var fragStyles=[];
1010
+ var fragCrosswindHrefs=[];
1010
1011
  var fragCrosswindCSS=null;
1011
1012
  var cleanFrag=html.replace(new RegExp('<scr'+'ipt\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/scr'+'ipt>','gi'),function(m,attrs,code){
1012
1013
  if(code&&code.trim()&&!isSignalsRuntimeScript({hasAttribute:function(name){return name==='data-stx-runtime'&&attrs.indexOf('data-stx-runtime')!==-1}},code)){
@@ -1029,6 +1030,12 @@ else {
1029
1030
  }
1030
1031
  return '';
1031
1032
  });
1033
+ cleanFrag=cleanFrag.replace(new RegExp('<link\\\\b([^>]*)>','gi'),function(m,attrs){
1034
+ if(attrs.indexOf('data-crosswind')===-1)return m;
1035
+ var hrefMatch=attrs.match(/\\bhref=(["'])(.*?)\\1/i);
1036
+ if(hrefMatch&&hrefMatch[2])fragCrosswindHrefs.push(hrefMatch[2]);
1037
+ return '';
1038
+ });
1032
1039
  // Remove old page styles (not crosswind \u2014 that gets merged)
1033
1040
  document.querySelectorAll('style[data-stx-page]').forEach(function(s){s.remove()});
1034
1041
  // Merge crosswind CSS from fragment into existing crosswind style
@@ -1044,6 +1051,19 @@ else {
1044
1051
  document.head.appendChild(cw);
1045
1052
  }
1046
1053
  }
1054
+ fragCrosswindHrefs.forEach(function(href){
1055
+ var absolute=new URL(href,location.href).href;
1056
+ var exists=false;
1057
+ document.querySelectorAll('head link[data-crosswind][href]').forEach(function(link){
1058
+ if(new URL(link.getAttribute('href'),location.href).href===absolute)exists=true;
1059
+ });
1060
+ if(exists)return;
1061
+ var link=document.createElement('link');
1062
+ link.setAttribute('data-crosswind','generated');
1063
+ link.setAttribute('rel','stylesheet');
1064
+ link.setAttribute('href',href);
1065
+ document.head.appendChild(link);
1066
+ });
1047
1067
  // Add new page styles
1048
1068
  fragStyles.forEach(function(s){
1049
1069
  var el=document.createElement('style');
package/dist/serve.js CHANGED
@@ -9325,7 +9325,7 @@ After installing: bun add bun-plugin-stx`);
9325
9325
  pageMiddlewarePatterns.length = 0;
9326
9326
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9327
9327
  try {
9328
- const { Router } = await import("./chunk-sqrxjkre.js");
9328
+ const { Router } = await import("./chunk-9e56perq.js");
9329
9329
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9330
9330
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9331
9331
  if (!options.quiet)
@@ -9994,6 +9994,21 @@ ${html}`;
9994
9994
  return new Response(null, { headers });
9995
9995
  return new Response(content2, { headers });
9996
9996
  }
9997
+ const crosswindAsset = path.match(/^\/_stx\/crosswind\.([a-f0-9]{16})\.css$/);
9998
+ if (crosswindAsset) {
9999
+ const stx = await stxModule;
10000
+ const content2 = stx.getCrosswindServeAsset(crosswindAsset[1]);
10001
+ if (content2 === undefined)
10002
+ return new Response("Crosswind asset not found", { status: 404 });
10003
+ const headers = {
10004
+ "Content-Type": "text/css; charset=utf-8",
10005
+ "Cache-Control": "public, max-age=31536000, immutable",
10006
+ ...corsHeaders
10007
+ };
10008
+ if (req.method === "HEAD")
10009
+ return new Response(null, { headers });
10010
+ return new Response(content2, { headers });
10011
+ }
9997
10012
  if (options.onRequest) {
9998
10013
  const hookResult = await options.onRequest(req);
9999
10014
  if (hookResult instanceof Response)
@@ -10187,6 +10202,11 @@ ${html}`;
10187
10202
  }
10188
10203
  headStyles.push(styleMatch[0]);
10189
10204
  }
10205
+ const crosswindLinkRe = /<link\b[^>]*\bdata-crosswind=(?:"generated"|'generated')[^>]*>/gi;
10206
+ let crosswindLinkMatch;
10207
+ while ((crosswindLinkMatch = crosswindLinkRe.exec(headContent)) !== null) {
10208
+ headStyles.push(crosswindLinkMatch[0]);
10209
+ }
10190
10210
  }
10191
10211
  const mainOpenMatch = fragment.match(/<main\b[^>]*>/i);
10192
10212
  const mainCloseIdx = fragment.lastIndexOf("</main>");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.133",
4
+ "version": "0.2.134",
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",