From 14dec68f6e0b5c090aa0e4c64be0e35c1ed8deff Mon Sep 17 00:00:00 2001 From: tschai-yim <89387771+tschai-yim@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:01:58 +0200 Subject: [PATCH 1/2] fix(vendor/scripts): support spaces in path --- packages/visx-vendor/scripts/buildVendor/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/visx-vendor/scripts/buildVendor/index.ts b/packages/visx-vendor/scripts/buildVendor/index.ts index 06b7b8225..63f6cbace 100644 --- a/packages/visx-vendor/scripts/buildVendor/index.ts +++ b/packages/visx-vendor/scripts/buildVendor/index.ts @@ -72,10 +72,10 @@ async function build() { const { stdout, stderr } = await exec( `babel \ - --config-file ${BABEL_CONFIG_FILE} \ + --config-file "${BABEL_CONFIG_FILE}" \ --only ${transpileGlob} \ - --out-dir ${VENDOR_CJS_PATH} \ - ${NODE_MODULES_PATH}`, + --out-dir "${VENDOR_CJS_PATH}" \ + "${NODE_MODULES_PATH}"`, ); if (stdout) { From 9ca766cdcbffb96ce508308d48ddc86219c61489 Mon Sep 17 00:00:00 2001 From: tschai-yim <89387771+tschai-yim@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:03:08 +0200 Subject: [PATCH 2/2] fix(event): mitigate firefox inconsistency --- packages/visx-event/src/localPointGeneric.ts | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/visx-event/src/localPointGeneric.ts b/packages/visx-event/src/localPointGeneric.ts index b6675f974..93588c442 100644 --- a/packages/visx-event/src/localPointGeneric.ts +++ b/packages/visx-event/src/localPointGeneric.ts @@ -3,6 +3,29 @@ import { EventType } from './types'; import { isSVGElement, isSVGGraphicsElement, isSVGSVGElement } from './typeGuards'; import getXAndYFromEvent from './getXAndYFromEvent'; +const CHILD_ID = '__visx-child-ctm-workaround'; + +/** + * Gets the screen CTM applied to children. + * + * Normally this is equivalent to `node.getScreenCTM()` but + * when `node` is a nested `SVGSVGElement` Firefox returns + * the screen CTM of the parent `SVGSVGElement`. See: + * - https://bugzilla.mozilla.org/show_bug.cgi?id=1344537 + * - https://bugzilla.mozilla.org/show_bug.cgi?id=1446011 + */ +function getChildScreenCTM(node: SVGGraphicsElement): DOMMatrix | null { + if (!(node instanceof SVGSVGElement)) return node.getScreenCTM(); + let child = node.children.namedItem(CHILD_ID) as SVGGraphicsElement; + if (child === null) { + child = document.createElementNS('http://www.w3.org/2000/svg', 'g'); + child.id = CHILD_ID; + node.appendChild(child); + } + const screenCTM = child.getScreenCTM(); + return screenCTM; +} + export default function localPoint(node: Element, event: EventType) { if (!node || !event) return null; @@ -10,7 +33,7 @@ export default function localPoint(node: Element, event: EventType) { // find top-most SVG const svg = isSVGElement(node) ? node.ownerSVGElement : node; - const screenCTM = isSVGGraphicsElement(svg) ? svg.getScreenCTM() : null; + const screenCTM = isSVGGraphicsElement(svg) ? getChildScreenCTM(svg) : null; if (isSVGSVGElement(svg) && screenCTM) { let point = svg.createSVGPoint();