UNPKG

@mux/mux-uploader

Version:

An uploader elements to be used with Mux Direct Uploads

4 lines • 202 kB
{ "version": 3, "sources": ["../src/constants.ts", "../src/polyfills/index.ts", "../../../node_modules/@mux/upchunk/node_modules/global/window.js", "../../../node_modules/@mux/upchunk/node_modules/is-function/index.js", "../../../node_modules/@mux/upchunk/node_modules/parse-headers/parse-headers.js", "../../../node_modules/@mux/upchunk/node_modules/xtend/immutable.js", "../../../node_modules/@mux/upchunk/node_modules/xhr/index.js", "../../../node_modules/@mux/upchunk/node_modules/src/lib/misc.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/error-handler.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/global.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/warning-handler.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/warnings.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/event.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/dom-exception.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/event-wrapper.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/listener.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/listener-list.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/listener-list-map.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/event-target.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/event-attribute-handler.ts", "../../../node_modules/@mux/upchunk/node_modules/src/lib/legacy.ts", "../../../node_modules/@mux/upchunk/src/upchunk.ts", "../src/utils/element-utils.ts", "../src/mux-uploader-drop.ts", "../src/utils/progress.ts", "../src/mux-uploader-progress.ts", "../src/mux-uploader-status.ts", "../src/mux-uploader-retry.ts", "../src/mux-uploader-pause.ts", "../src/mux-uploader-file-select.ts", "../src/layouts/block.ts", "../src/mux-uploader.ts", "../src/mux-uploader-sr-text.ts", "../src/index.ts"], "sourcesContent": ["export type ProgressTypes = {\n BAR: 'bar';\n RADIAL: 'radial';\n PERCENTAGE: 'percentage';\n};\n\nexport const ProgressTypes: ProgressTypes = {\n BAR: 'bar',\n RADIAL: 'radial',\n PERCENTAGE: 'percentage',\n};\n", "/* eslint @typescript-eslint/no-empty-function: \"off\" */\n\nclass EventTarget {\n addEventListener() {}\n removeEventListener() {}\n dispatchEvent(_event: Event) {\n return true;\n }\n}\n\n// @github/template-parts requires DocumentFragment to be available on globalThis for SSR\nif (typeof DocumentFragment === 'undefined') {\n class DocumentFragment extends EventTarget {}\n // @ts-ignore\n globalThis.DocumentFragment = DocumentFragment;\n}\n\nclass HTMLElement extends EventTarget {}\nclass HTMLVideoElement extends EventTarget {}\n\nconst customElements: CustomElementRegistry = {\n get(_name: string) {\n return undefined;\n },\n define(_name, _constructor, _options) {},\n getName(_constructor) {\n return null;\n },\n upgrade(_root) {},\n whenDefined(_name) {\n return Promise.resolve(HTMLElement as unknown as CustomElementConstructor);\n },\n};\n\nclass CustomEvent {\n #detail;\n get detail() {\n return this.#detail;\n }\n constructor(_typeArg: string, eventInitDict: CustomEventInit = {}) {\n // super(typeArg, eventInitDict);\n this.#detail = eventInitDict?.detail;\n }\n initCustomEvent() {}\n}\n\nfunction createElement(_tagName: string, _options?: ElementCreationOptions): HTMLElement {\n return new HTMLElement();\n}\n\nconst globalThisShim = {\n document: {\n createElement,\n },\n DocumentFragment,\n customElements,\n CustomEvent,\n EventTarget,\n HTMLElement,\n HTMLVideoElement,\n};\n\n// const isServer = typeof window === 'undefined' || typeof globalThis.customElements === 'undefined';\n// const GlobalThis = isServer ? globalThisShim : globalThis;\n// const Document = isServer ? globalThisShim.document : globalThis.document;\n//\n// export { GlobalThis as globalThis, Document as document };\nconst isServer = typeof window === 'undefined' || typeof globalThis.customElements === 'undefined';\ntype GlobalThis = typeof globalThis;\nconst internalGlobalThis: GlobalThis = (isServer ? globalThisShim : globalThis) as GlobalThis;\nconst internalDocument: Document = (isServer ? globalThisShim.document : globalThis.document) as Document;\n\nexport { internalGlobalThis as globalThis, internalDocument as document };\n", "var win;\n\nif (typeof window !== \"undefined\") {\n win = window;\n} else if (typeof global !== \"undefined\") {\n win = global;\n} else if (typeof self !== \"undefined\"){\n win = self;\n} else {\n win = {};\n}\n\nmodule.exports = win;\n", "module.exports = isFunction\n\nvar toString = Object.prototype.toString\n\nfunction isFunction (fn) {\n if (!fn) {\n return false\n }\n var string = toString.call(fn)\n return string === '[object Function]' ||\n (typeof fn === 'function' && string !== '[object RegExp]') ||\n (typeof window !== 'undefined' &&\n // IE8 and below\n (fn === window.setTimeout ||\n fn === window.alert ||\n fn === window.confirm ||\n fn === window.prompt))\n};\n", "var trim = function(string) {\n return string.replace(/^\\s+|\\s+$/g, '');\n}\n , isArray = function(arg) {\n return Object.prototype.toString.call(arg) === '[object Array]';\n }\n\nmodule.exports = function (headers) {\n if (!headers)\n return {}\n\n var result = {}\n\n var headersArr = trim(headers).split('\\n')\n\n for (var i = 0; i < headersArr.length; i++) {\n var row = headersArr[i]\n var index = row.indexOf(':')\n , key = trim(row.slice(0, index)).toLowerCase()\n , value = trim(row.slice(index + 1))\n\n if (typeof(result[key]) === 'undefined') {\n result[key] = value\n } else if (isArray(result[key])) {\n result[key].push(value)\n } else {\n result[key] = [ result[key], value ]\n }\n }\n\n return result\n}\n", "module.exports = extend\n\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction extend() {\n var target = {}\n\n for (var i = 0; i < arguments.length; i++) {\n var source = arguments[i]\n\n for (var key in source) {\n if (hasOwnProperty.call(source, key)) {\n target[key] = source[key]\n }\n }\n }\n\n return target\n}\n", "\"use strict\";\nvar window = require(\"global/window\")\nvar isFunction = require(\"is-function\")\nvar parseHeaders = require(\"parse-headers\")\nvar xtend = require(\"xtend\")\n\nmodule.exports = createXHR\n// Allow use of default import syntax in TypeScript\nmodule.exports.default = createXHR;\ncreateXHR.XMLHttpRequest = window.XMLHttpRequest || noop\ncreateXHR.XDomainRequest = \"withCredentials\" in (new createXHR.XMLHttpRequest()) ? createXHR.XMLHttpRequest : window.XDomainRequest\n\nforEachArray([\"get\", \"put\", \"post\", \"patch\", \"head\", \"delete\"], function(method) {\n createXHR[method === \"delete\" ? \"del\" : method] = function(uri, options, callback) {\n options = initParams(uri, options, callback)\n options.method = method.toUpperCase()\n return _createXHR(options)\n }\n})\n\nfunction forEachArray(array, iterator) {\n for (var i = 0; i < array.length; i++) {\n iterator(array[i])\n }\n}\n\nfunction isEmpty(obj){\n for(var i in obj){\n if(obj.hasOwnProperty(i)) return false\n }\n return true\n}\n\nfunction initParams(uri, options, callback) {\n var params = uri\n\n if (isFunction(options)) {\n callback = options\n if (typeof uri === \"string\") {\n params = {uri:uri}\n }\n } else {\n params = xtend(options, {uri: uri})\n }\n\n params.callback = callback\n return params\n}\n\nfunction createXHR(uri, options, callback) {\n options = initParams(uri, options, callback)\n return _createXHR(options)\n}\n\nfunction _createXHR(options) {\n if(typeof options.callback === \"undefined\"){\n throw new Error(\"callback argument missing\")\n }\n\n var called = false\n var callback = function cbOnce(err, response, body){\n if(!called){\n called = true\n options.callback(err, response, body)\n }\n }\n\n function readystatechange() {\n if (xhr.readyState === 4) {\n setTimeout(loadFunc, 0)\n }\n }\n\n function getBody() {\n // Chrome with requestType=blob throws errors arround when even testing access to responseText\n var body = undefined\n\n if (xhr.response) {\n body = xhr.response\n } else {\n body = xhr.responseText || getXml(xhr)\n }\n\n if (isJson) {\n try {\n body = JSON.parse(body)\n } catch (e) {}\n }\n\n return body\n }\n\n function errorFunc(evt) {\n clearTimeout(timeoutTimer)\n if(!(evt instanceof Error)){\n evt = new Error(\"\" + (evt || \"Unknown XMLHttpRequest Error\") )\n }\n evt.statusCode = 0\n return callback(evt, failureResponse)\n }\n\n // will load the data & process the response in a special response object\n function loadFunc() {\n if (aborted) return\n var status\n clearTimeout(timeoutTimer)\n if(options.useXDR && xhr.status===undefined) {\n //IE8 CORS GET successful response doesn't have a status field, but body is fine\n status = 200\n } else {\n status = (xhr.status === 1223 ? 204 : xhr.status)\n }\n var response = failureResponse\n var err = null\n\n if (status !== 0){\n response = {\n body: getBody(),\n statusCode: status,\n method: method,\n headers: {},\n url: uri,\n rawRequest: xhr\n }\n if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE\n response.headers = parseHeaders(xhr.getAllResponseHeaders())\n }\n } else {\n err = new Error(\"Internal XMLHttpRequest Error\")\n }\n return callback(err, response, response.body)\n }\n\n var xhr = options.xhr || null\n\n if (!xhr) {\n if (options.cors || options.useXDR) {\n xhr = new createXHR.XDomainRequest()\n }else{\n xhr = new createXHR.XMLHttpRequest()\n }\n }\n\n var key\n var aborted\n var uri = xhr.url = options.uri || options.url\n var method = xhr.method = options.method || \"GET\"\n var body = options.body || options.data\n var headers = xhr.headers = options.headers || {}\n var sync = !!options.sync\n var isJson = false\n var timeoutTimer\n var failureResponse = {\n body: undefined,\n headers: {},\n statusCode: 0,\n method: method,\n url: uri,\n rawRequest: xhr\n }\n\n if (\"json\" in options && options.json !== false) {\n isJson = true\n headers[\"accept\"] || headers[\"Accept\"] || (headers[\"Accept\"] = \"application/json\") //Don't override existing accept header declared by user\n if (method !== \"GET\" && method !== \"HEAD\") {\n headers[\"content-type\"] || headers[\"Content-Type\"] || (headers[\"Content-Type\"] = \"application/json\") //Don't override existing accept header declared by user\n body = JSON.stringify(options.json === true ? body : options.json)\n }\n }\n\n xhr.onreadystatechange = readystatechange\n xhr.onload = loadFunc\n xhr.onerror = errorFunc\n // IE9 must have onprogress be set to a unique function.\n xhr.onprogress = function () {\n // IE must die\n }\n xhr.onabort = function(){\n aborted = true;\n }\n xhr.ontimeout = errorFunc\n xhr.open(method, uri, !sync, options.username, options.password)\n //has to be after open\n if(!sync) {\n xhr.withCredentials = !!options.withCredentials\n }\n // Cannot set timeout with sync request\n // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly\n // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent\n if (!sync && options.timeout > 0 ) {\n timeoutTimer = setTimeout(function(){\n if (aborted) return\n aborted = true//IE9 may still call readystatechange\n xhr.abort(\"timeout\")\n var e = new Error(\"XMLHttpRequest timeout\")\n e.code = \"ETIMEDOUT\"\n errorFunc(e)\n }, options.timeout )\n }\n\n if (xhr.setRequestHeader) {\n for(key in headers){\n if(headers.hasOwnProperty(key)){\n xhr.setRequestHeader(key, headers[key])\n }\n }\n } else if (options.headers && !isEmpty(options.headers)) {\n throw new Error(\"Headers cannot be set on an XDomainRequest object\")\n }\n\n if (\"responseType\" in options) {\n xhr.responseType = options.responseType\n }\n\n if (\"beforeSend\" in options &&\n typeof options.beforeSend === \"function\"\n ) {\n options.beforeSend(xhr)\n }\n\n // Microsoft Edge browser sends \"undefined\" when send is called with undefined value.\n // XMLHttpRequest spec says to pass null as body to indicate no body\n // See https://github.com/naugtur/xhr/issues/100.\n xhr.send(body || null)\n\n return xhr\n\n\n}\n\nfunction getXml(xhr) {\n // xhr.responseXML will throw Exception \"InvalidStateError\" or \"DOMException\"\n // See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML.\n try {\n if (xhr.responseType === \"document\") {\n return xhr.responseXML\n }\n var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === \"parsererror\"\n if (xhr.responseType === \"\" && !firefoxBugTakenEffect) {\n return xhr.responseXML\n }\n } catch (e) {}\n\n return null\n}\n\nfunction noop() {}\n", "/**\n * Assert a condition.\n * @param condition The condition that it should satisfy.\n * @param message The error message.\n * @param args The arguments for replacing placeholders in the message.\n */\nexport function assertType(\n condition: boolean,\n message: string,\n ...args: any[]\n): asserts condition {\n if (!condition) {\n throw new TypeError(format(message, args))\n }\n}\n\n/**\n * Convert a text and arguments to one string.\n * @param message The formating text\n * @param args The arguments.\n */\nexport function format(message: string, args: any[]): string {\n let i = 0\n return message.replace(/%[os]/gu, () => anyToString(args[i++]))\n}\n\n/**\n * Convert a value to a string representation.\n * @param x The value to get the string representation.\n */\nexport function anyToString(x: any): string {\n if (typeof x !== \"object\" || x === null) {\n return String(x)\n }\n return Object.prototype.toString.call(x)\n}\n", "import { anyToString, assertType } from \"./misc\"\n\ndeclare const console: any\ndeclare const dispatchEvent: any\ndeclare const ErrorEvent: any\ndeclare const process: any\n\nlet currentErrorHandler: setErrorHandler.ErrorHandler | undefined\n\n/**\n * Set the error handler.\n * @param value The error handler to set.\n */\nexport function setErrorHandler(\n value: setErrorHandler.ErrorHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The error handler must be a function or undefined, but got %o.\",\n value,\n )\n currentErrorHandler = value\n}\nexport namespace setErrorHandler {\n /**\n * The error handler.\n * @param error The thrown error object.\n */\n export type ErrorHandler = (error: Error) => void\n}\n\n/**\n * Print a error message.\n * @param maybeError The error object.\n */\nexport function reportError(maybeError: unknown): void {\n try {\n const error =\n maybeError instanceof Error\n ? maybeError\n : new Error(anyToString(maybeError))\n\n // Call the user-defined error handler if exists.\n if (currentErrorHandler) {\n currentErrorHandler(error)\n return\n }\n\n // Dispatch an `error` event if this is on a browser.\n if (\n typeof dispatchEvent === \"function\" &&\n typeof ErrorEvent === \"function\"\n ) {\n dispatchEvent(\n new ErrorEvent(\"error\", { error, message: error.message }),\n )\n }\n\n // Emit an `uncaughtException` event if this is on Node.js.\n //istanbul ignore else\n else if (\n typeof process !== \"undefined\" &&\n typeof process.emit === \"function\"\n ) {\n process.emit(\"uncaughtException\", error)\n return\n }\n\n // Otherwise, print the error.\n console.error(error)\n } catch {\n // ignore.\n }\n}\n", "declare const globalThis: any\ndeclare const window: any\ndeclare const self: any\ndeclare const global: any\n\n/**\n * The global object.\n */\n//istanbul ignore next\nexport const Global: any =\n typeof window !== \"undefined\"\n ? window\n : typeof self !== \"undefined\"\n ? self\n : typeof global !== \"undefined\"\n ? global\n : typeof globalThis !== \"undefined\"\n ? globalThis\n : undefined\n", "import { assertType } from \"./misc\"\n\ndeclare const console: any\n\nlet currentWarnHandler: setWarningHandler.WarningHandler | undefined\n\n/**\n * Set the warning handler.\n * @param value The warning handler to set.\n */\nexport function setWarningHandler(\n value: setWarningHandler.WarningHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The warning handler must be a function or undefined, but got %o.\",\n value,\n )\n currentWarnHandler = value\n}\nexport namespace setWarningHandler {\n /**\n * The warning information.\n */\n export interface Warning {\n /**\n * The code of this warning.\n */\n code: string\n /**\n * The message in English.\n */\n message: string\n /**\n * The arguments for replacing placeholders in the text.\n */\n args: any[]\n }\n\n /**\n * The warning handler.\n * @param warning The warning.\n */\n export type WarningHandler = (warning: Warning) => void\n}\n\n/**\n * The warning information.\n */\nexport class Warning<TArgs extends any[]> {\n readonly code: string\n readonly message: string\n\n constructor(code: string, message: string) {\n this.code = code\n this.message = message\n }\n\n /**\n * Report this warning.\n * @param args The arguments of the warning.\n */\n warn(...args: TArgs): void {\n try {\n // Call the user-defined warning handler if exists.\n if (currentWarnHandler) {\n currentWarnHandler({ ...this, args })\n return\n }\n\n // Otherwise, print the warning.\n const stack = (new Error().stack ?? \"\").replace(\n /^(?:.+?\\n){2}/gu,\n \"\\n\",\n )\n console.warn(this.message, ...args, stack)\n } catch {\n // Ignore.\n }\n }\n}\n", "import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Warning } from \"./warning-handler\"\n\nexport const InitEventWasCalledWhileDispatching = new Warning<[]>(\n \"W01\",\n \"Unable to initialize event under dispatching.\",\n)\n\nexport const FalsyWasAssignedToCancelBubble = new Warning<[]>(\n \"W02\",\n \"Assigning any falsy value to 'cancelBubble' property has no effect.\",\n)\n\nexport const TruthyWasAssignedToReturnValue = new Warning<[]>(\n \"W03\",\n \"Assigning any truthy value to 'returnValue' property has no effect.\",\n)\n\nexport const NonCancelableEventWasCanceled = new Warning<[]>(\n \"W04\",\n \"Unable to preventDefault on non-cancelable events.\",\n)\n\nexport const CanceledInPassiveListener = new Warning<[]>(\n \"W05\",\n \"Unable to preventDefault inside passive event listener invocation.\",\n)\n\nexport const EventListenerWasDuplicated = new Warning<\n [type: \"bubble\" | \"capture\", callback: EventTarget.EventListener<any, any>]\n>(\n \"W06\",\n \"An event listener wasn't added because it has been added already: %o, %o\",\n)\n\nexport const OptionWasIgnored = new Warning<\n [name: \"passive\" | \"once\" | \"signal\"]\n>(\n \"W07\",\n \"The %o option value was abandoned because the event listener wasn't added as duplicated.\",\n)\n\nexport const InvalidEventListener = new Warning<\n [callback: EventTarget.EventListener<any, any> | {} | null | undefined]\n>(\n \"W08\",\n \"The 'callback' argument must be a function or an object that has 'handleEvent' method: %o\",\n)\n\nexport const InvalidAttributeHandler = new Warning<\n [callback: EventTarget.EventListener<any, any> | {}]\n>(\"W09\", \"Event attribute handler must be a function: %o\")\n", "import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\nimport {\n CanceledInPassiveListener,\n FalsyWasAssignedToCancelBubble,\n InitEventWasCalledWhileDispatching,\n NonCancelableEventWasCanceled,\n TruthyWasAssignedToReturnValue,\n} from \"./warnings\"\n\n/*eslint-disable class-methods-use-this */\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * `EventTarget` shim can control the internal state of this `Event` objects.\n * @see https://dom.spec.whatwg.org/#event\n */\nexport class Event<TEventType extends string = string> {\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n static get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n static get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n static get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n static get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * Initialize this event instance.\n * @param type The type of this event.\n * @param eventInitDict Options to initialize.\n * @see https://dom.spec.whatwg.org/#dom-event-event\n */\n constructor(type: TEventType, eventInitDict?: Event.EventInit) {\n Object.defineProperty(this, \"isTrusted\", {\n value: false,\n enumerable: true,\n })\n\n const opts = eventInitDict ?? {}\n internalDataMap.set(this, {\n type: String(type),\n bubbles: Boolean(opts.bubbles),\n cancelable: Boolean(opts.cancelable),\n composed: Boolean(opts.composed),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n inPassiveListenerFlag: false,\n dispatchFlag: false,\n timeStamp: Date.now(),\n })\n }\n\n /**\n * The type of this event.\n * @see https://dom.spec.whatwg.org/#dom-event-type\n */\n get type(): TEventType {\n return $(this).type as TEventType\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n get target(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @deprecated Use the `target` property instead.\n * @see https://dom.spec.whatwg.org/#dom-event-srcelement\n */\n get srcElement(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n get currentTarget(): EventTarget | null {\n return $(this).currentTarget\n }\n\n /**\n * The event target of the current dispatching.\n * This doesn't support node tree.\n * @see https://dom.spec.whatwg.org/#dom-event-composedpath\n */\n composedPath(): EventTarget[] {\n const currentTarget = $(this).currentTarget\n if (currentTarget) {\n return [currentTarget]\n }\n return []\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * The current event phase.\n * @see https://dom.spec.whatwg.org/#dom-event-eventphase\n */\n get eventPhase(): number {\n return $(this).dispatchFlag ? 2 : 0\n }\n\n /**\n * Stop event bubbling.\n * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value.\n * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation\n */\n stopPropagation(): void {\n $(this).stopPropagationFlag = true\n }\n\n /**\n * `true` if event bubbling was stopped.\n * @deprecated\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n get cancelBubble(): boolean {\n return $(this).stopPropagationFlag\n }\n\n /**\n * Stop event bubbling if `true` is set.\n * @deprecated Use the `stopPropagation()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n set cancelBubble(value: boolean) {\n if (value) {\n $(this).stopPropagationFlag = true\n } else {\n FalsyWasAssignedToCancelBubble.warn()\n }\n }\n\n /**\n * Stop event bubbling and subsequent event listener callings.\n * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation\n */\n stopImmediatePropagation(): void {\n const data = $(this)\n data.stopPropagationFlag = data.stopImmediatePropagationFlag = true\n }\n\n /**\n * `true` if this event will bubble.\n * @see https://dom.spec.whatwg.org/#dom-event-bubbles\n */\n get bubbles(): boolean {\n return $(this).bubbles\n }\n\n /**\n * `true` if this event can be canceled by the `preventDefault()` method.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelable\n */\n get cancelable(): boolean {\n return $(this).cancelable\n }\n\n /**\n * `true` if the default behavior will act.\n * @deprecated Use the `defaultPrevented` proeprty instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n get returnValue(): boolean {\n return !$(this).canceledFlag\n }\n\n /**\n * Cancel the default behavior if `false` is set.\n * @deprecated Use the `preventDefault()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n set returnValue(value: boolean) {\n if (!value) {\n setCancelFlag($(this))\n } else {\n TruthyWasAssignedToReturnValue.warn()\n }\n }\n\n /**\n * Cancel the default behavior.\n * @see https://dom.spec.whatwg.org/#dom-event-preventdefault\n */\n preventDefault(): void {\n setCancelFlag($(this))\n }\n\n /**\n * `true` if the default behavior was canceled.\n * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented\n */\n get defaultPrevented(): boolean {\n return $(this).canceledFlag\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-composed\n */\n get composed(): boolean {\n return $(this).composed\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-istrusted\n */\n //istanbul ignore next\n get isTrusted(): boolean {\n return false\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-timestamp\n */\n get timeStamp(): number {\n return $(this).timeStamp\n }\n\n /**\n * @deprecated Don't use this method. The constructor did initialization.\n */\n initEvent(type: string, bubbles = false, cancelable = false) {\n const data = $(this)\n if (data.dispatchFlag) {\n InitEventWasCalledWhileDispatching.warn()\n return\n }\n\n internalDataMap.set(this, {\n ...data,\n type: String(type),\n bubbles: Boolean(bubbles),\n cancelable: Boolean(cancelable),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n })\n }\n}\n\n/*eslint-enable class-methods-use-this */\n\nexport namespace Event {\n /**\n * The options of the `Event` constructor.\n * @see https://dom.spec.whatwg.org/#dictdef-eventinit\n */\n export interface EventInit {\n bubbles?: boolean\n cancelable?: boolean\n composed?: boolean\n }\n}\n\nexport { $ as getEventInternalData }\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nconst NONE = 0\nconst CAPTURING_PHASE = 1\nconst AT_TARGET = 2\nconst BUBBLING_PHASE = 3\n\n/**\n * Private data.\n */\ninterface EventInternalData {\n /**\n * The value of `type` attribute.\n */\n readonly type: string\n /**\n * The value of `bubbles` attribute.\n */\n readonly bubbles: boolean\n /**\n * The value of `cancelable` attribute.\n */\n readonly cancelable: boolean\n /**\n * The value of `composed` attribute.\n */\n readonly composed: boolean\n /**\n * The value of `timeStamp` attribute.\n */\n readonly timeStamp: number\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n target: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n currentTarget: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#stop-propagation-flag\n */\n stopPropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#stop-immediate-propagation-flag\n */\n stopImmediatePropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#canceled-flag\n */\n canceledFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#in-passive-listener-flag\n */\n inPassiveListenerFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#dispatch-flag\n */\n dispatchFlag: boolean\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap<any, EventInternalData>()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @param name The variable name to report.\n * @returns The private data of the event.\n */\nfunction $(event: unknown, name = \"this\"): EventInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'%s' must be an object that Event constructor created, but got another one: %o\",\n name,\n event,\n )\n return retv\n}\n\n/**\n * https://dom.spec.whatwg.org/#set-the-canceled-flag\n * @param data private data.\n */\nfunction setCancelFlag(data: EventInternalData) {\n if (data.inPassiveListenerFlag) {\n CanceledInPassiveListener.warn()\n return\n }\n if (!data.cancelable) {\n NonCancelableEventWasCanceled.warn()\n return\n }\n\n data.canceledFlag = true\n}\n\n// Set enumerable\nObject.defineProperty(Event, \"NONE\", { enumerable: true })\nObject.defineProperty(Event, \"CAPTURING_PHASE\", { enumerable: true })\nObject.defineProperty(Event, \"AT_TARGET\", { enumerable: true })\nObject.defineProperty(Event, \"BUBBLING_PHASE\", { enumerable: true })\nconst keys = Object.getOwnPropertyNames(Event.prototype)\nfor (let i = 0; i < keys.length; ++i) {\n if (keys[i] === \"constructor\") {\n continue\n }\n Object.defineProperty(Event.prototype, keys[i], { enumerable: true })\n}\n\n// Ensure `event instanceof window.Event` is `true`.\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n Object.setPrototypeOf(Event.prototype, Global.Event.prototype)\n}\n", "import { Global } from \"./global\"\n\n/**\n * Create a new InvalidStateError instance.\n * @param message The error message.\n */\nexport function createInvalidStateError(message: string): Error {\n if (Global.DOMException) {\n return new Global.DOMException(message, \"InvalidStateError\")\n }\n\n if (DOMException == null) {\n DOMException = class DOMException extends Error {\n constructor(msg: string) {\n super(msg)\n if ((Error as any).captureStackTrace) {\n ;(Error as any).captureStackTrace(this, DOMException)\n }\n }\n // eslint-disable-next-line class-methods-use-this\n get code() {\n return 11\n }\n // eslint-disable-next-line class-methods-use-this\n get name() {\n return \"InvalidStateError\"\n }\n }\n Object.defineProperties(DOMException.prototype, {\n code: { enumerable: true },\n name: { enumerable: true },\n })\n defineErrorCodeProperties(DOMException)\n defineErrorCodeProperties(DOMException.prototype)\n }\n return new DOMException(message)\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nlet DOMException: { new (message: string): Error } | undefined\n\nconst ErrorCodeMap = {\n INDEX_SIZE_ERR: 1,\n DOMSTRING_SIZE_ERR: 2,\n HIERARCHY_REQUEST_ERR: 3,\n WRONG_DOCUMENT_ERR: 4,\n INVALID_CHARACTER_ERR: 5,\n NO_DATA_ALLOWED_ERR: 6,\n NO_MODIFICATION_ALLOWED_ERR: 7,\n NOT_FOUND_ERR: 8,\n NOT_SUPPORTED_ERR: 9,\n INUSE_ATTRIBUTE_ERR: 10,\n INVALID_STATE_ERR: 11,\n SYNTAX_ERR: 12,\n INVALID_MODIFICATION_ERR: 13,\n NAMESPACE_ERR: 14,\n INVALID_ACCESS_ERR: 15,\n VALIDATION_ERR: 16,\n TYPE_MISMATCH_ERR: 17,\n SECURITY_ERR: 18,\n NETWORK_ERR: 19,\n ABORT_ERR: 20,\n URL_MISMATCH_ERR: 21,\n QUOTA_EXCEEDED_ERR: 22,\n TIMEOUT_ERR: 23,\n INVALID_NODE_TYPE_ERR: 24,\n DATA_CLONE_ERR: 25,\n}\ntype ErrorCodeMap = typeof ErrorCodeMap\n\nfunction defineErrorCodeProperties(obj: any): void {\n const keys = Object.keys(ErrorCodeMap) as (keyof ErrorCodeMap)[]\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n const value = ErrorCodeMap[key]\n Object.defineProperty(obj, key, {\n get() {\n return value\n },\n configurable: true,\n enumerable: true,\n })\n }\n}\n", "import { Event } from \"./event\"\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * This class controls the internal state of `Event`.\n * @see https://dom.spec.whatwg.org/#interface-event\n */\nexport class EventWrapper<TEventType extends string> extends Event<TEventType> {\n /**\n * Wrap a given event object to control states.\n * @param event The event-like object to wrap.\n */\n static wrap<T extends EventLike>(event: T): EventWrapperOf<T> {\n return new (getWrapperClassOf(event))(event)\n }\n\n protected constructor(event: Event<TEventType>) {\n super(event.type, {\n bubbles: event.bubbles,\n cancelable: event.cancelable,\n composed: event.composed,\n })\n\n if (event.cancelBubble) {\n super.stopPropagation()\n }\n if (event.defaultPrevented) {\n super.preventDefault()\n }\n\n internalDataMap.set(this, { original: event })\n\n // Define accessors\n const keys = Object.keys(event)\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n if (!(key in this)) {\n Object.defineProperty(\n this,\n key,\n defineRedirectDescriptor(event, key),\n )\n }\n }\n }\n\n stopPropagation(): void {\n super.stopPropagation()\n\n const { original } = $(this)\n if (\"stopPropagation\" in original) {\n original.stopPropagation!()\n }\n }\n\n get cancelBubble(): boolean {\n return super.cancelBubble\n }\n set cancelBubble(value: boolean) {\n super.cancelBubble = value\n\n const { original } = $(this)\n if (\"cancelBubble\" in original) {\n original.cancelBubble = value\n }\n }\n\n stopImmediatePropagation(): void {\n super.stopImmediatePropagation()\n\n const { original } = $(this)\n if (\"stopImmediatePropagation\" in original) {\n original.stopImmediatePropagation!()\n }\n }\n\n get returnValue(): boolean {\n return super.returnValue\n }\n set returnValue(value: boolean) {\n super.returnValue = value\n\n const { original } = $(this)\n if (\"returnValue\" in original) {\n original.returnValue = value\n }\n }\n\n preventDefault(): void {\n super.preventDefault()\n\n const { original } = $(this)\n if (\"preventDefault\" in original) {\n original.preventDefault!()\n }\n }\n\n get timeStamp(): number {\n const { original } = $(this)\n if (\"timeStamp\" in original) {\n return original.timeStamp!\n }\n return super.timeStamp\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\ntype EventLike = { readonly type: string } & Partial<Event>\ntype EventWrapperOf<T extends EventLike> = Event<T[\"type\"]> &\n Omit<T, keyof Event>\n\ninterface EventWrapperInternalData {\n readonly original: EventLike\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap<any, EventWrapperInternalData>()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @returns The private data of the event.\n */\nfunction $(event: unknown): EventWrapperInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'this' is expected an Event object, but got\",\n event,\n )\n return retv\n}\n\n/**\n * Cache for wrapper classes.\n * @type {WeakMap<Object, Function>}\n * @private\n */\nconst wrapperClassCache = new WeakMap()\n\n// Make association for wrappers.\nwrapperClassCache.set(Object.prototype, EventWrapper)\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n wrapperClassCache.set(Global.Event.prototype, EventWrapper)\n}\n\n/**\n * Get the wrapper class of a given prototype.\n * @param originalEvent The event object to wrap.\n */\nfunction getWrapperClassOf<T extends EventLike>(\n originalEvent: T,\n): { new (e: T): EventWrapperOf<T> } {\n const prototype = Object.getPrototypeOf(originalEvent)\n if (prototype == null) {\n return EventWrapper as any\n }\n\n let wrapper: any = wrapperClassCache.get(prototype)\n if (wrapper == null) {\n wrapper = defineWrapper(getWrapperClassOf(prototype), prototype)\n wrapperClassCache.set(prototype, wrapper)\n }\n\n return wrapper\n}\n\n/**\n * Define new wrapper class.\n * @param BaseEventWrapper The base wrapper class.\n * @param originalPrototype The prototype of the original event.\n */\nfunction defineWrapper(BaseEventWrapper: any, originalPrototype: any): any {\n class CustomEventWrapper extends BaseEventWrapper {}\n\n const keys = Object.keys(originalPrototype)\n for (let i = 0; i < keys.length; ++i) {\n Object.defineProperty(\n CustomEventWrapper.prototype,\n keys[i],\n defineRedirectDescriptor(originalPrototype, keys[i]),\n )\n }\n\n return CustomEventWrapper\n}\n\n/**\n * Get the property descriptor to redirect a given property.\n */\nfunction defineRedirectDescriptor(obj: any, key: string): PropertyDescriptor {\n const d = Object.getOwnPropertyDescriptor(obj, key)!\n return {\n get() {\n const original: any = $(this).original\n const value = original[key]\n if (typeof value === \"function\") {\n return value.bind(original)\n }\n return value\n },\n set(value: any) {\n const original: any = $(this).original\n original[key] = value\n },\n configurable: d.configurable,\n enumerable: d.enumerable,\n }\n}\n", "import { reportError } from \"./error-handler\"\nimport { Event } from \"./event\" // Used as only type, so no circular.\nimport { EventTarget } from \"./event-target\" // Used as only type, so no circular.\n\n/**\n * The event listener concept.\n * @see https://dom.spec.whatwg.org/#concept-event-listener\n */\nexport interface Listener {\n /**\n * The callback function.\n */\n readonly callback: Listener.Callback<any, any>\n /**\n * The flags of this listener.\n * This is writable to add the removed flag.\n */\n flags: ListenerFlags\n /**\n * The `AbortSignal` to remove this listener.\n */\n readonly signal: Listener.AbortSignal | undefined\n /**\n * The `abort` event listener for the `signal`.\n * To remove it from the `signal`.\n */\n readonly signalListener: (() => void) | undefined\n}\n\nexport namespace Listener {\n export type Callback<\n TEventTarget extends EventTarget<any, any>,\n TEvent extends Event\n > = CallbackFunction<TEventTarget, TEvent> | CallbackObject<TEvent>\n\n export interface CallbackFunction<\n TEventTarget extends EventTarget<any, any>,\n TEvent extends Event\n > {\n (this: TEventTarget, event: TEvent): void\n }\n\n export interface CallbackObject<TEvent extends Event> {\n handleEvent(event: TEvent): void\n }\n\n export interface AbortSignal {\n addEventListener(type: string, callback: Callback<any, Event>): void\n removeEventListener(type: string, callback: Callback<any, Event>): void\n }\n}\n\n/**\n * Create a new listener.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n * @param signalListener The abort event listener for the abort signal.\n */\nexport function createListener(\n callback: Listener.Callback<any, any>,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n signalListener: (() => void) | undefined,\n): Listener {\n return {\n callback,\n flags:\n (capture ? ListenerFlags.Capture : 0) |\n (passive ? ListenerFlags.Passive : 0) |\n (once ? ListenerFlags.Once : 0),\n signal,\n signalListener,\n }\n}\n\n/**\n * Set the `removed` flag to the given listener.\n * @param listener The listener to check.\n */\nexport function setRemoved(listener: Listener): void {\n listener.flags |= ListenerFlags.Removed\n}\n\n/**\n * Check if the given listener has the `capture` flag or not.\n * @param listener The listener to check.\n */\nexport function isCapture(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Capture) === ListenerFlags.Capture\n}\n\n/**\n * Check if the given listener has the `passive` flag or not.\n * @param listener The listener to check.\n */\nexport function isPassive(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Passive) === ListenerFlags.Passive\n}\n\n/**\n * Check if the given listener has the `once` flag or not.\n * @param listener The listener to check.\n */\nexport function isOnce(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Once) === ListenerFlags.Once\n}\n\n/**\n * Check if the given listener has the `removed` flag or not.\n * @param listener The listener to check.\n */\nexport function isRemoved(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Removed) === ListenerFlags.Removed\n}\n\n/**\n * Call an event listener.\n * @param listener The listener to call.\n * @param target The event target object for `thisArg`.\n * @param event The event object for the first argument.\n * @param attribute `true` if this callback is an event attribute handler.\n */\nexport function invokeCallback(\n { callback }: Listener,\n target: EventTarget<any, any>,\n event: Event<any>,\n): void {\n try {\n if (typeof callback === \"function\") {\n callback.call(target, event)\n } else if (typeof callback.handleEvent === \"function\") {\n callback.handleEvent(event)\n }\n } catch (thrownError) {\n reportError(thrownError)\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * The flags of listeners.\n */\nconst enum ListenerFlags {\n Capture = 0x01,\n Passive = 0x02,\n Once = 0x04,\n Removed = 0x08,\n}\n", "import { createListener, isCapture, Listener, setRemoved } from \"./listener\"\n\n/**\n * Information of an listener list.\n */\nexport interface ListenerList {\n /**\n * The callback function of the event attribute handler.\n */\n attrCallback: Listener.CallbackFunction<any, any> | undefined\n /**\n * The listener of the event attribute handler.\n */\n attrListener: Listener | undefined\n /**\n * `true` if the `dispatchEvent` method is traversing the current `listeners` array.\n */\n cow: boolean\n /**\n * The listeners.\n * This is writable for copy-on-write.\n */\n listeners: Listener[]\n}\n\n/**\n * Find the index of given listener.\n * This returns `-1` if not found.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n */\nexport function findIndexOfListener(\n { listeners }: ListenerList,\n callback: Listener.Callback<any, any>,\n capture: boolean,\n): number {\n for (let i = 0; i < listeners.length; ++i) {\n if (\n listeners[i].callback === callback &&\n isCapture(listeners[i]) === capture\n ) {\n return i\n }\n }\n return -1\n}\n\n/**\n * Add the given listener.\n * Does copy-on-write if needed.\n * @param list The listener list.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n */\nexport function addListener(\n list: ListenerList,\n callback: Listener.Callback<any, any>,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n): Listener {\n let signalListener: (() => void) | undefined\n if (signal) {\n signalListener = removeListener.bind(null, list, callback, capture)\n signal.addEventListener(\"abort\", signalListener)\n }\n\n const listener = createListener(\n callback,\n capture,\n passive,\n once,\n signal,\n signalListener,\n )\n\n if (list.cow) {\n list.cow = false\n list.listeners = [...list.listeners, listener]\n } else {\n list.listeners.push(listener)\n }\n\n return listener\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n * @returns `true` if it mutated the list directly.\n */\nexport function removeListener(\n list: ListenerList,\n callback: Listener.Callback<any, any>,\n capture: boolean,\n): boolean {\n const index = findIndexOfListener(list, callback, capture)\n if (index !== -1) {\n return removeListenerAt(list, index)\n }\n return false\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param index The index of the target listener.\n * @param disableCow Disable copy-on-write if true.\n * @returns `true` if it mutated