/* Chars */

/* Comment */

/* Doctype */

/* EndTag */

/* StartTag */

/* afterAttributeName */

/* afterAttributeValueQuoted */

/* afterDoctypeName */

/* afterDoctypePublicIdentifier */

/* afterDoctypePublicKeyword */

/* afterDoctypeSystemIdentifier */

/* afterDoctypeSystemKeyword */

/* attributeName */

/* attributeValueDoubleQuoted */

/* attributeValueSingleQuoted */

/* attributeValueUnquoted */

/* beforeAttributeName */

/* beforeAttributeValue */

/* beforeData */

/* beforeDoctypeName */

/* beforeDoctypePublicIdentifier */

/* betweenDoctypePublicAndSystemIdentifiers */

/* binding */

/* comment */

/* commentEnd */

/* commentEndDash */

/* commentStart */

/* commentStartDash */

/* data */

/* doctype */

/* doctypeName */

/* doctypePublicIdentifierDoubleQuoted */

/* doctypePublicIdentifierSingleQuoted */

/* doctypeSystemIdentifierDoubleQuoted */

/* doctypeSystemIdentifierSingleQuoted */

/* endTagName */

/* endTagOpen */

/* harmony export */

/* harmony import */

/* markupDeclarationOpen */

/* selfClosingStartTag */

/* tagName */

/* tagOpen */

/*#__PURE__*/

/**
	Given a string, returns an array of TOKEN instances representing the
	composition of that string.

	@method run
	@param {State<string>} start scanner starting state
	@param {string} str input string to scan
	@return {Token[]} list of tokens, each with a type and value
*/

/**
	Represents a list of tokens making up a valid email address
*/

/**
	Represents some plain text
*/

/**
	Returns a list of tokens skipped until the closing tag of tagName.

	* `tagName` is the closing tag which will prompt us to stop skipping
	* `tokens` is the array of tokens generated by HTML5Tokenizer which
	* `i` is the index immediately after the opening tag to skip
	* `skippedTokens` is an array which skipped tokens are being pushed into

	Caveats

	* Assumes that i is the first token after the given opening tagName
	* The closing tag will be skipped, but nothing after it
	* Will track whether there is a nested tag of the same type
*/

/**
	`tokens` and `token` in this section referes to tokens returned by
	`linkify.tokenize`. `linkified` will contain HTML Parser-style tokens
	@param {string}
	@param {import('linkifyjs').Options}
*/

/**
  	Lowercases relevant parts of the domain and adds the protocol if
  	required. Note that this will not escape unsafe HTML characters in the
  	URL.
  		@param {string} [scheme] default scheme (e.g., 'https')
  	@return {string} the full href
  */

/**
  	Returns an object  of relevant values for this token, which includes keys
  	* type - Kind of token ('url', 'email', etc.)
  	* value - Original text
  	* href - The value that should be added to the anchor tag's href
  		attribute
  		@method toObject
  	@param {string} [protocol] `'http'` by default
  */

/**
   *
   * @param {Options} options
   * @returns {string}
   */

/**
   *
   * @param {Options} options Formatting option
   */

/**
   * @param {IntermediateRepresentation} ir
   * @returns {any}
   */

/**
   * @param {Options} options Formatting options
   * @returns {string}
   */

/**
   * @template {keyof Opts} L
   * @param {L} key Name of options object to use
   * @param {string} [operator]
   * @param {MultiToken} [token]
   * @returns {Opts[L] | any}
   */

/**
   * @type string[]
   */

/**
   * Check whether this URL token has a protocol
   * @return {boolean}
   */

/**
   * Convert the given token to a rendered element that may be added to the
   * calling-interface's DOM
   * @param {MultiToken} token Token to render to an HTML element
   * @returns {any} Render result; e.g., HTML string, DOM element, React
   *   Component, etc.
   */

/**
   * Follow an existing transition from the given input to the next state.
   * Does not mutate.
   * @param {string} input character or token type to transition on
   * @returns {?State<T>} the next state, if any
   */

/**
   * Resolve an option's value based on the value of the option and the given
   * params. If operator and token are specified and the target option is
   * callable, automatically calls the function with the given argument.
   * @template {keyof Opts} K
   * @param {K} key Name of option to use
   * @param {string} [operator] will be passed to the target option if it's a
   * function. If not specified, RAW function value gets returned
   * @param {MultiToken} [token] The token from linkify.tokenize
   * @returns {Opts[K] | any}
   */

/**
   * Return an object that represents how this link should be rendered.
   * @param {Options} options Formattinng options
   */

/**
   * Return the string this token represents.
   * @return {string}
   */

