compat: polyfill AbortController/AbortSignal on older browsers (#2371)

This commit is contained in:
Huang Xin
2025-10-31 13:15:59 +08:00
committed by GitHub
parent 066d1c5b1e
commit 0d805a64f6
5 changed files with 41 additions and 30 deletions
+1
View File
@@ -67,6 +67,7 @@
"@tauri-apps/plugin-shell": "~2.3.1",
"@tauri-apps/plugin-updater": "^2.9.0",
"@zip.js/zip.js": "^2.7.53",
"abortcontroller-polyfill": "^1.7.8",
"app-store-server-api": "^0.17.1",
"aws4fetch": "^1.0.20",
"clsx": "^2.1.1",
@@ -1,5 +1,6 @@
'use client';
import '@/utils/polyfill';
import i18n from '@/i18n/i18n';
import { useEffect } from 'react';
import { IconContext } from 'react-icons';
-30
View File
@@ -2,36 +2,6 @@ import { BookFormat } from '@/types/book';
import { Contributor, Identifier, LanguageMap } from '@/utils/book';
import * as epubcfi from 'foliate-js/epubcfi.js';
// A groupBy polyfill for foliate-js
Object.groupBy ??= (iterable, callbackfn) => {
const obj = Object.create(null);
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++);
if (key in obj) {
obj[key].push(value);
} else {
obj[key] = [value];
}
}
return obj;
};
Map.groupBy ??= (iterable, callbackfn) => {
const map = new Map();
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++),
list = map.get(key);
if (list) {
list.push(value);
} else {
map.set(key, [value]);
}
}
return map;
};
export const CFI = epubcfi;
export type DocumentFile = File;
+31
View File
@@ -0,0 +1,31 @@
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
// A groupBy polyfill for foliate-js
Object.groupBy ??= (iterable, callbackfn) => {
const obj = Object.create(null);
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++);
if (key in obj) {
obj[key].push(value);
} else {
obj[key] = [value];
}
}
return obj;
};
Map.groupBy ??= (iterable, callbackfn) => {
const map = new Map();
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++),
list = map.get(key);
if (list) {
list.push(value);
} else {
map.set(key, [value]);
}
}
return map;
};