Skip to content

Commit 70c63ad

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(design): generalize CSS paint sinks and dimension parsing
1 parent 5a1c981 commit 70c63ad

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎scripts/check-design-conformance-colour-assignments.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,16 @@ test('none is not approved as a colour or a context-free local colour alias', ()
597597
})
598598

599599
test('text decoration inspects its paint without treating line/style/thickness as colours', () => {
600-
for (const value of ['underline', 'underline dashed 2px', 'none', 'underline var(--text-body)'])
600+
for (const value of [
601+
'underline',
602+
'underline dashed 2px',
603+
'underline 2pt',
604+
'underline 1Q',
605+
'underline 2cqw',
606+
'underline 1cap',
607+
'none',
608+
'underline var(--text-body)',
609+
])
601610
expect(
602611
flagged({
603612
[ui]: `export function update(node){node.style.textDecoration=${JSON.stringify(value)}}`,
@@ -612,3 +621,21 @@ test('text decoration inspects its paint without treating line/style/thickness a
612621
.unchecked.length
613622
).toBeGreaterThan(0)
614623
})
624+
625+
test('CSS colour longhands inspect authored paint across standard and vendor properties', () => {
626+
for (const property of [
627+
'textEmphasisColor',
628+
'columnRuleColor',
629+
'floodColor',
630+
'stopColor',
631+
'WebkitTextFillColor',
632+
]) {
633+
expect(
634+
flagged({ [ui]: `export function update(node){node.style.${property}='#ff00ff'}` }).length
635+
).toBeGreaterThan(0)
636+
expect(
637+
flagged({ [ui]: `export function update(node){node.style.${property}='var(--text-body)'}` })
638+
).toEqual([])
639+
expect(flagged({ [ui]: `export const data={${property}:'#ff00ff'}` })).toEqual([])
640+
}
641+
})

‎scripts/check-design-conformance.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ test('supported central v3/v4 utility aliases compare as the same styling defini
561561
input(sources)
562562
)
563563
expect(r.findings.filter((f) => f.file === file)).toEqual([])
564-
})
564+
}, 15_000)
565565

566566
test('CSS and inline token provenance survives numeric normalization', async () => {
567567
expect(

‎scripts/design-conformance/control-colour-assignments.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface ColourAssignmentReport {
5858
coverage: { checked: number; verified: number; invalid: number; unresolved: number }
5959
}
6060
const colourProperty =
61-
/^(?:color|background(?:-color|-image)?|border(?:-(?:top|bottom|left|right|inline|block)(?:-start|-end)?)?(?:-color)?|outline(?:-color)?|fill|stroke|caret-color|accent-color|text-decoration(?:-color)?|box-shadow|text-shadow)$/
61+
/^(?:color|(?:-[a-z]+-)?[a-z][\w-]*-color|background(?:-image)?|border(?:-(?:top|bottom|left|right|inline|block)(?:-start|-end)?)?|outline|fill|stroke|text-decoration|box-shadow|text-shadow)$/
6262
const kebab = (key: string) => key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
6363
/** A missing layout variable is not evidence of a colour. Actual colour sinks still take precedence. */
6464
const dimensional = (value: string): boolean => {
@@ -638,13 +638,13 @@ export class ColourAssignments {
638638
}
639639
const shadowSink = assignment.direct && /^(?:box|text)-shadow$/.test(assignment.name)
640640
const checks = assignment.values.map((value): Check => {
641-
const border = assignment.direct ? paintDeclarations(assignment.name, value) : null
642-
if (border) {
643-
const paint = border.filter((declaration) => declaration.category === 'colours')
641+
const shorthand = assignment.direct ? paintDeclarations(assignment.name, value) : null
642+
if (shorthand) {
643+
const paint = shorthand.filter((declaration) => declaration.category === 'colours')
644644
if (!paint.length)
645645
return {
646646
status: 'verified',
647-
reason: 'Border shorthand authors no colour',
647+
reason: 'CSS shorthand authors no explicit colour',
648648
references: [],
649649
}
650650
return combine(

‎scripts/design-conformance/normalize.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ export function paintDeclarations(property: string, value: string): Declaration[
106106
.nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')
107107
.map((node) => {
108108
const part = valueParser.stringify(node)
109+
const dimension = valueParser.unit(part)
110+
const thickness =
111+
/^(?:auto|from-font|0)$/.test(part) ||
112+
(dimension && /^(?:[a-z]+|%)$/i.test(dimension.unit)) ||
113+
(node.type === 'function' && ['calc', 'min', 'max', 'clamp'].includes(node.value))
109114
const suffix = /^(?:none|underline|overline|line-through|blink)$/.test(part)
110115
? 'line'
111116
: /^(?:solid|double|dotted|dashed|wavy)$/.test(part)
112117
? 'style'
113-
: /^(?:auto|from-font|0|[\d.]+(?:px|rem|em|ex|ch|lh|vw|vh|%))$/.test(part) ||
114-
(node.type === 'function' && ['calc', 'min', 'max', 'clamp'].includes(node.value))
118+
: thickness
115119
? 'thickness'
116120
: 'color'
117121
return {

0 commit comments

Comments
 (0)