Skip to content

Commit

Permalink
dev: disable browser-side text layout on tablets
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 14, 2023
1 parent 4bff3af commit fbbbeae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare global {
typstChangeTheme?: () => Promise<void>;
debounce<T extends { (...args: any[]): void }>(fn: T, delay = 200): T;
assignSemaHash: (u: number, x: number, y: number) => void;
typstProcessSvg: any;
typstBookRenderPage(
plugin: TypstSvgRenderer,
relPath: string,
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ window.assignSemaHash = (u: number, x: number, y: number) => {
location.hash = `loc-${u}x${x.toFixed(2)}x${y.toFixed(2)}`;
};

const userAgent = navigator.userAgent.toLowerCase();
const isTablet =
/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
userAgent,
);

const typstProcessSvgBase = window.typstProcessSvg;
// console.log('isTablet', isTablet, typstProcessSvgBase);
window.typstProcessSvg = function (t: HTMLElement, n: Record<string, any>) {
n = n || {};
if (isTablet) {
n.layoutText = false;
}
console.log('layout text feature', n);
typstProcessSvgBase(t, n);
};

window.typstBookRenderPage = function (
plugin: TypstRenderer,
relPath: string,
Expand Down

0 comments on commit fbbbeae

Please sign in to comment.