Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 34x 8x 34x 4x 4x 4x | import { px } from "style-value-types"
import { SVGDimensions } from "../types"
function calcOrigin(origin: number | string, offset: number, size: number) {
return typeof origin === "string"
? origin
: (px as any).transform(offset + size * origin)
}
/**
* The SVG transform origin defaults are different to CSS and is less intuitive,
* so we use the measured dimensions of the SVG to reconcile these.
*/
export function calcSVGTransformOrigin(
dimensions: SVGDimensions,
originX: number | string,
originY: number | string
) {
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width)
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height)
return `${pxOriginX} ${pxOriginY}`
}
|