Skip to content

Commit 4ea4b53

Browse files
committed
Add support text-decoration-skip shorthand
1 parent daa1e45 commit 4ea4b53

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

__tests__/style.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,8 +3543,28 @@ describe('text-decoration', () => {
35433543
})
35443544
})
35453545
describe('text-decoration-skip', () => {
3546-
it.todo('parses longhand declarations from a shorthand value')
3547-
it.todo('serializes a shorthand value from the declarations for its longhands')
3546+
test('expansion and reification', () => {
3547+
3548+
const style = createStyleBlock()
3549+
const longhands = shorthands.get('text-decoration-skip')[0]
3550+
3551+
// All equal longhand values
3552+
style.textDecorationSkip = 'auto'
3553+
expect(style).toHaveLength(longhands.length)
3554+
longhands.forEach(longhand => expect(style[longhand]).toBe(initial(longhand)))
3555+
expect(style.textDecorationSkip).toBe('auto')
3556+
3557+
// none
3558+
style.textDecorationSkip = 'none'
3559+
longhands.forEach(longhand =>
3560+
expect(style[longhand]).toBe(longhand === 'text-decoration-skip-self' ? 'no-skip' : 'none'))
3561+
expect(style.textDecorationSkip).toBe('none')
3562+
3563+
// All longhands cannot be represented
3564+
style.textDecorationSkipSelf = 'skip-all'
3565+
expect(style.textDecorationSkip).toBe('')
3566+
expect(style.cssText).toBe('text-decoration-skip-self: skip-all; text-decoration-skip-box: none; text-decoration-skip-spaces: none; text-decoration-skip-ink: none;')
3567+
})
35483568
})
35493569
describe('text-emphasis', () => {
35503570
test('expansion and reification', () => {

lib/parse/shorthand.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,20 @@ function parseTextBox(values, longhands) {
867867
return getInitialLonghandDeclarations(longhands)
868868
}
869869

870+
/**
871+
* @param {object} value
872+
* @param {Map} longhands
873+
* @see {@link https://drafts.csswg.org/css-text-decor-4/#propdef-text-decoration-skip}
874+
*/
875+
function parseTextDecorationSkip(value, longhands) {
876+
if (value.value === 'auto') {
877+
return getInitialLonghandDeclarations(longhands)
878+
}
879+
const declarations = setLonghands(value, longhands)
880+
declarations.set('text-decoration-skip-self', keyword('no-skip', ['text-decoration-skip-self']))
881+
return declarations
882+
}
883+
870884
/**
871885
* @param {object|object[]} values
872886
* @param {string[]} longhands
@@ -1081,6 +1095,8 @@ function parse(value, name, subProperties) {
10811095
return parseTextAlign(value, longhands)
10821096
case 'text-box':
10831097
return parseTextBox(value, longhands)
1098+
case 'text-decoration-skip':
1099+
return parseTextDecorationSkip(value, longhands)
10841100
case 'text-spacing':
10851101
return parseTextSpacing(value, longhands)
10861102
case 'transition':

lib/serialize.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,23 @@ function representTextBox(declarations) {
31303130
return [trim, edge]
31313131
}
31323132

3133+
/**
3134+
* @param {object[]} declarations
3135+
* @returns {string[]}
3136+
* @see {@link https://drafts.csswg.org/css-text-decor-4/#propdef-text-decoration-skip}
3137+
*/
3138+
function representTextDecorationSkip(declarations, longhands) {
3139+
const values = declarations.map(serializeValue)
3140+
if (values.every((value, i) => value === properties[longhands[i]].initial.serialized)) {
3141+
return ['auto']
3142+
}
3143+
const [self, ...tail] = values
3144+
if (self === 'no-skip' && tail.every(value => value === 'none')) {
3145+
return ['none']
3146+
}
3147+
return ['']
3148+
}
3149+
31333150
/**
31343151
* @param {object[]} position
31353152
* @returns {object[]}
@@ -3530,6 +3547,8 @@ function representDeclarationValue({ name, pending, source, value }) {
35303547
return representTextAlign(declarations)
35313548
case 'text-box':
35323549
return representTextBox(declarations)
3550+
case 'text-decoration-skip':
3551+
return representTextDecorationSkip(declarations, longhands)
35333552
case 'text-spacing':
35343553
return representTextSpacing(declarations)
35353554
case 'transition':

0 commit comments

Comments
 (0)