@pairdraw/dom-css 0.16.2 → 0.18.0

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.
@@ -476,8 +476,15 @@ function modeValue(variable, value, modeId, names, variables) {
476
476
  function block(selector, declarations, indent = "") {
477
477
  return `${indent}${selector} {\n${declarations.map(({ name, value }) => `${indent} --${name}: ${value};`).join("\n")}\n${indent}}`;
478
478
  }
479
+ /**
480
+ * A comment naming `text`. Collection and mode names are the person's own text, so a `*` before
481
+ * a `/` in them is spaced apart, which keeps a name from ending the comment and writing rules.
482
+ */
483
+ function cssComment(text) {
484
+ return `/* ${text.replaceAll("*/", "* /")} */`;
485
+ }
479
486
  function modeBlock(scope) {
480
- const comment = `/* ${scope.collection.name}: ${scope.mode.name} */`;
487
+ const comment = cssComment(`${scope.collection.name}: ${scope.mode.name}`);
481
488
  if (!isAtRuleCondition(scope.condition)) return `${comment}\n${block(scope.condition, scope.declarations)}`;
482
489
  return `${comment}\n${scope.condition} {\n${block(":root", scope.declarations, " ")}\n}`;
483
490
  }
@@ -501,6 +508,24 @@ function variantNames(scopes) {
501
508
  * references, and number formulas `calc()` over them; both are declared again in each mode that
502
509
  * changes what they point to.
503
510
  */
511
+ /**
512
+ * A name that took a numeric suffix is an alias nobody can read back from the stylesheet, so it
513
+ * is reported rather than left as a silent second spelling of another token.
514
+ */
515
+ function numberedNameIssues(variables, names, modeOf) {
516
+ const issues = [];
517
+ for (const variable of variables) {
518
+ const name = names.get(variable.id);
519
+ const base = deriveCSSName(variable);
520
+ if (!name || explicitCSSName(variable) || name === base) continue;
521
+ issues.push({
522
+ message: `"${variable.name}" is written --${name}: --${base} is taken`,
523
+ variableId: variable.id,
524
+ modeId: modeOf(variable)
525
+ });
526
+ }
527
+ return issues;
528
+ }
504
529
  function buildTokenStylesheet(source, { format, include = () => true }, validate) {
505
530
  const issues = [];
506
531
  const collections = [...source.variableCollections.values()];
@@ -532,6 +557,7 @@ function buildTokenStylesheet(source, { format, include = () => true }, validate
532
557
  value: css
533
558
  };
534
559
  }
560
+ issues.push(...numberedNameIssues(variables, names, defaultModeOf));
535
561
  const defaults = /* @__PURE__ */ new Map();
536
562
  const theme = [];
537
563
  const root = [];