chore: vendor Mitt & update project structure (#6209)

* chore: vendor Mitt into src/common/third-party

As discussed in #6203 we need to vendor our common dependencies in so
that when we ship an ESM build all imports point to file paths and do
not rely on Node resolution (e.g. a browser does not understand `import
mitt from 'mitt'`).
This commit is contained in:
Jack Franklin 2020-07-14 16:57:29 +01:00 committed by GitHub
parent fb806109a0
commit f1a6b8d66d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 609 additions and 73 deletions

View File

@ -10,3 +10,4 @@ lib/
# We ignore this file because it uses ES imports which we don't yet use
# in the Puppeteer src, so it trips up the ESLint-TypeScript parser.
utils/doclint/generate_types/test/test.ts
vendor/

View File

@ -87,8 +87,14 @@ module.exports = {
// enforce the variable in a catch block is named error
"unicorn/catch-error-name": "error",
"no-restricted-imports": ["error", {
patterns: ["*Events"],
paths: [{
name: "mitt",
message:
"Import Mitt from the vendored location: vendor/mitt/src/index.js",
}],
}],
"import/extensions": ["error", "ignorePackages"]
},

View File

@ -5,6 +5,10 @@
* [Code reviews](#code-reviews)
* [Code Style](#code-style)
* [TypeScript guidelines](#typescript-guidelines)
* [Project structure and TypeScript compilation](#project-structure-and-typescript-compilation)
- [Shipping CJS and ESM bundles](#shipping-cjs-and-esm-bundles)
- [tsconfig for the tests](#tsconfig-for-the-tests)
- [Root `tsconfig.json`](#root-tsconfigjson)
* [API guidelines](#api-guidelines)
* [Commit Messages](#commit-messages)
* [Writing Documentation](#writing-documentation)
@ -85,6 +89,42 @@ npm run tsc
- Try to avoid the use of `any` when possible. Consider `unknown` as a better alternative. You are able to use `any` if needbe, but it will generate an ESLint warning.
## Project structure and TypeScript compilation
The code in Puppeteer is split primarily into two folders:
- `src` contains all source code
- `vendor` contains all dependencies that we've vendored into the codebase. See the [`vendor/README.md`](https://github.com/puppeteer/puppeteer/blob/main/vendor/README.md) for details.
We structure these using TypeScript's project references, which lets us treat each folder like a standalone TypeScript project.
### Shipping CJS and ESM bundles
Currently Puppeteer ships two bundles; a CommonJS version for Node and an ESM bundle for the browser. Therefore we maintain two `tsconfig` files for each project; `tsconfig.esm.json` and `tsconfig.cjs.json`. At build time we compile twice, once outputting to CJS and another time to output to ESM.
We compile into the `lib` directory which is what we publish on the npm repository and it's structured like so:
```
lib
- cjs
- puppeteer <== the output of compiling `src/tsconfig.cjs.json`
- vendor <== the output of compiling `vendor/tsconfig.cjs.json`
- esm
- puppeteer <== the output of compiling `src/tsconfig.esm.json`
- vendor <== the output of compiling `vendor/tsconfig.esm.json`
```
The main entry point for the Node module Puppeteer is `cjs-entry.js`. This imports `lib/cjs/puppeteer/index.js` and exposes it to Node users.
### tsconfig for the tests
We also maintain `test/tsconfig.test.json`. This is **only used to compile the unit test `*.spec.ts` files**. When the tests are run, we first compile Puppeteer as normal before running the unit tests **against the compiled output**. Doing this lets the test run against the compiled code we ship to users so it gives us more confidence in our compiled output being correct.
### Root `tsconfig.json`
The root `tsconfig.json` exists for the API Extractor; it has to find a `tsconfig.json` in the project's root directory. It is _not_ used for anything else.
## API guidelines
When authoring new API methods, consider the following:
@ -153,6 +193,9 @@ For all dependencies (both installation and development):
A barrier for introducing new installation dependencies is especially high:
- **Do not add** installation dependency unless it's critical to project success.
There are additional considerations for dependencies that are environment agonistic. See the [`vendor/README.md`](https://github.com/puppeteer/puppeteer/blob/main/vendor/README.md) for details.
## Running & Writing Tests
- Every feature should be accompanied by a test.

View File

@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/cjs/api-docs-entry.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/cjs/puppeteer/api-docs-entry.d.ts",
"bundledPackages": [ "devtools-protocol" ],
"apiReport": {

View File

@ -25,5 +25,5 @@
* This means that we can publish to CJS and ESM whilst maintaining the expected
* import behaviour for CJS and ESM users.
*/
const puppeteerExport = require('./lib/cjs/index-core');
const puppeteerExport = require('./lib/cjs/puppeteer/index-core');
module.exports = puppeteerExport.default;

View File

@ -25,5 +25,5 @@
* This means that we can publish to CJS and ESM whilst maintaining the expected
* import behaviour for CJS and ESM users.
*/
const puppeteerExport = require('./lib/cjs/index');
const puppeteerExport = require('./lib/cjs/puppeteer/index');
module.exports = puppeteerExport.default;

View File

@ -29,7 +29,10 @@ const compileTypeScriptIfRequired = require('./typescript-if-required');
async function download() {
await compileTypeScriptIfRequired();
// need to ensure TS is compiled before loading the installer
const { downloadBrowser, logPolitely } = require('./lib/cjs/install');
const {
downloadBrowser,
logPolitely,
} = require('./lib/cjs/puppeteer/install');
if (process.env.PUPPETEER_SKIP_DOWNLOAD) {
logPolitely(

View File

@ -24,13 +24,12 @@
"doc": "node utils/doclint/cli.js",
"clean-lib": "rm -rf lib",
"tsc": "npm run clean-lib && tsc --version && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc -p .",
"tsc-esm": "tsc --build tsconfig-esm.json",
"typecheck": "tsc -p . --noEmit",
"tsc-cjs": "tsc -b src/tsconfig.cjs.json",
"tsc-esm": "tsc -b src/tsconfig.esm.json",
"apply-next-version": "node utils/apply_next_version.js",
"test-install": "scripts/test-install.sh",
"generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs",
"ensure-new-docs-up-to-date": "npm run generate-docs && exit `git status --porcelain | head -255 | wc -l`",
"ensure-new-docs-up-to-date": "npm run generate-docs && git status && exit `git status --porcelain | head -255 | wc -l`",
"generate-dependency-graph": "echo 'Requires graphviz installed locally!' && depcruise --exclude 'api.ts' --do-not-follow '^node_modules' --output-type dot src/index.ts | dot -T png > dependency-chart.png",
"ensure-correct-devtools-protocol-revision": "ts-node scripts/ensure-correct-devtools-protocol-package"
},
@ -49,7 +48,6 @@
"extract-zip": "^2.0.0",
"https-proxy-agent": "^4.0.0",
"mime": "^2.0.3",
"mitt": "^2.0.1",
"pkg-dir": "^4.2.0",
"progress": "^2.0.1",
"proxy-from-env": "^1.0.0",

View File

@ -1,4 +1,8 @@
import mitt, { Emitter, EventType, Handler } from 'mitt';
import mitt, {
Emitter,
EventType,
Handler,
} from '../../vendor/mitt/src/index.js';
/**
* @internal

11
src/tsconfig.cjs.json Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "../lib/cjs/puppeteer",
"module": "CommonJS"
},
"references": [
{ "path": "../vendor/tsconfig.cjs.json"}
]
}

11
src/tsconfig.esm.json Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "../lib/esm/puppeteer",
"module": "esnext"
},
"references": [
{ "path": "../vendor/tsconfig.esm.json"}
]
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EventEmitter } from '../lib/cjs/common/EventEmitter.js';
import { EventEmitter } from '../lib/cjs/puppeteer/common/EventEmitter.js';
import sinon from 'sinon';
import expect from 'expect';

View File

@ -39,32 +39,32 @@ const fs = require('fs');
* part of the TSDoc migration.
*/
const MODULES_TO_CHECK_FOR_COVERAGE = {
Accessibility: '../lib/cjs/common/Accessibility',
Browser: '../lib/cjs/common/Browser',
BrowserContext: '../lib/cjs/common/Browser',
BrowserFetcher: '../lib/cjs/node/BrowserFetcher',
CDPSession: '../lib/cjs/common/Connection',
ConsoleMessage: '../lib/cjs/common/ConsoleMessage',
Coverage: '../lib/cjs/common/Coverage',
Dialog: '../lib/cjs/common/Dialog',
ElementHandle: '../lib/cjs/common/JSHandle',
ExecutionContext: '../lib/cjs/common/ExecutionContext',
EventEmitter: '../lib/cjs/common/EventEmitter',
FileChooser: '../lib/cjs/common/FileChooser',
Frame: '../lib/cjs/common/FrameManager',
JSHandle: '../lib/cjs/common/JSHandle',
Keyboard: '../lib/cjs/common/Input',
Mouse: '../lib/cjs/common/Input',
Page: '../lib/cjs/common/Page',
Puppeteer: '../lib/cjs/common/Puppeteer',
HTTPRequest: '../lib/cjs/common/HTTPRequest',
HTTPResponse: '../lib/cjs/common/HTTPResponse',
SecurityDetails: '../lib/cjs/common/SecurityDetails',
Target: '../lib/cjs/common/Target',
TimeoutError: '../lib/cjs/common/Errors',
Touchscreen: '../lib/cjs/common/Input',
Tracing: '../lib/cjs/common/Tracing',
WebWorker: '../lib/cjs/common/WebWorker',
Accessibility: '../lib/cjs/puppeteer/common/Accessibility',
Browser: '../lib/cjs/puppeteer/common/Browser',
BrowserContext: '../lib/cjs/puppeteer/common/Browser',
BrowserFetcher: '../lib/cjs/puppeteer/node/BrowserFetcher',
CDPSession: '../lib/cjs/puppeteer/common/Connection',
ConsoleMessage: '../lib/cjs/puppeteer/common/ConsoleMessage',
Coverage: '../lib/cjs/puppeteer/common/Coverage',
Dialog: '../lib/cjs/puppeteer/common/Dialog',
ElementHandle: '../lib/cjs/puppeteer/common/JSHandle',
ExecutionContext: '../lib/cjs/puppeteer/common/ExecutionContext',
EventEmitter: '../lib/cjs/puppeteer/common/EventEmitter',
FileChooser: '../lib/cjs/puppeteer/common/FileChooser',
Frame: '../lib/cjs/puppeteer/common/FrameManager',
JSHandle: '../lib/cjs/puppeteer/common/JSHandle',
Keyboard: '../lib/cjs/puppeteer/common/Input',
Mouse: '../lib/cjs/puppeteer/common/Input',
Page: '../lib/cjs/puppeteer/common/Page',
Puppeteer: '../lib/cjs/puppeteer/common/Puppeteer',
HTTPRequest: '../lib/cjs/puppeteer/common/HTTPRequest',
HTTPResponse: '../lib/cjs/puppeteer/common/HTTPResponse',
SecurityDetails: '../lib/cjs/puppeteer/common/SecurityDetails',
Target: '../lib/cjs/puppeteer/common/Target',
TimeoutError: '../lib/cjs/puppeteer/common/Errors',
Touchscreen: '../lib/cjs/puppeteer/common/Input',
Tracing: '../lib/cjs/puppeteer/common/Tracing',
WebWorker: '../lib/cjs/puppeteer/common/WebWorker',
};
function traceAPICoverage(apiCoverage, className, modulePath) {

View File

@ -24,7 +24,7 @@ import {
} from './mocha-utils'; // eslint-disable-line import/extensions
import utils from './utils.js';
import { ElementHandle } from '../lib/cjs/common/JSHandle.js';
import { ElementHandle } from '../lib/cjs/puppeteer/common/JSHandle.js';
describe('ElementHandle specs', function () {
setupTestBrowserHooks();

View File

@ -23,7 +23,7 @@ import {
setupTestPageAndContextHooks,
itFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
import { KeyInput } from '../lib/cjs/common/USKeyboardLayout.js';
import { KeyInput } from '../lib/cjs/puppeteer/common/USKeyboardLayout.js';
describe('Keyboard', function () {
setupTestBrowserHooks();

View File

@ -27,7 +27,7 @@ import {
import utils from './utils.js';
import expect from 'expect';
import rimraf from 'rimraf';
import { Page } from '../lib/cjs/common/Page.js';
import { Page } from '../lib/cjs/puppeteer/common/Page.js';
const rmAsync = promisify(rimraf);
const mkdtempAsync = promisify(fs.mkdtemp);

View File

@ -1,3 +1,5 @@
const path = require('path');
require('ts-node').register({
/**
* We ignore the lib/ directory because that's already been TypeScript
@ -5,4 +7,5 @@ require('ts-node').register({
* the unit tests.
*/
ignore: ['lib/*', 'node_modules'],
project: path.join(__dirname, 'tsconfig.test.json'),
});

View File

@ -19,10 +19,13 @@ import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import sinon from 'sinon';
import puppeteer from '../lib/cjs/index.js';
import { Browser, BrowserContext } from '../lib/cjs/common/Browser.js';
import { Page } from '../lib/cjs/common/Page.js';
import { Puppeteer } from '../lib/cjs/common/Puppeteer.js';
import puppeteer from '../lib/cjs/puppeteer/index.js';
import {
Browser,
BrowserContext,
} from '../lib/cjs/puppeteer/common/Browser.js';
import { Page } from '../lib/cjs/puppeteer/common/Page.js';
import { Puppeteer } from '../lib/cjs/puppeteer/common/Puppeteer.js';
import utils from './utils.js';
import rimraf from 'rimraf';

View File

@ -21,7 +21,7 @@ import {
setupTestPageAndContextHooks,
itFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
import { KeyInput } from '../lib/cjs/common/USKeyboardLayout.js';
import { KeyInput } from '../lib/cjs/puppeteer/common/USKeyboardLayout.js';
interface Dimensions {
x: number;

View File

@ -26,8 +26,8 @@ import {
itFailsFirefox,
describeFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
import { Page, Metrics } from '../lib/cjs/common/Page.js';
import { JSHandle } from '../lib/cjs/common/JSHandle.js';
import { Page, Metrics } from '../lib/cjs/puppeteer/common/Page.js';
import { JSHandle } from '../lib/cjs/puppeteer/common/JSHandle.js';
describe('Page', function () {
setupTestBrowserHooks();

View File

@ -23,7 +23,7 @@ import {
setupTestPageAndContextHooks,
itFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
import { Target } from '../lib/cjs/common/Target.js';
import { Target } from '../lib/cjs/puppeteer/common/Target.js';
describe('Target', function () {
setupTestBrowserHooks();

3
test/tsconfig.test.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "../tsconfig.base.json",
}

View File

@ -22,8 +22,8 @@ import {
describeFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
import utils from './utils.js';
import { WebWorker } from '../lib/cjs/common/WebWorker.js';
import { ConsoleMessage } from '../lib/cjs/common/ConsoleMessage.js';
import { WebWorker } from '../lib/cjs/puppeteer/common/WebWorker.js';
import { ConsoleMessage } from '../lib/cjs/puppeteer/common/ConsoleMessage.js';
const { waitEvent } = utils;
describeFailsFirefox('Workers', function () {

12
tsconfig.base.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"esModuleInterop": true,
"allowJs": true,
"checkJs": true,
"target": "ESNext",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"resolveJsonModule": true
}
}

View File

@ -1,17 +1,11 @@
/**
* This configuration only exists for the API Extractor tool. See the details in
* CONTRIBUTING.md that describes our TypeScript setup.
*/
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"outDir": "./lib/cjs",
"target": "ESNext",
"moduleResolution": "node",
"module": "CommonJS",
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"resolveJsonModule": true
"noEmit": true
},
"include": [
"src"
]
"include": ["src"]
}

View File

@ -674,56 +674,56 @@ function compareDocumentations(actual, expected) {
'Method EventEmitter.emit() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.listenerCount() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.off() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.on() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.once() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.removeListener() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.addListener() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[
'Method EventEmitter.removeAllListeners() event',
{
actualName: 'string|symbol',
expectedName: 'Object',
expectedName: 'EventType',
},
],
[

View File

@ -72,8 +72,12 @@ async function run() {
const jsSources = [
...(await Source.readdir(path.join(PROJECT_DIR, 'lib'))),
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'cjs'))),
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'cjs', 'common'))),
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'cjs', 'node'))),
...(await Source.readdir(
path.join(PROJECT_DIR, 'lib', 'cjs', 'puppeteer', 'common')
)),
...(await Source.readdir(
path.join(PROJECT_DIR, 'lib', 'cjs', 'puppeteer', 'node')
)),
];
const allSrcCode = [...jsSources, ...tsSourcesNoDefinitions];
messages.push(...(await checkPublicAPI(page, mdSources, allSrcCode)));

13
vendor/README.md vendored Normal file
View File

@ -0,0 +1,13 @@
# Vendoring third party dependencies
Because we are working towards an agnostic Puppeteer that can run in any environment (see [#6125](https://github.com/puppeteer/puppeteer/issues/6125)) we cannot import common dependencies in a way that relies on Node's resolution to find them. For example, `import mitt from 'mitt'` works fine in Node, but in an ESM build running in the browser, the browser has no idea where to find `'mitt'`.
Therefore we put all common dependencies into this directory, `vendor`. This means there are extra criteria for these dependencies; ideally they will not depend on any other modules. If they do, we should consider an alternative way of managing our dependencies.
The process for updating a vendored dependency is:
1. `npm install {DEP NAME HERE}`
2. `cp -r node_modules/DEP vendor/DEP`
3. Update `eslintrc.js` to forbid importing DEP directly (see the `Mitt` rule already defined in there).
4. Use the new DEP, and run `npm run tsc` to check everything compiles successfully.
5. If the dep ships as compiled JS, you may need to disable TypeScript checking the file. Add an entry to the `excludes` property of the TSConfig files in `vendor`. (again, see the entry that's already there for Mitt as an example). Don't forget to update both the ESM and CJS config files.

171
vendor/mitt/README.md vendored Normal file
View File

@ -0,0 +1,171 @@
<p align="center">
<img src="https://i.imgur.com/BqsX9NT.png" width="300" height="300" alt="mitt">
<br>
<a href="https://www.npmjs.org/package/mitt"><img src="https://img.shields.io/npm/v/mitt.svg" alt="npm"></a>
<img src="https://github.com/developit/mitt/workflows/CI/badge.svg" alt="build status">
<a href="https://unpkg.com/mitt/dist/mitt.js"><img src="https://img.badgesize.io/https://unpkg.com/mitt/dist/mitt.js?compression=gzip" alt="gzip size"></a>
</p>
# Mitt
> Tiny 200b functional event emitter / pubsub.
- **Microscopic:** weighs less than 200 bytes gzipped
- **Useful:** a wildcard `"*"` event type listens to all events
- **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
- **Functional:** methods don't rely on `this`
- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken
Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and supports IE9+.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Examples & Demos](#examples--demos)
- [API](#api)
- [Contribute](#contribute)
- [License](#license)
## Install
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.
```sh
$ npm install --save mitt
```
Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:
```javascript
// using ES6 modules
import mitt from 'mitt'
// using CommonJS modules
var mitt = require('mitt')
```
The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):
```html
<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>
```
You can find the library on `window.mitt`.
## Usage
```js
import mitt from 'mitt'
const emitter = mitt()
// listen to an event
emitter.on('foo', e => console.log('foo', e) )
// listen to all events
emitter.on('*', (type, e) => console.log(type, e) )
// fire an event
emitter.emit('foo', { a: 'b' })
// working with handler references:
function onFoo() {}
emitter.on('foo', onFoo) // listen
emitter.off('foo', onFoo) // unlisten
```
### Typescript
```ts
import mitt from 'mitt';
const emitter: mitt.Emitter = mitt();
```
## Examples & Demos
<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">
<b>Preact + Mitt Codepen Demo</b>
<br>
<img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">
</a>
* * *
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### Table of Contents
- [mitt](#mitt)
- [on](#on)
- [Parameters](#parameters)
- [off](#off)
- [Parameters](#parameters-1)
- [emit](#emit)
- [Parameters](#parameters-2)
### mitt
Mitt: Tiny (~200b) functional event emitter / pubsub.
Returns **Mitt**
### on
Register an event handler for the given type.
#### Parameters
- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to listen for, or `"*"` for all events
- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event
### off
Remove an event handler for the given type.
#### Parameters
- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to unregister `handler` from, or `"*"`
- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove
### emit
Invoke all handlers for the given type.
If present, `"*"` handlers are invoked after type-matched handlers.
Note: Manually firing "\*" handlers is not supported.
#### Parameters
- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** The event type to invoke
- `evt` **Any?** Any value (object is recommended and powerful), passed to each handler
## Contribute
First off, thanks for taking the time to contribute!
Now, take a moment to be sure your contributions make sense to everyone else.
### Reporting Issues
Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).
If don't, just open a [new clear and descriptive issue](../../issues/new).
### Submitting pull requests
Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
- Fork it!
- Clone your fork: `git clone https://github.com/<your-username>/mitt`
- Navigate to the newly cloned directory: `cd mitt`
- Create a new branch for the new feature: `git checkout -b my-new-feature`
- Install the tools necessary for development: `npm install`
- Make your changes.
- Commit your changes: `git commit -am 'Add some feature'`
- Push to the branch: `git push origin my-new-feature`
- Submit a pull request with full remarks documenting your changes.
## License
[MIT License](https://opensource.org/licenses/MIT) © [Jason Miller](https://jasonformat.com/)

19
vendor/mitt/dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
export declare type EventType = string | symbol;
export declare type Handler = (event?: any) => void;
export declare type WildcardHandler = (type: EventType, event?: any) => void;
export declare type EventHandlerList = Array<Handler>;
export declare type WildCardEventHandlerList = Array<WildcardHandler>;
export declare type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;
export interface Emitter {
on(type: EventType, handler: Handler): void;
on(type: '*', handler: WildcardHandler): void;
off(type: EventType, handler: Handler): void;
off(type: '*', handler: WildcardHandler): void;
emit<T = any>(type: EventType, event?: T): void;
emit(type: '*', event?: any): void;
}
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
* @name mitt
* @returns {Mitt}
*/
export default function mitt(all?: EventHandlerMap): Emitter;

2
vendor/mitt/dist/mitt.es.js vendored Normal file
View File

@ -0,0 +1,2 @@
export default function(n){return n=n||new Map,{on:function(t,e){var i=n.get(t);i&&i.push(e)||n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&i.splice(i.indexOf(e)>>>0,1)},emit:function(t,e){(n.get(t)||[]).slice().map(function(n){n(e)}),(n.get("*")||[]).slice().map(function(n){n(t,e)})}}}
//# sourceMappingURL=mitt.es.js.map

1
vendor/mitt/dist/mitt.es.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"mitt.es.js","sources":["../src/index.ts"],"sourcesContent":["export type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler = (event?: any) => void;\nexport type WildcardHandler= (type: EventType, event?: any) => void\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList = Array<Handler>;\nexport type WildCardEventHandlerList = Array<WildcardHandler>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;\n\nexport interface Emitter {\n\ton(type: EventType, handler: Handler): void;\n\ton(type: '*', handler: WildcardHandler): void;\n\n\toff(type: EventType, handler: Handler): void;\n\toff(type: '*', handler: WildcardHandler): void;\n\n\temit<T = any>(type: EventType, event?: T): void;\n\temit(type: '*', event?: any): void;\n}\n\n/** Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt(all?: EventHandlerMap): Emitter {\n\tall = all || new Map();\n\n\treturn {\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param {string|symbol} type Type of event to listen for, or `\"*\"` for all events\n\t\t * @param {Function} handler Function to call in response to given event\n\t\t * @memberOf mitt\n\t\t */\n\t\ton(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tconst added = handlers && handlers.push(handler);\n\t\t\tif (!added) {\n\t\t\t\tall.set(type, [handler]);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t *\n\t\t * @param {string|symbol} type Type of event to unregister `handler` from, or `\"*\"`\n\t\t * @param {Function} handler Handler function to remove\n\t\t * @memberOf mitt\n\t\t */\n\t\toff(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `\"*\"` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing \"*\" handlers is not supported.\n\t\t *\n\t\t * @param {string|symbol} type The event type to invoke\n\t\t * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler\n\t\t * @memberOf mitt\n\t\t */\n\t\temit(type: EventType, evt: any) {\n\t\t\t((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });\n\t\t\t((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });\n\t\t}\n\t};\n}\n"],"names":["all","Map","on","type","handler","handlers","get","push","set","off","splice","indexOf","emit","evt","slice","map"],"mappings":"wBA6B6BA,GAG5B,OAFAA,EAAMA,GAAO,IAAIC,IAEV,CAQNC,YAAGC,EAAiBC,GACnB,IAAMC,EAAWL,EAAIM,IAAIH,GACXE,GAAYA,EAASE,KAAKH,IAEvCJ,EAAIQ,IAAIL,EAAM,CAACC,KAWjBK,aAAIN,EAAiBC,GACpB,IAAMC,EAAWL,EAAIM,IAAIH,GACrBE,GACHA,EAASK,OAAOL,EAASM,QAAQP,KAAa,EAAG,IAcnDQ,cAAKT,EAAiBU,IACnBb,EAAIM,IAAIH,IAAS,IAAyBW,QAAQC,IAAI,SAACX,GAAcA,EAAQS,MAC7Eb,EAAIM,IAAI,MAAQ,IAAiCQ,QAAQC,IAAI,SAACX,GAAcA,EAAQD,EAAMU"}

2
vendor/mitt/dist/mitt.js vendored Normal file
View File

@ -0,0 +1,2 @@
module.exports=function(n){return n=n||new Map,{on:function(e,t){var i=n.get(e);i&&i.push(t)||n.set(e,[t])},off:function(e,t){var i=n.get(e);i&&i.splice(i.indexOf(t)>>>0,1)},emit:function(e,t){(n.get(e)||[]).slice().map(function(n){n(t)}),(n.get("*")||[]).slice().map(function(n){n(e,t)})}}};
//# sourceMappingURL=mitt.js.map

1
vendor/mitt/dist/mitt.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"mitt.js","sources":["../src/index.ts"],"sourcesContent":["export type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler = (event?: any) => void;\nexport type WildcardHandler= (type: EventType, event?: any) => void\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList = Array<Handler>;\nexport type WildCardEventHandlerList = Array<WildcardHandler>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;\n\nexport interface Emitter {\n\ton(type: EventType, handler: Handler): void;\n\ton(type: '*', handler: WildcardHandler): void;\n\n\toff(type: EventType, handler: Handler): void;\n\toff(type: '*', handler: WildcardHandler): void;\n\n\temit<T = any>(type: EventType, event?: T): void;\n\temit(type: '*', event?: any): void;\n}\n\n/** Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt(all?: EventHandlerMap): Emitter {\n\tall = all || new Map();\n\n\treturn {\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param {string|symbol} type Type of event to listen for, or `\"*\"` for all events\n\t\t * @param {Function} handler Function to call in response to given event\n\t\t * @memberOf mitt\n\t\t */\n\t\ton(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tconst added = handlers && handlers.push(handler);\n\t\t\tif (!added) {\n\t\t\t\tall.set(type, [handler]);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t *\n\t\t * @param {string|symbol} type Type of event to unregister `handler` from, or `\"*\"`\n\t\t * @param {Function} handler Handler function to remove\n\t\t * @memberOf mitt\n\t\t */\n\t\toff(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `\"*\"` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing \"*\" handlers is not supported.\n\t\t *\n\t\t * @param {string|symbol} type The event type to invoke\n\t\t * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler\n\t\t * @memberOf mitt\n\t\t */\n\t\temit(type: EventType, evt: any) {\n\t\t\t((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });\n\t\t\t((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });\n\t\t}\n\t};\n}\n"],"names":["all","Map","on","type","handler","handlers","get","push","set","off","splice","indexOf","emit","evt","slice","map"],"mappings":"wBA6B6BA,GAG5B,OAFAA,EAAMA,GAAO,IAAIC,IAEV,CAQNC,YAAGC,EAAiBC,GACnB,IAAMC,EAAWL,EAAIM,IAAIH,GACXE,GAAYA,EAASE,KAAKH,IAEvCJ,EAAIQ,IAAIL,EAAM,CAACC,KAWjBK,aAAIN,EAAiBC,GACpB,IAAMC,EAAWL,EAAIM,IAAIH,GACrBE,GACHA,EAASK,OAAOL,EAASM,QAAQP,KAAa,EAAG,IAcnDQ,cAAKT,EAAiBU,IACnBb,EAAIM,IAAIH,IAAS,IAAyBW,QAAQC,IAAI,SAACX,GAAcA,EAAQS,MAC7Eb,EAAIM,IAAI,MAAQ,IAAiCQ,QAAQC,IAAI,SAACX,GAAcA,EAAQD,EAAMU"}

2
vendor/mitt/dist/mitt.modern.js vendored Normal file
View File

@ -0,0 +1,2 @@
export default function(e){return e=e||new Map,{on(t,n){const s=e.get(t);s&&s.push(n)||e.set(t,[n])},off(t,n){const s=e.get(t);s&&s.splice(s.indexOf(n)>>>0,1)},emit(t,n){(e.get(t)||[]).slice().map(e=>{e(n)}),(e.get("*")||[]).slice().map(e=>{e(t,n)})}}}
//# sourceMappingURL=mitt.modern.js.map

1
vendor/mitt/dist/mitt.modern.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"mitt.modern.js","sources":["../src/index.ts"],"sourcesContent":["export type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler = (event?: any) => void;\nexport type WildcardHandler= (type: EventType, event?: any) => void\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList = Array<Handler>;\nexport type WildCardEventHandlerList = Array<WildcardHandler>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;\n\nexport interface Emitter {\n\ton(type: EventType, handler: Handler): void;\n\ton(type: '*', handler: WildcardHandler): void;\n\n\toff(type: EventType, handler: Handler): void;\n\toff(type: '*', handler: WildcardHandler): void;\n\n\temit<T = any>(type: EventType, event?: T): void;\n\temit(type: '*', event?: any): void;\n}\n\n/** Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt(all?: EventHandlerMap): Emitter {\n\tall = all || new Map();\n\n\treturn {\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param {string|symbol} type Type of event to listen for, or `\"*\"` for all events\n\t\t * @param {Function} handler Function to call in response to given event\n\t\t * @memberOf mitt\n\t\t */\n\t\ton(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tconst added = handlers && handlers.push(handler);\n\t\t\tif (!added) {\n\t\t\t\tall.set(type, [handler]);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t *\n\t\t * @param {string|symbol} type Type of event to unregister `handler` from, or `\"*\"`\n\t\t * @param {Function} handler Handler function to remove\n\t\t * @memberOf mitt\n\t\t */\n\t\toff(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `\"*\"` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing \"*\" handlers is not supported.\n\t\t *\n\t\t * @param {string|symbol} type The event type to invoke\n\t\t * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler\n\t\t * @memberOf mitt\n\t\t */\n\t\temit(type: EventType, evt: any) {\n\t\t\t((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });\n\t\t\t((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });\n\t\t}\n\t};\n}\n"],"names":["all","Map","on","type","handler","handlers","get","push","set","off","splice","indexOf","emit","evt","slice","map"],"mappings":"wBA6B6BA,GAG5B,OAFAA,EAAMA,GAAO,IAAIC,IAEV,CAQNC,GAAGC,EAAiBC,GACnB,MAAMC,EAAWL,EAAIM,IAAIH,GACXE,GAAYA,EAASE,KAAKH,IAEvCJ,EAAIQ,IAAIL,EAAM,CAACC,KAWjBK,IAAIN,EAAiBC,GACpB,MAAMC,EAAWL,EAAIM,IAAIH,GACrBE,GACHA,EAASK,OAAOL,EAASM,QAAQP,KAAa,EAAG,IAcnDQ,KAAKT,EAAiBU,IACnBb,EAAIM,IAAIH,IAAS,IAAyBW,QAAQC,IAAKX,IAAcA,EAAQS,MAC7Eb,EAAIM,IAAI,MAAQ,IAAiCQ,QAAQC,IAAKX,IAAcA,EAAQD,EAAMU"}

2
vendor/mitt/dist/mitt.umd.js vendored Normal file
View File

@ -0,0 +1,2 @@
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).mitt=n()}(this,function(){return function(e){return e=e||new Map,{on:function(n,t){var f=e.get(n);f&&f.push(t)||e.set(n,[t])},off:function(n,t){var f=e.get(n);f&&f.splice(f.indexOf(t)>>>0,1)},emit:function(n,t){(e.get(n)||[]).slice().map(function(e){e(t)}),(e.get("*")||[]).slice().map(function(e){e(n,t)})}}}});
//# sourceMappingURL=mitt.umd.js.map

1
vendor/mitt/dist/mitt.umd.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"mitt.umd.js","sources":["../src/index.ts"],"sourcesContent":["export type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler = (event?: any) => void;\nexport type WildcardHandler= (type: EventType, event?: any) => void\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList = Array<Handler>;\nexport type WildCardEventHandlerList = Array<WildcardHandler>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;\n\nexport interface Emitter {\n\ton(type: EventType, handler: Handler): void;\n\ton(type: '*', handler: WildcardHandler): void;\n\n\toff(type: EventType, handler: Handler): void;\n\toff(type: '*', handler: WildcardHandler): void;\n\n\temit<T = any>(type: EventType, event?: T): void;\n\temit(type: '*', event?: any): void;\n}\n\n/** Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt(all?: EventHandlerMap): Emitter {\n\tall = all || new Map();\n\n\treturn {\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param {string|symbol} type Type of event to listen for, or `\"*\"` for all events\n\t\t * @param {Function} handler Function to call in response to given event\n\t\t * @memberOf mitt\n\t\t */\n\t\ton(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tconst added = handlers && handlers.push(handler);\n\t\t\tif (!added) {\n\t\t\t\tall.set(type, [handler]);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t *\n\t\t * @param {string|symbol} type Type of event to unregister `handler` from, or `\"*\"`\n\t\t * @param {Function} handler Handler function to remove\n\t\t * @memberOf mitt\n\t\t */\n\t\toff(type: EventType, handler: Handler) {\n\t\t\tconst handlers = all.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `\"*\"` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing \"*\" handlers is not supported.\n\t\t *\n\t\t * @param {string|symbol} type The event type to invoke\n\t\t * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler\n\t\t * @memberOf mitt\n\t\t */\n\t\temit(type: EventType, evt: any) {\n\t\t\t((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });\n\t\t\t((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });\n\t\t}\n\t};\n}\n"],"names":["all","Map","on","type","handler","handlers","get","push","set","off","splice","indexOf","emit","evt","slice","map"],"mappings":"6LA6B6BA,GAG5B,OAFAA,EAAMA,GAAO,IAAIC,IAEV,CAQNC,YAAGC,EAAiBC,GACnB,IAAMC,EAAWL,EAAIM,IAAIH,GACXE,GAAYA,EAASE,KAAKH,IAEvCJ,EAAIQ,IAAIL,EAAM,CAACC,KAWjBK,aAAIN,EAAiBC,GACpB,IAAMC,EAAWL,EAAIM,IAAIH,GACrBE,GACHA,EAASK,OAAOL,EAASM,QAAQP,KAAa,EAAG,IAcnDQ,cAAKT,EAAiBU,IACnBb,EAAIM,IAAIH,IAAS,IAAyBW,QAAQC,IAAI,SAACX,GAAcA,EAAQS,MAC7Eb,EAAIM,IAAI,MAAQ,IAAiCQ,QAAQC,IAAI,SAACX,GAAcA,EAAQD,EAAMU"}

125
vendor/mitt/package.json vendored Normal file
View File

@ -0,0 +1,125 @@
{
"_from": "mitt@^2.0.1",
"_id": "mitt@2.0.1",
"_inBundle": false,
"_integrity": "sha512-FhuJY+tYHLnPcBHQhbUFzscD5512HumCPE4URXZUgPi3IvOJi4Xva5IIgy3xX56GqCmw++MAm5UURG6kDBYTdg==",
"_location": "/mitt",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "mitt@^2.0.1",
"name": "mitt",
"escapedName": "mitt",
"rawSpec": "^2.0.1",
"saveSpec": null,
"fetchSpec": "^2.0.1"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/mitt/-/mitt-2.0.1.tgz",
"_shasum": "9e8a075b4daae82dd91aac155a0ece40ca7cb393",
"_spec": "mitt@^2.0.1",
"_where": "/Users/jacktfranklin/src/puppeteer",
"authors": [
"Jason Miller <jason@developit.ca>"
],
"bugs": {
"url": "https://github.com/developit/mitt/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Tiny 200b functional Event Emitter / pubsub.",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/sinon": "^9.0.4",
"@types/sinon-chai": "^3.2.4",
"@typescript-eslint/eslint-plugin": "^3.0.1",
"@typescript-eslint/parser": "^3.0.1",
"chai": "^4.2.0",
"documentation": "^13.0.0",
"eslint": "^7.1.0",
"eslint-config-developit": "^1.2.0",
"esm": "^3.2.25",
"microbundle": "^0.12.0",
"mocha": "^7.2.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"ts-node": "^8.10.1",
"typescript": "^3.9.3"
},
"eslintConfig": {
"extends": [
"developit",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"env": {
"browser": true,
"mocha": true,
"jest": false,
"es6": true
},
"globals": {
"expect": true
},
"rules": {
"semi": [
2,
"always"
],
"jest/valid-expect": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0
}
},
"eslintIgnore": [
"dist"
],
"esmodules": "dist/mitt.modern.js",
"files": [
"src",
"dist"
],
"homepage": "https://github.com/developit/mitt",
"jsnext:main": "dist/mitt.es.js",
"keywords": [
"events",
"eventemitter",
"emitter",
"pubsub"
],
"license": "MIT",
"main": "dist/mitt.js",
"module": "dist/mitt.es.js",
"name": "mitt",
"repository": {
"type": "git",
"url": "git+https://github.com/developit/mitt.git"
},
"scripts": {
"build": "npm-run-all --silent clean -p bundle -s docs",
"bundle": "microbundle",
"clean": "rimraf dist",
"docs": "documentation readme src/index.ts --section API -q --parse-extension ts",
"lint": "eslint src test --ext ts --ext js",
"release": "npm run -s build -s && npm t && git commit -m $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"test": "npm-run-all --silent typecheck lint testonly",
"testonly": "mocha --require esm test/**/*.js",
"typecheck": "tsc **/*.ts --noEmit"
},
"source": "src/index.ts",
"typings": "dist/index.d.ts",
"umd:main": "dist/mitt.umd.js",
"version": "2.0.1"
}

78
vendor/mitt/src/index.ts vendored Normal file
View File

@ -0,0 +1,78 @@
export type EventType = string | symbol;
// An event handler can take an optional event argument
// and should not return a value
export type Handler = (event?: any) => void;
export type WildcardHandler= (type: EventType, event?: any) => void
// An array of all currently registered event handlers for a type
export type EventHandlerList = Array<Handler>;
export type WildCardEventHandlerList = Array<WildcardHandler>;
// A map of event types and their corresponding event handlers.
export type EventHandlerMap = Map<EventType, EventHandlerList | WildCardEventHandlerList>;
export interface Emitter {
on(type: EventType, handler: Handler): void;
on(type: '*', handler: WildcardHandler): void;
off(type: EventType, handler: Handler): void;
off(type: '*', handler: WildcardHandler): void;
emit<T = any>(type: EventType, event?: T): void;
emit(type: '*', event?: any): void;
}
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
* @name mitt
* @returns {Mitt}
*/
export default function mitt(all?: EventHandlerMap): Emitter {
all = all || new Map();
return {
/**
* Register an event handler for the given type.
* @param {string|symbol} type Type of event to listen for, or `"*"` for all events
* @param {Function} handler Function to call in response to given event
* @memberOf mitt
*/
on(type: EventType, handler: Handler) {
const handlers = all.get(type);
const added = handlers && handlers.push(handler);
if (!added) {
all.set(type, [handler]);
}
},
/**
* Remove an event handler for the given type.
*
* @param {string|symbol} type Type of event to unregister `handler` from, or `"*"`
* @param {Function} handler Handler function to remove
* @memberOf mitt
*/
off(type: EventType, handler: Handler) {
const handlers = all.get(type);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}
},
/**
* Invoke all handlers for the given type.
* If present, `"*"` handlers are invoked after type-matched handlers.
*
* Note: Manually firing "*" handlers is not supported.
*
* @param {string|symbol} type The event type to invoke
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
* @memberOf mitt
*/
emit(type: EventType, evt: any) {
((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });
((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });
}
};
}

11
vendor/tsconfig.cjs.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.json",
"exclude": [
"mitt/dist"
],
"compilerOptions": {
"composite": true,
"outDir": "../lib/cjs/vendor",
"module": "CommonJS"
}
}

11
vendor/tsconfig.esm.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.json",
"exclude": [
"mitt/dist"
],
"compilerOptions": {
"composite": true,
"outDir": "../lib/esm/vendor",
"module": "esnext"
}
}