bun-plugin-stx 0.2.134 → 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.
Files changed (2) hide show
  1. package/dist/serve.js +16 -3
  2. package/package.json +1 -1
package/dist/serve.js CHANGED
@@ -10181,6 +10181,8 @@ ${html}`;
10181
10181
  const pageLayoutGroup = i18nConfig && i18nLocale ? `i18n:${i18nLocale}` : groupMetaMatch?.[1] || deriveLayoutGroup(pageLayout);
10182
10182
  let fragment = content;
10183
10183
  let containerAttrs = "";
10184
+ let mainContentStart = -1;
10185
+ let mainContentEnd = -1;
10184
10186
  const headStyles = [];
10185
10187
  const headMatch = content.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i);
10186
10188
  if (headMatch) {
@@ -10224,13 +10226,24 @@ ${html}`;
10224
10226
  }
10225
10227
  containerAttrs = mainOpenMatch[0].replace(/^<main\b/i, "").replace(/\/?>$/, "").trim();
10226
10228
  const mainStart = mainOpenMatch.index + mainOpenMatch[0].length;
10229
+ mainContentStart = mainStart;
10230
+ mainContentEnd = mainCloseIdx;
10227
10231
  fragment = fragment.slice(mainStart, mainCloseIdx).trim();
10228
10232
  }
10229
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
+ };
10230
10243
  const routeParamsRe = /<script\b[^>]*data-stx-route-params[^>]*>[\s\S]*?<\/script>/gi;
10231
10244
  let setupMatch;
10232
10245
  while ((setupMatch = routeParamsRe.exec(content)) !== null) {
10233
- pageSetupScripts.push(setupMatch[0]);
10246
+ appendOutsideMainScript(setupMatch);
10234
10247
  }
10235
10248
  const allScriptRe = /<script\b[^>]*data-stx-scoped[^>]*>[\s\S]*?<\/script>/gi;
10236
10249
  while ((setupMatch = allScriptRe.exec(content)) !== null) {
@@ -10239,11 +10252,11 @@ ${html}`;
10239
10252
  continue;
10240
10253
  if (scriptContent.includes("data-stx-reactive") && scriptContent.includes("window.__stx_reactive"))
10241
10254
  continue;
10242
- pageSetupScripts.push(scriptContent);
10255
+ appendOutsideMainScript(setupMatch);
10243
10256
  }
10244
10257
  const bridgeInitRe = /<script\b[^>]*data-stx-reactive[^>]*>(?![\s\S]*window\.__stx_reactive)[\s\S]*?<\/script>/gi;
10245
10258
  while ((setupMatch = bridgeInitRe.exec(content)) !== null) {
10246
- pageSetupScripts.push(setupMatch[0]);
10259
+ appendOutsideMainScript(setupMatch);
10247
10260
  }
10248
10261
  fragment = fragment.replace(/<script data-stx-scoped>\s*;?\(function\(\)\s*\{[\s\S]*?<\/script>/g, "");
10249
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.134",
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",