@stacksjs/stx 0.2.111 → 0.2.112

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.
package/dist/includes.js CHANGED
@@ -189,8 +189,8 @@ ${scriptContent}
189
189
  ${tail}})();
190
190
  `;
191
191
  }
192
- function transformSignalScript(scriptContent, scopeId) {
193
- const tail = `
192
+ function buildScopeRegistrationTail(scriptContent, scopeId) {
193
+ return `
194
194
  // Register scope variables for STX runtime
195
195
  if (!window.stx._scopes) window.stx._scopes = {};
196
196
  var __scopeRegistration = { __destroyCallbacks: __destroyHooks };
@@ -202,7 +202,10 @@ ${extractExports(scriptContent).split(",").map((s) => s.trim()).filter(Boolean).
202
202
  // shadowing import. __stxScopeRenames is emitted by bundleClientScript.
203
203
  try { if (typeof __stxScopeRenames !== 'undefined' && __stxScopeRenames) { for (var __stxRK in __stxScopeRenames) __scopeRegistration[__stxRK] = __stxScopeRenames[__stxRK]; } } catch (e) { /* no renames */ }
204
204
  window.stx._scopes['${scopeId}'] = __scopeRegistration;
205
- `, head = `
205
+ `;
206
+ }
207
+ function transformSignalScript(scriptContent, scopeId) {
208
+ const tail = buildScopeRegistrationTail(scriptContent, scopeId), head = `
206
209
  (function() {
207
210
  var __stxScopeEl = (typeof document !== 'undefined') ? document.querySelector('[data-stx-scope="${scopeId}"]') : null;
208
211
  var __stxPrevEl = (typeof window !== 'undefined') ? window.__STX_CURRENT_ELEMENT__ : undefined;
@@ -604,10 +607,7 @@ export async function processIncludes(template, context, filePath, options, depe
604
607
  if (!isServerScript && !isSignalScript) {
605
608
  const extraAttrs = scriptAttrs.replace(/\bclient\b/i, "").trim();
606
609
  signalScopeId = `stx_scope_${path.basename(includeFilePath, ".stx").replace(/[^a-zA-Z0-9]/g, "_")}_${++scopeIdCounter}`;
607
- const resolvedContent = transformStoreImports(scriptContent), tail = `
608
- if (!window.stx._scopes) window.stx._scopes = {};
609
- window.stx._scopes['${signalScopeId}'] = { __destroyCallbacks: __destroyHooks };
610
- `, wrapped = wrapClientScript(resolvedContent, tail);
610
+ const resolvedContent = transformStoreImports(scriptContent), tail = buildScopeRegistrationTail(resolvedContent, signalScopeId), wrapped = wrapClientScript(resolvedContent, tail);
611
611
  preservedScript += `${vendorStyleTags}<script data-stx-scoped${extraAttrs ? ` ${extraAttrs}` : ""}>${wrapped}</script>
612
612
  `;
613
613
  }