import type { record, rw } from "@libs/typing"
export const version = "0.0"
export const internal: unique symbol = Symbol.for("@@internal")
export function illegal(args: IArguments): void {
if ((!args[0]) || (typeof args[0] !== "object") || (!(internal in args[0]))) {
throw new TypeError("Illegal constructor")
}
}
export const unimplemented = Object.assign(function (): never {
throw new DOMException("While this feature is supposed to be supported, it has not been implemented yet in @libs/dom", "NotSupportedError")
}, {
getter<T>() {
return unimplemented()
},
})
export function dispatch<T extends EventTarget>(element: T, event: Event) {
element.dispatchEvent(event)
if (`on${event.type}` in element) {
;(element as rw)[`on${event.type}`]?.(event)
}
}
export class Indexable<T> extends Array<T> implements ArrayLike<T> {
constructor(..._: any[]) {
super()
illegal(arguments)
}
get [Symbol.toStringTag](): string {
return this.constructor.name
}
get [internal](): Pick<Array<T>, "push" | "pop" | "find" | "shift" | "unshift" | "splice" | "indexOf" | "map" | "filter"> {
return {
push: super.push.bind(this),
pop: super.pop.bind(this),
shift: super.shift.bind(this),
unshift: super.unshift.bind(this),
splice: super.splice.bind(this),
indexOf: super.indexOf.bind(this),
find: super.find.bind(this),
map: super.map.bind(this),
filter: super.filter.bind(this),
}
}
}
new Set(Object.getOwnPropertyNames(Array)).difference(
new Set([
"prototype",
"name",
"length",
]),
).forEach((property) => (Indexable as unknown as record)[property] = undefined)
new Set(Object.getOwnPropertyNames(Array.prototype)).difference(
new Set([
"constructor",
"item",
"keys",
"values",
"entries",
"forEach",
"length",
"toString",
]),
).forEach((property) => (Indexable.prototype as unknown as record)[property] = undefined)
export type _Permissions = Permissions
export type _PermissionsStatus = PermissionStatus
export type _UserActivation = UserActivation
export type _Navigator = Navigator
export type _MimeTypeArray = MimeTypeArray
export type _MimeType = MimeType
export type _Clipboard = Clipboard
export type _ClipboardItem = ClipboardItem
export type _ClipboardEvent = ClipboardEvent
export type _Node = Node
export type _NodeList = NodeList
export type _Document = Document
export type _DocumentFragment = DocumentFragment
export type _Element = Element
export type _Window = Window
export type _BarProp = BarProp
export type _Attr = Attr
|