|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const { |
| 4 | + visit, |
| 5 | + visitSkip, |
4 | 6 | querySelector, |
5 | | - closestByName, |
6 | 7 | detachNodeFromParent, |
7 | 8 | } = require('../lib/xast.js'); |
8 | 9 | const { collectStylesheet, computeStyle } = require('../lib/style.js'); |
@@ -67,6 +68,30 @@ exports.fn = (root, params) => { |
67 | 68 | } = params; |
68 | 69 | const stylesheet = collectStylesheet(root); |
69 | 70 |
|
| 71 | + visit(root, { |
| 72 | + element: { |
| 73 | + enter: (node, parentNode) => { |
| 74 | + // transparent element inside clipPath still affect clipped elements |
| 75 | + if (node.name === 'clipPath') { |
| 76 | + return visitSkip; |
| 77 | + } |
| 78 | + const computedStyle = computeStyle(stylesheet, node); |
| 79 | + // opacity="0" |
| 80 | + // |
| 81 | + // https://www.w3.org/TR/SVG11/masking.html#ObjectAndGroupOpacityProperties |
| 82 | + if ( |
| 83 | + opacity0 && |
| 84 | + computedStyle.opacity && |
| 85 | + computedStyle.opacity.type === 'static' && |
| 86 | + computedStyle.opacity.value === '0' |
| 87 | + ) { |
| 88 | + detachNodeFromParent(node, parentNode); |
| 89 | + return; |
| 90 | + } |
| 91 | + }, |
| 92 | + }, |
| 93 | + }); |
| 94 | + |
70 | 95 | return { |
71 | 96 | element: { |
72 | 97 | enter: (node, parentNode) => { |
@@ -102,21 +127,6 @@ exports.fn = (root, params) => { |
102 | 127 | return; |
103 | 128 | } |
104 | 129 |
|
105 | | - // opacity="0" |
106 | | - // |
107 | | - // https://www.w3.org/TR/SVG11/masking.html#ObjectAndGroupOpacityProperties |
108 | | - if ( |
109 | | - opacity0 && |
110 | | - computedStyle.opacity && |
111 | | - computedStyle.opacity.type === 'static' && |
112 | | - computedStyle.opacity.value === '0' && |
113 | | - // transparent element inside clipPath still affect clipped elements |
114 | | - closestByName(node, 'clipPath') == null |
115 | | - ) { |
116 | | - detachNodeFromParent(node, parentNode); |
117 | | - return; |
118 | | - } |
119 | | - |
120 | 130 | // Circles with zero radius |
121 | 131 | // |
122 | 132 | // https://www.w3.org/TR/SVG11/shapes.html#CircleElementRAttribute |
|
0 commit comments