/**
   * Returns true or false based on whether a token should be displayed as a
   * link based on the user options.
   * @param {MultiToken} token
   * @returns {boolean}
   */

/**
   * Short for "take regexp transition"; defines a transition for this state
   * when it encounters a token which matches the given regular expression
   * @param {RegExp} regexp Regular expression transition (populate first)
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   * @returns {State<T>} taken after the given input
   */

/**
   * Short for "take transition", this is a method for building/working with
   * state machines.
   *
   * If a state already exists for the given input, returns it.
   *
   * If a token is specified, that state will emit that token when reached by
   * the linkify engine.
   *
   * If no state exists, it will be initialized with some default transitions
   * that resemble existing default transitions.
   *
   * If a state is given for the second argument, that state will be
   * transitioned to on the given input regardless of what that input
   * previously did.
   *
   * Specify a token group flags to define groups that this token belongs to.
   * The token will be added to corresponding entires in the given groups
   * object.
   *
   * @param {string} input character, token type to transition on
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of groups
   * @returns {State<T>} taken after the given input
   */

/**
   * Short for "take transitions", will take as many sequential transitions as
   * the length of the given input and returns the
   * resulting final state.
   * @param {string | string[]} input
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   * @returns {State<T>} taken after the given input
   */

/**
   * Short for "transition all"; create a transition from the array of items
   * in the given list to the same final resulting state.
   * @param {string | string[]} inputs Group of inputs to transition on
   * @param {Transition<T> | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   */

/**
   * The end index of this token in the original input string (up to this
   * index but not including it)
   * @returns {number}
   */

/**
   * The start index of this token in the original input string
   * @returns {number}
   */

/**
   * What should the value for this token be in the `href` HTML attribute?
   * Returns the `.toString` value by default.
   * @param {string} [scheme]
   * @return {string}
  */

/**
   * Whether the state has a transition for the given input. Set the second
   * argument to true to only look for an exact match (and not a default or
   * regular-expression-based transition)
   * @param {string} input
   * @param {boolean} exactOnly
   */

/**
   * Whether this token should be rendered as a link according to the given options
   * @param {Options} options
   * @returns {boolean}
   */

/**
 * @param {string} str html string to link
 * @param {import('linkifyjs').Opts} [opts] linkify options
 * @returns {string} resulting string
 */

/**
 * @param {string} value
 * @param {Token[]} tokens
 */

/**
 * @template T
 * @param {State<T>} state
 * @param {RegExp} regexp
 * @param {T | State<T>} [next]
 * @param {Flags} [flags]
 * @param {Collections<T>} [groups]
 */

/**
 * @template T
 * @param {State<T>} state
 * @param {string | string[]} input
 * @param {Flags} [flags]
 * @param {Collections<T>} [groups]
 */

/**
 * @template T
 * @param {T} t token to add
 * @param {Collections<T>} groups
 * @param {Flags} flags
 */

/**
 * @template T
 * @param {T} t token to check
 * @param {Collections<T>} groups
 * @returns {Flags} group flags that contain this token
 */

/**
 * @template T
 * @param {string} name
 * @param {Collections<T>} groups to register in
 * @returns {T[]} Current list of tokens in the given collection
 */

/**
 * @template T
 * @typedef {null | T } Transition
 */

/**
 * @template T
 * @typedef {{ [collection: string]: T[] }} Collections
 */

/**
 * @type Required<Opts>
 */

/**
 * @typedef {(arg: { scanner: ScannerInit }) => void} TokenPlugin
 */

/**
 * @typedef {(arg: { scanner: ScannerInit, parser: ParserInit }) => void} Plugin
 */

/**
 * @typedef {{
 * 	start: State<MultiToken>,
 * 	tokens: typeof multi
 * }} ParserInit
 */

/**
 * @typedef {{
 * 	start: State<string>,
 * 	tokens: { groups: Collections<string> } & typeof tk
 * }} ScannerInit
 */

/**
 * Abstract class used for manufacturing tokens of text tokens. That is rather
 * than the value for a token being a small string of text, it's value an array
 * of text tokens.
 *
 * Used for grouping together URLs, emails, hashtags, and other potential
 * creations.
 * @class MultiToken
 * @property {string} t
 * @property {string} v
 * @property {Token[]} tk
 * @abstract
 */

/**
 * All formatted properties required to render a link, including `tagName`,
 * `attributes`, `content` and `eventListeners`.
 * @typedef {{ tagName: any, attributes: {[attr: string]: any}, content: string,
 * eventListeners: EventListeners }} IntermediateRepresentation
 */

