@yahoo/uds-create-config 5.94.5 → 5.95.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.
@@ -30,6 +30,22 @@ interface ConfigLintFindingBody {
30
30
  /** Where {@link suggestion} is written, when it isn't the finding's own place: a low-contrast fix
31
31
  * that changes the background rather than the text. */
32
32
  readonly target?: FindingPlace;
33
+ /** What's wrong, without the fixes {@link message} ends with, for a surface that lists them. */
34
+ readonly issue?: string;
35
+ /** Writing {@link suggestion}, as an instruction. */
36
+ readonly fixLabel?: string;
37
+ /** The other fix: the token the value names takes the suggestion as its own value, so every use of
38
+ * the token changes with it. */
39
+ readonly retarget?: LintRetarget;
40
+ }
41
+ /** A token's value repointed at another token, as a fix a finding offers. */
42
+ interface LintRetarget {
43
+ /** The token to change, by path. */
44
+ readonly token: string;
45
+ /** The token it points at instead, by path. */
46
+ readonly to: string;
47
+ /** The change, as an instruction. */
48
+ readonly label: string;
33
49
  }
34
50
  interface ConfigLintFinding extends ConfigLintFindingBody {
35
51
  readonly rule: ConfigReadLintRule;
@@ -50,6 +66,9 @@ interface LintReport {
50
66
  readonly suggestion?: string;
51
67
  /** Where the suggestion is written, when it isn't {@link at}. */
52
68
  readonly fixAt?: LintValue;
69
+ readonly issue?: string;
70
+ readonly fixLabel?: string;
71
+ readonly retarget?: LintRetarget;
53
72
  }
54
73
  /** What a check calls with each finding. */
55
74
  type ConfigLintReport = (finding: LintReport) => void;
@@ -245,8 +264,6 @@ interface LintValue {
245
264
  interface LintLayer {
246
265
  readonly component: LintedComponent;
247
266
  readonly cell: Readonly<Record<string, unknown>>;
248
- /** The cell as a person names it: `size=sm, variant=primary`. */
249
- readonly where: string;
250
267
  readonly name: string;
251
268
  /** Whether the layer is the root of something you press. */
252
269
  readonly pressable: boolean;
@@ -260,4 +277,4 @@ interface LintLayer {
260
277
  readonly width: LintValue | undefined;
261
278
  }
262
279
  //#endregion
263
- export { ConfigLintContext, ConfigLintFinding, ConfigLintOptions, ConfigLintReport, LintIgnore, LintLayer, LintValue, LintedComponent, ignoredBy };
280
+ export { ConfigLintContext, ConfigLintFinding, ConfigLintOptions, ConfigLintReport, LintIgnore, LintLayer, LintRetarget, LintValue, LintedComponent, ignoredBy };
@@ -232,7 +232,6 @@ function cellsOf(json, cap = 120) {
232
232
  }
233
233
  return cells;
234
234
  }
235
- const cellLabel = (cell, json) => Object.entries(json.props ?? {}).filter(([, prop]) => prop?.type === "variant").map(([name]) => `${name}=${String(cell[name])}`).join(", ");
236
235
  /** A scale step's name: a number (`3`, `0.5`, `3/5`) or a size (`md`, `2xl`). */
237
236
  const SCALE_STEP = new RegExp(`^(\\d+(\\.\\d+)?(/\\d+)?|${[
238
237
  "3xs",
@@ -557,7 +556,6 @@ function configLintContext({ config, rules, own: isOwn }) {
557
556
  if (found) return found;
558
557
  }
559
558
  };
560
- const where = cellLabel(cell, json);
561
559
  for (const name of names) {
562
560
  const ownText = once(() => at(name, ink));
563
561
  const ownFill = once(() => at(name, fill));
@@ -566,7 +564,6 @@ function configLintContext({ config, rules, own: isOwn }) {
566
564
  yield {
567
565
  component,
568
566
  cell,
569
- where,
570
567
  name,
571
568
  pressable: name === root && pressed,
572
569
  graphic: graphics.get(name) ?? false,
@@ -1,7 +1,7 @@
1
1
  import { ConfigEdit } from "../framework/config-op.js";
2
2
  import { Config } from "../framework/Config.js";
3
3
  import { AuthoringLintGroup, AuthoringLintRule, AuthoringLintSeverity } from "./rules.js";
4
- import { ConfigLintFinding, LintIgnore } from "./context.js";
4
+ import { ConfigLintFinding, LintIgnore, LintRetarget } from "./context.js";
5
5
 
6
6
  //#region src/lint/edits.d.ts
7
7
  /** Where a finding is, as the config stores it, and the value it suggests. */
@@ -75,5 +75,7 @@ declare const hasFix: (site: LintFixSite) => boolean;
75
75
  * fixes on the same rule and layer write together rather than the second replacing the first.
76
76
  */
77
77
  declare function fixEdits(sites: readonly LintFixSite[]): ConfigEdit[];
78
+ /** The edit that repoints a finding's token at its fix, the other choice a finding can offer. */
79
+ declare function retargetEdits(retarget: LintRetarget): ConfigEdit[];
78
80
  //#endregion
79
- export { LintFixSite, fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, rulesOf, severityEdits };
81
+ export { LintFixSite, fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, retargetEdits, rulesOf, severityEdits };
@@ -1,5 +1,6 @@
1
1
  import { Settings } from "../entities/system/Settings.js";
2
2
  import { styleSetEdits } from "../entities/system/component-style-set.js";
3
+ import { Token } from "../entities/system/Token.js";
3
4
  import "../index.js";
4
5
  import { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, flatLintSeverities, nestLintSeverities, ruleSeverity } from "./rules.js";
5
6
  //#region src/lint/edits.ts
@@ -86,7 +87,7 @@ const WRITES_SUGGESTION = new Set([
86
87
  /** The style change a finding's suggestion makes, when it has one answer and is this system's. */
87
88
  function changeOf(site) {
88
89
  const { component, suggestion } = site;
89
- if (site.source || !WRITES_SUGGESTION.has(site.rule)) return void 0;
90
+ if (!WRITES_SUGGESTION.has(site.rule)) return void 0;
90
91
  const at = site.target ?? site;
91
92
  if (!component || !at.layer || !at.prop || suggestion === void 0) return;
92
93
  return {
@@ -119,5 +120,14 @@ function fixEdits(sites) {
119
120
  isInteraction: () => false
120
121
  }));
121
122
  }
123
+ /** The edit that repoints a finding's token at its fix, the other choice a finding can offer. */
124
+ function retargetEdits(retarget) {
125
+ return [{
126
+ kind: "token",
127
+ operation: "update",
128
+ path: retarget.token,
129
+ data: { value: Token.ref(retarget.to) }
130
+ }];
131
+ }
122
132
  //#endregion
123
- export { fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, rulesOf, severityEdits };
133
+ export { fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, retargetEdits, rulesOf, severityEdits };
@@ -1,5 +1,5 @@
1
1
  import { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, AuthoringLintFix, AuthoringLintGroup, AuthoringLintRule, AuthoringLintRuleSettings, AuthoringLintSeverity, CONFIG_LINT_RULES, ConfigLintCheck, ConfigReadLintRule, LintReads, LintRuleSettingNote, flatLintSeverities, lintReads, lintRuleSettingNotes, nestLintSeverities, ruleSeverity } from "./rules.js";
2
2
  import { ConfigLintFinding, ConfigLintOptions, LintIgnore, ignoredBy } from "./context.js";
3
- import { LintFixSite, fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, rulesOf, severityEdits } from "./edits.js";
3
+ import { LintFixSite, fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, retargetEdits, rulesOf, severityEdits } from "./edits.js";
4
4
  import { AuthoringLintEdit, AuthoringLintFinding, AuthoringLintResult, LintIgnoreProblem, LintRun, LintSources, lint, lintConfig } from "./lint.js";
5
- export { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, AuthoringLintEdit, AuthoringLintFinding, AuthoringLintFix, AuthoringLintGroup, AuthoringLintResult, AuthoringLintRule, AuthoringLintRuleSettings, AuthoringLintSeverity, CONFIG_LINT_RULES, ConfigLintCheck, type ConfigLintFinding, type ConfigLintOptions, ConfigReadLintRule, LintFixSite, type LintIgnore, LintIgnoreProblem, LintReads, LintRuleSettingNote, LintRun, LintSources, fixEdits, flatLintSeverities, groupSeverity, hasFix, ignoreEdits, ignoreEntry, ignoredBy, lint, lintConfig, lintIgnores, lintReads, lintRuleSettingNotes, lintSeverities, nestLintSeverities, restoreEdits, ruleSeverity, rulesOf, severityEdits };
5
+ export { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, AuthoringLintEdit, AuthoringLintFinding, AuthoringLintFix, AuthoringLintGroup, AuthoringLintResult, AuthoringLintRule, AuthoringLintRuleSettings, AuthoringLintSeverity, CONFIG_LINT_RULES, ConfigLintCheck, type ConfigLintFinding, type ConfigLintOptions, ConfigReadLintRule, LintFixSite, type LintIgnore, LintIgnoreProblem, LintReads, LintRuleSettingNote, LintRun, LintSources, fixEdits, flatLintSeverities, groupSeverity, hasFix, ignoreEdits, ignoreEntry, ignoredBy, lint, lintConfig, lintIgnores, lintReads, lintRuleSettingNotes, lintSeverities, nestLintSeverities, restoreEdits, retargetEdits, ruleSeverity, rulesOf, severityEdits };
@@ -1,5 +1,5 @@
1
1
  import { ignoredBy } from "./context.js";
2
2
  import { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, CONFIG_LINT_RULES, flatLintSeverities, lintReads, lintRuleSettingNotes, nestLintSeverities, ruleSeverity } from "./rules.js";
3
- import { fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, rulesOf, severityEdits } from "./edits.js";
3
+ import { fixEdits, groupSeverity, hasFix, ignoreEdits, ignoreEntry, lintIgnores, lintSeverities, restoreEdits, retargetEdits, rulesOf, severityEdits } from "./edits.js";
4
4
  import { lint, lintConfig } from "./lint.js";
5
- export { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, CONFIG_LINT_RULES, fixEdits, flatLintSeverities, groupSeverity, hasFix, ignoreEdits, ignoreEntry, ignoredBy, lint, lintConfig, lintIgnores, lintReads, lintRuleSettingNotes, lintSeverities, nestLintSeverities, restoreEdits, ruleSeverity, rulesOf, severityEdits };
5
+ export { AUTHORING_LINT_GROUPS, AUTHORING_LINT_RULES, CONFIG_LINT_RULES, fixEdits, flatLintSeverities, groupSeverity, hasFix, ignoreEdits, ignoreEntry, ignoredBy, lint, lintConfig, lintIgnores, lintReads, lintRuleSettingNotes, lintSeverities, nestLintSeverities, restoreEdits, retargetEdits, ruleSeverity, rulesOf, severityEdits };
@@ -1,6 +1,7 @@
1
1
  import { isRef } from "../framework/utils/refs.js";
2
2
  import { resolveTokenValueUnder, stylePropEntries } from "../framework/projections.js";
3
- import { contrastRatio } from "../framework/utils/color.js";
3
+ import { Token } from "../entities/system/Token.js";
4
+ import { contrastRatio, luminance } from "../framework/utils/color.js";
4
5
  import { parseCssLength } from "../framework/utils/css-length.js";
5
6
  import "../index.js";
6
7
  import { MIN_CONTRAST, SCALE_STEP, TRANSPARENT, written } from "./context.js";
@@ -388,7 +389,7 @@ function literalMatchesToken(ctx, value, report) {
388
389
  if (!match) return;
389
390
  report({
390
391
  at: value,
391
- message: `\`${value.bracketed}\` is what ${value.site.prop}'s \`${match.name}\` holds. Use the token, so a change to it reaches this layer.`,
392
+ message: `Matches a token. Use \`${match.name}\`, so a change to it reaches this layer.`,
392
393
  suggestion: match.name
393
394
  });
394
395
  }
