function define(proto, key, func) {
    Object.defineProperty(proto, key, {
        configurable: true,
        writable: true,
        enumerable: false,
        value: func
    });
}
if (!Promise.withResolvers)
    define(Promise, 'withResolvers', function PromiseWithResolvers() {
        let resolve, reject;
        let promise = new Promise((_resolve, _reject) => {
            resolve = _resolve;
            reject = _reject;
        });
        return { promise, resolve, reject };
    });
if (!Array.prototype.toReversed)
    define(Array.prototype, 'toReversed', function toReversed() {
        return [...this].reverse();
    });
if (!Array.prototype.toSpliced)
    define(Array.prototype, 'toSpliced', function toSpliced(...args) {
        const copy = [...this];
        copy.splice(...args);
        return copy;
    });
if (!Array.prototype.at)
    define(Array.prototype, 'at', function at(index) {
        return index >= 0 ? this[index] : this[index + this.length];
    });
if (!Object.groupBy)
    define(Object, 'groupBy', function groupBy(array, callback) {
        return array.reduce((result, element, index) => {
            const key = callback(element, index);
            result[key] ??= [];
            result[key].push(element);
            return result;
        }, {});
    });
if (!Uint8Array.prototype.toBase64)
    define(Uint8Array.prototype, 'toBase64', function toBase64(options) {
        let binary = '';
        for (let i = 0; i < this.length; i++)
            Array.from(this)
                .map(c => String.fromCharCode(c))
                .join('');
        let base64 = btoa(binary);
        if (options?.alphabet === 'base64url')
            base64 = base64.replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
        return base64;
    });
if (!Uint8Array.fromBase64)
    define(Uint8Array, 'fromBase64', function fromBase64(base64, options) {
        let str = base64;
        if (options?.alphabet === 'base64url')
            str = str.replaceAll('-', '+').replaceAll('_', '/');
        const binary = atob(str); // 如果非法输入，让 DOMException 直接抛出（可用于 "strict" 模式）
        const bytes = new Uint8Array(binary.length);
        for (let i = 0; i < binary.length; i++)
            bytes[i] = binary.charCodeAt(i);
        return bytes;
    });
export {};
//# sourceMappingURL=polyfill.browser.js.map