Mobile bounds test
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
{ key: 'textBoxBorders', text: 'Text box borders', value: $settings.textBoxBorders },
|
{ key: 'textBoxBorders', text: 'Text box borders', value: $settings.textBoxBorders },
|
||||||
{ key: 'displayOCR', text: 'OCR enabled', value: $settings.displayOCR },
|
{ key: 'displayOCR', text: 'OCR enabled', value: $settings.displayOCR },
|
||||||
{ key: 'boldFont', text: 'Bold font', value: $settings.boldFont },
|
{ key: 'boldFont', text: 'Bold font', value: $settings.boldFont },
|
||||||
{ key: 'pageNum', text: 'Show page number', value: $settings.pageNum }
|
{ key: 'pageNum', text: 'Show page number', value: $settings.pageNum },
|
||||||
|
{ key: 'mobile', text: 'Mobile', value: $settings.mobile }
|
||||||
] as { key: SettingsKey; text: string; value: any }[];
|
] as { key: SettingsKey; text: string; value: any }[];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ export function initPanzoom(node: HTMLElement) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
panzoomStore.set(pz);
|
panzoomStore.set(pz);
|
||||||
|
|
||||||
|
|
||||||
|
pz.on('pan', () => keepInBounds())
|
||||||
|
pz.on('zoom', () => keepInBounds())
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanX = 'left' | 'center' | 'right';
|
type PanX = 'left' | 'center' | 'right';
|
||||||
@@ -135,3 +139,56 @@ export function zoomDefault() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function keepInBounds() {
|
||||||
|
if (!pz || !container) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { mobile } = get(settings)
|
||||||
|
|
||||||
|
if (!mobile) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const transform = pz.getTransform();
|
||||||
|
|
||||||
|
const { x, y, scale } = transform;
|
||||||
|
const { innerWidth, innerHeight } = window
|
||||||
|
|
||||||
|
const width = container.offsetWidth * scale;
|
||||||
|
const height = container.offsetHeight * scale;
|
||||||
|
|
||||||
|
const marginX = innerWidth * 0.01;
|
||||||
|
const marginY = innerHeight * 0.01;
|
||||||
|
|
||||||
|
let minX = innerWidth - width - marginX;
|
||||||
|
let maxX = marginX;
|
||||||
|
let minY = innerHeight - height - marginY;
|
||||||
|
let maxY = marginY;
|
||||||
|
|
||||||
|
if (width + 2 * marginX <= innerWidth) {
|
||||||
|
minX = marginX;
|
||||||
|
maxX = innerWidth - width - marginX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (height + 2 * marginY <= innerHeight) {
|
||||||
|
minY = marginY;
|
||||||
|
maxY = innerHeight - height - marginY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x < minX) {
|
||||||
|
transform.x = minX;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (x > maxX) {
|
||||||
|
transform.x = maxX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < minY) {
|
||||||
|
transform.y = minY;
|
||||||
|
}
|
||||||
|
if (y > maxY) {
|
||||||
|
transform.y = maxY;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ export type Settings = {
|
|||||||
boldFont: boolean;
|
boldFont: boolean;
|
||||||
pageNum: boolean;
|
pageNum: boolean;
|
||||||
hasCover: boolean;
|
hasCover: boolean;
|
||||||
|
mobile: boolean;
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
fontSize: FontSize;
|
fontSize: FontSize;
|
||||||
zoomDefault: ZoomModes;
|
zoomDefault: ZoomModes;
|
||||||
@@ -63,6 +64,7 @@ const defaultSettings: Settings = {
|
|||||||
textBoxBorders: false,
|
textBoxBorders: false,
|
||||||
boldFont: false,
|
boldFont: false,
|
||||||
pageNum: true,
|
pageNum: true,
|
||||||
|
mobile: false,
|
||||||
backgroundColor: '#0d0d0f',
|
backgroundColor: '#0d0d0f',
|
||||||
fontSize: 'auto',
|
fontSize: 'auto',
|
||||||
zoomDefault: 'zoomFitToScreen',
|
zoomDefault: 'zoomFitToScreen',
|
||||||
|
|||||||
Reference in New Issue
Block a user