Quantumbraid's picture
download
raw
1.49 kB
import { StateType } from "models";
/** Drop binary float noise on scale (e.g. 1.5000000000000002) without clipping real zoom values. */
export const roundScaleForTransform = (scale: number): number =>
Number.parseFloat(scale.toFixed(8));
export const getTransformStyles = (
x: number,
y: number,
scale: number,
): string => {
// Standard translate prevents blurry svg on the safari
const s = roundScaleForTransform(scale);
return `translate(${x}px, ${y}px) scale(${s})`;
};
export const getMatrixTransformStyles = (
x: number,
y: number,
scale: number,
): string => {
// The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
// Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
const a = scale;
const b = 0;
const c = 0;
const d = scale;
const tx = x;
const ty = y;
return `matrix3d(${a}, ${b}, 0, 0, ${c}, ${d}, 0, 0, 0, 0, 1, 0, ${tx}, ${ty}, 0, 1)`;
};
export const getCenterPosition = (
scale: number,
wrapperComponent: HTMLDivElement,
contentComponent: HTMLDivElement,
): StateType => {
const contentWidth = contentComponent.offsetWidth * scale;
const contentHeight = contentComponent.offsetHeight * scale;
const centerPositionX = (wrapperComponent.offsetWidth - contentWidth) / 2;
const centerPositionY = (wrapperComponent.offsetHeight - contentHeight) / 2;
return {
scale,
positionX: centerPositionX,
positionY: centerPositionY,
};
};

Xet Storage Details

Size:
1.49 kB
·
Xet hash:
e7e06389062b0ac0ca21c6d08fdedd12f78172556d9eeaee254ea2832feb5486

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.