@homebound/truss 2.5.0 → 2.5.1

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.
@@ -521,7 +521,7 @@ function getPropertyPriority(property) {
521
521
  }
522
522
  function getPseudoClassPriority(pseudo) {
523
523
  const leadingPseudo = pseudo.trim().match(/^::?[a-zA-Z-]+/)?.[0] ?? pseudo.split("(")[0];
524
- const base = leadingPseudo.replace(/[A-Z]/g, function(match) {
524
+ const base = leadingPseudo.replace(/[A-Z]/g, (match) => {
525
525
  return `-${match.toLowerCase()}`;
526
526
  });
527
527
  return PSEUDO_CLASS_PRIORITIES[base] ?? 40;
@@ -621,7 +621,7 @@ function whenPrefix(whenPseudo) {
621
621
  return `wh_${rel}_${pseudoTag}_${markerPart}`;
622
622
  }
623
623
  function pseudoSelectorTag(pseudo) {
624
- const replaced = pseudo.trim().replace(/::?[a-zA-Z-]+/g, function(match) {
624
+ const replaced = pseudo.trim().replace(/::?[a-zA-Z-]+/g, (match) => {
625
625
  return `_${pseudoIdentifierTag(match)}_`;
626
626
  });
627
627
  const cleaned = replaced.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
@@ -638,7 +638,7 @@ function pseudoIdentifierTag(pseudo) {
638
638
  function normalizePseudoIdentifier(pseudo) {
639
639
  const prefixMatch = pseudo.match(/^::?/);
640
640
  const prefix = prefixMatch?.[0] ?? "";
641
- const name = pseudo.slice(prefix.length).replace(/[A-Z]/g, function(match) {
641
+ const name = pseudo.slice(prefix.length).replace(/[A-Z]/g, (match) => {
642
642
  return `-${match.toLowerCase()}`;
643
643
  });
644
644
  return `${prefix}${name}`;
@@ -813,7 +813,7 @@ function collectVariableRules(rules, seg, mapping) {
813
813
  cssVarName: existingRule.cssVarName
814
814
  }
815
815
  ];
816
- if (!existingRule.declarations.some(function(entry) {
816
+ if (!existingRule.declarations.some((entry) => {
817
817
  return entry.cssProperty === declaration.cssProperty;
818
818
  })) {
819
819
  existingRule.declarations.push(declaration);
@@ -914,13 +914,13 @@ function getRuleDeclarations(rule) {
914
914
  return rule.declarations ?? [{ cssProperty: rule.cssProperty, cssValue: rule.cssValue, cssVarName: rule.cssVarName }];
915
915
  }
916
916
  function formatRuleBlock(selector, rule) {
917
- const body = getRuleDeclarations(rule).map(function(declaration) {
917
+ const body = getRuleDeclarations(rule).map((declaration) => {
918
918
  return `${declaration.cssProperty}: ${declaration.cssValue};`;
919
919
  }).join(" ");
920
920
  return `${selector} { ${body} }`;
921
921
  }
922
922
  function formatNestedRuleBlock(wrapper, selector, rule) {
923
- const body = getRuleDeclarations(rule).map(function(declaration) {
923
+ const body = getRuleDeclarations(rule).map((declaration) => {
924
924
  return `${declaration.cssProperty}: ${declaration.cssValue};`;
925
925
  }).join(" ");
926
926
  return `${wrapper} { ${selector} { ${body} } }`;
@@ -1923,12 +1923,12 @@ function findImportDeclaration(ast, source) {
1923
1923
  function replaceCssImportWithNamedImports(ast, cssBinding, source, imports) {
1924
1924
  for (const node of ast.program.body) {
1925
1925
  if (!t2.isImportDeclaration(node)) continue;
1926
- const cssSpecIndex = node.specifiers.findIndex(function(spec) {
1926
+ const cssSpecIndex = node.specifiers.findIndex((spec) => {
1927
1927
  return t2.isImportSpecifier(spec) && spec.local.name === cssBinding;
1928
1928
  });
1929
1929
  if (cssSpecIndex === -1 || node.specifiers.length !== 1) continue;
1930
1930
  node.source = t2.stringLiteral(source);
1931
- node.specifiers = imports.map(function(entry) {
1931
+ node.specifiers = imports.map((entry) => {
1932
1932
  return t2.importSpecifier(t2.identifier(entry.localName), t2.identifier(entry.importedName));
1933
1933
  });
1934
1934
  return true;
@@ -1940,7 +1940,7 @@ function upsertNamedImports(ast, source, imports) {
1940
1940
  for (const node of ast.program.body) {
1941
1941
  if (!t2.isImportDeclaration(node) || node.source.value !== source) continue;
1942
1942
  for (const entry of imports) {
1943
- const exists = node.specifiers.some(function(spec) {
1943
+ const exists = node.specifiers.some((spec) => {
1944
1944
  return t2.isImportSpecifier(spec) && t2.isIdentifier(spec.imported, { name: entry.importedName });
1945
1945
  });
1946
1946
  if (exists) continue;
@@ -1949,7 +1949,7 @@ function upsertNamedImports(ast, source, imports) {
1949
1949
  return;
1950
1950
  }
1951
1951
  const importDecl = t2.importDeclaration(
1952
- imports.map(function(entry) {
1952
+ imports.map((entry) => {
1953
1953
  return t2.importSpecifier(t2.identifier(entry.localName), t2.identifier(entry.importedName));
1954
1954
  }),
1955
1955
  t2.stringLiteral(source)
@@ -2031,7 +2031,7 @@ function buildStyleHashFromChain(chain, options) {
2031
2031
  const members = [];
2032
2032
  const previousProperties = /* @__PURE__ */ new Map();
2033
2033
  if (chain.markers.length > 0) {
2034
- const markerClasses = chain.markers.map(function(marker) {
2034
+ const markerClasses = chain.markers.map((marker) => {
2035
2035
  return markerClassName(marker.markerNode);
2036
2036
  });
2037
2037
  members.push(t3.objectProperty(t3.identifier("__marker"), t3.stringLiteral(markerClasses.join(" "))));
@@ -2149,7 +2149,7 @@ function collectConditionalOnlyProps(segments) {
2149
2149
  return result;
2150
2150
  }
2151
2151
  function mergeConditionalBranchMembers(members, previousProperties, conditionalOnlyProps) {
2152
- return members.map(function(member) {
2152
+ return members.map((member) => {
2153
2153
  if (!t3.isObjectProperty(member)) {
2154
2154
  return member;
2155
2155
  }
@@ -2200,10 +2200,10 @@ function arrayElementExpression(element) {
2200
2200
  function mergeVarsObject(previousVars, currentVars) {
2201
2201
  if (t3.isObjectExpression(previousVars) && t3.isObjectExpression(currentVars)) {
2202
2202
  return t3.objectExpression([
2203
- ...previousVars.properties.map(function(property) {
2203
+ ...previousVars.properties.map((property) => {
2204
2204
  return t3.cloneNode(property, true);
2205
2205
  }),
2206
- ...currentVars.properties.map(function(property) {
2206
+ ...currentVars.properties.map((property) => {
2207
2207
  return t3.cloneNode(property, true);
2208
2208
  })
2209
2209
  ]);
@@ -2227,7 +2227,7 @@ function clonePropertyKey(key) {
2227
2227
  }
2228
2228
  function injectDebugInfo(expr, line, options) {
2229
2229
  if (!options.debug) return;
2230
- const firstProp = expr.properties.find(function(p) {
2230
+ const firstProp = expr.properties.find((p) => {
2231
2231
  return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
2232
2232
  });
2233
2233
  if (!firstProp) return;
@@ -2481,7 +2481,7 @@ function transformTruss(code, filename, mapping, options = {}) {
2481
2481
  );
2482
2482
  }
2483
2483
  if (declarationsToInsert.length > 0) {
2484
- const insertIndex = ast.program.body.findIndex(function(node) {
2484
+ const insertIndex = ast.program.body.findIndex((node) => {
2485
2485
  return !t4.isImportDeclaration(node);
2486
2486
  });
2487
2487
  ast.program.body.splice(insertIndex === -1 ? ast.program.body.length : insertIndex, 0, ...declarationsToInsert);
@@ -2860,7 +2860,7 @@ function mergeTrussCss(sources) {
2860
2860
  }
2861
2861
  }
2862
2862
  }
2863
- allRules.sort(function(a, b) {
2863
+ allRules.sort((a, b) => {
2864
2864
  const diff = a.priority - b.priority;
2865
2865
  if (diff !== 0) return diff;
2866
2866
  return a.className < b.className ? -1 : a.className > b.className ? 1 : 0;
@@ -2888,7 +2888,7 @@ function trussEsbuildPlugin(opts) {
2888
2888
  name: "truss",
2889
2889
  setup(build) {
2890
2890
  outDir = build.initialOptions.outdir ?? build.initialOptions.outdir;
2891
- build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, function(args) {
2891
+ build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, (args) => {
2892
2892
  const code = readFileSync2(args.path, "utf8");
2893
2893
  if (!code.includes("Css")) return void 0;
2894
2894
  if (!mapping) {
@@ -2905,7 +2905,7 @@ function trussEsbuildPlugin(opts) {
2905
2905
  }
2906
2906
  return { contents: result.code, loader: loaderForPath(args.path) };
2907
2907
  });
2908
- build.onEnd(function() {
2908
+ build.onEnd(() => {
2909
2909
  if (cssRegistry.size === 0) return;
2910
2910
  const css = generateCssText(cssRegistry);
2911
2911
  const cssFileName = opts.outputCss ?? "truss.css";
@@ -2951,7 +2951,7 @@ function trussPlugin(opts) {
2951
2951
  let libraryCache = null;
2952
2952
  function loadLibraries() {
2953
2953
  if (!libraryCache) {
2954
- libraryCache = libraryPaths.map(function(libPath) {
2954
+ libraryCache = libraryPaths.map((libPath) => {
2955
2955
  const resolved = resolve2(projectRoot || process.cwd(), libPath);
2956
2956
  return readTrussCss(resolved);
2957
2957
  });
@@ -2984,20 +2984,20 @@ function trussPlugin(opts) {
2984
2984
  // -- Dev mode HMR --
2985
2985
  configureServer(server) {
2986
2986
  if (isTest) return;
2987
- server.middlewares.use(function(req, res, next) {
2987
+ server.middlewares.use((req, res, next) => {
2988
2988
  if (req.url !== VIRTUAL_CSS_ENDPOINT) return next();
2989
2989
  const css = collectCss();
2990
2990
  res.setHeader("Content-Type", "text/css");
2991
2991
  res.setHeader("Cache-Control", "no-store");
2992
2992
  res.end(css);
2993
2993
  });
2994
- const interval = setInterval(function() {
2994
+ const interval = setInterval(() => {
2995
2995
  if (cssVersion !== lastSentVersion && server.ws) {
2996
2996
  lastSentVersion = cssVersion;
2997
2997
  server.ws.send({ type: "custom", event: "truss:css-update" });
2998
2998
  }
2999
2999
  }, 150);
3000
- server.httpServer?.on("close", function() {
3000
+ server.httpServer?.on("close", () => {
3001
3001
  clearInterval(interval);
3002
3002
  });
3003
3003
  },
@@ -3026,7 +3026,7 @@ function trussPlugin(opts) {
3026
3026
  if (id === RESOLVED_VIRTUAL_RUNTIME_ID) {
3027
3027
  return `
3028
3028
  // Truss dev HMR runtime \u2014 keeps styles up to date without page reload
3029
- (function() {
3029
+ (() => {
3030
3030
  let style = document.getElementById("__truss_virtual__");
3031
3031
  if (!style) {
3032
3032
  style = document.createElement("style");
@@ -3036,16 +3036,16 @@ function trussPlugin(opts) {
3036
3036
 
3037
3037
  function fetchCss() {
3038
3038
  fetch("${VIRTUAL_CSS_ENDPOINT}")
3039
- .then(function(r) { return r.text(); })
3040
- .then(function(css) { style.textContent = css; })
3041
- .catch(function() {});
3039
+ .then((r) => r.text())
3040
+ .then((css) => { style.textContent = css; })
3041
+ .catch(() => {});
3042
3042
  }
3043
3043
 
3044
3044
  fetchCss();
3045
3045
 
3046
3046
  if (import.meta.hot) {
3047
3047
  import.meta.hot.on("truss:css-update", fetchCss);
3048
- import.meta.hot.on("vite:afterUpdate", function() {
3048
+ import.meta.hot.on("vite:afterUpdate", () => {
3049
3049
  setTimeout(fetchCss, 50);
3050
3050
  });
3051
3051
  }
@@ -3121,7 +3121,7 @@ function trussPlugin(opts) {
3121
3121
  const outDir = options.dir || join2(projectRoot, "dist");
3122
3122
  const trussPath = join2(outDir, "truss.css");
3123
3123
  if (!existsSync(trussPath)) {
3124
- const alreadyEmitted = Object.keys(bundle).some(function(key) {
3124
+ const alreadyEmitted = Object.keys(bundle).some((key) => {
3125
3125
  const asset = bundle[key];
3126
3126
  return asset.type === "asset" && key.endsWith(".css") && typeof asset.source === "string" && asset.source.includes(css);
3127
3127
  });