@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.
- package/lib/build/js/dialtone_migrate/index.mjs +2 -2
- package/lib/build/js/dialtone_migrate/test.mjs +26 -9
- package/lib/build/js/dialtone_migrate_typography/index.mjs +483 -455
- package/lib/build/js/dialtone_migrate_typography/test.mjs +426 -144
- package/lib/build/less/components/dropdown.less +16 -0
- package/lib/build/less/components/filter-pill.less +24 -0
- package/lib/build/less/components/stack.less +21 -0
- package/lib/build/less/components/toggle.less +1 -0
- package/lib/dist/dialtone-default-theme.css +124 -0
- package/lib/dist/dialtone-default-theme.min.css +1 -1
- package/lib/dist/dialtone-docs.json +1 -1
- package/lib/dist/dialtone.css +124 -0
- package/lib/dist/dialtone.min.css +1 -1
- package/lib/dist/js/dialtone_migrate/index.mjs +2 -2
- package/lib/dist/js/dialtone_migrate/test.mjs +26 -9
- package/lib/dist/js/dialtone_migrate_typography/index.mjs +483 -455
- package/lib/dist/js/dialtone_migrate_typography/test.mjs +426 -144
- package/lib/dist/no-layers/dialtone-default-theme.css +122 -0
- package/lib/dist/no-layers/dialtone-default-theme.min.css +1 -1
- package/lib/dist/no-layers/dialtone.css +122 -0
- package/lib/dist/no-layers/dialtone.min.css +1 -1
- package/package.json +1 -1
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @fileoverview Migration script to convert legacy typography utility classes to <dt-text> components.
|
|
7
|
+
* Composed classes become a DtText `variant`; override utilities become modifier props.
|
|
7
8
|
*
|
|
8
|
-
* Usage:
|
|
9
|
-
*
|
|
9
|
+
* Usage (no standalone bin; run the installed script or the dialtone-migrate runner):
|
|
10
|
+
* node <dialtone>/lib/dist/js/dialtone_migrate_typography/index.mjs [options]
|
|
11
|
+
* npx dialtone-migrate --only typography [options]
|
|
10
12
|
*
|
|
11
13
|
* Options:
|
|
12
14
|
* --cwd <path> Working directory (default: current directory)
|
|
@@ -17,9 +19,9 @@
|
|
|
17
19
|
* --help Show help
|
|
18
20
|
*
|
|
19
21
|
* Examples:
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
22
|
+
* node <script> --dry-run --cwd ./src
|
|
23
|
+
* node <script> --yes
|
|
24
|
+
* node <script> --remove-markers --cwd ./src
|
|
23
25
|
*/
|
|
24
26
|
|
|
25
27
|
import fs from 'fs/promises';
|
|
@@ -31,99 +33,106 @@ import { fileURLToPath } from 'node:url';
|
|
|
31
33
|
//------------------------------------------------------------------------------
|
|
32
34
|
// Class-to-Prop Mapping Tables
|
|
33
35
|
// Validated against packages/dialtone-tokens/tokens/theme/dp/default.json
|
|
34
|
-
// and packages/dialtone-vue/components/Text/TextConstants.js
|
|
36
|
+
// and packages/dialtone-vue/components/Text/TextConstants.js. Each variant renders
|
|
37
|
+
// the composition class that the legacy kind + size pair rendered (tests assert this).
|
|
35
38
|
//------------------------------------------------------------------------------
|
|
36
39
|
|
|
40
|
+
// Lookup tables are keyed by class names and attribute values read from the scanned file,
|
|
41
|
+
// so they must not inherit Object.prototype keys such as `constructor` or `toString`.
|
|
42
|
+
const lookupTable = entries => Object.assign(Object.create(null), entries);
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Composed typography class → DtText props.
|
|
46
|
+
* Never emit a composition `size` beside `variant`: with a variant, size is a raw
|
|
47
|
+
* font-size override.
|
|
39
48
|
* `flag` marks classes that cannot be safely auto-migrated.
|
|
40
49
|
* - 'eyebrow' : uses text-transform:uppercase — no DtText prop
|
|
41
50
|
* - 'code-sm' : font-size below DtText minimum code size
|
|
42
51
|
* - 'helper' : approximated as body+density — outputs review marker too
|
|
43
52
|
*/
|
|
44
|
-
const COMPOSED_CLASS_MAP = {
|
|
53
|
+
const COMPOSED_CLASS_MAP = lookupTable({
|
|
45
54
|
// headline
|
|
46
|
-
'd-headline--sm': {
|
|
47
|
-
'd-headline-small': {
|
|
48
|
-
'd-headline--md': {
|
|
49
|
-
'd-headline-medium': {
|
|
50
|
-
'd-headline--lg': {
|
|
51
|
-
'd-headline-large': {
|
|
52
|
-
'd-headline--xl': {
|
|
53
|
-
'd-headline-extra-large': {
|
|
54
|
-
'd-headline--xxl': {
|
|
55
|
-
'd-headline-extra-extra-large': {
|
|
55
|
+
'd-headline--sm': { variant: 'headline-xs' },
|
|
56
|
+
'd-headline-small': { variant: 'headline-xs' },
|
|
57
|
+
'd-headline--md': { variant: 'headline-md' },
|
|
58
|
+
'd-headline-medium': { variant: 'headline-md' },
|
|
59
|
+
'd-headline--lg': { variant: 'headline-xl' },
|
|
60
|
+
'd-headline-large': { variant: 'headline-xl' },
|
|
61
|
+
'd-headline--xl': { variant: 'headline-2xl' },
|
|
62
|
+
'd-headline-extra-large': { variant: 'headline-2xl' },
|
|
63
|
+
'd-headline--xxl': { variant: 'headline-3xl' },
|
|
64
|
+
'd-headline-extra-extra-large': { variant: 'headline-3xl' },
|
|
56
65
|
|
|
57
66
|
// headline — eyebrow (unmappable: text-transform:uppercase)
|
|
58
67
|
'd-headline--eyebrow': { flag: 'eyebrow' },
|
|
59
68
|
'd-headline-eyebrow': { flag: 'eyebrow' },
|
|
60
69
|
|
|
61
70
|
// headline — soft variants (strength=medium per token)
|
|
62
|
-
'd-headline--sm-soft': {
|
|
63
|
-
'd-headline-soft-small': {
|
|
64
|
-
'd-headline--lg-soft': {
|
|
71
|
+
'd-headline--sm-soft': { variant: 'headline-xs', strength: 'medium' },
|
|
72
|
+
'd-headline-soft-small': { variant: 'headline-xs', strength: 'medium' },
|
|
73
|
+
'd-headline--lg-soft': { variant: 'headline-xl', strength: 'medium' },
|
|
65
74
|
|
|
66
75
|
// headline — compact variants
|
|
67
|
-
'd-headline--sm-compact': {
|
|
68
|
-
'd-headline-compact-small': {
|
|
69
|
-
'd-headline--md-compact': {
|
|
70
|
-
'd-headline-compact-medium': {
|
|
71
|
-
'd-headline--lg-compact': {
|
|
72
|
-
'd-headline-compact-large': {
|
|
73
|
-
'd-headline--xl-compact': {
|
|
74
|
-
'd-headline--xxl-compact': {
|
|
76
|
+
'd-headline--sm-compact': { variant: 'headline-xs', density: '200' },
|
|
77
|
+
'd-headline-compact-small': { variant: 'headline-xs', density: '200' },
|
|
78
|
+
'd-headline--md-compact': { variant: 'headline-md', density: '300' },
|
|
79
|
+
'd-headline-compact-medium': { variant: 'headline-md', density: '300' },
|
|
80
|
+
'd-headline--lg-compact': { variant: 'headline-xl', density: '200' },
|
|
81
|
+
'd-headline-compact-large': { variant: 'headline-xl', density: '200' },
|
|
82
|
+
'd-headline--xl-compact': { variant: 'headline-2xl', density: '100' },
|
|
83
|
+
'd-headline--xxl-compact': { variant: 'headline-3xl' }, // same lh=200 as base, no density
|
|
75
84
|
|
|
76
85
|
// headline — soft-compact
|
|
77
|
-
'd-headline--sm-soft-compact': {
|
|
78
|
-
'd-headline-compact-soft-small': {
|
|
79
|
-
'd-headline--lg-soft-compact': {
|
|
86
|
+
'd-headline--sm-soft-compact': { variant: 'headline-xs', strength: 'medium', density: '200' },
|
|
87
|
+
'd-headline-compact-soft-small': { variant: 'headline-xs', strength: 'medium', density: '200' },
|
|
88
|
+
'd-headline--lg-soft-compact': { variant: 'headline-xl', strength: 'medium', density: '200' },
|
|
80
89
|
|
|
81
90
|
// body
|
|
82
|
-
'd-body--md': {
|
|
83
|
-
'd-body-base': {
|
|
84
|
-
'd-body--sm': {
|
|
85
|
-
'd-body-small': {
|
|
86
|
-
'd-body--md-compact': {
|
|
87
|
-
'd-body-compact': {
|
|
88
|
-
'd-body--sm-compact': {
|
|
89
|
-
'd-body-compact-small': {
|
|
91
|
+
'd-body--md': { variant: 'body-md' },
|
|
92
|
+
'd-body-base': { variant: 'body-md' },
|
|
93
|
+
'd-body--sm': { variant: 'body-xs' },
|
|
94
|
+
'd-body-small': { variant: 'body-xs' },
|
|
95
|
+
'd-body--md-compact': { variant: 'body-md', density: '300' },
|
|
96
|
+
'd-body-compact': { variant: 'body-md', density: '300' },
|
|
97
|
+
'd-body--sm-compact': { variant: 'body-xs', density: '200' },
|
|
98
|
+
'd-body-compact-small': { variant: 'body-xs', density: '200' },
|
|
90
99
|
|
|
91
100
|
// label
|
|
92
|
-
'd-label--md': {
|
|
93
|
-
'd-label-base': {
|
|
94
|
-
'd-label--sm': {
|
|
95
|
-
'd-label-small': {
|
|
96
|
-
'd-label--md-compact': {
|
|
97
|
-
'd-label-compact': {
|
|
98
|
-
'd-label--sm-compact': {
|
|
99
|
-
'd-label-compact-small': {
|
|
100
|
-
'd-label--md-plain': {
|
|
101
|
-
'd-label-plain': {
|
|
102
|
-
'd-label--md-plain-compact': {
|
|
103
|
-
'd-label-compact-plain': {
|
|
104
|
-
'd-label--sm-plain': {
|
|
105
|
-
'd-label-plain-small': {
|
|
106
|
-
'd-label--sm-plain-compact': {
|
|
107
|
-
'd-label-compact-plain-small': {
|
|
101
|
+
'd-label--md': { variant: 'label-md' },
|
|
102
|
+
'd-label-base': { variant: 'label-md' },
|
|
103
|
+
'd-label--sm': { variant: 'label-xs' },
|
|
104
|
+
'd-label-small': { variant: 'label-xs' },
|
|
105
|
+
'd-label--md-compact': { variant: 'label-md', density: '300' },
|
|
106
|
+
'd-label-compact': { variant: 'label-md', density: '300' },
|
|
107
|
+
'd-label--sm-compact': { variant: 'label-xs', density: '200' },
|
|
108
|
+
'd-label-compact-small': { variant: 'label-xs', density: '200' },
|
|
109
|
+
'd-label--md-plain': { variant: 'label-md', strength: 'normal' },
|
|
110
|
+
'd-label-plain': { variant: 'label-md', strength: 'normal' },
|
|
111
|
+
'd-label--md-plain-compact': { variant: 'label-md', strength: 'normal', density: '300' },
|
|
112
|
+
'd-label-compact-plain': { variant: 'label-md', strength: 'normal', density: '300' },
|
|
113
|
+
'd-label--sm-plain': { variant: 'label-xs', strength: 'normal' },
|
|
114
|
+
'd-label-plain-small': { variant: 'label-xs', strength: 'normal' },
|
|
115
|
+
'd-label--sm-plain-compact': { variant: 'label-xs', strength: 'normal', density: '200' },
|
|
116
|
+
'd-label-compact-plain-small': { variant: 'label-xs', strength: 'normal', density: '200' },
|
|
108
117
|
|
|
109
118
|
// code
|
|
110
|
-
'd-code--md': {
|
|
111
|
-
'd-code-base': {
|
|
119
|
+
'd-code--md': { variant: 'code-sm' },
|
|
120
|
+
'd-code-base': { variant: 'code-sm' },
|
|
112
121
|
'd-code--sm': { flag: 'code-sm' }, // font-size below DtText minimum
|
|
113
122
|
'd-code-small': { flag: 'code-sm' },
|
|
114
123
|
|
|
115
124
|
// helper — approximated as body+density, flagged for review
|
|
116
|
-
'd-helper--md': {
|
|
117
|
-
'd-helper-base': {
|
|
118
|
-
'd-helper--sm': {
|
|
119
|
-
'd-helper-small': {
|
|
120
|
-
};
|
|
125
|
+
'd-helper--md': { variant: 'body-md', density: '300', flag: 'helper' },
|
|
126
|
+
'd-helper-base': { variant: 'body-md', density: '300', flag: 'helper' },
|
|
127
|
+
'd-helper--sm': { variant: 'body-xs', density: '200', flag: 'helper' },
|
|
128
|
+
'd-helper-small': { variant: 'body-xs', density: '200', flag: 'helper' },
|
|
129
|
+
});
|
|
121
130
|
|
|
122
131
|
/**
|
|
123
132
|
* Override utility class → DtText prop name and value.
|
|
124
133
|
* These apply on top of (or independently from) composed class rewrites.
|
|
125
134
|
*/
|
|
126
|
-
const OVERRIDE_CLASS_MAP = {
|
|
135
|
+
const OVERRIDE_CLASS_MAP = lookupTable({
|
|
127
136
|
// font-weight → strength
|
|
128
137
|
'd-fw-bold': { prop: 'strength', value: 'bold' },
|
|
129
138
|
'd-fw-semibold': { prop: 'strength', value: 'semibold' },
|
|
@@ -164,9 +173,50 @@ const OVERRIDE_CLASS_MAP = {
|
|
|
164
173
|
'd-ta-center': { prop: 'align', value: 'center' },
|
|
165
174
|
'd-ta-justify': { prop: 'align', value: 'justify' },
|
|
166
175
|
|
|
167
|
-
// font-family →
|
|
168
|
-
|
|
169
|
-
}
|
|
176
|
+
// font-family → family. Only the family changes; size, weight and line height still
|
|
177
|
+
// inherit, so it never implies a composition.
|
|
178
|
+
'd-ff-mono': { prop: 'family', value: 'mono' },
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Lifting an override moves it from an !important utility to a normal DtText modifier.
|
|
182
|
+
// Inline styles beat the modifier but not the utility, so a style that sets the same
|
|
183
|
+
// CSS property makes the lift unsafe.
|
|
184
|
+
const OVERRIDE_STYLE_PROPERTIES = lookupTable({
|
|
185
|
+
strength: ['font-weight', 'font'],
|
|
186
|
+
density: ['line-height', 'font'],
|
|
187
|
+
family: ['font-family', 'font'],
|
|
188
|
+
tone: ['color'],
|
|
189
|
+
align: ['text-align'],
|
|
190
|
+
// No truncate: DtText's truncate prop adds the same !important d-truncate class, so an
|
|
191
|
+
// inline style cannot change what renders.
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// DtText values mirrored from packages/dialtone-vue/components/Text/TextConstants.js for
|
|
195
|
+
// --validate. The script must not import Vue source at runtime; tests assert parity.
|
|
196
|
+
const TEXT_VARIANTS = new Set([
|
|
197
|
+
'headline-3xl', 'headline-2xl', 'headline-xl', 'headline-lg', 'headline-md', 'headline-sm', 'headline-xs',
|
|
198
|
+
'body-lg', 'body-md', 'body-sm', 'body-xs',
|
|
199
|
+
'label-lg', 'label-md', 'label-sm', 'label-xs',
|
|
200
|
+
'code-lg', 'code-md', 'code-sm', 'code-xs',
|
|
201
|
+
]);
|
|
202
|
+
const TEXT_FAMILIES = new Set(['inherit', 'custom', 'sans', 'mono', 'expressive']);
|
|
203
|
+
// Raw font-size tokens: valid `size` values beside a variant, and the d-fs-* utility scale.
|
|
204
|
+
const TEXT_FONT_SIZES = new Set([
|
|
205
|
+
'50', '75', '100', '125', '150', '200', '250', '300', '350',
|
|
206
|
+
'400', '450', '500', '550', '600', '650', '700', '750', '800',
|
|
207
|
+
]);
|
|
208
|
+
// Legacy composition sizes, valid only with kind and no variant.
|
|
209
|
+
const TEXT_KIND_SIZES = lookupTable({
|
|
210
|
+
headline: ['700', '600', '500', '400', '300', '200', '100', '3xl', '2xl', 'xl', 'lg', 'md', 'sm', 'xs'],
|
|
211
|
+
body: ['400', '300', '200', '100', 'lg', 'md', 'sm', 'xs'],
|
|
212
|
+
label: ['400', '300', '200', '100', 'lg', 'md', 'sm', 'xs'],
|
|
213
|
+
code: ['400', '300', '200', '100', 'lg', 'md', 'sm', 'xs'],
|
|
214
|
+
});
|
|
215
|
+
// DtText prop names mirrored from packages/dialtone-vue/components/Text/Text.vue.
|
|
216
|
+
const TEXT_PROPS = new Set([
|
|
217
|
+
'as', 'kind', 'variant', 'size', 'family', 'italic', 'tone', 'align', 'truncate',
|
|
218
|
+
'maxLines', 'numeric', 'wrap', 'textBoxTrim', 'strength', 'density',
|
|
219
|
+
]);
|
|
170
220
|
|
|
171
221
|
// Rewriteable element tags (only these get turned into <dt-text>)
|
|
172
222
|
const REWRITEABLE_TAGS = new Set(['p', 'span', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'label']);
|
|
@@ -247,10 +297,10 @@ function maskInertContent (content) {
|
|
|
247
297
|
/**
|
|
248
298
|
* Restore masked segments back to their original content.
|
|
249
299
|
*/
|
|
250
|
-
function unmaskInertContent (content, segments, token, endToken) {
|
|
300
|
+
function unmaskInertContent (content, segments, token, endToken, restore = () => true) {
|
|
251
301
|
return content.replace(
|
|
252
302
|
new RegExp(`${escapeRe(token)}(\\d+)${escapeRe(endToken)}`, 'g'),
|
|
253
|
-
(
|
|
303
|
+
(match, idx) => (restore(segments[Number(idx)]) ? segments[Number(idx)] : match),
|
|
254
304
|
);
|
|
255
305
|
}
|
|
256
306
|
|
|
@@ -301,28 +351,43 @@ export function transformContent (content, opts = {}) {
|
|
|
301
351
|
out = flagLegacyHeadings(out, filePath, warnings, notes);
|
|
302
352
|
out = flagFontSizeClasses(out, filePath, warnings, notes);
|
|
303
353
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const transformed = deduplicateAdjacentMarkers(unmasked);
|
|
354
|
+
// Idempotency: a marker from a prior run is masked as a comment, so passes emit it
|
|
355
|
+
// again on rerun. Restore comments to drop repeats within each run of adjacent markers,
|
|
356
|
+
// inline or own-line, while <script> and <style> stay masked: a marker-like string there
|
|
357
|
+
// is application data.
|
|
358
|
+
const withComments = unmaskInertContent(out, segments, token, endToken, segment => segment.startsWith('<!--'));
|
|
359
|
+
const transformed = unmaskInertContent(deduplicateAdjacentMarkers(withComments), segments, token, endToken);
|
|
311
360
|
|
|
312
361
|
return { transformed, warnings, notes };
|
|
313
362
|
}
|
|
314
363
|
|
|
364
|
+
// Markers always precede the element they describe, so a marker repeated within one
|
|
365
|
+
// whitespace-separated run of markers is a rerun duplicate: earlier markers are masked
|
|
366
|
+
// as comments, so the passes cannot see them and emit them again. Drop the repeat, with
|
|
367
|
+
// its line when it has a line to itself. Any other content, including an unrelated
|
|
368
|
+
// comment, ends the run and is never touched.
|
|
315
369
|
function deduplicateAdjacentMarkers (content) {
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
for (const
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
370
|
+
const removals = [];
|
|
371
|
+
let seen = new Set();
|
|
372
|
+
let previousEnd = -1;
|
|
373
|
+
for (const m of content.matchAll(/<!--\s*dt-text-migrate:[\s\S]*?-->/g)) {
|
|
374
|
+
const start = m.index;
|
|
375
|
+
const end = start + m[0].length;
|
|
376
|
+
if (previousEnd === -1 || /\S/.test(content.slice(previousEnd, start))) seen = new Set();
|
|
377
|
+
previousEnd = end;
|
|
378
|
+
if (!seen.has(m[0])) {
|
|
379
|
+
seen.add(m[0]);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
const lineStart = content.lastIndexOf('\n', start - 1) + 1;
|
|
383
|
+
const lineEnd = content.indexOf('\n', end);
|
|
384
|
+
const ownLine = lineEnd !== -1 &&
|
|
385
|
+
!/\S/.test(content.slice(lineStart, start)) && !/\S/.test(content.slice(end, lineEnd));
|
|
386
|
+
removals.push(ownLine ? [lineStart, lineEnd + 1] : [start, end]);
|
|
324
387
|
}
|
|
325
|
-
|
|
388
|
+
let out = content;
|
|
389
|
+
for (const [start, end] of removals.reverse()) out = out.slice(0, start) + out.slice(end);
|
|
390
|
+
return out;
|
|
326
391
|
}
|
|
327
392
|
|
|
328
393
|
//------------------------------------------------------------------------------
|
|
@@ -392,65 +457,122 @@ function findMatchingClosingTag (content, startPos, tagName) {
|
|
|
392
457
|
return null;
|
|
393
458
|
}
|
|
394
459
|
|
|
460
|
+
const CONFLICT_MARKER = '<!-- dt-text-migrate: review conflicting class -->';
|
|
461
|
+
const NATIVE_PROP_MARKER = '<!-- dt-text-migrate: review attribute that may become a DtText prop -->';
|
|
462
|
+
const ALL_OVERRIDE_PROPS = new Set(Object.values(OVERRIDE_CLASS_MAP).map(override => override.prop));
|
|
463
|
+
const STYLE_OVERRIDE_PROPS = new Set(Object.keys(OVERRIDE_STYLE_PROPERTIES));
|
|
464
|
+
|
|
465
|
+
// Attribute names in an opening tag's attribute text. Quoted values are blanked first so
|
|
466
|
+
// text inside a value never reads as an attribute.
|
|
467
|
+
function attributeNames (attrStr) {
|
|
468
|
+
const stripped = attrStr.replace(/"[^"]*"|'[^']*'/g, '""');
|
|
469
|
+
return [...stripped.matchAll(/(?:^|\s)([^\s=/>"']+)/g)].map(m => m[1]);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// The DtText prop an attribute binds: `size`, `:size`, `v-bind:size`, `.size`,
|
|
473
|
+
// `:size.prop` and `v-model:size` all bind size.
|
|
474
|
+
function boundProp (name) {
|
|
475
|
+
return name.replace(/^(?::|\.|v-bind:|v-model:)/, '').split('.')[0];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Object spreads and dynamic argument names can supply any prop, or a style.
|
|
479
|
+
function hasUncertainBinding (names) {
|
|
480
|
+
return names.some(name => name === 'v-bind' || name.startsWith('v-bind.') ||
|
|
481
|
+
/^(?::|\.|v-bind:|v-model:)\[/.test(name));
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function hasAuthoredComposition (names) {
|
|
485
|
+
return names.some(name => ['kind', 'size', 'variant', 'family'].includes(boundProp(name)));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// A native element ignores attributes named like DtText props, but converting it makes
|
|
489
|
+
// them props: a size becomes a raw font-size override, a second variant duplicates the
|
|
490
|
+
// attribute and `as` changes the tag. A spread or dynamic name may supply any of them.
|
|
491
|
+
function mayBecomeTextProp (names) {
|
|
492
|
+
return hasUncertainBinding(names) ||
|
|
493
|
+
names.some(name => TEXT_PROPS.has(boundProp(name).replace(/-(\w)/g, (_, c) => c.toUpperCase())));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Props the element already authors, in any binding form: { [prop]: true }.
|
|
497
|
+
function parseExistingProps (names) {
|
|
498
|
+
const props = Object.create(null);
|
|
499
|
+
for (const name of names) props[boundProp(name)] = true;
|
|
500
|
+
return props;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Override props that cannot be lifted safely: every one for a spread or dynamic name,
|
|
504
|
+
// which may also supply the props themselves; every style-sensitive one for a bound style;
|
|
505
|
+
// otherwise the ones the static style declares.
|
|
506
|
+
function blockedOverrideProps (attrStr, names) {
|
|
507
|
+
if (hasUncertainBinding(names)) return ALL_OVERRIDE_PROPS;
|
|
508
|
+
// Any bound form counts, modifiers included: Vue compiles `:style.camel` to a style binding.
|
|
509
|
+
if (names.some(name => name !== 'style' && boundProp(name) === 'style')) return STYLE_OVERRIDE_PROPS;
|
|
510
|
+
const style = /(?:^|\s)style\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(attrStr);
|
|
511
|
+
if (!style) return new Set();
|
|
512
|
+
const declarations = style[1] ?? style[2];
|
|
513
|
+
// Comments, quoted strings and escapes need a CSS tokenizer to read reliably. They are
|
|
514
|
+
// rare in inline styles, so treat them like a bound style.
|
|
515
|
+
if (/\/\*|["'\\]/.test(declarations)) return STYLE_OVERRIDE_PROPS;
|
|
516
|
+
const declared = new Set(
|
|
517
|
+
[...declarations.matchAll(/(?:^|;)\s*([\w-]+)\s*:/g)].map(m => m[1].toLowerCase()),
|
|
518
|
+
);
|
|
519
|
+
if (declared.has('all')) return STYLE_OVERRIDE_PROPS; // `all` resets every property
|
|
520
|
+
return new Set(Object.keys(OVERRIDE_STYLE_PROPERTIES)
|
|
521
|
+
.filter(prop => OVERRIDE_STYLE_PROPERTIES[prop].some(property => declared.has(property))));
|
|
522
|
+
}
|
|
523
|
+
|
|
395
524
|
/**
|
|
396
|
-
* Split a class list into override props
|
|
397
|
-
*
|
|
398
|
-
* `
|
|
525
|
+
* Split a class list into liftable override props and the classes to keep.
|
|
526
|
+
* A prop stays as its utility class (and sets `conflict`) when the element already
|
|
527
|
+
* authors it, when `blocked` marks it unsafe, or when utilities disagree on its value.
|
|
528
|
+
* The class is kept because it may be what wins in CSS today.
|
|
529
|
+
* Returns { overrideProps: [{prop, value}], remaining: string[], conflict: boolean }.
|
|
399
530
|
*/
|
|
400
|
-
function extractOverrideProps (classes,
|
|
401
|
-
const
|
|
402
|
-
const remaining = [];
|
|
403
|
-
const conflictClasses = [];
|
|
404
|
-
|
|
531
|
+
function extractOverrideProps (classes, authored = {}, blocked = new Set()) {
|
|
532
|
+
const byProp = new Map();
|
|
405
533
|
for (const cls of classes) {
|
|
406
534
|
const override = OVERRIDE_CLASS_MAP[cls];
|
|
407
|
-
if (!override)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
535
|
+
if (!override) continue;
|
|
536
|
+
if (!byProp.has(override.prop)) byProp.set(override.prop, []);
|
|
537
|
+
byProp.get(override.prop).push(cls);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const overrideProps = [];
|
|
541
|
+
const kept = new Set();
|
|
542
|
+
for (const [prop, list] of byProp) {
|
|
543
|
+
const values = new Set(list.map(cls => OVERRIDE_CLASS_MAP[cls].value));
|
|
544
|
+
if (prop in authored || blocked.has(prop) || values.size > 1) {
|
|
545
|
+
list.forEach(cls => kept.add(cls));
|
|
415
546
|
continue;
|
|
416
547
|
}
|
|
417
|
-
|
|
418
|
-
if (!overrideProps.some(p => p.prop === prop)) {
|
|
419
|
-
overrideProps.push({ prop, value });
|
|
420
|
-
}
|
|
548
|
+
overrideProps.push({ prop, value: OVERRIDE_CLASS_MAP[list[0]].value });
|
|
421
549
|
}
|
|
422
550
|
|
|
423
|
-
|
|
551
|
+
const remaining = classes.filter(cls => !OVERRIDE_CLASS_MAP[cls] || kept.has(cls));
|
|
552
|
+
return { overrideProps, remaining, conflict: kept.size > 0 };
|
|
424
553
|
}
|
|
425
554
|
|
|
555
|
+
// Canonical prop order: as → variant → family → strength → density → tone → align →
|
|
556
|
+
// truncate → class. Directives, data attributes and events follow from the original tag.
|
|
557
|
+
const PROP_ORDER = ['variant', 'family', 'strength', 'density', 'tone', 'align', 'truncate'];
|
|
558
|
+
|
|
426
559
|
/**
|
|
427
|
-
* Build a <dt-text> opening tag from
|
|
428
|
-
*
|
|
560
|
+
* Build a <dt-text> opening tag from a composed-class mapping entry, the classes left
|
|
561
|
+
* after removing composed classes, and the element's other attributes.
|
|
429
562
|
*/
|
|
430
563
|
function buildDtTextTag (opts) {
|
|
431
|
-
const { originalTag,
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const { overrideProps, remaining, conflictClasses } = extractOverrideProps(retainedClasses, existingProps);
|
|
441
|
-
|
|
442
|
-
// Consolidate props into canonical order matching beacon's convention:
|
|
443
|
-
// as → kind → size → strength → density → tone → align → boolean (truncate, numeric) → class
|
|
444
|
-
// (directives/data-attrs/events flow through attrsBefore/attrsAfter from the original tag)
|
|
445
|
-
const finalProps = {};
|
|
446
|
-
if (kind) finalProps.kind = kind;
|
|
447
|
-
if (size) finalProps.size = size;
|
|
448
|
-
if (strength) finalProps.strength = strength;
|
|
449
|
-
if (density) finalProps.density = density;
|
|
450
|
-
for (const { prop, value } of overrideProps) {
|
|
451
|
-
// Override classes win over composed defaults if conflicting (e.g. d-fw-bold overrides headline-soft's medium)
|
|
452
|
-
finalProps[prop] = value;
|
|
564
|
+
const { originalTag, entry, retainedClasses, attrsBefore, attrsAfter, selfClosing, authored, blocked } = opts;
|
|
565
|
+
const { overrideProps, remaining, conflict } = extractOverrideProps(retainedClasses, authored, blocked);
|
|
566
|
+
|
|
567
|
+
const finalProps = { variant: entry.variant };
|
|
568
|
+
for (const prop of ['strength', 'density']) {
|
|
569
|
+
// Authored DtText props already beat the composed class in CSS (components layer
|
|
570
|
+
// over base), so the generated default yields to them.
|
|
571
|
+
if (entry[prop] && !(prop in authored)) finalProps[prop] = entry[prop];
|
|
453
572
|
}
|
|
573
|
+
// Override utilities are !important, so they also beat the composition's defaults:
|
|
574
|
+
// d-fw-bold on a soft headline renders bold today.
|
|
575
|
+
for (const { prop, value } of overrideProps) finalProps[prop] = value;
|
|
454
576
|
|
|
455
577
|
let tag = '<dt-text';
|
|
456
578
|
|
|
@@ -459,16 +581,10 @@ function buildDtTextTag (opts) {
|
|
|
459
581
|
tag += ` as="${originalTag}"`;
|
|
460
582
|
}
|
|
461
583
|
|
|
462
|
-
// Canonical order
|
|
463
|
-
const PROP_ORDER = ['kind', 'size', 'strength', 'density', 'tone', 'align', 'truncate', 'numeric'];
|
|
464
584
|
for (const prop of PROP_ORDER) {
|
|
465
585
|
if (!(prop in finalProps)) continue;
|
|
466
586
|
const value = finalProps[prop];
|
|
467
|
-
|
|
468
|
-
tag += ` ${prop}`; // boolean prop (e.g. truncate)
|
|
469
|
-
} else {
|
|
470
|
-
tag += ` ${prop}="${value}"`;
|
|
471
|
-
}
|
|
587
|
+
tag += value === null ? ` ${prop}` : ` ${prop}="${value}"`; // null → boolean prop (truncate)
|
|
472
588
|
}
|
|
473
589
|
|
|
474
590
|
if (remaining.length > 0) {
|
|
@@ -478,12 +594,7 @@ function buildDtTextTag (opts) {
|
|
|
478
594
|
if (attrsBefore) tag += ` ${attrsBefore}`;
|
|
479
595
|
if (attrsAfter) tag += ` ${attrsAfter}`;
|
|
480
596
|
|
|
481
|
-
|
|
482
|
-
const conflictComment = conflictClasses.length > 0
|
|
483
|
-
? '<!-- dt-text-migrate: review conflicting class -->'
|
|
484
|
-
: '';
|
|
485
|
-
|
|
486
|
-
return conflictComment + openTag;
|
|
597
|
+
return (conflict ? CONFLICT_MARKER : '') + tag + (selfClosing ? ' />' : '>');
|
|
487
598
|
}
|
|
488
599
|
|
|
489
600
|
// True if any class signals layout intent (display utility).
|
|
@@ -508,9 +619,19 @@ function hasBlockOrComponentChild (body) {
|
|
|
508
619
|
return false;
|
|
509
620
|
}
|
|
510
621
|
|
|
622
|
+
// Composed classes collapse only when every mapping field matches.
|
|
623
|
+
function sameMapping (a, b) {
|
|
624
|
+
return ['variant', 'strength', 'density', 'flag'].every(key => a[key] === b[key]);
|
|
625
|
+
}
|
|
626
|
+
|
|
511
627
|
function rewriteComposedClasses (content) {
|
|
512
628
|
const elementRe = new RegExp(ELEMENT_RE.source, 'g');
|
|
513
|
-
const
|
|
629
|
+
const replacements = [];
|
|
630
|
+
const mark = (start, review) => replacements.push({
|
|
631
|
+
start,
|
|
632
|
+
end: start,
|
|
633
|
+
replacement: `<!-- dt-text-migrate: ${review} -->`,
|
|
634
|
+
});
|
|
514
635
|
|
|
515
636
|
let m;
|
|
516
637
|
while ((m = elementRe.exec(content)) !== null) {
|
|
@@ -520,159 +641,73 @@ function rewriteComposedClasses (content) {
|
|
|
520
641
|
if (/(?:^|\s):class\b|(?:^|\s)v-bind:class\b/.test(attrsBefore + attrsAfter)) continue;
|
|
521
642
|
|
|
522
643
|
const classes = classValue.split(/\s+/).filter(Boolean);
|
|
644
|
+
const composed = classes.filter(cls => COMPOSED_CLASS_MAP[cls]);
|
|
645
|
+
if (composed.length === 0) continue;
|
|
523
646
|
|
|
524
|
-
// Find the first composed class in the class list
|
|
525
|
-
const composedEntry = classes.reduce((found, cls) => {
|
|
526
|
-
return found || (COMPOSED_CLASS_MAP[cls] ? { cls, entry: COMPOSED_CLASS_MAP[cls] } : null);
|
|
527
|
-
}, null);
|
|
528
|
-
|
|
529
|
-
if (!composedEntry) continue;
|
|
530
|
-
|
|
531
|
-
const { cls: composedCls, entry } = composedEntry;
|
|
532
|
-
|
|
533
|
-
// Only rewrite native rewriteable tags; skip if already dt-text (handled in Task 3)
|
|
534
|
-
const isNativeRewriteable = REWRITEABLE_TAGS.has(tagName.toLowerCase());
|
|
535
647
|
const isDtText = tagName === 'dt-text' || tagName === 'DtText';
|
|
536
|
-
if (!isNativeRewriteable && !isDtText) continue;
|
|
537
|
-
|
|
538
|
-
const retainedClasses = classes.filter(c => c !== composedCls);
|
|
539
|
-
const isSelfClosing = selfClosing === '/';
|
|
540
648
|
const openStart = m.index;
|
|
541
649
|
const openEnd = m.index + fullMatch.length;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
closeEnd = closing.index + closing.length;
|
|
552
|
-
closeReplacement = '</dt-text>';
|
|
553
|
-
}
|
|
650
|
+
const entry = COMPOSED_CLASS_MAP[composed[0]];
|
|
651
|
+
const attrs = `${attrsBefore} ${attrsAfter}`;
|
|
652
|
+
const names = attributeNames(attrs);
|
|
653
|
+
|
|
654
|
+
// Different compositions on one element: class order does not decide CSS precedence,
|
|
655
|
+
// so there is no safe single variant.
|
|
656
|
+
if (!composed.every(cls => sameMapping(COMPOSED_CLASS_MAP[cls], entry))) {
|
|
657
|
+
mark(openStart, 'review multiple composed classes');
|
|
658
|
+
continue;
|
|
554
659
|
}
|
|
555
660
|
|
|
556
|
-
//
|
|
557
|
-
//
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const elementBody = (!isSelfClosing && closeStart !== null)
|
|
561
|
-
? content.slice(openEnd, closeStart)
|
|
562
|
-
: '';
|
|
563
|
-
const isWrapper = isNativeRewriteable
|
|
564
|
-
&& (hasLayoutDisplaySignal(retainedClasses) || hasBlockOrComponentChild(elementBody));
|
|
565
|
-
|
|
566
|
-
if (isWrapper) {
|
|
567
|
-
matches.push({
|
|
568
|
-
entry: { flag: 'wrapper' },
|
|
569
|
-
composedCls,
|
|
570
|
-
tagName,
|
|
571
|
-
attrsBefore: attrsBefore.trim(),
|
|
572
|
-
attrsAfter: attrsAfter.trim(),
|
|
573
|
-
retainedClasses,
|
|
574
|
-
isSelfClosing,
|
|
575
|
-
openStart,
|
|
576
|
-
openEnd,
|
|
577
|
-
closeStart: null,
|
|
578
|
-
closeEnd: null,
|
|
579
|
-
closeReplacement: null,
|
|
580
|
-
});
|
|
661
|
+
// An authored composition, or a spread or dynamic name that may supply one, would sit
|
|
662
|
+
// beside the generated variant and turn its size into a raw font-size override.
|
|
663
|
+
if (isDtText && (hasAuthoredComposition(names) || hasUncertainBinding(names))) {
|
|
664
|
+
mark(openStart, 'review composed class with authored composition');
|
|
581
665
|
continue;
|
|
582
666
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
entry,
|
|
586
|
-
composedCls,
|
|
587
|
-
tagName,
|
|
588
|
-
attrsBefore: attrsBefore.trim(),
|
|
589
|
-
attrsAfter: attrsAfter.trim(),
|
|
590
|
-
retainedClasses,
|
|
591
|
-
isSelfClosing,
|
|
592
|
-
openStart,
|
|
593
|
-
openEnd,
|
|
594
|
-
closeStart,
|
|
595
|
-
closeEnd,
|
|
596
|
-
closeReplacement,
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
if (matches.length === 0) return content;
|
|
601
|
-
|
|
602
|
-
// Apply in reverse order to preserve positions
|
|
603
|
-
const replacements = [];
|
|
604
|
-
|
|
605
|
-
for (const match of matches) {
|
|
606
|
-
const {
|
|
607
|
-
entry, tagName, attrsBefore, attrsAfter, retainedClasses,
|
|
608
|
-
isSelfClosing, openStart, openEnd, closeStart, closeEnd,
|
|
609
|
-
} = match;
|
|
610
|
-
|
|
611
|
-
if (entry.flag === 'eyebrow' || entry.flag === 'code-sm') {
|
|
612
|
-
// Prepend a review comment before the element — no rewrite
|
|
613
|
-
replacements.push({
|
|
614
|
-
start: openStart,
|
|
615
|
-
end: openStart,
|
|
616
|
-
replacement: '<!-- dt-text-migrate: review -->',
|
|
617
|
-
});
|
|
667
|
+
if (!isDtText && mayBecomeTextProp(names)) {
|
|
668
|
+
replacements.push({ start: openStart, end: openStart, replacement: NATIVE_PROP_MARKER });
|
|
618
669
|
continue;
|
|
619
670
|
}
|
|
620
671
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
replacements.push({
|
|
626
|
-
start: openStart,
|
|
627
|
-
end: openStart,
|
|
628
|
-
replacement: '<!-- dt-text-migrate: review composed class on wrapper -->',
|
|
629
|
-
});
|
|
672
|
+
// Flagged classes are never rewritten. Check them before the wrapper test: a child this
|
|
673
|
+
// run converts to <dt-text> would make the element look like a wrapper on the next run.
|
|
674
|
+
if (entry.flag === 'eyebrow' || entry.flag === 'code-sm') {
|
|
675
|
+
mark(openStart, 'review');
|
|
630
676
|
continue;
|
|
631
677
|
}
|
|
632
678
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
attrsAfter,
|
|
644
|
-
selfClosing: isSelfClosing,
|
|
645
|
-
});
|
|
646
|
-
replacements.push({
|
|
647
|
-
start: openStart,
|
|
648
|
-
end: openEnd,
|
|
649
|
-
replacement: '<!-- dt-text-migrate: review helper -->' + newTag,
|
|
650
|
-
});
|
|
651
|
-
if (!isSelfClosing && closeStart !== null) {
|
|
652
|
-
replacements.push({ start: closeStart, end: closeEnd, replacement: '</dt-text>' });
|
|
653
|
-
}
|
|
679
|
+
const isSelfClosing = selfClosing === '/';
|
|
680
|
+
const closing = isSelfClosing ? null : findMatchingClosingTag(content, openEnd, tagName);
|
|
681
|
+
const retainedClasses = classes.filter(cls => !COMPOSED_CLASS_MAP[cls]);
|
|
682
|
+
|
|
683
|
+
// Wrapper safety: skip auto-convert when a native element looks like a layout
|
|
684
|
+
// container or contains non-text children. The marker keeps the legacy class visible
|
|
685
|
+
// in the migration diff; the consumer migrates it manually.
|
|
686
|
+
const elementBody = closing ? content.slice(openEnd, closing.index) : '';
|
|
687
|
+
if (!isDtText && (hasLayoutDisplaySignal(retainedClasses) || hasBlockOrComponentChild(elementBody))) {
|
|
688
|
+
mark(openStart, 'review composed class on wrapper');
|
|
654
689
|
continue;
|
|
655
690
|
}
|
|
656
691
|
|
|
657
|
-
// Normal rewrite
|
|
658
692
|
const newTag = buildDtTextTag({
|
|
659
693
|
originalTag: tagName,
|
|
660
|
-
|
|
661
|
-
size: entry.size,
|
|
662
|
-
density: entry.density,
|
|
663
|
-
strength: entry.strength,
|
|
694
|
+
entry,
|
|
664
695
|
retainedClasses,
|
|
665
|
-
attrsBefore,
|
|
666
|
-
attrsAfter,
|
|
696
|
+
attrsBefore: attrsBefore.trim(),
|
|
697
|
+
attrsAfter: attrsAfter.trim(),
|
|
667
698
|
selfClosing: isSelfClosing,
|
|
699
|
+
authored: parseExistingProps(names),
|
|
700
|
+
blocked: blockedOverrideProps(attrs, names),
|
|
668
701
|
});
|
|
669
|
-
|
|
670
|
-
replacements.push({ start: openStart, end: openEnd, replacement: newTag });
|
|
671
|
-
if (
|
|
672
|
-
replacements.push({ start:
|
|
702
|
+
const helperMarker = entry.flag === 'helper' ? '<!-- dt-text-migrate: review helper -->' : '';
|
|
703
|
+
replacements.push({ start: openStart, end: openEnd, replacement: helperMarker + newTag });
|
|
704
|
+
if (closing) {
|
|
705
|
+
replacements.push({ start: closing.index, end: closing.index + closing.length, replacement: '</dt-text>' });
|
|
673
706
|
}
|
|
674
707
|
}
|
|
675
708
|
|
|
709
|
+
if (replacements.length === 0) return content;
|
|
710
|
+
|
|
676
711
|
// Sort descending by start position, apply
|
|
677
712
|
replacements.sort((a, b) => b.start - a.start);
|
|
678
713
|
|
|
@@ -689,53 +724,22 @@ function rewriteComposedClasses (content) {
|
|
|
689
724
|
//------------------------------------------------------------------------------
|
|
690
725
|
|
|
691
726
|
/**
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*/
|
|
695
|
-
function parseExistingProps (attrStr) {
|
|
696
|
-
const props = {};
|
|
697
|
-
// Anchor on whitespace/start so we don't match suffix attrs like `font-kind=`,
|
|
698
|
-
// `wrapper-truncate=`, `label-size=` etc. — `\b` is a word boundary between `-` and `k`,
|
|
699
|
-
// so `\b(kind|...)` matches inside `font-kind=`. Requiring `\s` (or start of attrStr,
|
|
700
|
-
// which often begins with whitespace) anchors the prop as a real attribute name.
|
|
701
|
-
// Allow `:` or `v-bind:` prefix for bound props (e.g. `:size="…"` counts as an existing size).
|
|
702
|
-
const propRe = /(?:^|\s)(?::|v-bind:)?(kind|size|strength|density|tone|align|truncate|as)\s*=\s*"([^"]*)"/g;
|
|
703
|
-
const boolRe = /(?:^|\s)truncate\b(?!\s*[=:])/g;
|
|
704
|
-
let m;
|
|
705
|
-
while ((m = propRe.exec(attrStr)) !== null) {
|
|
706
|
-
props[m[1]] = m[2];
|
|
707
|
-
}
|
|
708
|
-
while ((m = boolRe.exec(attrStr)) !== null) {
|
|
709
|
-
props.truncate = true;
|
|
710
|
-
}
|
|
711
|
-
return props;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Build the attr string for the lifted props + remaining classes + preserved other attrs.
|
|
716
|
-
* Used for residual lift on existing <dt-text> elements.
|
|
727
|
+
* Build the opening tag for a residual lift on an existing <dt-text>: lifted props are
|
|
728
|
+
* appended, the class attribute keeps only the remaining classes.
|
|
717
729
|
*/
|
|
718
|
-
function buildResidualTag (tagName, existingAttrs, overrideProps, remaining,
|
|
730
|
+
function buildResidualTag (tagName, existingAttrs, overrideProps, remaining, selfClosing) {
|
|
719
731
|
// Strip the original class attribute — we'll rebuild it if remaining is non-empty
|
|
720
732
|
let attrs = existingAttrs.replace(/\sclass="[^"]*"/, '').trimEnd();
|
|
721
733
|
|
|
722
734
|
for (const { prop, value } of overrideProps) {
|
|
723
|
-
|
|
724
|
-
attrs += ` ${prop}`;
|
|
725
|
-
} else {
|
|
726
|
-
attrs += ` ${prop}="${value}"`;
|
|
727
|
-
}
|
|
735
|
+
attrs += value === null ? ` ${prop}` : ` ${prop}="${value}"`;
|
|
728
736
|
}
|
|
729
737
|
|
|
730
738
|
if (remaining.length > 0) {
|
|
731
739
|
attrs += ` class="${remaining.join(' ')}"`;
|
|
732
740
|
}
|
|
733
741
|
|
|
734
|
-
|
|
735
|
-
? '<!-- dt-text-migrate: review conflicting class -->'
|
|
736
|
-
: '';
|
|
737
|
-
|
|
738
|
-
return conflictComment + `<${tagName}${attrs}>`;
|
|
742
|
+
return `<${tagName}${attrs}${selfClosing ? ' />' : '>'}`;
|
|
739
743
|
}
|
|
740
744
|
|
|
741
745
|
function liftResidualOverrides (content) {
|
|
@@ -766,35 +770,46 @@ function liftResidualOverrides (content) {
|
|
|
766
770
|
const hasOverride = classes.some(c => OVERRIDE_CLASS_MAP[c]);
|
|
767
771
|
if (!hasOverride) continue;
|
|
768
772
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const existingProps = parseExistingProps(allAttrs);
|
|
773
|
-
const { overrideProps, remaining, conflictClasses } = extractOverrideProps(classes, existingProps);
|
|
773
|
+
// A composed class still present was rejected or protected by rewriteComposedClasses
|
|
774
|
+
// (or is on a native tag it handles); review must see that tag unchanged.
|
|
775
|
+
if (classes.some(c => COMPOSED_CLASS_MAP[c])) continue;
|
|
774
776
|
|
|
775
|
-
|
|
777
|
+
const attrs = `${attrsBefore} ${attrsAfter}`;
|
|
778
|
+
const names = attributeNames(attrs);
|
|
779
|
+
const lift = () => extractOverrideProps(classes, parseExistingProps(names), blockedOverrideProps(attrs, names));
|
|
780
|
+
|
|
781
|
+
if (isDtText) {
|
|
782
|
+
const { overrideProps, remaining, conflict } = lift();
|
|
783
|
+
if (overrideProps.length === 0) {
|
|
784
|
+
// Nothing to lift: leave the tag byte-for-byte so reruns stay identical.
|
|
785
|
+
if (conflict) replacements.push({ start: openStart, end: openStart, replacement: CONFLICT_MARKER });
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
776
788
|
|
|
777
789
|
replacements.push({
|
|
778
790
|
start: openStart,
|
|
779
791
|
end: openEnd,
|
|
780
|
-
replacement:
|
|
792
|
+
replacement: (conflict ? CONFLICT_MARKER : '') +
|
|
793
|
+
buildResidualTag(tagName, attrsBefore + attrsAfter, overrideProps, remaining, isSelfClosing),
|
|
781
794
|
});
|
|
782
795
|
|
|
783
796
|
} else if (isNative) {
|
|
784
|
-
//
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
//
|
|
789
|
-
// to <dt-text> would attach the .d-text base class which changes baseline typography —
|
|
790
|
-
// problematic for layout wrappers (e.g. <div class="d-fc-neutral-white"> around a stack).
|
|
791
|
-
// Restrict override-only rewriting to <span>/<p>/<label> where text-as-default is safe.
|
|
797
|
+
// ⚠️ Without a composed class there is no composition to establish. Converting
|
|
798
|
+
// <div>/<h*> to <dt-text> would attach the .d-text base class which changes baseline
|
|
799
|
+
// typography — problematic for layout wrappers (e.g. <div class="d-fc-neutral-white">
|
|
800
|
+
// around a stack). Restrict override-only rewriting to <span>/<p>/<label>, where the
|
|
801
|
+
// result keeps inheriting typography and only the atomic props apply.
|
|
792
802
|
const OVERRIDE_ONLY_REWRITEABLE = new Set(['span', 'p', 'label']);
|
|
793
803
|
if (!OVERRIDE_ONLY_REWRITEABLE.has(tagName.toLowerCase())) continue;
|
|
794
804
|
|
|
805
|
+
if (mayBecomeTextProp(names)) {
|
|
806
|
+
replacements.push({ start: openStart, end: openStart, replacement: NATIVE_PROP_MARKER });
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
|
|
795
810
|
// Skip elements with behavioral attrs — directives, events, id, ref, data-*
|
|
796
811
|
// mean the element has significance beyond typography (e.g. <span @click>, <span id="x">)
|
|
797
|
-
const allAttrs =
|
|
812
|
+
const allAttrs = attrs.trim();
|
|
798
813
|
if (/(?:v-|@\w|:(?!class)|\bid=|\bref=|\bdata-)/.test(allAttrs)) continue;
|
|
799
814
|
|
|
800
815
|
// Skip if any class is unrecognised — custom CSS may target it, unsafe to auto-convert
|
|
@@ -803,27 +818,20 @@ function liftResidualOverrides (content) {
|
|
|
803
818
|
// Wrapper safety: skip if element body contains block/component children.
|
|
804
819
|
// <span class="d-fw-bold"><dt-button>x</dt-button></span> should NOT become
|
|
805
820
|
// <dt-text strength="bold"><dt-button>…</dt-text>. (Mirrors the composed-path safety.)
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (closing) {
|
|
809
|
-
const body = content.slice(openEnd, closing.index);
|
|
810
|
-
if (hasBlockOrComponentChild(body)) continue;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
821
|
+
const closing = isSelfClosing ? null : findMatchingClosingTag(content, openEnd, tagName);
|
|
822
|
+
if (closing && hasBlockOrComponentChild(content.slice(openEnd, closing.index))) continue;
|
|
813
823
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
824
|
+
const { overrideProps, remaining, conflict } = lift();
|
|
825
|
+
if (overrideProps.length === 0) {
|
|
826
|
+
if (conflict) replacements.push({ start: openStart, end: openStart, replacement: CONFLICT_MARKER });
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
817
829
|
|
|
818
|
-
let newTag = '<dt-text';
|
|
830
|
+
let newTag = (conflict ? CONFLICT_MARKER : '') + '<dt-text';
|
|
819
831
|
if (tagName !== 'span') newTag += ` as="${tagName}"`;
|
|
820
832
|
|
|
821
833
|
for (const { prop, value } of overrideProps) {
|
|
822
|
-
|
|
823
|
-
newTag += ` ${prop}`;
|
|
824
|
-
} else {
|
|
825
|
-
newTag += ` ${prop}="${value}"`;
|
|
826
|
-
}
|
|
834
|
+
newTag += value === null ? ` ${prop}` : ` ${prop}="${value}"`;
|
|
827
835
|
}
|
|
828
836
|
|
|
829
837
|
if (remaining.length > 0) newTag += ` class="${remaining.join(' ')}"`;
|
|
@@ -833,15 +841,12 @@ function liftResidualOverrides (content) {
|
|
|
833
841
|
|
|
834
842
|
replacements.push({ start: openStart, end: openEnd, replacement: newTag });
|
|
835
843
|
|
|
836
|
-
if (
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
replacement: '</dt-text>',
|
|
843
|
-
});
|
|
844
|
-
}
|
|
844
|
+
if (closing) {
|
|
845
|
+
replacements.push({
|
|
846
|
+
start: closing.index,
|
|
847
|
+
end: closing.index + closing.length,
|
|
848
|
+
replacement: '</dt-text>',
|
|
849
|
+
});
|
|
845
850
|
}
|
|
846
851
|
}
|
|
847
852
|
}
|
|
@@ -883,35 +888,15 @@ function isSafeToCollapseSpan (fullTag) {
|
|
|
883
888
|
if (withoutClass.length > 0) return false;
|
|
884
889
|
|
|
885
890
|
const classes = classMatch[1].split(/\s+/).filter(Boolean);
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
// Reject if any composed class is flagged (eyebrow / code-sm / helper) — those are
|
|
889
|
-
// explicitly out-of-scope-for-auto-rewrite per the PRD and Task 2 already emits a
|
|
890
|
-
// review marker for them. Rewriting here would contradict the flag.
|
|
891
|
-
return !classes.some(c => COMPOSED_CLASS_MAP[c] && COMPOSED_CLASS_MAP[c].flag);
|
|
891
|
+
return classes.length > 0 && classes.every(c => ALL_KNOWN_CLASSES.has(c));
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
/**
|
|
895
|
-
* Rewrite a safe child span
|
|
895
|
+
* Rewrite a safe child span to <dt-text> carrying only its override props. Without a
|
|
896
|
+
* composition it keeps inheriting the parent's typography.
|
|
896
897
|
*/
|
|
897
|
-
function rewriteChildSpan (
|
|
898
|
-
const classMatch = spanTag.match(/\sclass="([^"]*)"/);
|
|
899
|
-
if (!classMatch) return spanTag;
|
|
900
|
-
|
|
901
|
-
const classes = classMatch[1].split(/\s+/).filter(Boolean);
|
|
902
|
-
const existingProps = {};
|
|
903
|
-
const { overrideProps, remaining } = extractOverrideProps(classes, existingProps);
|
|
904
|
-
const composedEntry = classes.reduce(
|
|
905
|
-
(f, c) => f || (COMPOSED_CLASS_MAP[c] ? { cls: c, entry: COMPOSED_CLASS_MAP[c] } : null),
|
|
906
|
-
null,
|
|
907
|
-
);
|
|
908
|
-
|
|
898
|
+
function rewriteChildSpan (overrideProps, remaining) {
|
|
909
899
|
let tag = '<dt-text';
|
|
910
|
-
if (composedEntry && !composedEntry.entry.flag) {
|
|
911
|
-
const { kind, size } = composedEntry.entry;
|
|
912
|
-
if (kind) tag += ` kind="${kind}"`;
|
|
913
|
-
if (size) tag += ` size="${size}"`;
|
|
914
|
-
}
|
|
915
900
|
for (const { prop, value } of overrideProps) {
|
|
916
901
|
tag += value === null ? ` ${prop}` : ` ${prop}="${value}"`;
|
|
917
902
|
}
|
|
@@ -927,11 +912,17 @@ function collapseNestedSpans (content) {
|
|
|
927
912
|
const dtTextRe = new RegExp(`<dt-text(${ATTR_BODY})>`, 'g');
|
|
928
913
|
let m;
|
|
929
914
|
const replacements = [];
|
|
915
|
+
// The span scan below covers the whole body, nested <dt-text> included, so edit each
|
|
916
|
+
// body once through its outermost ancestor: overlapping body replacements would apply
|
|
917
|
+
// the outer one with stale offsets and corrupt the template.
|
|
918
|
+
let coveredEnd = -1;
|
|
930
919
|
|
|
931
920
|
while ((m = dtTextRe.exec(content)) !== null) {
|
|
921
|
+
if (m.index < coveredEnd) continue;
|
|
932
922
|
const openEnd = m.index + m[0].length;
|
|
933
923
|
const closing = findMatchingClosingTag(content, openEnd, 'dt-text');
|
|
934
924
|
if (!closing) continue;
|
|
925
|
+
coveredEnd = closing.index;
|
|
935
926
|
const bodyStart = openEnd;
|
|
936
927
|
const bodyEnd = closing.index;
|
|
937
928
|
const body = content.slice(bodyStart, bodyEnd);
|
|
@@ -944,14 +935,28 @@ function collapseNestedSpans (content) {
|
|
|
944
935
|
while ((sm = childSpanRe.exec(body)) !== null) {
|
|
945
936
|
const spanTag = sm[0];
|
|
946
937
|
const spanOpenEnd = sm.index + spanTag.length;
|
|
947
|
-
|
|
938
|
+
const classes = (spanTag.match(/\sclass="([^"]*)"/)?.[1] ?? '').split(/\s+/).filter(Boolean);
|
|
939
|
+
|
|
940
|
+
// rewriteComposedClasses already converted or reviewed every composed span. One
|
|
941
|
+
// still here was rejected there (wrapper, multiple compositions, flag) and must
|
|
942
|
+
// not be retried.
|
|
943
|
+
if (classes.some(c => COMPOSED_CLASS_MAP[c])) continue;
|
|
944
|
+
// liftResidualOverrides already kept this span for its attributes.
|
|
945
|
+
if (body.slice(0, sm.index).endsWith(NATIVE_PROP_MARKER)) continue;
|
|
946
|
+
|
|
947
|
+
// Find the depth-matched </span> (handles nested <span>...<span>...</span>...</span>)
|
|
948
|
+
const closingSpan = findMatchingClosingTag(body, spanOpenEnd, 'span');
|
|
949
|
+
const spanBody = closingSpan ? body.slice(spanOpenEnd, closingSpan.index) : '';
|
|
950
|
+
|
|
951
|
+
if (isSafeToCollapseSpan(spanTag) && !hasBlockOrComponentChild(spanBody)) {
|
|
952
|
+
const { overrideProps, remaining, conflict } = extractOverrideProps(classes);
|
|
953
|
+
// liftResidualOverrides already marked conflicting spans for review.
|
|
954
|
+
if (conflict || overrideProps.length === 0) continue;
|
|
948
955
|
spanReplacements.push({
|
|
949
956
|
start: sm.index,
|
|
950
957
|
end: spanOpenEnd,
|
|
951
|
-
replacement: rewriteChildSpan(
|
|
958
|
+
replacement: rewriteChildSpan(overrideProps, remaining),
|
|
952
959
|
});
|
|
953
|
-
// Find the depth-matched </span> (handles nested <span>...<span>...</span>...</span>)
|
|
954
|
-
const closingSpan = findMatchingClosingTag(body, spanOpenEnd, 'span');
|
|
955
960
|
if (closingSpan) {
|
|
956
961
|
spanReplacements.push({
|
|
957
962
|
start: closingSpan.index,
|
|
@@ -959,19 +964,13 @@ function collapseNestedSpans (content) {
|
|
|
959
964
|
replacement: '</dt-text>',
|
|
960
965
|
});
|
|
961
966
|
}
|
|
962
|
-
} else {
|
|
963
|
-
//
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
start: sm.index,
|
|
970
|
-
end: sm.index,
|
|
971
|
-
replacement: '<!-- dt-text-migrate: review nested span -->',
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
}
|
|
967
|
+
} else if (classes.some(c => ALL_KNOWN_CLASSES.has(c))) {
|
|
968
|
+
// Typography classes on a span we cannot convert safely — flag it
|
|
969
|
+
spanReplacements.push({
|
|
970
|
+
start: sm.index,
|
|
971
|
+
end: sm.index,
|
|
972
|
+
replacement: '<!-- dt-text-migrate: review nested span -->',
|
|
973
|
+
});
|
|
975
974
|
}
|
|
976
975
|
}
|
|
977
976
|
|
|
@@ -1066,43 +1065,43 @@ function flagComposedOnWrapperTags (content) {
|
|
|
1066
1065
|
return out;
|
|
1067
1066
|
}
|
|
1068
1067
|
|
|
1069
|
-
//
|
|
1070
|
-
//
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
'600': 'headline size="700"',
|
|
1078
|
-
};
|
|
1068
|
+
// Describe a d-fs-N class without inferring a composition from font size. Beside a
|
|
1069
|
+
// variant, size="N" is a raw font-size override; without one, it has nothing to apply to.
|
|
1070
|
+
function fontSizeHint (fsN, hasVariant) {
|
|
1071
|
+
if (!TEXT_FONT_SIZES.has(fsN)) return 'no matching DtText size token; keep class';
|
|
1072
|
+
return hasVariant
|
|
1073
|
+
? `raw font-size token; size="${fsN}" can replace it alongside variant`
|
|
1074
|
+
: `raw font-size token; size="${fsN}" needs a variant, which font size alone does not determine`;
|
|
1075
|
+
}
|
|
1079
1076
|
|
|
1080
1077
|
function flagFontSizeClasses (content) {
|
|
1081
1078
|
// Iterate over real opening tags using a quote-aware regex so we never land
|
|
1082
1079
|
// inside a quoted attribute value (e.g. `title="a < b"`). Walking back with
|
|
1083
1080
|
// lastIndexOf('<') from a `class=` match is unsafe because `<` can appear
|
|
1084
1081
|
// inside `v-if="rowCount < total"` style bindings.
|
|
1085
|
-
const tagRe = new RegExp(`<[a-zA-Z][\\w-]*(${ATTR_BODY})\\sclass="([^"]*)"
|
|
1082
|
+
const tagRe = new RegExp(`<([a-zA-Z][\\w-]*)(${ATTR_BODY})\\sclass="([^"]*)"(${ATTR_BODY})\\/?>`, 'g');
|
|
1086
1083
|
const replacements = [];
|
|
1087
1084
|
let m;
|
|
1088
1085
|
|
|
1089
1086
|
while ((m = tagRe.exec(content)) !== null) {
|
|
1087
|
+
const [, tagName, attrsBefore, classValue, attrsAfter] = m;
|
|
1090
1088
|
const tagStart = m.index;
|
|
1091
|
-
const classValue = m[2];
|
|
1092
1089
|
|
|
1093
1090
|
// Only act on class attributes containing d-fs-N
|
|
1094
1091
|
const fsMatch = classValue.match(/\bd-fs-(\d+)\b/);
|
|
1095
1092
|
if (!fsMatch) continue;
|
|
1096
1093
|
|
|
1097
1094
|
const fsN = fsMatch[1];
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1095
|
+
const isDtText = tagName === 'dt-text' || tagName === 'DtText';
|
|
1096
|
+
const hasVariant = isDtText &&
|
|
1097
|
+
attributeNames(`${attrsBefore} ${attrsAfter}`).some(name => boundProp(name) === 'variant');
|
|
1098
|
+
const hint = `<!-- dt-text-migrate: review d-fs-${fsN} (${fontSizeHint(fsN, hasVariant)}) -->`;
|
|
1101
1099
|
|
|
1102
|
-
// Suppress when a
|
|
1103
|
-
//
|
|
1100
|
+
// Suppress only when a legacy-heading hint ends immediately before this tag: it already
|
|
1101
|
+
// describes the d-fs class. Other markers don't, and on a rerun they are masked, so
|
|
1102
|
+
// suppressing on them would emit the hint only on the second run.
|
|
1104
1103
|
const immediatelyBefore = content.slice(Math.max(0, tagStart - 500), tagStart);
|
|
1105
|
-
const alreadyFlagged = /<!--\s*dt-text-migrate
|
|
1104
|
+
const alreadyFlagged = /<!--\s*dt-text-migrate:\s*legacy heading[\s\S]*?-->\s*$/.test(immediatelyBefore);
|
|
1106
1105
|
if (!alreadyFlagged) {
|
|
1107
1106
|
replacements.push({ start: tagStart, end: tagStart, replacement: hint });
|
|
1108
1107
|
}
|
|
@@ -1120,11 +1119,11 @@ function flagFontSizeClasses (content) {
|
|
|
1120
1119
|
/**
|
|
1121
1120
|
* Detect the legacy raw-utility heading pattern (no composed class, but d-fw-* +
|
|
1122
1121
|
* d-fc-* + d-fs-N built up by hand on a rewriteable native tag) and emit a hint
|
|
1123
|
-
* comment
|
|
1124
|
-
*
|
|
1122
|
+
* comment for the DtText migration. Font size and weight alone cannot choose a
|
|
1123
|
+
* variant, so the hint leaves that step to the reviewer.
|
|
1125
1124
|
*
|
|
1126
|
-
* The
|
|
1127
|
-
*
|
|
1125
|
+
* The element is NOT rewritten; the developer reviews and applies. Cleanly removed by
|
|
1126
|
+
* --remove-markers.
|
|
1128
1127
|
*/
|
|
1129
1128
|
function flagLegacyHeadings (content) {
|
|
1130
1129
|
// Match rewriteable native elements with a static class attribute
|
|
@@ -1161,16 +1160,16 @@ function flagLegacyHeadings (content) {
|
|
|
1161
1160
|
const fcMatch = classes.find(c => OVERRIDE_CLASS_MAP[c] && OVERRIDE_CLASS_MAP[c].prop === 'tone');
|
|
1162
1161
|
const tone = fcMatch ? OVERRIDE_CLASS_MAP[fcMatch].value : null;
|
|
1163
1162
|
|
|
1164
|
-
//
|
|
1163
|
+
// A heading tag suggests a headline variant; its size step still needs review.
|
|
1165
1164
|
const isHeadingTag = /^h[1-6]$/.test(tagName);
|
|
1166
|
-
const
|
|
1167
|
-
const sizeHint =
|
|
1168
|
-
? `size
|
|
1169
|
-
: `
|
|
1165
|
+
const variantHint = isHeadingTag ? 'variant=headline-? (VERIFY)' : 'variant=? (VERIFY: headline, body or label)';
|
|
1166
|
+
const sizeHint = TEXT_FONT_SIZES.has(fsN)
|
|
1167
|
+
? `d-fs-${fsN} is a raw font-size token (size="${fsN}" once a variant is set)`
|
|
1168
|
+
: `d-fs-${fsN} has no matching DtText size token (keep class)`;
|
|
1170
1169
|
|
|
1171
1170
|
const parts = [];
|
|
1172
1171
|
if (!isHeadingTag) parts.push(`as=${tagName}`);
|
|
1173
|
-
parts.push(
|
|
1172
|
+
parts.push(variantHint, sizeHint, `strength=${strength}`);
|
|
1174
1173
|
if (tone) parts.push(`tone=${tone}`);
|
|
1175
1174
|
|
|
1176
1175
|
const hint = `<!-- dt-text-migrate: legacy heading — ${parts.join(' | ')} -->`;
|
|
@@ -1359,20 +1358,54 @@ function printImportInstructions (filePath, importCheck) {
|
|
|
1359
1358
|
// --validate mode: detect post-migration DtText prop bugs
|
|
1360
1359
|
//------------------------------------------------------------------------------
|
|
1361
1360
|
|
|
1362
|
-
const VALID_KINDS = new Set(['headline', 'body', 'label', 'code']);
|
|
1363
|
-
const VALID_SIZES = new Set([
|
|
1364
|
-
'100', '200', '300', '400', '500', '600', '700',
|
|
1365
|
-
'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl',
|
|
1366
|
-
]);
|
|
1367
1361
|
const VALID_STRENGTHS = new Set(['bold', 'semibold', 'medium', 'normal']);
|
|
1368
1362
|
const VALID_DENSITIES = new Set(['100', '200', '300', '400', '500', '600']);
|
|
1369
1363
|
const VALID_ALIGNS = new Set(['start', 'center', 'end', 'justify']);
|
|
1364
|
+
const VALID_STATIC_VALUES = {
|
|
1365
|
+
kind: new Set(Object.keys(TEXT_KIND_SIZES)),
|
|
1366
|
+
variant: TEXT_VARIANTS,
|
|
1367
|
+
family: TEXT_FAMILIES,
|
|
1368
|
+
strength: VALID_STRENGTHS,
|
|
1369
|
+
density: VALID_DENSITIES,
|
|
1370
|
+
align: VALID_ALIGNS,
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
// Size depends on context, as in DtText: beside a variant it is a raw font-size token;
|
|
1374
|
+
// with kind alone, a composition size; with neither, DtText ignores it. Bound values and
|
|
1375
|
+
// spreads stay unknown rather than guessed.
|
|
1376
|
+
function sizeIssue (names, values) {
|
|
1377
|
+
const binds = prop => names.some(name => boundProp(name) === prop);
|
|
1378
|
+
if (!binds('size') || hasUncertainBinding(names)) return null;
|
|
1379
|
+
|
|
1380
|
+
if (binds('variant')) {
|
|
1381
|
+
if (!('variant' in values) || !('size' in values) || TEXT_FONT_SIZES.has(values.size)) return null;
|
|
1382
|
+
return {
|
|
1383
|
+
type: 'invalid-value',
|
|
1384
|
+
message: `size="${values.size}" with variant must be a font-size token (expected one of: ${[...TEXT_FONT_SIZES].join(', ')}).`,
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
if (binds('kind')) {
|
|
1389
|
+
const allowed = TEXT_KIND_SIZES[values.kind];
|
|
1390
|
+
if (!allowed || !('size' in values) || allowed.includes(values.size)) return null;
|
|
1391
|
+
return {
|
|
1392
|
+
type: 'invalid-value',
|
|
1393
|
+
message: `size="${values.size}" is not valid for kind="${values.kind}" (expected one of: ${allowed.join(', ')}).`,
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
return {
|
|
1398
|
+
type: 'size-without-composition',
|
|
1399
|
+
message: 'size needs a variant (or legacy kind); without one DtText ignores it.',
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1370
1402
|
|
|
1371
1403
|
/**
|
|
1372
1404
|
* Scan a file's content for DtText prop bugs. Returns array of issues with line numbers.
|
|
1373
1405
|
* Issue types:
|
|
1374
1406
|
* - object-syntax — `:tone="{ muted: cond }"` style (CSS-class binding misapplied to prop)
|
|
1375
|
-
* - invalid-value — `density="160"`, `
|
|
1407
|
+
* - invalid-value — `density="160"`, `variant="title-md"`, a size invalid in its context
|
|
1408
|
+
* - size-without-composition — size with no variant or kind to apply to
|
|
1376
1409
|
* - mixed-class — DtText with `class="d-fw-bold"` or another typography utility
|
|
1377
1410
|
*/
|
|
1378
1411
|
export function validateDtTextProps (content) {
|
|
@@ -1399,6 +1432,7 @@ export function validateDtTextProps (content) {
|
|
|
1399
1432
|
const attrStr = m[1];
|
|
1400
1433
|
const lineNum = content.slice(0, m.index).split('\n').length;
|
|
1401
1434
|
const tagSnippet = m[0].length > 120 ? m[0].slice(0, 117) + '...' : m[0];
|
|
1435
|
+
const report = (type, message) => issues.push({ type, line: lineNum, message, snippet: tagSnippet });
|
|
1402
1436
|
|
|
1403
1437
|
// Object syntax detection: any prop bound with `:prop="{...}"`
|
|
1404
1438
|
const objectSyntaxRe = /:(\w[\w-]*)="\s*\{/g;
|
|
@@ -1406,46 +1440,34 @@ export function validateDtTextProps (content) {
|
|
|
1406
1440
|
while ((osm = objectSyntaxRe.exec(attrStr)) !== null) {
|
|
1407
1441
|
const propName = osm[1];
|
|
1408
1442
|
// Only flag known string props (where object syntax is wrong)
|
|
1409
|
-
if (['tone', 'kind', 'size', 'strength', 'density', 'align', 'as'].includes(propName)) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
line: lineNum,
|
|
1413
|
-
message: `:${propName}="{ ... }" uses CSS-class syntax — DtText expects a string. Use :${propName}="cond ? 'value' : undefined" instead.`,
|
|
1414
|
-
snippet: tagSnippet,
|
|
1415
|
-
});
|
|
1443
|
+
if (['tone', 'kind', 'variant', 'family', 'size', 'strength', 'density', 'align', 'as'].includes(propName)) {
|
|
1444
|
+
report('object-syntax',
|
|
1445
|
+
`:${propName}="{ ... }" uses CSS-class syntax — DtText expects a string. Use :${propName}="cond ? 'value' : undefined" instead.`);
|
|
1416
1446
|
}
|
|
1417
1447
|
}
|
|
1418
1448
|
|
|
1419
1449
|
// Static-value validation — anchor on whitespace so we don't match `:prop=` (bound)
|
|
1420
|
-
const
|
|
1450
|
+
const values = {};
|
|
1451
|
+
const staticPropRe = /\s(kind|variant|family|size|strength|density|align)\s*=\s*"([^"]+)"/g;
|
|
1421
1452
|
let spm;
|
|
1422
1453
|
while ((spm = staticPropRe.exec(attrStr)) !== null) {
|
|
1423
1454
|
const [, propName, value] = spm;
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
density: VALID_DENSITIES, align: VALID_ALIGNS,
|
|
1427
|
-
}[propName];
|
|
1455
|
+
values[propName] = value;
|
|
1456
|
+
const validSet = VALID_STATIC_VALUES[propName];
|
|
1428
1457
|
if (validSet && !validSet.has(value)) {
|
|
1429
|
-
|
|
1430
|
-
type: 'invalid-value',
|
|
1431
|
-
line: lineNum,
|
|
1432
|
-
message: `${propName}="${value}" is not a valid value (expected one of: ${[...validSet].join(', ')}).`,
|
|
1433
|
-
snippet: tagSnippet,
|
|
1434
|
-
});
|
|
1458
|
+
report('invalid-value', `${propName}="${value}" is not a valid value (expected one of: ${[...validSet].join(', ')}).`);
|
|
1435
1459
|
}
|
|
1436
1460
|
}
|
|
1437
1461
|
|
|
1462
|
+
const size = sizeIssue(attributeNames(attrStr), values);
|
|
1463
|
+
if (size) report(size.type, size.message);
|
|
1464
|
+
|
|
1438
1465
|
// Mixed class detection: DtText with class= containing typography utilities
|
|
1439
1466
|
const classM = attrStr.match(/\sclass="([^"]*)"/);
|
|
1440
1467
|
if (classM) {
|
|
1441
1468
|
const offenders = classM[1].split(/\s+/).filter(c => ALL_KNOWN_CLASSES.has(c));
|
|
1442
1469
|
if (offenders.length > 0) {
|
|
1443
|
-
|
|
1444
|
-
type: 'mixed-class',
|
|
1445
|
-
line: lineNum,
|
|
1446
|
-
message: `DtText carries typography utility classes [${offenders.join(', ')}] — lift to props instead.`,
|
|
1447
|
-
snippet: tagSnippet,
|
|
1448
|
-
});
|
|
1470
|
+
report('mixed-class', `DtText carries typography utility classes [${offenders.join(', ')}] — lift to props instead.`);
|
|
1449
1471
|
}
|
|
1450
1472
|
}
|
|
1451
1473
|
}
|
|
@@ -1597,9 +1619,13 @@ function parseArgs () {
|
|
|
1597
1619
|
|
|
1598
1620
|
if (arg === '--help' || arg === '-h') {
|
|
1599
1621
|
console.log(`
|
|
1600
|
-
Usage:
|
|
1622
|
+
Usage: node <path-to-this-script> [options]
|
|
1623
|
+
npx dialtone-migrate --only typography [options]
|
|
1601
1624
|
|
|
1602
|
-
Migrates legacy typography utility classes to <dt-text> components.
|
|
1625
|
+
Migrates legacy typography utility classes to <dt-text> components. Composed classes
|
|
1626
|
+
(d-headline--*, d-body--*, d-label--*, d-code--md) become a variant prop; override
|
|
1627
|
+
utilities become strength, density, tone, align, truncate and family props.
|
|
1628
|
+
Existing DtText kind + size pairs are left for: npx dialtone-migrate --only text-variant
|
|
1603
1629
|
|
|
1604
1630
|
Options:
|
|
1605
1631
|
--cwd <path> Working directory (default: current directory)
|
|
@@ -1608,18 +1634,20 @@ Options:
|
|
|
1608
1634
|
--yes, -y Apply all changes without prompting
|
|
1609
1635
|
--remove-markers Strip all <!-- dt-text-migrate: review ... --> comments
|
|
1610
1636
|
--validate Read-only mode: scan existing <dt-text> for prop bugs
|
|
1611
|
-
(object syntax, invalid values,
|
|
1637
|
+
(object syntax, invalid values, size without a variant or kind,
|
|
1638
|
+
mixed CSS classes)
|
|
1612
1639
|
--no-import Skip import injection (use when DtText is globally registered)
|
|
1613
1640
|
--package <name> Package name for injected DtText imports
|
|
1614
1641
|
(default: @dialpad/dialtone-vue when a Dialtone import is detected).
|
|
1615
1642
|
Use when Dialtone runs under a custom alias, e.g. @dialpad/dialtone-next.
|
|
1616
1643
|
--help, -h Show help
|
|
1617
1644
|
|
|
1618
|
-
Examples:
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1645
|
+
Examples (installed script path: lib/dist/js/dialtone_migrate_typography/index.mjs in
|
|
1646
|
+
@dialpad/dialtone-css, or dist/js/dialtone_migrate_typography/index.mjs in @dialpad/dialtone):
|
|
1647
|
+
node <script> --dry-run --cwd ./src
|
|
1648
|
+
node <script> --yes
|
|
1649
|
+
node <script> --file src/Foo.vue --dry-run
|
|
1650
|
+
node <script> --remove-markers --cwd ./src
|
|
1623
1651
|
|
|
1624
1652
|
Post-Migration Steps:
|
|
1625
1653
|
1. Add DtText imports as instructed by the script (skipped with --no-import)
|