@stacksjs/stx 0.2.111 → 0.2.113

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.
@@ -49,8 +49,8 @@ async function tryImportCrosswind(importPath) {
49
49
  } catch {}
50
50
  return null;
51
51
  }
52
- function findCrosswindPaths() {
53
- const paths = [], homeDir = process.env.HOME || process.env.USERPROFILE || "";
52
+ function findProjectCrosswindPaths() {
53
+ const paths = [];
54
54
  let currentDir = process.cwd();
55
55
  while (currentDir !== path.dirname(currentDir)) {
56
56
  paths.push(path.join(currentDir, "node_modules", "@cwcss", "crosswind", "dist", "index.js"));
@@ -61,6 +61,10 @@ function findCrosswindPaths() {
61
61
  paths.push(path.join(currentDir, "pantry", "@stacksjs", "crosswind", "dist", "index.js"));
62
62
  currentDir = path.dirname(currentDir);
63
63
  }
64
+ return paths;
65
+ }
66
+ function findDevCrosswindPaths() {
67
+ const paths = [], homeDir = process.env.HOME || process.env.USERPROFILE || "";
64
68
  if (homeDir) {
65
69
  const devPaths = [
66
70
  path.join(homeDir, "Code", "Tools", "crosswind", "packages", "crosswind", "dist", "index.js"),
@@ -81,6 +85,23 @@ export async function loadCrosswind() {
81
85
  return crosswindModule;
82
86
  crosswindLoadAttempted = !0;
83
87
  try {
88
+ const loadFrom = async (candidates) => {
89
+ for (const candidate of candidates) {
90
+ if (!await Bun.file(candidate).exists())
91
+ continue;
92
+ const result = await tryImportCrosswind(candidate);
93
+ if (result) {
94
+ if (!process.env.STACKS_DEV_QUIET)
95
+ console.log(`${colors.green}[Crosswind]${colors.reset} CSS engine loaded from ${path.dirname(path.dirname(candidate))}`);
96
+ return result;
97
+ }
98
+ }
99
+ return null;
100
+ }, projectModule = await loadFrom(findProjectCrosswindPaths());
101
+ if (projectModule) {
102
+ crosswindModule = projectModule;
103
+ return crosswindModule;
104
+ }
84
105
  const importPaths = [
85
106
  "@cwcss/crosswind",
86
107
  "@cwcss/crosswind/dist/index.js",
@@ -96,17 +117,11 @@ export async function loadCrosswind() {
96
117
  return crosswindModule;
97
118
  }
98
119
  }
99
- const localPaths = findCrosswindPaths();
100
- for (const localPath of localPaths)
101
- if (await Bun.file(localPath).exists()) {
102
- const result = await tryImportCrosswind(localPath);
103
- if (result) {
104
- crosswindModule = result;
105
- if (!process.env.STACKS_DEV_QUIET)
106
- console.log(`${colors.green}[Crosswind]${colors.reset} CSS engine loaded from ${path.dirname(path.dirname(localPath))}`);
107
- return crosswindModule;
108
- }
109
- }
120
+ const devModule = await loadFrom(findDevCrosswindPaths());
121
+ if (devModule) {
122
+ crosswindModule = devModule;
123
+ return crosswindModule;
124
+ }
110
125
  throw Error("Crosswind CSSGenerator not found in any location");
111
126
  } catch {
112
127
  console.warn(`${colors.yellow}[Crosswind] CSS engine not available, Tailwind styles will not be generated${colors.reset}`);
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
  }