@@ -406,7 +407,7 @@ function numberInBrackets(ctx, value, report) {
406
407
  const bare = bracketed.trim().replace(/px$/, "");
407
408
  report({
408
409
  at: value,
409
- message: `\`${site.prop}\` takes a number in ${reads === "px" ? "px" : "as it is"}: write \`${bare}\`.`,
410
+ message: `Write \`${bare}\` without the brackets. ${site.prop} takes a plain number${reads === "px" ? " in px" : ""}.`,
410
411
  suggestion: bare
411
412
  });
412
413
  }
@@ -425,7 +426,7 @@ function nearToken(ctx, value, report) {
425
426
  if (!nearest || nearest.off <= 0 || nearest.off > Math.max(1, nearest.px * .05) || tokens.some((one) => one.px === px)) return;
426
427
  report({
427
428
  at: value,
428
- message: `\`${written(site.value)}\` is ${Math.round(nearest.off * 100) / 100}px off ${site.prop}'s \`${nearest.name}\` (${nearest.literal}${/rem$/.test(nearest.literal) ? `, ${nearest.px}px at a 16px root` : ""}).`,
429
+ message: `\`${written(site.value)}\` is ${Math.round(nearest.off * 100) / 100}px off ${site.prop}'s \`${nearest.name}\` (${nearest.literal}${/rem$/.test(nearest.literal) ? `, ${nearest.px}px at a 16px root` : ""}). Use \`${nearest.name}\`.`,
429
430
  suggestion: nearest.name
430
431
  });
431
432
  }
