Skip to content

Commit 7f45084

Browse files
committed
fix(outline): enhance parseOutline to account for outline-offset in bleed calculation
1 parent 0b5eeab commit 7f45084

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

__tests__/utils.transforms.helpers.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ describe('parseOutline', () => {
6767
const cs = getComputedStyle(div)
6868
expect(parseOutline(cs)).toEqual({ top: 0, right: 0, bottom: 0, left: 0 })
6969
})
70+
71+
it('returns outline width for solid outline with no offset', () => {
72+
const cs = { outlineStyle: 'solid', outlineWidth: '3px', outlineOffset: '0px' }
73+
const res = parseOutline(cs)
74+
expect(res).toEqual({ top: 3, right: 3, bottom: 3, left: 3 })
75+
})
76+
77+
it('adds positive outline-offset to bleed (NEW-3)', () => {
78+
const cs = { outlineStyle: 'solid', outlineWidth: '2px', outlineOffset: '4px' }
79+
const res = parseOutline(cs)
80+
// total = ceil(2) + max(0, ceil(4)) = 2 + 4 = 6
81+
expect(res).toEqual({ top: 6, right: 6, bottom: 6, left: 6 })
82+
})
83+
84+
it('does not subtract for negative outline-offset (NEW-3)', () => {
85+
const cs = { outlineStyle: 'solid', outlineWidth: '3px', outlineOffset: '-2px' }
86+
const res = parseOutline(cs)
87+
// negative offset never reduces bleed below outline width
88+
expect(res).toEqual({ top: 3, right: 3, bottom: 3, left: 3 })
89+
})
7090
})
7191

7292
describe('parseFilterDropShadows', () => {

src/utils/transforms.helpers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ export function parseFilterBlur(cs) {
4747
*/
4848
export function parseOutline(cs) {
4949
if ((cs.outlineStyle || 'none') === 'none') return { top: 0, right: 0, bottom: 0, left: 0 }
50-
const w2 = Math.ceil(parseFloat(cs.outlineWidth || '0') || 0)
51-
return { top: w2, right: w2, bottom: w2, left: w2 }
50+
const w = Math.ceil(parseFloat(cs.outlineWidth || '0') || 0)
51+
// outline-offset > 0 pushes the outline further out, increasing bleed.
52+
// Negative offset moves it inward — it never reduces bleed below the outline width itself.
53+
const offset = parseFloat(cs.outlineOffset || '0') || 0
54+
const total = w + Math.max(0, Math.ceil(offset))
55+
return { top: total, right: total, bottom: total, left: total }
5256
}
5357

5458
/**

0 commit comments

Comments
 (0)