[refactor] seperate polyfill

This commit is contained in:
kwaroran
2023-05-26 08:53:44 +09:00
parent ef59206b31
commit 752bbf1f32
2 changed files with 32 additions and 26 deletions

30
src/ts/polyfill.ts Normal file
View File

@@ -0,0 +1,30 @@
import { ReadableStream, WritableStream, TransformStream } from "web-streams-polyfill/ponyfill/es2018";
import { Buffer as BufferPolyfill } from 'buffer'
import { polyfill as dragPolyfill} from "mobile-drag-drop"
import {scrollBehaviourDragImageTranslateOverride} from 'mobile-drag-drop/scroll-behaviour'
export function polyfill() {
try {
const testDom = document.createElement('div');
const supports = ('draggable' in testDom) || ('ondragstart' in testDom && 'ondrop' in testDom);
const isIos = navigator.userAgent ? (!!navigator.userAgent.match('iPhone OS') || !!navigator.userAgent.match('iPad')) : false
testDom.remove()
if((!supports) || isIos){
dragPolyfill({
// use this to make use of the scroll behaviour
dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride,
holdToDrag: 400,
forceApply: true
});
}
} catch (error) {
}
globalThis.Buffer = BufferPolyfill
//@ts-ignore
globalThis.WritableStream = globalThis.WritableStream ?? WritableStream
globalThis.ReadableStream = globalThis.ReadableStream ?? ReadableStream
globalThis.TransformStream = globalThis.TransformStream ?? TransformStream
}