/**
 * An object where each key is a valid DOM Event Name such as `click` or `focus`
 * and each value is an event handler function.
 *
 * https://developer.mozilla.org/en-US/docs/Web/API/Element#events
 * @typedef {?{ [event: string]: Function }} EventListeners
 */

/**
 * Convert a String to an Array of characters, taking into account that some
 * characters like emojis take up two string indexes.
 *
 * Adapted from core-js (MIT license)
 * https://github.com/zloirock/core-js/blob/2d69cf5f99ab3ea3463c395df81e5a15b68f49d9/packages/core-js/internals/string-multibyte.js
 *
 * @function stringToArray
 * @param {string} str
 * @returns {string[]}
 */

/**
 * Create a new token that can be emitted by the parser state machine
 * @param {string} type readable type of the token
 * @param {object} props properties to assign or override, including isLink = true or false
 * @returns {new (value: string, tokens: Token[]) => MultiToken} new token class
 */

/**
 * De-register all plugins and reset the internal state-machine. Used for
 * testing; not required in practice.
 * @private
 */

/**
 * Define a basic state machine state. j is the list of character transitions,
 * jr is the list of regex-match transitions, jd is the default state to
 * transition to t is the accepting token type, if any. If this is the terminal
 * state, then it does not emit a token.
 *
 * The template type T represents the type of the token this state accepts. This
 * should be a string (such as of the token exports in `text.js`) or a
 * MultiToken subclass (from `multi.js`)
 *
 * @template T
 * @param {T} [token] Token that this state emits
 */

/**
 * Detect URLs with the following additional protocol. Anything with format
 * "protocol://..." will be considered a link. If `optionalSlashSlash` is set to
 * `true`, anything with format "protocol:..." will be considered a link.
 * @param {string} protocol
 * @param {boolean} [optionalSlashSlash]
 */

/**
 * Fast version of ts function for when transition defaults are well known
 * @param {State<string>} state
 * @param {string} input
 * @param {string} t
 * @param {string} defaultt
 * @param {[RegExp, State<string>][]} jr
 * @returns {State<string>}
 */

/**
 * Find a list of linkable items in the given string.
 * @param {string} str string to find links in
 * @param {string | Opts} [type] either formatting options or specific type of
 * links to find, e.g., 'url' or 'email'
 * @param {Opts} [opts] formatting options for final output. Cannot be specified
 * if opts already provided in `type` argument
*/

/**
 * Generate the parser multi token-based state machine
 * @param {{ groups: Collections<string> }} tokens
 */

/**
 * Initialize the linkify state machine. Called automatically the first time
 * linkify is called on a string, but may be called manually as well.
 */

/**
 * Initialize the scanner character-based state machine for the given start
 * state
 * @param {[string, boolean][]} customSchemes List of custom schemes, where each
 * item is a length-2 tuple with the first element set to the string scheme, and
 * the second element set to `true` if the `://` after the scheme is optional
 */

/**
 * Is the given string valid linkable text of some sort. Note that this does not
 * trim the text for you.
 *
 * Optionally pass in a second `type` param, which is the type of link to test
 * for.
 *
 * For example,
 *
 *     linkify.test(str, 'email');
 *
 * Returns `true` if str is a valid email.
 * @param {string} str string to test for links
 * @param {string} [type] optional specific link type to look for
 * @returns boolean true/false
 */

/**
 * Parse a string into tokens that represent linkable and non-linkable sub-components
 * @param {string} str
 * @return {MultiToken[]} tokens
 */

/**
 * Register a linkify plugin
 * @param {string} name of plugin to register
 * @param {Plugin} plugin function that accepts the parser state machine and
 * extends the parser to recognize additional link types
 */

/**
 * Register a token plugin to allow the scanner to recognize additional token
 * types before the parser state machine is constructed from the results.
 * @param {string} name of plugin to register
 * @param {TokenPlugin} plugin function that accepts the scanner state machine
 * and available scanner tokens and collections and extends the state machine to
 * recognize additional tokens or groups.
 */

/**
 * Run the parser state machine on a list of scanned string-based tokens to
 * create a list of multi tokens, each of which represents a URL, email address,
 * plain text, etc.
 *
 * @param {State<MultiToken>} start parser start state
 * @param {string} input the original input used to generate the given tokens
 * @param {Token[]} tokens list of scanned tokens
 * @returns {MultiToken[]}
 */

/**
 * Scanner output token:
 * - `t` is the token name (e.g., 'NUM', 'EMOJI', 'TLD')
 * - `v` is the value of the token (e.g., '123', '❤️', 'com')
 * - `s` is the start index of the token in the original string
 * - `e` is the end index of the token in the original string
 * @typedef {{t: string, v: string, s: number, e: number}} Token
 */

