fix structuredclone

This commit is contained in:
kwaroran
2024-10-25 18:11:00 +09:00
parent b3fddb814e
commit 0f6246bef6
28 changed files with 114 additions and 104 deletions

View File

@@ -3,28 +3,39 @@ 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){
globalThis.polyfilledDragDrop = true
dragPolyfill({
// use this to make use of the scroll behaviour
dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride,
// holdToDrag: 400,
forceApply: true
});
}
} catch (error) {
function safeStructuredClone<T>(data:T):T{
try {
return structuredClone(data)
} catch (error) {
return JSON.parse(JSON.stringify(data))
}
}
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){
globalThis.polyfilledDragDrop = true
dragPolyfill({
// use this to make use of the scroll behaviour
dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride,
// holdToDrag: 400,
forceApply: true
});
}
globalThis.Buffer = BufferPolyfill
//@ts-ignore
globalThis.WritableStream = globalThis.WritableStream ?? WritableStream
globalThis.ReadableStream = globalThis.ReadableStream ?? ReadableStream
} catch (error) {
}
globalThis.safeStructuredClone = safeStructuredClone
globalThis.Buffer = BufferPolyfill
//@ts-ignore
globalThis.WritableStream = globalThis.WritableStream ?? WritableStream
//@ts-ignore
globalThis.ReadableStream = globalThis.ReadableStream ?? ReadableStream
//@ts-ignore
globalThis.TransformStream = globalThis.TransformStream ?? TransformStream
}