Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] Fix scale #3031

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/web/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,30 @@ export function calculateViewScale(view: HTMLElement) {
scaleY: 1,
};

const scales = styles.scale.split(' ');
// Get scales from scale property
if (styles.scale !== undefined && styles.scale !== 'none') {
const scales = styles.scale.split(' ');

if (scales[0] !== 'none') {
resultScales.scaleX = parseFloat(scales[0]);
}
if (scales[0]) {
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved
resultScales.scaleX = parseFloat(scales[0]);
}

if (scales[1]) {
resultScales.scaleY = parseFloat(scales[1]);
resultScales.scaleY = scales[1]
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved
? parseFloat(scales[1])
: parseFloat(scales[0]);
}

// Get scales from transform property
const matrixElements = new RegExp(/matrix\((.+)\)/).exec(
styles.transform
)?.[1];

if (!matrixElements) {
return resultScales;
}

const matrixElementsArray = matrixElements.split(', ');
if (matrixElements) {
const matrixElementsArray = matrixElements.split(', ');

resultScales.scaleX *= parseFloat(matrixElementsArray[0]);
resultScales.scaleY *= parseFloat(matrixElementsArray[3]);
resultScales.scaleX *= parseFloat(matrixElementsArray[0]);
resultScales.scaleY *= parseFloat(matrixElementsArray[3]);
}

return resultScales;
}
Loading