File tree 3 files changed +31
-10
lines changed
3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ following features:
88
88
- The ` flip-start ` ` try-tactic ` is only partially supported. The tactic is
89
89
only applied to property names and anchor sides.
90
90
- a ` position-area ` as a ` try-tactic `
91
- - Fallback does does not support anchor functions that are nested or passed
92
- through custom properties.
91
+ - Fallback does not support percentage anchor-side values, nor anchor
92
+ functions that are passed through custom properties.
93
93
- Polyfill allows anchoring in scroll more permissively than the spec allows,
94
94
for instance without a default ` position-anchor ` .
95
95
- ` anchor-scope ` property on pseudo-elements
Original file line number Diff line number Diff line change @@ -421,15 +421,20 @@ export function applyTryTacticToBlock(
421
421
declarations [ key ] ??= 'revert' ;
422
422
}
423
423
424
- // todo: This does not support anchor functions that are nested or passed
425
- // through custom properties.
426
- if ( isAnchorFunction ( valueAst . children . first ) ) {
427
- valueAst . children . first . children . forEach ( ( item ) => {
428
- if ( isIdentifier ( item ) && isAnchorSide ( item . name ) ) {
429
- item . name = mapAnchorSide ( item . name , tactic ) ;
424
+ // todo: This does not support percentage anchor-side values, nor anchor
425
+ // functions that are passed through custom properties.
426
+ csstree . walk ( valueAst , {
427
+ visit : 'Function' ,
428
+ enter ( node ) {
429
+ if ( isAnchorFunction ( node ) ) {
430
+ node . children . forEach ( ( item ) => {
431
+ if ( isIdentifier ( item ) && isAnchorSide ( item . name ) ) {
432
+ item . name = mapAnchorSide ( item . name , tactic ) ;
433
+ }
434
+ } ) ;
430
435
}
431
- } ) ;
432
- }
436
+ } ,
437
+ } ) ;
433
438
434
439
if ( key === 'position-area' ) {
435
440
valueAst . children . forEach ( ( id ) => {
Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ describe('fallback', () => {
47
47
bottom : 'anchor(self-start)' ,
48
48
} ,
49
49
] ,
50
+ [
51
+ 'flips anchor functions that are nested' ,
52
+ `${ propWrap ( 'bottom' ) } : calc(anchor(top) + 5px);${ propWrap ( 'top' ) } :calc(calc(anchor(--a top) + 5px) - 0.5em)` ,
53
+ {
54
+ top : 'calc(anchor(bottom) + 5px)' ,
55
+ bottom : 'calc(calc(anchor(--a bottom) + 5px) - 0.5em)' ,
56
+ } ,
57
+ ] ,
50
58
[
51
59
'does not flip left and right anchors' ,
52
60
`${ propWrap ( 'left' ) } : anchor(right);${ propWrap ( 'right' ) } :anchor(--a left)` ,
@@ -147,6 +155,14 @@ describe('fallback', () => {
147
155
right : 'anchor(self-start)' ,
148
156
} ,
149
157
] ,
158
+ [
159
+ 'flips anchor functions that are nested' ,
160
+ `${ propWrap ( 'right' ) } : calc(anchor(left) + 5px);${ propWrap ( 'left' ) } :calc(calc(anchor(--a left) + 5px) - 0.5em)` ,
161
+ {
162
+ left : 'calc(anchor(right) + 5px)' ,
163
+ right : 'calc(calc(anchor(--a right) + 5px) - 0.5em)' ,
164
+ } ,
165
+ ] ,
150
166
[
151
167
'does not flip top and bottom anchors' ,
152
168
`${ propWrap ( 'top' ) } : anchor(bottom);${ propWrap ( 'bottom' ) } :anchor(--a top)` ,
You can’t perform that action at this time.
0 commit comments