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;
};
+8
View File
@@ -110,6 +110,9 @@ importers:
'@zip.js/zip.js':
specifier: ^2.7.53
version: 2.7.53
abortcontroller-polyfill:
specifier: ^1.7.8
version: 1.7.8
app-store-server-api:
specifier: ^0.17.1
version: 0.17.1
@@ -3352,6 +3355,9 @@ packages:
resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==}
engines: {node: '>=6.5'}
abortcontroller-polyfill@1.7.8:
resolution: {integrity: sha512-9f1iZ2uWh92VcrU9Y8x+LdM4DLj75VE0MJB8zuF1iUnroEptStw+DQ8EQPMUdfe5k+PkB1uUfDQfWbhstH8LrQ==}
accepts@2.0.0:
resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==}
engines: {node: '>= 0.6'}
@@ -11441,6 +11447,8 @@ snapshots:
dependencies:
event-target-shim: 5.0.1
abortcontroller-polyfill@1.7.8: {}
accepts@2.0.0:
dependencies:
mime-types: 3.0.0