diff options
Diffstat (limited to 'packages/webapi/src')
-rw-r--r-- | packages/webapi/src/exclusions.ts | 3 | ||||
-rw-r--r-- | packages/webapi/src/inheritance.ts | 1 | ||||
-rw-r--r-- | packages/webapi/src/lib/Base64.ts | 7 | ||||
-rw-r--r-- | packages/webapi/src/lib/ContextEvent.ts | 57 | ||||
-rw-r--r-- | packages/webapi/src/lib/Object.ts | 21 | ||||
-rw-r--r-- | packages/webapi/src/lib/Promise.ts | 28 | ||||
-rw-r--r-- | packages/webapi/src/lib/String.ts | 30 | ||||
-rw-r--r-- | packages/webapi/src/lib/utils.ts | 35 | ||||
-rw-r--r-- | packages/webapi/src/polyfill.ts | 27 | ||||
-rw-r--r-- | packages/webapi/src/ponyfill.ts | 22 | ||||
-rw-r--r-- | packages/webapi/src/types.d.ts | 1 |
11 files changed, 1 insertions, 231 deletions
diff --git a/packages/webapi/src/exclusions.ts b/packages/webapi/src/exclusions.ts index edd8274b1..a664483dc 100644 --- a/packages/webapi/src/exclusions.ts +++ b/packages/webapi/src/exclusions.ts @@ -28,7 +28,6 @@ const exclusionsForNode = [ ...exclusionsForElement, ] as const const exclusionsForEventTarget = [ - 'AbortSignal', 'Event', 'CustomEvent', 'EventTarget', @@ -38,7 +37,6 @@ const exclusionsForEventTarget = [ ...exclusionsForNode, ] as const const exclusionsForEvent = [ - 'AbortSignal', 'Event', 'CustomEvent', 'EventTarget', @@ -49,7 +47,6 @@ const exclusionsForEvent = [ ] as const export const exclusions = { - 'Blob+': ['Blob', 'File'], 'Document+': exclusionsForDocument, 'Element+': exclusionsForElement, 'Event+': exclusionsForEvent, diff --git a/packages/webapi/src/inheritance.ts b/packages/webapi/src/inheritance.ts index 713c24928..6e3165633 100644 --- a/packages/webapi/src/inheritance.ts +++ b/packages/webapi/src/inheritance.ts @@ -5,7 +5,6 @@ export const inheritance = { Document: 'Node', DocumentFragment: 'Node', Element: 'Node', - File: 'Blob', HTMLDocument: 'Document', HTMLElement: 'Element', HTMLBodyElement: 'HTMLElement', diff --git a/packages/webapi/src/lib/Base64.ts b/packages/webapi/src/lib/Base64.ts deleted file mode 100644 index 593c56ae0..000000000 --- a/packages/webapi/src/lib/Base64.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function atob(data: string): string { - return Buffer.from(data, 'base64').toString('binary') -} - -export function btoa(data: string): string { - return Buffer.from(data, 'binary').toString('base64') -} diff --git a/packages/webapi/src/lib/ContextEvent.ts b/packages/webapi/src/lib/ContextEvent.ts deleted file mode 100644 index e712c4da1..000000000 --- a/packages/webapi/src/lib/ContextEvent.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Event } from 'event-target-shim' - -/** An event fired by a context requester to signal it desires a named context. */ -export class ContextEvent<T = unknown> extends Event<'context-request'> { - constructor(init: ContextEventInit<T>) { - super('context-request', { bubbles: true, composed: true }) - - init = Object(init) as Required<ContextEventInit<T>> - - this.context = init.context - } - - context!: Context<T> - multiple!: boolean - callback!: ContextCallback<Context<T>> -} - -interface ContextEventInit<T = unknown> { - context: Context<T> - multiple?: boolean - callback: ContextCallback<Context<T>> -} - -/** A Context object defines an optional initial value for a Context, as well as a name identifier for debugging purposes. */ -export type Context<T = unknown> = { - name: string - initialValue?: T -} - -/** A helper type which can extract a Context value type from a Context type. */ -export type ContextType<T extends Context> = T extends Context<infer Y> - ? Y - : never - -/** A function which creates a Context value object */ -export function createContext<T>( - name: string, - initialValue?: T -): Readonly<Context<T>> { - return { - name, - initialValue, - } -} - -/** A callback which is provided by a context requester and is called with the value satisfying the request. */ -export type ContextCallback<ValueType> = ( - value: ValueType, - dispose?: () => void -) => void - -declare global { - interface HTMLElementEventMap { - /** A 'context-request' event can be emitted by any element which desires a context value to be injected by an external provider. */ - 'context-request': ContextEvent - } -} diff --git a/packages/webapi/src/lib/Object.ts b/packages/webapi/src/lib/Object.ts deleted file mode 100644 index cfc1ea4a4..000000000 --- a/packages/webapi/src/lib/Object.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as _ from './utils' - -export const hasOwn = { - hasOwn(instance: object, property: any) { - return _.__object_hasOwnProperty(instance, property) - }, -}.hasOwn - -export const initObject = (target: any, exclude: Set<string>) => { - if (exclude.has('Object') || exclude.has('object') || exclude.has('hasOwn')) - return - - const Class = target.Object || globalThis.Object - - Object.defineProperty(Class, 'hasOwn', { - value: hasOwn, - writable: true, - enumerable: false, - configurable: true, - }) -} diff --git a/packages/webapi/src/lib/Promise.ts b/packages/webapi/src/lib/Promise.ts deleted file mode 100644 index 2591fb56a..000000000 --- a/packages/webapi/src/lib/Promise.ts +++ /dev/null @@ -1,28 +0,0 @@ -export const any = { - async any<T>(iterable: Iterable<T | PromiseLike<T>>): Promise<T> { - return Promise.all( - [...iterable].map((promise) => { - return new Promise((resolve, reject) => - Promise.resolve(promise).then(reject, resolve) - ) - }) - ).then( - (errors) => Promise.reject(errors), - (value) => Promise.resolve<T>(value) - ) - }, -}.any - -export const initPromise = (target: any, exclude: Set<string>) => { - if (exclude.has('Promise') || exclude.has('any')) return - - const Class = target.Promise || globalThis.Promise - - if (!Class.any) - Object.defineProperty(Class, 'any', { - value: any, - writable: true, - enumerable: false, - configurable: true, - }) -} diff --git a/packages/webapi/src/lib/String.ts b/packages/webapi/src/lib/String.ts deleted file mode 100644 index 92d39f39a..000000000 --- a/packages/webapi/src/lib/String.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as _ from './utils' - -export const replaceAll = { - replaceAll( - this: string, - searchValue: RegExp | string, - replaceValue: string | ((substring: string, ...args: any[]) => string) - ) { - return _.__object_isPrototypeOf(RegExp.prototype, searchValue) - ? this.replace(searchValue as RegExp, replaceValue as string) - : this.replace( - new RegExp(_.__string_escapeRegExp(searchValue as string), 'g'), - replaceValue as string - ) - }, -}.replaceAll - -export const initString = (target: any, exclude: Set<string>) => { - if (exclude.has('String') || exclude.has('replaceAll')) return - - const Class = target.String || globalThis.String - - if (!Class.prototype.replaceAll) - Object.defineProperty(Class.prototype, 'replaceAll', { - value: replaceAll, - writable: true, - enumerable: false, - configurable: true, - }) -} diff --git a/packages/webapi/src/lib/utils.ts b/packages/webapi/src/lib/utils.ts index 0086f75b6..61a78e97b 100644 --- a/packages/webapi/src/lib/utils.ts +++ b/packages/webapi/src/lib/utils.ts @@ -1,8 +1,5 @@ import { performance } from 'node:perf_hooks' -/** Returns the milliseconds elapsed since January 1, 1970 00:00:00 UTC. */ -export const __date_now = Date.now - /** Returns the function bound to the given object. */ export const __function_bind = Function.bind.bind( Function.call as unknown as any @@ -12,34 +9,6 @@ export const __function_bind = Function.bind.bind( ...args: TArgs ) => TFunc -/** Returns the function called with the specified values. */ -export const __function_call = Function.call.bind( - Function.call as unknown as any -) as <TArgs extends any, TFunc extends (...args: TArgs[]) => any>( - callback: TFunc, - thisArg: unknown, - ...args: TArgs[] -) => ReturnType<TFunc> - -/** Returns an object with the specified prototype. */ -export const __object_create = Object.create as { - <T extends any = any>(value: T): any extends T ? Record<any, any> : T -} - -/** Returns whether an object has a property with the specified name. */ -export const __object_hasOwnProperty = Function.call.bind( - Object.prototype.hasOwnProperty -) as { - <T1 extends object, T2>(object: T1, key: T2): T2 extends keyof T1 - ? true - : false -} - -/** Returns a string representation of an object. */ -export const __object_toString = Function.call.bind( - Object.prototype.toString -) as { (value: any): string } - /** Returns whether the object prototype exists in another object. */ export const __object_isPrototypeOf = Function.call.bind( Object.prototype.isPrototypeOf @@ -48,10 +17,6 @@ export const __object_isPrototypeOf = Function.call.bind( /** Current high resolution millisecond timestamp. */ export const __performance_now = performance.now as () => number -/** Returns the string escaped for use inside regular expressions. */ -export const __string_escapeRegExp = (value: string) => - value.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&') - // @ts-ignore export const INTERNALS = new WeakMap<unknown, any>() diff --git a/packages/webapi/src/polyfill.ts b/packages/webapi/src/polyfill.ts index 13ad0eb10..4d1531a3f 100644 --- a/packages/webapi/src/polyfill.ts +++ b/packages/webapi/src/polyfill.ts @@ -1,10 +1,5 @@ import { - AbortController, - AbortSignal, alert, - atob, - Blob, - btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, @@ -43,11 +38,7 @@ import { initCustomElementRegistry, initDocument, initMediaQueryList, - initObject, - initPromise, - initRelativeIndexingMethod, initStorage, - initString, initWindow, IntersectionObserver, MediaQueryList, @@ -87,12 +78,7 @@ import { inheritance } from './inheritance' export { pathToPosix } from './lib/utils' export { - AbortController, - AbortSignal, alert, - atob, - Blob, - btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, @@ -162,9 +148,6 @@ export { export const polyfill = (target: any, options?: PolyfillOptions) => { const webAPIs = { - AbortController, - AbortSignal, - Blob, ByteLengthQueuingStrategy, CanvasRenderingContext2D, CharacterData, @@ -225,8 +208,6 @@ export const polyfill = (target: any, options?: PolyfillOptions) => { Window, alert, - atob, - btoa, cancelAnimationFrame, cancelIdleCallback, clearTimeout, @@ -314,12 +295,8 @@ export const polyfill = (target: any, options?: PolyfillOptions) => { } } - initObject(target, excludeOptions) initMediaQueryList(target, excludeOptions) - initPromise(target, excludeOptions) - initRelativeIndexingMethod(target, excludeOptions) initStorage(target, excludeOptions) - initString(target, excludeOptions) initWindow(target, excludeOptions) return target @@ -330,11 +307,7 @@ polyfill.internals = (target: any, name: string) => { CustomElementRegistry: initCustomElementRegistry, Document: initDocument, MediaQueryList: initMediaQueryList, - Object: initObject, - Promise: initPromise, - RelativeIndexingMethod: initRelativeIndexingMethod, Storage: initStorage, - String: initString, Window: initWindow, } diff --git a/packages/webapi/src/ponyfill.ts b/packages/webapi/src/ponyfill.ts index efaad8cd3..429951e15 100644 --- a/packages/webapi/src/ponyfill.ts +++ b/packages/webapi/src/ponyfill.ts @@ -1,11 +1,5 @@ // @ts-check - -import { - AbortController, - AbortSignal, -} from 'abort-controller/dist/abort-controller.mjs' import { Event, EventTarget } from 'event-target-shim' -import { Blob, File } from 'fetch-blob/from.js' import { FormData } from 'formdata-polyfill/esm.min.js' import { ByteLengthQueuingStrategy, @@ -27,7 +21,6 @@ import { cancelAnimationFrame, requestAnimationFrame, } from './lib/AnimationFrame' -import { atob, btoa } from './lib/Base64' import { CharacterData, Comment, Text } from './lib/CharacterData' import { CustomEvent } from './lib/CustomEvent' import { DOMException } from './lib/DOMException' @@ -78,20 +71,13 @@ import { initWindow, Window } from './lib/Window' import { alert } from './lib/Alert' -import { initObject } from './lib/Object' -import { initPromise } from './lib/Promise' -import { initRelativeIndexingMethod } from './lib/RelativeIndexingMethod' -import { initString } from './lib/String' - const fetch = undici.fetch const Headers = undici.Headers const Response = undici.Response const Request = undici.Request +const File = undici.File export { - AbortController, - AbortSignal, - Blob, ByteLengthQueuingStrategy, CanvasRenderingContext2D, CharacterData, @@ -151,8 +137,6 @@ export { WritableStreamDefaultWriter, Window, alert, - atob, - btoa, cancelAnimationFrame, cancelIdleCallback, clearTimeout, @@ -164,10 +148,6 @@ export { initCustomElementRegistry, initDocument, initMediaQueryList, - initObject, - initPromise, - initRelativeIndexingMethod, initStorage, - initString, initWindow, } diff --git a/packages/webapi/src/types.d.ts b/packages/webapi/src/types.d.ts index 2597566ee..3592b7d5a 100644 --- a/packages/webapi/src/types.d.ts +++ b/packages/webapi/src/types.d.ts @@ -2,4 +2,3 @@ declare module 'node:*' declare module '@ungap/structured-clone/esm/index.js' declare module '@ungap/structured-clone/esm/deserialize.js' declare module '@ungap/structured-clone/esm/serialize.js' -declare module 'abort-controller/dist/abort-controller.mjs' |