/**
 * Scanner token groups
 * @type Collections<string>
 */

/**
 * See available options: https://linkify.js.org/docs/options.html
 * @typedef {{
 * 	defaultProtocol?: string,
 *  events?: OptObj<EventListeners>,
 * 	format?: Opt<string>,
 * 	formatHref?: Opt<string>,
 * 	nl2br?: boolean,
 * 	tagName?: Opt<any>,
 * 	target?: Opt<string>,
 * 	rel?: Opt<string>,
 * 	validate?: Opt<boolean>,
 * 	truncate?: Opt<number>,
 * 	className?: Opt<string>,
 * 	attributes?: OptObj<({ [attr: string]: any })>,
 *  ignoreTags?: string[],
 * 	render?: OptFn<((ir: IntermediateRepresentation) => any)>
 * }} Opts
 */

/**
 * Specify either a function described by template type `F` or an object.
 *
 * Each key in the object should be a link type (`'url'`, `'hashtag`', etc.). Each
 * value should be a function with template type `F` that is called when the
 * corresponding link type is encountered.
 * @template F
 * @typedef {F | { [type: string]: F}} OptFn
 */

/**
 * Specify either a value with template type `V`, a function that returns `V` or
 * an object where each value resolves to `V`.
 *
 * The function takes a string value (usually the link's href attribute), the
 * link type (`'url'`, `'hashtag`', etc.) and an internal token representation
 * of the link. It should return an object of the template type `V`
 *
 * For the object, each key should be a link type (`'url'`, `'hashtag`', etc.).
 * Each value should either have type `V` or a function that returns V. This
 * function similarly takes a string value and a token.
 *
 * Example valid types for `Opt<string>`:
 *
 * ```js
 * 'hello'
 * (value, type, token) => 'world'
 * { url: 'hello', email: (value, token) => 'world'}
 * ```
 * @template V
 * @typedef {V | ((value: string, type: string, token: MultiToken) => V) | { [type: string]: V | ((value: string, token: MultiToken) => V) }} Opt
 */

/**
 * Specify either an object described by the template type `O` or a function.
 *
 * The function takes a string value (usually the link's href attribute), the
 * link type (`'url'`, `'hashtag`', etc.) and an internal token representation
 * of the link. It should return an object of the template type `O`
 * @template O
 * @typedef {O | ((value: string, type: string, token: MultiToken) => O)} OptObj
 */

/**
 * Utility class for linkify interfaces to apply specified
 * {@link Opts formatting and rendering options}.
 *
 * @param {Opts | Options} [opts] Option value overrides.
 * @param {(ir: IntermediateRepresentation) => any} [defaultRender] (For
 *   internal use) default render function that determines how to generate an
 *   HTML element based on a link token's derived tagName, attributes and HTML.
 *   Similar to render option
 */

/**
 * Utility function for instantiating a new multitoken with all the relevant
 * fields during parsing.
 * @param {new (value: string, tokens: Token[]) => MultiToken} Multi class to instantiate
 * @param {string} input original input string
 * @param {Token[]} tokens consecutive tokens scanned from input string
 * @returns {MultiToken}
 */

/**
 * generated from https://raw.githubusercontent.com/w3c/html/26b5126f96f736f796b9e29718138919dd513744/entities.json
 * do not edit
 */

/** @class */

/** @protected */

/** @type Collections<string> */

/** @type State<string> */

/** @type {?State<T>} jd */

/** @type {?T} t */

/** @type {[RegExp, State<T>][]} jr */

/** @type {{ [input: string]: State<T> }} j */

/******************************************************************************
	Multi-Tokens
	Tokens composed of arrays of TextTokens
******************************************************************************/

/***/

/*const EmailColonPort = */

// (but not TLDs)

// Accepting state!

// Account for dots and hyphens. Hyphens are usually parts of domain names

// Base token

// Become real URLs after `SLASH` or `COLON NUM SLASH`

// Check if already has a prefix scheme

// Check if existing state given, just a basic transition

// Close brace/bracket to become regular URL

// Closing bracket component. This character WILL be included in the URL

// Closing tag

// Collect the states generated by different protocols. NOTE: If any new TLDs

// Comment

// Consider these to be just plain text

// Convert the tokens back into a string

// Create a new multitoken

// Data

// Emoji tokens. They are not grouped by the scanner except in cases where a

// Ensure all ignored tags are uppercase

// Ensure newly token is in the same groups as the old token

// Final possible email states

// Finally close off the textTokens (if available)

