bun-plugin-stx 0.2.133 → 0.2.135

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)
@@ -10166,6 +10181,8 @@ ${html}`;
10166
10181
  const pageLayoutGroup = i18nConfig && i18nLocale ? `i18n:${i18nLocale}` : groupMetaMatch?.[1] || deriveLayoutGroup(pageLayout);
10167
10182
  let fragment = content;
10168
10183
  let containerAttrs = "";
10184
+ let mainContentStart = -1;
10185
+ let mainContentEnd = -1;
10169
10186
  const headStyles = [];
10170
10187
  const headMatch = content.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i);
10171
10188
  if (headMatch) {
@@ -10187,6 +10204,11 @@ ${html}`;
10187
10204
  }
10188
10205
  headStyles.push(styleMatch[0]);
10189
10206
  }
10207
+ const crosswindLinkRe = /<link\b[^>]*\bdata-crosswind=(?:"generated"|'generated')[^>]*>/gi;
10208
+ let crosswindLinkMatch;
10209
+ while ((crosswindLinkMatch = crosswindLinkRe.exec(headContent)) !== null) {
10210
+ headStyles.push(crosswindLinkMatch[0]);
10211
+ }
10190
10212
  }
10191
10213
  const mainOpenMatch = fragment.match(/<main\b[^>]*>/i);
10192
10214
  const mainCloseIdx = fragment.lastIndexOf("</main>");
@@ -10204,13 +10226,24 @@ ${html}`;
10204
10226
  }
10205
10227
  containerAttrs = mainOpenMatch[0].replace(/^<main\b/i, "").replace(/\/?>$/, "").trim();
10206
10228
  const mainStart = mainOpenMatch.index + mainOpenMatch[0].length;
10229
+ mainContentStart = mainStart;
10230
+ mainContentEnd = mainCloseIdx;
10207
10231
  fragment = fragment.slice(mainStart, mainCloseIdx).trim();
10208
10232
  }
10209
10233
  const pageSetupScripts = [];
10234
+ const pageSetupScriptOffsets = new Set;
10235
+ const appendOutsideMainScript = (match) => {
10236
+ const offset = match.index;
10237
+ const insideMain = mainContentStart !== -1 && offset >= mainContentStart && offset < mainContentEnd;
10238
+ if (insideMain || pageSetupScriptOffsets.has(offset))
10239
+ return;
10240
+ pageSetupScriptOffsets.add(offset);
10241
+ pageSetupScripts.push(match[0]);
10242
+ };
10210
10243
  const routeParamsRe = /<script\b[^>]*data-stx-route-params[^>]*>[\s\S]*?<\/script>/gi;
10211
10244
  let setupMatch;
10212
10245
  while ((setupMatch = routeParamsRe.exec(content)) !== null) {
10213
- pageSetupScripts.push(setupMatch[0]);
10246
+ appendOutsideMainScript(setupMatch);
10214
10247
  }
10215
10248
  const allScriptRe = /<script\b[^>]*data-stx-scoped[^>]*>[\s\S]*?<\/script>/gi;
10216
10249
  while ((setupMatch = allScriptRe.exec(content)) !== null) {
@@ -10219,11 +10252,11 @@ ${html}`;
10219
10252
  continue;
10220
10253
  if (scriptContent.includes("data-stx-reactive") && scriptContent.includes("window.__stx_reactive"))
10221
10254
  continue;
10222
- pageSetupScripts.push(scriptContent);
10255
+ appendOutsideMainScript(setupMatch);
10223
10256
  }
10224
10257
  const bridgeInitRe = /<script\b[^>]*data-stx-reactive[^>]*>(?![\s\S]*window\.__stx_reactive)[\s\S]*?<\/script>/gi;
10225
10258
  while ((setupMatch = bridgeInitRe.exec(content)) !== null) {
10226
- pageSetupScripts.push(setupMatch[0]);
10259
+ appendOutsideMainScript(setupMatch);
10227
10260
  }
10228
10261
  fragment = fragment.replace(/<script data-stx-scoped>\s*;?\(function\(\)\s*\{[\s\S]*?<\/script>/g, "");
10229
10262
  const clearStale = "<script data-stx-page>if(window.stx)window.stx._latestSetup=null;</script>";
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.135",
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",