bun-plugin-stx 0.2.281 → 0.2.283

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.
@@ -890,7 +890,7 @@ function getRouterScript() {
890
890
  return blocks;
891
891
  }
892
892
 
893
- function mergeCrosswindCSS(existing,incoming){
893
+ function mergeCss(existing,incoming){
894
894
  var blocks=extractCssBlocks(incoming);
895
895
  var newBlocks=[];
896
896
  for(var bi=0;bi<blocks.length;bi++){
@@ -1420,8 +1420,8 @@ else {
1420
1420
  var fragScripts=[];
1421
1421
  var fragScriptId=0;
1422
1422
  var fragStyles=[];
1423
- var fragCrosswindHrefs=[];
1424
- var fragCrosswindCSS=null;
1423
+ var fragCssHrefs=[];
1424
+ var fragCss=null;
1425
1425
  var fragExternalScripts=[];
1426
1426
  var cleanFrag=html.replace(new RegExp('<scr'+'ipt\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/scr'+'ipt>','gi'),function(m,attrs,code){
1427
1427
  // A data block is not code, and everything below this line assumes it
@@ -1462,43 +1462,43 @@ else {
1462
1462
  return '';
1463
1463
  });
1464
1464
  cleanFrag=cleanFrag.replace(new RegExp('<sty'+'le\\\\b([^>]*)>([\\\\s\\\\S]*?)<\\\\/sty'+'le>','gi'),function(m,attrs,css){
1465
- if(attrs.indexOf('data-crosswind')!==-1){
1466
- fragCrosswindCSS=css;
1465
+ if(attrs.indexOf('data-css')!==-1){
1466
+ fragCss=css;
1467
1467
  }else{
1468
1468
  fragStyles.push({attrs:attrs,css:css});
1469
1469
  }
1470
1470
  return '';
1471
1471
  });
1472
1472
  cleanFrag=cleanFrag.replace(new RegExp('<link\\\\b([^>]*)>','gi'),function(m,attrs){
1473
- if(attrs.indexOf('data-crosswind')===-1)return m;
1473
+ if(attrs.indexOf('data-css')===-1)return m;
1474
1474
  var hrefMatch=attrs.match(/\\bhref=(["'])(.*?)\\1/i);
1475
- if(hrefMatch&&hrefMatch[2])fragCrosswindHrefs.push(hrefMatch[2]);
1475
+ if(hrefMatch&&hrefMatch[2])fragCssHrefs.push(hrefMatch[2]);
1476
1476
  return '';
1477
1477
  });
1478
- // Remove old page styles (not crosswind \u2014 that gets merged)
1478
+ // Remove old page styles (not css \u2014 that gets merged)
1479
1479
  document.querySelectorAll('style[data-stx-page]').forEach(function(s){s.remove()});
1480
- // Merge crosswind CSS from fragment into existing crosswind style
1481
- if(fragCrosswindCSS){
1482
- var curCrosswind=document.querySelector('head style[data-crosswind]');
1483
- if(curCrosswind){
1484
- var merged=mergeCrosswindCSS(curCrosswind.textContent||'',fragCrosswindCSS);
1485
- if(merged)curCrosswind.textContent=merged;
1480
+ // Merge css CSS from fragment into existing css style
1481
+ if(fragCss){
1482
+ var curCss=document.querySelector('head style[data-css]');
1483
+ if(curCss){
1484
+ var merged=mergeCss(curCss.textContent||'',fragCss);
1485
+ if(merged)curCss.textContent=merged;
1486
1486
  }else{
1487
1487
  var cw=document.createElement('style');
1488
- cw.setAttribute('data-crosswind','generated');
1489
- cw.textContent=fragCrosswindCSS;
1488
+ cw.setAttribute('data-css','generated');
1489
+ cw.textContent=fragCss;
1490
1490
  document.head.appendChild(cw);
1491
1491
  }
1492
1492
  }
1493
- fragCrosswindHrefs.forEach(function(href){
1493
+ fragCssHrefs.forEach(function(href){
1494
1494
  var absolute=new URL(href,location.href).href;
1495
1495
  var exists=false;
1496
- document.querySelectorAll('head link[data-crosswind][href]').forEach(function(link){
1496
+ document.querySelectorAll('head link[data-css][href]').forEach(function(link){
1497
1497
  if(new URL(link.getAttribute('href'),location.href).href===absolute)exists=true;
1498
1498
  });
1499
1499
  if(exists)return;
1500
1500
  var link=document.createElement('link');
1501
- link.setAttribute('data-crosswind','generated');
1501
+ link.setAttribute('data-css','generated');
1502
1502
  link.setAttribute('rel','stylesheet');
1503
1503
  link.setAttribute('href',href);
1504
1504
  document.head.appendChild(link);
@@ -1668,20 +1668,20 @@ else {
1668
1668
  var curStyles=document.querySelectorAll('head style');
1669
1669
  var newStyles=doc.querySelectorAll('head style');
1670
1670
 
1671
- // Merge crosswind styles instead of replacing \u2014 persistent elements
1671
+ // Merge css styles instead of replacing \u2014 persistent elements
1672
1672
  // (nav, footer) outside <main> still need their utility classes
1673
- var curCrosswind=document.querySelector('head style[data-crosswind]');
1674
- var newCrosswind=null;
1675
- newStyles.forEach(function(s){if(s.getAttribute('data-crosswind'))newCrosswind=s});
1673
+ var curCss=document.querySelector('head style[data-css]');
1674
+ var newCss=null;
1675
+ newStyles.forEach(function(s){if(s.getAttribute('data-css'))newCss=s});
1676
1676
 
1677
- if(curCrosswind&&newCrosswind){
1678
- var merged=mergeCrosswindCSS(curCrosswind.textContent||'',newCrosswind.textContent||'');
1679
- if(merged)curCrosswind.textContent=merged;
1677
+ if(curCss&&newCss){
1678
+ var merged=mergeCss(curCss.textContent||'',newCss.textContent||'');
1679
+ if(merged)curCss.textContent=merged;
1680
1680
  }
1681
1681
 
1682
1682
  var incoming=[];
1683
1683
  newStyles.forEach(function(s){
1684
- if(!keepIds[s.id]&&!s.getAttribute('data-crosswind')){
1684
+ if(!keepIds[s.id]&&!s.getAttribute('data-css')){
1685
1685
  var ns=document.createElement('style');
1686
1686
  ns.textContent=s.textContent;
1687
1687
  ns.setAttribute('data-stx-incoming','');
@@ -1690,17 +1690,17 @@ else {
1690
1690
  }
1691
1691
  });
1692
1692
 
1693
- // If no existing crosswind but new page has one, add it
1694
- if(!curCrosswind&&newCrosswind){
1693
+ // If no existing css but new page has one, add it
1694
+ if(!curCss&&newCss){
1695
1695
  var ns=document.createElement('style');
1696
- ns.textContent=newCrosswind.textContent;
1697
- ns.setAttribute('data-crosswind',newCrosswind.getAttribute('data-crosswind'));
1696
+ ns.textContent=newCss.textContent;
1697
+ ns.setAttribute('data-css',newCss.getAttribute('data-css'));
1698
1698
  document.head.appendChild(ns);
1699
1699
  }
1700
1700
 
1701
- // Remove old styles (except persistent ones, crosswind, and incoming)
1701
+ // Remove old styles (except persistent ones, css, and incoming)
1702
1702
  curStyles.forEach(function(s){
1703
- if(!keepIds[s.id]&&!s.hasAttribute('data-stx-incoming')&&!s.hasAttribute('data-crosswind'))s.remove();
1703
+ if(!keepIds[s.id]&&!s.hasAttribute('data-stx-incoming')&&!s.hasAttribute('data-css'))s.remove();
1704
1704
  });
1705
1705
 
1706
1706
  incoming.forEach(function(s){s.removeAttribute('data-stx-incoming')});
package/dist/serve.d.ts CHANGED
@@ -224,7 +224,7 @@ export declare interface ServeOptions {
224
224
  watchDirs?: string[]
225
225
  renderCache?: boolean
226
226
  renderCacheVary?: 'request' | 'source'
227
- crosswindCacheLimit?: number
227
+ cssCacheLimit?: number
228
228
  prewarmRenderCache?: boolean | number
229
229
  publicDir?: string
230
230
  quiet?: boolean
@@ -257,7 +257,7 @@ export declare interface ServeOptions {
257
257
  }
258
258
  }
259
259
  /**
260
- * The slice of Crosswind this server calls, taken from the package's own types
260
+ * The slice of Css this server calls, taken from the package's own types
261
261
  * rather than restated here.
262
262
  *
263
263
  * `CSSGenerator` has to be a constructor type, because it is `new`-ed below.
@@ -267,4 +267,4 @@ export declare interface ServeOptions {
267
267
  * what made this hard to see in the first place (see the deleted
268
268
  * `cwcss-crosswind.d.ts`). `typeof import` cannot drift from the real engine.
269
269
  */
270
- declare type CrosswindEngine = Pick<typeof import('@cwcss/crosswind'), 'CSSGenerator' | 'config'>;
270
+ declare type CssEngine = Pick<typeof import('@stacksjs/ts-css/engine'), 'CSSGenerator' | 'config'>;
package/dist/serve.js CHANGED
@@ -8718,7 +8718,7 @@ var defaultConfigDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "config");
8718
8718
  var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "src/generated");
8719
8719
 
8720
8720
  // src/serve.ts
8721
- import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, FRAGMENT_CACHE_CONTROL, getBuildId, mergeCrosswindConfig, readResponseHeaders, readResponseStatus, SPA_NAV_HEADER, spaNavVaryHeaders, stateDir, stateDirName } from "@stacksjs/stx";
8721
+ import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, FRAGMENT_CACHE_CONTROL, getBuildId, mergeCssConfig, readResponseHeaders, readResponseStatus, SPA_NAV_HEADER, spaNavVaryHeaders, stateDir, stateDirName } from "@stacksjs/stx";
8722
8722
  import { buildCodeFrame, locateFailureLine } from "@stacksjs/stx/build-message";
8723
8723
  import { clearBundleFailures, getBundleFailures } from "@stacksjs/stx/client-script-bundler";
8724
8724
  import { actionRedirectResponse, compressResponse, runPageAction as sharedRunPageAction } from "@stacksjs/stx";
@@ -8805,6 +8805,14 @@ async function runPageMiddleware(options) {
8805
8805
  }
8806
8806
 
8807
8807
  // src/serve.ts
8808
+ var ENGINE_PACKAGE_ENTRIES = [
8809
+ ["@stacksjs", "ts-css", "dist", "engine", "index.js"],
8810
+ ["@stacksjs", "ts-css", "src", "engine", "index.ts"]
8811
+ ];
8812
+ var ENGINE_SPECIFIERS = [
8813
+ "@stacksjs/ts-css/engine",
8814
+ "@stacksjs/ts-css/dist/engine/index.js"
8815
+ ];
8808
8816
  var defaultStxModule = import("@stacksjs/stx");
8809
8817
  var REACTIVE_TEMPLATE_DIRECTIVE_RE = /@for|:for|@if|:if|@else|:else|x-for|x-if|x-else/;
8810
8818
  function extractServerScriptsFromTemplate(content) {
@@ -9224,7 +9232,7 @@ After installing: bun add bun-plugin-stx`);
9224
9232
  const htmlCache = new Map;
9225
9233
  const ENABLE_HTML_CACHE = options.renderCache === true;
9226
9234
  const RENDER_CACHE_VARY = options.renderCacheVary ?? "request";
9227
- const crosswindCssCache = boundedCache(options.crosswindCacheLimit ?? 512);
9235
+ const cssCssCache = boundedCache(options.cssCacheLimit ?? 512);
9228
9236
  const hmrClients = new Set;
9229
9237
  const hmrEncoder = new TextEncoder;
9230
9238
  function broadcastHmr(event) {
@@ -9340,7 +9348,7 @@ function __stxOverlay(errs){
9340
9348
  sourceFiles = null;
9341
9349
  routes.clear();
9342
9350
  htmlCache.clear();
9343
- crosswindCssCache.clear();
9351
+ cssCssCache.clear();
9344
9352
  resolvedStxModule?.clearDevCaches?.();
9345
9353
  resolvedStxModule?.clearStoreCache?.();
9346
9354
  resolvedStxModule?.clearComposableCache?.();
@@ -9677,7 +9685,7 @@ function __stxOverlay(errs){
9677
9685
  pageMiddlewarePatterns.length = 0;
9678
9686
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9679
9687
  try {
9680
- const { Router } = await import("./chunk-cm8d5hgw.js");
9688
+ const { Router } = await import("./chunk-kn8qad4k.js");
9681
9689
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9682
9690
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9683
9691
  if (!options.quiet)
@@ -9718,49 +9726,52 @@ function __stxOverlay(errs){
9718
9726
  }
9719
9727
  return sig;
9720
9728
  }
9721
- let crosswindModule = null;
9722
- let crosswindLoadAttempted = false;
9723
- let crosswindUserConfigPromise = null;
9724
- async function loadCrosswind() {
9725
- if (crosswindLoadAttempted)
9726
- return crosswindModule;
9727
- crosswindLoadAttempted = true;
9729
+ let cssModule = null;
9730
+ let cssLoadAttempted = false;
9731
+ let cssUserConfigPromise = null;
9732
+ async function loadCssEngine() {
9733
+ if (cssLoadAttempted)
9734
+ return cssModule;
9735
+ cssLoadAttempted = true;
9728
9736
  let dir = process19.cwd();
9729
9737
  while (dir !== nodePath.dirname(dir)) {
9730
9738
  for (const store of ["node_modules", "pantry"]) {
9731
- for (const entry of ["dist/index.js", "src/index.ts"]) {
9732
- const candidate = nodePath.join(dir, store, "@cwcss", "crosswind", entry);
9739
+ for (const entry of ENGINE_PACKAGE_ENTRIES) {
9740
+ const candidate = nodePath.join(dir, store, ...entry);
9733
9741
  try {
9734
9742
  if (!await Bun.file(candidate).exists())
9735
9743
  continue;
9736
9744
  const mod = await import(candidate);
9737
9745
  if (mod?.CSSGenerator) {
9738
- crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9739
- return crosswindModule;
9746
+ cssModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9747
+ return cssModule;
9740
9748
  }
9741
9749
  } catch {}
9742
9750
  }
9743
9751
  }
9744
9752
  dir = nodePath.dirname(dir);
9745
9753
  }
9754
+ for (const specifier of ENGINE_SPECIFIERS) {
9755
+ try {
9756
+ const mod = await import(specifier);
9757
+ if (mod?.CSSGenerator) {
9758
+ cssModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9759
+ return cssModule;
9760
+ }
9761
+ } catch {}
9762
+ }
9746
9763
  try {
9747
- const mod = await import("./chunk-h1h4nv6w.js");
9748
- crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9749
- return crosswindModule;
9764
+ const localPath = nodePath.join(process19.env.HOME || "", "Code/Tools/crosswind/packages/toolkit/src/engine/index.ts");
9765
+ const mod = await import(localPath);
9766
+ cssModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9767
+ return cssModule;
9750
9768
  } catch {
9751
- try {
9752
- const localPath = nodePath.join(process19.env.HOME || "", "Code/Tools/crosswind/packages/crosswind/src/index.ts");
9753
- const mod = await import(localPath);
9754
- crosswindModule = { CSSGenerator: mod.CSSGenerator, config: mod.config };
9755
- return crosswindModule;
9756
- } catch {
9757
- return null;
9758
- }
9769
+ return null;
9759
9770
  }
9760
9771
  }
9761
- async function generateCrosswindCSS(htmlContent) {
9772
+ async function generateCss(htmlContent) {
9762
9773
  try {
9763
- const cw = await loadCrosswind();
9774
+ const cw = await loadCssEngine();
9764
9775
  if (!cw)
9765
9776
  return "";
9766
9777
  const classRegex = /class\s*=\s*["']([^"']+)["']/gi;
@@ -9790,23 +9801,23 @@ function __stxOverlay(errs){
9790
9801
  }
9791
9802
  if (classes.size === 0)
9792
9803
  return "";
9793
- if (!crosswindUserConfigPromise) {
9794
- crosswindUserConfigPromise = loadConfig6({
9795
- name: "crosswind",
9804
+ if (!cssUserConfigPromise) {
9805
+ cssUserConfigPromise = loadConfig6({
9806
+ name: "css",
9796
9807
  cwd: process19.cwd(),
9797
9808
  defaultConfig: {},
9798
9809
  checkEnv: false,
9799
9810
  verbose: false
9800
9811
  });
9801
9812
  }
9802
- const userConfig = await crosswindUserConfigPromise;
9803
- const merged = mergeCrosswindConfig(cw.config, userConfig);
9813
+ const userConfig = await cssUserConfigPromise;
9814
+ const merged = mergeCssConfig(cw.config, userConfig);
9804
9815
  const generatorConfig = merged.config;
9805
9816
  const { includePreflight, minify, tokenCSS } = merged;
9806
9817
  for (const cls of merged.safelist)
9807
9818
  classes.add(cls);
9808
9819
  const cacheKey = [...classes].sort().join(" ");
9809
- const cached = crosswindCssCache.read(cacheKey);
9820
+ const cached = cssCssCache.read(cacheKey);
9810
9821
  if (cached !== undefined)
9811
9822
  return cached;
9812
9823
  const generator = new cw.CSSGenerator(generatorConfig);
@@ -9849,9 +9860,9 @@ function __stxOverlay(errs){
9849
9860
  shortcutCSS += `@media (prefers-color-scheme: dark) { .dark .${name} { ${darkDecls.join(" ")} } }
9850
9861
  `;
9851
9862
  }
9852
- return crosswindCssCache.remember(cacheKey, tokenCSS + baseCss + shortcutCSS);
9863
+ return cssCssCache.remember(cacheKey, tokenCSS + baseCss + shortcutCSS);
9853
9864
  } catch (error) {
9854
- console.warn("Failed to generate Crosswind CSS:", error);
9865
+ console.warn("Failed to generate Css CSS:", error);
9855
9866
  return "";
9856
9867
  }
9857
9868
  }
@@ -10434,12 +10445,12 @@ ${block}`;
10434
10445
  }
10435
10446
  });
10436
10447
  }
10437
- const crosswindAsset = path.match(/^\/_stx\/crosswind\.([a-f0-9]{16})\.css$/);
10438
- if (crosswindAsset) {
10448
+ const cssAsset = path.match(/^\/_stx\/css\.([a-f0-9]{16})\.css$/);
10449
+ if (cssAsset) {
10439
10450
  const stx = await stxModule;
10440
- const content2 = stx.getCrosswindServeAsset(crosswindAsset[1]);
10451
+ const content2 = stx.getCssServeAsset(cssAsset[1]);
10441
10452
  if (content2 === undefined)
10442
- return new Response("Crosswind asset not found", { status: 404 });
10453
+ return new Response("Css asset not found", { status: 404 });
10443
10454
  const headers = {
10444
10455
  "Content-Type": "text/css; charset=utf-8",
10445
10456
  "Cache-Control": "public, max-age=31536000, immutable",
@@ -10634,24 +10645,24 @@ ${block}`;
10634
10645
  let styleMatch;
10635
10646
  const styleRe = /<style\b[^>]*>[\s\S]*?<\/style>/gi;
10636
10647
  while ((styleMatch = styleRe.exec(headContent)) !== null) {
10637
- if (styleMatch[0].includes("data-crosswind")) {
10648
+ if (styleMatch[0].includes("data-css")) {
10638
10649
  const cssContent = styleMatch[0].replace(/<style[^>]*>/, "").replace(/<\/style>/, "");
10639
10650
  const hiddenRule = cssContent.indexOf("[hidden]");
10640
10651
  if (hiddenRule !== -1) {
10641
10652
  const afterPreflight = cssContent.indexOf("}", hiddenRule) + 1;
10642
10653
  const utilities = cssContent.slice(afterPreflight).trim();
10643
10654
  if (utilities) {
10644
- headStyles.push(`<style data-crosswind="fragment">${utilities}</style>`);
10655
+ headStyles.push(`<style data-css="fragment">${utilities}</style>`);
10645
10656
  }
10646
10657
  }
10647
10658
  continue;
10648
10659
  }
10649
10660
  headStyles.push(styleMatch[0]);
10650
10661
  }
10651
- const crosswindLinkRe = /<link\b[^>]*\bdata-crosswind=(?:"generated"|'generated')[^>]*>/gi;
10652
- let crosswindLinkMatch;
10653
- while ((crosswindLinkMatch = crosswindLinkRe.exec(headContent)) !== null) {
10654
- headStyles.push(crosswindLinkMatch[0]);
10662
+ const cssLinkRe = /<link\b[^>]*\bdata-css=(?:"generated"|'generated')[^>]*>/gi;
10663
+ let cssLinkMatch;
10664
+ while ((cssLinkMatch = cssLinkRe.exec(headContent)) !== null) {
10665
+ headStyles.push(cssLinkMatch[0]);
10655
10666
  }
10656
10667
  }
10657
10668
  const containerSelector = stxConfig?.router?.container || "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.281",
4
+ "version": "0.2.283",
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",