Skip to content

Commit 401d30f

Browse files
committed
feat: cache check IOS result
1 parent 5f0f3e7 commit 401d30f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ export function drawImageInCanvas(img) {
186186
* see: https://stackoverflow.com/a/9039885
187187
* @returns {boolean} isIOS device
188188
*/
189-
function isIOS() {
190-
return [
189+
export function isIOS() {
190+
if (isIOS.cachedResult !== undefined) {
191+
return isIOS.cachedResult;
192+
}
193+
isIOS.cachedResult = [
191194
'iPad Simulator',
192195
'iPhone Simulator',
193196
'iPod Simulator',
@@ -197,6 +200,7 @@ function isIOS() {
197200
].includes(navigator.platform)
198201
// iPad on iOS 13 detection
199202
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document);
203+
return isIOS.cachedResult;
200204
}
201205

202206
/**
@@ -213,6 +217,9 @@ export async function drawFileInCanvas(file) {
213217
}
214218
img = await createImageBitmap(file);
215219
} catch (e) {
220+
if (process.env.BUILD === 'development') {
221+
console.error(e);
222+
}
216223
const dataUrl = await getDataUrlFromFile(file);
217224
img = await loadImage(dataUrl);
218225
}

0 commit comments

Comments
 (0)