// First close off the textTokens (if available)

// Force URL with scheme prefix followed by anything sane

// Frequently used states (name argument removed during minification)

// Generates states for top-level domains

// Get the next state

// HTML parser, not linkify's parser

// Helper functions to improve minification (not exported outside linkifyjs module)

// Here works with or without scheme:// prefix

// Hyphen can jump back to a domain name

// IMPLEMENTATION 1

// If any whitespace except newline, more whitespace!

// Ignore all the contents of ignored tags

// Initialize parser state machine and plugins

// Initialize scanner state machine and plugins

// Internationalized domain names containing non-ASCII

// Keep track of the latest accepting state

// Linkify the tokens given by the parser

// Local part of the email address

// Local part of the email address plus '.' (localpart cannot end in .)

// Local part of the email address plus @

// Localhost token

// Long URL with optional port and maybe query string

// Nested tag of the same type, "add to stack"

// No accepting state was found, part of a regular text token add

// No more jumps, just make a new token from the last accepting one

// Non-accepting

// Note that domains that begin with schemes are treated slighly differently

// Note that if stackCount > 0 here, the HTML is probably invalid

// Note that the final state can still be `UrlOpenbrace` (if the URL only

// Note that this is most accurate when tlds are in alphabetical order

// Nowhere left to jump! Return default, if any

// Possible email address (could have more tlds)

// Private methods

// Query strings

// Register custom schemes. Assumes each scheme is asciinumeric with hyphens

// Roll back to the latest accepting state

// Same as previous, but specific to non-fsm.ascii alphabet words

// Scheme states can transition to domain states

// Set default transition for start state (some symbol)

// Simplest possible URL with no query string

// Skip this token, it's not important

// Starting tokens with nowhere to jump to.

// State machine is not case sensitive, so input is tokenized in lowercased

// State which emits a word token

// States for special URL symbols that accept immediately after start

// THIS FILE IS AUTOMATICALLY GENERATED DO NOT EDIT DIRECTLY

// TLD followed by a port number

// Tags - attributes

// Tags - basic

// Tags - name

// Take the transition with the usual default mechanisms and use that as

// Token with maybe token groups

// Tokenize the string

// Tokens of only non-newline whitespace are arbitrarily long

// Types of characters the URL can definitely end in

// URL followed by (

// URL followed by ( and some symbols that the URL can end it

// URL followed by colon (potential port number here)

// URL followed by colon and port numner

// URL followed by some symbols (will not be part of the final URL)

// URL followed by {

// URL followed by { and some symbols that the URL can end it

// URL that begins with an opening bracket, followed by some symbols

// URL that beings with an opening bracket, followed by a symbols.

// URL with extra symbols at the end, followed by an opening bracket

// URL, followed by an opening bracket

// UrlOpenbrace followed by some symbols it cannot end it

// UrlOpenparenQ followed by some symbols it cannot end it

// Valid text token, linkify it!

// We don't need the complete named character reference because linkifyHtml

// Whitespace jumps

// `tokens` and `token` in this section refer to tokens generated by the

// a template for creating the next state

// be accounted for. &gt; &lt; and &quot; are also frequently relevant ones

// close to an email address now

// consume the `;`

// consume the entity chars

// does not modify the escape sequences. We do need &nbsp; so that

// domain followed by DOT

// domain followed by hyphen

// e.g., 'http'

// e.g., 'http:/'

// e.g., 'mailto'

// e.g., 'mailto:' or 'http://'

// form (still returns regular case). Uses selective `toLowerCase` because

// get added that are also protocols, set the token to be the same as the

// has a single opening bracket for some reason).

// https://data.iana.org/TLD/tlds-alpha-by-domain.txt

// intermediate representation

// localhost is a valid URL state

// lowercasing the entire string causes the length and character position to

// non-accepting state to avoid mixing whitespaces

// note: might be empty to prevent default jump

// number of tokens of this type on the [fictional] stack

// of tokens

// parsed string ends with a potential domain name (A)

// parsed string starts with local email info + @ with a potential domain name

// protocol to ensure parsing works as expected.

// single new line

// start index

// string value

// the first text token to the text tokens array and try again from

// the next

// this.j = []; // IMPLEMENTATION 2

// this.n = null; // DEBUG: State name

// token type/name

// tt(EmojiJoiner, EMOJI_VARIATION, Emoji); // also sketchy

// tt(Start, EMOJI_VARIATION, Emoji); // This one is sketchy

// two-index characters

// vary in some non-English strings with V8-based runtimes.

// whitespace is parsed properly. Other types of whitespace should already

// zero-width joiner

// zero-width joiner is present
