@dialpad/dialtone-css 9.4.0 → 9.6.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dialtone-migrate-typography tests.
2
+ * Typography migration (dialtone_migrate_typography) tests.
3
3
  *
4
4
  * One assertion per test; data-driven via for..of where multiple cases share a concept.
5
5
  * Run: node --test packages/dialtone-css/lib/build/js/dialtone_migrate_typography/test.mjs
@@ -29,6 +29,17 @@ function warnings (input) {
29
29
  return transformContent(input, { filePath: 'test.vue' }).warnings;
30
30
  }
31
31
 
32
+ // DtText's runtime constants are the authority for the mapping. Load them from source
33
+ // as a data URL: the Vue package has no "type": "module", and the script itself must not
34
+ // depend on Vue source at runtime.
35
+ const TEXT_CONSTANTS_PATH = path.resolve(
36
+ path.dirname(fileURLToPath(import.meta.url)),
37
+ '../../../../../dialtone-vue/components/Text/TextConstants.js',
38
+ );
39
+ const TEXT = await import(
40
+ `data:text/javascript;base64,${fs.readFileSync(TEXT_CONSTANTS_PATH).toString('base64')}`
41
+ );
42
+
32
43
  // ---------------------------------------------------------------------------
33
44
  // Task 1 — scaffold / no-op fast path
34
45
  // ---------------------------------------------------------------------------
