UNPKG

@jigra/text-zoom

Version:

The Text Zoom API provides the ability to change Web View text size for visual accessibility.

42 lines 1.22 kB
import { Plugins } from "@jigra/core"; export class TextZoomIOS { async get() { const percentage = this.getRaw(); const value = this.textSizePercentageToNumber(percentage); return { value }; } async getPreferred() { return Plugins.TextZoom.getPreferred(); } async set(options) { const num = this.textSizeNumberToPercentage(options.value); this.setRaw(num); } getRaw() { if (typeof document !== "undefined") { return document.body.style.webkitTextSizeAdjust || "100%"; } return "100%"; } setRaw(value) { if (typeof document !== "undefined") { document.body.style.webkitTextSizeAdjust = value; } } textSizePercentageToNumber(percentage) { const m = TextZoomIOS.TEXT_SIZE_REGEX.exec(percentage); if (!m) { return 1; } const parsed = Number.parseInt(m[1], 10); if (Number.isNaN(parsed)) { return 1; } return parsed / 100; } textSizeNumberToPercentage(num) { return `${Math.round(num * 100)}%`; } } TextZoomIOS.TEXT_SIZE_REGEX = /(\d+)%/; //# sourceMappingURL=ios.js.map