(style, bbox, idSuffix = '')
| 123 | // `bbox` must be in the same coordinate space as the drawn paths so a gradient |
| 124 | // spans the whole merged silhouette seamlessly (gradientUnits=userSpaceOnUse). |
| 125 | export const getFillSpec = (style, bbox, idSuffix = '') => { |
| 126 | const id = `sm-fill-${idSuffix}`; |
| 127 | const type = style.fillType || 'solid'; |
| 128 | if (type === 'solid') { |
| 129 | return { type: 'solid', id, paint: style.fill }; |
| 130 | } |
| 131 | |
| 132 | const c1 = style.fill; |
| 133 | const c2 = style.fillColor2 || style.fill; |
| 134 | const cx = bbox.x + bbox.w / 2; |
| 135 | const cy = bbox.y + bbox.h / 2; |
| 136 | |
| 137 | if (type === 'linear') { |
| 138 | const angle = (((style.gradientAngle ?? 135) - 90) * Math.PI) / 180; |
| 139 | const half = (Math.abs(Math.cos(angle)) * bbox.w + Math.abs(Math.sin(angle)) * bbox.h) / 2; |
| 140 | const dx = Math.cos(angle) * half; |
| 141 | const dy = Math.sin(angle) * half; |
| 142 | return { |
| 143 | type: 'linear', |
| 144 | id, |
| 145 | paint: `url(#${id})`, |
| 146 | x1: cx - dx, |
| 147 | y1: cy - dy, |
| 148 | x2: cx + dx, |
| 149 | y2: cy + dy, |
| 150 | stops: [ |
| 151 | { offset: 0, color: c1 }, |
| 152 | { offset: 1, color: c2 } |
| 153 | ] |
| 154 | }; |
| 155 | } |
| 156 | |
| 157 | // radial |
| 158 | return { |
| 159 | type: 'radial', |
| 160 | id, |
| 161 | paint: `url(#${id})`, |
| 162 | cx, |
| 163 | cy, |
| 164 | r: Math.max(bbox.w, bbox.h) / 2, |
| 165 | stops: [ |
| 166 | { offset: 0, color: c1 }, |
| 167 | { offset: 1, color: c2 } |
| 168 | ] |
| 169 | }; |
| 170 | }; |
| 171 | |
| 172 | // Description of the shadow + outer-stroke filter applied to the merged group. |
| 173 | export const getFxSpec = (style, idSuffix = '') => { |
no outgoing calls
no test coverage detected