@@ -453,7 +454,7 @@ function fixedInDarkMode(ctx, component, report) {
453
454
  if (!color || color[3] === 0) continue;
454
455
  report({
455
456
  at: value,
456
- message: value.token ? `\`${value.token}\` is ${literal} in ${dark} mode too, while ${changing.length} of this component's colors change.` : `\`${written(site.value)}\` is written as a color, so it stays ${literal} in ${dark} mode while ${changing.length} of this component's colors change.`
457
+ message: value.token ? `\`${value.token}\` stays ${literal} in ${dark} mode, while ${changing.length} other colors here change. Use a token with a ${dark} value.` : `Stays ${literal} in ${dark} mode, while ${changing.length} other colors here change. Use a token with a ${dark} value.`
457
458
  });
458
459
  }
459
460
  }
@@ -484,12 +485,23 @@ function lowContrast(ctx, layer, report) {
484
485
  change: "text",
485
486
  ...contrast
486
487
  });
487
- let advice = "";
488
- if (backdrop) advice = ` \`${backdrop.token}\` is the closest background that clears it in every mode.`;
489
- else if (recolor) advice = ` \`${recolor.token}\` is the closest text color that clears it in every mode.`;
488
+ const issue = `Fails ${minimum === 4.5 ? "text" : "icon"} contrast in ${mode.label} mode (${(Math.floor(ratio * 100) / 100).toFixed(2)}:1, needs ${minimum}:1).`;
489
+ let fixLabel;
490
+ if (backdrop) fixLabel = `Use \`${backdrop.token}\` for the background.`;
491
+ else if (recolor) fixLabel = `Use \`${recolor.token}\`.`;
492
+ else if (luminance(fg) > luminance(bg)) fixLabel = "Use a darker background or lighter text.";
493
+ else fixLabel = "Use a lighter background or darker text.";
494
+ const retarget = retargetOf({
495
+ ctx,
496
+ value: backdrop ? background : text,
497
+ to: (backdrop ?? recolor)?.token
498
+ });
490
499
  report({
491
500
  at: text,
492
- message: `\`${written(text.site.value)}\` on \`${written(background.site.value)}\` is ${(Math.floor(ratio * 100) / 100).toFixed(2)}:1 in ${mode.label} mode${layer.where ? ` (${layer.where})` : ""}; ${minimum === 4.5 ? "text" : "an icon"} needs ${minimum}:1.${advice}`,
501
+ message: `${issue} ${retarget ? `${fixLabel.slice(0, -1)}, or ${retarget.label.charAt(0).toLowerCase()}${retarget.label.slice(1)}` : fixLabel}`,
502
+ issue,
503
+ fixLabel,
504
+ ...retarget ? { retarget } : {},
493
505
  ...backdrop ? {
494
506
  suggestion: backdrop.name,
495
507
  fixAt: background
@@ -499,16 +511,32 @@ function lowContrast(ctx, layer, report) {
499
511
  return;
500
512
  }
501
513
  }
514
+ /**
515
+ * The token a fixed value names, repointed at the fix: offered when the value names a token whose own
516
+ * value is another token (`positive` → `spectrum/green/9`), so changing it is a choice about the
517
+ * system rather than about one palette step every other token reads.
518
+ */
519
+ function retargetOf({ ctx, value, to }) {
520
+ const token = value.token;
521
+ if (!token || !to || token === to) return void 0;
522
+ const stored = Token.get(ctx.config, token)?.value;
523
+ if (!isRef(stored)) return void 0;
524
+ return {
525
+ token,
526
+ to,
527
+ label: `Update \`${written(value.site.value)}\` to \`${to}\`.`
528
+ };
529
+ }
502
530
  /** small-tap-target: the root of something you press, under the platform's minimum. */
503
531
  function smallTapTarget(ctx, layer, report) {
504
532
  if (!layer.pressable) return;
505
533
  const { minTarget, unit } = ctx.platform;
506
- for (const [value, reads] of [[layer.height, "tall"], [layer.width, "wide"]]) {
534
+ for (const value of [layer.height, layer.width]) {
507
535
  const px = value?.px();
508
536
  if (!value || px === void 0 || px <= 0 || px >= minTarget) continue;
509
537
  report({
510
538
  at: value,
511
- message: `${layer.where ? `At ${layer.where}, it` : "It"}'s ${px}${unit} ${reads}; a target you press needs ${minTarget}${unit}.`
539
+ message: `Increase to ${minTarget}${unit} (currently ${px}${unit}) for touch compliance.`
512
540
  });
513
541
  }
514
542
  }
@@ -538,7 +566,7 @@ function duplicateToken(ctx, report) {
538
566
  token,
539
567
  prop: key,
540
568
  value: signature.split("|")[0],
541
- message: `\`${token}\` holds ${signature.split("|")[0]}, as \`${first}\` does${modes.length > 1 ? " in every mode" : ""}, and ${key} offers both.`,
569
+ message: `Same value as \`${first}\`${modes.length > 1 ? " in every mode" : ""} (${signature.split("|")[0]}). Use \`${first}\`, so ${key} offers each value once.`,
542
570
  suggestion: first
543
571
  });
544
572
  }