@@ -53,83 +64,75 @@ describe('fast path — no typography classes', () => {
53
64
  // Task 2 — composed class transformation
54
65
  // ---------------------------------------------------------------------------
55
66
 
56
- describe('headline → dt-text', () => {
57
- const cases = [
58
- // basic sizes
59
- ['d-headline--sm on p', '<p class="d-headline--sm">Hi</p>', '<dt-text as="p" kind="headline" size="100">Hi</dt-text>'],
60
- ['d-headline-small alias', '<p class="d-headline-small">Hi</p>', '<dt-text as="p" kind="headline" size="100">Hi</dt-text>'],
61
- ['d-headline--md on p', '<p class="d-headline--md">Hi</p>', '<dt-text as="p" kind="headline" size="300">Hi</dt-text>'],
62
- ['d-headline-medium alias', '<p class="d-headline-medium">Hi</p>', '<dt-text as="p" kind="headline" size="300">Hi</dt-text>'],
63
- ['d-headline--lg on p', '<p class="d-headline--lg">Hi</p>', '<dt-text as="p" kind="headline" size="500">Hi</dt-text>'],
64
- ['d-headline-large alias', '<p class="d-headline-large">Hi</p>', '<dt-text as="p" kind="headline" size="500">Hi</dt-text>'],
65
- ['d-headline--xl on p', '<p class="d-headline--xl">Hi</p>', '<dt-text as="p" kind="headline" size="600">Hi</dt-text>'],
66
- ['d-headline-extra-large alias', '<p class="d-headline-extra-large">Hi</p>', '<dt-text as="p" kind="headline" size="600">Hi</dt-text>'],
67
- ['d-headline--xxl on p', '<p class="d-headline--xxl">Hi</p>', '<dt-text as="p" kind="headline" size="700">Hi</dt-text>'],
68
- ['d-headline-extra-extra-large alias', '<p class="d-headline-extra-extra-large">Hi</p>', '<dt-text as="p" kind="headline" size="700">Hi</dt-text>'],
69
- // soft variants (strength=medium)
70
- ['d-headline--sm-soft', '<p class="d-headline--sm-soft">Hi</p>', '<dt-text as="p" kind="headline" size="100" strength="medium">Hi</dt-text>'],
71
- ['d-headline-soft-small alias', '<p class="d-headline-soft-small">Hi</p>', '<dt-text as="p" kind="headline" size="100" strength="medium">Hi</dt-text>'],
72
- ['d-headline--lg-soft', '<p class="d-headline--lg-soft">Hi</p>', '<dt-text as="p" kind="headline" size="500" strength="medium">Hi</dt-text>'],
73
- // compact variants
74
- ['d-headline--sm-compact', '<p class="d-headline--sm-compact">Hi</p>', '<dt-text as="p" kind="headline" size="100" density="200">Hi</dt-text>'],
75
- ['d-headline-compact-small alias', '<p class="d-headline-compact-small">Hi</p>', '<dt-text as="p" kind="headline" size="100" density="200">Hi</dt-text>'],
76
- ['d-headline--md-compact', '<p class="d-headline--md-compact">Hi</p>', '<dt-text as="p" kind="headline" size="300" density="300">Hi</dt-text>'],
77
- ['d-headline--lg-compact', '<p class="d-headline--lg-compact">Hi</p>', '<dt-text as="p" kind="headline" size="500" density="200">Hi</dt-text>'],
78
- ['d-headline--xl-compact', '<p class="d-headline--xl-compact">Hi</p>', '<dt-text as="p" kind="headline" size="600" density="100">Hi</dt-text>'],
79
- ['d-headline--xxl-compact (no density)', '<p class="d-headline--xxl-compact">Hi</p>', '<dt-text as="p" kind="headline" size="700">Hi</dt-text>'],
80
- // soft-compact
81
- ['d-headline--sm-soft-compact', '<p class="d-headline--sm-soft-compact">Hi</p>', '<dt-text as="p" kind="headline" size="100" strength="medium" density="200">Hi</dt-text>'],
82
- ['d-headline--lg-soft-compact', '<p class="d-headline--lg-soft-compact">Hi</p>', '<dt-text as="p" kind="headline" size="500" strength="medium" density="200">Hi</dt-text>'],
83
- ];
84
- for (const [label, input, expected] of cases) {
85
- it(label, () => { assert.equal(run(input), expected); });
86
- }
87
- });
88
-
89
- describe('body → dt-text', () => {
90
- const cases = [
91
- ['d-body--md on p', '<p class="d-body--md">Hi</p>', '<dt-text as="p" kind="body" size="300">Hi</dt-text>'],
92
- ['d-body-base alias', '<p class="d-body-base">Hi</p>', '<dt-text as="p" kind="body" size="300">Hi</dt-text>'],
93
- ['d-body--sm on p', '<p class="d-body--sm">Hi</p>', '<dt-text as="p" kind="body" size="100">Hi</dt-text>'],
94
- ['d-body-small alias', '<p class="d-body-small">Hi</p>', '<dt-text as="p" kind="body" size="100">Hi</dt-text>'],
95
- ['d-body--md-compact', '<p class="d-body--md-compact">Hi</p>', '<dt-text as="p" kind="body" size="300" density="300">Hi</dt-text>'],
96
- ['d-body-compact alias', '<p class="d-body-compact">Hi</p>', '<dt-text as="p" kind="body" size="300" density="300">Hi</dt-text>'],
97
- ['d-body--sm-compact', '<p class="d-body--sm-compact">Hi</p>', '<dt-text as="p" kind="body" size="100" density="200">Hi</dt-text>'],
98
- ['d-body-compact-small alias', '<p class="d-body-compact-small">Hi</p>', '<dt-text as="p" kind="body" size="100" density="200">Hi</dt-text>'],
67
+ describe('composed class → DtText variant', () => {
68
+ // [class, legacy kind, legacy size, variant, extra props]. Legacy kind + size is what
69
+ // the previous output rendered; the variant must resolve to the same composition class.
70
+ const rows = [
71
+ ['d-headline--sm', 'headline', '100', 'headline-xs', ''],
72
+ ['d-headline-small', 'headline', '100', 'headline-xs', ''],
73
+ ['d-headline--md', 'headline', '300', 'headline-md', ''],
74
+ ['d-headline-medium', 'headline', '300', 'headline-md', ''],
75
+ ['d-headline--lg', 'headline', '500', 'headline-xl', ''],
76
+ ['d-headline-large', 'headline', '500', 'headline-xl', ''],
77
+ ['d-headline--xl', 'headline', '600', 'headline-2xl', ''],
78
+ ['d-headline-extra-large', 'headline', '600', 'headline-2xl', ''],
79
+ ['d-headline--xxl', 'headline', '700', 'headline-3xl', ''],
80
+ ['d-headline-extra-extra-large', 'headline', '700', 'headline-3xl', ''],
81
+ ['d-headline--sm-soft', 'headline', '100', 'headline-xs', ' strength="medium"'],
82
+ ['d-headline-soft-small', 'headline', '100', 'headline-xs', ' strength="medium"'],
83
+ ['d-headline--lg-soft', 'headline', '500', 'headline-xl', ' strength="medium"'],
84
+ ['d-headline--sm-compact', 'headline', '100', 'headline-xs', ' density="200"'],
85
+ ['d-headline-compact-small', 'headline', '100', 'headline-xs', ' density="200"'],
86
+ ['d-headline--md-compact', 'headline', '300', 'headline-md', ' density="300"'],
87
+ ['d-headline-compact-medium', 'headline', '300', 'headline-md', ' density="300"'],
88
+ ['d-headline--lg-compact', 'headline', '500', 'headline-xl', ' density="200"'],
89
+ ['d-headline-compact-large', 'headline', '500', 'headline-xl', ' density="200"'],
90
+ ['d-headline--xl-compact', 'headline', '600', 'headline-2xl', ' density="100"'],
91
+ ['d-headline--xxl-compact', 'headline', '700', 'headline-3xl', ''],
92
+ ['d-headline--sm-soft-compact', 'headline', '100', 'headline-xs', ' strength="medium" density="200"'],
93
+ ['d-headline-compact-soft-small', 'headline', '100', 'headline-xs', ' strength="medium" density="200"'],
94
+ ['d-headline--lg-soft-compact', 'headline', '500', 'headline-xl', ' strength="medium" density="200"'],
95
+ ['d-body--md', 'body', '300', 'body-md', ''],
96
+ ['d-body-base', 'body', '300', 'body-md', ''],
97
+ ['d-body--sm', 'body', '100', 'body-xs', ''],
98
+ ['d-body-small', 'body', '100', 'body-xs', ''],
99
+ ['d-body--md-compact', 'body', '300', 'body-md', ' density="300"'],
100
+ ['d-body-compact', 'body', '300', 'body-md', ' density="300"'],
101
+ ['d-body--sm-compact', 'body', '100', 'body-xs', ' density="200"'],
102
+ ['d-body-compact-small', 'body', '100', 'body-xs', ' density="200"'],
103
+ ['d-label--md', 'label', '300', 'label-md', ''],
104
+ ['d-label-base', 'label', '300', 'label-md', ''],
105
+ ['d-label--sm', 'label', '100', 'label-xs', ''],
106
+ ['d-label-small', 'label', '100', 'label-xs', ''],
107
+ ['d-label--md-compact', 'label', '300', 'label-md', ' density="300"'],
108
+ ['d-label-compact', 'label', '300', 'label-md', ' density="300"'],
109
+ ['d-label--sm-compact', 'label', '100', 'label-xs', ' density="200"'],
110
+ ['d-label-compact-small', 'label', '100', 'label-xs', ' density="200"'],
111
+ ['d-label--md-plain', 'label', '300', 'label-md', ' strength="normal"'],
112
+ ['d-label-plain', 'label', '300', 'label-md', ' strength="normal"'],
113
+ ['d-label--md-plain-compact', 'label', '300', 'label-md', ' strength="normal" density="300"'],
114
+ ['d-label-compact-plain', 'label', '300', 'label-md', ' strength="normal" density="300"'],
115
+ ['d-label--sm-plain', 'label', '100', 'label-xs', ' strength="normal"'],
116
+ ['d-label-plain-small', 'label', '100', 'label-xs', ' strength="normal"'],
117
+ ['d-label--sm-plain-compact', 'label', '100', 'label-xs', ' strength="normal" density="200"'],
118
+ ['d-label-compact-plain-small', 'label', '100', 'label-xs', ' strength="normal" density="200"'],
119
+ ['d-code--md', 'code', '200', 'code-sm', ''],
120
+ ['d-code-base', 'code', '200', 'code-sm', ''],
99
121
  ];
100
- for (const [label, input, expected] of cases) {
101
- it(label, () => { assert.equal(run(input), expected); });
102
- }
103
- });
104
122
 
105
- describe('label → dt-text', () => {
106
- const cases = [
107
- ['d-label--md', '<p class="d-label--md">Hi</p>', '<dt-text as="p" kind="label" size="300">Hi</dt-text>'],
108
- ['d-label-base alias', '<p class="d-label-base">Hi</p>', '<dt-text as="p" kind="label" size="300">Hi</dt-text>'],
109
- ['d-label--sm', '<p class="d-label--sm">Hi</p>', '<dt-text as="p" kind="label" size="100">Hi</dt-text>'],
110
- ['d-label-small alias', '<p class="d-label-small">Hi</p>', '<dt-text as="p" kind="label" size="100">Hi</dt-text>'],
111
- ['d-label--md-compact', '<p class="d-label--md-compact">Hi</p>', '<dt-text as="p" kind="label" size="300" density="300">Hi</dt-text>'],
112
- ['d-label--sm-compact', '<p class="d-label--sm-compact">Hi</p>', '<dt-text as="p" kind="label" size="100" density="200">Hi</dt-text>'],
113
- ['d-label--md-plain', '<p class="d-label--md-plain">Hi</p>', '<dt-text as="p" kind="label" size="300" strength="normal">Hi</dt-text>'],
114
- ['d-label-plain alias', '<p class="d-label-plain">Hi</p>', '<dt-text as="p" kind="label" size="300" strength="normal">Hi</dt-text>'],
115
- ['d-label--md-plain-compact', '<p class="d-label--md-plain-compact">Hi</p>', '<dt-text as="p" kind="label" size="300" strength="normal" density="300">Hi</dt-text>'],
116
- ['d-label--sm-plain', '<p class="d-label--sm-plain">Hi</p>', '<dt-text as="p" kind="label" size="100" strength="normal">Hi</dt-text>'],
117
- ['d-label--sm-plain-compact', '<p class="d-label--sm-plain-compact">Hi</p>', '<dt-text as="p" kind="label" size="100" strength="normal" density="200">Hi</dt-text>'],
118
- ];
119
- for (const [label, input, expected] of cases) {
120
- it(label, () => { assert.equal(run(input), expected); });
123
+ for (const [cls, , , variant, extra] of rows) {
124
+ it(`${cls} emits variant="${variant}" with no kind or size`, () => {
125
+ assert.equal(run(`<p class="${cls}">Hi</p>`), `<dt-text as="p" variant="${variant}"${extra}>Hi</dt-text>`);
126
+ });
121
127
  }
122
- });
123
128
 
124
- describe('code → dt-text', () => {
125
- it('d-code--md maps to kind=code size=200', () => {
126
- assert.equal(run('<p class="d-code--md">Hi</p>'), '<dt-text as="p" kind="code" size="200">Hi</dt-text>');
127
- });
128
- it('d-code-base alias maps to kind=code size=200', () => {
129
- assert.equal(run('<p class="d-code-base">Hi</p>'), '<dt-text as="p" kind="code" size="200">Hi</dt-text>');
129
+ it('each variant renders the composition class of its legacy kind + size', () => {
130
+ for (const [cls, kind, size, variant] of rows) {
131
+ const legacy = `${TEXT.TEXT_KIND_MODIFIERS[kind]}--${TEXT.TEXT_SIZE_MAP[size]}`;
132
+ assert.equal(TEXT.TEXT_VARIANT_MODIFIERS[variant], legacy, cls);
133
+ }
130
134
  });
131
135
  });
132
-
133
136
  describe('flag rows — eyebrow and code-sm emit review comment, no rewrite', () => {
134
137
  it('d-headline--eyebrow emits review comment and leaves element unchanged', () => {
135
138
  const input = '<p class="d-headline--eyebrow">Hi</p>';
@@ -153,21 +156,21 @@ describe('flag rows — eyebrow and code-sm emit review comment, no rewrite', ()
153
156
  });
154
157
  });
155
158
 
156
- describe('helper rows — approximate as body+density with review marker', () => {
157
- it('d-helper--md rewrites to body size=300 density=300 with helper comment', () => {
158
- const input = '<p class="d-helper--md">Hi</p>';
159
- const out = run(input);
160
- assert.ok(out.includes('kind="body"'), 'should have kind=body');
161
- assert.ok(out.includes('size="300"'), 'should have size=300');
162
- assert.ok(out.includes('density="300"'), 'should have density=300');
163
- assert.ok(out.includes('<!-- dt-text-migrate: review helper -->'), 'should have helper comment');
164
- });
165
- it('d-helper--sm rewrites to body size=100 density=200 with helper comment', () => {
166
- const input = '<p class="d-helper--sm">Hi</p>';
167
- const out = run(input);
168
- assert.ok(out.includes('kind="body"') && out.includes('size="100"') && out.includes('density="200"'));
169
- assert.ok(out.includes('<!-- dt-text-migrate: review helper -->'));
170
- });
159
+ describe('helper rows — approximate as body variant + density with review marker', () => {
160
+ const rows = [
161
+ ['d-helper--md', 'body-md', '300'],
162
+ ['d-helper-base', 'body-md', '300'],
163
+ ['d-helper--sm', 'body-xs', '200'],
164
+ ['d-helper-small', 'body-xs', '200'],
165
+ ];
166
+ for (const [cls, variant, density] of rows) {
167
+ it(`${cls} emits variant="${variant}" density="${density}" with helper marker`, () => {
168
+ assert.equal(
169
+ run(`<p class="${cls}">Hi</p>`),
170
+ `<!-- dt-text-migrate: review helper --><dt-text as="p" variant="${variant}" density="${density}">Hi</dt-text>`,
171
+ );
172
+ });
173
+ }
171
174
  });
172
175
 
173
176
  describe('element tags — only rewriteable tags are converted', () => {
@@ -181,7 +184,7 @@ describe('element tags — only rewriteable tags are converted', () => {
181
184
  });
182
185
  }
183
186
  it('<span> is rewritten without as prop (DtText default)', () => {
184
- assert.equal(run('<span class="d-body--sm">x</span>'), '<dt-text kind="body" size="100">x</dt-text>');
187
+ assert.equal(run('<span class="d-body--sm">x</span>'), '<dt-text variant="body-xs">x</dt-text>');
185
188
  });
186
189
  // Non-rewriteable tags (a, button, li, dt-*) carrying composed typography
187
190
  // classes are NOT auto-converted, but they DO get a review marker so the
@@ -207,13 +210,13 @@ describe('mixed classes — composed class dropped, others retained', () => {
207
210
  it('retains non-typography class on output dt-text', () => {
208
211
  assert.equal(
209
212
  run('<p class="d-headline--md d-mb-200">Hi</p>'),
210
- '<dt-text as="p" kind="headline" size="300" class="d-mb-200">Hi</dt-text>',
213
+ '<dt-text as="p" variant="headline-md" class="d-mb-200">Hi</dt-text>',
211
214
  );
212
215
  });
213
216
  it('retains multiple non-typography classes', () => {
214
217
  assert.equal(
215
218
  run('<p class="d-headline--md d-mb-200 d-p-100">Hi</p>'),
216
- '<dt-text as="p" kind="headline" size="300" class="d-mb-200 d-p-100">Hi</dt-text>',
219
+ '<dt-text as="p" variant="headline-md" class="d-mb-200 d-p-100">Hi</dt-text>',
217
220
  );
218
221
  });
219
222
  it('drops only the composed class when mixed', () => {
@@ -230,8 +233,8 @@ describe('multi-element file — all matches rewritten', () => {
230
233
  '<p class="d-body--sm">Body</p>',
231
234
  ].join('\n');
232
235
  const expected = [
233
- '<dt-text as="p" kind="headline" size="300">Title</dt-text>',
234
- '<dt-text as="p" kind="body" size="100">Body</dt-text>',
236
+ '<dt-text as="p" variant="headline-md">Title</dt-text>',
237
+ '<dt-text as="p" variant="body-xs">Body</dt-text>',
235
238
  ].join('\n');
236
239
  assert.equal(run(input), expected);
237
240
  });
@@ -245,13 +248,13 @@ describe('override utilities on rewriteable elements', () => {
245
248
  it('d-fw-bold on p alongside composed class → strength prop', () => {
246
249
  assert.equal(
247
250
  run('<p class="d-headline--md d-fw-bold">x</p>'),
248
- '<dt-text as="p" kind="headline" size="300" strength="bold">x</dt-text>',
251
+ '<dt-text as="p" variant="headline-md" strength="bold">x</dt-text>',
249
252
  );
250
253
  });
251
254
  it('d-fc-tertiary → tone prop', () => {
252
255
  assert.equal(
253
256
  run('<p class="d-headline--md d-fc-tertiary">x</p>'),
254
- '<dt-text as="p" kind="headline" size="300" tone="tertiary">x</dt-text>',
257
+ '<dt-text as="p" variant="headline-md" tone="tertiary">x</dt-text>',
255
258
  );
256
259
  });
257
260
  it('d-fw-bold + d-fc-tertiary together on p', () => {
@@ -263,37 +266,37 @@ describe('override utilities on rewriteable elements', () => {
263
266
  it('d-lh-300 → density prop', () => {
264
267
  assert.equal(
265
268
  run('<p class="d-body--md d-lh-300">x</p>'),
266
- '<dt-text as="p" kind="body" size="300" density="300">x</dt-text>',
269
+ '<dt-text as="p" variant="body-md" density="300">x</dt-text>',
267
270
  );
268
271
  });
269
272
  it('d-truncate → truncate boolean prop (no value)', () => {
270
273
  assert.equal(
271
274
  run('<p class="d-body--sm d-truncate">x</p>'),
272
- '<dt-text as="p" kind="body" size="100" truncate>x</dt-text>',
275
+ '<dt-text as="p" variant="body-xs" truncate>x</dt-text>',
273
276
  );
274
277
  });
275
278
  it('d-ta-left → align="start" (logical naming)', () => {
276
279
  assert.equal(
277
280
  run('<p class="d-body--sm d-ta-left">x</p>'),
278
- '<dt-text as="p" kind="body" size="100" align="start">x</dt-text>',
281
+ '<dt-text as="p" variant="body-xs" align="start">x</dt-text>',
279
282
  );
280
283
  });
281
284
  it('d-ta-right → align="end" (logical naming)', () => {
282
285
  assert.equal(
283
286
  run('<p class="d-body--sm d-ta-right">x</p>'),
284
- '<dt-text as="p" kind="body" size="100" align="end">x</dt-text>',
287
+ '<dt-text as="p" variant="body-xs" align="end">x</dt-text>',
285
288
  );
286
289
  });
287
290
  it('d-ta-center → align="center"', () => {
288
291
  assert.equal(
289
292
  run('<p class="d-body--sm d-ta-center">x</p>'),
290
- '<dt-text as="p" kind="body" size="100" align="center">x</dt-text>',
293
+ '<dt-text as="p" variant="body-xs" align="center">x</dt-text>',
291
294
  );
292
295
  });
293
296
  it('d-ta-justify → align="justify"', () => {
294
297
  assert.equal(
295
298
  run('<p class="d-body--sm d-ta-justify">x</p>'),
296
- '<dt-text as="p" kind="body" size="100" align="justify">x</dt-text>',
299
+ '<dt-text as="p" variant="body-xs" align="justify">x</dt-text>',
297
300
  );
298
301
  });
299
302
  it('all 15 d-fc-* tones map correctly (spot-check)', () => {
@@ -354,16 +357,56 @@ describe('--validate — DtText prop bug detection', () => {
354
357
  const issues = validateDtTextProps('<dt-text kind="body" size="md" tone="primary">x</dt-text>');
355
358
  assert.equal(issues.length, 0);
356
359
  });
357
- it('accepts both numeric and t-shirt size values', () => {
358
- const a = validateDtTextProps('<dt-text size="300">x</dt-text>');
359
- const b = validateDtTextProps('<dt-text size="md">x</dt-text>');
360
- assert.equal(a.length, 0);
361
- assert.equal(b.length, 0);
362
- });
363
360
  it('non-typography classes on DtText do not flag', () => {
364
361
  const issues = validateDtTextProps('<dt-text class="my-custom d-mb-200">x</dt-text>');
365
362
  assert.equal(issues.length, 0);
366
363
  });
364
+
365
+ // Variant makes size a raw font-size token; kind alone keeps composition sizes;
366
+ // neither means size has nothing to apply to. Bound values stay unknown.
367
+ const contexts = [
368
+ ['variant + raw token', '<dt-text variant="body-md" size="250">', []],
369
+ ['variant + t-shirt size', '<dt-text variant="body-md" size="md">', ['invalid-value']],
370
+ ['variant decides over kind', '<dt-text kind="label" variant="body-md" size="md">', ['invalid-value']],
371
+ ['kind + composition size', '<dt-text kind="headline" size="3xl">', []],
372
+ ['kind + headline-only size', '<dt-text kind="body" size="700">', ['invalid-value']],
373
+ ['kind + raw token', '<dt-text kind="body" size="250">', ['invalid-value']],
374
+ ['static size alone', '<dt-text size="300">', ['size-without-composition']],
375
+ ['bound size alone', '<dt-text :size="s">', ['size-without-composition']],
376
+ ['spread may supply composition', '<dt-text v-bind="attrs" size="300">', []],
377
+ ['bound variant', '<dt-text :variant="v" size="md">', []],
378
+ ['bound kind', '<dt-text :kind="k" size="250">', []],
379
+ ['bound size with variant', '<dt-text variant="body-md" :size="s">', []],
380
+ ['invalid variant', '<dt-text variant="title-md">', ['invalid-value']],
381
+ ['invalid family', '<dt-text family="serif">', ['invalid-value']],
382
+ ['invalid variant and family report separately', '<dt-text variant="title-md" family="serif">', ['invalid-value', 'invalid-value']],
383
+ ['family alone', '<dt-text family="mono">', []],
384
+ ['kind alone', '<dt-text kind="code">', []],
385
+ ['object syntax on variant', '<dt-text :variant="{ \'body-md\': c }">', ['object-syntax']],
386
+ ['object syntax on family', '<dt-text :family="{ mono: c }">', ['object-syntax']],
387
+ ['inherited Object key as kind', '<dt-text kind="constructor" size="300">', ['invalid-value']],
388
+ ];
389
+ for (const [label, tag, expected] of contexts) {
390
+ it(`size context: ${label}`, () => {
391
+ assert.deepEqual(validateDtTextProps(`${tag}x</dt-text>`).map(i => i.type), expected);
392
+ });
393
+ }
394
+
395
+ it('mirrors DtText variant, family, font-size and per-kind size values', () => {
396
+ const accepted = (tag) => validateDtTextProps(`${tag}x</dt-text>`).length === 0;
397
+ for (const variant of Object.keys(TEXT.TEXT_VARIANT_MODIFIERS)) {
398
+ assert.ok(accepted(`<dt-text variant="${variant}">`), variant);
399
+ }
400
+ for (const family of Object.keys(TEXT.TEXT_FAMILY_MODIFIERS)) {
401
+ assert.ok(accepted(`<dt-text family="${family}">`), family);
402
+ }
403
+ for (const size of Object.keys(TEXT.TEXT_FONT_SIZE_MODIFIERS)) {
404
+ assert.ok(accepted(`<dt-text variant="body-md" size="${size}">`), size);
405
+ }
406
+ for (const [kind, sizes] of Object.entries(TEXT.TEXT_SIZE_MODIFIERS)) {
407
+ for (const size of sizes) assert.ok(accepted(`<dt-text kind="${kind}" size="${size}">`), `${kind} ${size}`);
408
+ }
409
+ });
367
410
  });
368
411
 
369
412
  describe('P3 — legacy raw-utility heading hint comment', () => {
@@ -371,7 +414,9 @@ describe('P3 — legacy raw-utility heading hint comment', () => {
371
414
  const input = '<h2 class="d-ff-custom d-fw-bold d-fs-300 d-fc-primary">x</h2>';
372
415
  const out = run(input);
373
416
  assert.ok(out.includes('dt-text-migrate: legacy heading'), `should emit hint, got: ${out}`);
374
- assert.ok(out.includes('kind=headline'), 'should propose kind=headline for h-tag');
417
+ assert.ok(out.includes('variant=headline-? (VERIFY)'), 'should leave the headline step to the reviewer');
418
+ assert.ok(out.includes('size="300"'), 'should describe d-fs-300 as a raw size token');
419
+ assert.ok(!/kind=|headline size/.test(out), 'should not infer a composition from font size');
375
420
  assert.ok(out.includes('strength=bold'), 'should propose strength=bold');
376
421
  assert.ok(out.includes('tone=primary'), 'should propose tone=primary');
377
422
  assert.ok(out.includes('<h2 class="d-ff-custom d-fw-bold d-fs-300 d-fc-primary">'), 'element unchanged');
@@ -399,19 +444,21 @@ describe('P3 — legacy raw-utility heading hint comment', () => {
399
444
  });
400
445
  });
401
446
 
402
- describe('d-ff-mono — establishes kind=code', () => {
403
- it('<span class="d-ff-mono"> → kind="code"', () => {
404
- assert.equal(
405
- run('<span class="d-ff-mono">x</span>'),
406
- '<dt-text kind="code">x</dt-text>',
407
- );
408
- });
409
- it('combined with d-fw-bold', () => {
410
- assert.equal(
411
- run('<span class="d-ff-mono d-fw-bold">x</span>'),
412
- '<dt-text kind="code" strength="bold">x</dt-text>',
413
- );
414
- });
447
+ describe('d-ff-mono — family="mono" without inventing a composition', () => {
448
+ const cases = [
449
+ ['alone keeps inherited typography', '<span class="d-ff-mono">x</span>', '<dt-text family="mono">x</dt-text>'],
450
+ ['with d-fw-bold', '<span class="d-ff-mono d-fw-bold">x</span>', '<dt-text family="mono" strength="bold">x</dt-text>'],
451
+ ['with a composed class', '<p class="d-body--md d-ff-mono">x</p>', '<dt-text as="p" variant="body-md" family="mono">x</dt-text>'],
452
+ ['nested in a composed parent', '<p class="d-headline--md">Run <span class="d-ff-mono">cmd</span></p>',
453
+ '<dt-text as="p" variant="headline-md">Run <dt-text family="mono">cmd</dt-text></dt-text>'],
454
+ ['authored family keeps the utility', '<dt-text family="sans" class="d-ff-mono">x</dt-text>',
455
+ '<!-- dt-text-migrate: review conflicting class --><dt-text family="sans" class="d-ff-mono">x</dt-text>'],
456
+ ['inline font-family keeps the utility', '<p class="d-body--md d-ff-mono" style="font-family: serif">x</p>',
457
+ '<!-- dt-text-migrate: review conflicting class --><dt-text as="p" variant="body-md" class="d-ff-mono" style="font-family: serif">x</dt-text>'],
458
+ ];
459
+ for (const [label, input, expected] of cases) {
460
+ it(label, () => { assert.equal(run(input), expected); });
461
+ }
415
462
  });
416
463
 
417
464
  describe('P1 — override-only without composed class: only span/p/label converted', () => {
@@ -515,10 +562,10 @@ describe('C1 — nested span with flagged composed class stays unwrapped', () =>
515
562
  });
516
563
 
517
564
  describe('F4 — parseExistingProps does not false-match suffix attrs', () => {
518
- it('font-kind= is not treated as kind=', () => {
565
+ it('font-family= is not treated as family=', () => {
519
566
  assert.equal(
520
- run('<dt-text font-kind="foo" class="d-ff-mono">x</dt-text>'),
521
- '<dt-text font-kind="foo" kind="code">x</dt-text>',
567
+ run('<dt-text font-family="foo" class="d-ff-mono">x</dt-text>'),
568
+ '<dt-text font-family="foo" family="mono">x</dt-text>',
522
569
  );
523
570
  });
524
571
  it('wrapper-truncate= is not treated as truncate', () => {
@@ -527,11 +574,6 @@ describe('F4 — parseExistingProps does not false-match suffix attrs', () => {
527
574
  '<dt-text wrapper-truncate="yes" truncate>x</dt-text>',
528
575
  );
529
576
  });
530
- it('legitimate conflict still flagged', () => {
531
- const out = run('<dt-text strength="bold" class="d-fw-normal">x</dt-text>');
532
- assert.ok(out.includes('<!-- dt-text-migrate: review conflicting class -->'));
533
- assert.ok(out.includes('strength="bold"'));
534
- });
535
577
  });
536
578
 
537
579
  describe('F3 — depth-aware parent body in collapseNestedSpans', () => {
@@ -556,13 +598,13 @@ describe('F1 — quote-aware opening-tag matching (> inside :prop binding)', ()
556
598
  it('<p class="d-headline--md" :title="a > b"> preserves the binding', () => {
557
599
  assert.equal(
558
600
  run('<p class="d-headline--md" :title="a > b">x</p>'),
559
- '<dt-text as="p" kind="headline" size="300" :title="a > b">x</dt-text>',
601
+ '<dt-text as="p" variant="headline-md" :title="a > b">x</dt-text>',
560
602
  );
561
603
  });
562
604
  it('<p :disabled="i > total" class="d-body--sm"> preserves the binding', () => {
563
605
  assert.equal(
564
606
  run('<p :disabled="i > total" class="d-body--sm">x</p>'),
565
- '<dt-text as="p" kind="body" size="100" :disabled="i > total">x</dt-text>',
607
+ '<dt-text as="p" variant="body-xs" :disabled="i > total">x</dt-text>',
566
608
  );
567
609
  });
568
610
  });
@@ -614,11 +656,11 @@ describe('already-dt-text residual lift', () => {
614
656
  '<dt-text kind="body" truncate>x</dt-text>',
615
657
  );
616
658
  });
617
- it('preserves existing explicit prop when class would conflict', () => {
618
- const input = '<dt-text strength="bold" class="d-fw-normal">x</dt-text>';
619
- const out = run(input);
620
- assert.ok(out.includes('strength="bold"'), 'should preserve strength=bold');
621
- assert.ok(out.includes('<!-- dt-text-migrate: review conflicting class -->'), 'should emit conflict comment');
659
+ it('keeps the authored prop and the conflicting class, which may win in CSS today', () => {
660
+ assert.equal(
661
+ run('<dt-text strength="bold" class="d-fw-normal">x</dt-text>'),
662
+ '<!-- dt-text-migrate: review conflicting class --><dt-text strength="bold" class="d-fw-normal">x</dt-text>',
663
+ );
622
664
  });
623
665
  it('retains unrecognised classes after lifting', () => {
624
666
  const out = run('<dt-text kind="body" class="d-fw-bold d-mb-200">x</dt-text>');
@@ -626,6 +668,9 @@ describe('already-dt-text residual lift', () => {
626
668
  assert.ok(out.includes('d-mb-200'), 'should retain d-mb-200');
627
669
  assert.ok(!out.includes('d-fw-bold'), 'should drop d-fw-bold');
628
670
  });
671
+ it('keeps a self-closing DtText self-closing', () => {
672
+ assert.equal(run('<dt-text class="d-fw-bold" />'), '<dt-text strength="bold" />');
673
+ });
629
674
  it('PascalCase DtText is also lifted', () => {
630
675
  assert.equal(
631
676
  run('<DtText kind="body" class="d-fw-bold">x</DtText>'),
@@ -642,13 +687,13 @@ describe('nested-span collapse — safe case', () => {
642
687
  it('collapses direct child span with only recognized classes', () => {
643
688
  assert.equal(
644
689
  run('<p class="d-headline--md"><span class="d-fw-bold">name</span></p>'),
645
- '<dt-text as="p" kind="headline" size="300"><dt-text strength="bold">name</dt-text></dt-text>',
690
+ '<dt-text as="p" variant="headline-md"><dt-text strength="bold">name</dt-text></dt-text>',
646
691
  );
647
692
  });
648
693
  it('collapses span with composed class', () => {
649
694
  assert.equal(
650
695
  run('<p class="d-headline--md"><span class="d-body--sm">note</span></p>'),
651
- '<dt-text as="p" kind="headline" size="300"><dt-text kind="body" size="100">note</dt-text></dt-text>',
696
+ '<dt-text as="p" variant="headline-md"><dt-text variant="body-xs">note</dt-text></dt-text>',
652
697
  );
653
698
  });
654
699
  });
@@ -695,7 +740,7 @@ describe('d-fs-* flagging', () => {
695
740
  const out = run('<p class="d-headline--md d-fs-150">x</p>');
696
741
  assert.ok(/dt-text-migrate: review d-fs-\d+/.test(out), 'should flag d-fs-N');
697
742
  assert.ok(out.includes('d-fs-150'), 'should retain d-fs-150 class');
698
- assert.ok(out.includes('kind="headline"'), 'should still rewrite composed class');
743
+ assert.ok(out.includes('variant="headline-md"'), 'should still rewrite composed class');
699
744
  });
700
745
  it('d-fs-* emits one comment regardless of multiple fs classes', () => {
701
746
  const out = run('<p class="d-headline--md d-fs-100 d-fs-200">x</p>');
@@ -818,7 +863,7 @@ describe('--remove-markers', () => {
818
863
  const input = [
819
864
  '<!-- dt-text-migrate: review -->',
820
865
  '<p class="d-headline--eyebrow">Hi</p>',
821
- '<!-- dt-text-migrate: review helper --><dt-text as="p" kind="body" size="300">note</dt-text>',
866
+ '<!-- dt-text-migrate: review helper --><dt-text as="p" variant="body-md">note</dt-text>',
822
867
  '<!-- dt-text-migrate: review nested span --><span class="d-fw-bold">x</span>',
823
868
  ].join('\n');
824
869
  const cleaned = removeMarkersForTest(input);
@@ -858,9 +903,9 @@ describe('end-to-end fixture', () => {
858
903
  it('transforms the fixture and produces expected shape', () => {
859
904
  const { transformed } = transformContent(input, { filePath: 'fixture.vue' });
860
905
  // (a) headline
861
- assert.ok(transformed.includes('<dt-text as="p" kind="headline" size="300">Title</dt-text>'), '(a) headline');
906
+ assert.ok(transformed.includes('<dt-text as="p" variant="headline-md">Title</dt-text>'), '(a) headline');
862
907
  // (b) body with truncate+tone
863
- assert.ok(transformed.includes('kind="body" size="100" tone="secondary" truncate'), '(b) body overrides');
908
+ assert.ok(transformed.includes('variant="body-xs" tone="secondary" truncate'), '(b) body overrides');
864
909
  // (c) residual lift
865
910
  assert.ok(transformed.includes('<dt-text kind="label" strength="bold">Label</dt-text>'), '(c) residual lift');
866
911
  // (d) nested-span collapse
@@ -1023,7 +1068,7 @@ describe('wrapper safety — positive cases still convert (no false positives)',
1023
1068
  it('<div class="d-body--md"> with text-only content still converts', () => {
1024
1069
  assert.equal(
1025
1070
  run('<div class="d-body--md">Hello</div>'),
1026
- '<dt-text as="div" kind="body" size="300">Hello</dt-text>',
1071
+ '<dt-text as="div" variant="body-md">Hello</dt-text>',
1027
1072
  );
1028
1073
  });
1029
1074
  // Div with allowed inline children (span, em, strong) — should still convert
@@ -1036,14 +1081,14 @@ describe('wrapper safety — positive cases still convert (no false positives)',
1036
1081
  it('<p class="d-body--md">Hi</p> still converts', () => {
1037
1082
  assert.equal(
1038
1083
  run('<p class="d-body--md">Hi</p>'),
1039
- '<dt-text as="p" kind="body" size="300">Hi</dt-text>',
1084
+ '<dt-text as="p" variant="body-md">Hi</dt-text>',
1040
1085
  );
1041
1086
  });
1042
1087
  // <span> with composed class still converts to plain dt-text
1043
1088
  it('<span class="d-body--sm">x</span> still converts', () => {
1044
1089
  assert.equal(
1045
1090
  run('<span class="d-body--sm">x</span>'),
1046
- '<dt-text kind="body" size="100">x</dt-text>',
1091
+ '<dt-text variant="body-xs">x</dt-text>',
1047
1092
  );
1048
1093
  });
1049
1094
  // Empty body — no children at all
@@ -1122,6 +1167,243 @@ describe('wrapper safety — override path (d-fw-*, d-fc-*, etc.) with component
1122
1167
  });
1123
1168
  });
1124
1169
 
1170
+ // ---------------------------------------------------------------------------
1171
+ // Variant output contracts — authored props, precedence and uncertain inputs
1172
+ // ---------------------------------------------------------------------------
1173
+
1174
+ describe('composed class on DtText with authored composition stays unchanged', () => {
1175
+ const PROTECTED = '<!-- dt-text-migrate: review composed class with authored composition -->';
1176
+ // A generated variant next to an authored size would turn that size into a raw
1177
+ // font-size override; spreads and dynamic names may supply composition props.
1178
+ const tags = [
1179
+ '<dt-text kind="body" size="100" class="d-headline--md d-fw-bold">',
1180
+ '<dt-text :size="s" class="d-body--md">',
1181
+ '<dt-text :size class="d-body--md">',
1182
+ '<dt-text v-bind:variant="v" class="d-body--md">',
1183
+ '<dt-text variant="body-md" class="d-headline--md">',
1184
+ '<dt-text family="sans" class="d-headline--md">',
1185
+ '<dt-text v-bind="attrs" class="d-headline--md">',
1186
+ '<dt-text :[prop]="v" class="d-headline--md">',
1187
+ ];
1188
+ for (const tag of tags) {
1189
+ it(tag, () => {
1190
+ const input = `${tag}x</dt-text>`;
1191
+ assert.equal(run(input), PROTECTED + input);
1192
+ });
1193
+ }
1194
+
1195
+ it('converts a DtText without authored composition', () => {
1196
+ assert.equal(run('<dt-text class="d-headline--md">x</dt-text>'), '<dt-text variant="headline-md">x</dt-text>');
1197
+ });
1198
+ it('authored strength replaces the generated default without review', () => {
1199
+ assert.equal(
1200
+ run('<dt-text strength="bold" class="d-headline--sm-soft">x</dt-text>'),
1201
+ '<dt-text variant="headline-xs" strength="bold">x</dt-text>',
1202
+ );
1203
+ });
1204
+ });
1205
+
1206
+ describe('native attributes that may become DtText props keep the element unchanged', () => {
1207
+ const NATIVE = '<!-- dt-text-migrate: review attribute that may become a DtText prop -->';
1208
+ // A native element ignores these today. After conversion they are DtText props: a spread
1209
+ // size becomes a raw font-size override, a second variant duplicates the attribute and
1210
+ // `as` changes the tag.
1211
+ const inputs = [
1212
+ '<span class="d-body--md" v-bind="{size:300}">A</span>',
1213
+ '<span class="d-body--md" variant="headline-xl">A</span>',
1214
+ '<span class="d-body--md" as="h1">A</span>',
1215
+ '<p class="d-body--md" :size="s">A</p>',
1216
+ '<p class="d-body--md" :[name]="v">A</p>',
1217
+ '<p class="d-body--md" max-lines="2">A</p>',
1218
+ '<span class="d-fw-bold" as="h1">A</span>',
1219
+ '<span class="d-fw-bold" v-bind="attrs">A</span>',
1220
+ ];
1221
+ for (const input of inputs) {
1222
+ it(input, () => { assert.equal(run(input), NATIVE + input); });
1223
+ }
1224
+
1225
+ for (const span of ['<span class="d-body--sm" size="300">A</span>', '<span class="d-fw-bold" variant="headline-xl">A</span>']) {
1226
+ it(`the nested pass keeps the decision: ${span}`, () => {
1227
+ assert.equal(run(`<dt-text kind="body">${span}</dt-text>`), `<dt-text kind="body">${NATIVE}${span}</dt-text>`);
1228
+ });
1229
+ }
1230
+ });
1231
+
1232
+ describe('override utilities beat generated composition defaults', () => {
1233
+ const cases = [
1234
+ ['soft + d-fw-bold', '<p class="d-headline--sm-soft d-fw-bold">x</p>', '<dt-text as="p" variant="headline-xs" strength="bold">x</dt-text>'],
1235
+ ['plain + d-fw-semibold', '<p class="d-label--md-plain d-fw-semibold">x</p>', '<dt-text as="p" variant="label-md" strength="semibold">x</dt-text>'],
1236
+ ['compact + d-lh-400', '<p class="d-body--md-compact d-lh-400">x</p>', '<dt-text as="p" variant="body-md" density="400">x</dt-text>'],
1237
+ ];
1238
+ for (const [label, input, expected] of cases) {
1239
+ it(label, () => { assert.equal(run(input), expected); });
1240
+ }
1241
+ });
1242
+
1243
+ describe('uncertain overrides keep their utility class with review', () => {
1244
+ const CONFLICT = '<!-- dt-text-migrate: review conflicting class -->';
1245
+ const cases = [
1246
+ ['different values for one prop', '<p class="d-body--md d-fw-bold d-fw-normal">x</p>',
1247
+ `${CONFLICT}<dt-text as="p" variant="body-md" class="d-fw-bold d-fw-normal">x</dt-text>`],
1248
+ ['authored tone on DtText', '<dt-text tone="primary" class="d-headline--md d-fc-secondary">x</dt-text>',
1249
+ `${CONFLICT}<dt-text variant="headline-md" class="d-fc-secondary" tone="primary">x</dt-text>`],
1250
+ ['inline style sets the same property', '<p class="d-body--md d-fw-bold" style="font-weight: 400">x</p>',
1251
+ `${CONFLICT}<dt-text as="p" variant="body-md" class="d-fw-bold" style="font-weight: 400">x</dt-text>`],
1252
+ ['bound style may set it', '<p class="d-body--md d-fw-bold" :style="s">x</p>',
1253
+ `${CONFLICT}<dt-text as="p" variant="body-md" class="d-fw-bold" :style="s">x</dt-text>`],
1254
+ ['spread may set style', '<dt-text v-bind="attrs" class="d-fw-bold">x</dt-text>',
1255
+ `${CONFLICT}<dt-text v-bind="attrs" class="d-fw-bold">x</dt-text>`],
1256
+ ['inline all reset', '<dt-text class="d-fw-bold" style="all: initial">x</dt-text>',
1257
+ `${CONFLICT}<dt-text class="d-fw-bold" style="all: initial">x</dt-text>`],
1258
+ ['bound style with a modifier', '<dt-text variant="body-md"\n :style.camel="{fontWeight: 400}"\n class="d-fw-bold">A</dt-text>',
1259
+ `${CONFLICT}<dt-text variant="body-md"\n :style.camel="{fontWeight: 400}"\n class="d-fw-bold">A</dt-text>`],
1260
+ ['comment before a static declaration', '<dt-text variant="body-md"\n style="/* note */font-weight: 400"\n class="d-fw-bold">A</dt-text>',
1261
+ `${CONFLICT}<dt-text variant="body-md"\n style="/* note */font-weight: 400"\n class="d-fw-bold">A</dt-text>`],
1262
+ ['comment delimiters inside CSS strings', `<dt-text class="d-fw-bold" style="--start: '/*'; font-weight: 400; --end: '*/'">A</dt-text>`,
1263
+ `${CONFLICT}<dt-text class="d-fw-bold" style="--start: '/*'; font-weight: 400; --end: '*/'">A</dt-text>`],
1264
+ ['escaped quote inside a CSS string', String.raw`<dt-text class="d-fw-bold" style="--a: 'it\'s /*'; font-weight: 400; --b: '*/'">A</dt-text>`,
1265
+ CONFLICT + String.raw`<dt-text class="d-fw-bold" style="--a: 'it\'s /*'; font-weight: 400; --b: '*/'">A</dt-text>`],
1266
+ ['escaped quote outside a CSS string', String.raw`<dt-text class="d-fw-bold" style="--a: \'; font-weight: 400; --b: 'tail'">A</dt-text>`,
1267
+ CONFLICT + String.raw`<dt-text class="d-fw-bold" style="--a: \'; font-weight: 400; --b: 'tail'">A</dt-text>`],
1268
+ ];
1269
+ for (const [label, input, expected] of cases) {
1270
+ it(label, () => { assert.equal(run(input), expected); });
1271
+ }
1272
+
1273
+ it('a class named like an Object prototype key stays an unknown class', () => {
1274
+ const input = '<span class="toString d-fw-bold">x</span>';
1275
+ assert.equal(run(input), input);
1276
+ });
1277
+ it('identical duplicates collapse to one prop', () => {
1278
+ assert.equal(run('<p class="d-body--md d-fw-bold d-fw-bold">x</p>'), '<dt-text as="p" variant="body-md" strength="bold">x</dt-text>');
1279
+ });
1280
+ // Comments, quotes and escapes need a CSS tokenizer to read reliably, so any of them
1281
+ // keeps every utility for review, whatever the style declares.
1282
+ for (const style of ['margin: 0 /* note */', 'content: \'x\'', String.raw`--a: \31`]) {
1283
+ it(`a style with a comment, quote or escape keeps every utility: ${style}`, () => {
1284
+ assert.equal(
1285
+ run(`<p class="d-body--md d-fw-bold" style="${style}">x</p>`),
1286
+ `${CONFLICT}<dt-text as="p" variant="body-md" class="d-fw-bold" style="${style}">x</dt-text>`,
1287
+ );
1288
+ });
1289
+ }
1290
+ // DtText's truncate prop adds the same !important d-truncate class, so no style changes
1291
+ // what renders.
1292
+ for (const style of ['white-space: normal', 'overflow: visible']) {
1293
+ it(`d-truncate converts despite an inline style: ${style}`, () => {
1294
+ assert.equal(
1295
+ run(`<p class="d-body--md d-truncate" style="${style}">x</p>`),
1296
+ `<dt-text as="p" variant="body-md" truncate style="${style}">x</dt-text>`,
1297
+ );
1298
+ });
1299
+ }
1300
+ it('d-truncate converts despite a bound style', () => {
1301
+ assert.equal(
1302
+ run('<p class="d-body--md d-truncate" :style="s">x</p>'),
1303
+ '<dt-text as="p" variant="body-md" truncate :style="s">x</dt-text>',
1304
+ );
1305
+ });
1306
+ it('inline style on another property does not block the lift', () => {
1307
+ assert.equal(
1308
+ run('<p class="d-body--md d-fw-bold" style="margin: 0">x</p>'),
1309
+ '<dt-text as="p" variant="body-md" strength="bold" style="margin: 0">x</dt-text>',
1310
+ );
1311
+ });
1312
+ });
1313
+
1314
+ describe('multiple composed classes', () => {
1315
+ const MULTIPLE = '<!-- dt-text-migrate: review multiple composed classes -->';
1316
+ it('aliases with identical mappings collapse', () => {
1317
+ assert.equal(run('<p class="d-body--md d-body-base">x</p>'), '<dt-text as="p" variant="body-md">x</dt-text>');
1318
+ });
1319
+ for (const classes of ['d-body--md d-label--sm', 'd-headline--sm d-headline--sm-soft']) {
1320
+ it(`different mappings stay unchanged: ${classes}`, () => {
1321
+ const input = `<p class="${classes}">x</p>`;
1322
+ assert.equal(run(input), MULTIPLE + input);
1323
+ });
1324
+ }
1325
+ });
1326
+
1327
+ describe('nested spans rejected by the composed pass are not retried', () => {
1328
+ const cases = [
1329
+ ['composed span wrapping a component', '<dt-text kind="body"><span class="d-body--sm"><dt-icon name="x" /></span></dt-text>',
1330
+ '<dt-text kind="body"><!-- dt-text-migrate: review composed class on wrapper --><span class="d-body--sm"><dt-icon name="x" /></span></dt-text>'],
1331
+ ['span with different compositions', '<dt-text kind="body"><span class="d-body--sm d-label--sm">x</span></dt-text>',
1332
+ '<dt-text kind="body"><!-- dt-text-migrate: review multiple composed classes --><span class="d-body--sm d-label--sm">x</span></dt-text>'],
1333
+ ['override span wrapping a component', '<dt-text kind="body"><span class="d-fw-bold"><dt-icon name="x" /></span></dt-text>',
1334
+ '<dt-text kind="body"><!-- dt-text-migrate: review nested span --><span class="d-fw-bold"><dt-icon name="x" /></span></dt-text>'],
1335
+ ];
1336
+ for (const [label, input, expected] of cases) {
1337
+ it(label, () => { assert.equal(run(input), expected); });
1338
+ }
1339
+ it('a span inside nested DtText bodies is edited once', () => {
1340
+ assert.equal(
1341
+ run('<dt-text><dt-text><span id="x" class="d-fw-bold">x</span></dt-text></dt-text>'),
1342
+ '<dt-text><dt-text><!-- dt-text-migrate: review nested span --><span id="x" class="d-fw-bold">x</span></dt-text></dt-text>',
1343
+ );
1344
+ });
1345
+ });
1346
+
1347
+ describe('raw font-size hints', () => {
1348
+ const cases = [
1349
+ ['token beside a generated variant', '<p class="d-headline--lg-compact d-fs-250">x</p>',
1350
+ '<!-- dt-text-migrate: review d-fs-250 (raw font-size token; size="250" can replace it alongside variant) --><dt-text as="p" variant="headline-xl" density="200" class="d-fs-250">x</dt-text>'],
1351
+ ['token without a composition', '<span class="d-fs-250">x</span>',
1352
+ '<!-- dt-text-migrate: review d-fs-250 (raw font-size token; size="250" needs a variant, which font size alone does not determine) --><span class="d-fs-250">x</span>'],
1353
+ ['unknown token', '<span class="d-fs-900">x</span>',
1354
+ '<!-- dt-text-migrate: review d-fs-900 (no matching DtText size token; keep class) --><span class="d-fs-900">x</span>'],
1355
+ ['token beside a helper marker', '<p class="d-helper--md d-fs-250">x</p>',
1356
+ '<!-- dt-text-migrate: review helper --><!-- dt-text-migrate: review d-fs-250 (raw font-size token; size="250" can replace it alongside variant) --><dt-text as="p" variant="body-md" density="300" class="d-fs-250">x</dt-text>'],
1357
+ ];
1358
+ for (const [label, input, expected] of cases) {
1359
+ it(label, () => { assert.equal(run(input), expected); });
1360
+ }
1361
+ });
1362
+
1363
+ describe('reruns are byte-identical, including review markers', () => {
1364
+ const inputs = [
1365
+ ['eyebrow', '<p class="d-headline--eyebrow">x</p>'],
1366
+ ['code-small', '<p class="d-code--sm">x</p>'],
1367
+ ['helper', '<p class="d-helper--md">x</p>'],
1368
+ ['raw size', '<p class="d-headline--lg-compact d-fs-250">x</p>'],
1369
+ ['legacy heading', '<h2 class="d-fw-bold d-fs-300">x</h2>'],
1370
+ ['conflicting utilities', '<p class="d-body--md d-fw-bold d-fw-normal" id="a">x</p>'],
1371
+ ['authored conflict', '<dt-text strength="bold" class="d-fw-normal" id="a">x</dt-text>'],
1372
+ ['protected composition', '<dt-text kind="body" size="100" class="d-headline--md">x</dt-text>'],
1373
+ ['multiple composed', '<p class="d-body--md d-label--sm">x</p>'],
1374
+ ['nested wrapper', '<p class="d-headline--md"><span class="d-body--sm"><dt-icon name="x" /></span></p>'],
1375
+ ['helper with raw size', '<p class="d-helper--md d-fs-250">x</p>'],
1376
+ ['flagged parent with a converted child', '<p class="d-headline--eyebrow">Step <span class="d-fw-bold">1</span></p>'],
1377
+ ['own-line and inline markers', '<div>\n <p :class="{ \'d-body--md\': c }">x</p><p class="d-code--sm">y</p>\n</div>'],
1378
+ ['unrelated comment', '<!-- keep -->\n<p class="d-code--sm">x</p>'],
1379
+ ['native attribute that may become a prop', '<span class="d-body--md" v-bind="{size:300}">A</span>'],
1380
+ ['kept span inside DtText', '<dt-text kind="body"><span class="d-fw-bold" variant="headline-xl">A</span></dt-text>'],
1381
+ ];
1382
+ for (const [label, input] of inputs) {
1383
+ it(label, () => {
1384
+ const once = run(input);
1385
+ assert.equal(run(once), once);
1386
+ });
1387
+ }
1388
+ it('keeps an unrelated comment once', () => {
1389
+ const out = run(run('<!-- keep --><p class="d-code--sm">x</p>'));
1390
+ assert.equal(out, '<!-- keep --><!-- dt-text-migrate: review --><p class="d-code--sm">x</p>');
1391
+ });
1392
+ });
1393
+
1394
+ describe('marker deduplication leaves script and style content unchanged', () => {
1395
+ const PAIR = '<!-- dt-text-migrate: review --><!-- dt-text-migrate: review -->';
1396
+ const cases = [
1397
+ ['script string', `<script>\nconst example = \`${PAIR}\`;\n</script>`],
1398
+ ['CSS content string', `<style>\n.x::after { content: "${PAIR}"; }\n</style>`],
1399
+ ];
1400
+ for (const [label, inert] of cases) {
1401
+ it(label, () => {
1402
+ assert.equal(run(`<p class="d-body--md">A</p>\n${inert}`), `<dt-text as="p" variant="body-md">A</dt-text>\n${inert}`);
1403
+ });
1404
+ }
1405
+ });
1406
+
1125
1407
  // ---------------------------------------------------------------------------
1126
1408
  // injectComponentImport — auto import insertion
1127
1409
  // ---------------------------------------------------------------------------