mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(app): backport rendering improvements (#1580)
This commit is contained in:
1 parent
0c291a01da
commit
42cdc1f877
513 files changed
+98743
-70397
No files matched your search
@@ -2,7 +2,32 @@
|
||||
|
||||
export const REM_BASE_PX = 16;
|
||||
|
||||
class NonFinitePixelValueError extends Error {
|
||||
public constructor(value: number) {
|
||||
super(`Pixel value must be finite: ${value}`);
|
||||
this.name = 'NonFinitePixelValueError';
|
||||
}
|
||||
}
|
||||
|
||||
export function remFromPx(px: number): `${number}rem` {
|
||||
if (!Number.isFinite(px)) {
|
||||
throw new NonFinitePixelValueError(px);
|
||||
}
|
||||
const rounded = Math.round((px / REM_BASE_PX) * 1e5) / 1e5;
|
||||
return `${rounded}rem`;
|
||||
}
|
||||
|
||||
export function getRemScaleForDocument(ownerDocument: Document | null): number {
|
||||
if (ownerDocument == null) {
|
||||
return 1;
|
||||
}
|
||||
const ownerWindow = ownerDocument.defaultView;
|
||||
if (ownerWindow == null) {
|
||||
return 1;
|
||||
}
|
||||
const rootFontSize = Number.parseFloat(ownerWindow.getComputedStyle(ownerDocument.documentElement).fontSize);
|
||||
if (!Number.isFinite(rootFontSize) || rootFontSize <= 0) {
|
||||
return 1;
|
||||
}
|
||||
return rootFontSize / REM_BASE_PX;
|
||||
}
|
||||
Reference in new issue
Block a user