[feat] better polyfill detection

This commit is contained in:
kwaroran
2023-05-26 03:51:29 +09:00
parent e63d8cecbb
commit 5d52dad6e1

View File

@@ -5,14 +5,22 @@ import { loadData } from "./ts/globalApi";
import { ReadableStream, WritableStream, TransformStream } from "web-streams-polyfill/ponyfill/es2018"; import { ReadableStream, WritableStream, TransformStream } from "web-streams-polyfill/ponyfill/es2018";
import { Buffer as BufferPolyfill } from 'buffer' import { Buffer as BufferPolyfill } from 'buffer'
import { initHotkey } from "./ts/hotkey"; import { initHotkey } from "./ts/hotkey";
import {polyfill as dragDropPolyfil} from "mobile-drag-drop";
import {scrollBehaviourDragImageTranslateOverride} from "mobile-drag-drop/scroll-behaviour";
dragDropPolyfil({ const testDom = document.createElement('div');
// use this to make use of the scroll behaviour const supports = ('draggable' in testDom) || ('ondragstart' in testDom && 'ondrop' in testDom);
dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride, const isIos = navigator.userAgent ? (!!navigator.userAgent.match('iPhone OS') || !!navigator.userAgent.match('iPad')) : false
holdToDrag: 400 testDom.remove()
});
if((!supports) || isIos){
const dragDrop = await import("mobile-drag-drop")
const dragDropBehavior = await import("mobile-drag-drop/scroll-behaviour")
dragDrop.polyfill({
// use this to make use of the scroll behaviour
dragImageTranslateOverride: dragDropBehavior.scrollBehaviourDragImageTranslateOverride,
holdToDrag: 400
});
}
//Polyfills //Polyfills
declare var Buffer: typeof BufferPolyfill; declare var Buffer: typeof BufferPolyfill;