@@ -3,7 +3,7 @@ import { customElement, property } from 'lit/decorators.js';
3
3
import { styleMap } from 'lit/directives/style-map.js' ;
4
4
import { analog , ElementPin } from './pin' ;
5
5
import { clamp } from './utils/clamp' ;
6
- import { calculateBoundingRect } from './utils/geometry ' ;
6
+ import { getScreenCTM } from './utils/ctm-workaround ' ;
7
7
8
8
const knobCenter = {
9
9
x : 9.91 ,
@@ -193,42 +193,11 @@ export class PotentiometerElement extends LitElement {
193
193
194
194
private updateKnobMatrix ( ) {
195
195
const knob = this . shadowRoot ?. querySelector < SVGRectElement > ( '#knob' ) ;
196
- this . pageToKnobMatrix = knob ?. getScreenCTM ( ) ?. inverse ( ) ?? null ;
197
-
198
- const { userAgent } = navigator ;
199
-
200
- if ( userAgent . indexOf ( 'Firefox' ) >= 0 || userAgent . indexOf ( 'Epiphany' ) >= 0 ) {
201
- // Firefox's getScreenCTM() is broken: https://bugzilla.mozilla.org/show_bug.cgi?id=1610093
202
- const firefoxWorkaround =
203
- this . shadowRoot ?. querySelector < SVGRectElement > ( '#firefox-workaround' ) ;
204
- const boundingRect = firefoxWorkaround ?. getBoundingClientRect ( ) ;
205
- const svgRect = firefoxWorkaround ?. ownerSVGElement ?. getBoundingClientRect ( ) ;
206
- if ( ! boundingRect || ! svgRect ) {
207
- return ;
208
- }
209
-
210
- const cx = svgRect . x + svgRect . width / 2 ;
211
- const cy = svgRect . y + svgRect . height / 2 ;
212
- const deltaX = cx - ( boundingRect . x + boundingRect . width / 2 ) ;
213
- const deltaY = cy - ( boundingRect . y + boundingRect . height / 2 ) ;
214
- const angle = ( Math . atan2 ( deltaY , deltaX ) / Math . PI ) * 180 ;
215
- const rotation = new DOMMatrix ( ) . rotate ( angle ) ;
216
- const rotatedRect = calculateBoundingRect ( new DOMRect ( 0 , 9.5 , 1 , 1 ) , rotation ) ;
217
- const sx = rotatedRect . width / boundingRect . width ;
218
- const sy = rotatedRect . height / boundingRect . height ;
219
- this . pageToKnobMatrix = rotation
220
- . inverse ( )
221
- . multiply (
222
- new DOMMatrix ( [
223
- sx ,
224
- 0 ,
225
- 0 ,
226
- sy ,
227
- rotatedRect . left - boundingRect . left * sx ,
228
- rotatedRect . top - boundingRect . top * sy ,
229
- ] )
230
- ) ;
231
- }
196
+ const workaroundElement = this . shadowRoot ?. querySelector < SVGRectElement > ( '#firefox-workaround' ) ;
197
+ this . pageToKnobMatrix =
198
+ knob && workaroundElement
199
+ ? getScreenCTM ( knob , workaroundElement , new DOMRect ( 0 , 9.5 , 1 , 1 ) )
200
+ : null ;
232
201
}
233
202
234
203
private rotateHandler ( event : MouseEvent | TouchEvent ) {
0 commit comments