fix mobile

This commit is contained in:
Jack
2023-09-16 17:33:28 +01:00
parent 85b93a0053
commit c3c4aa34ca
2 changed files with 38 additions and 36 deletions

View File

@ -49,15 +49,12 @@ export default class TypstPlugin extends Plugin {
fs: any; fs: any;
async onload() { async onload() {
this.textEncoder = new TextEncoder()
await this.loadSettings()
this.compilerWorker = (new CompilerWorker() as Worker); this.compilerWorker = (new CompilerWorker() as Worker);
if (!Platform.isMobileApp) { if (!Platform.isMobileApp) {
this.compilerWorker.postMessage(true); this.compilerWorker.postMessage(true);
this.fs = require("fs") this.fs = require("fs")
}
this.textEncoder = new TextEncoder()
await this.loadSettings()
let fonts = await Promise.all( let fonts = await Promise.all(
//@ts-expect-error //@ts-expect-error
(await window.queryLocalFonts() as Array) (await window.queryLocalFonts() as Array)
@ -67,6 +64,7 @@ export default class TypstPlugin extends Plugin {
) )
) )
this.compilerWorker.postMessage(fonts, fonts) this.compilerWorker.postMessage(fonts, fonts)
}
// Setup cutom canvas // Setup cutom canvas
TypstRenderElement.compile = (a, b, c, d, e) => this.processThenCompileTypst(a, b, c, d, e) TypstRenderElement.compile = (a, b, c, d, e) => this.processThenCompileTypst(a, b, c, d, e)
@ -233,7 +231,7 @@ export default class TypstPlugin extends Plugin {
const dpr = window.devicePixelRatio; const dpr = window.devicePixelRatio;
// * (72 / 96) // * (72 / 96)
const pxToPt = (px: number) => px.toString() + "pt" const pxToPt = (px: number) => px.toString() + "pt"
const sizing = `#let (WIDTH, HEIGHT, SIZE, THEME) = (${display ? pxToPt(size) : "auto"}, ${!display ? pxToPt(size) : "auto"}, ${pxToPt(fontSize * dpr)}, "${document.body.getCssPropertyValue("color-scheme")}")` const sizing = `#let (WIDTH, HEIGHT, SIZE, THEME) = (${display ? pxToPt(size) : "auto"}, ${!display ? pxToPt(size) : "auto"}, ${pxToPt(fontSize)}, "${document.body.getCssPropertyValue("color-scheme")}")`
return this.compileToTypst( return this.compileToTypst(
path, path,
`${sizing}\n${this.settings.preamable.shared}\n${source}`, `${sizing}\n${this.settings.preamable.shared}\n${source}`,
@ -385,6 +383,8 @@ class TypstSettingTab extends PluginSettingTab {
.addTextArea((c) => c.setValue(this.plugin.settings.preamable.math).onChange(async (value) => { this.plugin.settings.preamable.math = value; await this.plugin.saveSettings() })) .addTextArea((c) => c.setValue(this.plugin.settings.preamable.math).onChange(async (value) => { this.plugin.settings.preamable.math = value; await this.plugin.saveSettings() }))
//Font family settings //Font family settings
if (!Platform.isMobileApp) {
const fontSettings = containerEl.createDiv({ cls: "setting-item font-settings" }) const fontSettings = containerEl.createDiv({ cls: "setting-item font-settings" })
fontSettings.createDiv({ text: "Fonts", cls: "setting-item-name" }) fontSettings.createDiv({ text: "Fonts", cls: "setting-item-name" })
fontSettings.createDiv({ text: "Font family names that should be loaded for Typst from your system. Requires a reload on change.", cls: "setting-item-description" }) fontSettings.createDiv({ text: "Font family names that should be loaded for Typst from your system. Requires a reload on change.", cls: "setting-item-description" })
@ -413,6 +413,7 @@ class TypstSettingTab extends PluginSettingTab {
this.renderFontTags(fontTagsDiv) this.renderFontTags(fontTagsDiv)
} }
}
renderFontTags(fontTagsDiv: HTMLDivElement) { renderFontTags(fontTagsDiv: HTMLDivElement) {

View File

@ -1,4 +1,5 @@
import { optimize } from 'svgo'; //@ts-ignore
import { optimize } from 'svgo/dist/svgo.browser.js';
export default class TypstRenderElement extends HTMLElement { export default class TypstRenderElement extends HTMLElement {
static compile: (path: string, source: string, size: number, display: boolean, fontSize: number) => Promise<ImageData | string>; static compile: (path: string, source: string, size: number, display: boolean, fontSize: number) => Promise<ImageData | string>;