diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..6e76e56 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +fluff4.me \ No newline at end of file diff --git a/beta/.nojekyll b/beta/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/beta/env.json b/beta/env.json new file mode 100644 index 0000000..16004a6 --- /dev/null +++ b/beta/env.json @@ -0,0 +1 @@ +{"API_ORIGIN":"https://api.fluff4.me/","URL_ORIGIN":"https://fluff4.me/beta/","ENVIRONMENT":"beta","BUILD_NUMBER":"233","BUILD_SHA":"e146624e6be910959236bf9f63aca0bedb155d4d"} \ No newline at end of file diff --git a/beta/font/LICENSE.txt b/beta/font/LICENSE.txt new file mode 100644 index 0000000..e69c5e3 --- /dev/null +++ b/beta/font/LICENSE.txt @@ -0,0 +1,165 @@ +Fonticons, Inc. (https://fontawesome.com) + +-------------------------------------------------------------------------------- + +Font Awesome Free License + +Font Awesome Free is free, open source, and GPL friendly. You can use it for +commercial projects, open source projects, or really almost whatever you want. +Full Font Awesome Free license: https://fontawesome.com/license/free. + +-------------------------------------------------------------------------------- + +# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) + +The Font Awesome Free download is licensed under a Creative Commons +Attribution 4.0 International License and applies to all icons packaged +as SVG and JS file types. + +-------------------------------------------------------------------------------- + +# Fonts: SIL OFL 1.1 License + +In the Font Awesome Free download, the SIL OFL license applies to all icons +packaged as web and desktop font files. + +Copyright (c) 2024 Fonticons, Inc. (https://fontawesome.com) +with Reserved Font Name: "Font Awesome". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +SIL OPEN FONT LICENSE +Version 1.1 - 26 February 2007 + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting — in part or in whole — any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. + +-------------------------------------------------------------------------------- + +# Code: MIT License (https://opensource.org/licenses/MIT) + +In the Font Awesome Free download, the MIT license applies to all non-font and +non-icon files. + +Copyright 2024 Fonticons, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, copy, +modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------------- + +# Attribution + +Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font +Awesome Free files already contain embedded comments with sufficient +attribution, so you shouldn't need to do anything additional when using these +files normally. + +We've kept attribution comments terse, so we ask that you do not actively work +to remove them from files, especially code. They're a great way for folks to +learn about Font Awesome. + +-------------------------------------------------------------------------------- + +# Brand Icons + +All brand icons are trademarks of their respective owners. The use of these +trademarks does not indicate endorsement of the trademark holder by Font +Awesome, nor vice versa. **Please do not use brand logos for any purpose except +to represent the company, product, or service to which they refer.** diff --git a/beta/font/fa-solid-900.ttf b/beta/font/fa-solid-900.ttf new file mode 100644 index 0000000..e7e2ecf Binary files /dev/null and b/beta/font/fa-solid-900.ttf differ diff --git a/beta/font/fa-solid-900.woff2 b/beta/font/fa-solid-900.woff2 new file mode 100644 index 0000000..fec1fae Binary files /dev/null and b/beta/font/fa-solid-900.woff2 differ diff --git a/beta/image/banner.png b/beta/image/banner.png new file mode 100644 index 0000000..0bb9566 Binary files /dev/null and b/beta/image/banner.png differ diff --git a/beta/image/flag/flag gif frames.png b/beta/image/flag/flag gif frames.png new file mode 100644 index 0000000..271f6ba Binary files /dev/null and b/beta/image/flag/flag gif frames.png differ diff --git a/beta/image/flag/flag-padded.gif b/beta/image/flag/flag-padded.gif new file mode 100644 index 0000000..845acdb Binary files /dev/null and b/beta/image/flag/flag-padded.gif differ diff --git a/beta/image/flag/flag.gif b/beta/image/flag/flag.gif new file mode 100644 index 0000000..b4d7047 Binary files /dev/null and b/beta/image/flag/flag.gif differ diff --git a/beta/image/flag/flag_bg.gif b/beta/image/flag/flag_bg.gif new file mode 100644 index 0000000..be8ff39 Binary files /dev/null and b/beta/image/flag/flag_bg.gif differ diff --git a/beta/image/flag/flag_bg_compressed.gif b/beta/image/flag/flag_bg_compressed.gif new file mode 100644 index 0000000..43036fa Binary files /dev/null and b/beta/image/flag/flag_bg_compressed.gif differ diff --git a/beta/image/flag/logo-bg.png b/beta/image/flag/logo-bg.png new file mode 100644 index 0000000..8791593 Binary files /dev/null and b/beta/image/flag/logo-bg.png differ diff --git a/beta/image/flag/logo-greyscale-16.png b/beta/image/flag/logo-greyscale-16.png new file mode 100644 index 0000000..dfcc83e Binary files /dev/null and b/beta/image/flag/logo-greyscale-16.png differ diff --git a/beta/image/flag/logo-greyscale.pdn b/beta/image/flag/logo-greyscale.pdn new file mode 100644 index 0000000..b2428b1 Binary files /dev/null and b/beta/image/flag/logo-greyscale.pdn differ diff --git a/beta/image/flag/logo-greyscale.png b/beta/image/flag/logo-greyscale.png new file mode 100644 index 0000000..d128907 Binary files /dev/null and b/beta/image/flag/logo-greyscale.png differ diff --git a/beta/image/flag/logo-layer1.png b/beta/image/flag/logo-layer1.png new file mode 100644 index 0000000..c9ec32c Binary files /dev/null and b/beta/image/flag/logo-layer1.png differ diff --git a/beta/image/flag/logo-layer2.png b/beta/image/flag/logo-layer2.png new file mode 100644 index 0000000..9fb372c Binary files /dev/null and b/beta/image/flag/logo-layer2.png differ diff --git a/beta/image/flag/logo-layer3.png b/beta/image/flag/logo-layer3.png new file mode 100644 index 0000000..d0b42de Binary files /dev/null and b/beta/image/flag/logo-layer3.png differ diff --git a/beta/image/flag/logo-padded-bg.png b/beta/image/flag/logo-padded-bg.png new file mode 100644 index 0000000..981951c Binary files /dev/null and b/beta/image/flag/logo-padded-bg.png differ diff --git a/beta/image/flag/logo-padded.png b/beta/image/flag/logo-padded.png new file mode 100644 index 0000000..44d7168 Binary files /dev/null and b/beta/image/flag/logo-padded.png differ diff --git a/beta/image/flag/logo.pdn b/beta/image/flag/logo.pdn new file mode 100644 index 0000000..bc8b4b6 Binary files /dev/null and b/beta/image/flag/logo.pdn differ diff --git a/beta/image/flag/logo.png b/beta/image/flag/logo.png new file mode 100644 index 0000000..c031df4 Binary files /dev/null and b/beta/image/flag/logo.png differ diff --git a/beta/image/logo-wordmark.pdn b/beta/image/logo-wordmark.pdn new file mode 100644 index 0000000..9a946ec Binary files /dev/null and b/beta/image/logo-wordmark.pdn differ diff --git a/beta/image/logo-wordmark.svg b/beta/image/logo-wordmark.svg new file mode 100644 index 0000000..78e0424 --- /dev/null +++ b/beta/image/logo-wordmark.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/beta/image/logo.pdn b/beta/image/logo.pdn new file mode 100644 index 0000000..b04e663 Binary files /dev/null and b/beta/image/logo.pdn differ diff --git a/beta/image/logo.png b/beta/image/logo.png new file mode 100644 index 0000000..48a6c99 Binary files /dev/null and b/beta/image/logo.png differ diff --git a/beta/image/service/discord.png b/beta/image/service/discord.png new file mode 100644 index 0000000..907e9d0 Binary files /dev/null and b/beta/image/service/discord.png differ diff --git a/beta/image/service/github.png b/beta/image/service/github.png new file mode 100644 index 0000000..d9344c1 Binary files /dev/null and b/beta/image/service/github.png differ diff --git a/beta/image/service/google.png b/beta/image/service/google.png new file mode 100644 index 0000000..ac7b774 Binary files /dev/null and b/beta/image/service/google.png differ diff --git a/beta/image/service/patreon.png b/beta/image/service/patreon.png new file mode 100644 index 0000000..ae69de7 Binary files /dev/null and b/beta/image/service/patreon.png differ diff --git a/beta/index.html b/beta/index.html new file mode 100644 index 0000000..d9cb65f --- /dev/null +++ b/beta/index.html @@ -0,0 +1,39 @@ + + + + + fluff4.me + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/beta/index.js b/beta/index.js new file mode 100644 index 0000000..d19fdbe --- /dev/null +++ b/beta/index.js @@ -0,0 +1,11453 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +define("utility/Env", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class Env { + get isDev() { + return this.ENVIRONMENT === "dev"; + } + async load() { + const origin = location.origin; + const root = location.pathname.startsWith("/beta/") ? "/beta/" : "/"; + Object.assign(this, await fetch(origin + root + "env.json").then(response => response.json())); + document.documentElement.classList.add(`environment-${this.ENVIRONMENT}`); + } + } + exports.default = new Env; +}); +define("utility/Type", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +}); +define("utility/Objects", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Objects; + (function (Objects) { + Objects.EMPTY = {}; + function keys(object) { + return Object.keys(object); + } + Objects.keys = keys; + function values(object) { + return Object.values(object); + } + Objects.values = values; + function inherit(obj, inherits) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + Object.setPrototypeOf(obj, inherits.prototype); + return obj; + } + Objects.inherit = inherit; + function filterNullish(object) { + return filter(object, p => p[1] !== null && p[1] !== undefined); + } + Objects.filterNullish = filterNullish; + function filter(object, filter) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unnecessary-type-assertion + return Object.fromEntries(Object.entries(object).filter(filter)); + } + Objects.filter = filter; + function map(object, mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unnecessary-type-assertion + return Object.fromEntries(Object.entries(object).map(mapper)); + } + Objects.map = map; + async function mapAsync(object, mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return Object.fromEntries(await Promise.all(Object.entries(object).map(mapper))); + } + Objects.mapAsync = mapAsync; + function followPath(obj, keys) { + for (const key of keys) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + obj = obj?.[key]; + return obj; + } + Objects.followPath = followPath; + function applyJIT(obj, key, compute) { + const get = (() => { + const promise = compute(); + delete obj[key]; + obj[key] = promise; + if (promise instanceof Promise) + void promise.then(value => obj[key] = value); + return promise; + }); + get.compute = compute; + Object.defineProperty(obj, key, { + configurable: true, + get, + }); + } + Objects.applyJIT = applyJIT; + function copyJIT(target, from, key) { + const descriptor = Object.getOwnPropertyDescriptor(from, key); + if (!descriptor) + return; + if ("value" in descriptor) { + target[key] = from[key]; + return; + } + const compute = descriptor.get?.compute; + if (!compute) + return; + applyJIT(target, key, compute); + } + Objects.copyJIT = copyJIT; + Objects.assign = function (target, ...sources) { + for (const source of sources) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + for (const key of Object.keys(source)) { + const descriptor = Object.getOwnPropertyDescriptor(target, key); + if (!descriptor || descriptor.writable) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + target[key] = source[key]; + } + } + } + return target; + }; + function merge(a, b) { + if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || Array.isArray(a) || Array.isArray(b)) + return (b === undefined ? a : b); + const result = {}; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + result[key] = merge(a[key], b[key]); + return result; + } + Objects.merge = merge; + })(Objects || (Objects = {})); + exports.default = Objects; +}); +define("utility/string/MarkdownItHTML", ["require", "exports", "entities"], function (require, exports, entities_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + entities_1 = __importDefault(entities_1); + const html = Object.assign(((md, options) => { + const state = { + block: undefined, + inline: undefined, + i: 0, + l: 0, + e: 0, + src: "", + silent: false, + options: { + ...html.defaultOptions, + ...options, + }, + }; + md.block.ruler.at("html_block", (block, startLine, endLine, silent) => { + state.block = block; + state.src = state.block.src; + state.l = startLine; + state.i = state.block.bMarks[state.l] + state.block.tShift[state.l]; + state.e = state.src.length; + state.silent = silent; + const result = html.consumeBlock(state); + state.block = undefined; + return result; + }, { alt: ["paragraph"] }); + md.inline.ruler.at("html_inline", (inline, silent) => { + state.inline = inline; + state.e = inline.posMax; + state.i = inline.pos; + state.src = inline.src; + state.silent = silent; + const result = html.consumeInline(state); + state.inline = undefined; + return result; + }); + }), { + regexCSSProperty: /^[-a-zA-Z_][a-zA-Z0-9_-]*$/, + defaultOptions: { + voidElements: [ + "area", + "base", + "br", + "col", + "embed", + "hr", + "img", + "input", + "link", + "meta", + "source", + "track", + "wbr", + ], + allowedTags: [ + // headings + "hgroup", + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + // layout + "div", + "p", + "br", + "wbr", + "hr", + "details", + "summary", + "label", + // lists + "ol", + "ul", + "li", + // tables + "table", + "tr", + "th", + "td", + "caption", + "thead", + "tbody", + "tfoot", + // text + "span", + // text style + "i", + "b", + "u", + "s", + "strike", + "sup", + "sub", + "em", + "mark", + "small", + "strong", + // quoting/referencing + "q", + "cite", + "blockquote", + // links + "a", + // definitions + "abbr", + "dfn", + "dd", + "dt", + "dl", + // code + "code", + "samp", + "kbd", + // images + "img", + "figure", + "figcaption", + "area", + "map", + ], + allTagsAllowedAttributes: [ + "title", + "name", + "style", + "aria-label", + "aria-labelledby", + "aria-describedby", + "aria-hidden", + ], + allTagsAllowedAttributeValues: {}, + perTagAllowedAttributes: { + "a": ["href"], + "img": ["src", "alt", "usemap", "width", "height"], + "area": ["shape", "coords"], + "details": ["open"], + "ol": ["type", "start", "reversed"], + "li": ["value"], + "th": ["colspan", "rowspan", "headers", "scope", "abbr"], + "td": ["colspan", "rowspan", "headers"], + "q": ["cite"], + }, + perTagAllowedAttributeValues: { + "a": { "href": /^https?:/ }, + "img": { "src": /^https?:/ }, + "area": { "href": /^https?:/ }, + "q": { "cite": /^https?:/ }, + "blockquote": { "cite": /^https?:/ }, + }, + allTagsAllowedStyleProperties: [ + "color", + "text-align", + "font-family", + "font-style", + "font-weight", + "text-decoration", + "text-transform", + "line-height", + "letter-spacing", + "word-spacing", + "vertical-align", + "background-color", + "opacity", + "margin", + "padding", + "width", + "height", + "vertical-align", + "box-shadow", + "border-width", + "border-style", + "border-color", + "border-radius", + "text-indent", + "display", + "position", + ], + allTagsAllowedStylePropertyValues: { + "position": ["relative", "absolute", "sticky"], + }, + perTagAllowedStyleProperties: {}, + perTagAllowedStylePropertyValues: {}, + }, + Options(options) { + const factory = Object.assign({ ...structuredClone(html.defaultOptions), ...options }, { + disallowTags(...tags) { + const disallowed = tags.map(tag => tag.toLowerCase()); + factory.allowedTags = factory.allowedTags.filter(tag => !disallowed.includes(tag)); + return factory; + }, + allowTags(...tags) { + factory.allowedTags = [...new Set([...factory.allowedTags, ...tags.map(tag => tag.toLowerCase())])]; + return factory; + }, + disallowAttributes(...attributes) { + const disallowed = attributes.map(attr => attr.toLowerCase()); + factory.allTagsAllowedAttributes = factory.allTagsAllowedAttributes.filter(attr => !disallowed.includes(attr)); + for (const [tag, allowedAttributes] of Object.entries(factory.perTagAllowedAttributes)) + factory.perTagAllowedAttributes[tag] = allowedAttributes.filter(attr => !disallowed.includes(attr)); + return factory; + }, + allowAttributes(...attributes) { + factory.allTagsAllowedAttributes = [...new Set([...factory.allTagsAllowedAttributes, ...attributes.map(attr => attr.toLowerCase())])]; + return factory; + }, + }); + return factory; + }, + use(md, options) { + return md.use(html, options); + }, + consumeBlock(state) { + if (!state.block) + return false; + html.consumeInlineWhitespace(state); + if (state.silent) + return html.consumeTerminator(state); + const result = html.consumeTagsLine(state); + if (!result) + return false; + state.l++; + state.block.line = state.l; + const indent = html.consumeInlineWhitespace(state) || 0; + if (indent >= state.block.blkIndent + 4) + state.block.blkIndent = indent - 4; // allow for indented code blocks within html block + else + state.block.blkIndent = indent; + return true; + }, + consumeInline(state) { + if (!state.inline || state.src[state.i] !== "<") + return false; + const tag = html.consumeTag(state); + if (!tag) + return false; + state.inline.pos = state.i; + return true; + }, + consumeTerminator(state) { + const noSetBlockIndent = new Error().stack?.split("\n")?.at(4)?.includes("Array.lheading"); + const indent = html.consumeInlineWhitespace(state) || 0; + if (!html.consumeTagsLine(state)) + return false; + if (!noSetBlockIndent && state.block) + state.block.blkIndent = indent; + return true; + }, + consumeTagsLine(state) { + let consumed = false; + const tokens = []; + let token; + while (token = html.consumeTag(state)) { + if (typeof token === "object") + tokens.push(token); + consumed = true; + html.consumeInlineWhitespace(state); + } + if (!consumed) + return undefined; + if (state.i < state.src.length && !html.consumeNewline(state)) { + // a line of tags MUST end in a newline — if this doesn't, remove all the tokens we added and don't match + if (tokens.length) + state.block?.tokens.splice(0, Infinity, ...state.block.tokens + .filter(token => !tokens.includes(token))); + return undefined; + } + return { + tokens, + }; + }, + consumeNewline(state) { + if (state.inline) + return false; + if (state.src[state.i] === "\n") { + state.i++; + return true; + } + if (state.src[state.i] !== "\r") + return false; + state.i++; + if (state.src[state.i] === "\n") + state.i++; + return true; + }, + consumeWhitespace(state) { + if (state.inline) + return !!html.consumeInlineWhitespace(state); + const start = state.i; + if (state.i >= state.e) + return false; + for (state.i; state.i < state.e; state.i++) { + if (!html.isWhitespace(state)) + break; + if (html.consumeNewline(state)) { + state.l++; + state.i--; + } + } + return state.i > start; + }, + consumeInlineWhitespace(state) { + if (state.i >= state.e) + return undefined; + let indent = 0; + for (state.i; state.i < state.e; state.i++) { + if (state.src[state.i] === " ") + indent++; + else if (state.src[state.i] === "\t") + indent += 4; + else + break; + } + return indent || undefined; + }, + consumeTag(state) { + if (state.src[state.i] !== "<") + return undefined; + state.i++; + return html.consumeOpenTag(state) ?? html.consumeCloseTag(state); + }, + consumeOpenTag(state) { + const start = state.i; + const tagNameRaw = html.consumeTagName(state); + if (!tagNameRaw) + return undefined; + const tagName = tagNameRaw.toLowerCase(); + const o = state.options; + if (!o.allowedTags.includes(tagNameRaw)) { + state.i = start; + return undefined; + } + const attributes = []; + let style; + while (html.consumeWhitespace(state)) { + const attribute = html.consumeAttribute(state); + if (!attribute) + break; + let [name, value] = attribute; + name = name.toLowerCase(); + if (!o.allTagsAllowedAttributes.includes(name) && !o.perTagAllowedAttributes[tagName]?.includes(name)) + continue; + value = entities_1.default.decodeHTML5Strict(value); + if (name !== "style") { + const allowedValues = o.perTagAllowedAttributeValues[tagName]?.[name] ?? o.allTagsAllowedAttributeValues[name]; + if (allowedValues !== undefined && !html.matchesAllowedValues(value, allowedValues)) + continue; + attributes.push(attribute); + continue; + } + style = html.parseStyleAttributeValue(value); + let styleValue = ""; + for (let [property, value] of style) { + property = property.toLowerCase(); + if (!o.allTagsAllowedStyleProperties.includes(property) && !o.perTagAllowedStyleProperties[tagName]?.includes(property)) + continue; + const importantToken = "!important"; + const important = value.slice(-importantToken.length).toLowerCase() === importantToken; + if (important) + value = value.slice(0, -importantToken.length).trim(); + const allowedValues = o.perTagAllowedStylePropertyValues[tagName]?.[property] ?? o.allTagsAllowedStylePropertyValues[property]; + if (allowedValues !== undefined && !html.matchesAllowedValues(value, allowedValues)) + continue; + styleValue += `${property}:${value}${important ? importantToken : ""};`; + } + if (styleValue.length) + attributes.push(["style", styleValue.slice(0, -1)]); + } + if (state.src[state.i] === "/") + state.i++; + if (state.src[state.i] !== ">") { + state.i = start; + return undefined; + } + state.i++; + const nesting = state.options.voidElements.includes(tagName) ? 0 : 1; + if (state.silent) + return true; + let type = `html_${state.block ? "block" : "inline"}${nesting ? "_open" : ""}`; + if (tagName === "br") + type = "softbreak"; + const mdState = state.block ?? state.inline; + const token = mdState.push(type, tagName, nesting); + Object.assign(token, { + style, + raw: state.src.slice(start - 1, state.i), + }); + for (const attribute of attributes) + token.attrPush(attribute); + return token; + }, + consumeCloseTag(state) { + const start = state.i; + if (state.src[state.i] !== "/") + return undefined; + state.i++; + const tagNameRaw = html.consumeTagName(state); + if (!tagNameRaw) + return undefined; + if (state.src[state.i] !== ">") { + state.i = start; + return undefined; + } + state.i++; + const tagName = tagNameRaw.toLowerCase(); + if (!state.options.allowedTags.includes(tagName)) { + state.i = start; + return undefined; + } + if (state.silent || state.options.voidElements.includes(tagName)) + return true; + const type = `html_${state.block ? "block" : "inline"}_close`; + const mdState = state.block ?? state.inline; + const token = mdState.push(type, tagName, -1); + Object.assign(token, { raw: state.src.slice(start - 1, state.i) }); + if (state.inline && !state.inline.delimiters) + state.inline.delimiters = []; + return token; + }, + consumeTagName(state) { + const start = state.i; + if (state.i >= state.e) + return undefined; + if (!html.isAlpha(state)) + return undefined; + for (state.i++; state.i < state.e; state.i++) + if (!html.isAlphaNumeric(state)) + break; + return state.src.slice(start, state.i); + }, + consumeAttribute(state) { + const start = state.i; + const name = html.consumeAttributeName(state); + if (!name) + return undefined; + const valueStart = state.i; + html.consumeWhitespace(state); + if (state.src[state.i] !== "=") { + state.i = valueStart; + return [name, ""]; + } + state.i++; + html.consumeWhitespace(state); + const value = html.consumeAttributeValue(state); + if (!value) { + state.i = start; + return undefined; + } + return [name, value]; + }, + consumeAttributeName(state) { + const start = state.i; + if (state.i >= state.e) + return undefined; + for (state.i; state.i < state.e; state.i++) { + const charCode = state.src.charCodeAt(state.i); + const isInvalidChar = false + || charCode === 0x0020 // SPACE + || charCode === 0x0022 // " + || charCode === 0x0027 // ' + || charCode === 0x003E // > + || charCode === 0x002F // / + || charCode === 0x003D // = + || html.isNonCharacter(state, charCode) + || html.isControl(state, charCode); + if (isInvalidChar) + break; + } + return state.i > start ? state.src.slice(start, state.i) : undefined; + }, + consumeAttributeValue(state) { + return false + || html.consumeUnquotedAttributeValue(state) + || html.consumeQuotedAttributeValue(state) + || undefined; + }, + consumeUnquotedAttributeValue(state) { + let result = ""; + while (state.i < state.e) { + const charCode = state.src.charCodeAt(state.i); + // Check for invalid characters in unquoted attribute values + const isInvalidChar = false + || charCode === 0x0022 // " + || charCode === 0x0027 // ' + || charCode === 0x003D // = + || charCode === 0x003C // < + || charCode === 0x003E // > + || charCode === 0x0060 // ` + || html.isWhitespace(state, charCode); // ASCII whitespace + if (isInvalidChar) + break; + if (charCode !== 0x0026) { // not & + result += state.src[state.i]; + state.i++; + continue; + } + const charRef = html.consumeCharacterReference(state); + if (!charRef) { + result += "&"; + state.i++; + continue; + } + result += charRef; + // `i` is already at the next pos + } + return result || undefined; + }, + consumeQuotedAttributeValue(state) { + const start = state.i; + const quoteChar = state.src[state.i]; + if (quoteChar !== "'" && quoteChar !== '"') + return undefined; + state.i++; + let result = ""; + while (state.i < state.e) { + const charCode = state.src.charCodeAt(state.i); + if (state.src[state.i] === quoteChar) { + state.i++; + return result; + } + if (charCode !== 0x0026) { // not & + const charStart = state.i; + if (html.consumeNewline(state)) { + state.l++; + result += state.src.slice(charStart, state.i); + continue; + } + const isNewlineInInlineMode = state.inline && html.isWhitespace(state) && state.src[state.i] !== " " && state.src[state.i] !== "\t"; + if (isNewlineInInlineMode) { + state.i = start; + return undefined; + } + result += state.src[state.i]; + state.i++; + continue; + } + const charRef = html.consumeCharacterReference(state); + if (!charRef) { + result += "&"; + state.i++; + continue; + } + result += charRef; + // `i` is already at the next pos + } + // no closing quote before the end of `src` + state.i = start; + return undefined; + }, + consumeCharacterReference(state) { + const start = state.i; + if (state.src[state.i] !== "&") + return undefined; + state.i++; + const isValid = html.consumeNumericCharacterReference(state) || html.consumeNamedCharacterReference(state); + if (!isValid) { + state.i = start; + return undefined; + } + return state.src.slice(start, state.i); + }, + consumeNamedCharacterReference(state) { + const nameStart = state.i; + for (state.i; state.i < state.e; state.i++) + if (!html.isAlpha(state)) + break; + if (state.i === nameStart || state.src[state.i] !== ";") + return false; + state.i++; + return true; + }, + consumeNumericCharacterReference(state) { + if (state.src[state.i] !== "#") + return false; + state.i++; + const isHex = state.src[state.i] === "x" || state.src[state.i] === "X"; + if (isHex) + state.i++; + const digitsStart = state.i; + for (state.i; state.i < state.e; state.i++) + if (isHex ? !html.isHexadecimal(state) : !html.isNumeric(state)) + break; + if (state.i === digitsStart || state.src[state.i] !== ";") + return false; + const codePoint = parseInt(state.src.slice(digitsStart, state.i), isHex ? 16 : 10); + if (codePoint === 0x000D || html.isNonCharacter(state, codePoint) || (html.isControl(state, codePoint) && !html.isWhitespace(state, codePoint))) + return false; + state.i++; + return true; + }, + parseStyleAttributeValue: ((style) => { + if (style === undefined || style === null) + return undefined; + const styles = new Map(); + let key = ""; + let value = ""; + let inValue = false; + let isEscaped = false; + let isQuoted = false; + let isComment = false; + let quoteChar = ""; + let parenCount = 0; + for (let i = 0; i < style.length; i++) { + const char = style[i]; + if (isComment) { + if (char !== "*" && style[i + 1] !== "/") + continue; + isComment = false; + i++; + continue; + } + if (char === "\\") { + isEscaped = true; + continue; + } + if (isEscaped) { + value += char; + isEscaped = false; + continue; + } + if (!isComment && char === "/" && style[i + 1] === "*") { + isComment = true; + i++; + continue; + } + if (isQuoted) { + if (char === quoteChar) { + isQuoted = false; + value += char; + continue; + } + } + else { + if (char === '"' || char === "'") { + isQuoted = true; + quoteChar = char; + value += char; + continue; + } + } + if (char === "(" && !isQuoted) { + parenCount++; + value += char; + continue; + } + if (char === ")" && !isQuoted) { + parenCount--; + value += char; + continue; + } + if (char === ":" && !isQuoted && parenCount === 0) { + inValue = true; + continue; + } + if (char === ";" && !isQuoted && parenCount === 0) { + if (key && value) { + key = key.trim(); + if (!html.regexCSSProperty.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + key = ""; + value = ""; + } + inValue = false; + continue; + } + if (inValue) { + value += char; + } + else { + key += char; + } + } + if (key && value) { + key = key.trim(); + if (!html.regexCSSProperty.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + } + return styles; + }), + isAlpha(state, charCode = state.src.charCodeAt(state.i)) { + return (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122); // A-Z, a-z + }, + isNumeric(state, charCode = state.src.charCodeAt(state.i)) { + return charCode >= 48 && charCode <= 57; + }, + isHexadecimal(state, charCode = state.src.charCodeAt(state.i)) { + return (charCode >= 65 && charCode <= 70) || (charCode >= 97 && charCode <= 102) || html.isNumeric(state, charCode); + }, + isAlphaNumeric(state, charCode = state.src.charCodeAt(state.i)) { + return html.isAlpha(state, charCode) || html.isNumeric(state, charCode); + }, + isNonCharacter(state, charCode = state.src.charCodeAt(state.i)) { + return false + || (charCode >= 0xFDD0 && charCode <= 0xFDEF) + || charCode === 0xFFFE || charCode === 0xFFFF + || charCode === 0x1FFFE || charCode === 0x1FFFF + || charCode === 0x2FFFE || charCode === 0x2FFFF + || charCode === 0x3FFFE || charCode === 0x3FFFF + || charCode === 0x4FFFE || charCode === 0x4FFFF + || charCode === 0x5FFFE || charCode === 0x5FFFF + || charCode === 0x6FFFE || charCode === 0x6FFFF + || charCode === 0x7FFFE || charCode === 0x7FFFF + || charCode === 0x8FFFE || charCode === 0x8FFFF + || charCode === 0x9FFFE || charCode === 0x9FFFF + || charCode === 0xAFFFE || charCode === 0xAFFFF + || charCode === 0xBFFFE || charCode === 0xBFFFF + || charCode === 0xCFFFE || charCode === 0xCFFFF + || charCode === 0xDFFFE || charCode === 0xDFFFF + || charCode === 0xEFFFE || charCode === 0xEFFFF + || charCode === 0xFFFFE || charCode === 0xFFFFF + || charCode === 0x10FFFE || charCode === 0x10FFFF; + }, + isControl(state, charCode = state.src.charCodeAt(state.i)) { + return false + || (charCode >= 0x0000 && charCode <= 0x001F) + || (charCode >= 0x007F && charCode <= 0x009F); + }, + isWhitespace(state, charCode = state.src.charCodeAt(state.i)) { + return false + || charCode === 0x0009 // TAB + || charCode === 0x000A // LF + || charCode === 0x000C // FF + || charCode === 0x000D // CR + || charCode === 0x0020; // SPACE + }, + matchesAllowedValues(value, allowed) { + if (Array.isArray(allowed)) + return allowed.some(allowed => html.matchesAllowedValues(value, allowed)); + if (typeof allowed === "string") + return value === allowed; + if (typeof allowed === "function") + return allowed(value); + return allowed.test(value); + }, + }); + const MarkdownItHTML = html; + exports.default = MarkdownItHTML; +}); +define("utility/string/Strings", ["require", "exports", "markdown-it", "utility/string/MarkdownItHTML"], function (require, exports, markdown_it_1, MarkdownItHTML_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + markdown_it_1 = __importDefault(markdown_it_1); + MarkdownItHTML_1 = __importDefault(MarkdownItHTML_1); + var Strings; + (function (Strings) { + function includesAt(string, substring, index) { + if (index < 0) + index = string.length + index; + if (index + substring.length > string.length) + return false; + for (let i = 0; i < substring.length; i++) + if (string[i + index] !== substring[i]) + return false; + return true; + } + Strings.includesAt = includesAt; + function sliceTo(string, substring, startAt) { + const index = string.indexOf(substring, startAt); + if (index === -1) + return string; + return string.slice(0, index); + } + Strings.sliceTo = sliceTo; + function sliceAfter(string, substring, startAt) { + const index = string.indexOf(substring, startAt); + if (index === -1) + return string; + return string.slice(index + substring.length); + } + Strings.sliceAfter = sliceAfter; + function trimTextMatchingFromStart(string, substring, startAt) { + if (string.length < substring.length) + return string; + const index = string.indexOf(substring, startAt); + if (index !== 0) + return string; + return string.slice(index + substring.length); + } + Strings.trimTextMatchingFromStart = trimTextMatchingFromStart; + function trimTextMatchingFromEnd(string, substring, startAt) { + if (string.length < substring.length) + return string; + const index = string.lastIndexOf(substring, startAt); + if (index !== string.length - substring.length) + return string; + return string.slice(0, index); + } + Strings.trimTextMatchingFromEnd = trimTextMatchingFromEnd; + function extractFromQuotes(string) { + let substring = (string ?? "").trim(); + if (substring[0] === '"') + substring = substring.slice(1); + if (substring[substring.length - 1] === '"') + substring = substring.slice(0, -1); + return substring.trim(); + } + Strings.extractFromQuotes = extractFromQuotes; + function extractFromSquareBrackets(string) { + let substring = (string ?? ""); + if (substring[0] === "[") + substring = substring.slice(1).trimStart(); + if (substring[substring.length - 1] === "]") + substring = substring.slice(0, -1).trimEnd(); + return substring; + } + Strings.extractFromSquareBrackets = extractFromSquareBrackets; + function mergeRegularExpressions(flags, ...expressions) { + let exprString = ""; + for (const expr of expressions) + exprString += "|" + expr.source; + return new RegExp(exprString.slice(1), flags); + } + Strings.mergeRegularExpressions = mergeRegularExpressions; + function count(string, substring, stopAtCount = Infinity) { + let count = 0; + let lastIndex = -1; + while (count < stopAtCount) { + const index = string.indexOf(substring, lastIndex + 1); + if (index === -1) + return count; + count++; + lastIndex = index; + } + return count; + } + Strings.count = count; + function includesOnce(string, substring) { + return count(string, substring, 2) === 1; + } + Strings.includesOnce = includesOnce; + function getVariations(name) { + const variations = [name]; + variations.push(name + "d", name + "ed"); + if (name.endsWith("d")) + variations.push(...getVariations(name.slice(0, -1))); + if (name.endsWith("ed")) + variations.push(...getVariations(name.slice(0, -2))); + if (name.endsWith("ing")) { + variations.push(name.slice(0, -3)); + if (name[name.length - 4] === name[name.length - 5]) + variations.push(name.slice(0, -4)); + } + else { + variations.push(name + "ing", name + name[name.length - 1] + "ing"); + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ing"); + } + if (name.endsWith("ion")) { + variations.push(...getVariations(name.slice(0, -3))); + if (name[name.length - 4] === name[name.length - 5]) + variations.push(name.slice(0, -4)); + } + else + variations.push(name + "ion"); + if (name.endsWith("er")) + variations.push(name.slice(0, -1), name.slice(0, -2)); + else { + variations.push(name + "r", name + "er"); + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ier"); + } + if (name.endsWith("ier")) + variations.push(name.slice(0, -3) + "y"); + variations.push(name + "s", name + "es"); + if (name.endsWith("s")) + variations.push(name.slice(0, -1)); + else { + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ies"); + } + return variations; + } + Strings.getVariations = getVariations; + function shiftLine(lines, count = 1) { + for (let i = 0; i < count; i++) { + const index = lines.indexOf("\n"); + if (index === -1) + return lines; + lines = lines.slice(index + 1); + } + return lines; + } + Strings.shiftLine = shiftLine; + const REGEX_APOSTROPHE = /'/g; + const REGEX_NON_WORD_MULTI = /\W+/g; + function getWords(text) { + return text.toLowerCase() + .replace(REGEX_APOSTROPHE, "") + .split(REGEX_NON_WORD_MULTI) + .filter(Boolean); + } + Strings.getWords = getWords; + function fuzzyMatches(a, b, options) { + options ??= {}; + options.missingWordsThreshold ??= 0.4; + options.maxMissingWordsForFuzzy = 4; + const wordsA = getWords(a).map(getVariations); + const wordsB = getWords(b).map(getVariations); + let matches = 0; + let misses = 0; + let ia = 0; + let ib = 0; + NextMain: while (true) { + const va = wordsA[ia]; + const vb = wordsB[ib]; + if (!va && !vb) + break; + if (!va || !vb) { + ia++; + ib++; + misses++; + continue; + } + let loopMisses = 0; + for (let ia2 = ia; ia2 < wordsA.length && loopMisses <= options.maxMissingWordsForFuzzy; ia2++) { + const va = wordsA[ia2]; + if (va.some(va => vb.includes(va))) { + ia = ia2 + 1; + ib++; + matches++; + misses += loopMisses; + continue NextMain; + } + loopMisses++; + } + loopMisses = 0; + for (let ib2 = ib; ib2 < wordsB.length && loopMisses <= options.maxMissingWordsForFuzzy; ib2++) { + const vb = wordsB[ib2]; + if (vb.some(vb => va.includes(vb))) { + ia++; + ib = ib2 + 1; + matches++; + misses += loopMisses; + continue NextMain; + } + loopMisses++; + } + misses++; + ia++; + ib++; + } + return matches / (matches + misses) >= options.missingWordsThreshold; + } + Strings.fuzzyMatches = fuzzyMatches; + const REGEX_NON_WORD_MULTI_PREV = /(?<=\W+)/g; + function toTitleCase(text) { + return text.split(REGEX_NON_WORD_MULTI_PREV) + .map(word => word[0].toUpperCase() + word.slice(1)) + .join(""); + } + Strings.toTitleCase = toTitleCase; + Strings.markdown = new markdown_it_1.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_1.default.use(Strings.markdown, MarkdownItHTML_1.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + })(Strings || (Strings = {})); + exports.default = Strings; +}); +define("utility/Time", ["require", "exports", "utility/string/Strings"], function (require, exports, Strings_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Strings_1 = __importDefault(Strings_1); + var Time; + (function (Time) { + function floor(interval) { + return Math.floor(Date.now() / interval) * interval; + } + Time.floor = floor; + Time.frame = seconds(1) / 144; + function ms(ms) { return ms; } + Time.ms = ms; + function seconds(seconds) { return seconds * 1000; } + Time.seconds = seconds; + function minutes(minutes) { return minutes * 1000 * 60; } + Time.minutes = minutes; + function hours(hours) { return hours * 1000 * 60 * 60; } + Time.hours = hours; + function days(days) { return days * 1000 * 60 * 60 * 24; } + Time.days = days; + function weeks(weeks) { return weeks * 1000 * 60 * 60 * 24 * 7; } + Time.weeks = weeks; + function months(months) { return Math.floor(months * 1000 * 60 * 60 * 24 * (365.2422 / 12)); } + Time.months = months; + function years(years) { return Math.floor(years * 1000 * 60 * 60 * 24 * 365.2422); } + Time.years = years; + function decades(decades) { return Math.floor(decades * 1000 * 60 * 60 * 24 * 365.2422 * 10); } + Time.decades = decades; + function centuries(centuries) { return Math.floor(centuries * 1000 * 60 * 60 * 24 * 365.2422 * 10 * 10); } + Time.centuries = centuries; + function millenia(millenia) { return Math.floor(millenia * 1000 * 60 * 60 * 24 * 365.2422 * 10 * 10 * 10); } + Time.millenia = millenia; + function relative(unixTimeMs, options = {}) { + let ms = unixTimeMs - Date.now(); + const locale = navigator.language || "en-NZ"; + if (!locale.startsWith("en")) + return relativeIntl(ms, locale, options); + if (Math.abs(ms) < seconds(1)) + return "now"; + const ago = ms < 0; + if (ago) + ms = Math.abs(ms); + let limit = options.components ?? Infinity; + let value = ms; + let result = !ago && options.label !== false ? "in " : ""; + value = Math.floor(ms / years(1)); + ms -= value * years(1); + if (value && limit-- > 0) + result += `${value} year${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / months(1)); + ms -= value * months(1); + if (value && limit-- > 0) + result += `${value} month${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / weeks(1)); + ms -= value * weeks(1); + if (value && limit-- > 0) + result += `${value} week${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / days(1)); + ms -= value * days(1); + if (value && limit-- > 0) + result += `${value} day${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / hours(1)); + ms -= value * hours(1); + if (value && limit-- > 0) + result += `${value} hour${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / minutes(1)); + ms -= value * minutes(1); + if (value && limit-- > 0) + result += `${value} minute${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / seconds(1)); + if (value && limit-- > 0 && (!options.secondsExclusive || !result.includes(","))) + result += `${value} second${value === 1 ? "" : "s"}`; + result = Strings_1.default.trimTextMatchingFromEnd(result, ", "); + return `${result}${ago && options.label !== false ? " ago" : ""}`; + } + Time.relative = relative; + function relativeIntl(ms, locale, options) { + const rtf = new Intl.RelativeTimeFormat(locale, options); + let value = ms; + value = Math.floor(ms / years(1)); + if (value) + return rtf.format(value, "year"); + value = Math.floor(ms / months(1)); + if (value) + return rtf.format(value, "month"); + value = Math.floor(ms / weeks(1)); + if (value) + return rtf.format(value, "week"); + value = Math.floor(ms / days(1)); + if (value) + return rtf.format(value, "day"); + value = Math.floor(ms / hours(1)); + if (value) + return rtf.format(value, "hour"); + value = Math.floor(ms / minutes(1)); + if (value) + return rtf.format(value, "minute"); + value = Math.floor(ms / seconds(1)); + return rtf.format(value, "second"); + } + function absolute(ms, options = { dateStyle: "full", timeStyle: "medium" }) { + const locale = navigator.language || "en-NZ"; + const rtf = new Intl.DateTimeFormat(locale, options); + return rtf.format(ms); + } + Time.absolute = absolute; + })(Time || (Time = {})); + Object.assign(window, { Time }); + exports.default = Time; +}); +define("endpoint/Endpoint", ["require", "exports", "utility/Env", "utility/Objects", "utility/Time"], function (require, exports, Env_1, Objects_1, Time_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Env_1 = __importDefault(Env_1); + Objects_1 = __importDefault(Objects_1); + Time_1 = __importDefault(Time_1); + function Endpoint(route, method, headers) { + let pageSize; + const endpoint = { + header(header, value) { + headers ??= {}; + headers[header] = value; + return endpoint; + }, + headers(h) { + headers = { ...headers, ...h }; + return endpoint; + }, + removeHeader(header) { + delete headers?.[header]; + return endpoint; + }, + getPageSize: () => pageSize, + setPageSize: (size) => { + pageSize = size; + return endpoint; + }, + noResponse: () => endpoint.removeHeader("Accept"), + query: query, + prep: (...parameters) => { + const endpoint = Endpoint(route, method, headers); + return Object.assign(endpoint, { + query: (...p2) => { + const newParameters = []; + const length = Math.max(parameters.length, p2.length); + for (let i = 0; i < length; i++) + newParameters.push(Objects_1.default.merge(parameters[i], p2[i])); + const ownPageSize = pageSize; + pageSize = endpoint.getPageSize(); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const result = query(...newParameters); + pageSize = ownPageSize; + return result; + }, + }); + }, + }; + return endpoint; + async function query(data) { + const body = !data?.body ? undefined : JSON.stringify(data.body); + const url = route.slice(1) + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + .replaceAll(/\{([^}]+)\}/g, (match, paramName) => data?.params?.[paramName]); + const params = new URLSearchParams(data?.query); + if (pageSize) + params.set("page_size", `${pageSize}`); + const qs = params.size ? "?" + params.toString() : ""; + let error; + const response = await fetch(`${Env_1.default.API_ORIGIN}${url}${qs}`, { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + method, + headers: { + "Content-Type": body ? "application/json" : undefined, + "Accept": "application/json", + ...headers, + }, + credentials: "include", + body, + signal: AbortSignal.timeout(Time_1.default.seconds(5)), + }).catch((e) => { + if (e.name === "AbortError") { + error = Object.assign(new Error("Request timed out"), { + code: 408, + data: null, + headers: new Headers(), + }); + return; + } + if (e.name === "TypeError" && /invalid URL|Failed to construct/.test(e.message)) + throw e; + if (e.name === "TypeError" || e.name === "NetworkError") { + error = Object.assign(new Error("Network connection failed"), { + code: 503, + data: null, + headers: new Headers(), + }); + return; + } + if (!error) + throw e; + }); + if (error || !response) // will always mean the same thing, but ts doesn't know that + return error; + const code = response.status; + if (code !== 200) { + error = Object.assign(new Error(response.statusText), { code, retry: () => query(data) }); + delete error.stack; + } + const responseHeaders = { headers: response.headers }; + if (!response.body) + return Object.assign(error ?? {}, responseHeaders); + const responseType = response.headers.get("Content-Type"); + if (responseType === "application/json") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const json = await response.json().catch(e => { + error ??= Object.assign(e instanceof Error ? e : new Error("Failed to parse JSON"), { code, retry: () => query(data) }); + delete error.stack; + }); + if (error) + return Object.assign(error, json, responseHeaders); + const paginated = json; + if (paginated.has_more) { + Object.assign(json, { + next: () => query({ + ...data, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + query: { ...data?.query, page: (data?.query?.page ?? 0) + 1 }, + }), + getPage: (page) => query({ + ...data, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + query: { ...data?.query, page }, + }), + }); + } + return Object.assign(json, responseHeaders); + } + throw new Error(`Response type ${responseType} is not supported`); + } + } + exports.default = Endpoint; +}); +define("endpoint/manifest/EndpointFormInputLengths", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_1 = __importDefault(Endpoint_1); + exports.default = (0, Endpoint_1.default)("/manifest/form/lengths", "get"); +}); +define("model/Manifest", ["require", "exports", "utility/Time"], function (require, exports, Time_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Time_2 = __importDefault(Time_2); + function Manifest(definition) { + let manifestTime; + let promise; + const result = { + manifest: undefined, + isFresh(manifest) { + return !!manifest && Date.now() - (manifestTime ?? 0) < Time_2.default.minutes(5); + }, + async getManifest(force) { + // don't re-request the tag manifest if it was requested less than 5 minutes ago + if (!force && result.isFresh(result.manifest)) + return result.manifest; + return promise ??= (async () => { + try { + const response = await definition.get(); + if (response instanceof Error) + throw response; + result.manifest = response.data; + } + catch (err) { + if (definition.orElse) + result.manifest = definition.orElse(); + else + throw err; + } + manifestTime = Date.now(); + promise = undefined; + return result.manifest; + })(); + }, + }; + return result; + } + exports.default = Manifest; +}); +define("model/FormInputLengths", ["require", "exports", "endpoint/manifest/EndpointFormInputLengths", "model/Manifest"], function (require, exports, EndpointFormInputLengths_1, Manifest_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointFormInputLengths_1 = __importDefault(EndpointFormInputLengths_1); + Manifest_1 = __importDefault(Manifest_1); + exports.default = (0, Manifest_1.default)({ + get() { + return EndpointFormInputLengths_1.default.query(); + }, + orElse() { + const empy = {}; + return new Proxy({}, { + get(target, p, receiver) { + return empy; + }, + }); + }, + }); +}); +define("endpoint/auth/EndpointAuthRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_2 = __importDefault(Endpoint_2); + exports.default = (0, Endpoint_2.default)("/auth/remove", "post") + .noResponse(); +}); +define("endpoint/session/EndpointSessionGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_3 = __importDefault(Endpoint_3); + exports.default = (0, Endpoint_3.default)("/session", "get"); +}); +define("endpoint/session/EndpointSessionReset", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_4 = __importDefault(Endpoint_4); + exports.default = (0, Endpoint_4.default)("/session/reset", "post") + .noResponse(); +}); +define("ui/component/core/ActionRow", ["require", "exports", "ui/Component"], function (require, exports, Component_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_1 = __importDefault(Component_1); + const ActionRow = Component_1.default.Builder((row) => { + row.style("action-row"); + return row + .extend(row => ({ + left: undefined, + middle: undefined, + right: undefined, + })) + .extendJIT("left", row => (0, Component_1.default)() + .style("action-row-left") + .appendTo(row)) + .extendJIT("middle", row => (0, Component_1.default)() + .style("action-row-middle") + .appendTo(row)) + .extendJIT("right", row => (0, Component_1.default)() + .style("action-row-right") + .appendTo(row)); + }); + exports.default = ActionRow; +}); +define("utility/Define", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function Define(proto, key, implementation) { + try { + Object.defineProperty(proto, key, { + configurable: true, + writable: true, + value: implementation, + }); + } + catch (err) { + } + } + (function (Define) { + function all(protos, key, implementation) { + for (const proto of protos) { + Define(proto, key, implementation); + } + } + Define.all = all; + function magic(obj, key, implementation) { + try { + Object.defineProperty(obj, key, { + configurable: true, + ...implementation, + }); + } + catch (err) { + } + } + Define.magic = magic; + function set(obj, key, value) { + try { + Object.defineProperty(obj, key, { + configurable: true, + writable: true, + value, + }); + } + catch (err) { + } + return value; + } + Define.set = set; + })(Define || (Define = {})); + exports.default = Define; +}); +define("utility/Arrays", ["require", "exports", "utility/Define"], function (require, exports, Define_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Define_1 = __importDefault(Define_1); + var Arrays; + (function (Arrays) { + Arrays.EMPTY = []; + function resolve(or) { + return Array.isArray(or) ? or : or === undefined ? [] : [or]; + } + Arrays.resolve = resolve; + function includes(array, value) { + return Array.isArray(array) ? array.includes(value) : array === value; + } + Arrays.includes = includes; + function slice(or) { + return Array.isArray(or) ? or.slice() : or === undefined ? [] : [or]; + } + Arrays.slice = slice; + /** + * Removes one instance of the given value from the given array. + * @returns `true` if removed, `false` otherwise + */ + function remove(array, ...values) { + if (!array) + return false; + let removed = false; + for (const value of values) { + const index = array.indexOf(value); + if (index === -1) + continue; + array.splice(index, 1); + removed = true; + } + return removed; + } + Arrays.remove = remove; + /** + * Adds the given value to the given array if not present. + * @returns `true` if added, `false` otherwise + */ + function add(array, value) { + if (!array) + return false; + const index = array.indexOf(value); + if (index !== -1) + return false; + array.push(value); + return true; + } + Arrays.add = add; + function tuple(...values) { + return values; + } + Arrays.tuple = tuple; + function range(start, end, step) { + if (step === 0) + throw new Error("Invalid step for range"); + const result = []; + if (end === undefined) + end = start, start = 0; + step = end < start ? -1 : 1; + for (let i = start; step > 0 ? i < end : i > end; i += step) + result.push(i); + return result; + } + Arrays.range = range; + function filterNullish(value) { + return value !== null && value !== undefined; + } + Arrays.filterNullish = filterNullish; + function filterFalsy(value) { + return !!value; + } + Arrays.filterFalsy = filterFalsy; + function mergeSorted(...arrays) { + return arrays.reduce((prev, curr) => mergeSorted2(prev, curr), []); + } + Arrays.mergeSorted = mergeSorted; + function mergeSorted2(array1, array2) { + const merged = []; + let index1 = 0; + let index2 = 0; + while (index1 < array1.length || index2 < array2.length) { + const v1 = index1 < array1.length ? array1[index1] : undefined; + const v2 = index2 < array2.length ? array2[index2] : undefined; + if (v1 === v2) { + merged.push(v1); + index1++; + index2++; + continue; + } + if (v1 === undefined && v2 !== undefined) { + merged.push(v2); + index2++; + continue; + } + if (v2 === undefined && v1 !== undefined) { + merged.push(v1); + index1++; + continue; + } + const indexOfPerson1InList2 = array2.indexOf(v1, index2); + if (indexOfPerson1InList2 === -1) { + merged.push(v1); + index1++; + } + else { + merged.push(v2); + index2++; + } + } + return merged; + } + function applyPrototypes() { + (0, Define_1.default)(Array.prototype, "findLast", function (predicate) { + if (this.length > 0) + for (let i = this.length - 1; i >= 0; i--) + if (predicate(this[i], i, this)) + return this[i]; + return undefined; + }); + (0, Define_1.default)(Array.prototype, "findLastIndex", function (predicate) { + if (this.length > 0) + for (let i = this.length - 1; i >= 0; i--) + if (predicate(this[i], i, this)) + return i; + return -1; + }); + const originalSort = Array.prototype.sort; + (0, Define_1.default)(Array.prototype, "sort", function (...sorters) { + if (this.length <= 1) + return this; + if (!sorters.length) + return originalSort.call(this); + return originalSort.call(this, (a, b) => { + for (const sorter of sorters) { + if (sorter.length === 1) { + const mapper = sorter; + const sortValue = mapper(b) - mapper(a); + if (sortValue) + return sortValue; + } + else { + const sortValue = sorter(a, b); + if (sortValue) + return sortValue; + } + } + return 0; + }); + }); + (0, Define_1.default)(Array.prototype, "collect", function (collector, ...args) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return collector?.(this, ...args); + }); + (0, Define_1.default)(Array.prototype, "splat", function (collector, ...args) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return collector?.(...this, ...args); + }); + (0, Define_1.default)(Array.prototype, "toObject", function (mapper) { + return Object.fromEntries(mapper ? this.map(mapper) : this); + }); + (0, Define_1.default)(Array.prototype, "toMap", function (mapper) { + return new Map(mapper ? this.map(mapper) : this); + }); + (0, Define_1.default)(Array.prototype, "distinct", function (mapper) { + const result = []; + const encountered = mapper ? [] : result; + for (const value of this) { + const encounterValue = mapper ? mapper(value) : value; + if (encountered.includes(encounterValue)) + continue; + if (mapper) + encountered.push(encounterValue); + result.push(value); + } + return result; + }); + (0, Define_1.default)(Array.prototype, "findMap", function (predicate, mapper) { + for (let i = 0; i < this.length; i++) + if (predicate(this[i], i, this)) + return mapper(this[i], i, this); + return undefined; + }); + (0, Define_1.default)(Array.prototype, "groupBy", function (grouper) { + const result = {}; + for (let i = 0; i < this.length; i++) + (result[String(grouper(this[i], i, this))] ??= []).push(this[i]); + return Object.entries(result); + }); + (0, Define_1.default)(Array.prototype, "filterInPlace", function (filter) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return this.splice(0, Infinity, ...this.filter(filter)); + }); + (0, Define_1.default)(Array.prototype, "mapInPlace", function (mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return this.splice(0, Infinity, ...this.map(mapper)); + }); + } + Arrays.applyPrototypes = applyPrototypes; + })(Arrays || (Arrays = {})); + exports.default = Arrays; +}); +define("utility/State", ["require", "exports", "utility/Arrays", "utility/Define"], function (require, exports, Arrays_1, Define_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_1 = __importDefault(Arrays_1); + Define_2 = __importDefault(Define_2); + const SYMBOL_UNSUBSCRIBE = Symbol("UNSUBSCRIBE"); + const SYMBOL_VALUE = Symbol("VALUE"); + const SYMBOL_SUBSCRIBERS = Symbol("SUBSCRIBERS"); + function State(defaultValue, equals) { + const result = { + isState: true, + [SYMBOL_VALUE]: defaultValue, + [SYMBOL_SUBSCRIBERS]: [], + get value() { + return result[SYMBOL_VALUE]; + }, + set value(value) { + if (result[SYMBOL_VALUE] === value || equals?.(result[SYMBOL_VALUE], value)) + return; + result[SYMBOL_VALUE] = value; + result.emit(); + }, + equals: value => result[SYMBOL_VALUE] === value || equals?.(result[SYMBOL_VALUE], value) || false, + emit: () => { + for (const subscriber of result[SYMBOL_SUBSCRIBERS]) + subscriber(result[SYMBOL_VALUE]); + return result; + }, + use: (owner, subscriber) => { + result.subscribe(owner, subscriber); + subscriber(result[SYMBOL_VALUE], true); + return () => result.unsubscribe(subscriber); + }, + subscribe: (owner, subscriber) => { + function onRemoved() { + owner.removed.unsubscribe(onRemoved); + result.unsubscribe(subscriber); + fn[SYMBOL_UNSUBSCRIBE]?.delete(onRemoved); + } + const fn = subscriber; + fn[SYMBOL_UNSUBSCRIBE] ??= new Set(); + fn[SYMBOL_UNSUBSCRIBE].add(onRemoved); + owner.removed.subscribeManual(onRemoved); + result.subscribeManual(subscriber); + return () => { + result.unsubscribe(subscriber); + owner.removed.unsubscribe(onRemoved); + }; + }, + subscribeManual: subscriber => { + result[SYMBOL_SUBSCRIBERS].push(subscriber); + return () => result.unsubscribe(subscriber); + }, + unsubscribe: subscriber => { + result[SYMBOL_SUBSCRIBERS] = result[SYMBOL_SUBSCRIBERS].filter(s => s !== subscriber); + return result; + }, + await(owner, values, then) { + result.subscribe(owner, function awaitValue(newValue) { + if (newValue !== values && (!Array.isArray(values) || !values.includes(newValue))) + return; + result.unsubscribe(awaitValue); + then(newValue); + }); + return result; + }, + awaitManual(values, then) { + result.subscribeManual(function awaitValue(newValue) { + if (newValue !== values && (!Array.isArray(values) || !values.includes(newValue))) + return; + result.unsubscribe(awaitValue); + then(newValue); + }); + return result; + }, + map: (owner, mapper) => State.Map(owner, [result], mapper), + mapManual: mapper => State.MapManual([result], mapper), + get nonNullish() { + return Define_2.default.set(result, "nonNullish", State + .Generator(() => result.value !== undefined && result.value !== null) + .observeManual(result)); + }, + get truthy() { + return Define_2.default.set(result, "truthy", State + .Generator(() => !!result.value) + .observeManual(result)); + }, + get not() { + return getNot(); + }, + get falsy() { + return getNot(); + }, + }; + return result; + function getNot() { + const not = State + .Generator(() => !result.value) + .observeManual(result); + Define_2.default.set(result, "not", not); + Define_2.default.set(result, "falsy", not); + return not; + } + } + (function (State) { + function is(value) { + return typeof value === "object" && value?.isState === true; + } + State.is = is; + function get(value) { + return is(value) ? value : State(value); + } + State.get = get; + function Generator(generate) { + const result = State(generate()); + Define_2.default.magic(result, "value", { + get: () => result[SYMBOL_VALUE], + }); + result.refresh = () => { + const value = generate(); + if (result.equals(value)) + return result; + result[SYMBOL_VALUE] = value; + result.emit(); + return result; + }; + result.observe = (owner, ...states) => { + for (const state of states) + state?.subscribeManual(result.refresh); + owner.event.subscribe("remove", onRemove); + return result; + function onRemove() { + owner.event.unsubscribe("remove", onRemove); + for (const state of states) + state?.unsubscribe(result.refresh); + } + }; + result.observeManual = (...states) => { + for (const state of states) + state?.subscribeManual(result.refresh); + return result; + }; + result.unobserve = (...states) => { + for (const state of states) + state?.unsubscribe(result.refresh); + return result; + }; + return result; + } + State.Generator = Generator; + function JIT(generate) { + const result = State(undefined); + let isCached = false; + let cached; + Define_2.default.magic(result, "value", { + get: () => { + if (!isCached) { + isCached = true; + cached = generate(); + } + return cached; + }, + }); + result.emit = () => { + for (const subscriber of result[SYMBOL_SUBSCRIBERS]) + subscriber(undefined); + return result; + }; + result.markDirty = () => { + isCached = false; + cached = undefined; + result.emit(); + return result; + }; + result.observe = (...states) => { + for (const state of states) + state.subscribeManual(result.markDirty); + return result; + }; + result.unobserve = (...states) => { + for (const state of states) + state.unsubscribe(result.markDirty); + return result; + }; + return result; + } + State.JIT = JIT; + function Truthy(owner, state) { + return Generator(() => !!state.value) + .observe(owner, state); + } + State.Truthy = Truthy; + function NonNullish(owner, state) { + return Generator(() => state.value !== undefined && state.value !== null) + .observe(owner, state); + } + State.NonNullish = NonNullish; + function Falsy(owner, state) { + return Generator(() => !!state.value) + .observe(owner, state); + } + State.Falsy = Falsy; + function Some(owner, ...anyOfStates) { + return Generator(() => anyOfStates.some(state => state.value)) + .observe(owner, ...anyOfStates); + } + State.Some = Some; + function Every(owner, ...anyOfStates) { + return Generator(() => anyOfStates.every(state => state.value)) + .observe(owner, ...anyOfStates); + } + State.Every = Every; + function Map(owner, inputs, outputGenerator) { + return Generator(() => outputGenerator(...inputs.map(input => input?.value))) + .observe(owner, ...inputs.filter(Arrays_1.default.filterNullish)); + } + State.Map = Map; + function MapManual(inputs, outputGenerator) { + return Generator(() => outputGenerator(...inputs.map(input => input?.value))) + .observeManual(...inputs.filter(Arrays_1.default.filterNullish)); + } + State.MapManual = MapManual; + })(State || (State = {})); + exports.default = State; +}); +define("ui/utility/StyleManipulator", ["require", "exports", "style"], function (require, exports, style_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + style_1 = __importDefault(style_1); + function StyleManipulator(component) { + const styles = new Set(); + const stateUnsubscribers = new WeakMap(); + const unbindPropertyState = {}; + const result = Object.assign(((...names) => { + for (const name of names) + styles.add(name); + updateClasses(); + return component; + }), { + get: () => [...styles].sort(), + remove(...names) { + for (const name of names) + styles.delete(name); + updateClasses(names); + return component; + }, + toggle(enabled, ...names) { + if (enabled) + for (const name of names) + styles.add(name); + else + for (const name of names) + styles.delete(name); + updateClasses(!enabled ? names : undefined); + return component; + }, + bind(state, ...names) { + result.unbind(state); + const unsubscribe = state.use(component, active => { + if (active) + for (const name of names) + styles.add(name); + else + for (const name of names) + styles.delete(name); + updateClasses(!active ? names : undefined); + }); + stateUnsubscribers.set(state, [unsubscribe, names]); + return component; + }, + unbind(state) { + const bound = state && stateUnsubscribers.get(state); + if (!bound) + return component; + const [unsubscribe, names] = bound; + unsubscribe?.(); + stateUnsubscribers.delete(state); + result.remove(...names); + return component; + }, + refresh: () => updateClasses(), + hasProperty(property) { + return component.element.style.getPropertyValue(property) !== ""; + }, + setProperty(property, value) { + unbindPropertyState[property]?.(); + setProperty(property, value); + return component; + }, + toggleProperty(enabled, property, value) { + enabled ??= !result.hasProperty(property); + if (enabled === true) + return result.setProperty(property, enabled ? value : undefined); + else + return result.removeProperties(property); + }, + setVariable(variable, value) { + return result.setProperty(`--${variable}`, value); + }, + bindProperty(property, state) { + unbindPropertyState[property]?.(); + unbindPropertyState[property] = state.use(component, value => setProperty(property, value)); + return component; + }, + bindVariable(variable, state) { + return result.bindProperty(`--${variable}`, state); + }, + removeProperties(...properties) { + for (const property of properties) + component.element.style.removeProperty(property); + return component; + }, + removeVariables(...variables) { + for (const variable of variables) + component.element.style.removeProperty(`--${variable}`); + return component; + }, + }); + return result; + function updateClasses(deletedStyles) { + const toAdd = [...styles].flatMap(component => style_1.default[component]); + const toRemove = deletedStyles?.flatMap(component => style_1.default[component]).filter(cls => !toAdd.includes(cls)); + if (toRemove) + component.element.classList.remove(...toRemove); + component.element.classList.add(...toAdd); + return component; + } + function setProperty(property, value) { + if (value === undefined || value === null) + component.element.style.removeProperty(property); + else + component.element.style.setProperty(property, `${value}`); + } + } + exports.default = StyleManipulator; +}); +define("ui/component/core/Button", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_2, State_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_2 = __importDefault(Component_2); + State_1 = __importDefault(State_1); + const Button = Component_2.default.Builder("button", (button) => { + const disabledReasons = new Set(); + const disabled = State_1.default.Generator(() => !!disabledReasons.size); + let icon; + const unuseDisabledStateMap = new WeakMap(); + return button + .attributes.set("type", "button") + .style("button") + .style.bind(disabled, "button--disabled") + .attributes.bind(disabled, "disabled") + .extend(button => ({ + textWrapper: undefined, + disabled, + type: Object.assign((...types) => { + for (const type of types) + button.style(`button-type-${type}`); + return button; + }, { + remove(...types) { + for (const type of types) + button.style.remove(`button-type-${type}`); + return button; + }, + }), + setDisabled(newState, reason) { + const size = disabledReasons.size; + if (newState) + disabledReasons.add(reason); + else + disabledReasons.delete(reason); + if (disabledReasons.size !== size) + disabled.refresh(); + return button; + }, + bindDisabled(state, reason) { + unuseDisabledStateMap.get(state)?.(); + unuseDisabledStateMap.set(state, state.subscribe(button, newState => button.setDisabled(newState, reason))); + return button; + }, + unbindDisabled(state, reason) { + unuseDisabledStateMap.get(state)?.(); + unuseDisabledStateMap.delete(state); + return button; + }, + setIcon(newIcon) { + if (icon) + button.style.remove(`button-icon-${icon}`); + icon = newIcon; + if (icon) + button.style(`button-icon-${icon}`); + return button; + }, + })) + .extendJIT("textWrapper", button => (0, Component_2.default)() + .style("button-text") + .appendTo(button)); + }); + exports.default = Button; +}); +define("utility/EventManager", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.EventManager = void 0; + class EventManager { + static global = EventManager.make(); + static make() { + return new EventManager({}); + } + static emit(target, event, init) { + if (init instanceof Event) + event = init; + if (typeof event === "string") + event = new Event(event, { cancelable: true }); + if (typeof init === "function") + init?.(event); + else if (init && event !== init) + Object.assign(event, init); + target?.dispatchEvent(event); + return event; + } + host; + _target; + get target() { + return this._target instanceof WeakRef ? this._target.deref() : this._target; + } + constructor(host, target = new EventTarget()) { + this.host = new WeakRef(host); + this._target = target; + } + subscribe(type, listener) { + if (!Array.isArray(type)) + type = [type]; + for (const t of type) + this.target?.addEventListener(t, listener); + return this.host.deref(); + } + subscriptions = {}; + subscribeOnce(types, listener) { + if (!Array.isArray(types)) + types = [types]; + if (this.target) { + const target = this.target; + const subscriptions = this.subscriptions; + function realListener(event) { + listener.call(this, event); + for (const type of types) { + subscriptions[type]?.delete(listener); + target?.removeEventListener(type, realListener); + } + } + for (const type of types) { + subscriptions[type] ??= new WeakMap(); + subscriptions[type].set(listener, realListener); + this.target?.addEventListener(type, realListener); + } + } + return this.host.deref(); + } + unsubscribe(types, listener) { + if (!Array.isArray(types)) + types = [types]; + for (const type of types) { + this.target?.removeEventListener(type, listener); + const realListener = this.subscriptions[type]?.get(listener); + if (realListener) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + this.target?.removeEventListener(type, realListener); + this.subscriptions[type].delete(listener); + } + } + return this.host.deref(); + } + async waitFor(types) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return new Promise(resolve => this.subscribeOnce(types, resolve)); + } + until(promise, initialiser) { + if (typeof promise !== "object") + promise = this.waitFor(promise); + const manager = { + subscribe: (type, listener) => { + this.subscribe(type, listener); + void (promise).then(() => this.unsubscribe(type, listener)); + return manager; + }, + subscribeOnce: (type, listener) => { + this.subscribeOnce(type, listener); + void (promise).then(() => this.unsubscribe(type, listener)); + return manager; + }, + }; + initialiser?.(manager); + return this.host.deref(); + } + emit(event, init) { + event = EventManager.emit(this.target, event, init); + // const pipeTargets = this.pipeTargets.get(event.type) + // if (pipeTargets) { + // for (let i = 0; i < pipeTargets.length; i++) { + // const pipeTarget = pipeTargets[i].deref() + // if (pipeTarget) + // pipeTarget.dispatchEvent(event) + // else + // pipeTargets.splice(i--, 1) + // } + // if (!pipeTargets.length) + // this.pipeTargets.delete(event.type) + // } + return this.host.deref(); + } + } + exports.EventManager = EventManager; +}); +define("ui/InputBus", ["require", "exports", "ui/Component", "utility/EventManager"], function (require, exports, Component_3, EventManager_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_3 = __importDefault(Component_3); + var Classes; + (function (Classes) { + Classes["ReceiveFocusedClickEvents"] = "_receieve-focused-click-events"; + })(Classes || (Classes = {})); + Component_3.default.extend(component => { + component.extend(component => ({ + receiveFocusedClickEvents: () => component.classes.add(Classes.ReceiveFocusedClickEvents), + })); + }); + const MOUSE_KEYNAME_MAP = { + [0]: "MouseLeft", + [1]: "MouseMiddle", + [2]: "MouseRight", + [3]: "Mouse3", + [4]: "Mouse4", + [5]: "Mouse5", + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + [`${undefined}`]: "Mouse?", + }; + let lastUsed = 0; + const inputDownTime = {}; + const InputBus = Object.assign(EventManager_1.EventManager.make(), { + getPressStart: (name) => inputDownTime[name], + getPressDuration: (name) => inputDownTime[name] === undefined ? undefined : Date.now() - inputDownTime[name], + isDown: (name) => !!inputDownTime[name], + isUp: (name) => !inputDownTime[name], + }); + function emitKeyEvent(e) { + const target = e.target; + const input = target.closest("input[type=text], textarea, [contenteditable]"); + let usedByInput = !!input; + const isClick = true + && !usedByInput + && e.type === "keydown" + && (e.key === "Enter" || e.key === "Space") + && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey + && target.classList.contains(Classes.ReceiveFocusedClickEvents); + if (isClick) { + const result = target.component?.event.emit("click"); + if (result?.defaultPrevented) { + e.preventDefault(); + return; + } + } + const eventKey = e.key ?? MOUSE_KEYNAME_MAP[e.button]; + const eventType = e.type === "mousedown" ? "keydown" : e.type === "mouseup" ? "keyup" : e.type; + if (eventType === "keydown") + inputDownTime[eventKey] = Date.now(); + let cancelInput = false; + const event = { + key: eventKey, + ctrl: e.ctrlKey, + shift: e.shiftKey, + alt: e.altKey, + used: usedByInput, + input, + use: (key, ...modifiers) => { + if (event.used) + return false; + const matches = event.matches(key, ...modifiers); + if (matches) + event.used = true; + return matches; + }, + useOverInput: (key, ...modifiers) => { + if (event.used && !usedByInput) + return false; + const matches = event.matches(key, ...modifiers); + if (matches) { + event.used = true; + usedByInput = false; + } + return matches; + }, + matches: (key, ...modifiers) => { + if (eventKey !== key) + return false; + if (!modifiers.every(modifier => event[modifier])) + return false; + return true; + }, + cancelInput: () => cancelInput = true, + hovering: (selector) => { + const hovered = [...document.querySelectorAll(":hover")]; + return selector ? hovered[hovered.length - 1]?.closest(selector) ?? undefined : hovered[hovered.length - 1]; + }, + }; + if (eventType === "keyup") { + event.usedAnotherKeyDuring = lastUsed > (inputDownTime[eventKey] ?? 0); + delete inputDownTime[eventKey]; + } + InputBus.emit(eventType === "keydown" ? "down" : "up", event); + if ((event.used && !usedByInput) || (usedByInput && cancelInput)) { + e.preventDefault(); + lastUsed = Date.now(); + } + if (usedByInput) { + if (e.type === "keydown" && eventKey === "Enter" && !event.shift && !event.alt) { + const form = target.closest("form"); + if (form && (target.tagName.toLowerCase() === "input" || target.closest("[contenteditable]")) && !event.ctrl) { + e.preventDefault(); + } + else { + form?.requestSubmit(); + } + } + } + } + document.addEventListener("keydown", emitKeyEvent); + document.addEventListener("keyup", emitKeyEvent); + document.addEventListener("mousedown", emitKeyEvent); + document.addEventListener("mouseup", emitKeyEvent); + document.addEventListener("click", emitKeyEvent); + Object.defineProperty(MouseEvent.prototype, "used", { + get() { + return this._used ?? false; + }, + }); + Object.defineProperty(MouseEvent.prototype, "use", { + value: function (key, ...modifiers) { + if (this._used) + return false; + const matches = this.matches(key, ...modifiers); + if (matches) { + this._used = true; + // allow click & contextmenu handlers to be considered "used" for IKeyUpEvents + lastUsed = Date.now(); + } + return matches; + }, + }); + Object.defineProperty(MouseEvent.prototype, "matches", { + value: function (key, ...modifiers) { + if (MOUSE_KEYNAME_MAP[this.button] !== key) + return false; + if (!modifiers.every(modifier => this[`${modifier}Key`])) + return false; + return true; + }, + }); + exports.default = InputBus; +}); +define("ui/utility/FocusListener", ["require", "exports", "utility/State"], function (require, exports, State_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_2 = __importDefault(State_2); + var FocusListener; + (function (FocusListener) { + FocusListener.hasFocus = (0, State_2.default)(false); + FocusListener.focused = (0, State_2.default)(undefined); + function focusedComponent() { + return FocusListener.focused.value?.component; + } + FocusListener.focusedComponent = focusedComponent; + // interface QueuedFocusChange { + // type: "focus" | "blur" + // element: HTMLElement + // } + // let updatingFocusState = false + // let cursor = 0 + // const queue: QueuedFocusChange[] = [] + function focus(element) { + // if (updatingFocusState || exhaustingQueue) { + // queue.splice(cursor, 0, { type: "focus", element }) + // cursor++ + // return + // } + focusInternal(element); + } + FocusListener.focus = focus; + function focusInternal(element) { + if (document.querySelector(":focus-visible") === element) + return; + element.focus(); + } + function blur(element) { + // if (updatingFocusState || exhaustingQueue) { + // queue.splice(cursor, 0, { type: "blur", element }) + // cursor++ + // return + // } + blurInternal(element); + } + FocusListener.blur = blur; + function blurInternal(element) { + if (document.querySelector(":focus-visible") !== element) + return; + element.blur(); + } + function listen() { + document.addEventListener("focusin", onFocusIn); + document.addEventListener("focusout", onFocusOut); + } + FocusListener.listen = listen; + function onFocusIn() { + updateFocusState(); + } + function onFocusOut(event) { + if (event.relatedTarget === null) + updateFocusState(); + } + // let exhaustingQueue = false + function updateFocusState() { + if (document.activeElement && document.activeElement !== document.body && location.hash && document.activeElement.id !== location.hash.slice(1)) + history.pushState(undefined, "", " "); + const newFocused = document.querySelector(":focus-visible") ?? undefined; + if (newFocused === FocusListener.focused.value) + return; + // updatingFocusState = true + const lastFocusedComponent = FocusListener.focused.value?.component; + const focusedComponent = newFocused?.component; + const oldAncestors = !lastFocusedComponent ? undefined : [...lastFocusedComponent.getAncestorComponents()]; + const newAncestors = !focusedComponent ? undefined : [...focusedComponent.getAncestorComponents()]; + const lastFocusedContainsFocused = FocusListener.focused.value?.contains(newFocused ?? null); + FocusListener.focused.value = newFocused; + FocusListener.hasFocus.value = !!newFocused; + if (lastFocusedComponent) { + lastFocusedComponent.focused.value = false; + if (!lastFocusedContainsFocused) + lastFocusedComponent.hasFocused.value = false; + } + if (focusedComponent) { + focusedComponent.focused.value = true; + focusedComponent.hasFocused.value = true; + } + if (oldAncestors) + for (const ancestor of oldAncestors) + if (!newAncestors?.includes(ancestor)) + if (ancestor) + ancestor.hasFocused.value = false; + if (newAncestors) + for (const ancestor of newAncestors) + if (ancestor) + ancestor.hasFocused.value = true; + // updatingFocusState = false + // if (exhaustingQueue) + // return + // exhaustingQueue = true + // for (cursor = 0; cursor < queue.length; cursor++) { + // const change = queue[cursor] + // if (change.type === "blur") + // blurInternal(change.element) + // else if (change.type === "focus") + // focusInternal(change.element) + // } + // queue.splice(0, Infinity) + // cursor = 0 + // exhaustingQueue = false + } + })(FocusListener || (FocusListener = {})); + exports.default = FocusListener; + Object.assign(window, { FocusListener }); +}); +define("utility/maths/Vector2", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Vector2; + (function (Vector2) { + function ZERO() { + return { x: 0, y: 0 }; + } + Vector2.ZERO = ZERO; + function distance(v1, v2) { + return Math.sqrt((v2.x - v1.x) ** 2 + (v2.y - v1.y) ** 2); + } + Vector2.distance = distance; + function distanceWithin(v1, v2, within) { + return (v2.x - v1.x) ** 2 + (v2.y - v1.y) ** 2 < within ** 2; + } + Vector2.distanceWithin = distanceWithin; + })(Vector2 || (Vector2 = {})); + exports.default = Vector2; +}); +define("ui/utility/Mouse", ["require", "exports", "utility/State"], function (require, exports, State_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_3 = __importDefault(State_3); + var Mouse; + (function (Mouse) { + const pos = { x: 0, y: 0 }; + Mouse.state = (0, State_3.default)(pos); + const handlers = new Set(); + function onMove(handler) { + handlers.add(handler); + } + Mouse.onMove = onMove; + function offMove(handler) { + handlers.delete(handler); + } + Mouse.offMove = offMove; + function listen() { + document.addEventListener("mousemove", event => { + if (pos.x === event.clientX && pos.y === event.clientY) + return; + pos.x = event.clientX; + pos.y = event.clientY; + Mouse.state.emit(); + for (const handler of handlers) + handler(pos); + }); + } + Mouse.listen = listen; + })(Mouse || (Mouse = {})); + exports.default = Mouse; +}); +define("ui/utility/HoverListener", ["require", "exports", "ui/utility/Mouse"], function (require, exports, Mouse_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Mouse_1 = __importDefault(Mouse_1); + var HoverListener; + (function (HoverListener) { + let lastHovered = []; + function allHovered() { + return lastHovered; + } + HoverListener.allHovered = allHovered; + function hovered() { + return lastHovered.at(-1); + } + HoverListener.hovered = hovered; + function* allHoveredComponents() { + for (const element of lastHovered) { + const component = element.component; + if (component) + yield component; + } + } + HoverListener.allHoveredComponents = allHoveredComponents; + function hoveredComponent() { + return lastHovered.at(-1)?.component; + } + HoverListener.hoveredComponent = hoveredComponent; + function listen() { + Mouse_1.default.onMove(() => { + const allHovered = document.querySelectorAll(":hover"); + const hovered = allHovered[allHovered.length - 1]; + if (hovered === lastHovered[lastHovered.length - 1]) + return; + const newHovered = [...allHovered]; + for (const element of lastHovered) + if (element.component && !newHovered.includes(element)) + element.component.hovered.value = false; + for (const element of newHovered) + if (element.component && !lastHovered.includes(element)) + element.component.hovered.value = true; + lastHovered = newHovered; + }); + } + HoverListener.listen = listen; + })(HoverListener || (HoverListener = {})); + exports.default = HoverListener; + Object.assign(window, { HoverListener }); +}); +define("utility/Async", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Async; + (function (Async) { + async function sleep(ms, signal) { + // let stack = new Error().stack; + // stack = stack?.slice(stack.indexOf("\n") + 1); + // stack = stack?.slice(stack.indexOf("\n") + 1); + // stack = stack?.slice(0, stack.indexOf("\n")); + // console.log("sleep", stack); + if (!signal) { + return new Promise(resolve => { + window.setTimeout(() => resolve(undefined), ms); + }); + } + if (signal.aborted) { + return true; + } + return new Promise(resolve => { + // eslint-disable-next-line prefer-const + let timeoutId; + const onAbort = () => { + window.clearTimeout(timeoutId); + resolve(true); + }; + timeoutId = window.setTimeout(() => { + signal.removeEventListener("abort", onAbort); + resolve(false); + }, ms); + signal.addEventListener("abort", onAbort, { once: true }); + }); + } + Async.sleep = sleep; + function debounce(...args) { + let ms; + let callback; + if (typeof args[0] === "function") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [callback, ...args] = args; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return debounceByPromise(callback, ...args); + } + else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, callback, ...args] = args; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return debounceByTime(ms, callback, ...args); + } + } + Async.debounce = debounce; + const debouncedByTime = new WeakMap(); + function debounceByTime(ms, callback, ...args) { + let info = debouncedByTime.get(callback); + if (info && Date.now() - info.last < ms) { + const callbackRef = new WeakRef(callback); + callback = undefined; + const newAbortController = new AbortController(); + info.queued = sleep(Date.now() - info.last + ms, newAbortController.signal).then(aborted => { + if (aborted) { + return info?.queued; + } + delete info.queued; + delete info.abortController; + info.last = Date.now(); + return callbackRef.deref()?.(...args); + }); + info.abortController?.abort(); + info.abortController = newAbortController; + return info.queued; + } + if (!info) { + debouncedByTime.set(callback, info = { last: 0 }); + } + info.last = Date.now(); + return callback(...args); + } + const debouncedByPromise = new WeakMap(); + function debounceByPromise(callback, ...args) { + const debounceInfo = debouncedByPromise.get(callback); + if (debounceInfo?.nextQueued) { + return debounceInfo.promise; + } + const callbackRef = new WeakRef(callback); + callback = undefined; + const realCallback = () => { + try { + const callback = callbackRef.deref(); + if (!callback) { + return; + } + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const result = callback(...args); + const promise = Promise.resolve(result); + debouncedByPromise.set(callback, { + promise, + nextQueued: false, + }); + callback = undefined; + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + return promise; + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + return; + } + }; + if (debounceInfo) { + debounceInfo.nextQueued = true; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + return debounceInfo.promise.catch(realCallback).then(realCallback); + } + else { + return realCallback(); + } + } + function schedule(...args) { + let ms = 0; + let callback; + let debounceMs = false; + let signal; + if (typeof args[0] === "function") { + // (cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [callback, ...args] = args; + } + else if (typeof args[1] === "function") { + // (ms, cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, callback, ...args] = args; + } + else if (typeof args[2] === "function") { + // (ms, debounce | signal, cb, ...args) + if (typeof args[1] === "object") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, signal, callback, ...args] = args; + } + else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, debounceMs, callback, ...args] = args; + } + } + else { + // (ms, debounce, signal, cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, debounceMs, signal, callback, ...args] = args; + } + if (debounceMs === true) { + debounceMs = ms; + } + const cancelCallbacks = []; + // eslint-disable-next-line prefer-const + let timeoutId; + const result = { + cancelled: false, + completed: false, + cancel: () => { + if (result.cancelled || result.completed) { + return; + } + signal?.removeEventListener("abort", result.cancel); + result.cancelled = true; + window.clearTimeout(timeoutId); + for (const callback of cancelCallbacks) { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + } + cancelCallbacks.length = 0; + args.length = 0; + }, + onCancel: callback => { + if (result.completed) { + return result; + } + if (result.cancelled) { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + } + else { + cancelCallbacks.push(callback); + } + return result; + }, + }; + signal?.addEventListener("abort", result.cancel, { once: true }); + timeoutId = window.setTimeout(() => { + if (result.cancelled) { + return; + } + signal?.removeEventListener("abort", result.cancel); + result.completed = true; + cancelCallbacks.length = 0; + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = debounceMs ? debounce(debounceMs, callback, ...args) : callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + }, ms); + return result; + } + Async.schedule = schedule; + /** + * Create an AbortSignal that will be emitted after `ms`. + * @param ms The time until the signal will be emitted. + * @param controller An optional existing `AbortController`. + * @param message An optional custom timeout message. + */ + function timeout(ms, controller = new AbortController(), message = `Timed out after ${ms} ms`) { + schedule(ms, () => controller.abort(message)); + return controller.signal; + } + Async.timeout = timeout; + })(Async || (Async = {})); + exports.default = Async; +}); +define("utility/Task", ["require", "exports", "utility/Async", "utility/Time"], function (require, exports, Async_1, Time_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Async_1 = __importDefault(Async_1); + Time_3 = __importDefault(Time_3); + const DEFAULT_INTERVAL = Time_3.default.seconds(1) / 144; + class Task { + interval; + static async yield(instantIfUnsupported = false) { + if (typeof scheduler !== "undefined" && typeof scheduler.yield === "function") + return scheduler.yield(); + if (!instantIfUnsupported) + await Async_1.default.sleep(1); + } + static post(callback, priority) { + if (typeof scheduler === "undefined" || typeof scheduler.postTask !== "function") + return callback(); + return scheduler.postTask(callback, { priority }); + } + lastYieldEnd = Date.now(); + constructor(interval = DEFAULT_INTERVAL) { + this.interval = interval; + } + reset() { + this.lastYieldEnd = Date.now(); + } + async yield(instantIfUnsupported = false) { + if (Date.now() - this.lastYieldEnd > this.interval) { + await Task.yield(instantIfUnsupported); + this.lastYieldEnd = Date.now(); + } + } + } + exports.default = Task; +}); +define("ui/component/core/Popover", ["require", "exports", "ui/Component", "ui/InputBus", "ui/utility/FocusListener", "ui/utility/HoverListener", "ui/utility/Mouse", "utility/State", "utility/Task"], function (require, exports, Component_4, InputBus_1, FocusListener_1, HoverListener_1, Mouse_2, State_4, Task_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_4 = __importDefault(Component_4); + InputBus_1 = __importDefault(InputBus_1); + FocusListener_1 = __importDefault(FocusListener_1); + HoverListener_1 = __importDefault(HoverListener_1); + Mouse_2 = __importDefault(Mouse_2); + State_4 = __importDefault(State_4); + Task_1 = __importDefault(Task_1); + const FOCUS_TRAP = (0, Component_4.default)() + .tabIndex("auto") + .ariaHidden() + .style.setProperty("display", "none") + .prependTo(document.body); + Component_4.default.extend(component => { + component.extend((component) => ({ + clearPopover: () => component + .attributes.set("data-clear-popover", "true"), + setPopover: (popoverEvent, initialiser) => { + if (component.popover) + component.popover.remove(); + let isShown = false; + const popover = Popover() + .anchor.from(component) + .setOwner(component) + .tweak(initialiser, component) + .event.subscribe("toggle", e => { + const event = e; + if (event.newState === "closed") { + isShown = false; + component.clickState = false; + Mouse_2.default.offMove(updatePopoverState); + } + }) + .appendTo(document.body); + if (popoverEvent === "hover" && !component.popover) + component.hoveredOrFocused.subscribe(component, updatePopoverState); + const ariaLabel = component.attributes.getUsing("aria-label") ?? popover.attributes.get("aria-label"); + const ariaRole = popover.attributes.getUsing("role") ?? popover.attributes.get("role"); + component.ariaLabel.use((quilt, { arg }) => quilt["component/popover/button"](arg(ariaLabel), arg(ariaRole))); + popover.ariaLabel.use((quilt, { arg }) => quilt["component/popover"](arg(ariaLabel))); + component.clickState = false; + if (!component.popover) { + component.event.subscribe("click", async (event) => { + // always subscribe click because we need to handle it for keyboard navigation + if (!component.focused.value && popoverEvent !== "click") + return; + event.stopPropagation(); + event.preventDefault(); + component.clickState = true; + component.popover?.show(); + component.popover?.focus(); + component.popover?.style.removeProperties("left", "top"); + await Task_1.default.yield(); + component.popover?.anchor.apply(); + }); + component.receiveAncestorInsertEvents(); + component.event.subscribe(["insert", "ancestorInsert"], updatePopoverParent); + } + popover.popoverHasFocus.subscribe(component, hasFocused => { + if (hasFocused) + return; + component.clickState = false; + component.popover?.hide(); + component.focus(); + }); + return component.extend(component => ({ + popover, + popoverDescendants: [], + tweakPopover: initialiser => { + initialiser(component.popover, component); + return component; + }, + })); + function updatePopoverParent() { + if (!component.popover) + return; + const oldParent = component.popover.popoverParent.value; + component.popover.popoverParent.value = component.closest(Popover); + if (oldParent && oldParent !== component.popover.popoverParent.value) + oldParent.popoverChildren.value = oldParent.popoverChildren.value.filter(c => c !== component.popover); + if (component.popover.popoverParent.value && component.popover.popoverParent.value !== oldParent) + component.popover.popoverParent.value.popoverChildren.value = [...component.popover.popoverParent.value.popoverChildren.value, component.popover]; + } + async function updatePopoverState() { + if (!component.popover) + return; + const shouldShow = false + || component.hoveredOrFocused.value + || (true + && isShown + && (false + || (component.popover.isMouseWithin(true) && !shouldClearPopover()) + || InputBus_1.default.isDown("F4"))) + || !!component.clickState; + if (isShown === shouldShow) + return; + if (component.hoveredOrFocused.value && !isShown) + Mouse_2.default.onMove(updatePopoverState); + if (!shouldShow) + Mouse_2.default.offMove(updatePopoverState); + if (!shouldShow) + FOCUS_TRAP.style.setProperty("display", "none"); + isShown = shouldShow; + component.popover.toggle(shouldShow); + if (!shouldShow) + return; + FOCUS_TRAP.style.setProperty("display", "inline"); + component.popover.style.removeProperties("left", "top"); + await Task_1.default.yield(); + component.popover.anchor.apply(); + } + function shouldClearPopover() { + if (!component.popover) + return false; + const hovered = HoverListener_1.default.hovered() ?? null; + if (component.element.contains(hovered) || component.popover.element.contains(hovered)) + return false; + const clearsPopover = hovered?.closest("[data-clear-popover]"); + if (!clearsPopover) + return false; + const clearsPopoverWithinPopover = clearsPopover.component?.closest(Popover); + if (component.popover.containsPopoverDescendant(clearsPopoverWithinPopover)) + return false; + return true; + } + }, + })); + }); + const Popover = Component_4.default.Builder((component) => { + let mousePadding; + let unbind; + const visible = (0, State_4.default)(false); + let shouldCloseOnInput = true; + let normalStacking = false; + const popover = component + .style("popover") + .tabIndex("programmatic") + .attributes.set("popover", "manual") + .extend(popover => ({ + visible, + popoverChildren: (0, State_4.default)([]), + popoverParent: (0, State_4.default)(undefined), + popoverHasFocus: FocusListener_1.default.focused.map(popover, focused => visible.value && containsPopoverDescendant(focused)), + setCloseOnInput(closeOnInput = true) { + shouldCloseOnInput = closeOnInput; + return popover; + }, + setMousePadding: padding => { + mousePadding = padding; + return popover; + }, + setNormalStacking() { + popover.style("popover--normal-stacking"); + popover.attributes.remove("popover"); + normalStacking = true; + togglePopover(visible.value); + return popover; + }, + isMouseWithin: (checkDescendants = false) => { + if (popover.rect.value.expand(mousePadding ?? 100).intersects(Mouse_2.default.state.value)) + return true; + if (checkDescendants) + for (const child of popover.popoverChildren.value) + if (child.isMouseWithin(true)) + return true; + return false; + }, + containsPopoverDescendant, + show: () => { + unbind?.(); + togglePopover(true); + popover.visible.value = true; + return popover; + }, + hide: () => { + unbind?.(); + togglePopover(false); + popover.visible.value = false; + return popover; + }, + toggle: shown => { + unbind?.(); + togglePopover(shown); + popover.visible.value = shown ?? !popover.visible.value; + return popover; + }, + bind: state => { + unbind?.(); + unbind = state.use(popover, shown => { + togglePopover(shown); + popover.visible.value = shown; + }); + return popover; + }, + unbind: () => { + unbind?.(); + return popover; + }, + })); + popover.event.subscribe("toggle", event => { + popover.visible.value = event.newState === "open"; + }); + popover.onRooted(() => { + InputBus_1.default.subscribe("down", onInputDown); + component.event.subscribe("remove", () => InputBus_1.default.unsubscribe("down", onInputDown)); + }); + return popover; + function togglePopover(shown) { + if (normalStacking) + popover.style.toggle(!shown, "popover--normal-stacking--hidden"); + else + popover.element.togglePopover(shown); + } + function onInputDown(event) { + if (!popover.visible.value || !shouldCloseOnInput) + return; + if (!event.key.startsWith("Mouse") || popover.containsPopoverDescendant(HoverListener_1.default.hovered())) + return; + popover.element.togglePopover(false); + popover.visible.value = false; + } + function containsPopoverDescendant(descendant) { + if (!descendant) + return false; + const node = Component_4.default.is(descendant) ? descendant.element : descendant; + if (popover.element.contains(node)) + return true; + for (const child of popover.popoverChildren.value) + if (child === descendant) + return true; + else if (child.containsPopoverDescendant(descendant)) + return true; + return false; + } + }); + exports.default = Popover; +}); +define("ui/component/core/ext/CanHasActionsMenuButton", ["require", "exports", "ui/Component", "ui/component/core/Button"], function (require, exports, Component_5, Button_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_5 = __importDefault(Component_5); + Button_1 = __importDefault(Button_1); + const CanHasActionsMenuButton = Component_5.default.Extension((component, inserter) => { + let actionsMenuPopoverInitialiser = () => { }; + return component + .extend(component => ({ + actionsMenuButton: undefined, + setActionsMenu(initialiser) { + actionsMenuPopoverInitialiser = initialiser; + component.actionsMenuButton.setPopover("click", (popover, button) => { + popover.anchor.add("off right", "aligned top"); + popover.anchor.add("off right", "aligned bottom"); + initialiser(popover, button); + }); + return component; + }, + })) + .extendJIT("actionsMenuButton", component => { + const button = (0, Button_1.default)() + .style("block-actions-menu-button") + .setIcon("ellipsis-vertical") + .setPopover("click", actionsMenuPopoverInitialiser); + if (inserter) + inserter(button); + else + button.appendTo(component); + return button; + }); + }); + exports.default = CanHasActionsMenuButton; +}); +define("ui/utility/MarkdownContent", ["require", "exports", "ui/Component", "utility/string/Strings"], function (require, exports, Component_6, Strings_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_6 = __importDefault(Component_6); + Strings_2 = __importDefault(Strings_2); + const handlers = []; + Component_6.default.extend(component => component.extend(component => ({ + setMarkdownContent(markdown) { + component.classes.add("markdown"); + component.element.innerHTML = Strings_2.default.markdown.render(markdown); + for (const node of [...component.element.querySelectorAll("*")]) + for (const handler of handlers) + handler(node); + return component; + }, + }))); + var MarkdownContent; + (function (MarkdownContent) { + function handle(handler) { + handlers.push(handler); + } + MarkdownContent.handle = handle; + })(MarkdownContent || (MarkdownContent = {})); + exports.default = MarkdownContent; +}); +define("ui/component/core/Heading", ["require", "exports", "ui/Component", "ui/utility/MarkdownContent"], function (require, exports, Component_7, MarkdownContent_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.HeadingClasses = void 0; + Component_7 = __importDefault(Component_7); + MarkdownContent_1 = __importDefault(MarkdownContent_1); + var HeadingClasses; + (function (HeadingClasses) { + HeadingClasses["_ContainsHeading"] = "_contains-heading"; + })(HeadingClasses || (exports.HeadingClasses = HeadingClasses = {})); + Component_7.default.extend(component => component.extend(component => ({ + containsHeading: () => component.classes.has(HeadingClasses._ContainsHeading), + setContainsHeading() { + component.classes.add(HeadingClasses._ContainsHeading); + return component; + }, + }))); + const Heading = Component_7.default.Builder("h1", (component) => { + component.style("heading"); + component.text.state.use(component, text => component.setId(text?.toString().toLowerCase().replace(/\W+/g, "-"))); + component.tabIndex("programmatic"); + component.receiveAncestorInsertEvents(); + component.event.subscribe(["insert", "ancestorInsert"], updateHeadingLevel); + component.rooted.subscribeManual(updateHeadingLevel); + let initial = true; + let aestheticLevel; + let aestheticStyle; + return component.extend(heading => ({ + setAestheticLevel(level) { + const style = aestheticStyle ?? "heading"; + const oldLevel = getHeadingLevel(component.element); + if (isStyledHeadingLevel(oldLevel)) + component.style.remove(`${style}-${oldLevel}`); + if (aestheticLevel) + component.style.remove(`${style}-${aestheticLevel}`); + aestheticLevel = level; + if (isStyledHeadingLevel(aestheticLevel)) + component.style(`${style}-${aestheticLevel}`); + return heading; + }, + setAestheticStyle(style) { + const level = aestheticLevel ?? getHeadingLevel(component.element); + if (isStyledHeadingLevel(level)) + component.style.remove(`${aestheticStyle ?? "heading"}`, `${aestheticStyle ?? "heading"}-${level}`); + aestheticStyle = style; + if (isStyledHeadingLevel(level)) + component.style(`${style ?? "heading"}`, `${style ?? "heading"}-${level}`); + return heading; + }, + updateLevel: () => { + updateHeadingLevel(); + return heading; + }, + })); + function updateHeadingLevel() { + const newLevel = computeHeadingLevel(component.element); + const oldLevel = getHeadingLevel(component.element); + const isSameLevel = newLevel === oldLevel; + if (isSameLevel && !initial) + return; + const style = aestheticStyle ?? "heading"; + initial = false; + if (isStyledHeadingLevel(oldLevel)) + component.style.remove(`${style}-${oldLevel}`); + const isStyledLevel = isStyledHeadingLevel(newLevel); + if (!aestheticLevel && isStyledLevel) + component.style(`${style}-${newLevel}`); + if (aestheticLevel) + component.style(`${style}-${aestheticLevel}`); + if (isSameLevel) + return; + component.event.unsubscribe(["insert", "ancestorInsert"], updateHeadingLevel); + component.replaceElement(isStyledLevel ? `h${newLevel}` : "span"); + component.attributes.toggle(!isStyledLevel, "role", "heading"); + component.attributes.toggle(!isStyledLevel && typeof newLevel === "number", "aria-level", `${newLevel}`); + component.event.subscribe(["insert", "ancestorInsert"], updateHeadingLevel); + } + }); + function computeHeadingLevel(node) { + let currentNode = node; + let incrementHeading = false; + while (currentNode) { + const heading = getPreviousSiblingHeading(currentNode); + if (heading) { + const level = getHeadingLevel(heading); + if (!incrementHeading && level !== 1) + return level; + if (level === undefined || level > 6) + return level; + return level + 1; + } + currentNode = currentNode.parentNode ?? undefined; + incrementHeading ||= true; + } + return 1; + } + function getPreviousSiblingHeading(node) { + let sibling = node; + while (sibling) { + sibling = sibling.previousSibling ?? undefined; + if (sibling?.nodeType !== Node.ELEMENT_NODE) + continue; + const siblingElement = sibling; + if (isHeadingElement(siblingElement)) + return siblingElement; + if (siblingElement.getAttribute("role") === "heading") + return siblingElement; + if (siblingElement.tagName === "HGROUP") { + const [heading] = siblingElement.querySelectorAll("h1, h2, h3, h4, h5, h6, [role='heading']"); + if (heading) + return heading; + } + if (siblingElement.component?.containsHeading()) { + const [heading] = siblingElement.querySelectorAll("h1, h2, h3, h4, h5, h6, [role='heading']"); + if (heading) + return heading; + } + } + } + function isHeadingElement(value) { + if (!value || typeof value !== "object" || !("tagName" in value)) + return false; + const element = value; + return element.tagName[0] === "H" && element.tagName.length === 2 && !isNaN(+element.tagName[1]); + } + function getHeadingLevel(element) { + return +element.tagName.slice(1) || +element.getAttribute("aria-level") || undefined; + } + function isStyledHeadingLevel(level) { + return typeof level === "number" && level >= 1 && level <= 6; + } + //#endregion + //////////////////////////////////// + MarkdownContent_1.default.handle(element => { + if (isHeadingElement(element)) { + const level = getHeadingLevel(element); + const heading = Heading().setAestheticStyle("markdown-heading"); + heading.element.replaceChildren(...element.childNodes); + element.replaceWith(heading.element); + heading.emitInsert(); + if (isStyledHeadingLevel(level)) + heading.setAestheticLevel(level); + } + }); + exports.default = Heading; +}); +define("ui/component/core/Paragraph", ["require", "exports", "ui/Component"], function (require, exports, Component_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_8 = __importDefault(Component_8); + const Paragraph = Component_8.default.Builder(component => component + .style("paragraph")); + exports.default = Paragraph; +}); +define("ui/component/core/Block", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/ext/CanHasActionsMenuButton", "ui/component/core/Heading", "ui/component/core/Paragraph", "utility/State"], function (require, exports, Component_9, ActionRow_1, CanHasActionsMenuButton_1, Heading_1, Paragraph_1, State_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BlockClasses = void 0; + Component_9 = __importDefault(Component_9); + ActionRow_1 = __importDefault(ActionRow_1); + CanHasActionsMenuButton_1 = __importDefault(CanHasActionsMenuButton_1); + Heading_1 = __importDefault(Heading_1); + Paragraph_1 = __importDefault(Paragraph_1); + State_5 = __importDefault(State_5); + var BlockClasses; + (function (BlockClasses) { + BlockClasses["Main"] = "$block"; + })(BlockClasses || (exports.BlockClasses = BlockClasses = {})); + const Block = Component_9.default.Builder((component) => { + const types = (0, State_5.default)(new Set()); + let header; + let footer; + const block = component + .classes.add(BlockClasses.Main) + .viewTransition("block") + .style("block") + .extend(block => ({ + title: undefined, + header: undefined, + description: undefined, + primaryActions: undefined, + content: (0, Component_9.default)().style("block-content").appendTo(component), + footer: undefined, + type: Object.assign((...newTypes) => { + const oldSize = types.value.size; + for (const type of newTypes) { + types.value.add(type); + block.style(`block-type-${type}`); + header?.style(`block-type-${type}-header`); + footer?.style(`block-type-${type}-footer`); + } + if (types.value.size !== oldSize) + types.emit(); + return block; + }, { + state: types, + remove(...removeTypes) { + let removed = false; + for (const type of removeTypes) { + removed ||= types.value.delete(type); + block.style.remove(`block-type-${type}`); + header?.style.remove(`block-type-${type}-header`); + footer?.style.remove(`block-type-${type}-footer`); + } + if (removed) + types.emit(); + return block; + }, + }), + })) + .extendJIT("header", block => header = (0, Component_9.default)("hgroup") + .style("block-header", ...[...types.value].map(t => `block-type-${t}-header`)) + .prependTo(block)) + .extendJIT("title", block => (0, Heading_1.default)().style("block-title").prependTo(block.header)) + .extendJIT("primaryActions", block => (0, Component_9.default)().style("block-actions-primary").appendTo(block.header)) + .extendJIT("description", block => (0, Paragraph_1.default)().style("block-description").appendTo(block.header)) + .extendJIT("footer", block => footer = (0, ActionRow_1.default)() + .style("block-footer", ...[...types.value].map(t => `block-type-${t}-footer`)) + .appendTo(block)); + return block + .and(CanHasActionsMenuButton_1.default, button => button.appendTo(block.primaryActions)); + }); + exports.default = Block; +}); +define("ui/component/core/Slot", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_10, State_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_10 = __importDefault(Component_10); + State_6 = __importDefault(State_6); + const Slot = Object.assign(Component_10.default.Builder((slot) => { + slot.style("slot"); + let unuse; + let cleanup; + return slot + .extend(slot => ({ + use: (state, initialiser) => { + unuse?.(); + unuse = state.use(slot, value => { + cleanup?.(); + slot.removeContents(); + let result = initialiser(slot, value) || undefined; + if (result === slot) + result = undefined; + if (Component_10.default.is(result)) { + result.appendTo(slot); + cleanup = undefined; + return; + } + cleanup = result; + }); + return slot; + }, + if: (state, initialiser) => { + unuse?.(); + state.use(slot, value => { + if (!value) { + cleanup?.(); + cleanup = undefined; + slot.removeContents(); + return; + } + let result = initialiser(slot) || undefined; + if (result === slot) + result = undefined; + if (Component_10.default.is(result)) { + result.appendTo(slot); + cleanup = undefined; + return; + } + cleanup = result; + }); + return slot; + }, + })) + .event.subscribe("remove", () => cleanup?.()); + }), { + using: (value, initialiser) => Slot().use(State_6.default.get(value), initialiser), + }); + exports.default = Slot; +}); +define("ui/utility/Viewport", ["require", "exports", "utility/State"], function (require, exports, State_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_7 = __importDefault(State_7); + var Viewport; + (function (Viewport) { + Viewport.size = State_7.default.JIT(() => ({ w: window.innerWidth, h: window.innerHeight })); + function listen() { + window.addEventListener("resize", Viewport.size.markDirty); + } + Viewport.listen = listen; + })(Viewport || (Viewport = {})); + exports.default = Viewport; +}); +define("ui/utility/AnchorManipulator", ["require", "exports", "ui/utility/Mouse", "ui/utility/Viewport", "utility/Time"], function (require, exports, Mouse_3, Viewport_1, Time_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AllowXOffscreen = exports.AllowYOffscreen = exports.ANCHOR_LOCATION_ALIGNMENTS = exports.ANCHOR_SIDE_VERTICAL = exports.ANCHOR_SIDE_HORIZONTAL = exports.ANCHOR_TYPES = void 0; + Mouse_3 = __importDefault(Mouse_3); + Viewport_1 = __importDefault(Viewport_1); + Time_4 = __importDefault(Time_4); + //////////////////////////////////// + //#region Anchor Strings + exports.ANCHOR_TYPES = ["off", "aligned"]; + exports.ANCHOR_SIDE_HORIZONTAL = ["left", "right"]; + exports.ANCHOR_SIDE_VERTICAL = ["top", "bottom"]; + const anchorStrings = new Set(exports.ANCHOR_TYPES + .flatMap(type => [exports.ANCHOR_SIDE_HORIZONTAL, exports.ANCHOR_SIDE_VERTICAL] + .flatMap(sides => sides + .map(side => `${type} ${side}`))) + .flatMap(type => [type, `sticky ${type}`])); + anchorStrings.add("centre"); + anchorStrings.add("sticky centre"); + function isAnchorString(value) { + if (anchorStrings.has(value)) { + return true; + } + if (typeof value !== "string") { + return false; + } + const lastSpace = value.lastIndexOf(" "); + if (lastSpace === -1) { + return false; + } + const simpleAnchorString = value.slice(0, lastSpace); + if (!anchorStrings.has(simpleAnchorString)) { + return false; + } + const offsetString = value.slice(lastSpace + 1); + return !isNaN(+offsetString); + } + function parseAnchor(anchor) { + const sticky = anchor.startsWith("sticky"); + if (sticky) { + anchor = anchor.slice(7); + } + const simpleAnchor = anchor; + if (simpleAnchor === "centre") { + return { sticky, type: "centre", side: "centre", offset: 0 }; + } + const [type, side, offset] = simpleAnchor.split(" "); + return { + sticky, + type, + side, + offset: offset ? +offset : 0, + }; + } + exports.ANCHOR_LOCATION_ALIGNMENTS = ["left", "centre", "right"]; + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region Implementation + exports.AllowYOffscreen = { allowYOffscreen: true }; + exports.AllowXOffscreen = { allowXOffscreen: true }; + function AnchorManipulator(host) { + let locationPreference; + let refCache; + let location; + let currentAlignment; + let from; + function onFromRemove() { + from = undefined; + } + let lastRender = 0; + let rerenderTimeout; + const subscribed = []; + const addSubscription = (use) => use && subscribed.push(use); + const result = { + isMouse: () => !locationPreference?.length, + from: component => { + from?.event.unsubscribe("remove", onFromRemove); + from = component; + component.event.subscribe("remove", onFromRemove); + return host; + }, + reset: () => { + locationPreference = undefined; + result.markDirty(); + return host; + }, + add: (...config) => { + const options = typeof config[config.length - 1] === "string" ? undefined + : config.pop(); + let [xAnchor, xRefSelector, yAnchor, yRefSelector] = config; + if (isAnchorString(xRefSelector)) { + yRefSelector = yAnchor; + yAnchor = xRefSelector; + xRefSelector = "*"; + } + yRefSelector ??= "*"; + locationPreference ??= []; + locationPreference.push({ + xAnchor: parseAnchor(xAnchor), + xRefSelector, + yAnchor: parseAnchor(yAnchor), + yRefSelector, + options, + }); + result.markDirty(); + return host; + }, + markDirty: () => { + location = undefined; + if (lastRender) { + const timeSinceLastRender = Date.now() - lastRender; + if (timeSinceLastRender > Time_4.default.frame) + result.apply(); + else if (rerenderTimeout === undefined) + rerenderTimeout = window.setTimeout(result.apply, Time_4.default.frame - timeSinceLastRender); + } + return host; + }, + get: () => { + if (location) + return location; + for (const unuse of subscribed) + unuse(); + const tooltipBox = host?.rect.value; + if (tooltipBox && locationPreference && from) { + for (const preference of locationPreference) { + let alignment = "left"; + const xConf = preference.xAnchor; + const xRef = resolveAnchorRef(preference.xRefSelector); + const xBox = xRef?.rect.value; + addSubscription(xRef?.rect.subscribe(host, result.markDirty)); + const xCenter = (xBox?.left ?? 0) + (xBox?.width ?? Viewport_1.default.size.value.w) / 2; + const xRefX = (xConf.side === "right" ? xBox?.right : xConf.side === "left" ? xBox?.left : xCenter) ?? xCenter; + let x; + switch (xConf.type) { + case "aligned": + x = xConf.side === "right" ? xRefX - tooltipBox.width - xConf.offset : xRefX + xConf.offset; + alignment = xConf.side; + break; + case "off": + x = xConf.side === "right" ? xRefX + xConf.offset : xRefX - tooltipBox.width - xConf.offset; + // alignment is inverted side for "off" + alignment = xConf.side === "left" ? "right" : "left"; + break; + case "centre": + x = xRefX - tooltipBox.width / 2; + alignment = "centre"; + break; + } + if (preference.options?.xValid?.(x, xBox, tooltipBox) === false) { + continue; + } + if (!xConf.sticky && tooltipBox.width < Viewport_1.default.size.value.w && !preference.options?.allowXOffscreen) { + const isXOffScreen = x < 0 || x + tooltipBox.width > Viewport_1.default.size.value.w; + if (isXOffScreen) { + continue; + } + } + const yConf = preference.yAnchor; + const yRef = resolveAnchorRef(preference.yRefSelector); + const yBox = yRef?.rect.value; + addSubscription(yRef?.rect.subscribe(host, result.markDirty)); + const yCenter = (yBox?.top ?? 0) + (yBox?.height ?? Viewport_1.default.size.value.h) / 2; + const yRefY = (yConf.side === "bottom" ? yBox?.bottom : yConf.side === "top" ? yBox?.top : yCenter) ?? yCenter; + let y; + switch (yConf.type) { + case "aligned": + y = yConf.side === "bottom" ? yRefY - tooltipBox.height - yConf.offset : yRefY + yConf.offset; + break; + case "off": + y = yConf.side === "bottom" ? yRefY + yConf.offset : yRefY - tooltipBox.height - yConf.offset; + break; + case "centre": + y = yRefY - tooltipBox.height / 2; + break; + } + if (preference.options?.yValid?.(y, yBox, tooltipBox) === false) { + continue; + } + if (!yConf.sticky && tooltipBox.height < Viewport_1.default.size.value.h && !preference.options?.allowYOffscreen) { + const isYOffScreen = y < 0 + || y + tooltipBox.height > Viewport_1.default.size.value.h; + if (isYOffScreen) { + continue; + } + } + return location ??= { mouse: false, padX: xConf.type === "off", alignment, x, y }; + } + } + return location ??= { mouse: true, padX: true, ...Mouse_3.default.state.value }; + }, + apply: () => { + const location = result.get(); + let alignment = location.alignment ?? currentAlignment; + if (location.mouse) { + const shouldFlip = currentAlignment === "centre" || (currentAlignment === "right" ? location.x < Viewport_1.default.size.value.w / 2 - 200 : location.x > Viewport_1.default.size.value.w / 2 + 200); + if (shouldFlip) { + alignment = currentAlignment === "left" ? "right" : "left"; + } + } + if (currentAlignment !== alignment) { + currentAlignment = alignment; + // this.surface.classes.removeStartingWith("aligned-") + // this.surface.classes.add(`aligned-${this.currentAlignment}`) + } + // this.surface.classes.toggle(location.padX, "pad-x") + host.element.style.left = `${location.x}px`; + host.element.style.top = `${location.y}px`; + host.rect.markDirty(); + rerenderTimeout = undefined; + lastRender = Date.now(); + return host; + }, + }; + return result; + function resolveAnchorRef(selector) { + const refRef = refCache?.[selector]; + let ref; + if (refRef) { + ref = refRef.deref(); + } + else { + ref = from?.element.closest(selector)?.component; + if (ref) { + if (getComputedStyle(ref.element).display === "contents") { + const children = ref.element.children; + if (!children.length) + console.warn("Anchor ref has display: contents and no children"); + else { + ref = children[0].component ?? ref; + if (children.length > 1) + console.warn("Anchor ref has display: contents and multiple children"); + } + } + refCache ??= {}; + refCache[selector] = new WeakRef(ref); + } + } + return ref; + } + } + exports.default = AnchorManipulator; +}); +//#endregion +//////////////////////////////////// +define("ui/utility/StringApplicator", ["require", "exports", "lang/en-nz", "utility/State"], function (require, exports, en_nz_1, State_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.QuiltHelper = void 0; + en_nz_1 = __importDefault(en_nz_1); + State_8 = __importDefault(State_8); + var QuiltHelper; + (function (QuiltHelper) { + function renderWeave(weave) { + return weave.content.map(renderWeft); + } + QuiltHelper.renderWeave = renderWeave; + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents + function arg(arg) { + if (typeof arg === "object" && arg && "map" in arg) + arg = arg.value; + if (typeof arg === "function") + arg = arg(en_nz_1.default, QuiltHelper); + if (typeof arg === "string" && arg in en_nz_1.default) + arg = en_nz_1.default[arg](); + return arg; + } + QuiltHelper.arg = arg; + function isPlaintextWeft(weft) { + return true + && typeof weft.content === "string"; + } + function renderWeft(weft) { + if (isPlaintextWeft(weft)) + return document.createTextNode(weft.content); + let element; + const tag = weft.tag?.toLowerCase(); + if (tag) { + if (tag.startsWith("link(")) { + const link = element = document.createElement("a"); + const href = tag.slice(5, -1); + link.href = href; + link.addEventListener("click", event => { + event.preventDefault(); + navigate.toRawURL(href); + }); + } + } + element ??= document.createElement("span"); + if (Array.isArray(weft.content)) + element.append(...weft.content.map(renderWeft)); + else if (typeof weft.content === "object" && weft.content) + element.append(...renderWeave(weft.content)); + else + element.textContent = `${weft.content ?? ""}`; + return element; + } + })(QuiltHelper || (exports.QuiltHelper = QuiltHelper = {})); + function StringApplicator(host, defaultValueOrApply, apply) { + const defaultValue = !apply ? undefined : defaultValueOrApply; + apply ??= defaultValueOrApply; + let translationHandler; + let unbind; + const result = makeApplicator(host); + return result; + function makeApplicator(host) { + return { + state: (0, State_8.default)(defaultValue), + set: value => { + unbind?.(); + translationHandler = undefined; + setInternal(value); + return host; + }, + use: translation => { + unbind?.(); + if (typeof translation === "string") { + translationHandler = undefined; + setInternal(en_nz_1.default[translation]().toString()); + return host; + } + translationHandler = translation; + result.refresh(); + return host; + }, + bind: state => { + translationHandler = undefined; + unbind?.(); + unbind = state?.use(host, setInternal); + if (!state) + setInternal(defaultValue); + return host; + }, + unbind: () => { + unbind?.(); + setInternal(defaultValue); + return host; + }, + refresh: () => { + if (!translationHandler) + return; + setInternal(translationHandler(en_nz_1.default, QuiltHelper).toString()); + }, + rehost: makeApplicator, + }; + } + function setInternal(value) { + if (typeof value === "object" && value !== null) + value = value.toString(); + if (result.state.value !== value) { + result.state.value = value; + apply(value); + } + } + } + exports.default = StringApplicator; +}); +define("ui/component/core/ext/Input", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Popover", "ui/component/core/Slot", "ui/utility/AnchorManipulator", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_11, Block_1, Popover_1, Slot_1, AnchorManipulator_1, StringApplicator_1, State_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_11 = __importDefault(Component_11); + Popover_1 = __importDefault(Popover_1); + Slot_1 = __importDefault(Slot_1); + StringApplicator_1 = __importDefault(StringApplicator_1); + State_9 = __importDefault(State_9); + const Input = Component_11.default.Extension((component) => { + const hintText = (0, State_9.default)(undefined); + const maxLength = (0, State_9.default)(undefined); + const length = (0, State_9.default)(undefined); + const unusedPercent = State_9.default.MapManual([length, maxLength], (length, maxLength) => length === undefined || !maxLength ? undefined : 1 - length / maxLength); + const unusedChars = State_9.default.MapManual([length, maxLength], (length, maxLength) => length === undefined || !maxLength ? undefined : maxLength - length); + const hasPopover = State_9.default.MapManual([hintText, maxLength], (hintText, maxLength) => !!hintText || !!maxLength); + let popover; + hasPopover.subscribeManual(hasPopover => { + if (!hasPopover) { + popover?.remove(); + popover = undefined; + return; + } + popover = (0, Popover_1.default)() + .anchor.from(component) + .anchor.add("off right", `.\\${Block_1.BlockClasses.Main}`, "aligned top", { + ...AnchorManipulator_1.AllowYOffscreen, + yValid(y, hostBox, popoverBox) { + // only align top if the popover box is taller than the host box + return popoverBox.height > (hostBox?.height ?? 0); + }, + }) + .anchor.add("off right", `.\\${Block_1.BlockClasses.Main}`, "centre", AnchorManipulator_1.AllowYOffscreen) + .setNormalStacking() + .setCloseOnInput(false) + .style("input-popover") + .setOwner(component) + .tweak(popover => { + Slot_1.default.using(hintText, (slot, hintText) => !hintText ? undefined + : (0, Component_11.default)() + .style("input-popover-hint-text") + .text.set(hintText)) + .appendTo(popover); + Slot_1.default.using(maxLength, (slot, maxLength) => !maxLength ? undefined + : (0, Component_11.default)() + .style("input-popover-max-length") + .append((0, Component_11.default)() + .style("input-popover-max-length-icon") + .style.bind(unusedPercent.mapManual(p => (p ?? 0) < 0), "input-popover-max-length-icon--overflowing")) + .append((0, Component_11.default)() + .style("input-popover-max-length-text") + .text.bind(unusedChars.mapManual(chars => chars === undefined ? "" : `${chars}`))) + .style.bindVariable("remaining", unusedPercent.mapManual(p => 1 - (p ?? 0)))) + .appendTo(popover); + }) + .tweak(popoverInitialiser, component) + .appendTo(document.body); + }); + component.hasFocused.subscribeManual(hasFocused => popover?.toggle(hasFocused).anchor.apply()); + let popoverInitialiser; + return component.extend(component => ({ + required: (0, State_9.default)(false), + hint: (0, StringApplicator_1.default)(component, value => hintText.value = value), + maxLength, + length, + setMaxLength(newLength) { + maxLength.value = newLength; + return component; + }, + setRequired: (required = true) => { + component.attributes.toggle(required, "required"); + component.required.value = required; + return component; + }, + setLabel: label => { + component.setName(label?.for); + component.setId(label?.for); + label?.setInput(component); + return component; + }, + tweakPopover(initialiser) { + popoverInitialiser = initialiser; + return component; + }, + })); + }); + exports.default = Input; +}); +define("ui/component/core/Form", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/Block", "ui/component/core/Button", "utility/State"], function (require, exports, Component_12, ActionRow_2, Block_2, Button_2, State_10) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_12 = __importDefault(Component_12); + ActionRow_2 = __importDefault(ActionRow_2); + Block_2 = __importDefault(Block_2); + Button_2 = __importDefault(Button_2); + State_10 = __importDefault(State_10); + const Form = Component_12.default.Builder((form, label) => { + form.replaceElement("form") + .style("form") + .ariaRole("form") + .ariaLabelledBy(label); + form.receiveDescendantInsertEvents(); + const valid = State_10.default.Generator(() => form.element.checkValidity()); + form.event.subscribe(["input", "change", "descendantInsert"], () => valid.refresh()); + const content = (form.is(Block_2.default) ? form.content : (0, Component_12.default)()) + .style("form-content"); + const footer = (form.is(Block_2.default) ? form.footer : (0, ActionRow_2.default)()) + .style("form-footer"); + return form + .append(content, footer) + .extend(() => ({ + content, footer, + submit: undefined, + })) + .extendJIT("submit", () => (0, Button_2.default)() + .type("primary") + .attributes.set("type", "submit") + .bindDisabled(valid.not, "invalid") + .appendTo(footer.right)); + }); + exports.default = Form; +}); +define("ui/view/shared/component/View", ["require", "exports", "ui/Component"], function (require, exports, Component_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_13 = __importDefault(Component_13); + const View = Component_13.default.Builder((_, id) => (0, Component_13.default)() + .style("view", `view-type-${id}`) + .attributes.set("data-view", id) + .extend(view => ({ + viewId: id, + hash: "", + })) + .extendJIT("hash", view => `${view.viewId}${view.params ? `_${JSON.stringify(view.params)}` : ""}` + .replaceAll(/\W+/g, "-"))); + exports.default = View; +}); +define("ui/component/core/Label", ["require", "exports", "ui/Component", "ui/component/core/Form", "ui/view/shared/component/View", "utility/State"], function (require, exports, Component_14, Form_1, View_1, State_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AutoLabel = void 0; + Component_14 = __importDefault(Component_14); + Form_1 = __importDefault(Form_1); + View_1 = __importDefault(View_1); + State_11 = __importDefault(State_11); + const Label = Component_14.default.Builder("label", (label) => { + label.style("label"); + let requiredState; + return label + .extend(label => ({ + for: (0, State_11.default)(undefined), + setFor: inputName => { + label.attributes.set("for", inputName); + label.for.value = inputName; + return label; + }, + setRequired: (required = true) => { + label.style.unbind(requiredState); + requiredState = undefined; + if (typeof required === "boolean") + label.style.toggle("label-required"); + else + label.style.bind(requiredState = required, "label-required"); + return label; + }, + setInput: input => { + if (!label.is(exports.AutoLabel)) + label.setFor(input?.name.value); + label.setRequired(input?.required); + return label; + }, + })); + }); + exports.default = Label; + let globalI = 0; + exports.AutoLabel = Component_14.default.Builder("label", (component) => { + const i = globalI++; + const label = component.and(Label); + let formName; + let viewPath; + let unuseFormName; + label.receiveAncestorInsertEvents(); + label.event.subscribe(["insert", "ancestorInsert"], () => { + unuseFormName?.(); + const form = label.closest(Form_1.default); + unuseFormName = form?.name.use(label, name => formName = name); + const view = label.closest(View_1.default); + viewPath = view ? view.hash : "_"; + updateFor(); + }); + label.text.state.use(label, () => updateFor()); + return label.extend(label => ({})); + function updateFor() { + const text = label.text.state.value?.toString().toLowerCase().replace(/\W+/g, "-"); + if (!text) { + label.setFor(); + return; + } + if (!formName) + label.setFor(`${viewPath}--${text}--${i}`); + else + label.setFor(`${viewPath}--${formName}--${text}`); + } + }); +}); +define("ui/utility/AttributeManipulator", ["require", "exports", "lang/en-nz", "ui/utility/StringApplicator"], function (require, exports, en_nz_2, StringApplicator_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_2 = __importDefault(en_nz_2); + function AttributeManipulator(component) { + let translationHandlers; + const unuseAttributeMap = new Map(); + const result = { + get(attribute) { + return component.element.getAttribute(attribute) ?? undefined; + }, + append(...attributes) { + for (const attribute of attributes) { + delete translationHandlers?.[attribute]; + component.element.setAttribute(attribute, ""); + } + return component; + }, + prepend(...attributes) { + const oldAttributes = {}; + for (const attribute of [...component.element.attributes]) { + oldAttributes[attribute.name] = attribute.value; + component.element.removeAttribute(attribute.name); + } + for (const attribute of attributes) + component.element.setAttribute(attribute, oldAttributes[attribute] ?? ""); + for (const name of Object.keys(oldAttributes)) + component.element.setAttribute(name, oldAttributes[name]); + return component; + }, + set(attribute, value) { + delete translationHandlers?.[attribute]; + if (value === undefined) + component.element.removeAttribute(attribute); + else + component.element.setAttribute(attribute, value); + return component; + }, + bind(state, attribute, value) { + unuseAttributeMap.get(attribute)?.(); + unuseAttributeMap.set(attribute, state.use(component, active => { + if (active) + component.element.setAttribute(attribute, value ?? ""); + else + component.element.removeAttribute(attribute); + })); + return component; + }, + compute(attribute, supplier) { + if (component.element.hasAttribute(attribute)) + return component; + delete translationHandlers?.[attribute]; + const value = supplier(component); + if (value === undefined) + component.element.removeAttribute(attribute); + else + component.element.setAttribute(attribute, value); + return component; + }, + getUsing(attribute) { + return translationHandlers?.[attribute]; + }, + use(attribute, handler) { + translationHandlers ??= {}; + translationHandlers[attribute] = handler; + result.refresh(); + return component; + }, + refresh() { + if (!translationHandlers) + return; + for (const attribute in translationHandlers) { + const translationHandler = translationHandlers[attribute]; + const weave = typeof translationHandler === "string" ? en_nz_2.default[translationHandler]() : translationHandler(en_nz_2.default, StringApplicator_2.QuiltHelper); + component.element.setAttribute(attribute, weave.toString()); + } + }, + remove(...attributes) { + for (const attribute of attributes) { + delete translationHandlers?.[attribute]; + component.element.removeAttribute(attribute); + } + return component; + }, + toggle(present, attribute, value = "") { + return this[present ? "set" : "remove"](attribute, value); + }, + copy(element) { + if ("element" in element) + element = element.element; + for (const attribute of element.attributes) + component.element.setAttribute(attribute.name, attribute.value); + return component; + }, + }; + return result; + } + exports.default = AttributeManipulator; +}); +define("ui/utility/ClassManipulator", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function ClassManipulator(component) { + return { + has(...classes) { + return classes.every(className => component.element.classList.contains(className)); + }, + some(...classes) { + return classes.some(className => component.element.classList.contains(className)); + }, + add(...classes) { + component.element.classList.add(...classes); + return component; + }, + remove(...classes) { + component.element.classList.remove(...classes); + return component; + }, + toggle(present, ...classes) { + return this[present ? "add" : "remove"](...classes); + }, + copy(element) { + if ("element" in element) + element = element.element; + component.element.classList.add(...element.classList); + return component; + }, + }; + } + exports.default = ClassManipulator; +}); +define("ui/utility/EventManipulator", ["require", "exports", "utility/Arrays"], function (require, exports, Arrays_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_2 = __importDefault(Arrays_2); + const SYMBOL_REGISTERED_FUNCTION = Symbol("REGISTERED_FUNCTION"); + function EventManipulator(component) { + return { + emit(event, ...params) { + const detail = { result: [], params }; + const eventObject = new CustomEvent(event, { detail }); + component.element.dispatchEvent(eventObject); + return Object.assign(detail.result, { defaultPrevented: eventObject.defaultPrevented }); + }, + bubble(event, ...params) { + const detail = { result: [], params }; + const eventObject = new CustomEvent(event, { detail, bubbles: true }); + component.element.dispatchEvent(eventObject); + return Object.assign(detail.result, { defaultPrevented: eventObject.defaultPrevented }); + }, + subscribe(events, handler) { + if (handler[SYMBOL_REGISTERED_FUNCTION]) { + console.error(`Can't register handler for event(s) ${Arrays_2.default.resolve(events).join(", ")}, already used for other events`, handler); + return component; + } + const realHandler = (event) => { + const customEvent = event instanceof CustomEvent ? event : undefined; + const eventDetail = customEvent?.detail; + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + const result = handler(Object.assign(event, { component }), ...eventDetail?.params ?? []); + eventDetail?.result.push(result); + }; + Object.assign(handler, { [SYMBOL_REGISTERED_FUNCTION]: realHandler }); + for (const event of Arrays_2.default.resolve(events)) + component.element.addEventListener(event, realHandler); + return component; + }, + unsubscribe(events, handler) { + const realHandler = handler[SYMBOL_REGISTERED_FUNCTION]; + if (!realHandler) + return component; + delete handler[SYMBOL_REGISTERED_FUNCTION]; + for (const event of Arrays_2.default.resolve(events)) + component.element.removeEventListener(event, realHandler); + return component; + }, + }; + } + exports.default = EventManipulator; +}); +define("ui/utility/TextManipulator", ["require", "exports", "ui/utility/StringApplicator"], function (require, exports, StringApplicator_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + StringApplicator_3 = __importDefault(StringApplicator_3); + let Break; + const TextManipulator = Object.assign(function (component) { + return Object.assign((0, StringApplicator_3.default)(component, value => { + component.element.textContent = null; + if (!value) + return value; + const texts = value.split("\n"); + for (let i = 0; i < texts.length; i++) { + if (i > 0) + component.append(Break()); + component.element.append(document.createTextNode(texts[i])); + } + return value; + }), { + prepend(text) { + const texts = text.split("\n"); + for (let i = texts.length - 1; i >= 0; i--) { + if (i < texts.length - 1) + component.prepend(Break()); + component.element.prepend(document.createTextNode(texts[i])); + } + return component; + }, + append(text) { + const texts = text.split("\n"); + for (let i = 0; i < texts.length; i++) { + if (i > 0) + component.append(Break()); + component.element.append(document.createTextNode(texts[i])); + } + return component; + }, + }); + }, { + setComponent(Component) { + Break = Component + .Builder("br", component => component.style("break")) + .setName("Break"); + }, + }); + exports.default = TextManipulator; +}); +define("utility/Errors", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Errors; + (function (Errors) { + Errors.Impossible = () => new Error("Something impossible appears to have happened, what are you?"); + Errors.NotFound = () => Object.assign(new Error("Not found"), { code: 404 }); + Errors.BadData = (message) => Object.assign(new Error("Bad data was sent by the server", { cause: message }), { code: 500 }); + })(Errors || (Errors = {})); + exports.default = Errors; +}); +define("ui/Component", ["require", "exports", "ui/utility/AnchorManipulator", "ui/utility/AttributeManipulator", "ui/utility/ClassManipulator", "ui/utility/EventManipulator", "ui/utility/FocusListener", "ui/utility/StringApplicator", "ui/utility/StyleManipulator", "ui/utility/TextManipulator", "ui/utility/Viewport", "utility/Define", "utility/Env", "utility/Errors", "utility/State", "utility/string/Strings"], function (require, exports, AnchorManipulator_2, AttributeManipulator_1, ClassManipulator_1, EventManipulator_1, FocusListener_2, StringApplicator_4, StyleManipulator_1, TextManipulator_1, Viewport_2, Define_3, Env_2, Errors_1, State_12, Strings_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + AnchorManipulator_2 = __importDefault(AnchorManipulator_2); + AttributeManipulator_1 = __importDefault(AttributeManipulator_1); + ClassManipulator_1 = __importDefault(ClassManipulator_1); + EventManipulator_1 = __importDefault(EventManipulator_1); + FocusListener_2 = __importDefault(FocusListener_2); + StringApplicator_4 = __importDefault(StringApplicator_4); + StyleManipulator_1 = __importDefault(StyleManipulator_1); + TextManipulator_1 = __importDefault(TextManipulator_1); + Viewport_2 = __importDefault(Viewport_2); + Define_3 = __importDefault(Define_3); + Env_2 = __importDefault(Env_2); + Errors_1 = __importDefault(Errors_1); + State_12 = __importDefault(State_12); + Strings_3 = __importDefault(Strings_3); + const SYMBOL_COMPONENT_BRAND = Symbol("COMPONENT_BRAND"); + const ELEMENT_TO_COMPONENT_MAP = new WeakMap(); + Define_3.default.magic(Element.prototype, "component", { + get() { + return ELEMENT_TO_COMPONENT_MAP.get(this); + }, + set(component) { + if (component) { + ELEMENT_TO_COMPONENT_MAP.set(this, component); + } + else { + ELEMENT_TO_COMPONENT_MAP.delete(this); + } + }, + }); + var Classes; + (function (Classes) { + Classes["ReceiveAncestorInsertEvents"] = "_receieve-ancestor-insert-events"; + Classes["ReceiveDescendantInsertEvents"] = "_receieve-descendant-insert-events"; + Classes["ReceiveAncestorRectDirtyEvents"] = "_receieve-ancestor-rect-dirty-events"; + Classes["ReceiveScrollEvents"] = "_receieve-scroll-events"; + })(Classes || (Classes = {})); + const componentExtensionsRegistry = []; + function Component(type = "span") { + let unuseIdState; + let unuseNameState; + let unuseAriaLabelledByIdState; + let unuseAriaControlsIdState; + let descendantsListeningForScroll; + let owner; + let component = { + supers: [], + isComponent: true, + element: document.createElement(type), + removed: (0, State_12.default)(false), + rooted: (0, State_12.default)(false), + setOwner: newOwner => { + owner?.event.unsubscribe("remove", component.remove); + owner = newOwner; + owner.event.subscribe("remove", component.remove); + return component; + }, + replaceElement: newElement => { + if (typeof newElement === "string") + newElement = document.createElement(newElement); + const oldElement = component.element; + newElement.replaceChildren(...component.element.childNodes); + if (component.element.parentNode) + component.element.replaceWith(newElement); + component.element = newElement; + type = component.element.tagName; + ELEMENT_TO_COMPONENT_MAP.delete(oldElement); + ELEMENT_TO_COMPONENT_MAP.set(newElement, component); + component.attributes.copy(oldElement); + component.style.refresh(); + return component; + }, + is: (builder) => component.supers.includes(builder), + as: (builder) => component.supers.includes(builder) ? component : undefined, + cast: () => component, + and(builder, ...params) { + const result = builder.from(component, ...params); + if (result instanceof Promise) + return result.then(result => { + component = result; + component.supers.push(builder); + if (builder.name) + component.attributes.prepend(`:${builder.name.kebabcase}`); + return component; + }); + component = result; + component.supers.push(builder); + if (builder.name) + component.attributes.prepend(`:${builder.name.kebabcase}`); + return component; + }, + extend: extension => Object.assign(component, extension(component)), + extendMagic: (property, magic) => { + Define_3.default.magic(component, property, magic(component)); + return component; + }, + extendJIT: (property, supplier) => { + Define_3.default.magic(component, property, { + get: () => { + const value = supplier(component); + Define_3.default.set(component, property, value); + return value; + }, + set: value => { + Define_3.default.set(component, property, value); + }, + }); + return component; + }, + tweak: (tweaker, ...params) => { + tweaker?.(component, ...params); + return component; + }, + get style() { + return Define_3.default.set(component, "style", (0, StyleManipulator_1.default)(component)); + }, + get classes() { + return Define_3.default.set(component, "classes", (0, ClassManipulator_1.default)(component)); + }, + get attributes() { + return Define_3.default.set(component, "attributes", (0, AttributeManipulator_1.default)(component)); + }, + get event() { + return Define_3.default.set(component, "event", (0, EventManipulator_1.default)(component)); + }, + get text() { + return Define_3.default.set(component, "text", (0, TextManipulator_1.default)(component)); + }, + get anchor() { + return Define_3.default.set(component, "anchor", (0, AnchorManipulator_2.default)(component)); + }, + get hovered() { + return Define_3.default.set(component, "hovered", (0, State_12.default)(false)); + }, + get focused() { + return Define_3.default.set(component, "focused", (0, State_12.default)(false)); + }, + get hasFocused() { + return Define_3.default.set(component, "hasFocused", (0, State_12.default)(false)); + }, + get hoveredOrFocused() { + return Define_3.default.set(component, "hoveredOrFocused", State_12.default.Generator(() => component.hovered.value || component.focused.value) + .observe(component, component.hovered, component.focused)); + }, + get hoveredOrHasFocused() { + return Define_3.default.set(component, "hoveredOrHasFocused", State_12.default.Generator(() => component.hovered.value || component.hasFocused.value) + .observe(component, component.hovered, component.hasFocused)); + }, + get active() { + return Define_3.default.set(component, "active", (0, State_12.default)(false)); + }, + get id() { + return Define_3.default.set(component, "id", (0, State_12.default)(undefined)); + }, + get name() { + return Define_3.default.set(component, "name", (0, State_12.default)(undefined)); + }, + get rect() { + const rectState = State_12.default.JIT(() => component.element.getBoundingClientRect()); + const oldMarkDirty = rectState.markDirty; + rectState.markDirty = () => { + oldMarkDirty(); + for (const descendant of this.element.getElementsByClassName(Classes.ReceiveAncestorRectDirtyEvents)) + descendant.component?.event.emit("ancestorRectDirty"); + return rectState; + }; + this.receiveAncestorInsertEvents(); + this.receiveAncestorScrollEvents(); + this.classes.add(Classes.ReceiveAncestorRectDirtyEvents); + this.event.subscribe(["insert", "ancestorInsert", "ancestorScroll", "ancestorRectDirty"], rectState.markDirty); + Viewport_2.default.size.subscribe(component, rectState.markDirty); + return Define_3.default.set(component, "rect", rectState); + }, + setId: id => { + unuseIdState?.(); + unuseIdState = undefined; + if (id && typeof id !== "string") + unuseIdState = id.use(component, setId); + else + setId(id); + return component; + function setId(id) { + if (id) { + component.element.setAttribute("id", id); + component.id.value = id; + } + else { + component.element.removeAttribute("id"); + component.id.value = undefined; + } + } + }, + setName: name => { + unuseNameState?.(); + unuseNameState = undefined; + if (name && typeof name !== "string") + unuseNameState = name.use(component, setName); + else + setName(name); + return component; + function setName(name) { + if (name) { + name = name.replace(/[^\w-]+/g, "-").toLowerCase(); + component.element.setAttribute("name", name); + component.name.value = name; + } + else { + component.element.removeAttribute("name"); + component.name.value = undefined; + } + } + }, + remove(internal = false) { + component.removed.value = true; + component.rooted.value = false; + if (internal !== true) + for (const descendant of component.element.querySelectorAll("*")) + descendant.component?.remove(true); + component.element.component = undefined; + component.element.remove(); + component.event.emit("unroot"); + component.event.emit("remove"); + owner?.event.unsubscribe("remove", component.remove); + }, + appendTo(destination) { + Component.element(destination).append(component.element); + component.emitInsert(); + return component; + }, + prependTo(destination) { + Component.element(destination).prepend(component.element); + component.emitInsert(); + return component; + }, + insertTo(destination, direction, sibling) { + const element = Component.element(destination); + const siblingElement = sibling ? Component.element(sibling) : null; + if (direction === "before") + element.insertBefore(component.element, siblingElement); + else + element.insertBefore(component.element, siblingElement?.nextSibling ?? null); + component.emitInsert(); + return component; + }, + append(...contents) { + const elements = contents.map(Component.element); + component.element.append(...elements); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + prepend(...contents) { + const elements = contents.map(Component.element); + component.element.prepend(...elements); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + insert(direction, sibling, ...contents) { + const siblingElement = sibling ? Component.element(sibling) : null; + const elements = contents.map(Component.element); + if (direction === "before") + for (let i = elements.length - 1; i >= 0; i--) + component.element.insertBefore(elements[i], siblingElement); + else + for (const element of elements) + component.element.insertBefore(element, siblingElement?.nextSibling ?? null); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + removeContents() { + component.element.replaceChildren(); + return component; + }, + closest(builder) { + let cursor = component.element; + while (cursor) { + cursor = cursor.parentElement; + const component = cursor?.component; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + if (component?.is(builder)) + return component; + } + }, + get parent() { + return component.element.parentElement?.component; + }, + get previousSibling() { + return component.element.previousElementSibling?.component; + }, + get nextSibling() { + return component.element.nextElementSibling?.component; + }, + *getAncestorComponents() { + let cursor = component.element; + while (cursor) { + cursor = cursor.parentElement; + const component = cursor?.component; + if (component) + yield component; + } + }, + receiveAncestorInsertEvents: () => { + component.element.classList.add(Classes.ReceiveAncestorInsertEvents); + return component; + }, + receiveDescendantInsertEvents: () => { + component.element.classList.add(Classes.ReceiveAncestorInsertEvents); + return component; + }, + receiveAncestorScrollEvents() { + component.element.classList.add(Classes.ReceiveScrollEvents); + return component; + }, + emitInsert: () => { + updateRooted(component); + emitInsert(component); + return component; + }, + monitorScrollEvents() { + descendantsListeningForScroll ??= component.element.getElementsByClassName(Classes.ReceiveScrollEvents); + component.event.subscribe("scroll", () => { + for (const descendant of [...descendantsListeningForScroll]) + descendant.component?.event.emit("ancestorScroll"); + }); + return component; + }, + onRooted(callback) { + component.rooted.awaitManual(true, () => callback(component)); + return component; + }, + ariaRole: (role) => { + if (!role) + return component.attributes.remove("role"); + return component.attributes.set("role", role); + }, + get ariaLabel() { + return Define_3.default.set(component, "ariaLabel", (0, StringApplicator_4.default)(component, value => component.attributes.set("aria-label", value))); + }, + ariaLabelledBy: labelledBy => { + unuseAriaLabelledByIdState?.(); + if (labelledBy) { + const state = State_12.default.Generator(() => labelledBy.id.value ?? labelledBy.attributes.get("for")) + .observe(component, labelledBy.id, labelledBy.cast()?.for); + unuseAriaLabelledByIdState = state.use(component, id => component.attributes.set("aria-labelledby", id)); + } + return component; + }, + ariaHidden: () => component.attributes.set("aria-hidden", "true"), + ariaChecked: state => { + state.use(component, state => component.attributes.set("aria-checked", `${state}`)); + return component; + }, + ariaControls: target => { + unuseAriaControlsIdState?.(); + unuseAriaControlsIdState = target?.id.use(component, id => component.attributes.set("aria-controls", id)); + return component; + }, + tabIndex: index => { + if (index === undefined) + component.element.removeAttribute("tabindex"); + else if (index === "programmatic") + component.element.setAttribute("tabindex", "-1"); + else if (index === "auto") + component.element.setAttribute("tabindex", "0"); + else + component.element.setAttribute("tabindex", `${index}`); + return component; + }, + focus: () => { + FocusListener_2.default.focus(component.element); + return component; + }, + blur: () => { + FocusListener_2.default.blur(component.element); + return component; + }, + }; + for (const extension of componentExtensionsRegistry) + extension(component); + if (!Component.is(component)) + throw Errors_1.default.Impossible(); + component.element.component = component; + return component; + } + function emitInsert(component) { + if (!component) + return; + component.event.emit("insert"); + const descendantsListeningForEvent = component.element.getElementsByClassName(Classes.ReceiveAncestorInsertEvents); + for (const descendant of descendantsListeningForEvent) + descendant.component?.event.emit("ancestorInsert"); + let cursor = component.element.parentElement; + while (cursor) { + cursor.component?.event.emit("descendantInsert"); + cursor = cursor.parentElement; + } + } + function updateRooted(component) { + if (component) { + const rooted = document.documentElement.contains(component.element); + if (component.rooted.value === rooted) + return; + component.rooted.value = rooted; + component.event.emit(rooted ? "root" : "unroot"); + for (const descendant of component.element.querySelectorAll("*")) { + const component = descendant.component; + if (component) { + component.rooted.value = rooted; + component.event.emit(rooted ? "root" : "unroot"); + } + } + } + } + (function (Component) { + function is(value) { + return typeof value === "object" && !!value?.isComponent; + } + Component.is = is; + function element(from) { + return is(from) ? from.element : from; + } + Component.element = element; + const defaultBuilder = (type) => Component(type); + function Builder(initialOrBuilder, builder) { + let name = getBuilderName(); + const type = typeof initialOrBuilder === "string" ? initialOrBuilder : undefined; + const initialBuilder = !builder || typeof initialOrBuilder === "string" ? defaultBuilder : initialOrBuilder; + builder ??= initialOrBuilder; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const realBuilder = (component = initialBuilder(type), ...params) => builder(component, ...params); + const simpleBuilder = (...params) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const component = realBuilder(undefined, ...params); + if (component instanceof Promise) + return component.then(completeComponent); + return completeComponent(component); + }; + Object.defineProperty(simpleBuilder, "name", { value: name, configurable: true }); + const resultBuilder = Object.assign(simpleBuilder, { + from: realBuilder, + setName(newName) { + name = addKebabCase(newName); + Object.defineProperty(simpleBuilder, "name", { value: name }); + return resultBuilder; + }, + }); + return resultBuilder; + function completeComponent(component) { + if (name && Env_2.default.isDev) { + component[Symbol.toStringTag] ??= name.toString(); + const tagName = `:${name.kebabcase}`; + if (component.element.tagName === "SPAN") { + component.replaceElement(tagName); + } + else { + component.attributes.prepend(tagName); + } + } + component.supers.push(simpleBuilder); + return component; + } + } + Component.Builder = Builder; + function Extension(builder) { + return { + name: getBuilderName(), + from: builder, + }; + } + Component.Extension = Extension; + function extend(extension) { + componentExtensionsRegistry.push(extension); + } + Component.extend = extend; + /** + * Returns the component for the given element, if it exists + */ + function get(element) { + if (!element || (typeof element !== "object" && typeof element !== "function")) + return undefined; + return ELEMENT_TO_COMPONENT_MAP.get(element); + } + Component.get = get; + const STACK_FILE_NAME_REGEX = /\(http.*?(\w+)\.ts:\d+:\d+\)/; + const PASCAL_CASE_WORD_START = /(?<=[a-z0-9_-])(?=[A-Z])/g; + function addKebabCase(name) { + return Object.assign(String(name), { + kebabcase: name.replaceAll(PASCAL_CASE_WORD_START, "-").toLowerCase(), + }); + } + function getBuilderName() { + const stack = Strings_3.default.shiftLine((new Error().stack ?? ""), 3); + const name = stack.match(STACK_FILE_NAME_REGEX)?.[1]; + if (!name) + return undefined; + return addKebabCase(name); + } + })(Component || (Component = {})); + TextManipulator_1.default.setComponent(Component); + exports.default = Component; +}); +define("utility/Store", ["require", "exports", "utility/State"], function (require, exports, State_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_13 = __importDefault(State_13); + // export type IStoreEvents = + // & { [KEY in keyof ILocalStorage as `set${Capitalize}`]: { value: ILocalStorage[KEY]; oldValue: ILocalStorage[KEY] } } + // & { [KEY in keyof ILocalStorage as `delete${Capitalize}`]: { oldValue: ILocalStorage[KEY] } } + let storage; + let statesProxy; + let states; + class Store { + // public static readonly event = EventManager.make() + static get items() { + return storage ??= new Proxy({}, { + has(_, key) { + return Store.has(key); + }, + get(_, key) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return Store.get(key); + }, + set(_, key, value) { + return Store.set(key, value); + }, + deleteProperty(_, key) { + return Store.delete(key); + }, + }); + } + static get state() { + const s = states ??= {}; + return statesProxy ??= new Proxy({}, { + has(_, key) { + return Store.has(key); + }, + get(_, key) { + return s[key] ??= (0, State_13.default)(Store.get(key)); + }, + }); + } + static get full() { + const result = {}; + for (const [key, value] of Object.entries(localStorage)) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + result[key] = JSON.parse(value); + return result; + } + static has(key) { + return localStorage.getItem(key) !== null; + } + static get(key) { + const value = localStorage.getItem(key); + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return value === null ? null : JSON.parse(value); + } + catch { + localStorage.removeItem(key); + return null; + } + } + static set(key, value) { + // const oldValue = Store.get(key) + if (value === undefined) + localStorage.removeItem(key); + else + localStorage.setItem(key, JSON.stringify(value)); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + // Store.event.emit(`set${key[0].toUpperCase()}${key.slice(1)}` as keyof IStoreEvents, { value, oldValue } as never) + const state = states?.[key]; + if (state) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + state.value = value; + return true; + } + static delete(key) { + // const oldValue = Store.get(key) + localStorage.removeItem(key); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + // Store.event.emit(`delete${key[0].toUpperCase()}${key.slice(1)}` as keyof IStoreEvents, { oldValue } as never) + const state = states?.[key]; + if (state) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + state.value = undefined; + return true; + } + } + exports.default = Store; + Object.assign(window, { Store }); +}); +define("utility/Popup", ["require", "exports", "utility/Store"], function (require, exports, Store_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = popup; + Store_1 = __importDefault(Store_1); + function popup(name, url, width = 600, height = 800) { + const left = (window.innerWidth - width) / 2 + window.screenLeft; + const top = (window.innerHeight - height) / 2 + window.screenTop; + return new Promise((resolve, reject) => { + delete Store_1.default.items.popupError; + const options = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left; + const oauthPopup = window.open(url, name, options); + const interval = setInterval(() => { + if (oauthPopup?.closed) { + clearInterval(interval); + const popupError = Store_1.default.items.popupError; + if (popupError) + return reject(Object.assign(new Error(popupError.message ?? "Internal Server Error"), { code: popupError.code })); + resolve(); + } + }, 100); + }); + } +}); +define("model/Session", ["require", "exports", "endpoint/auth/EndpointAuthRemove", "endpoint/session/EndpointSessionGet", "endpoint/session/EndpointSessionReset", "utility/Env", "utility/Popup", "utility/State", "utility/Store"], function (require, exports, EndpointAuthRemove_1, EndpointSessionGet_1, EndpointSessionReset_1, Env_3, Popup_1, State_14, Store_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthRemove_1 = __importDefault(EndpointAuthRemove_1); + EndpointSessionGet_1 = __importDefault(EndpointSessionGet_1); + EndpointSessionReset_1 = __importDefault(EndpointSessionReset_1); + Env_3 = __importDefault(Env_3); + Popup_1 = __importDefault(Popup_1); + State_14 = __importDefault(State_14); + Store_2 = __importDefault(Store_2); + var Session; + (function (Session) { + const clearedWithSessionChange = []; + function setClearedWithSessionChange(...keys) { + clearedWithSessionChange.push(...keys); + } + Session.setClearedWithSessionChange = setClearedWithSessionChange; + async function refresh() { + const session = await EndpointSessionGet_1.default.query(); + const stateToken = session.headers.get("State-Token"); + if (stateToken) + Store_2.default.items.stateToken = stateToken; + if (Store_2.default.items.session?.created !== session.data?.created) + for (const key of clearedWithSessionChange) + Store_2.default.delete(key); + Store_2.default.items.session = session?.data ?? undefined; + updateState(); + } + Session.refresh = refresh; + async function reset() { + await EndpointSessionReset_1.default.query(); + delete Store_2.default.items.session; + updateState(); + } + Session.reset = reset; + function setAuthor(author) { + const session = Store_2.default.items.session; + if (!session) + return void refresh(); + Store_2.default.items.session = { + ...session, + author: { + ...author, + authorisations: undefined, + }, + authorisations: author.authorisations ?? session.authorisations, + }; + updateState(); + } + Session.setAuthor = setAuthor; + function updateState() { + Auth.state.value = Store_2.default.items.session?.author ? "logged-in" : Store_2.default.items.session?.authorisations?.length ? "has-authorisations" : "none"; + Auth.authorisations.value = Store_2.default.items.session?.authorisations ?? []; + Auth.author.value = Store_2.default.items.session?.author ?? undefined; + } + function getStateToken() { + return Store_2.default.items.stateToken; + } + Session.getStateToken = getStateToken; + let Auth; + (function (Auth) { + Auth.state = (0, State_14.default)("none"); + Auth.loggedIn = State_14.default.Generator(() => Auth.state.value === "logged-in").observeManual(Auth.state); + Auth.authorisations = (0, State_14.default)([]); + Auth.author = (0, State_14.default)(undefined, (a, b) => a?.vanity === b?.vanity); + function getAll() { + return Store_2.default.items.session?.authorisations ?? []; + } + Auth.getAll = getAll; + function get(service) { + return Store_2.default.items.session?.authorisations?.find(auth => auth.service === service); + } + Auth.get = get; + function isAuthed(service) { + return Session.Auth.authorisations.value.some(auth => auth.service === service.name); + } + Auth.isAuthed = isAuthed; + async function unauth(authOrId) { + const id = typeof authOrId === "string" ? authOrId : authOrId.id; + await EndpointAuthRemove_1.default.query({ body: { id } }); + const session = Store_2.default.items.session; + if (session?.authorisations) { + let authorisations = session.authorisations.filter(auth => auth.id !== id); + if (!authorisations.length) + authorisations = null; + Store_2.default.items.session = { + ...session, + authorisations, + }; + } + updateState(); + } + Auth.unauth = unauth; + async function auth(service) { + await (0, Popup_1.default)(`Login Using ${service.name}`, service.url_begin, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session.refresh(); + } + Auth.auth = auth; + let isRequestingDangerToken = false; + function canRequestDangerToken() { + return !isRequestingDangerToken; + } + Auth.canRequestDangerToken = canRequestDangerToken; + async function requestDangerToken(type, service) { + if (isRequestingDangerToken) + return false; + isRequestingDangerToken = true; + const result = await (0, Popup_1.default)(`Re-authenticate Using ${service.name}`, `${Env_3.default.API_ORIGIN}danger-token/request/${type}/${service.id}/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + isRequestingDangerToken = false; + return result; + } + Auth.requestDangerToken = requestDangerToken; + async function await(owner) { + if (Auth.state.value === "logged-in") + return true; + return new Promise(resolve => { + Auth.state.subscribe(owner, handleStateChange); + function handleStateChange(value) { + if (value !== "logged-in") + return; + resolve(); + Auth.state.unsubscribe(handleStateChange); + } + }); + } + Auth.await = await; + })(Auth = Session.Auth || (Session.Auth = {})); + })(Session || (Session = {})); + Object.assign(window, { Session }); + exports.default = Session; +}); +define("navigation/Route", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function Route(path, route) { + const segments = (path.startsWith("/") ? path.slice(1) : path).split("/"); + const varGroups = []; + let regexString = "^"; + for (const segment of segments) { + regexString += "/+"; + if (segment[0] !== "$") { + regexString += segment; + continue; + } + if (segment[1] === "$") { + varGroups.push(segment.slice(2)); + regexString += "(.*)"; + continue; + } + varGroups.push(segment.slice(1)); + regexString += "([^/]+)"; + } + regexString += "$"; + const regex = new RegExp(regexString); + const rawRoutePath = path; + return { + path, + ...typeof route === "function" ? { handler: route } : route, + match: path => { + const match = path.match(regex); + if (!match) + return undefined; + const params = {}; + for (let i = 0; i < varGroups.length; i++) { + const groupName = varGroups[i]; + const group = match[i + 1]; + if (group === undefined) { + console.warn(`${rawRoutePath} matched, but $${groupName} was unset`); + return undefined; + } + params[groupName] = group; + } + return params; + }, + }; + } + exports.default = Route; +}); +define("endpoint/author/EndpointAuthorDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_5 = __importDefault(Endpoint_5); + exports.default = (0, Endpoint_5.default)("/author/delete", "post") + .noResponse(); +}); +define("ui/component/core/Dialog", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_15, State_15) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_15 = __importDefault(Component_15); + State_15 = __importDefault(State_15); + const Dialog = Component_15.default.Builder(() => { + const opened = (0, State_15.default)(false); + const willOpen = (0, State_15.default)(false); + const willClose = (0, State_15.default)(false); + let modal = true; + let unbind; + const dialog = (0, Component_15.default)("dialog") + .style("dialog") + .style.bind(opened, "dialog--open") + .extend(dialog => ({ + opened, + willClose, + willOpen, + setNotModal: (notModal = true) => { + modal = !notModal; + dialog.style.toggle(notModal, "dialog--not-modal"); + return dialog; + }, + setFullscreen: (fullscreen = true) => dialog.style.toggle(fullscreen, "dialog--fullscreen"), + open: () => { + dialog.willOpen.value = true; + if (!dialog.willOpen.value) + return dialog; + unbind?.(); + dialog.element[modal ? "showModal" : "show"](); + dialog.opened.value = true; + dialog.willOpen.value = false; + return dialog; + }, + close: () => { + dialog.willClose.value = true; + if (!dialog.willClose.value) + return dialog; + unbind?.(); + dialog.element.close(); + dialog.opened.value = false; + dialog.willClose.value = false; + return dialog; + }, + toggle: (open = !dialog.opened.value) => { + const willChangeStateName = open ? "willOpen" : "willClose"; + dialog[willChangeStateName].value = true; + if (!dialog[willChangeStateName].value) + return dialog; + unbind?.(); + if (open) + dialog.element[modal ? "showModal" : "show"](); + else + dialog.element.close(); + dialog.opened.value = open ?? !dialog.opened.value; + dialog[willChangeStateName].value = false; + return dialog; + }, + bind: state => { + unbind?.(); + unbind = state.use(dialog, open => { + const willChangeStateName = open ? "willOpen" : "willClose"; + dialog[willChangeStateName].value = true; + if (open) + dialog.element[modal ? "showModal" : "show"](); + else + dialog.element.close(); + dialog.opened.value = open; + dialog[willChangeStateName].value = false; + }); + return dialog; + }, + unbind: () => { + unbind?.(); + return dialog; + }, + })); + return dialog; + }); + exports.default = Dialog; +}); +define("ui/component/core/BlockDialog", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Dialog", "utility/Task"], function (require, exports, Component_16, Block_3, Dialog_1, Task_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_16 = __importDefault(Component_16); + Block_3 = __importDefault(Block_3); + Dialog_1 = __importDefault(Dialog_1); + Task_2 = __importDefault(Task_2); + const BlockDialog = Component_16.default.Builder((component) => { + const dialog = component.and(Dialog_1.default).and(Block_3.default) + .viewTransition() + .style.remove("block"); + dialog + .style("dialog-block-wrapper") + .style.bind(dialog.opened.not, "dialog-block-wrapper--closed"); + const block = (0, Block_3.default)() + .style("dialog-block") + .style.bind(dialog.opened.not, "dialog-block--closed") + .appendTo(dialog); + dialog + .extend(dialog => ({ + type: block.type, + content: block.content, + setActionsMenu: block.setActionsMenu, + })) + .extendJIT("header", () => block.header) + .extendJIT("title", () => block.title) + .extendJIT("primaryActions", () => block.primaryActions) + .extendJIT("description", () => block.description) + .extendJIT("footer", () => block.footer) + .extendJIT("actionsMenuButton", () => block.actionsMenuButton); + const superOpen = dialog.open; + return dialog.extend(dialog => ({ + open() { + superOpen(); + block.style("dialog-block--opening"); + void Task_2.default.yield().then(() => block.style.remove("dialog-block--opening")); + return dialog; + }, + })); + }); + exports.default = BlockDialog; +}); +define("endpoint/auth/EndpointAuthServices", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_6 = __importDefault(Endpoint_6); + exports.default = (0, Endpoint_6.default)("/auth/services", "get"); +}); +define("ui/component/core/Checkbutton", ["require", "exports", "ui/Component", "ui/component/core/Button", "utility/State"], function (require, exports, Component_17, Button_3, State_16) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_17 = __importDefault(Component_17); + Button_3 = __importDefault(Button_3); + State_16 = __importDefault(State_16); + const Checkbutton = Component_17.default.Builder("label", (component) => { + const input = (0, Component_17.default)("input") + .style("checkbutton-input") + .attributes.set("type", "checkbox"); + const inputElement = input.element; + const state = (0, State_16.default)(false); + let unuse; + const checkbutton = component + .and(Button_3.default) + .style("checkbutton") + .tabIndex("auto") + .ariaChecked(state) + .ariaRole("checkbox") + .append(input) + .extend(() => ({ + input, + checked: state, + isChecked: () => inputElement.checked, + setChecked: (checked) => { + if (checked === inputElement.checked) + return checkbutton; + if (unuse) { + checkbutton.event.emit("trySetChecked", checked); + return checkbutton; + } + inputElement.checked = checked; + onChange(); + return checkbutton; + }, + use: sourceState => { + unuse = sourceState.use(checkbutton, checked => { + if (inputElement.checked === checked) + return; + inputElement.checked = checked; + onChange(); + }); + return checkbutton; + }, + unuse: () => { + unuse?.(); + unuse = undefined; + return checkbutton; + }, + })); + input.event.subscribe("change", () => { + if (unuse) { + const checked = inputElement.checked; + inputElement.checked = !checked; // undo because it's managed by a State + checkbutton.event.emit("trySetChecked", checked); + return; + } + onChange(); + }); + function onChange() { + state.value = inputElement.checked; + checkbutton.style.toggle(inputElement.checked, "checkbutton--checked"); + checkbutton.event.emit("setChecked", inputElement.checked); + } + return checkbutton; + }); + exports.default = Checkbutton; +}); +define("ui/component/OAuthService", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Checkbutton", "utility/State"], function (require, exports, Session_1, Component_18, Checkbutton_1, State_17) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_1 = __importDefault(Session_1); + Component_18 = __importDefault(Component_18); + Checkbutton_1 = __importDefault(Checkbutton_1); + State_17 = __importDefault(State_17); + const OAuthService = Component_18.default.Builder((component, service, reauthDangerToken) => { + const authedAtStart = !!Session_1.default.Auth.get(service.name); + const authorisationState = Session_1.default.Auth.authorisations.map(component, authorisations => authorisations.find(authorisation => authorisation.service === service.name)); + const isAuthed = State_17.default.Truthy(component, authorisationState); + const button = component + .and(Checkbutton_1.default) + .setChecked(authedAtStart) + .style("oauth-service") + .ariaRole("button") + .attributes.remove("aria-checked") + .style.bind(isAuthed, "oauth-service--authenticated") + .style.setVariable("colour", `#${service.colour.toString(16)}`) + .append((0, Component_18.default)("img") + .style("oauth-service-icon") + .attributes.set("src", service.icon)) + .append((0, Component_18.default)() + .style("oauth-service-name") + .text.set(service.name)) + .extend(button => ({})); + if (!reauthDangerToken) + (0, Component_18.default)() + .style("oauth-service-state") + .style.bind(isAuthed, "oauth-service-state--authenticated") + .style.bind(button.hoveredOrFocused, "oauth-service-state--focus") + .appendTo((0, Component_18.default)() + .style("oauth-service-state-wrapper") + .style.bind(button.hoveredOrFocused, "oauth-service-state-wrapper--focus") + .appendTo(button)); + const username = (0, Component_18.default)() + .style("oauth-service-username") + .style.bind(isAuthed, "oauth-service-username--has-username") + .ariaHidden() + .appendTo(button); + authorisationState.use(button, authorisation => { + button.ariaLabel.use(quilt => quilt[`view/account/auth/service/accessibility/${authorisation ? "disconnect" : "connect"}`](service.name, authorisation?.display_name)); + username.text.set(authorisation?.display_name ?? ""); + }); + button.onRooted(() => { + button.event.subscribe("click", async (event) => { + event.preventDefault(); + if (reauthDangerToken) { + if (!Session_1.default.Auth.canRequestDangerToken()) + return; + const granted = await Session_1.default.Auth.requestDangerToken(reauthDangerToken, service); + if (granted) + button.event.bubble("dangerTokenGranted", reauthDangerToken); + else + ; + // TODO show notification + return; + } + let auth = Session_1.default.Auth.get(service.name); + if (auth) + await Session_1.default.Auth.unauth(auth.id); + else + await Session_1.default.Auth.auth(service); + auth = Session_1.default.Auth.get(service.name); + event.component.setChecked(!!auth); + }); + }); + return button; + }); + exports.default = OAuthService; +}); +define("ui/component/OAuthServices", ["require", "exports", "endpoint/auth/EndpointAuthServices", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/OAuthService", "utility/Objects"], function (require, exports, EndpointAuthServices_1, Session_2, Component_19, Block_4, OAuthService_1, Objects_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthServices_1 = __importDefault(EndpointAuthServices_1); + Session_2 = __importDefault(Session_2); + Component_19 = __importDefault(Component_19); + Block_4 = __importDefault(Block_4); + OAuthService_1 = __importDefault(OAuthService_1); + Objects_2 = __importDefault(Objects_2); + const OAuthServices = Component_19.default.Builder(async (component, state, reauthDangerToken) => { + const block = component + .and(Block_4.default) + .viewTransition("oauth-services") + .style("oauth-service-container") + .style.toggle(!!reauthDangerToken, "oauth-service-container--reauth-list") + .extend(block => ({})); + if (reauthDangerToken) { + block.type("flush"); + } + else { + state.use(component, state => { + block.title.text.use(`view/account/auth/${state}/title`); + block.description.text.use(`view/account/auth/${state}/description`); + }); + } + const list = (0, Component_19.default)() + .style("oauth-service-list") + .appendTo(block); + const services = await EndpointAuthServices_1.default.query(); + if (services instanceof Error) { + console.error(services); + return block; + } + for (const service of Objects_2.default.values(services.data)) + if (!reauthDangerToken || Session_2.default.Auth.isAuthed(service)) + (0, OAuthService_1.default)(service, reauthDangerToken) + // .event.subscribe("dangerTokenGranted", event => block.event.emit("dangerTokenGranted")) + .appendTo(list); + return block; + }); + exports.default = OAuthServices; +}); +define("ui/component/core/ConfirmDialog", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/BlockDialog", "ui/component/core/Button", "ui/component/core/Paragraph", "ui/component/OAuthServices", "utility/State"], function (require, exports, Session_3, Component_20, BlockDialog_1, Button_4, Paragraph_2, OAuthServices_1, State_18) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_3 = __importDefault(Session_3); + Component_20 = __importDefault(Component_20); + BlockDialog_1 = __importDefault(BlockDialog_1); + Button_4 = __importDefault(Button_4); + Paragraph_2 = __importDefault(Paragraph_2); + OAuthServices_1 = __importDefault(OAuthServices_1); + State_18 = __importDefault(State_18); + const ConfirmDialog = Object.assign(Component_20.default.Builder(async (component, definition) => { + const dialog = component.and(BlockDialog_1.default); + const state = (0, State_18.default)(undefined); + dialog.title.text.use(definition?.titleTranslation ?? "shared/prompt/confirm"); + const cancelButton = (0, Button_4.default)() + .text.use(definition?.confirmButtonTranslation ?? "shared/action/cancel") + .appendTo(dialog.footer.right); + const confirmButton = (0, Button_4.default)() + .type("primary") + .text.use(definition?.confirmButtonTranslation ?? "shared/action/confirm") + .appendTo(dialog.footer.right); + if (definition?.dangerToken) { + confirmButton.setDisabled(true, "danger-token"); + (0, Paragraph_2.default)() + .text.use("shared/prompt/reauth") + .appendTo(dialog.content); + const authServices = await (0, OAuthServices_1.default)(Session_3.default.Auth.state, definition.dangerToken); + authServices + .event.subscribe("dangerTokenGranted", () => confirmButton.setDisabled(false, "danger-token")) + .appendTo(dialog.content); + } + return dialog + .extend(dialog => ({ + state, + cancelButton, + confirmButton, + await(owner) { + state.value = undefined; + dialog.open(); + return new Promise(resolve => dialog.state.await(owner, [true, false], resolve)); + }, + cancel() { + state.value = false; + dialog.close(); + }, + confirm() { + state.value = true; + dialog.close(); + }, + })) + .onRooted(dialog => { + dialog.cancelButton.event.subscribe("click", dialog.cancel); + dialog.confirmButton.event.subscribe("click", dialog.confirm); + }); + }), { + prompt: async (owner, definition) => (await ConfirmDialog(definition)) + .appendTo(document.body) + .event.subscribe("close", event => event.component.event.subscribe("transitionend", event => event.component.remove())) + .await(owner), + }); + exports.default = ConfirmDialog; +}); +define("endpoint/author/EndpointAuthorCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_7 = __importDefault(Endpoint_7); + exports.default = (0, Endpoint_7.default)("/author/create", "post"); +}); +define("endpoint/author/EndpointAuthorUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_8 = __importDefault(Endpoint_8); + exports.default = (0, Endpoint_8.default)("/author/update", "post"); +}); +define("ui/component/core/LabelledRow", ["require", "exports", "ui/Component", "ui/component/core/Label"], function (require, exports, Component_21, Label_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_21 = __importDefault(Component_21); + const LabelledRow = Component_21.default.Builder((row) => { + row.style("labelled-row"); + let label = (0, Label_1.AutoLabel)().style("labelled-row-label").appendTo(row); + let content = (0, Component_21.default)().style("labelled-row-content").appendTo(row); + return row + .extend(row => ({ + label, content, + })) + .extendMagic("label", row => ({ + get: () => label, + set: newLabel => { + if (label === newLabel) + return; + label.element.replaceWith(newLabel.element); + label = newLabel; + }, + })) + .extendMagic("content", row => ({ + get: () => content, + set: newContent => { + if (content === newContent) + return; + content.element.replaceWith(newContent.element); + content = newContent; + }, + })); + }); + exports.default = LabelledRow; +}); +define("ui/component/core/LabelledTable", ["require", "exports", "ui/Component", "ui/component/core/LabelledRow"], function (require, exports, Component_22, LabelledRow_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_22 = __importDefault(Component_22); + LabelledRow_1 = __importDefault(LabelledRow_1); + const LabelledTable = Component_22.default.Builder((table) => { + table.style("labelled-table"); + let labelInitialiser; + let factory; + return table.extend(table => ({ + label: initialiser => { + labelInitialiser = initialiser; + return factory ??= { + content: contentInitialiser => { + const row = (0, LabelledRow_1.default)() + .style("labelled-row--in-labelled-table") + .appendTo(table); + row.label = labelInitialiser(row.label, row); + row.content = contentInitialiser(row.content, row.label, row) ?? row.content; + labelInitialiser = undefined; + return table; + }, + }; + }, + })); + }); + exports.default = LabelledTable; +}); +define("ui/component/core/TextInput", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_23, Input_1, StringApplicator_5, State_19) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_23 = __importDefault(Component_23); + Input_1 = __importDefault(Input_1); + StringApplicator_5 = __importDefault(StringApplicator_5); + State_19 = __importDefault(State_19); + const TextInput = Component_23.default.Builder("input", (component) => { + let shouldIgnoreInputEvent = false; + let filterFunction; + const input = component + .and(Input_1.default) + .style("text-input") + .attributes.set("type", "text") + .extend(input => ({ + value: "", + state: (0, State_19.default)(""), + default: (0, StringApplicator_5.default)(input, value => { + if (input.value === "") { + input.value = value ?? ""; + input.state.value = value ?? ""; + input.length.value = value?.length ?? 0; + } + }), + placeholder: (0, StringApplicator_5.default)(input, value => { + input.attributes.set("placeholder", value); + }), + ignoreInputEvent: (ignore = true) => { + shouldIgnoreInputEvent = ignore; + return input; + }, + filter: filter => { + filterFunction = filter; + return input; + }, + })) + .extendMagic("value", input => ({ + get: () => input.element.value || "", + set: (value) => { + input.element.value = value; + input.state.value = value; + input.length.value = value.length; + }, + })); + input.length.value = 0; + input.event.subscribe(["input", "change"], event => { + const element = input.element.asType("input"); + if (filterFunction && element) { + if (event.type === "change") { + input.value = filterFunction(input.value, "", true); + } + else { + let { selectionStart, selectionEnd, value } = element; + const hasSelection = selectionStart !== null || selectionEnd !== null; + selectionStart ??= value.length; + selectionEnd ??= value.length; + const beforeSelection = filterFunction(value.slice(0, selectionStart), "", false); + const selection = filterFunction(value.slice(selectionStart, selectionEnd), beforeSelection, false); + const afterSelection = filterFunction(value.slice(selectionEnd), selection || beforeSelection, false); + input.value = beforeSelection + selection + afterSelection; + if (hasSelection) + element.setSelectionRange(beforeSelection.length, beforeSelection.length + selection.length); + } + } + if (shouldIgnoreInputEvent) + return; + input.state.value = input.value; + input.length.value = input.value.length; + }); + return input; + }); + exports.default = TextInput; +}); +define("ui/component/core/TextInputBlock", ["require", "exports", "ui/Component", "ui/component/core/TextInput"], function (require, exports, Component_24, TextInput_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_24 = __importDefault(Component_24); + TextInput_1 = __importDefault(TextInput_1); + const TextInputBlock = Component_24.default.Builder((component) => { + const inputs = []; + const block = component + .style("text-input-block") + .extend(block => ({ + inputs, + addInput: (initialiser) => { + const input = (0, TextInput_1.default)() + .style("text-input-block-input") + .tweak(initialiser) + .event.subscribe("remove", () => { + inputs.filterInPlace(i => i !== input); + const firstInput = inputs.at(0); + firstInput?.style("text-input-block-input--first"); + firstInput?.previousSibling?.remove(); // remove previous divider if it exists + inputs.at(-1)?.style("text-input-block-input--last"); + inputs.at(-1)?.parent?.style("text-input-block-input-wrapper--last"); + }) + .appendTo((0, Component_24.default)() + .style("text-input-block-input-wrapper") + .appendTo(block)); + if (!inputs.length) + input.style("text-input-block-input--first"); + inputs.at(-1)?.style.remove("text-input-block-input--last"); + inputs.at(-1)?.parent?.style.remove("text-input-block-input-wrapper--last"); + inputs.push(input); + input.style("text-input-block-input--last"); + input.parent?.style("text-input-block-input-wrapper--last"); + return block; + }, + })); + return block; + }); + exports.default = TextInputBlock; +}); +define("ui/component/core/LabelledTextInputBlock", ["require", "exports", "ui/Component", "ui/component/core/Label", "ui/component/core/TextInputBlock"], function (require, exports, Component_25, Label_2, TextInputBlock_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_25 = __importDefault(Component_25); + TextInputBlock_1 = __importDefault(TextInputBlock_1); + const LabelledTextInputBlock = Component_25.default.Builder((block) => { + block.style("labelled-text-input-block", "labelled-row") + .ariaRole("group"); + const labels = (0, Component_25.default)() + .style("labelled-text-input-block-labels") + .appendTo(block); + const inputs = (0, TextInputBlock_1.default)() + .style("labelled-text-input-block-inputs") + .appendTo(block); + let labelInitialiser; + let factory; + return block.extend(block => ({ + labels, + inputs, + label: initialiser => { + labelInitialiser = initialiser; + return factory ??= { + input: inputInitialiser => { + const rowNumber = inputs.inputs.length + 1; + const label = (0, Label_2.AutoLabel)() + .style("labelled-text-input-block-label") + .style.setProperty("grid-row", `${rowNumber}`) + .appendTo(labels); + labelInitialiser(label); + inputs.addInput(input => input + .style("labelled-text-input-block-input") + .style.setProperty("grid-row", `${rowNumber}`) + .tweak(input => inputInitialiser(input.setLabel(label), label))); + labelInitialiser = undefined; + return block; + }, + }; + }, + })); + }); + exports.default = LabelledTextInputBlock; +}); +define("ui/Announcer", ["require", "exports", "ui/Component"], function (require, exports, Component_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_26 = __importDefault(Component_26); + var Announcer; + (function (Announcer) { + const assertive = (0, Component_26.default)() + .attributes.set("aria-live", "assertive") + .style.setProperty("opacity", "0") + .style.setProperty("user-select", "none") + .style.setProperty("pointer-events", "none") + .style.setProperty("position", "fixed") + .appendTo(document.body); + const polite = (0, Component_26.default)() + .attributes.set("aria-live", "polite") + .style.setProperty("opacity", "0") + .style.setProperty("user-select", "none") + .style.setProperty("pointer-events", "none") + .style.setProperty("position", "fixed") + .appendTo(document.body); + function interrupt(id, announcer) { + announceInternal(assertive, id, announcer); + } + Announcer.interrupt = interrupt; + function announce(id, announcer) { + announceInternal(polite, id, announcer); + } + Announcer.announce = announce; + function announceInternal(within, id, announcer) { + const components = []; + announcer(keyOrHandler => { + components.push((0, Component_26.default)("p") + .attributes.set("data-id", id) + .text.use(keyOrHandler)); + }); + const current = getAnnouncementElements(within, id); + if (current.length) { + const currentText = current.map(el => el.textContent).join("\n"); + const newText = components.map(component => component.element.textContent).join("\n"); + if (newText === currentText) + return; + for (const element of current) + element.remove(); + } + for (const component of components) + component.appendTo(within); + } + function getAnnouncementElements(within, id) { + return [ + ...within.element.querySelectorAll(`[data-id="${id}"]`), + ]; + } + })(Announcer || (Announcer = {})); + exports.default = Announcer; +}); +define("ui/component/core/RadioButton", ["require", "exports", "ui/Component", "ui/component/core/Checkbutton"], function (require, exports, Component_27, Checkbutton_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_27 = __importDefault(Component_27); + Checkbutton_2 = __importDefault(Checkbutton_2); + exports.default = Component_27.default.Builder(() => { + const cb = (0, Checkbutton_2.default)(); + cb.ariaRole("radio"); + cb.input.attributes.set("type", "radio"); + return cb; + }); +}); +define("ui/view/shared/ext/ViewTransition", ["require", "exports", "ui/Component", "utility/Arrays"], function (require, exports, Component_28, Arrays_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_28 = __importDefault(Component_28); + Arrays_3 = __importDefault(Arrays_3); + var ViewTransition; + (function (ViewTransition) { + const DATA_VIEW_TRANSITION_NAME = "data-view-transition-name"; + const DATA_SUBVIEW_TRANSITION_NAME = "data-subview-transition-name"; + const DATA_ID = "data-view-transition-id"; + const VIEW_TRANSITION_CLASS_VIEW = "view-transition"; + const VIEW_TRANSITION_CLASS_SUBVIEW = "subview-transition"; + const VIEW_TRANSITION_CLASS_DELAY = "view-transition-delay"; + const PADDING = 100; + Component_28.default.extend(component => component.extend(component => ({ + viewTransition(name) { + if (name) { + name = name.replace(/[^a-z0-9-]+/g, "-").toLowerCase(); + component.attributes.set(DATA_VIEW_TRANSITION_NAME, name); + component.attributes.compute(DATA_ID, () => `${id++}`); + } + else { + component.attributes.remove(DATA_VIEW_TRANSITION_NAME); + component.attributes.remove(DATA_ID); + } + return component; + }, + subviewTransition(name) { + if (name) { + name = name.replace(/[^a-z0-9-]+/g, "-").toLowerCase(); + component.attributes.set(DATA_SUBVIEW_TRANSITION_NAME, name); + component.attributes.compute(DATA_ID, () => `${id++}`); + } + else { + component.attributes.remove(DATA_SUBVIEW_TRANSITION_NAME); + component.attributes.remove(DATA_ID); + } + return component; + }, + }))); + let id = 0; + let i = 0; + let queuedUnapply; + function perform(type, name, swap) { + queuedUnapply = undefined; + if (typeof name === "function") { + swap = name; + name = undefined; + } + reapply(type, name); + const transition = document.startViewTransition(async () => { + await swap(); + reapply(type, name); + }); + const id = queuedUnapply = i++; + void transition.finished.then(() => { + if (queuedUnapply !== id) + // another view transition started, no unapply + return; + unapply(type); + }); + return transition; + } + ViewTransition.perform = perform; + function reapply(type, name) { + const components = getComponents(type, name).filter(isInView); + let i = 0; + if (type === "view") + for (const component of components) { + component.classes.add(VIEW_TRANSITION_CLASS_VIEW); + const name = component.attributes.get(DATA_VIEW_TRANSITION_NAME); + component.style.setVariable("view-transition-delay", `${VIEW_TRANSITION_CLASS_DELAY}-${i}`); + component.style.setProperty("view-transition-name", `${VIEW_TRANSITION_CLASS_VIEW}-${name}-${i++}`); + } + else + for (const component of components) { + component.classes.add(VIEW_TRANSITION_CLASS_SUBVIEW); + const name = component.attributes.get(DATA_SUBVIEW_TRANSITION_NAME); + const id = +component.attributes.get(DATA_ID) || 0; + component.style.setProperty("view-transition-name", `${VIEW_TRANSITION_CLASS_SUBVIEW}-${name}-${id}`); + component.style.setVariable("view-transition-delay", `${VIEW_TRANSITION_CLASS_DELAY}-${i++}`); + } + } + ViewTransition.reapply = reapply; + function unapply(type) { + for (const component of getComponents(type)) { + component.classes.remove(VIEW_TRANSITION_CLASS_VIEW); + component.classes.remove(VIEW_TRANSITION_CLASS_SUBVIEW); + component.style.removeProperties("view-transition-name"); + component.style.removeVariables("view-transition-delay"); + } + } + ViewTransition.unapply = unapply; + function isInView(component) { + const rect = component.element.getBoundingClientRect(); + return true + && rect.bottom > -PADDING && rect.top < window.innerHeight + PADDING + && rect.right > -PADDING && rect.left < window.innerWidth + PADDING; + } + function getComponents(type, name) { + return [...document.querySelectorAll(`[${type === "view" ? DATA_VIEW_TRANSITION_NAME : DATA_SUBVIEW_TRANSITION_NAME}${name ? `="${name}"` : ""}]`)] + .map(e => e.component) + .filter(Arrays_3.default.filterNullish); + } + })(ViewTransition || (ViewTransition = {})); + exports.default = ViewTransition; +}); +define("ui/component/core/TextEditor", ["require", "exports", "lang/en-nz", "markdown-it", "model/Session", "prosemirror-commands", "prosemirror-dropcursor", "prosemirror-example-setup", "prosemirror-gapcursor", "prosemirror-history", "prosemirror-inputrules", "prosemirror-keymap", "prosemirror-markdown", "prosemirror-model", "prosemirror-schema-list", "prosemirror-state", "prosemirror-transform", "prosemirror-view", "ui/Announcer", "ui/Component", "ui/component/core/Button", "ui/component/core/Checkbutton", "ui/component/core/Dialog", "ui/component/core/ext/Input", "ui/component/core/Popover", "ui/component/core/RadioButton", "ui/component/core/Slot", "ui/utility/StringApplicator", "ui/utility/Viewport", "ui/view/shared/ext/ViewTransition", "utility/Arrays", "utility/Define", "utility/Objects", "utility/State", "utility/Store", "utility/string/MarkdownItHTML", "utility/Time", "w3c-keyname"], function (require, exports, en_nz_3, markdown_it_2, Session_4, prosemirror_commands_1, prosemirror_dropcursor_1, prosemirror_example_setup_1, prosemirror_gapcursor_1, prosemirror_history_1, prosemirror_inputrules_1, prosemirror_keymap_1, prosemirror_markdown_1, prosemirror_model_1, prosemirror_schema_list_1, prosemirror_state_1, prosemirror_transform_1, prosemirror_view_1, Announcer_1, Component_29, Button_5, Checkbutton_3, Dialog_2, Input_2, Popover_2, RadioButton_1, Slot_2, StringApplicator_6, Viewport_3, ViewTransition_1, Arrays_4, Define_4, Objects_3, State_20, Store_3, MarkdownItHTML_2, Time_5, w3c_keyname_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_3 = __importDefault(en_nz_3); + markdown_it_2 = __importDefault(markdown_it_2); + Session_4 = __importDefault(Session_4); + Announcer_1 = __importDefault(Announcer_1); + Component_29 = __importDefault(Component_29); + Button_5 = __importDefault(Button_5); + Checkbutton_3 = __importDefault(Checkbutton_3); + Dialog_2 = __importDefault(Dialog_2); + Input_2 = __importDefault(Input_2); + Popover_2 = __importDefault(Popover_2); + RadioButton_1 = __importDefault(RadioButton_1); + Slot_2 = __importDefault(Slot_2); + StringApplicator_6 = __importDefault(StringApplicator_6); + Viewport_3 = __importDefault(Viewport_3); + ViewTransition_1 = __importDefault(ViewTransition_1); + Arrays_4 = __importDefault(Arrays_4); + Define_4 = __importDefault(Define_4); + Objects_3 = __importDefault(Objects_3); + State_20 = __importDefault(State_20); + Store_3 = __importDefault(Store_3); + MarkdownItHTML_2 = __importDefault(MarkdownItHTML_2); + Time_5 = __importDefault(Time_5); + w3c_keyname_1 = __importDefault(w3c_keyname_1); + function vars(...params) { } + function types() { } + //////////////////////////////////// + //#region Module Augmentation + const baseKeyName = w3c_keyname_1.default.keyName; + w3c_keyname_1.default.keyName = (event) => { + const keyboardEvent = event; + if (keyboardEvent.code.startsWith("Numpad") && !keyboardEvent.shiftKey && (keyboardEvent.ctrlKey || keyboardEvent.altKey)) { + Object.defineProperty(event, "shiftKey", { value: true }); + const str = keyboardEvent.code.slice(6); + if (str === "Decimal") + return "."; + if (!isNaN(+str)) + return str; + } + return baseKeyName(event); + }; + (0, Define_4.default)(prosemirror_model_1.ResolvedPos.prototype, "closest", function (node, attrsOrStartingAtDepth, startingAtDepth) { + if (typeof attrsOrStartingAtDepth === "number") { + startingAtDepth = attrsOrStartingAtDepth; + attrsOrStartingAtDepth = undefined; + } + const attrs = attrsOrStartingAtDepth; + startingAtDepth ??= this.depth; + for (let depth = startingAtDepth; depth >= 0; depth--) { + const current = this.node(depth); + if (current.type === node && (!attrs || current.hasAttrs(attrs))) + return current; + } + return undefined; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "matches", function (type, attrs) { + if (type !== undefined && this.type !== type) + return false; + return attrs === undefined || this.hasAttrs(attrs); + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "hasAttrs", function (attrs) { + for (const [attr, val] of Object.entries(attrs)) + if (this.attrs[attr] !== val) + return false; + return true; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "pos", function (document) { + if (document === this) + return 0; + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node === this) { + result = pos; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "parent", function (document) { + if (document === this) + return undefined; + // eslint-disable-next-line @typescript-eslint/no-this-alias + const searchNode = this; + return searchChildren(document); + function searchChildren(parent) { + let result; + parent.forEach(child => { + result ??= (child === searchNode ? parent : undefined) + ?? searchChildren(child); + }); + return result; + } + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "depth", function (document) { + if (document === this) + return 0; + // eslint-disable-next-line @typescript-eslint/no-this-alias + const searchNode = this; + return searchChildren(document, 1); + function searchChildren(parent, depth) { + let result; + parent.forEach(child => { + result ??= (child === searchNode ? depth : undefined) + ?? searchChildren(child, depth + 1); + }); + return result; + } + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "pos", function (document) { + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node.content === this) { + result = pos + 1; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "range", function (document) { + const pos = this.pos(document); + if (!pos) + return undefined; + const $from = document.resolve(pos); + const $to = document.resolve(pos + this.size); + return new prosemirror_model_1.NodeRange($from, $to, Math.min($from.depth, $to.depth)); + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "parent", function (document) { + if (document.content === this) + return document; + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node.content === this) { + result = node; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_transform_1.Transform.prototype, "stripNodeType", function (from, type) { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const tr = this; + let range = from instanceof prosemirror_model_1.Fragment ? from.range(tr.doc) : from; + if (!range) + return this; + while (stripRange()) + ; + return this; + function stripRange() { + let stripped = false; + range.parent.forEach((node, pos, index) => { + if (stripped) + return; + if (index >= range.startIndex && index < range.endIndex) { + if (node.type === type) { + stripNode(node); + stripped = true; + return; + } + if (stripDescendants(node)) { + stripped = true; + return; + } + } + }); + return stripped; + } + function stripDescendants(node) { + let stripped = false; + node.descendants((node, pos) => { + if (stripped) + return; + if (node.type === type) { + stripNode(node); + stripped = true; + return; + } + }); + return stripped; + } + function stripNode(node) { + const nodePos = node.pos(tr.doc); + if (nodePos === undefined) + throw new Error("Unable to continue stripping, no pos"); + const liftRange = node.content.range(tr.doc); + if (!liftRange) + throw new Error("Unable to continue stripping, unable to resolve node range"); + const depth = (0, prosemirror_transform_1.liftTarget)(liftRange); + if (depth !== null) + tr.lift(liftRange, depth); + if (range) { + let start = range.$from.pos; + start = start <= nodePos ? start : start - 1; + let end = range.$to.pos; + end = end < nodePos + node.nodeSize ? end - 1 : end - 2; + const newRange = tr.doc.resolve(start).blockRange(tr.doc.resolve(end)); + if (!newRange) + throw new Error("Unable to continue stripping, unable to resolve new range"); + range = newRange; + } + } + }); + //#endregion + types(); + Session_4.default.setClearedWithSessionChange("textEditorDrafts"); + //#endregion + vars(w3c_keyname_1.default.keyName); + types(); + types(); + const schema = new prosemirror_model_1.Schema({ + nodes: Objects_3.default.filterNullish({ + ...prosemirror_markdown_1.schema.spec.nodes.toObject(), + image: undefined, + heading: { + ...prosemirror_markdown_1.schema.spec.nodes.get("heading"), + content: "text*", + toDOM(node) { + const heading = (0, Component_29.default)(`h${node.attrs.level}`); + heading.style("markdown-heading", `markdown-heading-${node.attrs.level}`); + return { + dom: heading.element, + contentDOM: heading.element, + }; + }, + }, + text_align: { + attrs: { align: { default: "left", validate: (value) => value === "left" || value === "center" || value === "right" } }, + content: "block+", + group: "block", + defining: true, + parseDOM: [ + { tag: "center", getAttrs: () => ({ align: "center" }) }, + { + tag: "*", getAttrs: (element) => { + const textAlign = element.style.getPropertyValue("text-align"); + if (!textAlign) + return false; + return { + align: textAlign === "justify" || textAlign === "start" ? "left" + : textAlign === "end" ? "right" + : textAlign, + }; + }, + priority: 51, + }, + ], + toDOM: (node) => ["div", Objects_3.default.filterNullish({ + "class": node.attrs.align === "left" ? "align-left" : undefined, + "style": `text-align:${node.attrs.align}`, + }), 0], + }, + }), + marks: { + ...prosemirror_markdown_1.schema.spec.marks.toObject(), + underline: { + parseDOM: [ + { tag: "u" }, + { style: "text-decoration=underline", clearMark: m => m.type.name === "underline" }, + ], + toDOM() { return ["u"]; }, + }, + strikethrough: { + parseDOM: [ + { tag: "s" }, + { style: "text-decoration=line-through", clearMark: m => m.type.name === "strikethrough" }, + ], + // toDOM () { return ["s"] }, + toDOM() { + const span = document.createElement("span"); + span.style.setProperty("text-decoration", "line-through"); + return span; + }, + }, + subscript: { + parseDOM: [ + { tag: "sub" }, + ], + toDOM() { return ["sub"]; }, + }, + superscript: { + parseDOM: [ + { tag: "sup" }, + ], + toDOM() { return ["sup"]; }, + }, + }, + }); + //#endregion + vars(schema); + types(); + //////////////////////////////////// + //////////////////////////////////// + //#region Markdown + const REGEX_ATTRIBUTE = (() => { + const attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*"; + const unquoted = "[^\"'=<>`\\x00-\\x20]+"; + const single_quoted = "'[^']*'"; + const double_quoted = '"[^"]*"'; + const attr_value = `(?:${unquoted}|${single_quoted}|${double_quoted})`; + const attribute = `(${attr_name})(?:\\s*=\\s*(${attr_value}))(?= |$)`; + return new RegExp(attribute, "g"); + })(); + const REGEX_CSS_PROPERTY = /^[-a-zA-Z_][a-zA-Z0-9_-]*$/; + const markdown = new markdown_it_2.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_2.default.use(markdown, MarkdownItHTML_2.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + markdown.inline.ruler.enable("strikethrough"); + markdown.inline.ruler2.enable("strikethrough"); + //////////////////////////////////// + //#region Underline Parse + // Based on https://github.com/markdown-it/markdown-it/blob/0fe7ccb4b7f30236fb05f623be6924961d296d3d/lib/rules_inline/strikethrough.mjs + markdown.inline.ruler.before("emphasis", "underline", function underline_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent || marker !== 0x5F /* _ */) + return false; + const scanned = state.scanDelims(state.pos, true); + let len = scanned.length; + if (len < 2) + return false; + const ch = String.fromCharCode(marker); + let token; + if (len % 2) { + token = state.push("text", "", 0); + token.content = ch; + len--; + } + for (let i = 0; i < len; i += 2) { + token = state.push("text", "", 0); + token.content = ch + ch; + state.delimiters.push({ + marker, + length: 0, // disable "rule of 3" length checks meant for emphasis + token: state.tokens.length - 1, + end: -1, + open: scanned.can_open, + close: scanned.can_close, + }); + } + state.pos += scanned.length; + return true; + }); + markdown.inline.ruler2.before("emphasis", "underline", function underline_postProcess(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + const delimiters = tokens_meta[curr]?.delimiters; + if (delimiters) + postProcess(state, delimiters); + } + state.delimiters = state.delimiters.filter(delim => delim.marker !== 0x5F /* _ */); + return true; + function postProcess(state, delimiters) { + let token; + const loneMarkers = []; + const max = delimiters.length; + for (let i = 0; i < max; i++) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x5F /* _ */) + continue; + if (startDelim.end === -1) + continue; + const endDelim = delimiters[startDelim.end]; + token = state.tokens[startDelim.token]; + token.type = "u_open"; + token.tag = "u"; + token.nesting = 1; + token.markup = "__"; + token.content = ""; + token = state.tokens[endDelim.token]; + token.type = "u_close"; + token.tag = "u"; + token.nesting = -1; + token.markup = "__"; + token.content = ""; + if (state.tokens[endDelim.token - 1].type === "text" && + state.tokens[endDelim.token - 1].content === "_") { + loneMarkers.push(endDelim.token - 1); + } + } + // If a marker sequence has an odd number of characters, it's splitted + // like this: `_____` -> `_` + `__` + `__`, leaving one marker at the + // start of the sequence. + // + // So, we have to move all those markers after subsequent u_close tags. + // + while (loneMarkers.length) { + const i = loneMarkers.pop() ?? 0; + let j = i + 1; + while (j < state.tokens.length && state.tokens[j].type === "u_close") { + j++; + } + j--; + if (i !== j) { + token = state.tokens[j]; + state.tokens[j] = state.tokens[i]; + state.tokens[i] = token; + } + } + } + }); + const markdownHTMLNodeRegistry = { + text_align: { + getAttrs: token => { + const align = token.style?.get("text-align"); + if (!["left", "center", "right"].includes(align)) + return undefined; + return { align }; + }, + }, + }; + const originalParse = markdown.parse; + markdown.parse = (src, env) => { + const rawTokens = originalParse.call(markdown, src, env); + const tokens = []; + // the `level` of the parent `_open` token + let level = 0; + for (const token of rawTokens) { + if (token.type !== "html_block_open" && token.type !== "html_block_close") { + tokens.push(token); + continue; + } + if (token.nesting < 0) { + const opening = tokens.findLast(token => token.level === level); + if (!opening) { + console.warn("Invalid HTML in markdown:", token.raw); + continue; + } + token.type = `${opening.type.slice(0, -5)}_close`; + tokens.push(token); + level = token.level; + continue; + } + for (const [nodeType, spec] of Object.entries(markdownHTMLNodeRegistry)) { + const attrs = spec.getAttrs(token); + if (attrs) { + token.type = nodeType; + if (attrs !== true) + token.nodeAttrs = attrs; + break; + } + } + token.type = `${token.type}_open`; + level = token.level; + tokens.push(token); + } + return tokens; + }; + const markdownParser = new prosemirror_markdown_1.MarkdownParser(schema, markdown, Objects_3.default.filterNullish({ + ...prosemirror_markdown_1.defaultMarkdownParser.tokens, + image: undefined, + u: { + mark: "underline", + }, + s: { + mark: "strikethrough", + }, + ...Object.entries(markdownHTMLNodeRegistry) + .toObject(([tokenType, spec]) => [tokenType, { + block: tokenType, + getAttrs: token => token.nodeAttrs ?? {}, + }]), + })); + const markdownSerializer = new prosemirror_markdown_1.MarkdownSerializer({ + ...prosemirror_markdown_1.defaultMarkdownSerializer.nodes, + text_align: (state, node, parent, index) => { + state.write(`
\n`); + state.renderContent(node); + state.write("
"); + state.closeBlock(node); + }, + }, { + ...prosemirror_markdown_1.defaultMarkdownSerializer.marks, + strikethrough: { + open: "~~", + close: "~~", + expelEnclosingWhitespace: true, + }, + underline: { + open: "__", + close: "__", + expelEnclosingWhitespace: true, + }, + }); + function parseStyleAttributeValue(style) { + if (style === undefined || style === null) + return undefined; + const styles = new Map(); + let key = ""; + let value = ""; + let inValue = false; + let isEscaped = false; + let isQuoted = false; + let quoteChar = ""; + let parenCount = 0; + for (let i = 0; i < style.length; i++) { + const char = style[i]; + if (char === "\\") { + isEscaped = true; + continue; + } + if (isEscaped) { + value += char; + isEscaped = false; + continue; + } + if ((char === '"' || char === "'") && !isQuoted) { + isQuoted = true; + quoteChar = char; + continue; + } + if (char === quoteChar && isQuoted) { + isQuoted = false; + continue; + } + if (char === "(" && !isQuoted) { + parenCount++; + value += char; + continue; + } + if (char === ")" && !isQuoted) { + parenCount--; + value += char; + continue; + } + if (char === ":" && !isQuoted && parenCount === 0) { + inValue = true; + continue; + } + if (char === ";" && !isQuoted && parenCount === 0) { + if (key && value) { + key = key.trim(); + if (!REGEX_CSS_PROPERTY.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + key = ""; + value = ""; + } + inValue = false; + continue; + } + if (inValue) { + value += char; + } + else { + key += char; + } + } + if (key && value) { + key = key.trim(); + if (!REGEX_CSS_PROPERTY.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + } + return styles; + } + //#endregion + vars(REGEX_ATTRIBUTE, REGEX_CSS_PROPERTY, markdownParser, markdownSerializer, parseStyleAttributeValue); + //////////////////////////////////// + const BLOCK_TYPES = [ + "paragraph", + "code_block", + ]; + let globalid = 0; + const TextEditor = Component_29.default.Builder((component) => { + const id = globalid++; + const isMarkdown = (0, State_20.default)(false); + const content = (0, State_20.default)(""); + const isFullscreen = (0, State_20.default)(false); + // eslint-disable-next-line prefer-const + let editor; + const state = (0, State_20.default)(undefined); + //////////////////////////////////// + //#region Announcements + state.subscribe(component, () => { + if (!editor.mirror?.hasFocus() || !editor.mirror.state.selection.empty) + return; + const pos = editor.mirror.state.selection.from + 1; + const $pos = editor.mirror.state.doc.resolve(pos > editor.mirror.state.doc.content.size ? pos - 1 : pos); + Announcer_1.default.interrupt("text-editor/format/inline", announce => { + const markTypes = Object.keys(schema.marks); + let hadActive = false; + for (const type of markTypes) { + if (!isMarkActive(schema.marks[type], $pos)) + continue; + hadActive = true; + announce(`component/text-editor/formatting/${type}`); + } + if (!hadActive) + announce("component/text-editor/formatting/none"); + }); + }); + //////////////////////////////////// + //#region Types + const ToolbarButtonTypeMark = Component_29.default.Extension((component, type) => { + const mark = schema.marks[type]; + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`) + .extend(() => ({ mark })); + }); + const ToolbarButtonTypeNode = Component_29.default.Extension((component, type) => { + const node = schema.nodes[type.replaceAll("-", "_")]; + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`) + .extend(() => ({ node })); + }); + const ToolbarButtonTypeOther = Component_29.default.Extension((component, type) => { + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`); + }); + //#endregion + vars(ToolbarButtonTypeMark, ToolbarButtonTypeNode, ToolbarButtonTypeOther); + //////////////////////////////////// + //////////////////////////////////// + //#region Components + const ToolbarButtonGroup = Component_29.default.Builder(component => component + .ariaRole("group") + .style("text-editor-toolbar-button-group")); + const ToolbarButton = Component_29.default.Builder((_, handler) => { + return (0, Button_5.default)() + .style("text-editor-toolbar-button") + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + handler(event.component); + }); + }); + const ToolbarCheckbutton = Component_29.default.Builder((_, state, toggler) => { + return (0, Checkbutton_3.default)() + .style("text-editor-toolbar-button") + .style.bind(state, "text-editor-toolbar-button--enabled") + .use(state) + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + toggler(event.component); + }); + }); + const ToolbarRadioButton = Component_29.default.Builder((_, name, state, toggler) => { + return (0, RadioButton_1.default)() + .style("text-editor-toolbar-button") + .setName(name) + .style.bind(state, "text-editor-toolbar-button--enabled") + .use(state) + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + toggler(event.component); + }); + }); + const ToolbarButtonPopover = Component_29.default.Builder((_, align) => { + return (0, Button_5.default)() + .style("text-editor-toolbar-button", "text-editor-toolbar-button--has-popover") + .clearPopover() + .setPopover("hover", (popover, button) => { + popover + .style("text-editor-toolbar-popover") + .style.bind(popover.popoverParent.nonNullish, "text-editor-toolbar-popover-sub", `text-editor-toolbar-popover-sub--${align}`) + .anchor.add(align === "centre" ? align : `aligned ${align}`, "off bottom") + .style.toggle(align === "left", "text-editor-toolbar-popover--left") + .style.toggle(align === "right", "text-editor-toolbar-popover--right") + .setMousePadding(20); + button.style.bind(popover.visible, "text-editor-toolbar-button--has-popover-visible"); + }) + .receiveAncestorInsertEvents() + .event.subscribe(["insert", "ancestorInsert"], event => event.component.style.toggle(!!event.component.closest(Popover_2.default), "text-editor-toolbar-button--has-popover--within-popover")); + }); + //#endregion + vars(ToolbarButtonGroup, ToolbarButton, ToolbarCheckbutton, ToolbarRadioButton, ToolbarButtonPopover); + //////////////////////////////////// + //////////////////////////////////// + //#region Specifics + const ToolbarButtonMark = Component_29.default.Builder((_, type) => { + const mark = schema.marks[type]; + const toggler = markToggler(mark); + const markActive = state.map(component, state => isMarkActive(mark)); + return ToolbarCheckbutton(markActive, toggler) + .and(ToolbarButtonTypeMark, type); + }); + const ToolbarButtonAlign = Component_29.default.Builder((_, align) => { + const toggler = wrapper(schema.nodes.text_align, { align: align === "centre" ? "center" : align }); + const alignActive = state.map(component, state => isAlignActive(align)); + return ToolbarRadioButton(`text-editor-${id}-text-align`, alignActive, toggler) + .and(ToolbarButtonTypeOther, `align-${align}`); + }); + const ToolbarButtonBlockType = Component_29.default.Builder((_, type) => { + const node = schema.nodes[type.replaceAll("-", "_")]; + const toggle = blockTypeToggler(node); + const typeActive = state.map(component, state => isTypeActive(node)); + return ToolbarRadioButton(`text-editor-${id}-block-type`, typeActive, toggle) + .and(ToolbarButtonTypeNode, type); + }); + const ToolbarButtonHeading = Component_29.default.Builder((_, level) => { + const node = schema.nodes.heading; + const toggle = blockTypeToggler(node, { level }); + const typeActive = state.map(component, state => isTypeActive(node, { level })); + return ToolbarRadioButton(`text-editor-${id}-block-type`, typeActive, toggle) + .style(`text-editor-toolbar-h${level}`); + }); + const ToolbarButtonWrap = Component_29.default.Builder((_, type) => ToolbarButton(wrapper(schema.nodes[type.replaceAll("-", "_")])) + .and(ToolbarButtonTypeNode, type)); + const ToolbarButtonList = Component_29.default.Builder((_, type) => ToolbarButton(listWrapper(schema.nodes[type.replaceAll("-", "_")])) + .and(ToolbarButtonTypeNode, type)); + //#endregion + vars(ToolbarButtonMark, ToolbarButtonAlign, ToolbarButtonBlockType, ToolbarButtonHeading, ToolbarButtonWrap, ToolbarButtonList); + types(); + //////////////////////////////////// + //////////////////////////////////// + //#region Commands + let inTransaction = false; + function wrapCmd(cmd) { + return (component) => { + if (!state.value) + return; + inTransaction = true; + cmd(state.value, editor.mirror?.dispatch, editor.mirror); + inTransaction = false; + if (!component.hasFocused.value) + editor.document?.focus(); + }; + } + function markToggler(type) { + return wrapCmd((0, prosemirror_commands_1.toggleMark)(type)); + } + function wrapper(node, attrs) { + if (node === schema.nodes.text_align) + return wrapCmd((state, dispatch) => { + const { $from, $to } = state.selection; + let range = $from.blockRange($to); + if (range) { + const textAlignBlock = $from.closest(schema.nodes.text_align, range.depth); + if (textAlignBlock && !range.startIndex && range.endIndex === textAlignBlock.childCount) { + const pos = textAlignBlock.pos(state.doc); + if (pos === undefined) + return false; + if (dispatch) + dispatch(state.tr + .setNodeMarkup(pos, undefined, attrs) + .stripNodeType(textAlignBlock.content, schema.nodes.text_align) + .scrollIntoView()); + return true; + } + } + const wrapping = range && (0, prosemirror_transform_1.findWrapping)(range, node, attrs); + if (!wrapping) + return false; + if (dispatch) { + const tr = state.tr; + tr.wrap(range, wrapping); + range = tr.doc.resolve($from.pos + 1).blockRange(tr.doc.resolve($to.pos + 1)); + if (!range) + throw new Error("Unable to strip nodes, unable to resolve new range"); + tr.stripNodeType(range, schema.nodes.text_align); + tr.scrollIntoView(); + dispatch(tr); + } + return true; + }); + return wrapCmd((0, prosemirror_commands_1.wrapIn)(node, attrs)); + } + function blockTypeToggler(node, attrs) { + return wrapCmd((0, prosemirror_commands_1.setBlockType)(node, attrs)); + } + function listWrapper(node, attrs) { + return wrapCmd((0, prosemirror_schema_list_1.wrapInList)(node, attrs)); + } + //#endregion + vars(wrapCmd, markToggler, wrapper, blockTypeToggler, listWrapper); + //////////////////////////////////// + //#endregion + vars(ToolbarButtonTypeMark, ToolbarButtonTypeNode, ToolbarButtonTypeOther); + vars(ToolbarButtonGroup, ToolbarButton, ToolbarCheckbutton, ToolbarRadioButton, ToolbarButtonPopover); + vars(ToolbarButtonMark, ToolbarButtonAlign, ToolbarButtonBlockType, ToolbarButtonHeading, ToolbarButtonWrap, ToolbarButtonList); + types(); + //////////////////////////////////// + const toolbar = (0, Component_29.default)() + .style("text-editor-toolbar") + .style.bind(isFullscreen, "text-editor-toolbar--fullscreen") + .ariaRole("toolbar") + .append((0, Component_29.default)() + .style("text-editor-toolbar-left") + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/inline") + .append(ToolbarButtonMark("strong")) + .append(ToolbarButtonMark("em")) + .append(ToolbarButtonPopover("left") + .and(ToolbarButtonTypeOther, "other-formatting") + .tweakPopover(popover => popover + .append(ToolbarButtonMark("underline")) + .append(ToolbarButtonMark("strikethrough")) + .append(ToolbarButtonMark("subscript")) + .append(ToolbarButtonMark("superscript")) + .append(ToolbarButtonMark("code"))))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/block") + .append(ToolbarButtonPopover("centre") + .tweakPopover(popover => popover + .ariaRole("radiogroup") + .append(ToolbarButtonAlign("left")) + .append(ToolbarButtonAlign("centre")) + .append(ToolbarButtonAlign("right"))) + .tweak(button => { + state.use(button, () => { + const align = !editor?.mirror?.hasFocus() && !inTransaction ? "left" : getAlign() ?? "mixed"; + button.ariaLabel.set(en_nz_3.default["component/text-editor/toolbar/button/align"](en_nz_3.default[`component/text-editor/toolbar/button/align/currently/${align}`]()).toString()); + button.style.remove("text-editor-toolbar-align-left", "text-editor-toolbar-align-centre", "text-editor-toolbar-align-right", "text-editor-toolbar-align-mixed"); + button.style(`text-editor-toolbar-align-${align}`); + }); + }))) + .append(ToolbarButtonGroup() + .ariaRole() + .append(ToolbarButtonPopover("centre") + .tweakPopover(popover => popover + .ariaRole("radiogroup") + .append(ToolbarButtonBlockType("paragraph")) + .append(ToolbarButtonPopover("centre") + .style("text-editor-toolbar-heading") + .tweakPopover(popover => popover + .append(ToolbarButtonHeading(1)) + .append(ToolbarButtonHeading(2)) + .append(ToolbarButtonHeading(3)) + .append(ToolbarButtonHeading(4)) + .append(ToolbarButtonHeading(5)) + .append(ToolbarButtonHeading(6)))) + .append(ToolbarButtonBlockType("code-block"))) + .tweak(button => { + state.use(button, () => { + const blockType = !editor?.mirror?.hasFocus() && !inTransaction ? "paragraph" : getBlockType() ?? "mixed"; + button.ariaLabel.set(en_nz_3.default["component/text-editor/toolbar/button/block-type"](en_nz_3.default[`component/text-editor/toolbar/button/block-type/currently/${blockType}`]()).toString()); + button.style.remove("text-editor-toolbar-mixed", ...BLOCK_TYPES + .map(type => type.replaceAll("_", "-")) + .map(type => `text-editor-toolbar-${type}`)); + button.style(`text-editor-toolbar-${blockType}`); + }); + }))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/wrapper") + .append(ToolbarButton(wrapCmd(prosemirror_commands_1.lift)).and(ToolbarButtonTypeOther, "lift") + .style.bind(state.map(component, value => !value || !(0, prosemirror_commands_1.lift)(value)), "text-editor-toolbar-button--hidden")) + .append(ToolbarButtonWrap("blockquote")) + .append(ToolbarButtonList("bullet-list")) + .append(ToolbarButtonList("ordered-list"))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/insert") + .append(ToolbarButton(wrapCmd((state, dispatch) => { + dispatch?.(state.tr.replaceSelectionWith(schema.nodes.horizontal_rule.create())); + return true; + })) + .and(ToolbarButtonTypeOther, "hr")))) + .append((0, Component_29.default)() + .style("text-editor-toolbar-right") + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/actions") + .append(ToolbarButton(wrapCmd(prosemirror_history_1.undo)).and(ToolbarButtonTypeOther, "undo")) + .append(ToolbarButton(wrapCmd(prosemirror_history_1.redo)).and(ToolbarButtonTypeOther, "redo")) + .append(ToolbarButton(toggleFullscreen) + .style.bind(isFullscreen.not, "text-editor-toolbar-fullscreen") + .style.bind(isFullscreen, "text-editor-toolbar-unfullscreen") + .ariaLabel.bind(isFullscreen.map(component, fullscreen => en_nz_3.default[`component/text-editor/toolbar/button/${fullscreen ? "unfullscreen" : "fullscreen"}`]().toString()))))) + .appendTo(component); + //#endregion + vars(toolbar); + //////////////////////////////////// + //////////////////////////////////// + //#region Main UI + let label; + let unsubscribeLabelFor; + const stopUsingLabel = () => { + label?.event.unsubscribe("remove", stopUsingLabel); + label = undefined; + unsubscribeLabelFor?.(); + unsubscribeLabelFor = undefined; + }; + const viewTransitionName = "text-editor"; + const actualEditor = (0, Component_29.default)() + .subviewTransition(viewTransitionName) + .style("text-editor") + .style.bind(isFullscreen, "text-editor--fullscreen") + .event.subscribe("click", event => { + const target = Component_29.default.get(event.target); + if (target !== toolbar && !target?.is(TextEditor)) + return; + editor.document?.focus(); + }) + .append(toolbar); + editor = (0, Slot_2.default)() + .and(Input_2.default) + .append(actualEditor) + .extend(editor => ({ + default: (0, StringApplicator_6.default)(editor, value => loadFromMarkdown(value)), + toolbar, + setRequired(required = true) { + editor.style.toggle(required, "text-editor--required"); + editor.required.value = required; + refresh(); + return editor; + }, + setLabel(newLabel) { + label = newLabel; + label?.event.subscribe("remove", stopUsingLabel); + refresh(); + // the moment a name is assigned to the editor, attempt to replace the doc with a local draft (if it exists) + unsubscribeLabelFor = label?.for.use(editor, loadLocal); + return editor; + }, + useMarkdown: () => { + clearLocal(); + return !state.value ? "" : markdownSerializer.serialize(state.value?.doc); + }, + })); + const documentSlot = (0, Slot_2.default)() + .style.bind(isFullscreen, "text-editor-document-slot--fullscreen") + .use(isMarkdown, (slot, isMarkdown) => { + if (isMarkdown) { + state.value = undefined; + return; + } + return createDefaultView(slot); + }) + .appendTo(actualEditor); + const contentWidth = State_20.default.Generator(() => `${editor.document?.element.scrollWidth ?? 0}px`) + .observe(component, state, Viewport_3.default.size); + const scrollbarProxy = (0, Component_29.default)() + .style("text-editor-document-scrollbar-proxy") + .style.bind(isFullscreen, "text-editor-document-scrollbar-proxy--fullscreen") + .style.bind(contentWidth.map(component, () => (editor.document?.element.scrollWidth ?? 0) > (editor.document?.rect.value.width ?? 0)), "text-editor-document-scrollbar-proxy--visible") + .style.bindVariable("content-width", contentWidth) + .event.subscribe("scroll", () => editor.document?.element.scrollTo({ left: scrollbarProxy.element.scrollLeft, behavior: "instant" })) + .appendTo(actualEditor); + const fullscreenContentWidth = State_20.default.Generator(() => `${documentSlot.element.scrollWidth ?? 0}px`) + .observe(component, state, Viewport_3.default.size); + documentSlot.style.bindVariable("content-width", fullscreenContentWidth); + state.use(editor, state => { + saveLocal(undefined, state?.doc); + toolbar.rect.markDirty(); + }); + const fullscreenDialog = (0, Dialog_2.default)() + .and(Slot_2.default) + .style.remove("slot") + .setFullscreen() + .setOwner(editor) + .bind(isFullscreen) + .appendTo(document.body); + //#endregion + vars(editor, actualEditor, documentSlot, scrollbarProxy, fullscreenDialog); + //////////////////////////////////// + return editor; + //////////////////////////////////// + //#region ProseMirror Init + function markInputRule(regexp, markType, getAttrs = null, getContent) { + return new prosemirror_inputrules_1.InputRule(regexp, (state, match, start, end) => { + const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + const content = getContent instanceof Function ? getContent(match) : getContent; + const tr = state.tr; + tr.replaceWith(start, end, typeof content === "string" ? schema.text(content) : content); + const mark = markType.create(attrs); + tr.addMark(tr.mapping.map(start), tr.mapping.map(end), mark); + tr.removeStoredMark(mark); + return tr; + }); + } + function createDefaultView(slot) { + const view = new prosemirror_view_1.EditorView(slot.element, { + state: prosemirror_state_1.EditorState.create({ + doc: markdownParser.parse(content.value), + plugins: [ + (0, prosemirror_example_setup_1.buildInputRules)(schema), + (0, prosemirror_inputrules_1.inputRules)({ + rules: [ + markInputRule(/\*\*([^*]+?)\*\*/, schema.marks.strong, undefined, match => match[1]), + markInputRule(/__([^_]+?)__/, schema.marks.underline, undefined, match => match[1]), + markInputRule(/\/\/([^/]+?)\/\//, schema.marks.em, undefined, match => match[1]), + markInputRule(/`([^`]+?)`/, schema.marks.code, undefined, match => match[1]), + markInputRule(/\[(.+?)\]\(([^ ]+?)(?:[  ](?:\((.+?)\)|["'“”‘’](.+?)["'“”‘’]))?\)/, schema.marks.link, ([match, text, href, title1, title2]) => ({ href, title: title1 || title2 || undefined }), match => match[1]), + ], + }), + (0, prosemirror_keymap_1.keymap)((0, prosemirror_example_setup_1.buildKeymap)(schema, {})), + (0, prosemirror_keymap_1.keymap)(prosemirror_commands_1.baseKeymap), + (0, prosemirror_keymap_1.keymap)({ + "Mod-s": (0, prosemirror_commands_1.toggleMark)(schema.marks.strikethrough), + "Mod-S": (0, prosemirror_commands_1.toggleMark)(schema.marks.strikethrough), + "Mod-.": (0, prosemirror_commands_1.toggleMark)(schema.marks.superscript), + "Mod-,": (0, prosemirror_commands_1.toggleMark)(schema.marks.subscript), + "Alt-Ctrl-0": (0, prosemirror_commands_1.setBlockType)(schema.nodes.paragraph), + ...Arrays_4.default.range(1, 7) + .toObject(i => [`Alt-Ctrl-${i}`, (0, prosemirror_commands_1.setBlockType)(schema.nodes.heading, { level: i })]), + }), + (0, prosemirror_dropcursor_1.dropCursor)(), + (0, prosemirror_gapcursor_1.gapCursor)(), + (0, prosemirror_history_1.history)(), + new prosemirror_state_1.Plugin({ + view() { + return { + update(view, prevState) { + state.value = view.state; + if (state.value === prevState) + state.emit(); + }, + }; + }, + }), + ], + }), + }); + editor.mirror = view; + editor.document = (0, Component_29.default)() + .and(Input_2.default) + .replaceElement(editor.mirror.dom) + .ariaRole("textbox") + .classes.add("markdown") + .style("text-editor-document") + .style.bind(isFullscreen, "text-editor-document--fullscreen") + .setId(`text-editor-${id}`) + .attributes.set("aria-multiline", "true") + .event.subscribe("scroll", () => scrollbarProxy.element.scrollTo({ left: editor.document?.element.scrollLeft ?? 0, behavior: "instant" })); + toolbar.ariaControls(editor.document); + refresh(); + return () => { + content.value = markdownSerializer.serialize(view.state.doc); + editor.mirror = undefined; + editor.document = undefined; + refresh(); + view.destroy(); + }; + } + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region Events/Actions + function refresh() { + label?.setInput(editor.document); + editor.document?.setName(label?.for); + editor.document?.setId(label?.for); + label?.setId(label.for.map(component, v => `${v}-label`)); + toolbar.ariaLabelledBy(label); + editor.document?.ariaLabelledBy(label); + editor.document?.attributes.toggle(editor.required.value, "aria-required", "true"); + } + function toggleFullscreen() { + ViewTransition_1.default.perform("subview", viewTransitionName, () => { + isFullscreen.value = !isFullscreen.value; + actualEditor.appendTo(isFullscreen.value ? fullscreenDialog : editor); + actualEditor.rect.markDirty(); + }); + } + function clearLocal(name = editor.document?.name.value) { + if (!name) + return; + Store_3.default.items.textEditorDrafts = Store_3.default.items.textEditorDrafts?.filter(draft => draft.name !== name); + } + function loadFromMarkdown(markdown = "") { + // hack to fix it not redrawing when calling updateState now? + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + (editor.mirror?.docView).dirty = 2; // CONTENT_DIRTY + editor.mirror?.updateState(prosemirror_state_1.EditorState.create({ + plugins: editor.mirror.state.plugins.slice(), + doc: markdownParser.parse(markdown), + })); + } + function loadLocal(name = editor.document?.name.value) { + if (!name) + return; + const draft = Store_3.default.items.textEditorDrafts?.find(draft => draft.name === name); + if (!draft) + return; + loadFromMarkdown(draft.body); + } + function saveLocal(name = editor.document?.name.value, doc) { + if (!name) + return; + const body = !doc ? "" : markdownSerializer.serialize(doc); + editor.length.value = body.length; + if (body === editor.default.state.value) + return clearLocal(); + Store_3.default.items.textEditorDrafts = [ + ...!body ? [] : [{ name, body, created: Date.now() }], + ...(Store_3.default.items.textEditorDrafts ?? []) + .filter(draft => true + && draft.name !== name // keep old drafts that don't share names with the new draft + && Date.now() - draft.created < Time_5.default.days(1) // keep old drafts only if they were made in the last day + && true), + ] + // disallow more than 4 drafts due to localstorage limitations with using localStorage + // this won't be necessary when drafts are stored in indexeddb + .slice(0, 4); + } + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region State + function isMarkActive(type, pos) { + if (!state.value) + return false; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return !!type.isInSet(state.value.storedMarks || pos.marks()); + return state.value.doc.rangeHasMark(selection.from, selection.to, type); + } + function isTypeActive(type, attrs, pos) { + if (!state.value) + return false; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return !!pos.closest(type, attrs); + let found = false; + state.value.doc.nodesBetween(selection.from, selection.to, node => { + found ||= node.matches(type, attrs); + }); + return found; + } + function getBlockType(pos) { + if (!state.value) + return undefined; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) { + for (const blockType of BLOCK_TYPES) + if (isTypeActive(schema.nodes[blockType], pos)) + return blockType.replaceAll("_", "-"); + return "paragraph"; + } + const types = new Set(); + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + if (node.type !== schema.nodes.text) + return; + const $pos = state.value?.doc.resolve(pos); + if (!$pos) + return; + for (const blockType of BLOCK_TYPES) + if (isTypeActive(schema.nodes[blockType], $pos)) { + types.add(blockType.replaceAll("_", "-")); + return; + } + }); + if (!types.size) + return getBlockType(selection.$from); + if (types.size > 1) + return undefined; + const [type] = types; + return type; + } + function isAlignActive(align, pos) { + if (!state.value) + return false; + align = align === "centre" ? "center" : align; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return (pos.closest(schema.nodes.text_align)?.attrs.align ?? "left") === align; + let found = false; + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + const resolved = state.value?.doc.resolve(pos); + found ||= !resolved ? align === "left" : isAlignActive(align, resolved); + }); + return found; + } + function getAlign(pos) { + if (!state.value) + return undefined; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const align = pos.closest(schema.nodes.text_align)?.attrs.align ?? "left"; + return align === "center" ? "centre" : align; + } + const aligns = new Set(); + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + if (node.type === schema.nodes.text) { + const $pos = state.value?.doc.resolve(pos); + if ($pos) + aligns.add(getAlign($pos)); + } + }); + if (!aligns.size) + return getAlign(selection.$from); + if (aligns.size > 1) + return undefined; + const [align] = aligns; + return align; + } + //#endregion + //////////////////////////////////// + }); + exports.default = TextEditor; +}); +define("ui/component/core/toast/ToastList", ["require", "exports", "ui/Component", "utility/Async", "utility/Task", "utility/Time"], function (require, exports, Component_30, Async_2, Task_3, Time_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_30 = __importDefault(Component_30); + Async_2 = __importDefault(Async_2); + Task_3 = __importDefault(Task_3); + Time_6 = __importDefault(Time_6); + const ToastComponent = Component_30.default.Builder((component) => { + const title = (0, Component_30.default)() + .style("toast-title") + .appendTo(component); + return component + .style("toast") + .extend(toast => ({ + title, + content: undefined, + type: Object.assign((...types) => { + for (const type of types) + toast.style(`toast-type-${type}`); + return toast; + }, { + remove(...types) { + for (const type of types) + toast.style.remove(`toast-type-${type}`); + return toast; + }, + }), + })) + .extendJIT("content", toast => (0, Component_30.default)() + .style("toast-content") + .appendTo(toast)); + }).setName("Toast"); + const ToastList = Component_30.default.Builder((component) => { + const toasts = component + .style("toast-list") + .extend(toasts => ({ + info: add.bind(null, "info"), + success: add.bind(null, "success"), + warning: add.bind(null, "warning"), + })); + Object.assign(window, { toast: toasts }); + return toasts; + function add(type, toast, ...params) { + const component = ToastComponent() + .type(type) + .style("toast--measuring") + .tweak(toast.initialise, ...params); + void lifecycle(toast, component); + return component; + } + async function lifecycle(toast, component) { + const wrapper = (0, Component_30.default)().style("toast-wrapper").appendTo(toasts); + component.style("toast--measuring").appendTo(wrapper); + await Task_3.default.yield(); + const rect = component.rect.value; + component.style.remove("toast--measuring"); + wrapper.style.setProperty("height", `${rect.height}px`); + await Async_2.default.sleep(toast.duration); + component.style("toast--hide"); + wrapper.style.removeProperties("height"); + await Promise.race([ + new Promise(resolve => component.event.subscribe("animationend", resolve)), + Async_2.default.sleep(Time_6.default.seconds(1)), + ]); + return; + wrapper.remove(); + } + }); + //#endregion + //////////////////////////////////// + exports.default = ToastList; +}); +define("ui/component/core/toast/Toast", ["require", "exports", "ui/Component"], function (require, exports, Component_31) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.TOAST_ERROR = exports.TOAST_SUCCESS = void 0; + Component_31 = __importDefault(Component_31); + function Toast(toast) { + return toast; + } + exports.default = Toast; + exports.TOAST_SUCCESS = Toast({ + duration: 2000, + initialise(toast, translation) { + toast.title.text.use(translation); + }, + }); + function isErrorResponse(error) { + return error.headers !== undefined; + } + exports.TOAST_ERROR = Toast({ + duration: 5000, + initialise(toast, translation, error) { + toast.title.text.use(translation); + if (!isErrorResponse(error) || !error.detail) + toast.content.text.set(error.message); + else + toast.content + .append((0, Component_31.default)() + .style("toast-error-type") + .text.set(error.message)) + .text.append(": ") + .text.append(error.detail); + }, + }); +}); +define("ui/component/VanityInput", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/component/core/TextInput"], function (require, exports, Component_32, Input_3, TextInput_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_32 = __importDefault(Component_32); + Input_3 = __importDefault(Input_3); + TextInput_2 = __importDefault(TextInput_2); + const VanityInput = Object.assign(Component_32.default.Builder((component) => { + const input = (0, TextInput_2.default)() + .style("vanity-input-input") + .filter(filterVanity) + .appendTo(component); + return component.and(Input_3.default) + .style("vanity-input") + .append((0, Component_32.default)() + .style("vanity-input-prefix") + .text.set("@")) + .extend(component => ({ + // vanity input + input, + // input + required: input.required, + hint: input.hint.rehost(component), + maxLength: input.maxLength, + length: input.length, + setMaxLength(maxLength) { + input.setMaxLength(maxLength); + return component; + }, + setRequired(required) { + input.setRequired(required); + return component; + }, + setLabel(label) { + input.setLabel(label); + return component; + }, + tweakPopover(initialiser) { + input.tweakPopover(initialiser); + return component; + }, + // text input + state: input.state, + value: undefined, + default: input.default.rehost(component), + placeholder: input.placeholder.rehost(component), + ignoreInputEvent(ignore = true) { + input.ignoreInputEvent(ignore); + return component; + }, + filter(filter) { + input.filter(filter); + return component; + }, + })) + .extendMagic("value", component => ({ + get() { return input.value; }, + set(value) { input.value = value; }, + })); + }), { + filter: filterVanity, + }); + exports.default = VanityInput; + function filterVanity(vanity, textBefore = "", isFullText = true) { + vanity = vanity.replace(/[\W_]+/g, "-"); + if (isFullText) + vanity = vanity.replace(/^-|-$/g, ""); + if (textBefore.endsWith("-") && vanity.startsWith("-")) + return vanity.slice(1); + return vanity; + } +}); +define("ui/view/account/AccountViewForm", ["require", "exports", "endpoint/author/EndpointAuthorCreate", "endpoint/author/EndpointAuthorUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/LabelledTextInputBlock", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast", "ui/component/VanityInput"], function (require, exports, EndpointAuthorCreate_1, EndpointAuthorUpdate_1, en_nz_4, FormInputLengths_1, Session_5, Component_33, Block_5, Form_2, LabelledTable_1, LabelledTextInputBlock_1, TextEditor_1, TextInput_3, Toast_1, VanityInput_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorCreate_1 = __importDefault(EndpointAuthorCreate_1); + EndpointAuthorUpdate_1 = __importDefault(EndpointAuthorUpdate_1); + en_nz_4 = __importDefault(en_nz_4); + FormInputLengths_1 = __importDefault(FormInputLengths_1); + Session_5 = __importDefault(Session_5); + Component_33 = __importDefault(Component_33); + Block_5 = __importDefault(Block_5); + Form_2 = __importDefault(Form_2); + LabelledTable_1 = __importDefault(LabelledTable_1); + LabelledTextInputBlock_1 = __importDefault(LabelledTextInputBlock_1); + TextEditor_1 = __importDefault(TextEditor_1); + TextInput_3 = __importDefault(TextInput_3); + VanityInput_1 = __importDefault(VanityInput_1); + exports.default = Component_33.default.Builder((component, type) => { + const block = component.and(Block_5.default); + const form = block.and(Form_2.default, block.title); + form.viewTransition("account-form"); + form.title.text.use(`view/account/${type}/title`); + form.setName(en_nz_4.default[`view/account/${type}/title`]().toString()); + if (type === "create") + form.description.text.use("view/account/create/description"); + form.submit.textWrapper.text.use(`view/account/${type}/submit`); + const table = (0, LabelledTable_1.default)().appendTo(form.content); + const nameInput = (0, TextInput_3.default)() + .setRequired() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.name)) + .hint.use("view/account/name/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.name); + table.label(label => label.text.use("view/account/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const vanityInput = (0, VanityInput_1.default)() + .placeholder.bind(nameInput.state + .map(component, name => VanityInput_1.default.filter(name))) + .default.bind(Session_5.default.Auth.author.map(component, author => author?.vanity)) + .hint.use("view/account/vanity/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.vanity); + table.label(label => label.text.use("view/account/vanity/label")) + .content((content, label) => content.append(vanityInput.setLabel(label))); + const pronounsInput = (0, TextInput_3.default)() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.pronouns)) + .hint.use("view/account/pronouns/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.pronouns); + table.label(label => label.text.use("view/account/pronouns/label")) + .content((content, label) => content.append(pronounsInput.setLabel(label))); + const descriptionInput = (0, TextEditor_1.default)() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.description.body)) + .hint.use("view/account/description/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.description); + table.label(label => label.text.use("view/account/description/label")) + .content((content, label) => content.append(descriptionInput.setLabel(label))); + let supportLinkInput; + let supportMessageInput; + (0, LabelledTextInputBlock_1.default)() + .style("labelled-row--in-labelled-table") + .ariaLabel.use("view/account/support-link/label") + .label(label => label.text.use("view/account/support-link/label")) + .input(input => supportLinkInput = input + .default.bind(Session_5.default.Auth.author.map(component, author => author?.support_link)) + .hint.use("view/account/support-link/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.support_link)) + .label(label => label.text.use("view/account/support-message/label")) + .input(input => supportMessageInput = input + .default.bind(Session_5.default.Auth.author.map(component, author => author?.support_message)) + .hint.use("view/account/support-message/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.support_message)) + .appendTo(table); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const response = await (type === "create" ? EndpointAuthorCreate_1.default : EndpointAuthorUpdate_1.default).query({ + body: { + name: nameInput.value, + vanity: vanityInput.value, + description: descriptionInput.useMarkdown(), + pronouns: pronounsInput.value, + support_link: supportLinkInput.value, + support_message: supportMessageInput.value, + }, + }); + if (response instanceof Error) { + toast.warning(Toast_1.TOAST_ERROR, "view/account/toast/failed-to-save", response); + console.error(response); + return; + } + toast.success(Toast_1.TOAST_SUCCESS, "view/account/toast/saved"); + Session_5.default.setAuthor(response.data); + }); + return form; + }); +}); +define("ui/view/shared/component/ViewDefinition", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function ViewDefinition(definition) { + const result = { + ...definition, + navigate: (app, params) => app.view.show(result, params), + }; + return result; + } + exports.default = ViewDefinition; +}); +define("ui/view/AccountView", ["require", "exports", "endpoint/author/EndpointAuthorDelete", "model/Session", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/ConfirmDialog", "ui/component/core/Slot", "ui/component/OAuthServices", "ui/view/account/AccountViewForm", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "utility/State"], function (require, exports, EndpointAuthorDelete_1, Session_6, ActionRow_3, Button_6, ConfirmDialog_1, Slot_3, OAuthServices_2, AccountViewForm_1, View_2, ViewDefinition_1, ViewTransition_2, State_21) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorDelete_1 = __importDefault(EndpointAuthorDelete_1); + Session_6 = __importDefault(Session_6); + ActionRow_3 = __importDefault(ActionRow_3); + Button_6 = __importDefault(Button_6); + ConfirmDialog_1 = __importDefault(ConfirmDialog_1); + Slot_3 = __importDefault(Slot_3); + OAuthServices_2 = __importDefault(OAuthServices_2); + AccountViewForm_1 = __importDefault(AccountViewForm_1); + View_2 = __importDefault(View_2); + ViewDefinition_1 = __importDefault(ViewDefinition_1); + ViewTransition_2 = __importDefault(ViewTransition_2); + State_21 = __importDefault(State_21); + exports.default = (0, ViewDefinition_1.default)({ + create: async () => { + const id = "account"; + const view = (0, View_2.default)(id); + const state = (0, State_21.default)(Session_6.default.Auth.state.value); + (0, Slot_3.default)() + .use(state, () => createForm()?.subviewTransition(id)) + .appendTo(view); + const services = await (0, OAuthServices_2.default)(state); + services.header.subviewTransition(id); + services.appendTo(view); + (0, Slot_3.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + Session_6.default.Auth.state.subscribe(view, () => ViewTransition_2.default.perform("subview", id, updateAuthState)); + updateAuthState(); + return view; + function updateAuthState(newState = Session_6.default.Auth.state.value) { + state.value = newState; + } + function createForm() { + switch (state.value) { + case "has-authorisations": + return (0, AccountViewForm_1.default)("create"); + case "logged-in": + return (0, AccountViewForm_1.default)("update"); + } + } + function createActionRow() { + switch (state.value) { + case "logged-in": + return (0, ActionRow_3.default)() + .viewTransition("account-action-row") + .tweak(row => row.right + .append((0, Button_6.default)() + .text.use("view/account/action/logout") + .event.subscribe("click", () => Session_6.default.reset())) + .append((0, Button_6.default)() + .text.use("view/account/action/delete") + .event.subscribe("click", async () => { + const result = await ConfirmDialog_1.default.prompt(view, { dangerToken: "delete-account" }); + if (!result) + return; + const response = await EndpointAuthorDelete_1.default.query(); + if (response instanceof Error) { + console.error(response); + return; + } + return Session_6.default.reset(); + }))); + } + } + }, + }); +}); +define("endpoint/author/EndpointAuthorGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_9 = __importDefault(Endpoint_9); + exports.default = (0, Endpoint_9.default)("/author/{vanity}/get", "get"); +}); +define("endpoint/work/EndpointWorkGetAllAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_10) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_10 = __importDefault(Endpoint_10); + exports.default = (0, Endpoint_10.default)("/works/{author}", "get"); +}); +define("ui/component/core/ExternalLink", ["require", "exports", "ui/Component"], function (require, exports, Component_34) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_34 = __importDefault(Component_34); + const ExternalLink = Component_34.default.Builder("a", (component, href) => { + component.style("link", "link-external"); + if (href !== undefined) + component.attributes.set("href", href); + return component; + }); + exports.default = ExternalLink; +}); +define("ui/component/Author", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/ExternalLink", "ui/component/core/Slot"], function (require, exports, Component_35, Block_6, ExternalLink_1, Slot_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_35 = __importDefault(Component_35); + Block_6 = __importDefault(Block_6); + ExternalLink_1 = __importDefault(ExternalLink_1); + Slot_4 = __importDefault(Slot_4); + exports.default = Component_35.default.Builder((component, author) => { + component + .viewTransition("author") + .style("author"); + const block = component.and(Block_6.default); + block.title + .style("author-name") + .text.set(author.name); + block.description + .append((0, Component_35.default)() + .style("author-vanity") + .text.set(`@${author.vanity}`)) + .append(Slot_4.default.using(author.pronouns, (slot, pronouns) => pronouns && slot + .text.append(" · ") + .append((0, Component_35.default)() + .style("author-pronouns") + .text.set(pronouns)))); + (0, Component_35.default)() + .style("author-description") + .append(Slot_4.default.using(author.description.body, (slot, body) => { + if (body) + slot.setMarkdownContent(body); + else + slot.style("placeholder").text.use("author/description/empty"); + })) + .appendTo(block.content); + if (author.support_link && author.support_message) + (0, ExternalLink_1.default)(author.support_link) + .style("author-support-link") + .text.set(author.support_message) + .appendTo(block.content); + return block; + }); +}); +define("ui/component/core/Link", ["require", "exports", "ui/Component", "utility/Env"], function (require, exports, Component_36, Env_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_36 = __importDefault(Component_36); + Env_4 = __importDefault(Env_4); + const Link = Component_36.default.Builder("a", (component, route) => { + component.style("link"); + if (route !== undefined) { + component.attributes.set("href", `${Env_4.default.URL_ORIGIN}${route.slice(1)}`); + component.event.subscribe("click", event => { + event.preventDefault(); + event.stopImmediatePropagation(); + void navigate.toURL(route); + }); + } + return component; + }); + exports.default = Link; +}); +define("ui/component/core/Paginator", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Button", "ui/component/core/Slot", "utility/Async", "utility/State"], function (require, exports, Component_37, Block_7, Button_7, Slot_5, Async_3, State_22) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_37 = __importDefault(Component_37); + Block_7 = __importDefault(Block_7); + Button_7 = __importDefault(Button_7); + Slot_5 = __importDefault(Slot_5); + Async_3 = __importDefault(Async_3); + State_22 = __importDefault(State_22); + const Paginator = Component_37.default.Builder((component) => { + const block = component.and(Block_7.default); + const isFlush = block.type.state.mapManual(type => type.has("flush")); + block.style.bind(isFlush, "paginator--flush"); + block.header + .style("paginator-header") + .style.bind(isFlush, "paginator-header--flush"); + const content = block.content + .style("paginator-content"); + block.footer + .style("paginator-footer", "paginator-footer--hidden") + .style.bind(isFlush, "paginator-footer--flush"); + block.footer.left.style("paginator-footer-left"); + block.footer.right.style("paginator-footer-right"); + const buttonFirst = (0, Button_7.default)() + .style("paginator-button", "paginator-button-first") + .event.subscribe("click", () => showPage(0)) + .appendTo(block.footer.left); + const buttonPrev = (0, Button_7.default)() + .style("paginator-button", "paginator-button-prev") + .event.subscribe("click", () => showPage(Math.max(cursor.value - 1, 0))) + .appendTo(block.footer.left); + const buttonNext = (0, Button_7.default)() + .style("paginator-button", "paginator-button-next") + .event.subscribe("click", () => showPage(Math.min(cursor.value + 1, using?.pageCount === true ? Infinity : pages.length - 1))) + .appendTo(block.footer.right); + const buttonLast = (0, Button_7.default)() + .style("paginator-button", "paginator-button-last") + .event.subscribe("click", () => showPage(pages.length - 1)) + .appendTo(block.footer.right); + let pageContent = []; + let pages = []; + const cursor = (0, State_22.default)(0); + const data = cursor.mapManual(page => pageContent[page]); + let showingPage = -1; + let orElseContentInitialiser; + let isEmpty = true; + let using; + const paginator = block + .viewTransition("paginator") + .style("paginator") + .extend(component => ({ + page: cursor, + data, + useInitial(initialData, page, pageCount) { + resetPages(); + pageContent[page] = initialData; + cursor.value = page; + data.refresh(); + using = { endpoint: undefined, initialiser: undefined, pageCount }; + return component; + }, + thenUse(endpoint) { + using.endpoint = endpoint; + return component; + }, + async withContent(contentInitialiser) { + clearContent(); + using.initialiser = contentInitialiser; + await setup(pageContent[cursor.value], cursor.value, using.pageCount); + return component; + }, + async useEndpoint(endpoint, initialiser) { + clearContent(); + resetPages(); + const mainPage = MainPage(); + let response; + while (true) { + const result = await endpoint.query(); + if (result instanceof Error) { + mainPage.removeContents(); + await new Promise(resolve => mainPage.append(RetryDialog(resolve))); + continue; + } + response = result; + break; + } + using = { endpoint: endpoint, initialiser: initialiser, pageCount: response.page_count }; + await setup(response.data, 0, response.page_count); + return component; + }, + orElse(contentInitialiser) { + orElseContentInitialiser = contentInitialiser; + if (isEmpty) { + clearContent(); + resetPages(); + const mainPage = MainPage() + .style.remove("paginator-page--hidden"); + content.style("paginator-content--or-else"); + contentInitialiser(mainPage); + } + return component; + }, + })); + return paginator; + function clearContent() { + content.removeContents(); + block.footer.style("paginator-footer--hidden"); + } + function resetPages() { + pageContent = []; + pages = []; + cursor.value = 0; + } + async function setup(initialData, page, pageCount) { + if (pageCount === true || pageCount > 1) + block.footer.style.remove("paginator-footer--hidden"); + if (pageCount !== true) + while (pages.length < pageCount) + pages.push(Page()); + const pageComponent = pages[page] + .style("paginator-page--initial-load") + .style.remove("paginator-page--hidden"); + pageContent[page] = initialData; + cursor.value = page; + data.refresh(); + if (initialData && (!Array.isArray(initialData) || initialData.length)) { + await using.initialiser(pageComponent, initialData, paginator); + isEmpty = false; + } + else { + content.style("paginator-content--or-else"); + orElseContentInitialiser?.(pageComponent); + } + updateButtons(page); + } + function MainPage() { + const mainPage = Page() + .style("paginator-page--initial-load"); + pages.push(mainPage); + return mainPage; + } + function Page() { + return (0, Slot_5.default)() + .style("paginator-page", "paginator-page--hidden") + .style.bind(isFlush, "paginator-page--flush") + .appendTo(content); + } + function RetryDialog(retry) { + return (0, Component_37.default)() + .style("paginator-error") + .append((0, Component_37.default)() + .style("paginator-error-text") + .text.use("component/paginator/error")) + .append((0, Button_7.default)() + .type("primary") + .text.use("component/paginator/error/retry") + .event.subscribe("click", () => retry())); + } + function updateButtons(page = cursor.value, pageCount = using?.pageCount ?? 0) { + buttonFirst.style.toggle(page <= 0, "paginator-button--disabled"); + buttonPrev.style.toggle(page <= 0, "paginator-button--disabled"); + buttonNext.style.toggle(pageCount !== true && page >= pageCount - 1, "paginator-button--disabled"); + buttonLast.style.toggle(pageCount !== true && page >= pageCount - 1, "paginator-button--disabled"); + buttonLast.style.toggle(pageCount === true, "paginator-button--hidden"); + } + async function showPage(number) { + if (cursor.value === number || !using) + return; + const oldNumber = cursor.value; + const direction = Math.sign(number - oldNumber); + pages[oldNumber] + .style.remove("paginator-page--initial-load", "paginator-page--bounce") + .style("paginator-page--hidden") + .style.setVariable("page-direction", direction); + let page = pages[number]; + if (!page) + pages.push(page ??= Page()); + page.style.setVariable("page-direction", direction); + updateButtons(number); + if (pageContent[number]) { + cursor.value = number; + page.style.remove("paginator-page--hidden"); + scrollIntoView(direction); + return; + } + let response; + while (true) { + page.removeContents(); + showingPage = number; + const result = await using?.endpoint.query({ query: { page: number } }); + if (showingPage !== number) + return; + const isError = result instanceof Error; + if (!isError && !hasResults(result.data)) { + cursor.value = number; + pages[oldNumber].style("paginator-page--bounce"); + await Async_3.default.sleep(200); + return showPage(oldNumber); + } + page.style.remove("paginator-page--hidden"); + if (isError) { + await new Promise(resolve => { + RetryDialog(resolve).appendTo(page); + block.header.element.scrollIntoView(); + }); + if (showingPage !== number) + return; + continue; + } + response = result; + break; + } + pageContent[number] = response.data; + cursor.value = number; + await using?.initialiser(page, response.data, paginator); + scrollIntoView(direction); + } + function scrollIntoView(direction) { + const scrollTarget = direction > 0 ? block.element : pages[cursor.value].element.lastElementChild; + scrollTarget?.scrollIntoView(); + } + }); + function hasResults(result) { + if (result === null || result === undefined) + return false; + if (typeof result !== "object") + return true; + if (Array.isArray(result)) + return result.length > 0; + for (const sub of Object.values(result)) + if (hasResults(sub)) + return true; + return false; + } + exports.default = Paginator; +}); +define("endpoint/tag/EndpointTagManifest", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_11 = __importDefault(Endpoint_11); + exports.default = (0, Endpoint_11.default)("/manifest/tags", "get"); +}); +define("model/Tags", ["require", "exports", "endpoint/tag/EndpointTagManifest", "model/Manifest"], function (require, exports, EndpointTagManifest_1, Manifest_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.resolve = resolve; + EndpointTagManifest_1 = __importDefault(EndpointTagManifest_1); + Manifest_2 = __importDefault(Manifest_2); + const Tags = Object.assign((0, Manifest_2.default)({ + get() { + return EndpointTagManifest_1.default.query(); + }, + }), { resolve }); + exports.default = Tags; + async function resolve(tags, name) { + if (!tags?.length) + return []; + if (Array.isArray(tags)) + return resolveInternal(tags); + const tag = name ? `${tags}: ${name}` : tags; + const [result] = await resolveInternal([tag]); + return result; + } + async function resolveInternal(tags) { + const result = []; + let manifest = await Tags.getManifest(); + resolveTags(); + if (result.length !== tags.length && !Tags.isFresh()) { + manifest = await Tags.getManifest(true); + resolveTags(); + } + return result; + function resolveTags() { + result.splice(0, Infinity); + for (const tagString of tags) { + const tag = manifest.tags[tagString]; + if (!tag) + continue; + result.push(tag); + } + } + } +}); +define("ui/component/core/TextLabel", ["require", "exports", "ui/Component"], function (require, exports, Component_38) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_38 = __importDefault(Component_38); + const TextLabel = Component_38.default.Builder((component) => { + component.style("text-label"); + const label = (0, Component_38.default)() + .style("text-label-label"); + const punctuation = (0, Component_38.default)() + .style("text-label-punctuation") + .text.set(": "); + const content = (0, Component_38.default)() + .style("text-label-content"); + return component + .append(label, punctuation, content) + .extend(() => ({ + label, content, + })); + }); + exports.default = TextLabel; +}); +define("ui/component/core/Timestamp", ["require", "exports", "ui/Component", "utility/State", "utility/Time"], function (require, exports, Component_39, State_23, Time_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_39 = __importDefault(Component_39); + State_23 = __importDefault(State_23); + Time_7 = __importDefault(Time_7); + const Timestamp = Component_39.default.Builder((component, time) => { + const state = (0, State_23.default)(new Date(time ?? Date.now())); + state.use(component, update); + return component + .style("timestamp") + .extend(component => ({ time: state })) + .onRooted(component => { + update(); + const interval = setInterval(update, Time_7.default.seconds(1)); + component.event.subscribe("remove", () => clearInterval(interval)); + }); + function update() { + component.text.set(Time_7.default.relative(state.value.getTime(), { components: 2, secondsExclusive: true })); + } + }); + exports.default = Timestamp; +}); +define("ui/component/Tag", ["require", "exports", "ui/Component", "ui/component/core/Button", "ui/component/core/Link"], function (require, exports, Component_40, Button_8, Link_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_40 = __importDefault(Component_40); + Button_8 = __importDefault(Button_8); + Link_1 = __importDefault(Link_1); + const toURLRegex = /\W+/g; + const toURL = (name) => name.replaceAll(toURLRegex, "-").toLowerCase(); + const Tag = Component_40.default.Builder("a", (component, tag) => { + component + .and(Link_1.default, `/tag/${toURL(tag.category)}/${toURL(tag.name)}`) + .and(Button_8.default) + .style("tag"); + (0, Component_40.default)() + .style("tag-category") + .text.set(tag.category) + .appendTo(component); + (0, Component_40.default)() + .style("tag-name") + .text.set(tag.name) + .appendTo(component); + // component.href.use(`/tag/${tag.id}`) + return component.extend(component => ({ tag })); + }); + exports.default = Tag; +}); +define("ui/component/Work", ["require", "exports", "model/Session", "model/Tags", "ui/Component", "ui/component/core/Block", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Slot", "ui/component/core/TextLabel", "ui/component/core/Timestamp", "ui/component/Tag"], function (require, exports, Session_7, Tags_1, Component_41, Block_8, Button_9, Link_2, Slot_6, TextLabel_1, Timestamp_1, Tag_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_7 = __importDefault(Session_7); + Tags_1 = __importDefault(Tags_1); + Component_41 = __importDefault(Component_41); + Block_8 = __importDefault(Block_8); + Button_9 = __importDefault(Button_9); + Link_2 = __importDefault(Link_2); + Slot_6 = __importDefault(Slot_6); + TextLabel_1 = __importDefault(TextLabel_1); + Timestamp_1 = __importDefault(Timestamp_1); + Tag_1 = __importDefault(Tag_1); + const Work = Component_41.default.Builder(async (component, work, author, notFullOverride) => { + author = author ?? work.synopsis?.mentions[0]; + component + .viewTransition("work") + .style("work") + .style.toggle(component.is(Link_2.default), "work--link"); + const block = component.and(Block_8.default); + const isFlush = block.type.state.mapManual(types => types.has("flush")); + block.header.style("work-header"); + block.title + .style("work-name") + .text.set(work.name); + if (author) + block.description + .style("work-author-list") + .style.bind(isFlush, "work-author-list--flush") + .append((0, Link_2.default)(`/author/${author.vanity}`) + .style("work-author") + .text.set(author.name)); + block.content.style("work-content"); + (0, Slot_6.default)() + .use(isFlush, (slot, isFlush) => { + isFlush ||= notFullOverride ?? false; + const shouldShowDescription = isFlush || (work.synopsis?.body && work.description); + if (shouldShowDescription) + (0, Component_41.default)() + .style("work-description") + .style.toggle(!work.description, "placeholder") + .tweak(component => { + if (work.description) + component.text.set(work.description); + else + component.text.use("work/description/empty"); + }) + .appendTo(slot); + if (!isFlush) + (0, Component_41.default)() + .style("work-synopsis") + .style.toggle(!work.synopsis?.body && !work.description, "placeholder") + .append(Slot_6.default.using(work.synopsis ?? work.description, (slot, synopsis) => { + if (typeof synopsis === "string") + slot.text.set(synopsis); + else if (!synopsis.body) + slot.text.use("work/description/empty"); + else + slot.setMarkdownContent(synopsis.body); + })) + .appendTo(slot); + }) + .appendTo(block.content); + let tagsWrapper; + const tags = await Tags_1.default.resolve(work.global_tags); + for (const tag of tags) { + (0, Tag_1.default)(tag) + .appendTo(tagsWrapper ??= (0, Component_41.default)() + .style("work-tags") + .style.bind(isFlush, "work-tags--flush") + .appendTo(block.content)); + } + (0, TextLabel_1.default)() + .tweak(textLabel => textLabel.label.text.use("work/chapters/label")) + .tweak(textLabel => textLabel.content.text.set(`${work.chapter_count_public}`)) + .appendTo(block.footer.left); + if (work.time_last_update) + block.footer.right.append((0, Timestamp_1.default)(work.time_last_update).style("work-timestamp")); + block.setActionsMenu((popover, button) => { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/view") + .event.subscribe("click", () => navigate.toURL(`/work/${author?.vanity}/${work.vanity}`)) + .appendTo(popover); + if (author && author.vanity === Session_7.default.Auth.author.value?.vanity) { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/edit") + .event.subscribe("click", () => navigate.toURL(`/work/${author.vanity}/${work.vanity}/edit`)) + .appendTo(popover); + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/delete") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + else if (Session_7.default.Auth.loggedIn.value) { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/follow") + .event.subscribe("click", () => { }) + .appendTo(popover); + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/ignore") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + }); + return block.extend(component => ({ work })); + }); + exports.default = Work; +}); +define("ui/view/AuthorView", ["require", "exports", "endpoint/author/EndpointAuthorGet", "endpoint/work/EndpointWorkGetAllAuthor", "model/Session", "ui/Component", "ui/component/Author", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Paginator", "ui/component/core/Slot", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, EndpointAuthorGet_1, EndpointWorkGetAllAuthor_1, Session_8, Component_42, Author_1, Button_10, Link_3, Paginator_1, Slot_7, Work_1, View_3, ViewDefinition_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorGet_1 = __importDefault(EndpointAuthorGet_1); + EndpointWorkGetAllAuthor_1 = __importDefault(EndpointWorkGetAllAuthor_1); + Session_8 = __importDefault(Session_8); + Component_42 = __importDefault(Component_42); + Author_1 = __importDefault(Author_1); + Button_10 = __importDefault(Button_10); + Link_3 = __importDefault(Link_3); + Paginator_1 = __importDefault(Paginator_1); + Slot_7 = __importDefault(Slot_7); + Work_1 = __importDefault(Work_1); + View_3 = __importDefault(View_3); + ViewDefinition_2 = __importDefault(ViewDefinition_2); + exports.default = (0, ViewDefinition_2.default)({ + create: async (params) => { + const view = (0, View_3.default)("author"); + const author = await EndpointAuthorGet_1.default.query({ params }); + if (author instanceof Error) + throw author; + (0, Author_1.default)(author.data) + .viewTransition("author-view-author") + .setContainsHeading() + .appendTo(view); + const paginator = (0, Paginator_1.default)() + .viewTransition("author-view-works") + .tweak(p => p.title.text.use("view/author/works/title")) + .tweak(p => p.primaryActions.append((0, Slot_7.default)() + .if(Session_8.default.Auth.loggedIn, () => (0, Button_10.default)() + .setIcon("plus") + .ariaLabel.use("view/author/works/action/label/new") + .event.subscribe("click", () => navigate.toURL("/work/new"))))) + .appendTo(view); + const worksQuery = EndpointWorkGetAllAuthor_1.default.prep({ + params: { + author: params.vanity, + }, + }); + await paginator.useEndpoint(worksQuery, async (slot, works) => { + for (const workData of works) { + const work = await (0, Link_3.default)(`/work/${author.data.vanity}/${workData.vanity}`) + .and(Work_1.default, workData, author.data); + work + .viewTransition() + .type("flush") + .appendTo(slot); + } + }); + paginator.orElse(slot => (0, Component_42.default)() + .style("placeholder") + .text.use("view/author/works/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("endpoint/work/EndpointWorkGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_12 = __importDefault(Endpoint_12); + exports.default = (0, Endpoint_12.default)("/work/{author}/{vanity}/get", "get"); +}); +define("endpoint/chapter/EndpointChapterGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_13 = __importDefault(Endpoint_13); + exports.default = (0, Endpoint_13.default)("/work/{author}/{vanity}/chapter/{url}/get", "get"); +}); +define("endpoint/chapter/EndpointChapterCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_14) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_14 = __importDefault(Endpoint_14); + exports.default = (0, Endpoint_14.default)("/work/{author}/{vanity}/chapter/create", "post"); +}); +define("endpoint/chapter/EndpointChapterUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_15) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_15 = __importDefault(Endpoint_15); + exports.default = (0, Endpoint_15.default)("/work/{author}/{vanity}/chapter/{url}/update", "post"); +}); +define("ui/view/chapter/ChapterEditForm", ["require", "exports", "endpoint/chapter/EndpointChapterCreate", "endpoint/chapter/EndpointChapterUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast"], function (require, exports, EndpointChapterCreate_1, EndpointChapterUpdate_1, en_nz_5, FormInputLengths_2, Session_9, Component_43, Block_9, Form_3, LabelledTable_2, TextEditor_2, TextInput_4, Toast_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterCreate_1 = __importDefault(EndpointChapterCreate_1); + EndpointChapterUpdate_1 = __importDefault(EndpointChapterUpdate_1); + en_nz_5 = __importDefault(en_nz_5); + FormInputLengths_2 = __importDefault(FormInputLengths_2); + Session_9 = __importDefault(Session_9); + Component_43 = __importDefault(Component_43); + Block_9 = __importDefault(Block_9); + Form_3 = __importDefault(Form_3); + LabelledTable_2 = __importDefault(LabelledTable_2); + TextEditor_2 = __importDefault(TextEditor_2); + TextInput_4 = __importDefault(TextInput_4); + exports.default = Component_43.default.Builder((component, state, workParams) => { + const block = component.and(Block_9.default); + const form = block.and(Form_3.default, block.title); + form.viewTransition("chapter-edit-form"); + const type = state.value ? "update" : "create"; + form.title.text.use(`view/chapter-edit/${type}/title`); + form.setName(en_nz_5.default[`view/chapter-edit/${type}/title`]().toString()); + // if (params.type === "create") + // form.description.text.use("view/work-edit/create/description") + form.submit.textWrapper.text.use(`view/chapter-edit/${type}/submit`); + const table = (0, LabelledTable_2.default)().appendTo(form.content); + const nameInput = (0, TextInput_4.default)() + .setRequired() + .default.bind(state.map(component, work => work?.name)) + .hint.use("view/chapter-edit/shared/form/name/hint") + .setMaxLength(FormInputLengths_2.default.manifest?.chapter.name); + table.label(label => label.text.use("view/chapter-edit/shared/form/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const bodyInput = (0, TextEditor_2.default)() + .default.bind(state.map(component, chapter => chapter?.body ?? undefined)) + .hint.use("view/chapter-edit/shared/form/body/hint"); + table.label(label => label.text.use("view/chapter-edit/shared/form/body/label")) + .content((content, label) => content.append(bodyInput.setLabel(label))); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const response = await (() => { + switch (type) { + case "create": + return EndpointChapterCreate_1.default.query({ + params: workParams, + body: { + name: nameInput.value, + body: bodyInput.useMarkdown(), + visibility: "Private", + }, + }); + case "update": { + if (!state.value) + return; + const authorVanity = Session_9.default.Auth.author.value?.vanity; + if (!authorVanity) + return new Error("Cannot update a work when not signed in"); + return EndpointChapterUpdate_1.default.query({ + params: { + ...workParams, + url: state.value.url, + }, + body: { + name: nameInput.value, + body: bodyInput.useMarkdown(), + visibility: "Private", + }, + }); + } + } + })(); + if (response instanceof Error) { + toast.warning(Toast_2.TOAST_ERROR, "view/chapter-edit/shared/toast/failed-to-save", response); + console.error(response); + return; + } + toast.success(Toast_2.TOAST_SUCCESS, "view/chapter-edit/shared/toast/saved"); + state.value = response?.data; + }); + return form; + }); +}); +define("ui/view/ChapterEditView", ["require", "exports", "endpoint/chapter/EndpointChapterGet", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/Slot", "ui/view/chapter/ChapterEditForm", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "utility/State"], function (require, exports, EndpointChapterGet_1, ActionRow_4, Button_11, Slot_8, ChapterEditForm_1, View_4, ViewDefinition_3, ViewTransition_3, State_24) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGet_1 = __importDefault(EndpointChapterGet_1); + ActionRow_4 = __importDefault(ActionRow_4); + Button_11 = __importDefault(Button_11); + Slot_8 = __importDefault(Slot_8); + ChapterEditForm_1 = __importDefault(ChapterEditForm_1); + View_4 = __importDefault(View_4); + ViewDefinition_3 = __importDefault(ViewDefinition_3); + ViewTransition_3 = __importDefault(ViewTransition_3); + State_24 = __importDefault(State_24); + exports.default = (0, ViewDefinition_3.default)({ + requiresLogin: true, + create: async (params) => { + const id = "chapter-edit"; + const view = (0, View_4.default)(id); + const chapter = !params.url ? undefined : await EndpointChapterGet_1.default.query({ params: params }); + if (chapter instanceof Error) + throw chapter; + const state = (0, State_24.default)(chapter?.data); + const stateInternal = (0, State_24.default)(chapter?.data); + (0, Slot_8.default)() + .use(state, () => (0, ChapterEditForm_1.default)(stateInternal, params).subviewTransition(id)) + .appendTo(view); + (0, Slot_8.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + stateInternal.subscribe(view, chapter => ViewTransition_3.default.perform("subview", id, () => state.value = chapter)); + return view; + function createActionRow() { + if (!stateInternal.value) + return; + return (0, ActionRow_4.default)() + .viewTransition("chapter-edit-action-row") + .tweak(row => row.right + .append((0, Button_11.default)() + .text.use("view/chapter-edit/update/action/delete") + .event.subscribe("click", async () => { + // const response = await EndpointAuthorDelete.query() + // if (response instanceof Error) { + // console.error(response) + // return + // } + // return Session.reset() + }))); + } + }, + }); +}); +define("endpoint/chapter/EndpointChapterGetPaged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_16) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_16 = __importDefault(Endpoint_16); + exports.default = (0, Endpoint_16.default)("/work/{author}/{vanity}/chapters/paged", "get"); +}); +define("ui/view/shared/component/PaginatedView", ["require", "exports", "ui/Component", "ui/component/core/Paginator", "ui/view/shared/component/View"], function (require, exports, Component_44, Paginator_2, View_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_44 = __importDefault(Component_44); + Paginator_2 = __importDefault(Paginator_2); + View_5 = __importDefault(View_5); + const PaginatedView = Component_44.default.Builder((_, id) => { + let paginator; + const urls = []; + return (0, View_5.default)(id) + .extend(view => ({ + setURL, + paginator: () => { + paginator ??= (0, Paginator_2.default)().extend(paginator => ({ setURL })); + paginator.page.subscribeManual(page => { + const route = urls[page]; + if (route) + navigate.setURL(route); + }); + return paginator; + }, + })); + function setURL(route) { + navigate.setURL(route); + const page = paginator?.page.value; + if (page !== undefined) + urls[page] = route; + } + }); + exports.default = PaginatedView; +}); +define("utility/maths/Maths", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Maths; + (function (Maths) { + function sum(...nums) { + let result = 0; + for (const num of nums) + result += num; + return result; + } + Maths.sum = sum; + function average(...nums) { + let result = 0; + for (const num of nums) + result += num; + return result / nums.length; + } + Maths.average = average; + function bits(number) { + const result = new BitsSet(); + for (let i = 52; i >= 0; i--) { + const v = 1 << i; + if (number & v) + result.add(v); + } + return result; + } + Maths.bits = bits; + class BitsSet extends Set { + everyIn(type) { + const t = type ?? 0; + for (const bit of this) + if (!(t & bit)) + return false; + return true; + } + someIn(type) { + const t = type ?? 0; + for (const bit of this) + if (t & bit) + return true; + return false; + } + every(predicate) { + for (const bit of this) + if (!predicate(bit)) + return false; + return true; + } + some(predicate) { + for (const bit of this) + if (predicate(bit)) + return true; + return false; + } + } + Maths.BitsSet = BitsSet; + function bitsn(flag) { + const result = new BitsSetN(); + for (let i = 52n; i >= 0n; i--) { + const v = 1n << i; + if (flag & v) + result.add(v); + } + return result; + } + Maths.bitsn = bitsn; + class BitsSetN extends Set { + everyIn(type) { + const t = type ?? 0n; + for (const bit of this) + if (!(t & bit)) + return false; + return true; + } + someIn(type) { + const t = type ?? 0n; + for (const bit of this) + if (t & bit) + return true; + return false; + } + every(predicate) { + for (const bit of this) + if (!predicate(bit)) + return false; + return true; + } + some(predicate) { + for (const bit of this) + if (predicate(bit)) + return true; + return false; + } + } + Maths.BitsSetN = BitsSetN; + function lerp(from, to, t) { + return (1 - t) * from + t * to; + } + Maths.lerp = lerp; + function parseIntOrUndefined(value) { + const result = parseFloat(value); + return isNaN(result) || !Number.isInteger(result) ? undefined : result; + } + Maths.parseIntOrUndefined = parseIntOrUndefined; + })(Maths || (Maths = {})); + exports.default = Maths; +}); +define("ui/view/ChapterView", ["require", "exports", "endpoint/chapter/EndpointChapterGet", "endpoint/chapter/EndpointChapterGetPaged", "endpoint/work/EndpointWorkGet", "lang/en-nz", "ui/component/Work", "ui/view/shared/component/PaginatedView", "ui/view/shared/component/ViewDefinition", "utility/maths/Maths", "utility/State"], function (require, exports, EndpointChapterGet_2, EndpointChapterGetPaged_1, EndpointWorkGet_1, en_nz_6, Work_2, PaginatedView_1, ViewDefinition_4, Maths_1, State_25) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGet_2 = __importDefault(EndpointChapterGet_2); + EndpointChapterGetPaged_1 = __importDefault(EndpointChapterGetPaged_1); + EndpointWorkGet_1 = __importDefault(EndpointWorkGet_1); + en_nz_6 = __importDefault(en_nz_6); + Work_2 = __importDefault(Work_2); + PaginatedView_1 = __importDefault(PaginatedView_1); + ViewDefinition_4 = __importDefault(ViewDefinition_4); + Maths_1 = __importDefault(Maths_1); + State_25 = __importDefault(State_25); + exports.default = (0, ViewDefinition_4.default)({ + create: async (params) => { + const view = (0, PaginatedView_1.default)("chapter"); + const response = await EndpointWorkGet_1.default.query({ params }); + if (response instanceof Error) + throw response; + const author = response.data.synopsis.mentions.find(author => author.vanity === params.author); + const workData = response.data; + delete workData.synopsis; + delete workData.custom_tags; + const work = await (0, Work_2.default)(workData, author); + work + .viewTransition("work-view-work") + .style("view-type-chapter-work") + .setContainsHeading() + .appendTo(view); + const initialChapterResponse = await EndpointChapterGet_2.default.query({ params }); + if (initialChapterResponse instanceof Error) + throw initialChapterResponse; + const chapterState = (0, State_25.default)(initialChapterResponse.data); + const chaptersQuery = EndpointChapterGetPaged_1.default.prep({ params }); + const paginator = await view.paginator() + .viewTransition("chapter-view-chapter") + .style("view-type-chapter-block") + .tweak(p => p.title.text.bind(chapterState.mapManual(chapter => en_nz_6.default["view/chapter/title"](Maths_1.default.parseIntOrUndefined(chapter.url), chapter.name)))) + .appendTo(view) + .useInitial(initialChapterResponse.data, initialChapterResponse.page, initialChapterResponse.page_count) + .thenUse(chaptersQuery) + .withContent((slot, chapter, paginator) => { + paginator.setURL(`/work/${params.author}/${params.vanity}/chapter/${chapter.url}`); + slot + .style("view-type-chapter-block-body") + .setMarkdownContent(chapter.body ?? ""); + }); + paginator.data.use(paginator, chapter => chapterState.value = chapter); + return view; + }, + }); +}); +define("ui/view/debug/ButtonRegistry", ["require", "exports", "model/Session", "utility/Env"], function (require, exports, Session_10, Env_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BUTTON_REGISTRY = void 0; + Session_10 = __importDefault(Session_10); + Env_5 = __importDefault(Env_5); + exports.BUTTON_REGISTRY = { + createAuthor: { + name: "Create Author", + async execute(name, vanity, description, pronouns) { + const response = await fetch(`${Env_5.default.API_ORIGIN}author/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + "Accept": "application/json", + }, + body: JSON.stringify({ + name: name, + vanity: vanity, + description: description, + pronouns: pronouns, + }), + }).then(response => response.json()); + console.log(response); + await Session_10.default.refresh(); + }, + }, + updateAuthor: { + name: "Update Author", + async execute(name, description, vanity, support_link, support_message) { + await fetch(`${Env_5.default.API_ORIGIN}author/update`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + vanity: vanity, + support_link: support_link, + support_message: support_message, + }), + }); + }, + }, + deleteAuthor: { + name: "Delete Author", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}author/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewAuthor: { + name: "View Author", + async execute(label, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}author/${vanity}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + clearSession: { + name: "Clear Session", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}session/reset`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + }); + await Session_10.default.refresh(); + }, + }, + createWork: { + name: "Create Work", + async execute(name, synopsis, description, vanity, status, visibility, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + synopsis: synopsis, + description: description, + vanity: vanity, + status: status, + visibility: visibility, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateWork: { + name: "Update Work", + async execute(author, url, name, description, vanity, status, visibility) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/update`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + vanity: vanity, + status: status, + visibility: visibility, + }), + }); + }, + }, + deleteWork: { + name: "Delete Work", + async execute(author, url) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewWork: { + name: "View Work", + async execute(label, author, url) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllWorksByAuthor: { + name: "View All Works By Author", + async execute(label, author) { + const response = await fetch(`${Env_5.default.API_ORIGIN}works/${author}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + createChapter: { + name: "Create Chapter", + async execute(author, work_url, name, body, visibility, is_numbered, notesBefore, notesAfter, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + body: body, + visibility: visibility, + is_numbered: is_numbered, + notes_before: notesBefore, + notes_after: notesAfter, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateChapter: { + name: "Update Chapter", + async execute(author, work_url, index, name, body, visibility, is_numbered, notesBefore, notesAfter, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/update`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name, + body, + visibility, + is_numbered, + notes_before: notesBefore, + notes_after: notesAfter, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + deleteChapter: { + name: "Delete Chapter", + async execute(author, work_url, index) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewChapter: { + name: "View Chapter", + async execute(label, author, work_url, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + viewChapterPaginated: { + name: "View Chapter Paginated", + async execute(label, author, work_url, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapters/individual?page=${index}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllChapters: { + name: "Get All Chapters", + async execute(author, vanity, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapters/list?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + follow: { + name: "Follow", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}follow/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + followWork: { + name: "Follow", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}follow/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unfollow: { + name: "Unfollow", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unfollow/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unfollowWork: { + name: "Unfollow", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unfollow/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + getFollow: { + name: "Get Follow", + async execute(type, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}follows/${type}/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getFollowWork: { + name: "Get Follow", + async execute(author_vanity, work_vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}follows/work/${author_vanity}/${work_vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllFollows: { + name: "Get All Follows", + async execute(type, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}following/${type}?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllFollowsMerged: { + name: "Get All Follows Merged", + async execute(page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}following?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + ignore: { + name: "Ignore", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}ignore/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + ignoreWork: { + name: "Ignore", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}ignore/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unignore: { + name: "Unignore", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unignore/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unignoreWork: { + name: "Unignore", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unignore/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + getIgnore: { + name: "Get Ignore", + async execute(type, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignores/${type}/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getIgnoreWork: { + name: "Get Ignore", + async execute(author_vanity, work_vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignores/work/${author_vanity}/${work_vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllIgnores: { + name: "Get All Ignores", + async execute(type, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignoring/${type}?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllIgnoresMerged: { + name: "Get All Ignores Merged", + async execute(page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignoring?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + privilegeGetAllAuthor: { + name: "Get All Author Privileges", + async execute(label, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/get/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + privilegeGrantAuthor: { + name: "Grant Privileges to Author", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/grant/author/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("granted privileges", response); + }, + }, + privilegeRevokeAuthor: { + name: "Revoke Privileges from Author", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/revoke/author/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("revoked privileges", response); + }, + }, + createRole: { + name: "Create Role", + async execute(roleName, visibilty, roleBelow) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: roleName, + below: roleBelow, + description: "idk some test stuff", + visibilty: visibilty, + }), + }).then(response => response.json()); + console.log("created role", response); + }, + }, + deleteRole: { + name: "Delete Role", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/delete/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("deleted role", response); + }, + }, + editRole: { + name: "Edit Role", + async execute(vanity, name, description) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/update/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + }), + }).then(response => response.json()); + console.log("edited role", response); + }, + }, + grantRoleToAuthor: { + name: "Grant Role to Author", + async execute(roleVanity, authorVanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/grant/${roleVanity}/${authorVanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("granted role", response); + }, + }, + revokeRoleFromAuthor: { + name: "Revoke Role from Author", + async execute(roleVanity, authorVanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/revoke/${roleVanity}/${authorVanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("granted role", response); + }, + }, + privilegeGrantRole: { + name: "Grant Privileges to Role", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/grant/role/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("granted privileges to role", response); + }, + }, + privilegeRevokeRole: { + name: "Revoke Privileges from Role", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/revoke/role/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("revoked privileges from role", response); + }, + }, + roleListAll: { + name: "List all roles", + async execute(label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + roleReorder: { + name: "Reorder roles", + async execute(...roles) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/reorder`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + roles, + }), + }).then(response => response.json()); + console.log("reordered roles", response); + }, + }, + createCommentChapter: { + name: "Create Comment Chapter", + async execute(author, vanity, index, body, parent_id) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapter/${index}/comment/add`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + body, + parent_id, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateCommentChapter: { + name: "Update Comment Chapter", + async execute(id, comment_body) { + const response = await fetch(`${Env_5.default.API_ORIGIN}comment/update/chapter`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + body: comment_body, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + deleteCommentChapter: { + name: "Delete Comment Chapter", + async execute(id) { + await fetch(`${Env_5.default.API_ORIGIN}comment/remove/chapter`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + }), + }); + }, + }, + getComment: { + name: "Get Comment", + async execute(id, label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}comment/get`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + }), + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllComments: { + name: "Get All Comments", + async execute(author, vanity, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapter/${index}/comments`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + patreonGetTiers: { + name: "Get Tiers", + async execute(label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}patreon/campaign/tiers/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + patreonSetThresholds: { + name: "Set Chapter Thresholds", + async execute(author_vanity, work_vanity, visibility, chapters, tier_id) { + const response = await fetch(`${Env_5.default.API_ORIGIN}patreon/campaign/tiers/set/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + visibility: visibility, + chapters: chapters, + tier_id: tier_id, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagCreateCategory: { + name: "Tag Create Category", + async execute(categoryName, categoryDescription) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/create/category`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: categoryName, + description: categoryDescription, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagCreateGlobal: { + name: "Tag Create Global", + async execute(tagName, tagDescription, tagCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/create/global`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: tagName, + description: tagDescription, + category: tagCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagPromoteCustom: { + name: "Tag Promote Custom", + async execute(tagName, newDescription, newCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/promote/${tagName}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + description: newDescription, + category: newCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagDemoteGlobal: { + name: "Tag Demote Global", + async execute(tagName) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/demote/${tagName}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagUpdateCategory: { + name: "Tag Update Category", + async execute(vanity, categoryName, categoryDescription) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/update/category/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: categoryName, + description: categoryDescription, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagUpdateGlobal: { + name: "Tag Update Global", + async execute(vanity, tagName, tagDescription, tagCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/update/global/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: tagName, + description: tagDescription, + category: tagCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagRemoveCategory: { + name: "Tag Remove Category", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/remove/category/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagRemoveGlobal: { + name: "Tag Remove Global", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/remove/global/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagGetManifest: { + name: "Tag Get Manifest", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}manifest/tags`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + manifestFormLengthGet: { + name: "Form Length Manifest", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}manifest/form/lengths`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsGet: { + name: "Get Notifications", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}notifications/get/all`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsGetUnread: { + name: "Get Unread Notifications", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}notifications/get/unread`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsMark: { + name: "Mark Notifications Read/Unread", + async execute(state, notifications) { + await fetch(`${Env_5.default.API_ORIGIN}notifications/mark/${state}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + notification_ids: notifications, + }), + }); + }, + }, + seedBulk: { + name: "Seed Bulk", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}seed/bulk`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + feedGet: { + name: "Get Feed", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}feed/get`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + }; +}); +define("ui/view/DebugView", ["require", "exports", "endpoint/auth/EndpointAuthServices", "model/Session", "ui/Component", "ui/component/core/Button", "ui/view/debug/ButtonRegistry", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Env", "utility/Objects", "utility/Popup"], function (require, exports, EndpointAuthServices_2, Session_11, Component_45, Button_12, ButtonRegistry_1, View_6, ViewDefinition_5, Env_6, Objects_4, Popup_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthServices_2 = __importDefault(EndpointAuthServices_2); + Session_11 = __importDefault(Session_11); + Component_45 = __importDefault(Component_45); + Button_12 = __importDefault(Button_12); + View_6 = __importDefault(View_6); + ViewDefinition_5 = __importDefault(ViewDefinition_5); + Env_6 = __importDefault(Env_6); + Objects_4 = __importDefault(Objects_4); + Popup_2 = __importDefault(Popup_2); + const Block = Component_45.default.Builder(component => component + .style("debug-block")); + exports.default = (0, ViewDefinition_5.default)({ + async create() { + const view = (0, View_6.default)("debug"); + const createButton = (implementation, ...args) => { + return (0, Button_12.default)() + .text.set(implementation.name) + .event.subscribe("click", async () => { + try { + await implementation.execute(...args); + } + catch (err) { + const error = err; + console.warn(`Button ${implementation.name} failed to execute:`, error); + } + }); + }; + const oauthDiv = Block().appendTo(view); + const OAuthServices = await EndpointAuthServices_2.default.query(); + for (const service of Objects_4.default.values(OAuthServices.data ?? {})) { + if (!service) + continue; + (0, Button_12.default)() + .text.set(`OAuth ${service.name}`) + .event.subscribe("click", async () => { + await (0, Popup_2.default)(`OAuth ${service.name}`, service.url_begin, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(oauthDiv); + (0, Button_12.default)() + .text.set(`UnOAuth ${service.name}`) + .event.subscribe("click", async () => { + const id = Session_11.default.Auth.get(service.id)?.id; + if (id === undefined) + return; + await fetch(`${Env_6.default.API_ORIGIN}auth/remove`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ id }), + }); + }) + .appendTo(oauthDiv); + } + // document.body.append(createButton(BUTTON_REGISTRY.createAuthor, "test author 1", "hi-im-an-author")); + oauthDiv.append(createButton(ButtonRegistry_1.BUTTON_REGISTRY.clearSession)); + const profileButtons = Block().appendTo(view); + profileButtons.append(createButton({ + name: "Seed Bulk Data", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.seedBulk.execute(); + }, + })); + profileButtons.append(createButton({ + name: "Create Profile 1", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("prolific author", "somanystories", "wow a description that mentions ", "she/her pronies m8"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("a debut work", "pretty decent by ", "short description", "debut", "Complete", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "debut", "chapter 1", "woo look it's prolific author's first story!", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("sequel to debut", "wow they wrote a sequel", "sequel short description", "sequel", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "sequel", "the chapters", "pretend there's a story here", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("work in progress", "test", "short description test", "wip", "Ongoing", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "wip", "draft", "it's a rough draft", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "debut"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "sequel"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "wip"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "somanystories"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 1", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("author with many stories", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "somanystories"); + }, + })); + profileButtons.append(createButton({ + name: "Create Profile 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("single story author", "justonestory", " writes so much"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("one big work", "made by ", "wow description", "bigstory", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 1", "start of a long story", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story interlude", "middle of a long story", "Public", false, "only notes before"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 2", "aaaa", "Public", true, undefined, "only notes after"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3", "aaaaaaa", "Public", true, "both notes before", "and notes after"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.1", "aaaaaaaaaaaaaaaaaaa", "Public", false); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.2", "aaaaaaaaaaaaaaaaaaa", "Private", false); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.3", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 4", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 5", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 6", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateChapter.execute("justonestory", "bigstory", 4, undefined, undefined, undefined, false); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("", "justonestory", "bigstory", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("big story five chapters", "justonestory", "bigstory"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllChapters.execute("justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("0", "justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("4 (3.1)", "justonestory", "bigstory", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("6 (private)", "justonestory", "bigstory", 6); + // await BUTTON_REGISTRY.follow.execute("work", "debut"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("justonestory author", "justonestory"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 2's stories", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("", "justonestory", "bigstory", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("big story five chapters", "justonestory", "bigstory"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllChapters.execute("justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("0", "justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("4 (3.1)", "justonestory", "bigstory", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("6 (private)", "justonestory", "bigstory", 6); + }, + })); + // profileButtons.append(createButton({ + // name: "Set Chiri Patreon chapters", + // async execute () { + // await BUTTON_REGISTRY.patreonSetThresholds.execute("justonestory", "bigstory", "Patreon", ["8", "9"], "4392761") + // }, + // })) + const followButtons = Block().appendTo(view); + followButtons.append(createButton({ + name: "Test New Following", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("new follows", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("wow a work", "test pls ignore", "pls ignore", "wowawork", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.follow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.followWork.execute("thefollower", "wowawork"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.unignoreWork.execute("thefollower", "wowawork"); + // await BUTTON_REGISTRY.unfollow.execute("work", "wowawork"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollowWork.execute("thefollower", "wowawork"); + }, + })); + followButtons.append(createButton({ + name: "Create a work with loads of chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("even longer story", "aaaaaaaaa", "short description aaaaa", "wowbig", "Ongoing", "Public"); + for (let i = 0; i < 2000; i++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "wowbig", `chapter ${i}`, `wow chapter body ${i}`, "Public"); + } + }, + })); + followButtons.append(createButton({ + name: "Follows testing", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(0); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(1); + }, + })); + followButtons.append(createButton({ + name: "Spam Create Follow Work Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("spam create works", "manyworks"); + for (let i = 0; i < 100; i++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute(`rapid story ${i}`, "aaaaaaaaa", "rapid story aaaaa", `rapidstory${i}`, "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.follow.execute("work", `rapidstory${i}`); + } + }, + })); + followButtons.append(createButton({ + name: "Test Ignore Endpoints", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("ignoring myself", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("to ignore", "testing ignoring", "test ignoring", "worktoignore", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.ignore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.ignore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("author"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("author"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnoresMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnoresMerged.execute(); + }, + })); + const privRoleButtons = Block().appendTo(view); + privRoleButtons.append(createButton({ + name: "privileges initial test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "WorkViewPrivate", "PrivilegeViewAuthor"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGetAllAuthor.execute("privileges of somanystories", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeAuthor.execute("somanystories", "WorkViewPrivate"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RevokePrivilege"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeAuthor.execute("somanystories", "WorkViewPrivate"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "ThisPrivilegeDoesntExist"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGetAllAuthor.execute("privileges of somanystories", "somanystories"); + }, + })); + privRoleButtons.append(createButton({ + name: "grant privs for testing", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "PrivilegeRevoke", "RoleCreate", "RoleEdit", "RoleDelete", "RoleGrant", "RoleRevoke", "PrivilegeViewAuthor", "RoleViewAll"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("TestingRevoke", "Visible"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("TestingRevoke", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.revokeRoleFromAuthor.execute("TestingRevoke", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantRole.execute("TestingRevoke", "ViewAllRoles"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeRole.execute("TestingRevoke", "ViewAllRoles"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteRole.execute("TestingRevoke"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("SecondAuthorRole", "Visible"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("SecondAuthorRole", "justonestory"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantRole.execute("SecondAuthorRole", "RoleEdit", "RoleDelete", "RoleCreate"); + // await BUTTON_REGISTRY.privilegeGrantAuthor.execute("justonestory", "ViewPrivateStories"); + }, + })); + privRoleButtons.append(createButton({ + name: "second author test stuff", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("DontWork", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("DoWork", "SecondAuthorRole"); + await ButtonRegistry_1.BUTTON_REGISTRY.editRole.execute("Admin", "CantDoThis"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteRole.execute("SecondAuthorRole"); + }, + })); + privRoleButtons.append(createButton({ + name: "see highest level", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleViewAll", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("NotTopRole", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("NotTopRole", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("listing all roles"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("listing all roles"); + }, + })); + privRoleButtons.append(createButton({ + name: "role reorder test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleViewAll", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role1", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role2", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role3", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role4", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleReorder.execute("Role1", "Role2", "Role3", "Role4"); + }, + })); + const moreRoleButtons = Block().appendTo(view); + moreRoleButtons.append(createButton({ + name: "Make ten billion works", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("lots of works test", "manyworks", "test description"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("manyworks", "TagGlobalCreate", "TagGlobalDelete", "TagGlobalUpdate", "TagCategoryCreate", "TagCategoryUpdate", "TagCategoryDelete", "TagPromote", "TagDemote"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category One", "the first test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Two", "the second test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Three", "the third test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag One", "test tag 1", "Category One"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Two", "test tag 1", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Three", "test tag 1", "Category Three"); + for (let a = 0; a < 333; a++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute(`work${a}`, `description no ${a} mentions \n"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."`, "Lorem ipsum dolor sit amet, consectetur adipiscing elit,", `testwork${a}`, "Ongoing", "Public", ["Category One: Tag One", "Category Two: Tag Two", "Category Three: Tag Three"], ["custom tag one", `custom tag two ${a}`]); + } + for (let a = 0; a < 333; a++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("manyworks", `testwork${a}`, `chapter ${a}`, `it's a test chapter ${a}`, "Public"); + } + }, + })); + moreRoleButtons.append(createButton({ + name: "view ten billion works", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("many works", "manyworks"); + }, + })); + moreRoleButtons.append(createButton({ + name: "admin list roles test (profile 1)", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role4", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role3", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role2", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role1", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("Role2", "justonestory"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("all roles admin"); + }, + })); + moreRoleButtons.append(createButton({ + name: "user list roles test (profile 2)", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("all roles user"); + }, + })); + moreRoleButtons.append(createButton({ + name: "Delete Author Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.deleteAuthor.execute(); + }, + })); + const commentsButton = Block().appendTo(view); + commentsButton.append(createButton({ + name: "Author 2 lots of comments", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comments 1"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "2", "base comments 2"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "3", "base comments 3"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "4", "base comments 4"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "5", "base comments 5"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment ", "6"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 2", "6"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 3", "11"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 4", "12"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comment index 1"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 6", "13"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 7", "11"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comment index 1 again"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllComments.execute("justonestory", "bigstory", "1"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("1", "get comment"); + }, + })); + commentsButton.append(createButton({ + name: "Author 2 just get comments", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllComments.execute("justonestory", "bigstory", "1"); + }, + })); + commentsButton.append(createButton({ + name: "Author 1 single comment ping", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("somanystories", "debut", "1", "wow you write so many stories @somanystories how do you do it"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("somanystories", "debut", "1", "@somanystories you're so @somanystories amazing"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("5"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateCommentChapter.execute("4", "okay done fawning over @somanystories now"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteCommentChapter.execute("5"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("5"); + }, + })); + commentsButton.append(createButton({ + name: "try to delete author 1's comment", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.deleteCommentChapter.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + }, + })); + const patreonButtons = Block().appendTo(view); + (0, Button_12.default)() + .text.set("Campaign Test") + .event.subscribe("click", async () => { + await (0, Popup_2.default)("Campaign OAuth", `${Env_6.default.API_ORIGIN}auth/patreon/campaign/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(patreonButtons); + patreonButtons.append(createButton({ + name: "create patreon author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("has a campaign", "patreonuser"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("patreon only story", "test", "short description test", "exclusive", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 1", "hewwo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 2", "hewwoo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 3", "hewwooo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 4", "hewwooo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 5", "hewwooo", "Private"); + }, + })); + patreonButtons.append(createButton({ + name: "get patreon tiers", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.patreonGetTiers.execute("patreon tiers"); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonGetTiers.execute("patreon tiers"); + }, + })); + patreonButtons.append(createButton({ + name: "set patreon chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.updateChapter.execute("patreonuser", "exclusive", 1, undefined, undefined, "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Public", ["2", "3"]); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Patreon", ["4", "5"], "4392761"); + }, + })); + (0, Button_12.default)() + .text.set("Patron Test") + .event.subscribe("click", async () => { + await (0, Popup_2.default)("Patron OAuth", `${Env_6.default.API_ORIGIN}auth/patreon/patron/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(patreonButtons); + patreonButtons.append(createButton({ + name: "get patreon-only chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("public:", "patreonuser", "exclusive", 3); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("public:", "patreonuser", "exclusive", 3); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("patreon:", "patreonuser", "exclusive", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("patreon:", "patreonuser", "exclusive", 4); + }, + })); + patreonButtons.append(createButton({ + name: "update patreon-only chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Public", ["4"]); + }, + })); + const tagButtons = Block().appendTo(view); + tagButtons.append(createButton({ + name: "Create Tag Author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("tagging test", "thetagger", "test description"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("thetagger", "TagGlobalCreate", "TagGlobalDelete", "TagGlobalUpdate", "TagCategoryCreate", "TagCategoryUpdate", "TagCategoryDelete", "TagPromote", "TagDemote"); + }, + })); + tagButtons.append(createButton({ + name: "Update Tag Author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateAuthor.execute("the tagger 2", "wow i'm "); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + }, + })); + tagButtons.append(createButton({ + name: "Tag Create Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category One", "the first test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Two", "the second test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Three", "the third test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag One", "test tag 1 ", "Category One"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateGlobal.execute("Category One: Tag One", "Tag One Updated", "test tag 1 updated", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateCategory.execute("Category One", "Category One Updated", "first test category updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagRemoveCategory.execute("Category One Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagRemoveGlobal.execute("Category Two: Tag One Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateGlobal.execute("Category Three: tag conflict", undefined, undefined, "Category Two"); + }, + })); + tagButtons.append(createButton({ + name: "Work Tag Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Two", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Three", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Four", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("Tag Test Work", "test", "desc test", "testwork", "Ongoing", "Public", ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 1", "custom tag 2"]); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("Tag Test Work Two", "test2", "desc test", "testworktwo", "Ongoing", "Public", ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 2", "custom tag 3"]); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 1", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 2", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateWork.execute("thetagger", "testworktwo", "Test Work Two Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 3", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 4", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "thetagger"); + }, + })); + tagButtons.append(createButton({ + name: "Chapter Tag Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("thetagger", "testworktwo", "test chapter", "test chapter body", "Public", true, undefined, undefined, ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 2", "custom tag 3", "custom tag 4"]); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("chapter", "thetagger", "testworktwo", 1); + }, + })); + tagButtons.append(createButton({ + name: "Tag Promote/Demote", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagPromoteCustom.execute("custom tag 1", "test description", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagDemoteGlobal.execute("Category Two: Tag Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 3", "thetagger", "testwork"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 4", "thetagger", "testworktwo"); + }, + })); + tagButtons.append(createButton({ + name: "manifest test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagGetManifest.execute(); + }, + })); + tagButtons.append(createButton({ + name: "manifest test 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("extra tag", "wow", "Category Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagGetManifest.execute(); + }, + })); + tagButtons.append(createButton({ + name: "form length manifest", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.manifestFormLengthGet.execute(); + }, + })); + const notifButtons = Block().appendTo(view); + notifButtons.append(createButton({ + name: "Get Notifications", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsGet.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsGetUnread.execute(); + }, + })); + notifButtons.append(createButton({ + name: "Mark Notifications Read", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsMark.execute("read", ["ba397c1b-02e5-462c-b367-04b007d1f09a", "d8830a0c-3e2c-4caa-ae4b-679a8c5cefa5"]); + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsMark.execute("unread", ["ba397c1b-02e5-462c-b367-04b007d1f09a", "3b9781ea-d15d-4915-bbeb-4788ed734453"]); + }, + })); + notifButtons.append(createButton({ + name: "Get Front Page Feed", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.feedGet.execute(); + }, + })); + return view; + }, + }); +}); +define("endpoint/feed/EndpointFeedGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_17) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_17 = __importDefault(Endpoint_17); + exports.default = (0, Endpoint_17.default)("/feed/get", "get"); +}); +define("ui/view/FeedView", ["require", "exports", "endpoint/feed/EndpointFeedGet", "ui/Component", "ui/component/core/Link", "ui/component/core/Paginator", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, EndpointFeedGet_1, Component_46, Link_4, Paginator_3, Work_3, View_7, ViewDefinition_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointFeedGet_1 = __importDefault(EndpointFeedGet_1); + Component_46 = __importDefault(Component_46); + Link_4 = __importDefault(Link_4); + Paginator_3 = __importDefault(Paginator_3); + Work_3 = __importDefault(Work_3); + View_7 = __importDefault(View_7); + ViewDefinition_6 = __importDefault(ViewDefinition_6); + exports.default = (0, ViewDefinition_6.default)({ + create: async () => { + const view = (0, View_7.default)("feed"); + const paginator = (0, Paginator_3.default)() + .viewTransition("author-view-feed") + .type("flush") + .tweak(p => p.title.text.use("view/feed/main/title")) + .appendTo(view); + const endpoint = EndpointFeedGet_1.default.prep().setPageSize(3); + await paginator.useEndpoint(endpoint, async (slot, { works, authors }) => { + for (const workData of works) { + const author = authors.find(author => author.vanity === workData.author); + const work = await (0, Link_4.default)(author && `/work/${author.vanity}/${workData.vanity}`) + .and(Work_3.default, workData, author, true); + work + .viewTransition() + .appendTo(slot); + } + }); + paginator.orElse(slot => (0, Component_46.default)() + .style("placeholder") + .text.use("view/feed/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("ui/view/HomeView", ["require", "exports", "markdown-it", "ui/Component", "ui/component/core/Block", "ui/component/core/TextEditor", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Env", "utility/string/MarkdownItHTML"], function (require, exports, markdown_it_3, Component_47, Block_10, TextEditor_3, View_8, ViewDefinition_7, Env_7, MarkdownItHTML_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + markdown_it_3 = __importDefault(markdown_it_3); + Component_47 = __importDefault(Component_47); + Block_10 = __importDefault(Block_10); + TextEditor_3 = __importDefault(TextEditor_3); + View_8 = __importDefault(View_8); + ViewDefinition_7 = __importDefault(ViewDefinition_7); + Env_7 = __importDefault(Env_7); + MarkdownItHTML_3 = __importDefault(MarkdownItHTML_3); + exports.default = (0, ViewDefinition_7.default)({ + create: () => { + const view = (0, View_8.default)("home"); + const block = (0, Block_10.default)().appendTo(view); + block.title.text.set("Test the text editor"); + block.description.text.set("fluff4.me is still a work-in-progress. In the meantime, feel free to play with this!"); + // const form = block.and(Form, block.title) + (0, TextEditor_3.default)() + .appendTo(block.content); + if (Env_7.default.isDev) { + (0, Component_47.default)("br").appendTo(block.content); + const output = (0, Component_47.default)("div"); + (0, Component_47.default)("div") + .attributes.set("contenteditable", "plaintext-only") + .style.setProperty("white-space", "pre-wrap") + .style.setProperty("font", "inherit") + .style.setProperty("background", "#222") + .style.setProperty("width", "100%") + .style.setProperty("height", "400px") + .style.setProperty("padding", "0.5em") + .style.setProperty("box-sizing", "border-box") + .event.subscribe("input", event => { + const text = event.component.element.textContent ?? ""; + const md = new markdown_it_3.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_3.default.use(md, MarkdownItHTML_3.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + console.log(md.parse(text, {})); + output.element.innerHTML = md.render(text); + }) + .appendTo(block.content); + output + .style.setProperty("font", "inherit") + .style.setProperty("background", "#222") + .style.setProperty("width", "100%") + .style.setProperty("padding", "0.5em") + .style.setProperty("margin-top", "1em") + .style.setProperty("box-sizing", "border-box") + .appendTo(block.content); + } + return view; + }, + }); +}); +define("ui/view/TagView", ["require", "exports", "model/Tags", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Errors"], function (require, exports, Tags_2, View_9, ViewDefinition_8, Errors_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Tags_2 = __importDefault(Tags_2); + View_9 = __importDefault(View_9); + ViewDefinition_8 = __importDefault(ViewDefinition_8); + Errors_2 = __importDefault(Errors_2); + const fromURLRegex = /(-|^)(.)/g; + const fromURL = (name) => name.replaceAll(fromURLRegex, (_, dash, char) => `${dash ? " " : ""}${char.toUpperCase()}`); + exports.default = (0, ViewDefinition_8.default)({ + create: async (params) => { + const view = (0, View_9.default)("tag"); + const tag = await Tags_2.default.resolve(fromURL(params.category), fromURL(params.name)); + if (!tag) + throw Errors_2.default.NotFound(); + return view; + }, + }); +}); +define("endpoint/work/EndpointWorkCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_18) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_18 = __importDefault(Endpoint_18); + exports.default = (0, Endpoint_18.default)("/work/create", "post"); +}); +define("endpoint/work/EndpointWorkUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_19) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_19 = __importDefault(Endpoint_19); + exports.default = (0, Endpoint_19.default)("/work/{author}/{vanity}/update", "post"); +}); +define("ui/component/core/Textarea", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_48, Input_4, StringApplicator_7, State_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_48 = __importDefault(Component_48); + Input_4 = __importDefault(Input_4); + StringApplicator_7 = __importDefault(StringApplicator_7); + State_26 = __importDefault(State_26); + const Textarea = Component_48.default.Builder((component) => { + let shouldIgnoreInputEvent = false; + const input = component + .and(Input_4.default) + .style("text-input", "text-area") + .attributes.set("contenteditable", "plaintext-only") + .ariaRole("textbox") + .attributes.set("aria-multiline", "true") + .extend(input => ({ + value: "", + state: (0, State_26.default)(""), + default: (0, StringApplicator_7.default)(input, value => { + if (input.value === "") { + input.value = value ?? ""; + input.state.value = value ?? ""; + input.length.value = value?.length ?? 0; + } + }), + placeholder: (0, StringApplicator_7.default)(input, value => { + input.attributes.set("placeholder", value); + }), + ignoreInputEvent: (ignore = true) => { + shouldIgnoreInputEvent = ignore; + return input; + }, + setLabel(label) { + component.setName(label?.for); + component.setId(label?.for); + label?.setInput(input); + component.ariaLabelledBy(label); + return input; + }, + })) + .extendMagic("value", input => ({ + get: () => input.element.textContent || "", + set: (value) => { + input.element.textContent = value; + input.state.value = value; + input.length.value = value.length; + }, + })); + input.length.value = 0; + input.onRooted(input => { + input.event.subscribe(["input", "change"], event => { + if (shouldIgnoreInputEvent) + return; + input.state.value = input.value; + input.length.value = input.value.length; + }); + }); + return input; + }); + exports.default = Textarea; +}); +define("ui/view/work/WorkEditForm", ["require", "exports", "endpoint/work/EndpointWorkCreate", "endpoint/work/EndpointWorkUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/Textarea", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast"], function (require, exports, EndpointWorkCreate_1, EndpointWorkUpdate_1, en_nz_7, FormInputLengths_3, Session_12, Component_49, Block_11, Form_4, LabelledTable_3, Textarea_1, TextEditor_4, TextInput_5, Toast_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointWorkCreate_1 = __importDefault(EndpointWorkCreate_1); + EndpointWorkUpdate_1 = __importDefault(EndpointWorkUpdate_1); + en_nz_7 = __importDefault(en_nz_7); + FormInputLengths_3 = __importDefault(FormInputLengths_3); + Session_12 = __importDefault(Session_12); + Component_49 = __importDefault(Component_49); + Block_11 = __importDefault(Block_11); + Form_4 = __importDefault(Form_4); + LabelledTable_3 = __importDefault(LabelledTable_3); + Textarea_1 = __importDefault(Textarea_1); + TextEditor_4 = __importDefault(TextEditor_4); + TextInput_5 = __importDefault(TextInput_5); + exports.default = Component_49.default.Builder((component, state) => { + const block = component.and(Block_11.default); + const form = block.and(Form_4.default, block.title); + form.viewTransition("work-edit-form"); + const type = state.value ? "update" : "create"; + form.title.text.use(`view/work-edit/${type}/title`); + form.setName(en_nz_7.default[`view/work-edit/${type}/title`]().toString()); + // if (params.type === "create") + // form.description.text.use("view/work-edit/create/description") + form.submit.textWrapper.text.use(`view/work-edit/${type}/submit`); + const table = (0, LabelledTable_3.default)().appendTo(form.content); + const nameInput = (0, TextInput_5.default)() + .setRequired() + .default.bind(state.map(component, work => work?.name)) + .hint.use("view/work-edit/shared/form/name/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.name); + table.label(label => label.text.use("view/work-edit/shared/form/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const vanityInput = (0, TextInput_5.default)() + .placeholder.bind(nameInput.state + .map(component, name => filterVanity(name))) + .default.bind(state.map(component, work => work?.vanity)) + .filter(filterVanity) + .hint.use("view/work-edit/shared/form/vanity/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.vanity); + table.label(label => label.text.use("view/work-edit/shared/form/vanity/label")) + .content((content, label) => content.append(vanityInput.setLabel(label))); + const descriptionInput = (0, Textarea_1.default)() + .default.bind(state.map(component, work => work?.description)) + .hint.use("view/work-edit/shared/form/description/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.description); + table.label(label => label.text.use("view/work-edit/shared/form/description/label")) + .content((content, label) => content.append(descriptionInput.setLabel(label))); + const synopsisInput = (0, TextEditor_4.default)() + .default.bind(state.map(component, work => work?.synopsis.body)) + .hint.use("view/work-edit/shared/form/synopsis/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.synopsis); + table.label(label => label.text.use("view/work-edit/shared/form/synopsis/label")) + .content((content, label) => content.append(synopsisInput.setLabel(label))); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const name = nameInput.value; + const response = await (() => { + switch (type) { + case "create": + return EndpointWorkCreate_1.default.query({ + body: { + name, + vanity: vanityInput.value, + description: descriptionInput.value, + synopsis: synopsisInput.useMarkdown(), + }, + }); + case "update": { + if (!state.value) + return; + const authorVanity = Session_12.default.Auth.author.value?.vanity; + if (!authorVanity) + return new Error("Cannot update a work when not signed in"); + return EndpointWorkUpdate_1.default.query({ + params: { + author: authorVanity, + vanity: state.value.vanity, + }, + body: { + name, + vanity: vanityInput.value, + description: descriptionInput.value, + synopsis: synopsisInput.useMarkdown(), + }, + }); + } + } + })(); + if (response instanceof Error) { + toast.warning(Toast_3.TOAST_ERROR, quilt => quilt["view/work-edit/shared/toast/failed-to-save"](name), response); + console.error(response); + return; + } + toast.success(Toast_3.TOAST_SUCCESS, quilt => quilt["view/work-edit/shared/toast/saved"](name)); + state.value = response?.data; + }); + return form; + function filterVanity(vanity, textBefore = "", isFullText = true) { + vanity = vanity.replace(/[\W_]+/g, "-"); + if (isFullText) + vanity = vanity.replace(/^-|-$/g, ""); + if (textBefore.endsWith("-") && vanity.startsWith("-")) + return vanity.slice(1); + return vanity; + } + }); +}); +define("ui/view/WorkEditView", ["require", "exports", "endpoint/work/EndpointWorkGet", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/Slot", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "ui/view/work/WorkEditForm", "utility/State"], function (require, exports, EndpointWorkGet_2, ActionRow_5, Button_13, Slot_9, View_10, ViewDefinition_9, ViewTransition_4, WorkEditForm_1, State_27) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointWorkGet_2 = __importDefault(EndpointWorkGet_2); + ActionRow_5 = __importDefault(ActionRow_5); + Button_13 = __importDefault(Button_13); + Slot_9 = __importDefault(Slot_9); + View_10 = __importDefault(View_10); + ViewDefinition_9 = __importDefault(ViewDefinition_9); + ViewTransition_4 = __importDefault(ViewTransition_4); + WorkEditForm_1 = __importDefault(WorkEditForm_1); + State_27 = __importDefault(State_27); + exports.default = (0, ViewDefinition_9.default)({ + requiresLogin: true, + create: async (params) => { + const id = "work-edit"; + const view = (0, View_10.default)(id); + const work = params && await EndpointWorkGet_2.default.query({ params }); + if (work instanceof Error) + throw work; + const state = (0, State_27.default)(work?.data); + const stateInternal = (0, State_27.default)(work?.data); + (0, Slot_9.default)() + .use(state, () => (0, WorkEditForm_1.default)(stateInternal).subviewTransition(id)) + .appendTo(view); + (0, Slot_9.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + stateInternal.subscribe(view, work => ViewTransition_4.default.perform("subview", id, () => state.value = work)); + return view; + function createActionRow() { + if (!stateInternal.value) + return; + return (0, ActionRow_5.default)() + .viewTransition("work-edit-action-row") + .tweak(row => row.right + .append((0, Button_13.default)() + .text.use("view/work-edit/update/action/delete") + .event.subscribe("click", async () => { + // const response = await EndpointAuthorDelete.query() + // if (response instanceof Error) { + // console.error(response) + // return + // } + // return Session.reset() + }))); + } + }, + }); +}); +define("endpoint/chapter/EndpointChapterGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_20) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_20 = __importDefault(Endpoint_20); + exports.default = (0, Endpoint_20.default)("/work/{author}/{vanity}/chapters/list", "get"); +}); +define("ui/component/Chapter", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/ext/CanHasActionsMenuButton", "ui/component/core/Link", "ui/component/core/Timestamp", "utility/maths/Maths"], function (require, exports, Session_13, Component_50, Button_14, CanHasActionsMenuButton_2, Link_5, Timestamp_2, Maths_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_13 = __importDefault(Session_13); + Component_50 = __importDefault(Component_50); + Button_14 = __importDefault(Button_14); + CanHasActionsMenuButton_2 = __importDefault(CanHasActionsMenuButton_2); + Link_5 = __importDefault(Link_5); + Timestamp_2 = __importDefault(Timestamp_2); + Maths_2 = __importDefault(Maths_2); + const Chapter = Component_50.default.Builder((component, chapter, work, author) => { + component = (0, Link_5.default)(`/work/${author.vanity}/${work.vanity}/chapter/${chapter.url}`) + .style("chapter"); + const chapterNumber = Maths_2.default.parseIntOrUndefined(chapter.url); + const number = (0, Component_50.default)() + .style("chapter-number") + .text.set(chapterNumber ? `${chapterNumber.toLocaleString()}` : "") + .appendTo(component); + const chapterName = (0, Component_50.default)() + .style("chapter-name") + .text.set(chapter.name) + .appendTo(component); + const right = (0, Component_50.default)() + .style("chapter-right") + .appendTo(component); + const timestamp = !chapter.time_last_update ? undefined + : (0, Timestamp_2.default)(chapter.time_last_update) + .style("chapter-timestamp") + .appendTo(right); + return component + .and(CanHasActionsMenuButton_2.default, button => button + .type("inherit-size") + .style("chapter-actions-menu-button") + .style.bind(component.hoveredOrHasFocused.not, "chapter-actions-menu-button--not-focused") + .appendTo(right)) + .setActionsMenu((popover, button) => { + if (author && author.vanity === Session_13.default.Auth.author.value?.vanity) { + (0, Button_14.default)() + .type("flush") + .text.use("view/work/chapters/action/label/edit") + .event.subscribe("click", () => navigate.toURL(`/work/${author.vanity}/${work.vanity}/chapter/${chapter.url}/edit`)) + .appendTo(popover); + (0, Button_14.default)() + .type("flush") + .text.use("view/author/works/action/label/delete") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + }) + .tweak(component => component.actionsMenuButton) + .extend(component => ({ + chapter, + number, + chapterName, + timestamp, + })); + }); + exports.default = Chapter; +}); +define("ui/view/WorkView", ["require", "exports", "endpoint/chapter/EndpointChapterGetAll", "endpoint/work/EndpointWorkGet", "model/Session", "ui/Component", "ui/component/Chapter", "ui/component/core/Button", "ui/component/core/Paginator", "ui/component/core/Slot", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Errors"], function (require, exports, EndpointChapterGetAll_1, EndpointWorkGet_3, Session_14, Component_51, Chapter_1, Button_15, Paginator_4, Slot_10, Work_4, View_11, ViewDefinition_10, Errors_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGetAll_1 = __importDefault(EndpointChapterGetAll_1); + EndpointWorkGet_3 = __importDefault(EndpointWorkGet_3); + Session_14 = __importDefault(Session_14); + Component_51 = __importDefault(Component_51); + Chapter_1 = __importDefault(Chapter_1); + Button_15 = __importDefault(Button_15); + Paginator_4 = __importDefault(Paginator_4); + Slot_10 = __importDefault(Slot_10); + Work_4 = __importDefault(Work_4); + View_11 = __importDefault(View_11); + ViewDefinition_10 = __importDefault(ViewDefinition_10); + Errors_3 = __importDefault(Errors_3); + exports.default = (0, ViewDefinition_10.default)({ + create: async (params) => { + const view = (0, View_11.default)("work"); + const response = await EndpointWorkGet_3.default.query({ params }); + if (response instanceof Error) + throw response; + const workData = response.data; + const authorData = workData.synopsis.mentions.find(author => author.vanity === params.author); + if (!authorData) + throw Errors_3.default.BadData("Work author not in synopsis authors"); + const work = await (0, Work_4.default)(workData, authorData); + work + .viewTransition("work-view-work") + .setContainsHeading() + .appendTo(view); + const paginator = (0, Paginator_4.default)() + .viewTransition("work-view-chapters") + .tweak(p => p.title.text.use("view/work/chapters/title")) + .tweak(p => p.primaryActions.append((0, Slot_10.default)() + .if(Session_14.default.Auth.loggedIn, () => (0, Button_15.default)() + .setIcon("plus") + .ariaLabel.use("view/work/chapters/action/label/new") + .event.subscribe("click", () => navigate.toURL(`/work/${params.author}/${params.vanity}/chapter/new`))))) + .appendTo(view); + const chaptersQuery = EndpointChapterGetAll_1.default.prep({ + params: { + author: params.author, + vanity: params.vanity, + }, + }); + await paginator.useEndpoint(chaptersQuery, (slot, chapters) => { + slot.style("chapter-list"); + for (const chapterData of chapters) + (0, Chapter_1.default)(chapterData, workData, authorData) + .appendTo(slot); + }); + paginator.orElse(slot => (0, Component_51.default)() + .style("placeholder") + .text.use("view/work/chapters/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("navigation/Routes", ["require", "exports", "navigation/Route", "ui/view/AccountView", "ui/view/AuthorView", "ui/view/ChapterEditView", "ui/view/ChapterView", "ui/view/DebugView", "ui/view/FeedView", "ui/view/HomeView", "ui/view/TagView", "ui/view/WorkEditView", "ui/view/WorkView", "utility/Env"], function (require, exports, Route_1, AccountView_1, AuthorView_1, ChapterEditView_1, ChapterView_1, DebugView_1, FeedView_1, HomeView_1, TagView_1, WorkEditView_1, WorkView_1, Env_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Route_1 = __importDefault(Route_1); + AccountView_1 = __importDefault(AccountView_1); + AuthorView_1 = __importDefault(AuthorView_1); + ChapterEditView_1 = __importDefault(ChapterEditView_1); + ChapterView_1 = __importDefault(ChapterView_1); + DebugView_1 = __importDefault(DebugView_1); + FeedView_1 = __importDefault(FeedView_1); + HomeView_1 = __importDefault(HomeView_1); + TagView_1 = __importDefault(TagView_1); + WorkEditView_1 = __importDefault(WorkEditView_1); + WorkView_1 = __importDefault(WorkView_1); + Env_8 = __importDefault(Env_8); + const Routes = [ + (0, Route_1.default)("/debug", DebugView_1.default.navigate), + (0, Route_1.default)("/", Env_8.default.isDev ? FeedView_1.default.navigate : HomeView_1.default.navigate), + (0, Route_1.default)("/account", AccountView_1.default.navigate), + (0, Route_1.default)("/author/$vanity", AuthorView_1.default.navigate), + (0, Route_1.default)("/work/new", WorkEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity", WorkView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/edit", WorkEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/new", ChapterEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/$url", ChapterView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/$url/edit", ChapterEditView_1.default.navigate), + (0, Route_1.default)("/tag/$category/$name", TagView_1.default.navigate), + ]; + exports.default = Routes; +}); +define("ui/view/ErrorView", ["require", "exports", "lang/en-nz", "ui/component/core/Heading", "ui/component/core/Paragraph", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, en_nz_8, Heading_2, Paragraph_3, View_12, ViewDefinition_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_8 = __importDefault(en_nz_8); + Heading_2 = __importDefault(Heading_2); + Paragraph_3 = __importDefault(Paragraph_3); + View_12 = __importDefault(View_12); + ViewDefinition_11 = __importDefault(ViewDefinition_11); + exports.default = (0, ViewDefinition_11.default)({ + create: (params) => { + const view = (0, View_12.default)("error"); + if (params.code === 500 && params.error) + console.error(params.error); + (0, Heading_2.default)() + .text.use(quilt => quilt["view/error/title"]({ CODE: params.code })) + .appendTo(view); + const key = `view/error/description-${params.code}`; + if (key in en_nz_8.default) + (0, Paragraph_3.default)() + .text.use(key) + .appendTo(view); + return view; + }, + }); +}); +define("ui/view/RequireLoginView", ["require", "exports", "ui/component/core/ActionRow", "ui/component/core/Block", "ui/component/core/Button", "ui/view/AccountView", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, ActionRow_6, Block_12, Button_16, AccountView_2, View_13, ViewDefinition_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + ActionRow_6 = __importDefault(ActionRow_6); + Block_12 = __importDefault(Block_12); + Button_16 = __importDefault(Button_16); + AccountView_2 = __importDefault(AccountView_2); + View_13 = __importDefault(View_13); + ViewDefinition_12 = __importDefault(ViewDefinition_12); + exports.default = (0, ViewDefinition_12.default)({ + create: () => { + const view = (0, View_13.default)("require-login"); + const block = (0, Block_12.default)().appendTo(view); + block.title.text.use("view/shared/login-required/title"); + block.description.text.use("view/shared/login-required/description"); + const actionRow = (0, ActionRow_6.default)() + .appendTo(block); + (0, Button_16.default)() + .type("primary") + .text.use("view/shared/login-required/action") + .event.subscribe("click", () => navigate.ephemeral(AccountView_2.default, undefined)) + .appendTo(actionRow.right); + return view; + }, + }); +}); +define("ui/view/shared/component/ViewContainer", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/Dialog", "ui/view/AccountView", "ui/view/ErrorView", "ui/view/RequireLoginView", "ui/view/shared/ext/ViewTransition"], function (require, exports, Session_15, Component_52, Button_17, Dialog_3, AccountView_3, ErrorView_1, RequireLoginView_1, ViewTransition_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_15 = __importDefault(Session_15); + Component_52 = __importDefault(Component_52); + Button_17 = __importDefault(Button_17); + Dialog_3 = __importDefault(Dialog_3); + AccountView_3 = __importDefault(AccountView_3); + ErrorView_1 = __importDefault(ErrorView_1); + RequireLoginView_1 = __importDefault(RequireLoginView_1); + ViewTransition_5 = __importDefault(ViewTransition_5); + let globalId = 0; + const ViewContainer = () => { + let cancelLogin; + const container = (0, Component_52.default)() + .style("view-container") + .tabIndex("programmatic") + .ariaRole("main") + .ariaLabel.use("view/container/alt") + .extend(container => ({ + show: async (definition, params) => { + const showingId = ++globalId; + let view; + let loadParams = undefined; + const needsLogin = definition.requiresLogin && !Session_15.default.Auth.loggedIn.value; + if (needsLogin || definition.load) { + let loginPromise; + const transition = ViewTransition_5.default.perform("view", async () => { + swapRemove(); + if (!needsLogin) + return; + const login = logIn(); + loginPromise = login?.authed; + await login?.accountViewShown; + }); + await transition.updateCallbackDone; + await loginPromise; + if (needsLogin && !Session_15.default.Auth.loggedIn.value) { + let setLoggedIn; + const loggedIn = new Promise(resolve => setLoggedIn = resolve); + ViewTransition_5.default.perform("view", async () => { + hideEphemeral(); + const view = await swapAdd(RequireLoginView_1.default); + if (!view) + return; + Session_15.default.Auth.loggedIn.subscribe(view, loggedIn => loggedIn && setLoggedIn()); + }); + await loggedIn; + } + } + loadParams = !definition.load ? undefined : await definition.load(params); + if (globalId !== showingId) + return; + if (container.view || showingId > 1) { + const transition = ViewTransition_5.default.perform("view", swap); + await transition.updateCallbackDone; + } + else { + await swap(); + } + return view; + async function swap() { + swapRemove(); + await swapAdd(); + } + function swapRemove() { + container.view?.remove(); + hideEphemeral(); + } + async function swapAdd(replacementDefinition = definition) { + const shownView = await Promise.resolve(replacementDefinition.create(params, loadParams)) + .then(v => { + view = replacementDefinition === definition ? v : undefined; + return v; + }) + .catch((error) => ErrorView_1.default.create({ code: error.code ?? 500, error })); + if (shownView) { + shownView.appendTo(container); + container.view = shownView; + if (replacementDefinition === definition) + shownView.params = params; + } + return shownView; + } + }, + ephemeralDialog: (0, Dialog_3.default)() + .style("view-container-ephemeral") + .tweak(dialog => dialog.style.bind(dialog.opened, "view-container-ephemeral--open")) + .setOwner(container) + .setNotModal() + .append((0, Button_17.default)() + .style("view-container-ephemeral-close") + .event.subscribe("click", () => { + if (cancelLogin) + cancelLogin(); + else + return container.hideEphemeral(); + })) + .appendTo(document.body), + showEphemeral: async (definition, params) => { + let view; + const transition = document.startViewTransition(async () => view = await showEphemeral(definition, params)); + await transition.updateCallbackDone; + return view; + }, + hideEphemeral: async () => { + const transition = document.startViewTransition(hideEphemeral); + await transition.updateCallbackDone; + }, + })); + return container; + async function showEphemeral(definition, params) { + container.ephemeral?.remove(); + let view; + const shownView = await Promise.resolve(definition.create(params)) + .then(v => view = v) + .catch((error) => ErrorView_1.default.create({ code: error.code ?? 500, error })); + if (shownView) { + shownView.appendTo(container.ephemeralDialog); + container.ephemeral = shownView; + container.ephemeralDialog.open(); + container.attributes.append("inert"); + container.ephemeralDialog.opened.subscribe(shownView, opened => { + if (!opened) { + hideEphemeral(); + } + }); + } + return view; + } + function hideEphemeral() { + container.ephemeralDialog.close(); + container.ephemeral?.remove(); + delete container.ephemeral; + container.attributes.remove("inert"); + } + function logIn() { + if (Session_15.default.Auth.author.value) + return; + const accountViewShown = showEphemeral(AccountView_3.default, undefined); + const authPromise = accountViewShown.then(async (view) => { + if (!view) + return false; + const loginCancelledPromise = new Promise(resolve => cancelLogin = resolve); + await Promise.race([ + Session_15.default.Auth.await(view), + loginCancelledPromise, + ]); + cancelLogin = undefined; + return Session_15.default.Auth.loggedIn.value; + }); + return { + accountViewShown, + authed: authPromise, + }; + } + }; + exports.default = ViewContainer; +}); +define("navigation/Navigate", ["require", "exports", "navigation/Routes", "ui/view/ErrorView", "utility/Env"], function (require, exports, Routes_1, ErrorView_2, Env_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Routes_1 = __importDefault(Routes_1); + ErrorView_2 = __importDefault(ErrorView_2); + Env_9 = __importDefault(Env_9); + function Navigator(app) { + let lastURL; + const navigate = { + fromURL: async () => { + if (location.href === lastURL?.href) + return; + const oldURL = lastURL; + lastURL = new URL(location.href); + let errored = false; + if (location.pathname !== oldURL?.pathname) { + const url = location.pathname; + let handled = false; + for (const route of Routes_1.default) { + const params = route.match(url); + if (!params) + continue; + await route.handler(app, (!Object.keys(params).length ? undefined : params)); + handled = true; + break; + } + if (!handled) { + errored = true; + await app.view.show(ErrorView_2.default, { code: 404 }); + } + } + if (location.hash && !errored) { + const id = location.hash.slice(1); + const element = document.getElementById(id); + if (!element) { + console.error(`No element by ID: "${id}"`); + location.hash = ""; + return; + } + element.scrollIntoView(); + element.focus(); + } + }, + toURL: async (url) => { + navigate.setURL(url); + return navigate.fromURL(); + }, + setURL: (url) => { + if (url !== location.pathname) + history.pushState({}, "", `${Env_9.default.URL_ORIGIN}${url.slice(1)}`); + }, + toRawURL: (url) => { + if (url.startsWith("http")) { + location.href = url; + return true; + } + if (url.startsWith("/")) { + void navigate.toURL(url); + return true; + } + if (url.startsWith("#")) { + const id = url.slice(1); + const element = document.getElementById(id); + if (!element) { + console.error(`No element by ID: "${id}"`); + return false; + } + location.hash = url; + return true; + } + console.error(`Unsupported raw URL to navigate to: "${url}"`); + return false; + }, + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + ephemeral: (...args) => app.view.showEphemeral(...args), + }; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + window.addEventListener("popstate", navigate.fromURL); + Object.assign(window, { navigate }); + return navigate; + } + exports.default = Navigator; +}); +define("ui/component/masthead/Flag", ["require", "exports", "ui/Component", "utility/Arrays"], function (require, exports, Component_53, Arrays_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_53 = __importDefault(Component_53); + Arrays_5 = __importDefault(Arrays_5); + const Flag = Component_53.default.Builder((component) => { + const stripes = Arrays_5.default.range(5) + .map(i => (0, Component_53.default)() + .style("flag-stripe", `flag-stripe-${FLAG_STRIPE_COLOURS[i]}`, `flag-stripe-${i + 1}`)); + let endWhen = Infinity; + const activeReasons = new Set(); + function add(reason) { + if (!activeReasons.size) { + endWhen = Infinity; + for (const stripe of stripes) { + stripe.style.remove("flag-stripe--animate-end-0", "flag-stripe--animate-end-1"); + stripe.style("flag-stripe--animate"); + } + } + activeReasons.add(reason); + } + function remove(reason) { + activeReasons.delete(reason); + } + function toggle(reason, enabled) { + if (enabled) + add(reason); + else + remove(reason); + } + component.hoveredOrFocused.subscribe(component, enabled => toggle("focus", enabled)); + for (const stripe of stripes) { + const first = stripe === stripes[0]; + let iteration = 0; + stripe.event.subscribe("animationstart", () => iteration = 0); + stripe.event.subscribe("animationiteration", () => { + iteration++; + if (first && !activeReasons.size) + endWhen = iteration; + if (iteration >= endWhen) { + stripe.style.remove("flag-stripe--animate"); + stripe.style(`flag-stripe--animate-end-${(iteration % 2)}`); + } + }); + } + return component + .style("flag") + .append(...stripes) + .extend(flag => ({ + wave: toggle, + })); + }); + exports.default = Flag; + const FLAG_STRIPE_COLOURS = [ + "blue", + "pink", + "white", + "pink", + "blue", + ]; +}); +define("ui/component/PrimaryNav", ["require", "exports", "ui/Component"], function (require, exports, Component_54) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_54 = __importDefault(Component_54); + exports.default = Component_54.default.Builder(nav => { + // Heading() + // .text.set("hi") + // .appendTo(nav) + return nav; + }); +}); +define("ui/component/Sidebar", ["require", "exports", "ui/Component", "ui/component/core/Button", "utility/Env", "utility/Store"], function (require, exports, Component_55, Button_18, Env_10, Store_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_55 = __importDefault(Component_55); + Button_18 = __importDefault(Button_18); + Env_10 = __importDefault(Env_10); + Store_4 = __importDefault(Store_4); + const Sidebar = Component_55.default.Builder("nav", (sidebar) => { + sidebar.style("sidebar") + .ariaLabel.use("masthead/primary-nav/alt"); + if (Env_10.default.ENVIRONMENT === "dev") + (0, Button_18.default)() + .text.set("Debug") + .event.subscribe("click", () => navigate.toURL("/debug")) + .appendTo(sidebar); + updateSidebarVisibility(); + return sidebar.extend(sidebar => ({ + toggle: () => { + Store_4.default.items.sidebar = !Store_4.default.items.sidebar; + updateSidebarVisibility(); + return sidebar; + }, + })); + function updateSidebarVisibility() { + sidebar.style.toggle(!!Store_4.default.items.sidebar, "sidebar--visible"); + } + }); + exports.default = Sidebar; +}); +define("ui/component/Masthead", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Slot", "ui/component/masthead/Flag", "ui/component/PrimaryNav", "ui/component/Sidebar", "ui/utility/Viewport", "utility/Env", "utility/Task"], function (require, exports, Session_16, Component_56, Button_19, Link_6, Slot_11, Flag_1, PrimaryNav_1, Sidebar_1, Viewport_4, Env_11, Task_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_16 = __importDefault(Session_16); + Component_56 = __importDefault(Component_56); + Button_19 = __importDefault(Button_19); + Link_6 = __importDefault(Link_6); + Slot_11 = __importDefault(Slot_11); + Flag_1 = __importDefault(Flag_1); + PrimaryNav_1 = __importDefault(PrimaryNav_1); + Sidebar_1 = __importDefault(Sidebar_1); + Viewport_4 = __importDefault(Viewport_4); + Env_11 = __importDefault(Env_11); + Task_4 = __importDefault(Task_4); + const Masthead = Component_56.default.Builder("header", (masthead, view) => { + masthead.style("masthead"); + const sidebar = (0, Sidebar_1.default)(); + const nav = (0, PrimaryNav_1.default)(); + (0, Button_19.default)() + .style("masthead-skip-nav") + .text.use("masthead/skip-navigation") + .event.subscribe("click", view.focus) + .appendTo(masthead); + let popover; + const left = (0, Component_56.default)() + .append((0, Component_56.default)() + .and(Button_19.default) + .style("masthead-left-hamburger", "masthead-left-hamburger-sidebar") + .ariaHidden() + .event.subscribe("click", sidebar.toggle)) + .append((0, Button_19.default)() + .style("masthead-left-hamburger", "masthead-left-hamburger-popover") + .ariaLabel.use("masthead/primary-nav/alt") + .clearPopover() + .setPopover("hover", p => popover = p + .anchor.add("aligned left", "off bottom") + .ariaRole("navigation"))) + .style("masthead-left") + .appendTo(masthead); + sidebar.style.bind(masthead.hasFocused, "sidebar--visible-due-to-keyboard-navigation"); + Viewport_4.default.size.use(masthead, async () => { + await Task_4.default.yield(); + nav.appendTo(sidebar.element.clientWidth ? sidebar : popover); + }); + const flag = (0, Flag_1.default)() + .style("masthead-home-logo"); + const homeLink = (0, Link_6.default)("/") + .ariaLabel.use("home/label") + .clearPopover() + .append((0, Component_56.default)() + .and(Button_19.default) + .style("masthead-home", "heading") + .append(flag) + .append((0, Component_56.default)("img") + .style("masthead-home-logo-wordmark") + .ariaHidden() + .attributes.set("src", `${Env_11.default.URL_ORIGIN}image/logo-wordmark.svg`))) + .appendTo(left); + flag.style.bind(homeLink.hoveredOrFocused, "flag--focused"); + flag.style.bind(homeLink.active, "flag--active"); + homeLink.hoveredOrFocused.subscribe(masthead, focus => flag.wave("home link focus", focus)); + (0, Component_56.default)() + .style("masthead-search") + .appendTo(masthead); + (0, Component_56.default)() + .style("masthead-user") + .append((0, Button_19.default)() + .style("masthead-user-notifications") + .clearPopover() + .ariaLabel.use("masthead/user/notifications/alt")) + .append((0, Button_19.default)() + .style("masthead-user-profile") + .clearPopover() + .ariaLabel.use("masthead/user/profile/alt") + .setPopover("hover", popover => popover + .anchor.add("aligned right", "off bottom") + .ariaRole("navigation") + .append((0, Slot_11.default)() + .use(Session_16.default.Auth.author, (slot, author) => { + if (!author) { + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/login") + .event.subscribe("click", () => navigate.toURL("/account")) + .appendTo(slot); + return; + } + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/profile") + .event.subscribe("click", () => navigate.toURL(`/author/${author.vanity}`)) + .appendTo(slot); + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/account") + .event.subscribe("click", () => navigate.toURL("/account")) + .appendTo(slot); + })))) + .appendTo(masthead); + return masthead.extend(masthead => ({ + sidebar, + })); + }); + exports.default = Masthead; +}); +define("App", ["require", "exports", "lang/en-nz", "model/FormInputLengths", "model/Session", "navigation/Navigate", "style", "ui/Component", "ui/component/core/toast/ToastList", "ui/component/Masthead", "ui/InputBus", "ui/utility/FocusListener", "ui/utility/HoverListener", "ui/utility/Mouse", "ui/utility/Viewport", "ui/view/shared/component/ViewContainer", "utility/Async", "utility/Store", "utility/Time"], function (require, exports, en_nz_9, FormInputLengths_4, Session_17, Navigate_1, style_2, Component_57, ToastList_1, Masthead_1, InputBus_2, FocusListener_3, HoverListener_2, Mouse_4, Viewport_5, ViewContainer_1, Async_4, Store_5, Time_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_9 = __importDefault(en_nz_9); + FormInputLengths_4 = __importDefault(FormInputLengths_4); + Session_17 = __importDefault(Session_17); + Navigate_1 = __importDefault(Navigate_1); + style_2 = __importDefault(style_2); + Component_57 = __importDefault(Component_57); + ToastList_1 = __importDefault(ToastList_1); + Masthead_1 = __importDefault(Masthead_1); + InputBus_2 = __importDefault(InputBus_2); + FocusListener_3 = __importDefault(FocusListener_3); + HoverListener_2 = __importDefault(HoverListener_2); + Mouse_4 = __importDefault(Mouse_4); + Viewport_5 = __importDefault(Viewport_5); + ViewContainer_1 = __importDefault(ViewContainer_1); + Async_4 = __importDefault(Async_4); + Store_5 = __importDefault(Store_5); + Time_8 = __importDefault(Time_8); + async function App() { + if (location.pathname.startsWith("/auth/")) { + if (location.pathname.endsWith("/error")) { + const params = new URLSearchParams(location.search); + // eslint-disable-next-line no-debugger + debugger; + Store_5.default.items.popupError = { + code: +(params.get("code") ?? "500"), + message: params.get("message") ?? "Internal Server Error", + }; + } + window.close(); + } + await screen?.orientation?.lock?.("portrait-primary").catch(() => { }); + InputBus_2.default.subscribe("down", event => { + if (event.use("F6")) + for (const stylesheet of document.querySelectorAll("link[rel=stylesheet]")) { + const href = stylesheet.getAttribute("href"); + const newHref = `${href.slice(0, Math.max(0, href.indexOf("?")) || Infinity)}?${Math.random().toString().slice(2)}`; + stylesheet.setAttribute("href", newHref); + } + if (event.use("F4")) + document.documentElement.classList.add("persist-tooltips"); + }); + InputBus_2.default.subscribe("up", event => { + if (event.use("F4")) + document.documentElement.classList.remove("persist-tooltips"); + }); + await FormInputLengths_4.default.getManifest(); + // const path = URL.path ?? URL.hash; + // if (path === AuthView.id) { + // URL.hash = null; + // URL.path = null; + // } + // ViewManager.showByHash(URL.path ?? URL.hash); + await Promise.race([ + Session_17.default.refresh(), + Async_4.default.sleep(Time_8.default.seconds(2)), + ]); + HoverListener_2.default.listen(); + FocusListener_3.default.listen(); + Mouse_4.default.listen(); + Viewport_5.default.listen(); + document.title = en_nz_9.default["fluff4me/title"]().toString(); + document.body.classList.add(...style_2.default.body); + const view = (0, ViewContainer_1.default)(); + const masthead = (0, Masthead_1.default)(view); + const related = (0, Component_57.default)() + .style("app-content-related"); + const content = (0, Component_57.default)() + .style("app-content") + .monitorScrollEvents() + .append(view, related); + const app = (0, Component_57.default)() + .style("app") + .append(masthead, masthead.sidebar, content) + .append((0, ToastList_1.default)()) + .extend(app => ({ + navigate: (0, Navigate_1.default)(app), + view, + })) + .appendTo(document.body); + await app.navigate.fromURL(); + Object.assign(window, { app }); + return app; + } + exports.default = App; +}); +define("Constants", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.APP_NAME = void 0; + exports.APP_NAME = "fluff4.me / Queer Webnovels"; +}); +define("utility/DOMRect", ["require", "exports", "utility/Define"], function (require, exports, Define_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = default_1; + Define_5 = __importDefault(Define_5); + function default_1() { + Define_5.default.magic(DOMRect.prototype, "centreX", { + get() { + return this.left + this.width / 2; + }, + }); + Define_5.default.magic(DOMRect.prototype, "centreY", { + get() { + return this.top + this.height / 2; + }, + }); + (0, Define_5.default)(DOMRect.prototype, "expand", function (amount) { + return new DOMRect(this.x - amount, this.y - amount, this.width + amount * 2, this.height + amount * 2); + }); + (0, Define_5.default)(DOMRect.prototype, "contract", function (amount) { + return new DOMRect(Math.min(this.x + amount, this.centreX), Math.min(this.y - amount, this.centreY), Math.max(0, this.width - amount * 2), Math.max(0, this.height - amount * 2)); + }); + (0, Define_5.default)(DOMRect.prototype, "intersects", function (target) { + if ("width" in target) + return true + && this.left >= target.right + && this.right <= target.left + && this.top >= target.bottom + && this.bottom <= target.top; + return true + && this.left <= target.x && this.right >= target.x + && this.top <= target.y && this.bottom >= target.y; + }); + } +}); +define("utility/Elements", ["require", "exports", "utility/Define"], function (require, exports, Define_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Define_6 = __importDefault(Define_6); + var Elements; + (function (Elements) { + function applyPrototypes() { + Define_6.default.set(Element.prototype, "asType", function (tagName) { + return this.tagName.toLowerCase() === tagName ? this : undefined; + }); + } + Elements.applyPrototypes = applyPrototypes; + })(Elements || (Elements = {})); + exports.default = Elements; +}); +define("index", ["require", "exports", "utility/Arrays", "utility/DOMRect", "utility/Elements", "browser-source-map-support", "utility/Env"], function (require, exports, Arrays_6, DOMRect_1, Elements_1, browser_source_map_support_1, Env_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_6 = __importDefault(Arrays_6); + DOMRect_1 = __importDefault(DOMRect_1); + Elements_1 = __importDefault(Elements_1); + browser_source_map_support_1 = __importDefault(browser_source_map_support_1); + Env_12 = __importDefault(Env_12); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + browser_source_map_support_1.default.install({ + environment: "browser", + }); + // view transition api fallback + const noopViewTransition = { + finished: Promise.resolve(undefined), + ready: Promise.resolve(undefined), + updateCallbackDone: Promise.resolve(undefined), + skipTransition: () => { }, + }; + document.startViewTransition ??= cb => { + cb?.(); + return noopViewTransition; + }; + (0, DOMRect_1.default)(); + Arrays_6.default.applyPrototypes(); + Elements_1.default.applyPrototypes(); + void (async () => { + await Env_12.default.load(); + const app = await new Promise((resolve_1, reject_1) => { require(["App"], resolve_1, reject_1); }).then(__importStar); + await app.default(); + })(); +}); +define("endpoint/chapter/EndpointChapterDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_21) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_21 = __importDefault(Endpoint_21); + exports.default = (0, Endpoint_21.default)("/work/{author}/{vanity}/chapter/{url}/delete", "post"); +}); +define("endpoint/comment/EndpointCommentAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_22) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_22 = __importDefault(Endpoint_22); + exports.default = (0, Endpoint_22.default)("/work/{author}/{vanity}/chapter/{url}/comment/add", "post"); +}); +define("endpoint/comment/EndpointCommentGetAllChapter", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_23) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_23 = __importDefault(Endpoint_23); + exports.default = (0, Endpoint_23.default)("/work/{author}/{vanity}/chapter/{url}/comments", "get"); +}); +define("endpoint/comment/EndpointCommentRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_24) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_24 = __importDefault(Endpoint_24); + exports.default = (0, Endpoint_24.default)("/comment/remove/chapter", "post"); +}); +define("endpoint/comment/EndpointCommentUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_25) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_25 = __importDefault(Endpoint_25); + exports.default = (0, Endpoint_25.default)("/comment/update/chapter", "post"); +}); +define("endpoint/follow/EndpointFollowAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_26 = __importDefault(Endpoint_26); + exports.default = (0, Endpoint_26.default)("/follow/{type}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowAddWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_27) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_27 = __importDefault(Endpoint_27); + exports.default = (0, Endpoint_27.default)("/follow/work/{author}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_28) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_28 = __importDefault(Endpoint_28); + exports.default = (0, Endpoint_28.default)("/follows/{type}/{vanity}", "get"); +}); +define("endpoint/follow/EndpointFollowGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_29) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_29 = __importDefault(Endpoint_29); + exports.default = (0, Endpoint_29.default)("/following/{type}", "get"); +}); +define("endpoint/follow/EndpointFollowGetAllMerged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_30) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_30 = __importDefault(Endpoint_30); + exports.default = (0, Endpoint_30.default)("/following", "get"); +}); +define("endpoint/follow/EndpointFollowGetWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_31) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_31 = __importDefault(Endpoint_31); + exports.default = (0, Endpoint_31.default)("/follows/work/{author}/{vanity}", "get"); +}); +define("endpoint/follow/EndpointFollowRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_32) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_32 = __importDefault(Endpoint_32); + exports.default = (0, Endpoint_32.default)("/unfollow/{type}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowRemoveWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_33) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_33 = __importDefault(Endpoint_33); + exports.default = (0, Endpoint_33.default)("/unfollow/work/{author}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_34) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_34 = __importDefault(Endpoint_34); + exports.default = (0, Endpoint_34.default)("/ignore/{type}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreAddWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_35) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_35 = __importDefault(Endpoint_35); + exports.default = (0, Endpoint_35.default)("/ignore/work/{author}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_36) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_36 = __importDefault(Endpoint_36); + exports.default = (0, Endpoint_36.default)("/ignores/{type}/{vanity}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_37) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_37 = __importDefault(Endpoint_37); + exports.default = (0, Endpoint_37.default)("/ignoring/{type}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetAllMerged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_38) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_38 = __importDefault(Endpoint_38); + exports.default = (0, Endpoint_38.default)("/ignoring", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_39) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_39 = __importDefault(Endpoint_39); + exports.default = (0, Endpoint_39.default)("/ignores/work/{author}/{vanity}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_40) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_40 = __importDefault(Endpoint_40); + exports.default = (0, Endpoint_40.default)("/unignore/{type}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreRemoveWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_41) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_41 = __importDefault(Endpoint_41); + exports.default = (0, Endpoint_41.default)("/unignore/work/{author}/{vanity}", "post"); +}); +define("endpoint/notification/EndpointNotificationGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_42) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_42 = __importDefault(Endpoint_42); + exports.default = (0, Endpoint_42.default)("/notifications/get/all", "get"); +}); +define("endpoint/notification/EndpointNotificationGetCount", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_43) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_43 = __importDefault(Endpoint_43); + exports.default = (0, Endpoint_43.default)("/notifications/get/count", "get"); +}); +define("endpoint/notification/EndpointNotificationGetUnread", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_44) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_44 = __importDefault(Endpoint_44); + exports.default = (0, Endpoint_44.default)("/notifications/get/unread", "get"); +}); +define("endpoint/notification/EndpointNotificationMarkRead", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_45) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_45 = __importDefault(Endpoint_45); + exports.default = (0, Endpoint_45.default)("/notifications/mark/read", "post"); +}); +define("endpoint/notification/EndpointNotificationMarkUnread", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_46) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_46 = __importDefault(Endpoint_46); + exports.default = (0, Endpoint_46.default)("/notifications/mark/unread", "post"); +}); +define("endpoint/patreon/EndpointPatreonGetTiers", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_47) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_47 = __importDefault(Endpoint_47); + exports.default = (0, Endpoint_47.default)("/patreon/campaign/tiers/get", "get"); +}); +define("endpoint/patreon/EndpointPatreonSetThresholds", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_48) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_48 = __importDefault(Endpoint_48); + exports.default = (0, Endpoint_48.default)("/patreon/campaign/tiers/set/{author}/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeGetAllAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_49) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_49 = __importDefault(Endpoint_49); + exports.default = (0, Endpoint_49.default)("/privilege/get/{vanity}", "get"); +}); +define("endpoint/privilege/EndpointPrivilegeGrantAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_50) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_50 = __importDefault(Endpoint_50); + exports.default = (0, Endpoint_50.default)("/privilege/grant/author/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeGrantRole", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_51) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_51 = __importDefault(Endpoint_51); + exports.default = (0, Endpoint_51.default)("/privilege/grant/role/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeRevokeAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_52) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_52 = __importDefault(Endpoint_52); + exports.default = (0, Endpoint_52.default)("/privilege/revoke/author/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeRevokeRole", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_53) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_53 = __importDefault(Endpoint_53); + exports.default = (0, Endpoint_53.default)("/privilege/revoke/role/{vanity}", "post"); +}); +define("endpoint/role/EndpointRoleCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_54) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_54 = __importDefault(Endpoint_54); + exports.default = (0, Endpoint_54.default)("/role/create", "post"); +}); +define("endpoint/role/EndpointRoleDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_55) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_55 = __importDefault(Endpoint_55); + exports.default = (0, Endpoint_55.default)("/role/delete/{role}", "post"); +}); +define("endpoint/role/EndpointRoleGrantAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_56) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_56 = __importDefault(Endpoint_56); + exports.default = (0, Endpoint_56.default)("/role/grant/{role}/{author}", "post"); +}); +define("endpoint/role/EndpointRoleListAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_57) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_57 = __importDefault(Endpoint_57); + exports.default = (0, Endpoint_57.default)("/role/get", "get"); +}); +define("endpoint/role/EndpointRoleReorder", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_58) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_58 = __importDefault(Endpoint_58); + exports.default = (0, Endpoint_58.default)("/role/reorder", "post"); +}); +define("endpoint/role/EndpointRoleRevokeAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_59) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_59 = __importDefault(Endpoint_59); + exports.default = (0, Endpoint_59.default)("/role/revoke/{role}/{author}", "post"); +}); +define("endpoint/role/EndpointRoleUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_60) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_60 = __importDefault(Endpoint_60); + exports.default = (0, Endpoint_60.default)("/role/update/{role}", "post"); +}); +define("endpoint/tag/EndpointTagCreateCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_61) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_61 = __importDefault(Endpoint_61); + exports.default = (0, Endpoint_61.default)("/tag/create/category", "post"); +}); +define("endpoint/tag/EndpointTagCreateGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_62) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_62 = __importDefault(Endpoint_62); + exports.default = (0, Endpoint_62.default)("/tag/create/global", "post"); +}); +define("endpoint/tag/EndpointTagCustomPromote", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_63) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_63 = __importDefault(Endpoint_63); + exports.default = (0, Endpoint_63.default)("/tag/promote/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagGlobalDemote", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_64) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_64 = __importDefault(Endpoint_64); + exports.default = (0, Endpoint_64.default)("/tag/demote/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagRemoveCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_65) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_65 = __importDefault(Endpoint_65); + exports.default = (0, Endpoint_65.default)("/tag/remove/category/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagRemoveGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_66) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_66 = __importDefault(Endpoint_66); + exports.default = (0, Endpoint_66.default)("/tag/remove/global/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagUpdateCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_67) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_67 = __importDefault(Endpoint_67); + exports.default = (0, Endpoint_67.default)("/tag/update/category/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagUpdateGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_68) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_68 = __importDefault(Endpoint_68); + exports.default = (0, Endpoint_68.default)("/tag/update/global/{vanity}", "post"); +}); +define("ui/component/core/ActionHeading", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/Heading"], function (require, exports, Component_58, ActionRow_7, Heading_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_58 = __importDefault(Component_58); + ActionRow_7 = __importDefault(ActionRow_7); + Heading_3 = __importDefault(Heading_3); + const ActionHeading = Component_58.default.Builder((component) => { + const row = component.and(ActionRow_7.default) + .viewTransition("action-heading") + .style("action-heading"); + const heading = row.left.and(Heading_3.default).style("action-heading-heading"); + return row.extend(row => ({ + heading, + })); + }); + exports.default = ActionHeading; +}); +//#region Not currently used +// interface AnchorNameManipulator { +// (name: string): HOST +// remove (name: string): HOST +// } +// interface AnchorComponentExtensions { +// anchorName: AnchorNameManipulator +// } +// declare module "ui/Component" { +// interface ComponentExtensions extends AnchorComponentExtensions { } +// } +// Component.extend(component => { +// let anchorNames: string[] | undefined +// return { +// anchorName: Object.assign( +// (name: string) => { +// anchorNames ??= [] +// if (!name.startsWith("--")) +// name = `--${name}` +// anchorNames.push(name) +// component.style.setProperty("anchor-name", anchorNames.join(",")) +// return component +// }, +// { +// remove: (name: string) => { +// const index = anchorNames?.indexOf(name) ?? -1 +// if (index === -1) +// return component +// anchorNames!.splice(index, 1) +// if (!anchorNames!.length) +// component.style.removeProperties("anchor-name") +// else +// component.style.setProperty("anchor-name", anchorNames!.join(",")) +// return component +// }, +// }, +// ), +// } +// }) +// namespace Anchor { +// const INDICES: Record = {} +// export function name (type: string) { +// const id = INDICES[type] ?? 0 +// INDICES[type] = id + 1 +// return `--${type}-${id}` +// } +// } +// export default Anchor +define("ui/utility/ActiveListener", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var ActiveListener; + (function (ActiveListener) { + let lastActive = []; + function allActive() { + return lastActive; + } + ActiveListener.allActive = allActive; + function active() { + return lastActive.at(-1); + } + ActiveListener.active = active; + function* allActiveComponents() { + for (const element of lastActive) { + const component = element.component; + if (component) + yield component; + } + } + ActiveListener.allActiveComponents = allActiveComponents; + function activeComponent() { + return lastActive.at(-1)?.component; + } + ActiveListener.activeComponent = activeComponent; + function listen() { + document.addEventListener("mousedown", updateActive); + document.addEventListener("mouseup", updateActive); + function updateActive() { + const allActive = document.querySelectorAll(":active"); + const active = allActive[allActive.length - 1]; + if (active === lastActive[lastActive.length - 1]) + return; + const newActive = [...allActive]; + for (const element of lastActive) + if (element.component && !newActive.includes(element)) + element.component.active.value = false; + for (const element of newActive) + if (element.component && !lastActive.includes(element)) + element.component.active.value = true; + lastActive = newActive; + } + } + ActiveListener.listen = listen; + })(ActiveListener || (ActiveListener = {})); + exports.default = ActiveListener; + Object.assign(window, { ActiveListener }); +}); +define("utility/Debug", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Debug = void 0; + var Debug; + (function (Debug) { + Debug.placeholder = false; + })(Debug || (exports.Debug = Debug = {})); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + window.Debug = Debug; +}); +define("utility/Functions", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Functions; + (function (Functions) { + function resolve(fn, ...args) { + return typeof fn === "function" ? fn(...args) : fn; + } + Functions.resolve = resolve; + })(Functions || (Functions = {})); + exports.default = Functions; +}); +define("utility/Tuples", ["require", "exports", "utility/Arrays"], function (require, exports, Arrays_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_7 = __importDefault(Arrays_7); + var Tuples; + (function (Tuples) { + function make(...values) { + return values; + } + Tuples.make = make; + const nullishFilters = Object.fromEntries(Arrays_7.default.range(6) + .map(index => make(index, (value) => value[index] !== undefined && value[index] !== null))); + function filterNullish(index) { + return nullishFilters[index]; + } + Tuples.filterNullish = filterNullish; + const falsyFilters = Object.fromEntries(Arrays_7.default.range(6) + .map(index => make(index, (value) => value[index]))); + function filterFalsy(index) { + return falsyFilters[index]; + } + Tuples.filterFalsy = filterFalsy; + function getter(index) { + return tuple => tuple[index]; + } + Tuples.getter = getter; + function filter(index, predicate) { + return (tuple, i) => predicate(tuple[index], i); + } + Tuples.filter = filter; + })(Tuples || (Tuples = {})); + exports.default = Tuples; +}); +define("utility/decorator/Bound", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Bound = Bound; + exports.Final = Final; + function Bound(target, key, descriptor) { + return Bounder(target, key, descriptor); + } + function Final(target, key, descriptor) { + return Bounder(target, key, descriptor); + } + function Bounder(target, key, descriptor) { + return { + configurable: false, + enumerable: descriptor.enumerable, + get() { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins + if (!this || this === target.prototype || this.hasOwnProperty(key) || typeof descriptor.value !== "function") { + return descriptor.value; + } + const value = descriptor.value.bind(this); + Object.defineProperty(this, key, { + configurable: false, + enumerable: descriptor.enumerable, + value, + }); + return value; + }, + }; + } + exports.default = Bound; +}); diff --git a/beta/js/init.js b/beta/js/init.js new file mode 100644 index 0000000..c06c2b2 --- /dev/null +++ b/beta/js/init.js @@ -0,0 +1,348 @@ +/* eslint-disable */ + +(() => { + const baseURL = document.currentScript.dataset.baseUrl + + /** + * @enum {number} + */ + const ModuleState = { + Unprocessed: 0, + Waiting: 1, + Processed: 2, + Error: 3, + } + + /** + * @typedef {(module: string) => any} ModuleGetter + */ + + /** + * @typedef {(modules: string[], resolve: (module: any) => void, reject: (err?: any) => any) => void} ModuleGetterAsync + */ + + /** + * @typedef {(getModule: ModuleGetter | ModuleGetterAsync, module: Module, ...args: any[]) => any} ModuleInitializer + */ + + /** + * @typedef {{ _name: string; _state: ModuleState; _requirements: string[]; _initializer: ModuleInitializer; _error?: Error }} Module + */ + + /** + * @type {Map} + */ + const moduleMap = new Map() + /** + * @type {Set} + */ + const requirements = new Set() + + /** + * @param {string | string[]} name + * @param {string[] | ModuleInitializer} reqs + * @param {ModuleInitializer?} fn + */ + function define (name, reqs, fn) { + if (Array.isArray(name)) { + fn = reqs + reqs = name + + const src = document.currentScript.getAttribute("src") + if (!src) + throw new Error("Cannot define module without a name") + + name = src.startsWith("./") ? src.slice(2) : src.startsWith("/") ? src.slice(1) : src + name = baseURL && name.startsWith(baseURL) ? name.slice(baseURL.length) : name + name = name.endsWith(".js") ? name.slice(0, -3) : name + name = name.endsWith("/index") ? name.slice(0, -6) : name + } + + reqs ??= [] + + if (moduleMap.has(name)) + throw new Error(`Module "${name}" cannot be redefined`) + + if (typeof reqs === "function") { + if (fn) + throw new Error("Unsupport define call") + + fn = reqs + reqs = [] + } + + const _requirements = reqs.slice(2).map(req => findModuleName(name, req)) + /** + * @type {Module} + */ + const module = { + _name: name, + _state: ModuleState.Unprocessed, + _requirements, + _initializer: fn, + _init: document.currentScript?.dataset.init === name, + _replace (newModule) { + if (typeof newModule !== "object" && typeof newModule !== "function") + throw new Error("Cannot assign module.exports to a non-object") + + newModule._name = name + newModule._state = ModuleState.Unprocessed + newModule._requirements = _requirements + newModule._initializer = fn + newModule._replace = module._replace + moduleMap.set(name, newModule) + }, + } + moduleMap.set(name, module) + for (const req of module._requirements) + requirements.add(req) + + const preload = name.endsWith("$preload") + if (preload) { + if (module._requirements.length) + throw new Error(`Module "${name}" cannot import other modules`) + + initializeModule(module) + } + + if (initialProcessCompleted) + processModules() + } + + define.amd = true + + /** + * @param {string} name + * @param {string[]} [requiredBy] + */ + function getModule (name, requiredBy) { + let module = moduleMap.get(name) + if (!module) { + if (name.endsWith(".js")) + name = name.slice(0, -3) + + if (name.startsWith(".")) { + let from = requiredBy[requiredBy.length - 1] + if (!from.includes("/")) + from += "/" + + name = findModuleName(from, name) + } + + module = moduleMap.get(name) + if (!module) + throw new Error(`Module "${name}" has not been declared and cannot be required`) + } + + if (module._state === ModuleState.Unprocessed) + module = processModule(name, module, requiredBy) + + return module + } + + /** + * @param {string} name + */ + function initializeModuleByName (name) { + initializeModule(getModule(name)) + } + + /** + * @param {Module} module + * @param {string[]} [requiredBy] + * @param {...any} args + */ + function initializeModule (module, requiredBy, ...args) { + if (module._state) + throw new Error(`Module "${module._name}" has already been processed`) + + try { + requiredBy = [...requiredBy, module._name] + + /** + * @param {string | string[]} nameOrNames + * @param {(module: any) => void} [resolve] + * @param {(err?: any) => void} [reject] + */ + function require (nameOrNames, resolve, reject) { + if (Array.isArray(nameOrNames)) { + const results = nameOrNames.map(name => getModule(name, requiredBy)) + return resolve(results.length === 1 ? results[0] : results) + } + + return getModule(nameOrNames, requiredBy) + } + + module.require = require + + const result = module._initializer(require, module, ...args) + if (module.default === undefined) { + module.default = result ?? module + module.__esModule = true + } + + module = moduleMap.get(module._name) + module._state = ModuleState.Processed + + injectModule(module) + + } catch (err) { + module._state = ModuleState.Error + module._error = err + err.message = `[Module initialization ${module._name}] ${err.message}` + console.error(err) + } + } + + const isInjectableModuleDefaultNameRegex = /^[A-Z_$][a-zA-Z_$0-9]+$/ + function injectModule (module) { + const name = module._name + const inject = module.default ?? module + const moduleDefaultName = basename(name) + if (isInjectableModuleDefaultNameRegex.test(moduleDefaultName) && !(moduleDefaultName in window)) + Object.assign(window, { [moduleDefaultName]: inject }) + + for (const key of Object.keys(module)) { + if (key !== "default" && !key.startsWith("_") && isInjectableModuleDefaultNameRegex.test(key) && !(key in window)) { + Object.assign(window, { [key]: module[key] }) + } + } + } + + + //////////////////////////////////// + // Add the above functions to Window + // + + /** + * @type {Window & typeof globalThis & { define: typeof define; getModule: typeof getModule; initializeModule: typeof initializeModuleByName }} + */ + const moddableWindow = (window) + moddableWindow.define = define + moddableWindow.getModule = getModule + moddableWindow.initializeModule = initializeModuleByName + + + //////////////////////////////////// + // Actually process the modules + // + + document.addEventListener("DOMContentLoaded", processModules) + + let initialProcessCompleted = false + async function processModules () { + const scriptsStillToImport = Array.from(document.querySelectorAll("template[data-script]")) + .map(definition => { + const script = /** @type {HTMLTemplateElement} */ (definition).dataset.script + definition.remove() + return script + }) + + await Promise.all(Array.from(new Set(scriptsStillToImport)).map(tryImportAdditionalModule)) + + while (requirements.size) { + const remainingRequirements = Array.from(requirements) + await Promise.all(remainingRequirements.map(tryImportAdditionalModule)) + for (const req of remainingRequirements) + requirements.delete(req) + } + + for (const [name, module] of moduleMap.entries()) + if (module._init) + processModule(name, module) + + initialProcessCompleted = true + } + + /** + * @param {string} req + */ + async function tryImportAdditionalModule (req) { + if (moduleMap.has(req)) + return + + await importAdditionalModule(req) + + if (!moduleMap.has(req)) + throw new Error(`The required module '${req}' could not be asynchronously loaded.`) + } + + /** + * @param {string} req + */ + async function importAdditionalModule (req) { + const script = document.createElement("script") + document.head.appendChild(script) + /** @type {Promise} */ + const promise = new Promise(resolve => script.addEventListener("load", () => resolve())) + script.src = `/script/${req}.js` + return promise + } + + /** + * @param {string} name + * @param {Module | undefined} module + * @param {string[]} requiredBy + */ + function processModule (name, module = moduleMap.get(name), requiredBy = []) { + if (!module) + throw new Error(`No "${name}" module defined`) + + if (module._state === ModuleState.Waiting) + throw new Error(`Circular dependency! Dependency chain: ${[...requiredBy, name].map(m => `"${m}"`).join(" > ")}`) + + if (!module._state) { + module._state = ModuleState.Waiting + const args = module._requirements + .map(req => processModule(req, undefined, [...requiredBy, name])) + + module._state = ModuleState.Unprocessed + initializeModule(module, requiredBy, ...args) + } + + return moduleMap.get(name) + } + + + //////////////////////////////////// + // Utils + // + + /** + * @param {string} name + * @param {string} requirement + */ + function findModuleName (name, requirement) { + let root = dirname(name) + if (requirement.startsWith("./")) + return join(root, requirement.slice(2)) + + while (requirement.startsWith("../")) + root = dirname(root), requirement = requirement.slice(3) + + return requirement // join(root, requirement); + } + + /** + * @param {string} name + */ + function dirname (name) { + const lastIndex = name.lastIndexOf("/") + return lastIndex === -1 ? "" : name.slice(0, lastIndex) + } + + /** + * @param {string} name + */ + function basename (name) { + const lastIndex = name.lastIndexOf("/") + return name.slice(lastIndex + 1) + } + + /** + * @param {...string} path + */ + function join (...path) { + return path.filter(p => p).join("/") + } +})() diff --git a/beta/js/vendor.js b/beta/js/vendor.js new file mode 100644 index 0000000..204b894 --- /dev/null +++ b/beta/js/vendor.js @@ -0,0 +1,23464 @@ +define("prosemirror-commands",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorState = require('prosemirror-state'); +var deleteSelection = function deleteSelection(state, dispatch) { + if (state.selection.empty) return false; + if (dispatch) dispatch(state.tr.deleteSelection().scrollIntoView()); + return true; +}; +function atBlockStart(state, view) { + var $cursor = state.selection.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) return null; + return $cursor; +} +var joinBackward = function joinBackward(state, dispatch, view) { + var $cursor = atBlockStart(state, view); + if (!$cursor) return false; + var $cut = findCutBefore($cursor); + if (!$cut) { + var range = $cursor.blockRange(), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; + } + var before = $cut.nodeBefore; + if (deleteBarrier(state, $cut, dispatch, -1)) return true; + if ($cursor.parent.content.size == 0 && (textblockAt(before, "end") || prosemirrorState.NodeSelection.isSelectable(before))) { + for (var depth = $cursor.depth;; depth--) { + var delStep = prosemirrorTransform.replaceStep(state.doc, $cursor.before(depth), $cursor.after(depth), prosemirrorModel.Slice.empty); + if (delStep && delStep.slice.size < delStep.to - delStep.from) { + if (dispatch) { + var tr = state.tr.step(delStep); + tr.setSelection(textblockAt(before, "end") ? prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos, -1)), -1) : prosemirrorState.NodeSelection.create(tr.doc, $cut.pos - before.nodeSize)); + dispatch(tr.scrollIntoView()); + } + return true; + } + if (depth == 1 || $cursor.node(depth - 1).childCount > 1) break; + } + } + if (before.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr["delete"]($cut.pos - before.nodeSize, $cut.pos).scrollIntoView()); + return true; + } + return false; +}; +var joinTextblockBackward = function joinTextblockBackward(state, dispatch, view) { + var $cursor = atBlockStart(state, view); + if (!$cursor) return false; + var $cut = findCutBefore($cursor); + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; +}; +var joinTextblockForward = function joinTextblockForward(state, dispatch, view) { + var $cursor = atBlockEnd(state, view); + if (!$cursor) return false; + var $cut = findCutAfter($cursor); + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; +}; +function joinTextblocksAround(state, $cut, dispatch) { + var before = $cut.nodeBefore, + beforeText = before, + beforePos = $cut.pos - 1; + for (; !beforeText.isTextblock; beforePos--) { + if (beforeText.type.spec.isolating) return false; + var child = beforeText.lastChild; + if (!child) return false; + beforeText = child; + } + var after = $cut.nodeAfter, + afterText = after, + afterPos = $cut.pos + 1; + for (; !afterText.isTextblock; afterPos++) { + if (afterText.type.spec.isolating) return false; + var _child = afterText.firstChild; + if (!_child) return false; + afterText = _child; + } + var step = prosemirrorTransform.replaceStep(state.doc, beforePos, afterPos, prosemirrorModel.Slice.empty); + if (!step || step.from != beforePos || step instanceof prosemirrorTransform.ReplaceStep && step.slice.size >= afterPos - beforePos) return false; + if (dispatch) { + var tr = state.tr.step(step); + tr.setSelection(prosemirrorState.TextSelection.create(tr.doc, beforePos)); + dispatch(tr.scrollIntoView()); + } + return true; +} +function textblockAt(node, side) { + var only = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + for (var scan = node; scan; scan = side == "start" ? scan.firstChild : scan.lastChild) { + if (scan.isTextblock) return true; + if (only && scan.childCount != 1) return false; + } + return false; +} +var selectNodeBackward = function selectNodeBackward(state, dispatch, view) { + var _state$selection = state.selection, + $head = _state$selection.$head, + empty = _state$selection.empty, + $cut = $head; + if (!empty) return false; + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("backward", state) : $head.parentOffset > 0) return false; + $cut = findCutBefore($head); + } + var node = $cut && $cut.nodeBefore; + if (!node || !prosemirrorState.NodeSelection.isSelectable(node)) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, $cut.pos - node.nodeSize)).scrollIntoView()); + return true; +}; +function findCutBefore($pos) { + if (!$pos.parent.type.spec.isolating) for (var i = $pos.depth - 1; i >= 0; i--) { + if ($pos.index(i) > 0) return $pos.doc.resolve($pos.before(i + 1)); + if ($pos.node(i).type.spec.isolating) break; + } + return null; +} +function atBlockEnd(state, view) { + var $cursor = state.selection.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("forward", state) : $cursor.parentOffset < $cursor.parent.content.size)) return null; + return $cursor; +} +var joinForward = function joinForward(state, dispatch, view) { + var $cursor = atBlockEnd(state, view); + if (!$cursor) return false; + var $cut = findCutAfter($cursor); + if (!$cut) return false; + var after = $cut.nodeAfter; + if (deleteBarrier(state, $cut, dispatch, 1)) return true; + if ($cursor.parent.content.size == 0 && (textblockAt(after, "start") || prosemirrorState.NodeSelection.isSelectable(after))) { + var delStep = prosemirrorTransform.replaceStep(state.doc, $cursor.before(), $cursor.after(), prosemirrorModel.Slice.empty); + if (delStep && delStep.slice.size < delStep.to - delStep.from) { + if (dispatch) { + var tr = state.tr.step(delStep); + tr.setSelection(textblockAt(after, "start") ? prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1) : prosemirrorState.NodeSelection.create(tr.doc, tr.mapping.map($cut.pos))); + dispatch(tr.scrollIntoView()); + } + return true; + } + } + if (after.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr["delete"]($cut.pos, $cut.pos + after.nodeSize).scrollIntoView()); + return true; + } + return false; +}; +var selectNodeForward = function selectNodeForward(state, dispatch, view) { + var _state$selection2 = state.selection, + $head = _state$selection2.$head, + empty = _state$selection2.empty, + $cut = $head; + if (!empty) return false; + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("forward", state) : $head.parentOffset < $head.parent.content.size) return false; + $cut = findCutAfter($head); + } + var node = $cut && $cut.nodeAfter; + if (!node || !prosemirrorState.NodeSelection.isSelectable(node)) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, $cut.pos)).scrollIntoView()); + return true; +}; +function findCutAfter($pos) { + if (!$pos.parent.type.spec.isolating) for (var i = $pos.depth - 1; i >= 0; i--) { + var parent = $pos.node(i); + if ($pos.index(i) + 1 < parent.childCount) return $pos.doc.resolve($pos.after(i + 1)); + if (parent.type.spec.isolating) break; + } + return null; +} +var joinUp = function joinUp(state, dispatch) { + var sel = state.selection, + nodeSel = sel instanceof prosemirrorState.NodeSelection, + point; + if (nodeSel) { + if (sel.node.isTextblock || !prosemirrorTransform.canJoin(state.doc, sel.from)) return false; + point = sel.from; + } else { + point = prosemirrorTransform.joinPoint(state.doc, sel.from, -1); + if (point == null) return false; + } + if (dispatch) { + var tr = state.tr.join(point); + if (nodeSel) tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, point - state.doc.resolve(point).nodeBefore.nodeSize)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var joinDown = function joinDown(state, dispatch) { + var sel = state.selection, + point; + if (sel instanceof prosemirrorState.NodeSelection) { + if (sel.node.isTextblock || !prosemirrorTransform.canJoin(state.doc, sel.to)) return false; + point = sel.to; + } else { + point = prosemirrorTransform.joinPoint(state.doc, sel.to, 1); + if (point == null) return false; + } + if (dispatch) dispatch(state.tr.join(point).scrollIntoView()); + return true; +}; +var lift = function lift(state, dispatch) { + var _state$selection3 = state.selection, + $from = _state$selection3.$from, + $to = _state$selection3.$to; + var range = $from.blockRange($to), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; +}; +var newlineInCode = function newlineInCode(state, dispatch) { + var _state$selection4 = state.selection, + $head = _state$selection4.$head, + $anchor = _state$selection4.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; + if (dispatch) dispatch(state.tr.insertText("\n").scrollIntoView()); + return true; +}; +function defaultBlockAt(match) { + for (var i = 0; i < match.edgeCount; i++) { + var _match$edge = match.edge(i), + type = _match$edge.type; + if (type.isTextblock && !type.hasRequiredAttrs()) return type; + } + return null; +} +var exitCode = function exitCode(state, dispatch) { + var _state$selection5 = state.selection, + $head = _state$selection5.$head, + $anchor = _state$selection5.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; + var above = $head.node(-1), + after = $head.indexAfter(-1), + type = defaultBlockAt(above.contentMatchAt(after)); + if (!type || !above.canReplaceWith(after, after, type)) return false; + if (dispatch) { + var pos = $head.after(), + tr = state.tr.replaceWith(pos, pos, type.createAndFill()); + tr.setSelection(prosemirrorState.Selection.near(tr.doc.resolve(pos), 1)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var createParagraphNear = function createParagraphNear(state, dispatch) { + var sel = state.selection, + $from = sel.$from, + $to = sel.$to; + if (sel instanceof prosemirrorState.AllSelection || $from.parent.inlineContent || $to.parent.inlineContent) return false; + var type = defaultBlockAt($to.parent.contentMatchAt($to.indexAfter())); + if (!type || !type.isTextblock) return false; + if (dispatch) { + var side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos; + var tr = state.tr.insert(side, type.createAndFill()); + tr.setSelection(prosemirrorState.TextSelection.create(tr.doc, side + 1)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var liftEmptyBlock = function liftEmptyBlock(state, dispatch) { + var $cursor = state.selection.$cursor; + if (!$cursor || $cursor.parent.content.size) return false; + if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) { + var before = $cursor.before(); + if (prosemirrorTransform.canSplit(state.doc, before)) { + if (dispatch) dispatch(state.tr.split(before).scrollIntoView()); + return true; + } + } + var range = $cursor.blockRange(), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; +}; +function splitBlockAs(splitNode) { + return function (state, dispatch) { + var _state$selection6 = state.selection, + $from = _state$selection6.$from, + $to = _state$selection6.$to; + if (state.selection instanceof prosemirrorState.NodeSelection && state.selection.node.isBlock) { + if (!$from.parentOffset || !prosemirrorTransform.canSplit(state.doc, $from.pos)) return false; + if (dispatch) dispatch(state.tr.split($from.pos).scrollIntoView()); + return true; + } + if (!$from.parent.isBlock) return false; + var atEnd = $to.parentOffset == $to.parent.content.size; + var tr = state.tr; + if (state.selection instanceof prosemirrorState.TextSelection || state.selection instanceof prosemirrorState.AllSelection) tr.deleteSelection(); + var deflt = $from.depth == 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1))); + var splitType = splitNode && splitNode($to.parent, atEnd, $from); + var types = splitType ? [splitType] : atEnd && deflt ? [{ + type: deflt + }] : undefined; + var can = prosemirrorTransform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, types); + if (!types && !can && prosemirrorTransform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ + type: deflt + }] : undefined)) { + if (deflt) types = [{ + type: deflt + }]; + can = true; + } + if (!can) return false; + tr.split(tr.mapping.map($from.pos), 1, types); + if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) { + var first = tr.mapping.map($from.before()), + $first = tr.doc.resolve(first); + if (deflt && $from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(tr.mapping.map($from.before()), deflt); + } + if (dispatch) dispatch(tr.scrollIntoView()); + return true; + }; +} +var splitBlock = splitBlockAs(); +var splitBlockKeepMarks = function splitBlockKeepMarks(state, dispatch) { + return splitBlock(state, dispatch && function (tr) { + var marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks(); + if (marks) tr.ensureMarks(marks); + dispatch(tr); + }); +}; +var selectParentNode = function selectParentNode(state, dispatch) { + var _state$selection7 = state.selection, + $from = _state$selection7.$from, + to = _state$selection7.to, + pos; + var same = $from.sharedDepth(to); + if (same == 0) return false; + pos = $from.before(same); + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, pos))); + return true; +}; +var selectAll = function selectAll(state, dispatch) { + if (dispatch) dispatch(state.tr.setSelection(new prosemirrorState.AllSelection(state.doc))); + return true; +}; +function joinMaybeClear(state, $pos, dispatch) { + var before = $pos.nodeBefore, + after = $pos.nodeAfter, + index = $pos.index(); + if (!before || !after || !before.type.compatibleContent(after.type)) return false; + if (!before.content.size && $pos.parent.canReplace(index - 1, index)) { + if (dispatch) dispatch(state.tr["delete"]($pos.pos - before.nodeSize, $pos.pos).scrollIntoView()); + return true; + } + if (!$pos.parent.canReplace(index, index + 1) || !(after.isTextblock || prosemirrorTransform.canJoin(state.doc, $pos.pos))) return false; + if (dispatch) dispatch(state.tr.join($pos.pos).scrollIntoView()); + return true; +} +function deleteBarrier(state, $cut, dispatch, dir) { + var before = $cut.nodeBefore, + after = $cut.nodeAfter, + conn, + match; + var isolated = before.type.spec.isolating || after.type.spec.isolating; + if (!isolated && joinMaybeClear(state, $cut, dispatch)) return true; + var canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1); + if (canDelAfter && (conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && match.matchType(conn[0] || after.type).validEnd) { + if (dispatch) { + var end = $cut.pos + after.nodeSize, + wrap = prosemirrorModel.Fragment.empty; + for (var i = conn.length - 1; i >= 0; i--) wrap = prosemirrorModel.Fragment.from(conn[i].create(null, wrap)); + wrap = prosemirrorModel.Fragment.from(before.copy(wrap)); + var tr = state.tr.step(new prosemirrorTransform.ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new prosemirrorModel.Slice(wrap, 1, 0), conn.length, true)); + var $joinAt = tr.doc.resolve(end + 2 * conn.length); + if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && prosemirrorTransform.canJoin(tr.doc, $joinAt.pos)) tr.join($joinAt.pos); + dispatch(tr.scrollIntoView()); + } + return true; + } + var selAfter = after.type.spec.isolating || dir > 0 && isolated ? null : prosemirrorState.Selection.findFrom($cut, 1); + var range = selAfter && selAfter.$from.blockRange(selAfter.$to), + target = range && prosemirrorTransform.liftTarget(range); + if (target != null && target >= $cut.depth) { + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; + } + if (canDelAfter && textblockAt(after, "start", true) && textblockAt(before, "end")) { + var at = before, + _wrap = []; + for (;;) { + _wrap.push(at); + if (at.isTextblock) break; + at = at.lastChild; + } + var afterText = after, + afterDepth = 1; + for (; !afterText.isTextblock; afterText = afterText.firstChild) afterDepth++; + if (at.canReplace(at.childCount, at.childCount, afterText.content)) { + if (dispatch) { + var _end = prosemirrorModel.Fragment.empty; + for (var _i = _wrap.length - 1; _i >= 0; _i--) _end = prosemirrorModel.Fragment.from(_wrap[_i].copy(_end)); + var _tr = state.tr.step(new prosemirrorTransform.ReplaceAroundStep($cut.pos - _wrap.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new prosemirrorModel.Slice(_end, _wrap.length, 0), 0, true)); + dispatch(_tr.scrollIntoView()); + } + return true; + } + } + return false; +} +function selectTextblockSide(side) { + return function (state, dispatch) { + var sel = state.selection, + $pos = side < 0 ? sel.$from : sel.$to; + var depth = $pos.depth; + while ($pos.node(depth).isInline) { + if (!depth) return false; + depth--; + } + if (!$pos.node(depth).isTextblock) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.TextSelection.create(state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))); + return true; + }; +} +var selectTextblockStart = selectTextblockSide(-1); +var selectTextblockEnd = selectTextblockSide(1); +function wrapIn(nodeType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var _state$selection8 = state.selection, + $from = _state$selection8.$from, + $to = _state$selection8.$to; + var range = $from.blockRange($to), + wrapping = range && prosemirrorTransform.findWrapping(range, nodeType, attrs); + if (!wrapping) return false; + if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView()); + return true; + }; +} +function setBlockType(nodeType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var applicable = false; + for (var i = 0; i < state.selection.ranges.length && !applicable; i++) { + var _state$selection$rang = state.selection.ranges[i], + from = _state$selection$rang.$from.pos, + to = _state$selection$rang.$to.pos; + state.doc.nodesBetween(from, to, function (node, pos) { + if (applicable) return false; + if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return; + if (node.type == nodeType) { + applicable = true; + } else { + var $pos = state.doc.resolve(pos), + index = $pos.index(); + applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType); + } + }); + } + if (!applicable) return false; + if (dispatch) { + var tr = state.tr; + for (var _i2 = 0; _i2 < state.selection.ranges.length; _i2++) { + var _state$selection$rang2 = state.selection.ranges[_i2], + _from = _state$selection$rang2.$from.pos, + _to = _state$selection$rang2.$to.pos; + tr.setBlockType(_from, _to, nodeType, attrs); + } + dispatch(tr.scrollIntoView()); + } + return true; + }; +} +function markApplies(doc, ranges, type, enterAtoms) { + var _loop = function _loop() { + var _ranges$i = ranges[i], + $from = _ranges$i.$from, + $to = _ranges$i.$to; + var can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false; + doc.nodesBetween($from.pos, $to.pos, function (node, pos) { + if (can || !enterAtoms && node.isAtom && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) return false; + can = node.inlineContent && node.type.allowsMarkType(type); + }); + if (can) return { + v: true + }; + }, + _ret; + for (var i = 0; i < ranges.length; i++) { + _ret = _loop(); + if (_ret) return _ret.v; + } + return false; +} +function removeInlineAtoms(ranges) { + var result = []; + var _loop2 = function _loop2() { + var _ranges$i2 = ranges[i], + $from = _ranges$i2.$from, + $to = _ranges$i2.$to; + $from.doc.nodesBetween($from.pos, $to.pos, function (node, pos) { + if (node.isAtom && node.content.size && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) { + if (pos + 1 > $from.pos) result.push(new prosemirrorState.SelectionRange($from, $from.doc.resolve(pos + 1))); + $from = $from.doc.resolve(pos + 1 + node.content.size); + return false; + } + }); + if ($from.pos < $to.pos) result.push(new prosemirrorState.SelectionRange($from, $to)); + }; + for (var i = 0; i < ranges.length; i++) { + _loop2(); + } + return result; +} +function toggleMark(markType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var options = arguments.length > 2 ? arguments[2] : undefined; + var removeWhenPresent = (options && options.removeWhenPresent) !== false; + var enterAtoms = (options && options.enterInlineAtoms) !== false; + return function (state, dispatch) { + var _state$selection9 = state.selection, + empty = _state$selection9.empty, + $cursor = _state$selection9.$cursor, + ranges = _state$selection9.ranges; + if (empty && !$cursor || !markApplies(state.doc, ranges, markType, enterAtoms)) return false; + if (dispatch) { + if ($cursor) { + if (markType.isInSet(state.storedMarks || $cursor.marks())) dispatch(state.tr.removeStoredMark(markType));else dispatch(state.tr.addStoredMark(markType.create(attrs))); + } else { + var add, + tr = state.tr; + if (!enterAtoms) ranges = removeInlineAtoms(ranges); + if (removeWhenPresent) { + add = !ranges.some(function (r) { + return state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType); + }); + } else { + add = !ranges.every(function (r) { + var missing = false; + tr.doc.nodesBetween(r.$from.pos, r.$to.pos, function (node, pos, parent) { + if (missing) return false; + missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(node.textBetween(Math.max(0, r.$from.pos - pos), Math.min(node.nodeSize, r.$to.pos - pos)))); + }); + return !missing; + }); + } + for (var i = 0; i < ranges.length; i++) { + var _ranges$i3 = ranges[i], + $from = _ranges$i3.$from, + $to = _ranges$i3.$to; + if (!add) { + tr.removeMark($from.pos, $to.pos, markType); + } else { + var from = $from.pos, + to = $to.pos, + start = $from.nodeAfter, + end = $to.nodeBefore; + var spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0; + var spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0; + if (from + spaceStart < to) { + from += spaceStart; + to -= spaceEnd; + } + tr.addMark(from, to, markType.create(attrs)); + } + } + dispatch(tr.scrollIntoView()); + } + } + return true; + }; +} +function wrapDispatchForJoin(dispatch, isJoinable) { + return function (tr) { + if (!tr.isGeneric) return dispatch(tr); + var ranges = []; + for (var i = 0; i < tr.mapping.maps.length; i++) { + var map = tr.mapping.maps[i]; + for (var j = 0; j < ranges.length; j++) ranges[j] = map.map(ranges[j]); + map.forEach(function (_s, _e, from, to) { + return ranges.push(from, to); + }); + } + var joinable = []; + for (var _i3 = 0; _i3 < ranges.length; _i3 += 2) { + var from = ranges[_i3], + to = ranges[_i3 + 1]; + var $from = tr.doc.resolve(from), + depth = $from.sharedDepth(to), + parent = $from.node(depth); + for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { + var after = parent.maybeChild(index); + if (!after) break; + if (index && joinable.indexOf(pos) == -1) { + var before = parent.child(index - 1); + if (before.type == after.type && isJoinable(before, after)) joinable.push(pos); + } + pos += after.nodeSize; + } + } + joinable.sort(function (a, b) { + return a - b; + }); + for (var _i4 = joinable.length - 1; _i4 >= 0; _i4--) { + if (prosemirrorTransform.canJoin(tr.doc, joinable[_i4])) tr.join(joinable[_i4]); + } + dispatch(tr); + }; +} +function autoJoin(command, isJoinable) { + var canJoin = Array.isArray(isJoinable) ? function (node) { + return isJoinable.indexOf(node.type.name) > -1; + } : isJoinable; + return function (state, dispatch, view) { + return command(state, dispatch && wrapDispatchForJoin(dispatch, canJoin), view); + }; +} +function chainCommands() { + for (var _len = arguments.length, commands = new Array(_len), _key = 0; _key < _len; _key++) { + commands[_key] = arguments[_key]; + } + return function (state, dispatch, view) { + for (var i = 0; i < commands.length; i++) if (commands[i](state, dispatch, view)) return true; + return false; + }; +} +var backspace = chainCommands(deleteSelection, joinBackward, selectNodeBackward); +var del = chainCommands(deleteSelection, joinForward, selectNodeForward); +var pcBaseKeymap = { + "Enter": chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock), + "Mod-Enter": exitCode, + "Backspace": backspace, + "Mod-Backspace": backspace, + "Shift-Backspace": backspace, + "Delete": del, + "Mod-Delete": del, + "Mod-a": selectAll +}; +var macBaseKeymap = { + "Ctrl-h": pcBaseKeymap["Backspace"], + "Alt-Backspace": pcBaseKeymap["Mod-Backspace"], + "Ctrl-d": pcBaseKeymap["Delete"], + "Ctrl-Alt-Backspace": pcBaseKeymap["Mod-Delete"], + "Alt-Delete": pcBaseKeymap["Mod-Delete"], + "Alt-d": pcBaseKeymap["Mod-Delete"], + "Ctrl-a": selectTextblockStart, + "Ctrl-e": selectTextblockEnd +}; +for (var key in pcBaseKeymap) macBaseKeymap[key] = pcBaseKeymap[key]; +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : typeof os != "undefined" && os.platform ? os.platform() == "darwin" : false; +var baseKeymap = mac ? macBaseKeymap : pcBaseKeymap; +exports.autoJoin = autoJoin; +exports.baseKeymap = baseKeymap; +exports.chainCommands = chainCommands; +exports.createParagraphNear = createParagraphNear; +exports.deleteSelection = deleteSelection; +exports.exitCode = exitCode; +exports.joinBackward = joinBackward; +exports.joinDown = joinDown; +exports.joinForward = joinForward; +exports.joinTextblockBackward = joinTextblockBackward; +exports.joinTextblockForward = joinTextblockForward; +exports.joinUp = joinUp; +exports.lift = lift; +exports.liftEmptyBlock = liftEmptyBlock; +exports.macBaseKeymap = macBaseKeymap; +exports.newlineInCode = newlineInCode; +exports.pcBaseKeymap = pcBaseKeymap; +exports.selectAll = selectAll; +exports.selectNodeBackward = selectNodeBackward; +exports.selectNodeForward = selectNodeForward; +exports.selectParentNode = selectParentNode; +exports.selectTextblockEnd = selectTextblockEnd; +exports.selectTextblockStart = selectTextblockStart; +exports.setBlockType = setBlockType; +exports.splitBlock = splitBlock; +exports.splitBlockAs = splitBlockAs; +exports.splitBlockKeepMarks = splitBlockKeepMarks; +exports.toggleMark = toggleMark; +exports.wrapIn = wrapIn; + +}); +define("prosemirror-dropcursor",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorState = require('prosemirror-state'); + +var prosemirrorTransform = require('prosemirror-transform'); + +function dropCursor() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new prosemirrorState.Plugin({ + view: function view(editorView) { + return new DropCursorView(editorView, options); + } + }); +} + +var DropCursorView = function () { + function DropCursorView(editorView, options) { + var _this = this; + + _classCallCheck(this, DropCursorView); + + var _a; + + this.editorView = editorView; + this.cursorPos = null; + this.element = null; + this.timeout = -1; + this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1; + this.color = options.color === false ? undefined : options.color || "black"; + this["class"] = options["class"]; + this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(function (name) { + var handler = function handler(e) { + _this[name](e); + }; + + editorView.dom.addEventListener(name, handler); + return { + name: name, + handler: handler + }; + }); + } + + _createClass(DropCursorView, [{ + key: "destroy", + value: function destroy() { + var _this2 = this; + + this.handlers.forEach(function (_ref) { + var name = _ref.name, + handler = _ref.handler; + return _this2.editorView.dom.removeEventListener(name, handler); + }); + } + }, { + key: "update", + value: function update(editorView, prevState) { + if (this.cursorPos != null && prevState.doc != editorView.state.doc) { + if (this.cursorPos > editorView.state.doc.content.size) this.setCursor(null);else this.updateOverlay(); + } + } + }, { + key: "setCursor", + value: function setCursor(pos) { + if (pos == this.cursorPos) return; + this.cursorPos = pos; + + if (pos == null) { + this.element.parentNode.removeChild(this.element); + this.element = null; + } else { + this.updateOverlay(); + } + } + }, { + key: "updateOverlay", + value: function updateOverlay() { + var $pos = this.editorView.state.doc.resolve(this.cursorPos); + var isBlock = !$pos.parent.inlineContent, + rect; + + if (isBlock) { + var before = $pos.nodeBefore, + after = $pos.nodeAfter; + + if (before || after) { + var node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0)); + + if (node) { + var nodeRect = node.getBoundingClientRect(); + var top = before ? nodeRect.bottom : nodeRect.top; + if (before && after) top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2; + rect = { + left: nodeRect.left, + right: nodeRect.right, + top: top - this.width / 2, + bottom: top + this.width / 2 + }; + } + } + } + + if (!rect) { + var coords = this.editorView.coordsAtPos(this.cursorPos); + rect = { + left: coords.left - this.width / 2, + right: coords.left + this.width / 2, + top: coords.top, + bottom: coords.bottom + }; + } + + var parent = this.editorView.dom.offsetParent; + + if (!this.element) { + this.element = parent.appendChild(document.createElement("div")); + if (this["class"]) this.element.className = this["class"]; + this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;"; + + if (this.color) { + this.element.style.backgroundColor = this.color; + } + } + + this.element.classList.toggle("prosemirror-dropcursor-block", isBlock); + this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock); + var parentLeft, parentTop; + + if (!parent || parent == document.body && getComputedStyle(parent).position == "static") { + parentLeft = -pageXOffset; + parentTop = -pageYOffset; + } else { + var _rect = parent.getBoundingClientRect(); + + parentLeft = _rect.left - parent.scrollLeft; + parentTop = _rect.top - parent.scrollTop; + } + + this.element.style.left = rect.left - parentLeft + "px"; + this.element.style.top = rect.top - parentTop + "px"; + this.element.style.width = rect.right - rect.left + "px"; + this.element.style.height = rect.bottom - rect.top + "px"; + } + }, { + key: "scheduleRemoval", + value: function scheduleRemoval(timeout) { + var _this3 = this; + + clearTimeout(this.timeout); + this.timeout = setTimeout(function () { + return _this3.setCursor(null); + }, timeout); + } + }, { + key: "dragover", + value: function dragover(event) { + if (!this.editorView.editable) return; + var pos = this.editorView.posAtCoords({ + left: event.clientX, + top: event.clientY + }); + var node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside); + var disableDropCursor = node && node.type.spec.disableDropCursor; + var disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor; + + if (pos && !disabled) { + var target = pos.pos; + + if (this.editorView.dragging && this.editorView.dragging.slice) { + var point = prosemirrorTransform.dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice); + if (point != null) target = point; + } + + this.setCursor(target); + this.scheduleRemoval(5000); + } + } + }, { + key: "dragend", + value: function dragend() { + this.scheduleRemoval(20); + } + }, { + key: "drop", + value: function drop() { + this.scheduleRemoval(20); + } + }, { + key: "dragleave", + value: function dragleave(event) { + if (event.target == this.editorView.dom || !this.editorView.dom.contains(event.relatedTarget)) this.setCursor(null); + } + }]); + + return DropCursorView; +}(); + +exports.dropCursor = dropCursor; + +}); +define("prosemirror-example-setup",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorKeymap = require('prosemirror-keymap'); +var prosemirrorHistory = require('prosemirror-history'); +var prosemirrorCommands = require('prosemirror-commands'); +var prosemirrorState = require('prosemirror-state'); +var prosemirrorDropcursor = require('prosemirror-dropcursor'); +var prosemirrorGapcursor = require('prosemirror-gapcursor'); +var prosemirrorMenu = require('prosemirror-menu'); +var prosemirrorSchemaList = require('prosemirror-schema-list'); +var prosemirrorInputrules = require('prosemirror-inputrules'); +var prefix = "ProseMirror-prompt"; +function openPrompt(options) { + var wrapper = document.body.appendChild(document.createElement("div")); + wrapper.className = prefix; + var mouseOutside = function mouseOutside(e) { + if (!wrapper.contains(e.target)) close(); + }; + setTimeout(function () { + return window.addEventListener("mousedown", mouseOutside); + }, 50); + var close = function close() { + window.removeEventListener("mousedown", mouseOutside); + if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper); + }; + var domFields = []; + for (var name in options.fields) domFields.push(options.fields[name].render()); + var submitButton = document.createElement("button"); + submitButton.type = "submit"; + submitButton.className = prefix + "-submit"; + submitButton.textContent = "OK"; + var cancelButton = document.createElement("button"); + cancelButton.type = "button"; + cancelButton.className = prefix + "-cancel"; + cancelButton.textContent = "Cancel"; + cancelButton.addEventListener("click", close); + var form = wrapper.appendChild(document.createElement("form")); + if (options.title) form.appendChild(document.createElement("h5")).textContent = options.title; + domFields.forEach(function (field) { + form.appendChild(document.createElement("div")).appendChild(field); + }); + var buttons = form.appendChild(document.createElement("div")); + buttons.className = prefix + "-buttons"; + buttons.appendChild(submitButton); + buttons.appendChild(document.createTextNode(" ")); + buttons.appendChild(cancelButton); + var box = wrapper.getBoundingClientRect(); + wrapper.style.top = (window.innerHeight - box.height) / 2 + "px"; + wrapper.style.left = (window.innerWidth - box.width) / 2 + "px"; + var submit = function submit() { + var params = getValues(options.fields, domFields); + if (params) { + close(); + options.callback(params); + } + }; + form.addEventListener("submit", function (e) { + e.preventDefault(); + submit(); + }); + form.addEventListener("keydown", function (e) { + if (e.keyCode == 27) { + e.preventDefault(); + close(); + } else if (e.keyCode == 13 && !(e.ctrlKey || e.metaKey || e.shiftKey)) { + e.preventDefault(); + submit(); + } else if (e.keyCode == 9) { + window.setTimeout(function () { + if (!wrapper.contains(document.activeElement)) close(); + }, 500); + } + }); + var input = form.elements[0]; + if (input) input.focus(); +} +function getValues(fields, domFields) { + var result = Object.create(null), + i = 0; + for (var name in fields) { + var field = fields[name], + dom = domFields[i++]; + var value = field.read(dom), + bad = field.validate(value); + if (bad) { + reportInvalid(dom, bad); + return null; + } + result[name] = field.clean(value); + } + return result; +} +function reportInvalid(dom, message) { + var parent = dom.parentNode; + var msg = parent.appendChild(document.createElement("div")); + msg.style.left = dom.offsetLeft + dom.offsetWidth + 2 + "px"; + msg.style.top = dom.offsetTop - 5 + "px"; + msg.className = "ProseMirror-invalid"; + msg.textContent = message; + setTimeout(function () { + return parent.removeChild(msg); + }, 1500); +} +var Field = function () { + function Field(options) { + _classCallCheck(this, Field); + this.options = options; + } + _createClass(Field, [{ + key: "read", + value: function read(dom) { + return dom.value; + } + }, { + key: "validateType", + value: function validateType(value) { + return null; + } + }, { + key: "validate", + value: function validate(value) { + if (!value && this.options.required) return "Required field"; + return this.validateType(value) || (this.options.validate ? this.options.validate(value) : null); + } + }, { + key: "clean", + value: function clean(value) { + return this.options.clean ? this.options.clean(value) : value; + } + }]); + return Field; +}(); +var TextField = function (_Field) { + _inherits(TextField, _Field); + var _super = _createSuper(TextField); + function TextField() { + _classCallCheck(this, TextField); + return _super.apply(this, arguments); + } + _createClass(TextField, [{ + key: "render", + value: function render() { + var input = document.createElement("input"); + input.type = "text"; + input.placeholder = this.options.label; + input.value = this.options.value || ""; + input.autocomplete = "off"; + return input; + } + }]); + return TextField; +}(Field); +function canInsert(state, nodeType) { + var $from = state.selection.$from; + for (var d = $from.depth; d >= 0; d--) { + var index = $from.index(d); + if ($from.node(d).canReplaceWith(index, index, nodeType)) return true; + } + return false; +} +function insertImageItem(nodeType) { + return new prosemirrorMenu.MenuItem({ + title: "Insert image", + label: "Image", + enable: function enable(state) { + return canInsert(state, nodeType); + }, + run: function run(state, _, view) { + var _state$selection = state.selection, + from = _state$selection.from, + to = _state$selection.to, + attrs = null; + if (state.selection instanceof prosemirrorState.NodeSelection && state.selection.node.type == nodeType) attrs = state.selection.node.attrs; + openPrompt({ + title: "Insert image", + fields: { + src: new TextField({ + label: "Location", + required: true, + value: attrs && attrs.src + }), + title: new TextField({ + label: "Title", + value: attrs && attrs.title + }), + alt: new TextField({ + label: "Description", + value: attrs ? attrs.alt : state.doc.textBetween(from, to, " ") + }) + }, + callback: function callback(attrs) { + view.dispatch(view.state.tr.replaceSelectionWith(nodeType.createAndFill(attrs))); + view.focus(); + } + }); + } + }); +} +function cmdItem(cmd, options) { + var passedOptions = { + label: options.title, + run: cmd + }; + for (var prop in options) passedOptions[prop] = options[prop]; + if (!options.enable && !options.select) passedOptions[options.enable ? "enable" : "select"] = function (state) { + return cmd(state); + }; + return new prosemirrorMenu.MenuItem(passedOptions); +} +function markActive(state, type) { + var _state$selection2 = state.selection, + from = _state$selection2.from, + $from = _state$selection2.$from, + to = _state$selection2.to, + empty = _state$selection2.empty; + if (empty) return !!type.isInSet(state.storedMarks || $from.marks());else return state.doc.rangeHasMark(from, to, type); +} +function markItem(markType, options) { + var passedOptions = { + active: function active(state) { + return markActive(state, markType); + } + }; + for (var prop in options) passedOptions[prop] = options[prop]; + return cmdItem(prosemirrorCommands.toggleMark(markType), passedOptions); +} +function linkItem(markType) { + return new prosemirrorMenu.MenuItem({ + title: "Add or remove link", + icon: prosemirrorMenu.icons.link, + active: function active(state) { + return markActive(state, markType); + }, + enable: function enable(state) { + return !state.selection.empty; + }, + run: function run(state, dispatch, view) { + if (markActive(state, markType)) { + prosemirrorCommands.toggleMark(markType)(state, dispatch); + return true; + } + openPrompt({ + title: "Create a link", + fields: { + href: new TextField({ + label: "Link target", + required: true + }), + title: new TextField({ + label: "Title" + }) + }, + callback: function callback(attrs) { + prosemirrorCommands.toggleMark(markType, attrs)(view.state, view.dispatch); + view.focus(); + } + }); + } + }); +} +function wrapListItem(nodeType, options) { + return cmdItem(prosemirrorSchemaList.wrapInList(nodeType, options.attrs), options); +} +function buildMenuItems(schema) { + var r = {}; + var mark; + if (mark = schema.marks.strong) r.toggleStrong = markItem(mark, { + title: "Toggle strong style", + icon: prosemirrorMenu.icons.strong + }); + if (mark = schema.marks.em) r.toggleEm = markItem(mark, { + title: "Toggle emphasis", + icon: prosemirrorMenu.icons.em + }); + if (mark = schema.marks.code) r.toggleCode = markItem(mark, { + title: "Toggle code font", + icon: prosemirrorMenu.icons.code + }); + if (mark = schema.marks.link) r.toggleLink = linkItem(mark); + var node; + if (node = schema.nodes.image) r.insertImage = insertImageItem(node); + if (node = schema.nodes.bullet_list) r.wrapBulletList = wrapListItem(node, { + title: "Wrap in bullet list", + icon: prosemirrorMenu.icons.bulletList + }); + if (node = schema.nodes.ordered_list) r.wrapOrderedList = wrapListItem(node, { + title: "Wrap in ordered list", + icon: prosemirrorMenu.icons.orderedList + }); + if (node = schema.nodes.blockquote) r.wrapBlockQuote = prosemirrorMenu.wrapItem(node, { + title: "Wrap in block quote", + icon: prosemirrorMenu.icons.blockquote + }); + if (node = schema.nodes.paragraph) r.makeParagraph = prosemirrorMenu.blockTypeItem(node, { + title: "Change to paragraph", + label: "Plain" + }); + if (node = schema.nodes.code_block) r.makeCodeBlock = prosemirrorMenu.blockTypeItem(node, { + title: "Change to code block", + label: "Code" + }); + if (node = schema.nodes.heading) for (var i = 1; i <= 10; i++) r["makeHead" + i] = prosemirrorMenu.blockTypeItem(node, { + title: "Change to heading " + i, + label: "Level " + i, + attrs: { + level: i + } + }); + if (node = schema.nodes.horizontal_rule) { + var hr = node; + r.insertHorizontalRule = new prosemirrorMenu.MenuItem({ + title: "Insert horizontal rule", + label: "Horizontal rule", + enable: function enable(state) { + return canInsert(state, hr); + }, + run: function run(state, dispatch) { + dispatch(state.tr.replaceSelectionWith(hr.create())); + } + }); + } + var cut = function cut(arr) { + return arr.filter(function (x) { + return x; + }); + }; + r.insertMenu = new prosemirrorMenu.Dropdown(cut([r.insertImage, r.insertHorizontalRule]), { + label: "Insert" + }); + r.typeMenu = new prosemirrorMenu.Dropdown(cut([r.makeParagraph, r.makeCodeBlock, r.makeHead1 && new prosemirrorMenu.DropdownSubmenu(cut([r.makeHead1, r.makeHead2, r.makeHead3, r.makeHead4, r.makeHead5, r.makeHead6]), { + label: "Heading" + })]), { + label: "Type..." + }); + r.inlineMenu = [cut([r.toggleStrong, r.toggleEm, r.toggleCode, r.toggleLink])]; + r.blockMenu = [cut([r.wrapBulletList, r.wrapOrderedList, r.wrapBlockQuote, prosemirrorMenu.joinUpItem, prosemirrorMenu.liftItem, prosemirrorMenu.selectParentNodeItem])]; + r.fullMenu = r.inlineMenu.concat([[r.insertMenu, r.typeMenu]], [[prosemirrorMenu.undoItem, prosemirrorMenu.redoItem]], r.blockMenu); + return r; +} +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false; +function buildKeymap(schema, mapKeys) { + var keys = {}, + type; + function bind(key, cmd) { + if (mapKeys) { + var mapped = mapKeys[key]; + if (mapped === false) return; + if (mapped) key = mapped; + } + keys[key] = cmd; + } + bind("Mod-z", prosemirrorHistory.undo); + bind("Shift-Mod-z", prosemirrorHistory.redo); + bind("Backspace", prosemirrorInputrules.undoInputRule); + if (!mac) bind("Mod-y", prosemirrorHistory.redo); + bind("Alt-ArrowUp", prosemirrorCommands.joinUp); + bind("Alt-ArrowDown", prosemirrorCommands.joinDown); + bind("Mod-BracketLeft", prosemirrorCommands.lift); + bind("Escape", prosemirrorCommands.selectParentNode); + if (type = schema.marks.strong) { + bind("Mod-b", prosemirrorCommands.toggleMark(type)); + bind("Mod-B", prosemirrorCommands.toggleMark(type)); + } + if (type = schema.marks.em) { + bind("Mod-i", prosemirrorCommands.toggleMark(type)); + bind("Mod-I", prosemirrorCommands.toggleMark(type)); + } + if (type = schema.marks.code) bind("Mod-`", prosemirrorCommands.toggleMark(type)); + if (type = schema.nodes.bullet_list) bind("Shift-Ctrl-8", prosemirrorSchemaList.wrapInList(type)); + if (type = schema.nodes.ordered_list) bind("Shift-Ctrl-9", prosemirrorSchemaList.wrapInList(type)); + if (type = schema.nodes.blockquote) bind("Ctrl->", prosemirrorCommands.wrapIn(type)); + if (type = schema.nodes.hard_break) { + var br = type, + cmd = prosemirrorCommands.chainCommands(prosemirrorCommands.exitCode, function (state, dispatch) { + if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView()); + return true; + }); + bind("Mod-Enter", cmd); + bind("Shift-Enter", cmd); + if (mac) bind("Ctrl-Enter", cmd); + } + if (type = schema.nodes.list_item) { + bind("Enter", prosemirrorSchemaList.splitListItem(type)); + bind("Mod-[", prosemirrorSchemaList.liftListItem(type)); + bind("Mod-]", prosemirrorSchemaList.sinkListItem(type)); + } + if (type = schema.nodes.paragraph) bind("Shift-Ctrl-0", prosemirrorCommands.setBlockType(type)); + if (type = schema.nodes.code_block) bind("Shift-Ctrl-\\", prosemirrorCommands.setBlockType(type)); + if (type = schema.nodes.heading) for (var i = 1; i <= 6; i++) bind("Shift-Ctrl-" + i, prosemirrorCommands.setBlockType(type, { + level: i + })); + if (type = schema.nodes.horizontal_rule) { + var hr = type; + bind("Mod-_", function (state, dispatch) { + if (dispatch) dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView()); + return true; + }); + } + return keys; +} +function blockQuoteRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^\s*>\s$/, nodeType); +} +function orderedListRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^(\d+)\.\s$/, nodeType, function (match) { + return { + order: +match[1] + }; + }, function (match, node) { + return node.childCount + node.attrs.order == +match[1]; + }); +} +function bulletListRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^\s*([-+*])\s$/, nodeType); +} +function codeBlockRule(nodeType) { + return prosemirrorInputrules.textblockTypeInputRule(/^```$/, nodeType); +} +function headingRule(nodeType, maxLevel) { + return prosemirrorInputrules.textblockTypeInputRule(new RegExp("^(#{1," + maxLevel + "})\\s$"), nodeType, function (match) { + return { + level: match[1].length + }; + }); +} +function buildInputRules(schema) { + var rules = prosemirrorInputrules.smartQuotes.concat(prosemirrorInputrules.ellipsis, prosemirrorInputrules.emDash), + type; + if (type = schema.nodes.blockquote) rules.push(blockQuoteRule(type)); + if (type = schema.nodes.ordered_list) rules.push(orderedListRule(type)); + if (type = schema.nodes.bullet_list) rules.push(bulletListRule(type)); + if (type = schema.nodes.code_block) rules.push(codeBlockRule(type)); + if (type = schema.nodes.heading) rules.push(headingRule(type, 6)); + return prosemirrorInputrules.inputRules({ + rules: rules + }); +} +function exampleSetup(options) { + var plugins = [buildInputRules(options.schema), prosemirrorKeymap.keymap(buildKeymap(options.schema, options.mapKeys)), prosemirrorKeymap.keymap(prosemirrorCommands.baseKeymap), prosemirrorDropcursor.dropCursor(), prosemirrorGapcursor.gapCursor()]; + if (options.menuBar !== false) plugins.push(prosemirrorMenu.menuBar({ + floating: options.floatingMenu !== false, + content: options.menuContent || buildMenuItems(options.schema).fullMenu + })); + if (options.history !== false) plugins.push(prosemirrorHistory.history()); + return plugins.concat(new prosemirrorState.Plugin({ + props: { + attributes: { + "class": "ProseMirror-example-setup-style" + } + } + })); +} +exports.buildInputRules = buildInputRules; +exports.buildKeymap = buildKeymap; +exports.buildMenuItems = buildMenuItems; +exports.exampleSetup = exampleSetup; + +}); +define("prosemirror-gapcursor",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorKeymap = require('prosemirror-keymap'); + +var prosemirrorState = require('prosemirror-state'); + +var prosemirrorModel = require('prosemirror-model'); + +var prosemirrorView = require('prosemirror-view'); + +var GapCursor = function (_prosemirrorState$Sel) { + _inherits(GapCursor, _prosemirrorState$Sel); + + var _super = _createSuper(GapCursor); + + function GapCursor($pos) { + _classCallCheck(this, GapCursor); + + return _super.call(this, $pos, $pos); + } + + _createClass(GapCursor, [{ + key: "map", + value: function map(doc, mapping) { + var $pos = doc.resolve(mapping.map(this.head)); + return GapCursor.valid($pos) ? new GapCursor($pos) : prosemirrorState.Selection.near($pos); + } + }, { + key: "content", + value: function content() { + return prosemirrorModel.Slice.empty; + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof GapCursor && other.head == this.head; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "gapcursor", + pos: this.head + }; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new GapBookmark(this.anchor); + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for GapCursor.fromJSON"); + return new GapCursor(doc.resolve(json.pos)); + } + }, { + key: "valid", + value: function valid($pos) { + var parent = $pos.parent; + if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos)) return false; + var override = parent.type.spec.allowGapCursor; + if (override != null) return override; + var deflt = parent.contentMatchAt($pos.index()).defaultType; + return deflt && deflt.isTextblock; + } + }, { + key: "findGapCursorFrom", + value: function findGapCursorFrom($pos, dir) { + var mustMove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + search: for (;;) { + if (!mustMove && GapCursor.valid($pos)) return $pos; + var pos = $pos.pos, + next = null; + + for (var d = $pos.depth;; d--) { + var parent = $pos.node(d); + + if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) { + next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1); + break; + } else if (d == 0) { + return null; + } + + pos += dir; + var $cur = $pos.doc.resolve(pos); + if (GapCursor.valid($cur)) return $cur; + } + + for (;;) { + var inside = dir > 0 ? next.firstChild : next.lastChild; + + if (!inside) { + if (next.isAtom && !next.isText && !prosemirrorState.NodeSelection.isSelectable(next)) { + $pos = $pos.doc.resolve(pos + next.nodeSize * dir); + mustMove = false; + continue search; + } + + break; + } + + next = inside; + pos += dir; + + var _$cur = $pos.doc.resolve(pos); + + if (GapCursor.valid(_$cur)) return _$cur; + } + + return null; + } + } + }]); + + return GapCursor; +}(prosemirrorState.Selection); + +GapCursor.prototype.visible = false; +GapCursor.findFrom = GapCursor.findGapCursorFrom; +prosemirrorState.Selection.jsonID("gapcursor", GapCursor); + +var GapBookmark = function () { + function GapBookmark(pos) { + _classCallCheck(this, GapBookmark); + + this.pos = pos; + } + + _createClass(GapBookmark, [{ + key: "map", + value: function map(mapping) { + return new GapBookmark(mapping.map(this.pos)); + } + }, { + key: "resolve", + value: function resolve(doc) { + var $pos = doc.resolve(this.pos); + return GapCursor.valid($pos) ? new GapCursor($pos) : prosemirrorState.Selection.near($pos); + } + }]); + + return GapBookmark; +}(); + +function closedBefore($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.index(d), + parent = $pos.node(d); + + if (index == 0) { + if (parent.type.spec.isolating) return true; + continue; + } + + for (var before = parent.child(index - 1);; before = before.lastChild) { + if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating) return true; + if (before.inlineContent) return false; + } + } + + return true; +} + +function closedAfter($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.indexAfter(d), + parent = $pos.node(d); + + if (index == parent.childCount) { + if (parent.type.spec.isolating) return true; + continue; + } + + for (var after = parent.child(index);; after = after.firstChild) { + if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating) return true; + if (after.inlineContent) return false; + } + } + + return true; +} + +function gapCursor() { + return new prosemirrorState.Plugin({ + props: { + decorations: drawGapCursor, + createSelectionBetween: function createSelectionBetween(_view, $anchor, $head) { + return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null; + }, + handleClick: handleClick, + handleKeyDown: handleKeyDown, + handleDOMEvents: { + beforeinput: beforeinput + } + } + }); +} + +var handleKeyDown = prosemirrorKeymap.keydownHandler({ + "ArrowLeft": arrow("horiz", -1), + "ArrowRight": arrow("horiz", 1), + "ArrowUp": arrow("vert", -1), + "ArrowDown": arrow("vert", 1) +}); + +function arrow(axis, dir) { + var dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left"; + return function (state, dispatch, view) { + var sel = state.selection; + var $start = dir > 0 ? sel.$to : sel.$from, + mustMove = sel.empty; + + if (sel instanceof prosemirrorState.TextSelection) { + if (!view.endOfTextblock(dirStr) || $start.depth == 0) return false; + mustMove = false; + $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before()); + } + + var $found = GapCursor.findGapCursorFrom($start, dir, mustMove); + if (!$found) return false; + if (dispatch) dispatch(state.tr.setSelection(new GapCursor($found))); + return true; + }; +} + +function handleClick(view, pos, event) { + if (!view || !view.editable) return false; + var $pos = view.state.doc.resolve(pos); + if (!GapCursor.valid($pos)) return false; + var clickPos = view.posAtCoords({ + left: event.clientX, + top: event.clientY + }); + if (clickPos && clickPos.inside > -1 && prosemirrorState.NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside))) return false; + view.dispatch(view.state.tr.setSelection(new GapCursor($pos))); + return true; +} + +function beforeinput(view, event) { + if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor)) return false; + var $from = view.state.selection.$from; + var insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text); + if (!insert) return false; + var frag = prosemirrorModel.Fragment.empty; + + for (var i = insert.length - 1; i >= 0; i--) { + frag = prosemirrorModel.Fragment.from(insert[i].createAndFill(null, frag)); + } + + var tr = view.state.tr.replace($from.pos, $from.pos, new prosemirrorModel.Slice(frag, 0, 0)); + tr.setSelection(prosemirrorState.TextSelection.near(tr.doc.resolve($from.pos + 1))); + view.dispatch(tr); + return false; +} + +function drawGapCursor(state) { + if (!(state.selection instanceof GapCursor)) return null; + var node = document.createElement("div"); + node.className = "ProseMirror-gapcursor"; + return prosemirrorView.DecorationSet.create(state.doc, [prosemirrorView.Decoration.widget(state.selection.head, node, { + key: "gapcursor" + })]); +} + +exports.GapCursor = GapCursor; +exports.gapCursor = gapCursor; + +}); +define("prosemirror-history",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var RopeSequence = require('rope-sequence'); +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorState = require('prosemirror-state'); +var max_empty_items = 500; +var Branch = function () { + function Branch(items, eventCount) { + _classCallCheck(this, Branch); + this.items = items; + this.eventCount = eventCount; + } + _createClass(Branch, [{ + key: "popEvent", + value: function popEvent(state, preserveItems) { + var _this = this; + if (this.eventCount == 0) return null; + var end = this.items.length; + for (;; end--) { + var next = this.items.get(end - 1); + if (next.selection) { + --end; + break; + } + } + var remap, mapFrom; + if (preserveItems) { + remap = this.remapping(end, this.items.length); + mapFrom = remap.maps.length; + } + var transform = state.tr; + var selection, remaining; + var addAfter = [], + addBefore = []; + this.items.forEach(function (item, i) { + if (!item.step) { + if (!remap) { + remap = _this.remapping(end, i + 1); + mapFrom = remap.maps.length; + } + mapFrom--; + addBefore.push(item); + return; + } + if (remap) { + addBefore.push(new Item(item.map)); + var step = item.step.map(remap.slice(mapFrom)), + map; + if (step && transform.maybeStep(step).doc) { + map = transform.mapping.maps[transform.mapping.maps.length - 1]; + addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length)); + } + mapFrom--; + if (map) remap.appendMap(map, mapFrom); + } else { + transform.maybeStep(item.step); + } + if (item.selection) { + selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection; + remaining = new Branch(_this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), _this.eventCount - 1); + return false; + } + }, this.items.length, 0); + return { + remaining: remaining, + transform: transform, + selection: selection + }; + } + }, { + key: "addTransform", + value: function addTransform(transform, selection, histOptions, preserveItems) { + var newItems = [], + eventCount = this.eventCount; + var oldItems = this.items, + lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null; + for (var i = 0; i < transform.steps.length; i++) { + var step = transform.steps[i].invert(transform.docs[i]); + var item = new Item(transform.mapping.maps[i], step, selection), + merged = void 0; + if (merged = lastItem && lastItem.merge(item)) { + item = merged; + if (i) newItems.pop();else oldItems = oldItems.slice(0, oldItems.length - 1); + } + newItems.push(item); + if (selection) { + eventCount++; + selection = undefined; + } + if (!preserveItems) lastItem = item; + } + var overflow = eventCount - histOptions.depth; + if (overflow > DEPTH_OVERFLOW) { + oldItems = cutOffEvents(oldItems, overflow); + eventCount -= overflow; + } + return new Branch(oldItems.append(newItems), eventCount); + } + }, { + key: "remapping", + value: function remapping(from, to) { + var maps = new prosemirrorTransform.Mapping(); + this.items.forEach(function (item, i) { + var mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from ? maps.maps.length - item.mirrorOffset : undefined; + maps.appendMap(item.map, mirrorPos); + }, from, to); + return maps; + } + }, { + key: "addMaps", + value: function addMaps(array) { + if (this.eventCount == 0) return this; + return new Branch(this.items.append(array.map(function (map) { + return new Item(map); + })), this.eventCount); + } + }, { + key: "rebased", + value: function rebased(rebasedTransform, rebasedCount) { + if (!this.eventCount) return this; + var rebasedItems = [], + start = Math.max(0, this.items.length - rebasedCount); + var mapping = rebasedTransform.mapping; + var newUntil = rebasedTransform.steps.length; + var eventCount = this.eventCount; + this.items.forEach(function (item) { + if (item.selection) eventCount--; + }, start); + var iRebased = rebasedCount; + this.items.forEach(function (item) { + var pos = mapping.getMirror(--iRebased); + if (pos == null) return; + newUntil = Math.min(newUntil, pos); + var map = mapping.maps[pos]; + if (item.step) { + var step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]); + var selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos)); + if (selection) eventCount++; + rebasedItems.push(new Item(map, step, selection)); + } else { + rebasedItems.push(new Item(map)); + } + }, start); + var newMaps = []; + for (var i = rebasedCount; i < newUntil; i++) newMaps.push(new Item(mapping.maps[i])); + var items = this.items.slice(0, start).append(newMaps).append(rebasedItems); + var branch = new Branch(items, eventCount); + if (branch.emptyItemCount() > max_empty_items) branch = branch.compress(this.items.length - rebasedItems.length); + return branch; + } + }, { + key: "emptyItemCount", + value: function emptyItemCount() { + var count = 0; + this.items.forEach(function (item) { + if (!item.step) count++; + }); + return count; + } + }, { + key: "compress", + value: function compress() { + var upto = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items.length; + var remap = this.remapping(0, upto), + mapFrom = remap.maps.length; + var items = [], + events = 0; + this.items.forEach(function (item, i) { + if (i >= upto) { + items.push(item); + if (item.selection) events++; + } else if (item.step) { + var step = item.step.map(remap.slice(mapFrom)), + map = step && step.getMap(); + mapFrom--; + if (map) remap.appendMap(map, mapFrom); + if (step) { + var selection = item.selection && item.selection.map(remap.slice(mapFrom)); + if (selection) events++; + var newItem = new Item(map.invert(), step, selection), + merged, + last = items.length - 1; + if (merged = items.length && items[last].merge(newItem)) items[last] = merged;else items.push(newItem); + } + } else if (item.map) { + mapFrom--; + } + }, this.items.length, 0); + return new Branch(RopeSequence.from(items.reverse()), events); + } + }]); + return Branch; +}(); +Branch.empty = new Branch(RopeSequence.empty, 0); +function cutOffEvents(items, n) { + var cutPoint; + items.forEach(function (item, i) { + if (item.selection && n-- == 0) { + cutPoint = i; + return false; + } + }); + return items.slice(cutPoint); +} +var Item = function () { + function Item(map, step, selection, mirrorOffset) { + _classCallCheck(this, Item); + this.map = map; + this.step = step; + this.selection = selection; + this.mirrorOffset = mirrorOffset; + } + _createClass(Item, [{ + key: "merge", + value: function merge(other) { + if (this.step && other.step && !other.selection) { + var step = other.step.merge(this.step); + if (step) return new Item(step.getMap().invert(), step, this.selection); + } + } + }]); + return Item; +}(); +var HistoryState = _createClass(function HistoryState(done, undone, prevRanges, prevTime, prevComposition) { + _classCallCheck(this, HistoryState); + this.done = done; + this.undone = undone; + this.prevRanges = prevRanges; + this.prevTime = prevTime; + this.prevComposition = prevComposition; +}); +var DEPTH_OVERFLOW = 20; +function applyTransaction(history, state, tr, options) { + var historyTr = tr.getMeta(historyKey), + rebased; + if (historyTr) return historyTr.historyState; + if (tr.getMeta(closeHistoryKey)) history = new HistoryState(history.done, history.undone, null, 0, -1); + var appended = tr.getMeta("appendedTransaction"); + if (tr.steps.length == 0) { + return history; + } else if (appended && appended.getMeta(historyKey)) { + if (appended.getMeta(historyKey).redo) return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);else return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition); + } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) { + var composition = tr.getMeta("composition"); + var newGroup = history.prevTime == 0 || !appended && history.prevComposition != composition && (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges)); + var prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps); + return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition); + } else if (rebased = tr.getMeta("rebased")) { + return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition); + } else { + return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition); + } +} +function isAdjacentTo(transform, prevRanges) { + if (!prevRanges) return false; + if (!transform.docChanged) return true; + var adjacent = false; + transform.mapping.maps[0].forEach(function (start, end) { + for (var i = 0; i < prevRanges.length; i += 2) if (start <= prevRanges[i + 1] && end >= prevRanges[i]) adjacent = true; + }); + return adjacent; +} +function rangesFor(maps) { + var result = []; + for (var i = maps.length - 1; i >= 0 && result.length == 0; i--) maps[i].forEach(function (_from, _to, from, to) { + return result.push(from, to); + }); + return result; +} +function mapRanges(ranges, mapping) { + if (!ranges) return null; + var result = []; + for (var i = 0; i < ranges.length; i += 2) { + var from = mapping.map(ranges[i], 1), + to = mapping.map(ranges[i + 1], -1); + if (from <= to) result.push(from, to); + } + return result; +} +function histTransaction(history, state, redo) { + var preserveItems = mustPreserveItems(state); + var histOptions = historyKey.get(state).spec.config; + var pop = (redo ? history.undone : history.done).popEvent(state, preserveItems); + if (!pop) return null; + var selection = pop.selection.resolve(pop.transform.doc); + var added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems); + var newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1); + return pop.transform.setSelection(selection).setMeta(historyKey, { + redo: redo, + historyState: newHist + }); +} +var cachedPreserveItems = false, + cachedPreserveItemsPlugins = null; +function mustPreserveItems(state) { + var plugins = state.plugins; + if (cachedPreserveItemsPlugins != plugins) { + cachedPreserveItems = false; + cachedPreserveItemsPlugins = plugins; + for (var i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) { + cachedPreserveItems = true; + break; + } + } + return cachedPreserveItems; +} +function closeHistory(tr) { + return tr.setMeta(closeHistoryKey, true); +} +var historyKey = new prosemirrorState.PluginKey("history"); +var closeHistoryKey = new prosemirrorState.PluginKey("closeHistory"); +function history() { + var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + config = { + depth: config.depth || 100, + newGroupDelay: config.newGroupDelay || 500 + }; + return new prosemirrorState.Plugin({ + key: historyKey, + state: { + init: function init() { + return new HistoryState(Branch.empty, Branch.empty, null, 0, -1); + }, + apply: function apply(tr, hist, state) { + return applyTransaction(hist, state, tr, config); + } + }, + config: config, + props: { + handleDOMEvents: { + beforeinput: function beforeinput(view, e) { + var inputType = e.inputType; + var command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null; + if (!command) return false; + e.preventDefault(); + return command(view.state, view.dispatch); + } + } + } + }); +} +function buildCommand(redo, scroll) { + return function (state, dispatch) { + var hist = historyKey.getState(state); + if (!hist || (redo ? hist.undone : hist.done).eventCount == 0) return false; + if (dispatch) { + var tr = histTransaction(hist, state, redo); + if (tr) dispatch(scroll ? tr.scrollIntoView() : tr); + } + return true; + }; +} +var undo = buildCommand(false, true); +var redo = buildCommand(true, true); +var undoNoScroll = buildCommand(false, false); +var redoNoScroll = buildCommand(true, false); +function undoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.done.eventCount : 0; +} +function redoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.undone.eventCount : 0; +} +exports.closeHistory = closeHistory; +exports.history = history; +exports.redo = redo; +exports.redoDepth = redoDepth; +exports.redoNoScroll = redoNoScroll; +exports.undo = undo; +exports.undoDepth = undoDepth; +exports.undoNoScroll = undoNoScroll; + +}); +define("prosemirror-inputrules",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var prosemirrorState = require('prosemirror-state'); +var prosemirrorTransform = require('prosemirror-transform'); +var InputRule = _createClass(function InputRule(match, handler) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + _classCallCheck(this, InputRule); + this.match = match; + this.match = match; + this.handler = typeof handler == "string" ? stringHandler(handler) : handler; + this.undoable = options.undoable !== false; + this.inCode = options.inCode || false; +}); +function stringHandler(string) { + return function (state, match, start, end) { + var insert = string; + if (match[1]) { + var offset = match[0].lastIndexOf(match[1]); + insert += match[0].slice(offset + match[1].length); + start += offset; + var cutOff = start - end; + if (cutOff > 0) { + insert = match[0].slice(offset - cutOff, offset) + insert; + start = end; + } + } + return state.tr.insertText(insert, start, end); + }; +} +var MAX_MATCH = 500; +function inputRules(_ref) { + var rules = _ref.rules; + var plugin = new prosemirrorState.Plugin({ + state: { + init: function init() { + return null; + }, + apply: function apply(tr, prev) { + var stored = tr.getMeta(this); + if (stored) return stored; + return tr.selectionSet || tr.docChanged ? null : prev; + } + }, + props: { + handleTextInput: function handleTextInput(view, from, to, text) { + return run(view, from, to, text, rules, plugin); + }, + handleDOMEvents: { + compositionend: function compositionend(view) { + setTimeout(function () { + var $cursor = view.state.selection.$cursor; + if ($cursor) run(view, $cursor.pos, $cursor.pos, "", rules, plugin); + }); + } + } + }, + isInputRules: true + }); + return plugin; +} +function run(view, from, to, text, rules, plugin) { + if (view.composing) return false; + var state = view.state, + $from = state.doc.resolve(from); + var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, "\uFFFC") + text; + for (var i = 0; i < rules.length; i++) { + var rule = rules[i]; + if ($from.parent.type.spec.code) { + if (!rule.inCode) continue; + } else if (rule.inCode === "only") { + continue; + } + var match = rule.match.exec(textBefore); + var tr = match && rule.handler(state, match, from - (match[0].length - text.length), to); + if (!tr) continue; + if (rule.undoable) tr.setMeta(plugin, { + transform: tr, + from: from, + to: to, + text: text + }); + view.dispatch(tr); + return true; + } + return false; +} +var undoInputRule = function undoInputRule(state, dispatch) { + var plugins = state.plugins; + for (var i = 0; i < plugins.length; i++) { + var plugin = plugins[i], + undoable = void 0; + if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) { + if (dispatch) { + var tr = state.tr, + toUndo = undoable.transform; + for (var j = toUndo.steps.length - 1; j >= 0; j--) tr.step(toUndo.steps[j].invert(toUndo.docs[j])); + if (undoable.text) { + var marks = tr.doc.resolve(undoable.from).marks(); + tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks)); + } else { + tr["delete"](undoable.from, undoable.to); + } + dispatch(tr); + } + return true; + } + } + return false; +}; +var emDash = new InputRule(/--$/, "—"); +var ellipsis = new InputRule(/\.\.\.$/, "…"); +var openDoubleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/, "“"); +var closeDoubleQuote = new InputRule(/"$/, "”"); +var openSingleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/, "‘"); +var closeSingleQuote = new InputRule(/'$/, "’"); +var smartQuotes = [openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote]; +function wrappingInputRule(regexp, nodeType) { + var getAttrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var joinPredicate = arguments.length > 3 ? arguments[3] : undefined; + return new InputRule(regexp, function (state, match, start, end) { + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + var tr = state.tr["delete"](start, end); + var $start = tr.doc.resolve(start), + range = $start.blockRange(), + wrapping = range && prosemirrorTransform.findWrapping(range, nodeType, attrs); + if (!wrapping) return null; + tr.wrap(range, wrapping); + var before = tr.doc.resolve(start - 1).nodeBefore; + if (before && before.type == nodeType && prosemirrorTransform.canJoin(tr.doc, start - 1) && (!joinPredicate || joinPredicate(match, before))) tr.join(start - 1); + return tr; + }); +} +function textblockTypeInputRule(regexp, nodeType) { + var getAttrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + return new InputRule(regexp, function (state, match, start, end) { + var $start = state.doc.resolve(start); + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) return null; + return state.tr["delete"](start, end).setBlockType(start, start, nodeType, attrs); + }); +} +exports.InputRule = InputRule; +exports.closeDoubleQuote = closeDoubleQuote; +exports.closeSingleQuote = closeSingleQuote; +exports.ellipsis = ellipsis; +exports.emDash = emDash; +exports.inputRules = inputRules; +exports.openDoubleQuote = openDoubleQuote; +exports.openSingleQuote = openSingleQuote; +exports.smartQuotes = smartQuotes; +exports.textblockTypeInputRule = textblockTypeInputRule; +exports.undoInputRule = undoInputRule; +exports.wrappingInputRule = wrappingInputRule; + +}); +define("prosemirror-keymap",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var w3cKeyname = require('w3c-keyname'); + +var prosemirrorState = require('prosemirror-state'); + +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false; + +function normalizeKeyName(name) { + var parts = name.split(/-(?!$)/), + result = parts[parts.length - 1]; + if (result == "Space") result = " "; + var alt, ctrl, shift, meta; + + for (var i = 0; i < parts.length - 1; i++) { + var mod = parts[i]; + if (/^(cmd|meta|m)$/i.test(mod)) meta = true;else if (/^a(lt)?$/i.test(mod)) alt = true;else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;else if (/^s(hift)?$/i.test(mod)) shift = true;else if (/^mod$/i.test(mod)) { + if (mac) meta = true;else ctrl = true; + } else throw new Error("Unrecognized modifier name: " + mod); + } + + if (alt) result = "Alt-" + result; + if (ctrl) result = "Ctrl-" + result; + if (meta) result = "Meta-" + result; + if (shift) result = "Shift-" + result; + return result; +} + +function normalize(map) { + var copy = Object.create(null); + + for (var prop in map) { + copy[normalizeKeyName(prop)] = map[prop]; + } + + return copy; +} + +function modifiers(name, event) { + var shift = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + if (event.altKey) name = "Alt-" + name; + if (event.ctrlKey) name = "Ctrl-" + name; + if (event.metaKey) name = "Meta-" + name; + if (shift && event.shiftKey) name = "Shift-" + name; + return name; +} + +function keymap(bindings) { + return new prosemirrorState.Plugin({ + props: { + handleKeyDown: keydownHandler(bindings) + } + }); +} + +function keydownHandler(bindings) { + var map = normalize(bindings); + return function (view, event) { + var name = w3cKeyname.keyName(event), + baseName, + direct = map[modifiers(name, event)]; + if (direct && direct(view.state, view.dispatch, view)) return true; + + if (name.length == 1 && name != " ") { + if (event.shiftKey) { + var noShift = map[modifiers(name, event, false)]; + if (noShift && noShift(view.state, view.dispatch, view)) return true; + } + + if ((event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && (baseName = w3cKeyname.base[event.keyCode]) && baseName != name) { + var fromCode = map[modifiers(baseName, event)]; + if (fromCode && fromCode(view.state, view.dispatch, view)) return true; + } + } + + return false; + }; +} + +exports.keydownHandler = keydownHandler; +exports.keymap = keymap; + +}); +define("prosemirror-markdown",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorModel = require('prosemirror-model'); +var MarkdownIt = require('markdown-it'); +var schema = new prosemirrorModel.Schema({ + nodes: { + doc: { + content: "block+" + }, + paragraph: { + content: "inline*", + group: "block", + parseDOM: [{ + tag: "p" + }], + toDOM: function toDOM() { + return ["p", 0]; + } + }, + blockquote: { + content: "block+", + group: "block", + parseDOM: [{ + tag: "blockquote" + }], + toDOM: function toDOM() { + return ["blockquote", 0]; + } + }, + horizontal_rule: { + group: "block", + parseDOM: [{ + tag: "hr" + }], + toDOM: function toDOM() { + return ["div", ["hr"]]; + } + }, + heading: { + attrs: { + level: { + "default": 1 + } + }, + content: "(text | image)*", + group: "block", + defining: true, + parseDOM: [{ + tag: "h1", + attrs: { + level: 1 + } + }, { + tag: "h2", + attrs: { + level: 2 + } + }, { + tag: "h3", + attrs: { + level: 3 + } + }, { + tag: "h4", + attrs: { + level: 4 + } + }, { + tag: "h5", + attrs: { + level: 5 + } + }, { + tag: "h6", + attrs: { + level: 6 + } + }], + toDOM: function toDOM(node) { + return ["h" + node.attrs.level, 0]; + } + }, + code_block: { + content: "text*", + group: "block", + code: true, + defining: true, + marks: "", + attrs: { + params: { + "default": "" + } + }, + parseDOM: [{ + tag: "pre", + preserveWhitespace: "full", + getAttrs: function getAttrs(node) { + return { + params: node.getAttribute("data-params") || "" + }; + } + }], + toDOM: function toDOM(node) { + return ["pre", node.attrs.params ? { + "data-params": node.attrs.params + } : {}, ["code", 0]]; + } + }, + ordered_list: { + content: "list_item+", + group: "block", + attrs: { + order: { + "default": 1 + }, + tight: { + "default": false + } + }, + parseDOM: [{ + tag: "ol", + getAttrs: function getAttrs(dom) { + return { + order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1, + tight: dom.hasAttribute("data-tight") + }; + } + }], + toDOM: function toDOM(node) { + return ["ol", { + start: node.attrs.order == 1 ? null : node.attrs.order, + "data-tight": node.attrs.tight ? "true" : null + }, 0]; + } + }, + bullet_list: { + content: "list_item+", + group: "block", + attrs: { + tight: { + "default": false + } + }, + parseDOM: [{ + tag: "ul", + getAttrs: function getAttrs(dom) { + return { + tight: dom.hasAttribute("data-tight") + }; + } + }], + toDOM: function toDOM(node) { + return ["ul", { + "data-tight": node.attrs.tight ? "true" : null + }, 0]; + } + }, + list_item: { + content: "block+", + defining: true, + parseDOM: [{ + tag: "li" + }], + toDOM: function toDOM() { + return ["li", 0]; + } + }, + text: { + group: "inline" + }, + image: { + inline: true, + attrs: { + src: {}, + alt: { + "default": null + }, + title: { + "default": null + } + }, + group: "inline", + draggable: true, + parseDOM: [{ + tag: "img[src]", + getAttrs: function getAttrs(dom) { + return { + src: dom.getAttribute("src"), + title: dom.getAttribute("title"), + alt: dom.getAttribute("alt") + }; + } + }], + toDOM: function toDOM(node) { + return ["img", node.attrs]; + } + }, + hard_break: { + inline: true, + group: "inline", + selectable: false, + parseDOM: [{ + tag: "br" + }], + toDOM: function toDOM() { + return ["br"]; + } + } + }, + marks: { + em: { + parseDOM: [{ + tag: "i" + }, { + tag: "em" + }, { + style: "font-style=italic" + }, { + style: "font-style=normal", + clearMark: function clearMark(m) { + return m.type.name == "em"; + } + }], + toDOM: function toDOM() { + return ["em"]; + } + }, + strong: { + parseDOM: [{ + tag: "strong" + }, { + tag: "b", + getAttrs: function getAttrs(node) { + return node.style.fontWeight != "normal" && null; + } + }, { + style: "font-weight=400", + clearMark: function clearMark(m) { + return m.type.name == "strong"; + } + }, { + style: "font-weight", + getAttrs: function getAttrs(value) { + return /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null; + } + }], + toDOM: function toDOM() { + return ["strong"]; + } + }, + link: { + attrs: { + href: {}, + title: { + "default": null + } + }, + inclusive: false, + parseDOM: [{ + tag: "a[href]", + getAttrs: function getAttrs(dom) { + return { + href: dom.getAttribute("href"), + title: dom.getAttribute("title") + }; + } + }], + toDOM: function toDOM(node) { + return ["a", node.attrs]; + } + }, + code: { + parseDOM: [{ + tag: "code" + }], + toDOM: function toDOM() { + return ["code"]; + } + } + } +}); +function maybeMerge(a, b) { + if (a.isText && b.isText && prosemirrorModel.Mark.sameSet(a.marks, b.marks)) return a.withText(a.text + b.text); +} +var MarkdownParseState = function () { + function MarkdownParseState(schema, tokenHandlers) { + _classCallCheck(this, MarkdownParseState); + this.schema = schema; + this.tokenHandlers = tokenHandlers; + this.stack = [{ + type: schema.topNodeType, + attrs: null, + content: [], + marks: prosemirrorModel.Mark.none + }]; + } + _createClass(MarkdownParseState, [{ + key: "top", + value: function top() { + return this.stack[this.stack.length - 1]; + } + }, { + key: "push", + value: function push(elt) { + if (this.stack.length) this.top().content.push(elt); + } + }, { + key: "addText", + value: function addText(text) { + if (!text) return; + var top = this.top(), + nodes = top.content, + last = nodes[nodes.length - 1]; + var node = this.schema.text(text, top.marks), + merged; + if (last && (merged = maybeMerge(last, node))) nodes[nodes.length - 1] = merged;else nodes.push(node); + } + }, { + key: "openMark", + value: function openMark(mark) { + var top = this.top(); + top.marks = mark.addToSet(top.marks); + } + }, { + key: "closeMark", + value: function closeMark(mark) { + var top = this.top(); + top.marks = mark.removeFromSet(top.marks); + } + }, { + key: "parseTokens", + value: function parseTokens(toks) { + for (var i = 0; i < toks.length; i++) { + var tok = toks[i]; + var handler = this.tokenHandlers[tok.type]; + if (!handler) throw new Error("Token type `" + tok.type + "` not supported by Markdown parser"); + handler(this, tok, toks, i); + } + } + }, { + key: "addNode", + value: function addNode(type, attrs, content) { + var top = this.top(); + var node = type.createAndFill(attrs, content, top ? top.marks : []); + if (!node) return null; + this.push(node); + return node; + } + }, { + key: "openNode", + value: function openNode(type, attrs) { + this.stack.push({ + type: type, + attrs: attrs, + content: [], + marks: prosemirrorModel.Mark.none + }); + } + }, { + key: "closeNode", + value: function closeNode() { + var info = this.stack.pop(); + return this.addNode(info.type, info.attrs, info.content); + } + }]); + return MarkdownParseState; +}(); +function attrs(spec, token, tokens, i) { + if (spec.getAttrs) return spec.getAttrs(token, tokens, i);else if (spec.attrs instanceof Function) return spec.attrs(token);else return spec.attrs; +} +function noCloseToken(spec, type) { + return spec.noCloseToken || type == "code_inline" || type == "code_block" || type == "fence"; +} +function withoutTrailingNewline(str) { + return str[str.length - 1] == "\n" ? str.slice(0, str.length - 1) : str; +} +function noOp() {} +function tokenHandlers(schema, tokens) { + var handlers = Object.create(null); + var _loop = function _loop() { + var spec = tokens[type]; + if (spec.block) { + var nodeType = schema.nodeType(spec.block); + if (noCloseToken(spec, type)) { + handlers[type] = function (state, tok, tokens, i) { + state.openNode(nodeType, attrs(spec, tok, tokens, i)); + state.addText(withoutTrailingNewline(tok.content)); + state.closeNode(); + }; + } else { + handlers[type + "_open"] = function (state, tok, tokens, i) { + return state.openNode(nodeType, attrs(spec, tok, tokens, i)); + }; + handlers[type + "_close"] = function (state) { + return state.closeNode(); + }; + } + } else if (spec.node) { + var _nodeType = schema.nodeType(spec.node); + handlers[type] = function (state, tok, tokens, i) { + return state.addNode(_nodeType, attrs(spec, tok, tokens, i)); + }; + } else if (spec.mark) { + var markType = schema.marks[spec.mark]; + if (noCloseToken(spec, type)) { + handlers[type] = function (state, tok, tokens, i) { + state.openMark(markType.create(attrs(spec, tok, tokens, i))); + state.addText(withoutTrailingNewline(tok.content)); + state.closeMark(markType); + }; + } else { + handlers[type + "_open"] = function (state, tok, tokens, i) { + return state.openMark(markType.create(attrs(spec, tok, tokens, i))); + }; + handlers[type + "_close"] = function (state) { + return state.closeMark(markType); + }; + } + } else if (spec.ignore) { + if (noCloseToken(spec, type)) { + handlers[type] = noOp; + } else { + handlers[type + "_open"] = noOp; + handlers[type + "_close"] = noOp; + } + } else { + throw new RangeError("Unrecognized parsing spec " + JSON.stringify(spec)); + } + }; + for (var type in tokens) { + _loop(); + } + handlers.text = function (state, tok) { + return state.addText(tok.content); + }; + handlers.inline = function (state, tok) { + return state.parseTokens(tok.children); + }; + handlers.softbreak = handlers.softbreak || function (state) { + return state.addText(" "); + }; + return handlers; +} +var MarkdownParser = function () { + function MarkdownParser(schema, tokenizer, tokens) { + _classCallCheck(this, MarkdownParser); + this.schema = schema; + this.tokenizer = tokenizer; + this.tokens = tokens; + this.tokenHandlers = tokenHandlers(schema, tokens); + } + _createClass(MarkdownParser, [{ + key: "parse", + value: function parse(text) { + var markdownEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var state = new MarkdownParseState(this.schema, this.tokenHandlers), + doc; + state.parseTokens(this.tokenizer.parse(text, markdownEnv)); + do { + doc = state.closeNode(); + } while (state.stack.length); + return doc || this.schema.topNodeType.createAndFill(); + } + }]); + return MarkdownParser; +}(); +function listIsTight(tokens, i) { + while (++i < tokens.length) if (tokens[i].type != "list_item_open") return tokens[i].hidden; + return false; +} +var defaultMarkdownParser = new MarkdownParser(schema, MarkdownIt("commonmark", { + html: false +}), { + blockquote: { + block: "blockquote" + }, + paragraph: { + block: "paragraph" + }, + list_item: { + block: "list_item" + }, + bullet_list: { + block: "bullet_list", + getAttrs: function getAttrs(_, tokens, i) { + return { + tight: listIsTight(tokens, i) + }; + } + }, + ordered_list: { + block: "ordered_list", + getAttrs: function getAttrs(tok, tokens, i) { + return { + order: +tok.attrGet("start") || 1, + tight: listIsTight(tokens, i) + }; + } + }, + heading: { + block: "heading", + getAttrs: function getAttrs(tok) { + return { + level: +tok.tag.slice(1) + }; + } + }, + code_block: { + block: "code_block", + noCloseToken: true + }, + fence: { + block: "code_block", + getAttrs: function getAttrs(tok) { + return { + params: tok.info || "" + }; + }, + noCloseToken: true + }, + hr: { + node: "horizontal_rule" + }, + image: { + node: "image", + getAttrs: function getAttrs(tok) { + return { + src: tok.attrGet("src"), + title: tok.attrGet("title") || null, + alt: tok.children[0] && tok.children[0].content || null + }; + } + }, + hardbreak: { + node: "hard_break" + }, + em: { + mark: "em" + }, + strong: { + mark: "strong" + }, + link: { + mark: "link", + getAttrs: function getAttrs(tok) { + return { + href: tok.attrGet("href"), + title: tok.attrGet("title") || null + }; + } + }, + code_inline: { + mark: "code", + noCloseToken: true + } +}); +var blankMark = { + open: "", + close: "", + mixable: true +}; +var MarkdownSerializer = function () { + function MarkdownSerializer(nodes, marks) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + _classCallCheck(this, MarkdownSerializer); + this.nodes = nodes; + this.marks = marks; + this.options = options; + } + _createClass(MarkdownSerializer, [{ + key: "serialize", + value: function serialize(content) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + options = Object.assign({}, this.options, options); + var state = new MarkdownSerializerState(this.nodes, this.marks, options); + state.renderContent(content); + return state.out; + } + }]); + return MarkdownSerializer; +}(); +var defaultMarkdownSerializer = new MarkdownSerializer({ + blockquote: function blockquote(state, node) { + state.wrapBlock("> ", null, node, function () { + return state.renderContent(node); + }); + }, + code_block: function code_block(state, node) { + var backticks = node.textContent.match(/`{3,}/gm); + var fence = backticks ? backticks.sort().slice(-1)[0] + "`" : "```"; + state.write(fence + (node.attrs.params || "") + "\n"); + state.text(node.textContent, false); + state.write("\n"); + state.write(fence); + state.closeBlock(node); + }, + heading: function heading(state, node) { + state.write(state.repeat("#", node.attrs.level) + " "); + state.renderInline(node, false); + state.closeBlock(node); + }, + horizontal_rule: function horizontal_rule(state, node) { + state.write(node.attrs.markup || "---"); + state.closeBlock(node); + }, + bullet_list: function bullet_list(state, node) { + state.renderList(node, " ", function () { + return (node.attrs.bullet || "*") + " "; + }); + }, + ordered_list: function ordered_list(state, node) { + var start = node.attrs.order || 1; + var maxW = String(start + node.childCount - 1).length; + var space = state.repeat(" ", maxW + 2); + state.renderList(node, space, function (i) { + var nStr = String(start + i); + return state.repeat(" ", maxW - nStr.length) + nStr + ". "; + }); + }, + list_item: function list_item(state, node) { + state.renderContent(node); + }, + paragraph: function paragraph(state, node) { + state.renderInline(node); + state.closeBlock(node); + }, + image: function image(state, node) { + state.write("![" + state.esc(node.attrs.alt || "") + "](" + node.attrs.src.replace(/[\(\)]/g, "\\$&") + (node.attrs.title ? ' "' + node.attrs.title.replace(/"/g, '\\"') + '"' : "") + ")"); + }, + hard_break: function hard_break(state, node, parent, index) { + for (var i = index + 1; i < parent.childCount; i++) if (parent.child(i).type != node.type) { + state.write("\\\n"); + return; + } + }, + text: function text(state, node) { + state.text(node.text, !state.inAutolink); + } +}, { + em: { + open: "*", + close: "*", + mixable: true, + expelEnclosingWhitespace: true + }, + strong: { + open: "**", + close: "**", + mixable: true, + expelEnclosingWhitespace: true + }, + link: { + open: function open(state, mark, parent, index) { + state.inAutolink = isPlainURL(mark, parent, index); + return state.inAutolink ? "<" : "["; + }, + close: function close(state, mark, parent, index) { + var inAutolink = state.inAutolink; + state.inAutolink = undefined; + return inAutolink ? ">" : "](" + mark.attrs.href.replace(/[\(\)"]/g, "\\$&") + (mark.attrs.title ? " \"".concat(mark.attrs.title.replace(/"/g, '\\"'), "\"") : "") + ")"; + }, + mixable: true + }, + code: { + open: function open(_state, _mark, parent, index) { + return backticksFor(parent.child(index), -1); + }, + close: function close(_state, _mark, parent, index) { + return backticksFor(parent.child(index - 1), 1); + }, + escape: false + } +}); +function backticksFor(node, side) { + var ticks = /`+/g, + m, + len = 0; + if (node.isText) while (m = ticks.exec(node.text)) len = Math.max(len, m[0].length); + var result = len > 0 && side > 0 ? " `" : "`"; + for (var i = 0; i < len; i++) result += "`"; + if (len > 0 && side < 0) result += " "; + return result; +} +function isPlainURL(link, parent, index) { + if (link.attrs.title || !/^\w+:/.test(link.attrs.href)) return false; + var content = parent.child(index); + if (!content.isText || content.text != link.attrs.href || content.marks[content.marks.length - 1] != link) return false; + return index == parent.childCount - 1 || !link.isInSet(parent.child(index + 1).marks); +} +var MarkdownSerializerState = function () { + function MarkdownSerializerState(nodes, marks, options) { + _classCallCheck(this, MarkdownSerializerState); + this.nodes = nodes; + this.marks = marks; + this.options = options; + this.delim = ""; + this.out = ""; + this.closed = null; + this.inAutolink = undefined; + this.atBlockStart = false; + this.inTightList = false; + if (typeof this.options.tightLists == "undefined") this.options.tightLists = false; + if (typeof this.options.hardBreakNodeName == "undefined") this.options.hardBreakNodeName = "hard_break"; + } + _createClass(MarkdownSerializerState, [{ + key: "flushClose", + value: function flushClose() { + var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; + if (this.closed) { + if (!this.atBlank()) this.out += "\n"; + if (size > 1) { + var delimMin = this.delim; + var trim = /\s+$/.exec(delimMin); + if (trim) delimMin = delimMin.slice(0, delimMin.length - trim[0].length); + for (var i = 1; i < size; i++) this.out += delimMin + "\n"; + } + this.closed = null; + } + } + }, { + key: "getMark", + value: function getMark(name) { + var info = this.marks[name]; + if (!info) { + if (this.options.strict !== false) throw new Error("Mark type `".concat(name, "` not supported by Markdown renderer")); + info = blankMark; + } + return info; + } + }, { + key: "wrapBlock", + value: function wrapBlock(delim, firstDelim, node, f) { + var old = this.delim; + this.write(firstDelim != null ? firstDelim : delim); + this.delim += delim; + f(); + this.delim = old; + this.closeBlock(node); + } + }, { + key: "atBlank", + value: function atBlank() { + return /(^|\n)$/.test(this.out); + } + }, { + key: "ensureNewLine", + value: function ensureNewLine() { + if (!this.atBlank()) this.out += "\n"; + } + }, { + key: "write", + value: function write(content) { + this.flushClose(); + if (this.delim && this.atBlank()) this.out += this.delim; + if (content) this.out += content; + } + }, { + key: "closeBlock", + value: function closeBlock(node) { + this.closed = node; + } + }, { + key: "text", + value: function text(_text) { + var escape = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var lines = _text.split("\n"); + for (var i = 0; i < lines.length; i++) { + this.write(); + if (!escape && lines[i][0] == "[" && /(^|[^\\])\!$/.test(this.out)) this.out = this.out.slice(0, this.out.length - 1) + "\\!"; + this.out += escape ? this.esc(lines[i], this.atBlockStart) : lines[i]; + if (i != lines.length - 1) this.out += "\n"; + } + } + }, { + key: "render", + value: function render(node, parent, index) { + if (this.nodes[node.type.name]) { + this.nodes[node.type.name](this, node, parent, index); + } else { + if (this.options.strict !== false) { + throw new Error("Token type `" + node.type.name + "` not supported by Markdown renderer"); + } else if (!node.type.isLeaf) { + if (node.type.inlineContent) this.renderInline(node);else this.renderContent(node); + if (node.isBlock) this.closeBlock(node); + } + } + } + }, { + key: "renderContent", + value: function renderContent(parent) { + var _this = this; + parent.forEach(function (node, _, i) { + return _this.render(node, parent, i); + }); + } + }, { + key: "renderInline", + value: function renderInline(parent) { + var _this2 = this; + var fromBlockStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + this.atBlockStart = fromBlockStart; + var active = [], + trailing = ""; + var progress = function progress(node, offset, index) { + var marks = node ? node.marks : []; + if (node && node.type.name === _this2.options.hardBreakNodeName) marks = marks.filter(function (m) { + if (index + 1 == parent.childCount) return false; + var next = parent.child(index + 1); + return m.isInSet(next.marks) && (!next.isText || /\S/.test(next.text)); + }); + var leading = trailing; + trailing = ""; + if (node && node.isText && marks.some(function (mark) { + var info = _this2.getMark(mark.type.name); + return info && info.expelEnclosingWhitespace && !mark.isInSet(active); + })) { + var _exec = /^(\s*)(.*)$/m.exec(node.text), + _exec2 = _slicedToArray(_exec, 3), + _ = _exec2[0], + lead = _exec2[1], + rest = _exec2[2]; + if (lead) { + leading += lead; + node = rest ? node.withText(rest) : null; + if (!node) marks = active; + } + } + if (node && node.isText && marks.some(function (mark) { + var info = _this2.getMark(mark.type.name); + return info && info.expelEnclosingWhitespace && (index == parent.childCount - 1 || !mark.isInSet(parent.child(index + 1).marks)); + })) { + var _exec3 = /^(.*?)(\s*)$/m.exec(node.text), + _exec4 = _slicedToArray(_exec3, 3), + _2 = _exec4[0], + _rest = _exec4[1], + trail = _exec4[2]; + if (trail) { + trailing = trail; + node = _rest ? node.withText(_rest) : null; + if (!node) marks = active; + } + } + var inner = marks.length ? marks[marks.length - 1] : null; + var noEsc = inner && _this2.getMark(inner.type.name).escape === false; + var len = marks.length - (noEsc ? 1 : 0); + outer: for (var i = 0; i < len; i++) { + var mark = marks[i]; + if (!_this2.getMark(mark.type.name).mixable) break; + for (var j = 0; j < active.length; j++) { + var other = active[j]; + if (!_this2.getMark(other.type.name).mixable) break; + if (mark.eq(other)) { + if (i > j) marks = marks.slice(0, j).concat(mark).concat(marks.slice(j, i)).concat(marks.slice(i + 1, len));else if (j > i) marks = marks.slice(0, i).concat(marks.slice(i + 1, j)).concat(mark).concat(marks.slice(j, len)); + continue outer; + } + } + } + var keep = 0; + while (keep < Math.min(active.length, len) && marks[keep].eq(active[keep])) ++keep; + while (keep < active.length) _this2.text(_this2.markString(active.pop(), false, parent, index), false); + if (leading) _this2.text(leading); + if (node) { + while (active.length < len) { + var add = marks[active.length]; + active.push(add); + _this2.text(_this2.markString(add, true, parent, index), false); + _this2.atBlockStart = false; + } + if (noEsc && node.isText) _this2.text(_this2.markString(inner, true, parent, index) + node.text + _this2.markString(inner, false, parent, index + 1), false);else _this2.render(node, parent, index); + _this2.atBlockStart = false; + } + if ((node === null || node === void 0 ? void 0 : node.isText) && node.nodeSize > 0) { + _this2.atBlockStart = false; + } + }; + parent.forEach(progress); + progress(null, 0, parent.childCount); + this.atBlockStart = false; + } + }, { + key: "renderList", + value: function renderList(node, delim, firstDelim) { + var _this3 = this; + if (this.closed && this.closed.type == node.type) this.flushClose(3);else if (this.inTightList) this.flushClose(1); + var isTight = typeof node.attrs.tight != "undefined" ? node.attrs.tight : this.options.tightLists; + var prevTight = this.inTightList; + this.inTightList = isTight; + node.forEach(function (child, _, i) { + if (i && isTight) _this3.flushClose(1); + _this3.wrapBlock(delim, firstDelim(i), node, function () { + return _this3.render(child, node, i); + }); + }); + this.inTightList = prevTight; + } + }, { + key: "esc", + value: function esc(str) { + var startOfLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + str = str.replace(/[`*\\~\[\]_]/g, function (m, i) { + return m == "_" && i > 0 && i + 1 < str.length && str[i - 1].match(/\w/) && str[i + 1].match(/\w/) ? m : "\\" + m; + }); + if (startOfLine) str = str.replace(/^(\+[ ]|[\-*>])/, "\\$&").replace(/^(\s*)(#{1,6})(\s|$)/, '$1\\$2$3').replace(/^(\s*\d+)\.\s/, "$1\\. "); + if (this.options.escapeExtraCharacters) str = str.replace(this.options.escapeExtraCharacters, "\\$&"); + return str; + } + }, { + key: "quote", + value: function quote(str) { + var wrap = str.indexOf('"') == -1 ? '""' : str.indexOf("'") == -1 ? "''" : "()"; + return wrap[0] + str + wrap[1]; + } + }, { + key: "repeat", + value: function repeat(str, n) { + var out = ""; + for (var i = 0; i < n; i++) out += str; + return out; + } + }, { + key: "markString", + value: function markString(mark, open, parent, index) { + var info = this.getMark(mark.type.name); + var value = open ? info.open : info.close; + return typeof value == "string" ? value : value(this, mark, parent, index); + } + }, { + key: "getEnclosingWhitespace", + value: function getEnclosingWhitespace(text) { + return { + leading: (text.match(/^(\s+)/) || [undefined])[0], + trailing: (text.match(/(\s+)$/) || [undefined])[0] + }; + } + }]); + return MarkdownSerializerState; +}(); +exports.MarkdownParser = MarkdownParser; +exports.MarkdownSerializer = MarkdownSerializer; +exports.MarkdownSerializerState = MarkdownSerializerState; +exports.defaultMarkdownParser = defaultMarkdownParser; +exports.defaultMarkdownSerializer = defaultMarkdownSerializer; +exports.schema = schema; + +}); +define("prosemirror-model",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var OrderedMap = require('orderedmap'); +function _findDiffStart(a, b, pos) { + for (var i = 0;; i++) { + if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos; + var childA = a.child(i), + childB = b.child(i); + if (childA == childB) { + pos += childA.nodeSize; + continue; + } + if (!childA.sameMarkup(childB)) return pos; + if (childA.isText && childA.text != childB.text) { + for (var j = 0; childA.text[j] == childB.text[j]; j++) pos++; + return pos; + } + if (childA.content.size || childB.content.size) { + var inner = _findDiffStart(childA.content, childB.content, pos + 1); + if (inner != null) return inner; + } + pos += childA.nodeSize; + } +} +function _findDiffEnd(a, b, posA, posB) { + for (var iA = a.childCount, iB = b.childCount;;) { + if (iA == 0 || iB == 0) return iA == iB ? null : { + a: posA, + b: posB + }; + var childA = a.child(--iA), + childB = b.child(--iB), + size = childA.nodeSize; + if (childA == childB) { + posA -= size; + posB -= size; + continue; + } + if (!childA.sameMarkup(childB)) return { + a: posA, + b: posB + }; + if (childA.isText && childA.text != childB.text) { + var same = 0, + minSize = Math.min(childA.text.length, childB.text.length); + while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) { + same++; + posA--; + posB--; + } + return { + a: posA, + b: posB + }; + } + if (childA.content.size || childB.content.size) { + var inner = _findDiffEnd(childA.content, childB.content, posA - 1, posB - 1); + if (inner) return inner; + } + posA -= size; + posB -= size; + } +} +var Fragment = function () { + function Fragment(content, size) { + _classCallCheck(this, Fragment); + this.content = content; + this.size = size || 0; + if (size == null) for (var i = 0; i < content.length; i++) this.size += content[i].nodeSize; + } + _createClass(Fragment, [{ + key: "nodesBetween", + value: function nodesBetween(from, to, f) { + var nodeStart = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + var parent = arguments.length > 4 ? arguments[4] : undefined; + for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], + end = pos + child.nodeSize; + if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) { + var start = pos + 1; + child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start); + } + pos = end; + } + } + }, { + key: "descendants", + value: function descendants(f) { + this.nodesBetween(0, this.size, f); + } + }, { + key: "textBetween", + value: function textBetween(from, to, blockSeparator, leafText) { + var text = "", + first = true; + this.nodesBetween(from, to, function (node, pos) { + var nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : ""; + if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) { + if (first) first = false;else text += blockSeparator; + } + text += nodeText; + }, 0); + return text; + } + }, { + key: "append", + value: function append(other) { + if (!other.size) return this; + if (!this.size) return other; + var last = this.lastChild, + first = other.firstChild, + content = this.content.slice(), + i = 0; + if (last.isText && last.sameMarkup(first)) { + content[content.length - 1] = last.withText(last.text + first.text); + i = 1; + } + for (; i < other.content.length; i++) content.push(other.content[i]); + return new Fragment(content, this.size + other.size); + } + }, { + key: "cut", + value: function cut(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size; + if (from == 0 && to == this.size) return this; + var result = [], + size = 0; + if (to > from) for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], + end = pos + child.nodeSize; + if (end > from) { + if (pos < from || end > to) { + if (child.isText) child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));else child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1)); + } + result.push(child); + size += child.nodeSize; + } + pos = end; + } + return new Fragment(result, size); + } + }, { + key: "cutByIndex", + value: function cutByIndex(from, to) { + if (from == to) return Fragment.empty; + if (from == 0 && to == this.content.length) return this; + return new Fragment(this.content.slice(from, to)); + } + }, { + key: "replaceChild", + value: function replaceChild(index, node) { + var current = this.content[index]; + if (current == node) return this; + var copy = this.content.slice(); + var size = this.size + node.nodeSize - current.nodeSize; + copy[index] = node; + return new Fragment(copy, size); + } + }, { + key: "addToStart", + value: function addToStart(node) { + return new Fragment([node].concat(this.content), this.size + node.nodeSize); + } + }, { + key: "addToEnd", + value: function addToEnd(node) { + return new Fragment(this.content.concat(node), this.size + node.nodeSize); + } + }, { + key: "eq", + value: function eq(other) { + if (this.content.length != other.content.length) return false; + for (var i = 0; i < this.content.length; i++) if (!this.content[i].eq(other.content[i])) return false; + return true; + } + }, { + key: "firstChild", + get: function get() { + return this.content.length ? this.content[0] : null; + } + }, { + key: "lastChild", + get: function get() { + return this.content.length ? this.content[this.content.length - 1] : null; + } + }, { + key: "childCount", + get: function get() { + return this.content.length; + } + }, { + key: "child", + value: function child(index) { + var found = this.content[index]; + if (!found) throw new RangeError("Index " + index + " out of range for " + this); + return found; + } + }, { + key: "maybeChild", + value: function maybeChild(index) { + return this.content[index] || null; + } + }, { + key: "forEach", + value: function forEach(f) { + for (var i = 0, p = 0; i < this.content.length; i++) { + var child = this.content[i]; + f(child, p, i); + p += child.nodeSize; + } + } + }, { + key: "findDiffStart", + value: function findDiffStart(other) { + var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return _findDiffStart(this, other, pos); + } + }, { + key: "findDiffEnd", + value: function findDiffEnd(other) { + var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size; + var otherPos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : other.size; + return _findDiffEnd(this, other, pos, otherPos); + } + }, { + key: "findIndex", + value: function findIndex(pos) { + var round = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; + if (pos == 0) return retIndex(0, pos); + if (pos == this.size) return retIndex(this.content.length, pos); + if (pos > this.size || pos < 0) throw new RangeError("Position ".concat(pos, " outside of fragment (").concat(this, ")")); + for (var i = 0, curPos = 0;; i++) { + var cur = this.child(i), + end = curPos + cur.nodeSize; + if (end >= pos) { + if (end == pos || round > 0) return retIndex(i + 1, end); + return retIndex(i, curPos); + } + curPos = end; + } + } + }, { + key: "toString", + value: function toString() { + return "<" + this.toStringInner() + ">"; + } + }, { + key: "toStringInner", + value: function toStringInner() { + return this.content.join(", "); + } + }, { + key: "toJSON", + value: function toJSON() { + return this.content.length ? this.content.map(function (n) { + return n.toJSON(); + }) : null; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, value) { + if (!value) return Fragment.empty; + if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON"); + return new Fragment(value.map(schema.nodeFromJSON)); + } + }, { + key: "fromArray", + value: function fromArray(array) { + if (!array.length) return Fragment.empty; + var joined, + size = 0; + for (var i = 0; i < array.length; i++) { + var node = array[i]; + size += node.nodeSize; + if (i && node.isText && array[i - 1].sameMarkup(node)) { + if (!joined) joined = array.slice(0, i); + joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text); + } else if (joined) { + joined.push(node); + } + } + return new Fragment(joined || array, size); + } + }, { + key: "from", + value: function from(nodes) { + if (!nodes) return Fragment.empty; + if (nodes instanceof Fragment) return nodes; + if (Array.isArray(nodes)) return this.fromArray(nodes); + if (nodes.attrs) return new Fragment([nodes], nodes.nodeSize); + throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")); + } + }]); + return Fragment; +}(); +Fragment.empty = new Fragment([], 0); +var found = { + index: 0, + offset: 0 +}; +function retIndex(index, offset) { + found.index = index; + found.offset = offset; + return found; +} +function compareDeep(a, b) { + if (a === b) return true; + if (!(a && _typeof(a) == "object") || !(b && _typeof(b) == "object")) return false; + var array = Array.isArray(a); + if (Array.isArray(b) != array) return false; + if (array) { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false; + } else { + for (var p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false; + for (var _p in b) if (!(_p in a)) return false; + } + return true; +} +var Mark = function () { + function Mark(type, attrs) { + _classCallCheck(this, Mark); + this.type = type; + this.attrs = attrs; + } + _createClass(Mark, [{ + key: "addToSet", + value: function addToSet(set) { + var copy, + placed = false; + for (var i = 0; i < set.length; i++) { + var other = set[i]; + if (this.eq(other)) return set; + if (this.type.excludes(other.type)) { + if (!copy) copy = set.slice(0, i); + } else if (other.type.excludes(this.type)) { + return set; + } else { + if (!placed && other.type.rank > this.type.rank) { + if (!copy) copy = set.slice(0, i); + copy.push(this); + placed = true; + } + if (copy) copy.push(other); + } + } + if (!copy) copy = set.slice(); + if (!placed) copy.push(this); + return copy; + } + }, { + key: "removeFromSet", + value: function removeFromSet(set) { + for (var i = 0; i < set.length; i++) if (this.eq(set[i])) return set.slice(0, i).concat(set.slice(i + 1)); + return set; + } + }, { + key: "isInSet", + value: function isInSet(set) { + for (var i = 0; i < set.length; i++) if (this.eq(set[i])) return true; + return false; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs); + } + }, { + key: "toJSON", + value: function toJSON() { + var obj = { + type: this.type.name + }; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break; + } + return obj; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) throw new RangeError("Invalid input for Mark.fromJSON"); + var type = schema.marks[json.type]; + if (!type) throw new RangeError("There is no mark type ".concat(json.type, " in this schema")); + var mark = type.create(json.attrs); + type.checkAttrs(mark.attrs); + return mark; + } + }, { + key: "sameSet", + value: function sameSet(a, b) { + if (a == b) return true; + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!a[i].eq(b[i])) return false; + return true; + } + }, { + key: "setFrom", + value: function setFrom(marks) { + if (!marks || Array.isArray(marks) && marks.length == 0) return Mark.none; + if (marks instanceof Mark) return [marks]; + var copy = marks.slice(); + copy.sort(function (a, b) { + return a.type.rank - b.type.rank; + }); + return copy; + } + }]); + return Mark; +}(); +Mark.none = []; +var ReplaceError = function (_Error) { + _inherits(ReplaceError, _Error); + var _super = _createSuper(ReplaceError); + function ReplaceError() { + _classCallCheck(this, ReplaceError); + return _super.apply(this, arguments); + } + return _createClass(ReplaceError); +}(_wrapNativeSuper(Error)); +var Slice = function () { + function Slice(content, openStart, openEnd) { + _classCallCheck(this, Slice); + this.content = content; + this.openStart = openStart; + this.openEnd = openEnd; + } + _createClass(Slice, [{ + key: "size", + get: function get() { + return this.content.size - this.openStart - this.openEnd; + } + }, { + key: "insertAt", + value: function insertAt(pos, fragment) { + var content = insertInto(this.content, pos + this.openStart, fragment); + return content && new Slice(content, this.openStart, this.openEnd); + } + }, { + key: "removeBetween", + value: function removeBetween(from, to) { + return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd); + } + }, { + key: "eq", + value: function eq(other) { + return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd; + } + }, { + key: "toString", + value: function toString() { + return this.content + "(" + this.openStart + "," + this.openEnd + ")"; + } + }, { + key: "toJSON", + value: function toJSON() { + if (!this.content.size) return null; + var json = { + content: this.content.toJSON() + }; + if (this.openStart > 0) json.openStart = this.openStart; + if (this.openEnd > 0) json.openEnd = this.openEnd; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) return Slice.empty; + var openStart = json.openStart || 0, + openEnd = json.openEnd || 0; + if (typeof openStart != "number" || typeof openEnd != "number") throw new RangeError("Invalid input for Slice.fromJSON"); + return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd); + } + }, { + key: "maxOpen", + value: function maxOpen(fragment) { + var openIsolating = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var openStart = 0, + openEnd = 0; + for (var n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) openStart++; + for (var _n = fragment.lastChild; _n && !_n.isLeaf && (openIsolating || !_n.type.spec.isolating); _n = _n.lastChild) openEnd++; + return new Slice(fragment, openStart, openEnd); + } + }]); + return Slice; +}(); +Slice.empty = new Slice(Fragment.empty, 0, 0); +function removeRange(content, from, to) { + var _content$findIndex = content.findIndex(from), + index = _content$findIndex.index, + offset = _content$findIndex.offset, + child = content.maybeChild(index); + var _content$findIndex2 = content.findIndex(to), + indexTo = _content$findIndex2.index, + offsetTo = _content$findIndex2.offset; + if (offset == from || child.isText) { + if (offsetTo != to && !content.child(indexTo).isText) throw new RangeError("Removing non-flat range"); + return content.cut(0, from).append(content.cut(to)); + } + if (index != indexTo) throw new RangeError("Removing non-flat range"); + return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1))); +} +function insertInto(content, dist, insert, parent) { + var _content$findIndex3 = content.findIndex(dist), + index = _content$findIndex3.index, + offset = _content$findIndex3.offset, + child = content.maybeChild(index); + if (offset == dist || child.isText) { + if (parent && !parent.canReplace(index, index, insert)) return null; + return content.cut(0, dist).append(insert).append(content.cut(dist)); + } + var inner = insertInto(child.content, dist - offset - 1, insert); + return inner && content.replaceChild(index, child.copy(inner)); +} +function _replace($from, $to, slice) { + if (slice.openStart > $from.depth) throw new ReplaceError("Inserted content deeper than insertion position"); + if ($from.depth - slice.openStart != $to.depth - slice.openEnd) throw new ReplaceError("Inconsistent open depths"); + return replaceOuter($from, $to, slice, 0); +} +function replaceOuter($from, $to, slice, depth) { + var index = $from.index(depth), + node = $from.node(depth); + if (index == $to.index(depth) && depth < $from.depth - slice.openStart) { + var inner = replaceOuter($from, $to, slice, depth + 1); + return node.copy(node.content.replaceChild(index, inner)); + } else if (!slice.content.size) { + return close(node, replaceTwoWay($from, $to, depth)); + } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { + var parent = $from.parent, + content = parent.content; + return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))); + } else { + var _prepareSliceForRepla = prepareSliceForReplace(slice, $from), + start = _prepareSliceForRepla.start, + end = _prepareSliceForRepla.end; + return close(node, replaceThreeWay($from, start, end, $to, depth)); + } +} +function checkJoin(main, sub) { + if (!sub.type.compatibleContent(main.type)) throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name); +} +function joinable($before, $after, depth) { + var node = $before.node(depth); + checkJoin(node, $after.node(depth)); + return node; +} +function addNode(child, target) { + var last = target.length - 1; + if (last >= 0 && child.isText && child.sameMarkup(target[last])) target[last] = child.withText(target[last].text + child.text);else target.push(child); +} +function addRange($start, $end, depth, target) { + var node = ($end || $start).node(depth); + var startIndex = 0, + endIndex = $end ? $end.index(depth) : node.childCount; + if ($start) { + startIndex = $start.index(depth); + if ($start.depth > depth) { + startIndex++; + } else if ($start.textOffset) { + addNode($start.nodeAfter, target); + startIndex++; + } + } + for (var i = startIndex; i < endIndex; i++) addNode(node.child(i), target); + if ($end && $end.depth == depth && $end.textOffset) addNode($end.nodeBefore, target); +} +function close(node, content) { + node.type.checkContent(content); + return node.copy(content); +} +function replaceThreeWay($from, $start, $end, $to, depth) { + var openStart = $from.depth > depth && joinable($from, $start, depth + 1); + var openEnd = $to.depth > depth && joinable($end, $to, depth + 1); + var content = []; + addRange(null, $from, depth, content); + if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { + checkJoin(openStart, openEnd); + addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content); + } else { + if (openStart) addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content); + addRange($start, $end, depth, content); + if (openEnd) addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content); + } + addRange($to, null, depth, content); + return new Fragment(content); +} +function replaceTwoWay($from, $to, depth) { + var content = []; + addRange(null, $from, depth, content); + if ($from.depth > depth) { + var type = joinable($from, $to, depth + 1); + addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content); + } + addRange($to, null, depth, content); + return new Fragment(content); +} +function prepareSliceForReplace(slice, $along) { + var extra = $along.depth - slice.openStart, + parent = $along.node(extra); + var node = parent.copy(slice.content); + for (var i = extra - 1; i >= 0; i--) node = $along.node(i).copy(Fragment.from(node)); + return { + start: node.resolveNoCache(slice.openStart + extra), + end: node.resolveNoCache(node.content.size - slice.openEnd - extra) + }; +} +var ResolvedPos = function () { + function ResolvedPos(pos, path, parentOffset) { + _classCallCheck(this, ResolvedPos); + this.pos = pos; + this.path = path; + this.parentOffset = parentOffset; + this.depth = path.length / 3 - 1; + } + _createClass(ResolvedPos, [{ + key: "resolveDepth", + value: function resolveDepth(val) { + if (val == null) return this.depth; + if (val < 0) return this.depth + val; + return val; + } + }, { + key: "parent", + get: function get() { + return this.node(this.depth); + } + }, { + key: "doc", + get: function get() { + return this.node(0); + } + }, { + key: "node", + value: function node(depth) { + return this.path[this.resolveDepth(depth) * 3]; + } + }, { + key: "index", + value: function index(depth) { + return this.path[this.resolveDepth(depth) * 3 + 1]; + } + }, { + key: "indexAfter", + value: function indexAfter(depth) { + depth = this.resolveDepth(depth); + return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1); + } + }, { + key: "start", + value: function start(depth) { + depth = this.resolveDepth(depth); + return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; + } + }, { + key: "end", + value: function end(depth) { + depth = this.resolveDepth(depth); + return this.start(depth) + this.node(depth).content.size; + } + }, { + key: "before", + value: function before(depth) { + depth = this.resolveDepth(depth); + if (!depth) throw new RangeError("There is no position before the top-level node"); + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1]; + } + }, { + key: "after", + value: function after(depth) { + depth = this.resolveDepth(depth); + if (!depth) throw new RangeError("There is no position after the top-level node"); + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize; + } + }, { + key: "textOffset", + get: function get() { + return this.pos - this.path[this.path.length - 1]; + } + }, { + key: "nodeAfter", + get: function get() { + var parent = this.parent, + index = this.index(this.depth); + if (index == parent.childCount) return null; + var dOff = this.pos - this.path[this.path.length - 1], + child = parent.child(index); + return dOff ? parent.child(index).cut(dOff) : child; + } + }, { + key: "nodeBefore", + get: function get() { + var index = this.index(this.depth); + var dOff = this.pos - this.path[this.path.length - 1]; + if (dOff) return this.parent.child(index).cut(0, dOff); + return index == 0 ? null : this.parent.child(index - 1); + } + }, { + key: "posAtIndex", + value: function posAtIndex(index, depth) { + depth = this.resolveDepth(depth); + var node = this.path[depth * 3], + pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; + for (var i = 0; i < index; i++) pos += node.child(i).nodeSize; + return pos; + } + }, { + key: "marks", + value: function marks() { + var parent = this.parent, + index = this.index(); + if (parent.content.size == 0) return Mark.none; + if (this.textOffset) return parent.child(index).marks; + var main = parent.maybeChild(index - 1), + other = parent.maybeChild(index); + if (!main) { + var tmp = main; + main = other; + other = tmp; + } + var marks = main.marks; + for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) marks = marks[i--].removeFromSet(marks); + return marks; + } + }, { + key: "marksAcross", + value: function marksAcross($end) { + var after = this.parent.maybeChild(this.index()); + if (!after || !after.isInline) return null; + var marks = after.marks, + next = $end.parent.maybeChild($end.index()); + for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) marks = marks[i--].removeFromSet(marks); + return marks; + } + }, { + key: "sharedDepth", + value: function sharedDepth(pos) { + for (var depth = this.depth; depth > 0; depth--) if (this.start(depth) <= pos && this.end(depth) >= pos) return depth; + return 0; + } + }, { + key: "blockRange", + value: function blockRange() { + var other = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this; + var pred = arguments.length > 1 ? arguments[1] : undefined; + if (other.pos < this.pos) return other.blockRange(this); + for (var d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) return new NodeRange(this, other, d); + return null; + } + }, { + key: "sameParent", + value: function sameParent(other) { + return this.pos - this.parentOffset == other.pos - other.parentOffset; + } + }, { + key: "max", + value: function max(other) { + return other.pos > this.pos ? other : this; + } + }, { + key: "min", + value: function min(other) { + return other.pos < this.pos ? other : this; + } + }, { + key: "toString", + value: function toString() { + var str = ""; + for (var i = 1; i <= this.depth; i++) str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1); + return str + ":" + this.parentOffset; + } + }], [{ + key: "resolve", + value: function resolve(doc, pos) { + if (!(pos >= 0 && pos <= doc.content.size)) throw new RangeError("Position " + pos + " out of range"); + var path = []; + var start = 0, + parentOffset = pos; + for (var node = doc;;) { + var _node$content$findInd = node.content.findIndex(parentOffset), + index = _node$content$findInd.index, + offset = _node$content$findInd.offset; + var rem = parentOffset - offset; + path.push(node, index, start + offset); + if (!rem) break; + node = node.child(index); + if (node.isText) break; + parentOffset = rem - 1; + start += offset + 1; + } + return new ResolvedPos(pos, path, parentOffset); + } + }, { + key: "resolveCached", + value: function resolveCached(doc, pos) { + var cache = resolveCache.get(doc); + if (cache) { + for (var i = 0; i < cache.elts.length; i++) { + var elt = cache.elts[i]; + if (elt.pos == pos) return elt; + } + } else { + resolveCache.set(doc, cache = new ResolveCache()); + } + var result = cache.elts[cache.i] = ResolvedPos.resolve(doc, pos); + cache.i = (cache.i + 1) % resolveCacheSize; + return result; + } + }]); + return ResolvedPos; +}(); +var ResolveCache = _createClass(function ResolveCache() { + _classCallCheck(this, ResolveCache); + this.elts = []; + this.i = 0; +}); +var resolveCacheSize = 12, + resolveCache = new WeakMap(); +var NodeRange = function () { + function NodeRange($from, $to, depth) { + _classCallCheck(this, NodeRange); + this.$from = $from; + this.$to = $to; + this.depth = depth; + } + _createClass(NodeRange, [{ + key: "start", + get: function get() { + return this.$from.before(this.depth + 1); + } + }, { + key: "end", + get: function get() { + return this.$to.after(this.depth + 1); + } + }, { + key: "parent", + get: function get() { + return this.$from.node(this.depth); + } + }, { + key: "startIndex", + get: function get() { + return this.$from.index(this.depth); + } + }, { + key: "endIndex", + get: function get() { + return this.$to.indexAfter(this.depth); + } + }]); + return NodeRange; +}(); +var emptyAttrs = Object.create(null); +var Node = function () { + function Node(type, attrs, content) { + var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Mark.none; + _classCallCheck(this, Node); + this.type = type; + this.attrs = attrs; + this.marks = marks; + this.content = content || Fragment.empty; + } + _createClass(Node, [{ + key: "nodeSize", + get: function get() { + return this.isLeaf ? 1 : 2 + this.content.size; + } + }, { + key: "childCount", + get: function get() { + return this.content.childCount; + } + }, { + key: "child", + value: function child(index) { + return this.content.child(index); + } + }, { + key: "maybeChild", + value: function maybeChild(index) { + return this.content.maybeChild(index); + } + }, { + key: "forEach", + value: function forEach(f) { + this.content.forEach(f); + } + }, { + key: "nodesBetween", + value: function nodesBetween(from, to, f) { + var startPos = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + this.content.nodesBetween(from, to, f, startPos, this); + } + }, { + key: "descendants", + value: function descendants(f) { + this.nodesBetween(0, this.content.size, f); + } + }, { + key: "textContent", + get: function get() { + return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, ""); + } + }, { + key: "textBetween", + value: function textBetween(from, to, blockSeparator, leafText) { + return this.content.textBetween(from, to, blockSeparator, leafText); + } + }, { + key: "firstChild", + get: function get() { + return this.content.firstChild; + } + }, { + key: "lastChild", + get: function get() { + return this.content.lastChild; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || this.sameMarkup(other) && this.content.eq(other.content); + } + }, { + key: "sameMarkup", + value: function sameMarkup(other) { + return this.hasMarkup(other.type, other.attrs, other.marks); + } + }, { + key: "hasMarkup", + value: function hasMarkup(type, attrs, marks) { + return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none); + } + }, { + key: "copy", + value: function copy() { + var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + if (content == this.content) return this; + return new Node(this.type, this.attrs, content, this.marks); + } + }, { + key: "mark", + value: function mark(marks) { + return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks); + } + }, { + key: "cut", + value: function cut(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.content.size; + if (from == 0 && to == this.content.size) return this; + return this.copy(this.content.cut(from, to)); + } + }, { + key: "slice", + value: function slice(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.content.size; + var includeParents = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + if (from == to) return Slice.empty; + var $from = this.resolve(from), + $to = this.resolve(to); + var depth = includeParents ? 0 : $from.sharedDepth(to); + var start = $from.start(depth), + node = $from.node(depth); + var content = node.content.cut($from.pos - start, $to.pos - start); + return new Slice(content, $from.depth - depth, $to.depth - depth); + } + }, { + key: "replace", + value: function replace(from, to, slice) { + return _replace(this.resolve(from), this.resolve(to), slice); + } + }, { + key: "nodeAt", + value: function nodeAt(pos) { + for (var node = this;;) { + var _node$content$findInd2 = node.content.findIndex(pos), + index = _node$content$findInd2.index, + offset = _node$content$findInd2.offset; + node = node.maybeChild(index); + if (!node) return null; + if (offset == pos || node.isText) return node; + pos -= offset + 1; + } + } + }, { + key: "childAfter", + value: function childAfter(pos) { + var _this$content$findInd = this.content.findIndex(pos), + index = _this$content$findInd.index, + offset = _this$content$findInd.offset; + return { + node: this.content.maybeChild(index), + index: index, + offset: offset + }; + } + }, { + key: "childBefore", + value: function childBefore(pos) { + if (pos == 0) return { + node: null, + index: 0, + offset: 0 + }; + var _this$content$findInd2 = this.content.findIndex(pos), + index = _this$content$findInd2.index, + offset = _this$content$findInd2.offset; + if (offset < pos) return { + node: this.content.child(index), + index: index, + offset: offset + }; + var node = this.content.child(index - 1); + return { + node: node, + index: index - 1, + offset: offset - node.nodeSize + }; + } + }, { + key: "resolve", + value: function resolve(pos) { + return ResolvedPos.resolveCached(this, pos); + } + }, { + key: "resolveNoCache", + value: function resolveNoCache(pos) { + return ResolvedPos.resolve(this, pos); + } + }, { + key: "rangeHasMark", + value: function rangeHasMark(from, to, type) { + var found = false; + if (to > from) this.nodesBetween(from, to, function (node) { + if (type.isInSet(node.marks)) found = true; + return !found; + }); + return found; + } + }, { + key: "isBlock", + get: function get() { + return this.type.isBlock; + } + }, { + key: "isTextblock", + get: function get() { + return this.type.isTextblock; + } + }, { + key: "inlineContent", + get: function get() { + return this.type.inlineContent; + } + }, { + key: "isInline", + get: function get() { + return this.type.isInline; + } + }, { + key: "isText", + get: function get() { + return this.type.isText; + } + }, { + key: "isLeaf", + get: function get() { + return this.type.isLeaf; + } + }, { + key: "isAtom", + get: function get() { + return this.type.isAtom; + } + }, { + key: "toString", + value: function toString() { + if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); + var name = this.type.name; + if (this.content.size) name += "(" + this.content.toStringInner() + ")"; + return wrapMarks(this.marks, name); + } + }, { + key: "contentMatchAt", + value: function contentMatchAt(index) { + var match = this.type.contentMatch.matchFragment(this.content, 0, index); + if (!match) throw new Error("Called contentMatchAt on a node with invalid content"); + return match; + } + }, { + key: "canReplace", + value: function canReplace(from, to) { + var replacement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Fragment.empty; + var start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + var end = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : replacement.childCount; + var one = this.contentMatchAt(from).matchFragment(replacement, start, end); + var two = one && one.matchFragment(this.content, to); + if (!two || !two.validEnd) return false; + for (var i = start; i < end; i++) if (!this.type.allowsMarks(replacement.child(i).marks)) return false; + return true; + } + }, { + key: "canReplaceWith", + value: function canReplaceWith(from, to, type, marks) { + if (marks && !this.type.allowsMarks(marks)) return false; + var start = this.contentMatchAt(from).matchType(type); + var end = start && start.matchFragment(this.content, to); + return end ? end.validEnd : false; + } + }, { + key: "canAppend", + value: function canAppend(other) { + if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content);else return this.type.compatibleContent(other.type); + } + }, { + key: "check", + value: function check() { + this.type.checkContent(this.content); + this.type.checkAttrs(this.attrs); + var copy = Mark.none; + for (var i = 0; i < this.marks.length; i++) { + var mark = this.marks[i]; + mark.type.checkAttrs(mark.attrs); + copy = mark.addToSet(copy); + } + if (!Mark.sameSet(copy, this.marks)) throw new RangeError("Invalid collection of marks for node ".concat(this.type.name, ": ").concat(this.marks.map(function (m) { + return m.type.name; + }))); + this.content.forEach(function (node) { + return node.check(); + }); + } + }, { + key: "toJSON", + value: function toJSON() { + var obj = { + type: this.type.name + }; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break; + } + if (this.content.size) obj.content = this.content.toJSON(); + if (this.marks.length) obj.marks = this.marks.map(function (n) { + return n.toJSON(); + }); + return obj; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) throw new RangeError("Invalid input for Node.fromJSON"); + var marks = undefined; + if (json.marks) { + if (!Array.isArray(json.marks)) throw new RangeError("Invalid mark data for Node.fromJSON"); + marks = json.marks.map(schema.markFromJSON); + } + if (json.type == "text") { + if (typeof json.text != "string") throw new RangeError("Invalid text node in JSON"); + return schema.text(json.text, marks); + } + var content = Fragment.fromJSON(schema, json.content); + var node = schema.nodeType(json.type).create(json.attrs, content, marks); + node.type.checkAttrs(node.attrs); + return node; + } + }]); + return Node; +}(); +Node.prototype.text = undefined; +var TextNode = function (_Node) { + _inherits(TextNode, _Node); + var _super2 = _createSuper(TextNode); + function TextNode(type, attrs, content, marks) { + var _this; + _classCallCheck(this, TextNode); + _this = _super2.call(this, type, attrs, null, marks); + if (!content) throw new RangeError("Empty text nodes are not allowed"); + _this.text = content; + return _this; + } + _createClass(TextNode, [{ + key: "toString", + value: function toString() { + if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); + return wrapMarks(this.marks, JSON.stringify(this.text)); + } + }, { + key: "textContent", + get: function get() { + return this.text; + } + }, { + key: "textBetween", + value: function textBetween(from, to) { + return this.text.slice(from, to); + } + }, { + key: "nodeSize", + get: function get() { + return this.text.length; + } + }, { + key: "mark", + value: function mark(marks) { + return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks); + } + }, { + key: "withText", + value: function withText(text) { + if (text == this.text) return this; + return new TextNode(this.type, this.attrs, text, this.marks); + } + }, { + key: "cut", + value: function cut() { + var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.text.length; + if (from == 0 && to == this.text.length) return this; + return this.withText(this.text.slice(from, to)); + } + }, { + key: "eq", + value: function eq(other) { + return this.sameMarkup(other) && this.text == other.text; + } + }, { + key: "toJSON", + value: function toJSON() { + var base = _get(_getPrototypeOf(TextNode.prototype), "toJSON", this).call(this); + base.text = this.text; + return base; + } + }]); + return TextNode; +}(Node); +function wrapMarks(marks, str) { + for (var i = marks.length - 1; i >= 0; i--) str = marks[i].type.name + "(" + str + ")"; + return str; +} +var ContentMatch = function () { + function ContentMatch(validEnd) { + _classCallCheck(this, ContentMatch); + this.validEnd = validEnd; + this.next = []; + this.wrapCache = []; + } + _createClass(ContentMatch, [{ + key: "matchType", + value: function matchType(type) { + for (var i = 0; i < this.next.length; i++) if (this.next[i].type == type) return this.next[i].next; + return null; + } + }, { + key: "matchFragment", + value: function matchFragment(frag) { + var start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : frag.childCount; + var cur = this; + for (var i = start; cur && i < end; i++) cur = cur.matchType(frag.child(i).type); + return cur; + } + }, { + key: "inlineContent", + get: function get() { + return this.next.length != 0 && this.next[0].type.isInline; + } + }, { + key: "defaultType", + get: function get() { + for (var i = 0; i < this.next.length; i++) { + var type = this.next[i].type; + if (!(type.isText || type.hasRequiredAttrs())) return type; + } + return null; + } + }, { + key: "compatible", + value: function compatible(other) { + for (var i = 0; i < this.next.length; i++) for (var j = 0; j < other.next.length; j++) if (this.next[i].type == other.next[j].type) return true; + return false; + } + }, { + key: "fillBefore", + value: function fillBefore(after) { + var toEnd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var seen = [this]; + function search(match, types) { + var finished = match.matchFragment(after, startIndex); + if (finished && (!toEnd || finished.validEnd)) return Fragment.from(types.map(function (tp) { + return tp.createAndFill(); + })); + for (var i = 0; i < match.next.length; i++) { + var _match$next$i = match.next[i], + type = _match$next$i.type, + next = _match$next$i.next; + if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) { + seen.push(next); + var _found = search(next, types.concat(type)); + if (_found) return _found; + } + } + return null; + } + return search(this, []); + } + }, { + key: "findWrapping", + value: function findWrapping(target) { + for (var i = 0; i < this.wrapCache.length; i += 2) if (this.wrapCache[i] == target) return this.wrapCache[i + 1]; + var computed = this.computeWrapping(target); + this.wrapCache.push(target, computed); + return computed; + } + }, { + key: "computeWrapping", + value: function computeWrapping(target) { + var seen = Object.create(null), + active = [{ + match: this, + type: null, + via: null + }]; + while (active.length) { + var current = active.shift(), + match = current.match; + if (match.matchType(target)) { + var result = []; + for (var obj = current; obj.type; obj = obj.via) result.push(obj.type); + return result.reverse(); + } + for (var i = 0; i < match.next.length; i++) { + var _match$next$i2 = match.next[i], + type = _match$next$i2.type, + next = _match$next$i2.next; + if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) { + active.push({ + match: type.contentMatch, + type: type, + via: current + }); + seen[type.name] = true; + } + } + } + return null; + } + }, { + key: "edgeCount", + get: function get() { + return this.next.length; + } + }, { + key: "edge", + value: function edge(n) { + if (n >= this.next.length) throw new RangeError("There's no ".concat(n, "th edge in this content match")); + return this.next[n]; + } + }, { + key: "toString", + value: function toString() { + var seen = []; + function scan(m) { + seen.push(m); + for (var i = 0; i < m.next.length; i++) if (seen.indexOf(m.next[i].next) == -1) scan(m.next[i].next); + } + scan(this); + return seen.map(function (m, i) { + var out = i + (m.validEnd ? "*" : " ") + " "; + for (var _i = 0; _i < m.next.length; _i++) out += (_i ? ", " : "") + m.next[_i].type.name + "->" + seen.indexOf(m.next[_i].next); + return out; + }).join("\n"); + } + }], [{ + key: "parse", + value: function parse(string, nodeTypes) { + var stream = new TokenStream(string, nodeTypes); + if (stream.next == null) return ContentMatch.empty; + var expr = parseExpr(stream); + if (stream.next) stream.err("Unexpected trailing text"); + var match = dfa(nfa(expr)); + checkForDeadEnds(match, stream); + return match; + } + }]); + return ContentMatch; +}(); +ContentMatch.empty = new ContentMatch(true); +var TokenStream = function () { + function TokenStream(string, nodeTypes) { + _classCallCheck(this, TokenStream); + this.string = string; + this.nodeTypes = nodeTypes; + this.inline = null; + this.pos = 0; + this.tokens = string.split(/\s*(?=\b|\W|$)/); + if (this.tokens[this.tokens.length - 1] == "") this.tokens.pop(); + if (this.tokens[0] == "") this.tokens.shift(); + } + _createClass(TokenStream, [{ + key: "next", + get: function get() { + return this.tokens[this.pos]; + } + }, { + key: "eat", + value: function eat(tok) { + return this.next == tok && (this.pos++ || true); + } + }, { + key: "err", + value: function err(str) { + throw new SyntaxError(str + " (in content expression '" + this.string + "')"); + } + }]); + return TokenStream; +}(); +function parseExpr(stream) { + var exprs = []; + do { + exprs.push(parseExprSeq(stream)); + } while (stream.eat("|")); + return exprs.length == 1 ? exprs[0] : { + type: "choice", + exprs: exprs + }; +} +function parseExprSeq(stream) { + var exprs = []; + do { + exprs.push(parseExprSubscript(stream)); + } while (stream.next && stream.next != ")" && stream.next != "|"); + return exprs.length == 1 ? exprs[0] : { + type: "seq", + exprs: exprs + }; +} +function parseExprSubscript(stream) { + var expr = parseExprAtom(stream); + for (;;) { + if (stream.eat("+")) expr = { + type: "plus", + expr: expr + };else if (stream.eat("*")) expr = { + type: "star", + expr: expr + };else if (stream.eat("?")) expr = { + type: "opt", + expr: expr + };else if (stream.eat("{")) expr = parseExprRange(stream, expr);else break; + } + return expr; +} +function parseNum(stream) { + if (/\D/.test(stream.next)) stream.err("Expected number, got '" + stream.next + "'"); + var result = Number(stream.next); + stream.pos++; + return result; +} +function parseExprRange(stream, expr) { + var min = parseNum(stream), + max = min; + if (stream.eat(",")) { + if (stream.next != "}") max = parseNum(stream);else max = -1; + } + if (!stream.eat("}")) stream.err("Unclosed braced range"); + return { + type: "range", + min: min, + max: max, + expr: expr + }; +} +function resolveName(stream, name) { + var types = stream.nodeTypes, + type = types[name]; + if (type) return [type]; + var result = []; + for (var typeName in types) { + var _type = types[typeName]; + if (_type.isInGroup(name)) result.push(_type); + } + if (result.length == 0) stream.err("No node type or group '" + name + "' found"); + return result; +} +function parseExprAtom(stream) { + if (stream.eat("(")) { + var expr = parseExpr(stream); + if (!stream.eat(")")) stream.err("Missing closing paren"); + return expr; + } else if (!/\W/.test(stream.next)) { + var exprs = resolveName(stream, stream.next).map(function (type) { + if (stream.inline == null) stream.inline = type.isInline;else if (stream.inline != type.isInline) stream.err("Mixing inline and block content"); + return { + type: "name", + value: type + }; + }); + stream.pos++; + return exprs.length == 1 ? exprs[0] : { + type: "choice", + exprs: exprs + }; + } else { + stream.err("Unexpected token '" + stream.next + "'"); + } +} +function nfa(expr) { + var nfa = [[]]; + connect(compile(expr, 0), node()); + return nfa; + function node() { + return nfa.push([]) - 1; + } + function edge(from, to, term) { + var edge = { + term: term, + to: to + }; + nfa[from].push(edge); + return edge; + } + function connect(edges, to) { + edges.forEach(function (edge) { + return edge.to = to; + }); + } + function compile(expr, from) { + if (expr.type == "choice") { + return expr.exprs.reduce(function (out, expr) { + return out.concat(compile(expr, from)); + }, []); + } else if (expr.type == "seq") { + for (var i = 0;; i++) { + var next = compile(expr.exprs[i], from); + if (i == expr.exprs.length - 1) return next; + connect(next, from = node()); + } + } else if (expr.type == "star") { + var loop = node(); + edge(from, loop); + connect(compile(expr.expr, loop), loop); + return [edge(loop)]; + } else if (expr.type == "plus") { + var _loop = node(); + connect(compile(expr.expr, from), _loop); + connect(compile(expr.expr, _loop), _loop); + return [edge(_loop)]; + } else if (expr.type == "opt") { + return [edge(from)].concat(compile(expr.expr, from)); + } else if (expr.type == "range") { + var cur = from; + for (var _i2 = 0; _i2 < expr.min; _i2++) { + var _next = node(); + connect(compile(expr.expr, cur), _next); + cur = _next; + } + if (expr.max == -1) { + connect(compile(expr.expr, cur), cur); + } else { + for (var _i3 = expr.min; _i3 < expr.max; _i3++) { + var _next2 = node(); + edge(cur, _next2); + connect(compile(expr.expr, cur), _next2); + cur = _next2; + } + } + return [edge(cur)]; + } else if (expr.type == "name") { + return [edge(from, undefined, expr.value)]; + } else { + throw new Error("Unknown expr type"); + } + } +} +function cmp(a, b) { + return b - a; +} +function nullFrom(nfa, node) { + var result = []; + scan(node); + return result.sort(cmp); + function scan(node) { + var edges = nfa[node]; + if (edges.length == 1 && !edges[0].term) return scan(edges[0].to); + result.push(node); + for (var i = 0; i < edges.length; i++) { + var _edges$i = edges[i], + term = _edges$i.term, + to = _edges$i.to; + if (!term && result.indexOf(to) == -1) scan(to); + } + } +} +function dfa(nfa) { + var labeled = Object.create(null); + return explore(nullFrom(nfa, 0)); + function explore(states) { + var out = []; + states.forEach(function (node) { + nfa[node].forEach(function (_ref) { + var term = _ref.term, + to = _ref.to; + if (!term) return; + var set; + for (var i = 0; i < out.length; i++) if (out[i][0] == term) set = out[i][1]; + nullFrom(nfa, to).forEach(function (node) { + if (!set) out.push([term, set = []]); + if (set.indexOf(node) == -1) set.push(node); + }); + }); + }); + var state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1); + for (var i = 0; i < out.length; i++) { + var _states = out[i][1].sort(cmp); + state.next.push({ + type: out[i][0], + next: labeled[_states.join(",")] || explore(_states) + }); + } + return state; + } +} +function checkForDeadEnds(match, stream) { + for (var i = 0, work = [match]; i < work.length; i++) { + var state = work[i], + dead = !state.validEnd, + nodes = []; + for (var j = 0; j < state.next.length; j++) { + var _state$next$j = state.next[j], + type = _state$next$j.type, + next = _state$next$j.next; + nodes.push(type.name); + if (dead && !(type.isText || type.hasRequiredAttrs())) dead = false; + if (work.indexOf(next) == -1) work.push(next); + } + if (dead) stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)"); + } +} +function defaultAttrs(attrs) { + var defaults = Object.create(null); + for (var attrName in attrs) { + var attr = attrs[attrName]; + if (!attr.hasDefault) return null; + defaults[attrName] = attr["default"]; + } + return defaults; +} +function _computeAttrs(attrs, value) { + var built = Object.create(null); + for (var name in attrs) { + var given = value && value[name]; + if (given === undefined) { + var attr = attrs[name]; + if (attr.hasDefault) given = attr["default"];else throw new RangeError("No value supplied for attribute " + name); + } + built[name] = given; + } + return built; +} +function _checkAttrs(attrs, values, type, name) { + for (var _name in values) if (!(_name in attrs)) throw new RangeError("Unsupported attribute ".concat(_name, " for ").concat(type, " of type ").concat(_name)); + for (var _name2 in attrs) { + var attr = attrs[_name2]; + if (attr.validate) attr.validate(values[_name2]); + } +} +function initAttrs(typeName, attrs) { + var result = Object.create(null); + if (attrs) for (var name in attrs) result[name] = new Attribute(typeName, name, attrs[name]); + return result; +} +var NodeType = function () { + function NodeType(name, schema, spec) { + _classCallCheck(this, NodeType); + this.name = name; + this.schema = schema; + this.spec = spec; + this.markSet = null; + this.groups = spec.group ? spec.group.split(" ") : []; + this.attrs = initAttrs(name, spec.attrs); + this.defaultAttrs = defaultAttrs(this.attrs); + this.contentMatch = null; + this.inlineContent = null; + this.isBlock = !(spec.inline || name == "text"); + this.isText = name == "text"; + } + _createClass(NodeType, [{ + key: "isInline", + get: function get() { + return !this.isBlock; + } + }, { + key: "isTextblock", + get: function get() { + return this.isBlock && this.inlineContent; + } + }, { + key: "isLeaf", + get: function get() { + return this.contentMatch == ContentMatch.empty; + } + }, { + key: "isAtom", + get: function get() { + return this.isLeaf || !!this.spec.atom; + } + }, { + key: "isInGroup", + value: function isInGroup(group) { + return this.groups.indexOf(group) > -1; + } + }, { + key: "whitespace", + get: function get() { + return this.spec.whitespace || (this.spec.code ? "pre" : "normal"); + } + }, { + key: "hasRequiredAttrs", + value: function hasRequiredAttrs() { + for (var n in this.attrs) if (this.attrs[n].isRequired) return true; + return false; + } + }, { + key: "compatibleContent", + value: function compatibleContent(other) { + return this == other || this.contentMatch.compatible(other.contentMatch); + } + }, { + key: "computeAttrs", + value: function computeAttrs(attrs) { + if (!attrs && this.defaultAttrs) return this.defaultAttrs;else return _computeAttrs(this.attrs, attrs); + } + }, { + key: "create", + value: function create() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + if (this.isText) throw new Error("NodeType.create can't construct text nodes"); + return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks)); + } + }, { + key: "createChecked", + value: function createChecked() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + content = Fragment.from(content); + this.checkContent(content); + return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks)); + } + }, { + key: "createAndFill", + value: function createAndFill() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + attrs = this.computeAttrs(attrs); + content = Fragment.from(content); + if (content.size) { + var before = this.contentMatch.fillBefore(content); + if (!before) return null; + content = before.append(content); + } + var matched = this.contentMatch.matchFragment(content); + var after = matched && matched.fillBefore(Fragment.empty, true); + if (!after) return null; + return new Node(this, attrs, content.append(after), Mark.setFrom(marks)); + } + }, { + key: "validContent", + value: function validContent(content) { + var result = this.contentMatch.matchFragment(content); + if (!result || !result.validEnd) return false; + for (var i = 0; i < content.childCount; i++) if (!this.allowsMarks(content.child(i).marks)) return false; + return true; + } + }, { + key: "checkContent", + value: function checkContent(content) { + if (!this.validContent(content)) throw new RangeError("Invalid content for node ".concat(this.name, ": ").concat(content.toString().slice(0, 50))); + } + }, { + key: "checkAttrs", + value: function checkAttrs(attrs) { + _checkAttrs(this.attrs, attrs, "node", this.name); + } + }, { + key: "allowsMarkType", + value: function allowsMarkType(markType) { + return this.markSet == null || this.markSet.indexOf(markType) > -1; + } + }, { + key: "allowsMarks", + value: function allowsMarks(marks) { + if (this.markSet == null) return true; + for (var i = 0; i < marks.length; i++) if (!this.allowsMarkType(marks[i].type)) return false; + return true; + } + }, { + key: "allowedMarks", + value: function allowedMarks(marks) { + if (this.markSet == null) return marks; + var copy; + for (var i = 0; i < marks.length; i++) { + if (!this.allowsMarkType(marks[i].type)) { + if (!copy) copy = marks.slice(0, i); + } else if (copy) { + copy.push(marks[i]); + } + } + return !copy ? marks : copy.length ? copy : Mark.none; + } + }], [{ + key: "compile", + value: function compile(nodes, schema) { + var result = Object.create(null); + nodes.forEach(function (name, spec) { + return result[name] = new NodeType(name, schema, spec); + }); + var topType = schema.spec.topNode || "doc"; + if (!result[topType]) throw new RangeError("Schema is missing its top node type ('" + topType + "')"); + if (!result.text) throw new RangeError("Every schema needs a 'text' type"); + for (var _ in result.text.attrs) throw new RangeError("The text node type should not have attributes"); + return result; + } + }]); + return NodeType; +}(); +function validateType(typeName, attrName, type) { + var types = type.split("|"); + return function (value) { + var name = value === null ? "null" : _typeof(value); + if (types.indexOf(name) < 0) throw new RangeError("Expected value of type ".concat(types, " for attribute ").concat(attrName, " on type ").concat(typeName, ", got ").concat(name)); + }; +} +var Attribute = function () { + function Attribute(typeName, attrName, options) { + _classCallCheck(this, Attribute); + this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default"); + this["default"] = options["default"]; + this.validate = typeof options.validate == "string" ? validateType(typeName, attrName, options.validate) : options.validate; + } + _createClass(Attribute, [{ + key: "isRequired", + get: function get() { + return !this.hasDefault; + } + }]); + return Attribute; +}(); +var MarkType = function () { + function MarkType(name, rank, schema, spec) { + _classCallCheck(this, MarkType); + this.name = name; + this.rank = rank; + this.schema = schema; + this.spec = spec; + this.attrs = initAttrs(name, spec.attrs); + this.excluded = null; + var defaults = defaultAttrs(this.attrs); + this.instance = defaults ? new Mark(this, defaults) : null; + } + _createClass(MarkType, [{ + key: "create", + value: function create() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + if (!attrs && this.instance) return this.instance; + return new Mark(this, _computeAttrs(this.attrs, attrs)); + } + }, { + key: "removeFromSet", + value: function removeFromSet(set) { + for (var i = 0; i < set.length; i++) if (set[i].type == this) { + set = set.slice(0, i).concat(set.slice(i + 1)); + i--; + } + return set; + } + }, { + key: "isInSet", + value: function isInSet(set) { + for (var i = 0; i < set.length; i++) if (set[i].type == this) return set[i]; + } + }, { + key: "checkAttrs", + value: function checkAttrs(attrs) { + _checkAttrs(this.attrs, attrs, "mark", this.name); + } + }, { + key: "excludes", + value: function excludes(other) { + return this.excluded.indexOf(other) > -1; + } + }], [{ + key: "compile", + value: function compile(marks, schema) { + var result = Object.create(null), + rank = 0; + marks.forEach(function (name, spec) { + return result[name] = new MarkType(name, rank++, schema, spec); + }); + return result; + } + }]); + return MarkType; +}(); +var Schema = function () { + function Schema(spec) { + _classCallCheck(this, Schema); + this.linebreakReplacement = null; + this.cached = Object.create(null); + var instanceSpec = this.spec = {}; + for (var prop in spec) instanceSpec[prop] = spec[prop]; + instanceSpec.nodes = OrderedMap.from(spec.nodes), instanceSpec.marks = OrderedMap.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this); + this.marks = MarkType.compile(this.spec.marks, this); + var contentExprCache = Object.create(null); + for (var _prop in this.nodes) { + if (_prop in this.marks) throw new RangeError(_prop + " can not be both a node and a mark"); + var type = this.nodes[_prop], + contentExpr = type.spec.content || "", + markExpr = type.spec.marks; + type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes)); + type.inlineContent = type.contentMatch.inlineContent; + if (type.spec.linebreakReplacement) { + if (this.linebreakReplacement) throw new RangeError("Multiple linebreak nodes defined"); + if (!type.isInline || !type.isLeaf) throw new RangeError("Linebreak replacement nodes must be inline leaf nodes"); + this.linebreakReplacement = type; + } + type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null; + } + for (var _prop2 in this.marks) { + var _type2 = this.marks[_prop2], + excl = _type2.spec.excludes; + _type2.excluded = excl == null ? [_type2] : excl == "" ? [] : gatherMarks(this, excl.split(" ")); + } + this.nodeFromJSON = this.nodeFromJSON.bind(this); + this.markFromJSON = this.markFromJSON.bind(this); + this.topNodeType = this.nodes[this.spec.topNode || "doc"]; + this.cached.wrappings = Object.create(null); + } + _createClass(Schema, [{ + key: "node", + value: function node(type) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var content = arguments.length > 2 ? arguments[2] : undefined; + var marks = arguments.length > 3 ? arguments[3] : undefined; + if (typeof type == "string") type = this.nodeType(type);else if (!(type instanceof NodeType)) throw new RangeError("Invalid node type: " + type);else if (type.schema != this) throw new RangeError("Node type from different schema used (" + type.name + ")"); + return type.createChecked(attrs, content, marks); + } + }, { + key: "text", + value: function text(_text, marks) { + var type = this.nodes.text; + return new TextNode(type, type.defaultAttrs, _text, Mark.setFrom(marks)); + } + }, { + key: "mark", + value: function mark(type, attrs) { + if (typeof type == "string") type = this.marks[type]; + return type.create(attrs); + } + }, { + key: "nodeFromJSON", + value: function nodeFromJSON(json) { + return Node.fromJSON(this, json); + } + }, { + key: "markFromJSON", + value: function markFromJSON(json) { + return Mark.fromJSON(this, json); + } + }, { + key: "nodeType", + value: function nodeType(name) { + var found = this.nodes[name]; + if (!found) throw new RangeError("Unknown node type: " + name); + return found; + } + }]); + return Schema; +}(); +function gatherMarks(schema, marks) { + var found = []; + for (var i = 0; i < marks.length; i++) { + var name = marks[i], + mark = schema.marks[name], + ok = mark; + if (mark) { + found.push(mark); + } else { + for (var prop in schema.marks) { + var _mark = schema.marks[prop]; + if (name == "_" || _mark.spec.group && _mark.spec.group.split(" ").indexOf(name) > -1) found.push(ok = _mark); + } + } + if (!ok) throw new SyntaxError("Unknown mark type: '" + marks[i] + "'"); + } + return found; +} +function isTagRule(rule) { + return rule.tag != null; +} +function isStyleRule(rule) { + return rule.style != null; +} +var DOMParser = function () { + function DOMParser(schema, rules) { + var _this2 = this; + _classCallCheck(this, DOMParser); + this.schema = schema; + this.rules = rules; + this.tags = []; + this.styles = []; + var matchedStyles = this.matchedStyles = []; + rules.forEach(function (rule) { + if (isTagRule(rule)) { + _this2.tags.push(rule); + } else if (isStyleRule(rule)) { + var prop = /[^=]*/.exec(rule.style)[0]; + if (matchedStyles.indexOf(prop) < 0) matchedStyles.push(prop); + _this2.styles.push(rule); + } + }); + this.normalizeLists = !this.tags.some(function (r) { + if (!/^(ul|ol)\b/.test(r.tag) || !r.node) return false; + var node = schema.nodes[r.node]; + return node.contentMatch.matchType(node); + }); + } + _createClass(DOMParser, [{ + key: "parse", + value: function parse(dom) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var context = new ParseContext(this, options, false); + context.addAll(dom, Mark.none, options.from, options.to); + return context.finish(); + } + }, { + key: "parseSlice", + value: function parseSlice(dom) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var context = new ParseContext(this, options, true); + context.addAll(dom, Mark.none, options.from, options.to); + return Slice.maxOpen(context.finish()); + } + }, { + key: "matchTag", + value: function matchTag(dom, context, after) { + for (var i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) { + var rule = this.tags[i]; + if (matches(dom, rule.tag) && (rule.namespace === undefined || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) { + if (rule.getAttrs) { + var result = rule.getAttrs(dom); + if (result === false) continue; + rule.attrs = result || undefined; + } + return rule; + } + } + } + }, { + key: "matchStyle", + value: function matchStyle(prop, value, context, after) { + for (var i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) { + var rule = this.styles[i], + style = rule.style; + if (style.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || style.length > prop.length && (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value)) continue; + if (rule.getAttrs) { + var result = rule.getAttrs(value); + if (result === false) continue; + rule.attrs = result || undefined; + } + return rule; + } + } + }], [{ + key: "schemaRules", + value: function schemaRules(schema) { + var result = []; + function insert(rule) { + var priority = rule.priority == null ? 50 : rule.priority, + i = 0; + for (; i < result.length; i++) { + var next = result[i], + nextPriority = next.priority == null ? 50 : next.priority; + if (nextPriority < priority) break; + } + result.splice(i, 0, rule); + } + var _loop2 = function _loop2(name) { + var rules = schema.marks[name].spec.parseDOM; + if (rules) rules.forEach(function (rule) { + insert(rule = copy(rule)); + if (!(rule.mark || rule.ignore || rule.clearMark)) rule.mark = name; + }); + }; + for (var name in schema.marks) { + _loop2(name); + } + var _loop3 = function _loop3(_name3) { + var rules = schema.nodes[_name3].spec.parseDOM; + if (rules) rules.forEach(function (rule) { + insert(rule = copy(rule)); + if (!(rule.node || rule.ignore || rule.mark)) rule.node = _name3; + }); + }; + for (var _name3 in schema.nodes) { + _loop3(_name3); + } + return result; + } + }, { + key: "fromSchema", + value: function fromSchema(schema) { + return schema.cached.domParser || (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema))); + } + }]); + return DOMParser; +}(); +var blockTags = { + address: true, + article: true, + aside: true, + blockquote: true, + canvas: true, + dd: true, + div: true, + dl: true, + fieldset: true, + figcaption: true, + figure: true, + footer: true, + form: true, + h1: true, + h2: true, + h3: true, + h4: true, + h5: true, + h6: true, + header: true, + hgroup: true, + hr: true, + li: true, + noscript: true, + ol: true, + output: true, + p: true, + pre: true, + section: true, + table: true, + tfoot: true, + ul: true +}; +var ignoreTags = { + head: true, + noscript: true, + object: true, + script: true, + style: true, + title: true +}; +var listTags = { + ol: true, + ul: true +}; +var OPT_PRESERVE_WS = 1, + OPT_PRESERVE_WS_FULL = 2, + OPT_OPEN_LEFT = 4; +function wsOptionsFor(type, preserveWhitespace, base) { + if (preserveWhitespace != null) return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0); + return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT; +} +var NodeContext = function () { + function NodeContext(type, attrs, marks, solid, match, options) { + _classCallCheck(this, NodeContext); + this.type = type; + this.attrs = attrs; + this.marks = marks; + this.solid = solid; + this.options = options; + this.content = []; + this.activeMarks = Mark.none; + this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch); + } + _createClass(NodeContext, [{ + key: "findWrapping", + value: function findWrapping(node) { + if (!this.match) { + if (!this.type) return []; + var fill = this.type.contentMatch.fillBefore(Fragment.from(node)); + if (fill) { + this.match = this.type.contentMatch.matchFragment(fill); + } else { + var start = this.type.contentMatch, + wrap; + if (wrap = start.findWrapping(node.type)) { + this.match = start; + return wrap; + } else { + return null; + } + } + } + return this.match.findWrapping(node.type); + } + }, { + key: "finish", + value: function finish(openEnd) { + if (!(this.options & OPT_PRESERVE_WS)) { + var last = this.content[this.content.length - 1], + m; + if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) { + var text = last; + if (last.text.length == m[0].length) this.content.pop();else this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length)); + } + } + var content = Fragment.from(this.content); + if (!openEnd && this.match) content = content.append(this.match.fillBefore(Fragment.empty, true)); + return this.type ? this.type.create(this.attrs, content, this.marks) : content; + } + }, { + key: "inlineContext", + value: function inlineContext(node) { + if (this.type) return this.type.inlineContent; + if (this.content.length) return this.content[0].isInline; + return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase()); + } + }]); + return NodeContext; +}(); +var ParseContext = function () { + function ParseContext(parser, options, isOpen) { + _classCallCheck(this, ParseContext); + this.parser = parser; + this.options = options; + this.isOpen = isOpen; + this.open = 0; + var topNode = options.topNode, + topContext; + var topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0); + if (topNode) topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);else if (isOpen) topContext = new NodeContext(null, null, Mark.none, true, null, topOptions);else topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions); + this.nodes = [topContext]; + this.find = options.findPositions; + this.needsBlock = false; + } + _createClass(ParseContext, [{ + key: "top", + get: function get() { + return this.nodes[this.open]; + } + }, { + key: "addDOM", + value: function addDOM(dom, marks) { + if (dom.nodeType == 3) this.addTextNode(dom, marks);else if (dom.nodeType == 1) this.addElement(dom, marks); + } + }, { + key: "addTextNode", + value: function addTextNode(dom, marks) { + var value = dom.nodeValue; + var top = this.top; + if (top.options & OPT_PRESERVE_WS_FULL || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) { + if (!(top.options & OPT_PRESERVE_WS)) { + value = value.replace(/[ \t\r\n\u000c]+/g, " "); + if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) { + var nodeBefore = top.content[top.content.length - 1]; + var domNodeBefore = dom.previousSibling; + if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == 'BR' || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text)) value = value.slice(1); + } + } else if (!(top.options & OPT_PRESERVE_WS_FULL)) { + value = value.replace(/\r?\n|\r/g, " "); + } else { + value = value.replace(/\r\n?/g, "\n"); + } + if (value) this.insertNode(this.parser.schema.text(value), marks); + this.findInText(dom); + } else { + this.findInside(dom); + } + } + }, { + key: "addElement", + value: function addElement(dom, marks, matchAfter) { + var name = dom.nodeName.toLowerCase(), + ruleID; + if (listTags.hasOwnProperty(name) && this.parser.normalizeLists) normalizeList(dom); + var rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter)); + if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) { + this.findInside(dom); + this.ignoreFallback(dom, marks); + } else if (!rule || rule.skip || rule.closeParent) { + if (rule && rule.closeParent) this.open = Math.max(0, this.open - 1);else if (rule && rule.skip.nodeType) dom = rule.skip; + var sync, + top = this.top, + oldNeedsBlock = this.needsBlock; + if (blockTags.hasOwnProperty(name)) { + if (top.content.length && top.content[0].isInline && this.open) { + this.open--; + top = this.top; + } + sync = true; + if (!top.type) this.needsBlock = true; + } else if (!dom.firstChild) { + this.leafFallback(dom, marks); + return; + } + var innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks); + if (innerMarks) this.addAll(dom, innerMarks); + if (sync) this.sync(top); + this.needsBlock = oldNeedsBlock; + } else { + var _innerMarks = this.readStyles(dom, marks); + if (_innerMarks) this.addElementByRule(dom, rule, _innerMarks, rule.consuming === false ? ruleID : undefined); + } + } + }, { + key: "leafFallback", + value: function leafFallback(dom, marks) { + if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent) this.addTextNode(dom.ownerDocument.createTextNode("\n"), marks); + } + }, { + key: "ignoreFallback", + value: function ignoreFallback(dom, marks) { + if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent)) this.findPlace(this.parser.schema.text("-"), marks); + } + }, { + key: "readStyles", + value: function readStyles(dom, marks) { + var _this3 = this; + var styles = dom.style; + if (styles && styles.length) for (var i = 0; i < this.parser.matchedStyles.length; i++) { + var name = this.parser.matchedStyles[i], + value = styles.getPropertyValue(name); + if (value) { + var _loop4 = function _loop4(_after) { + var rule = _this3.parser.matchStyle(name, value, _this3, _after); + if (!rule) { + after = _after; + return 0; + } + if (rule.ignore) return { + v: null + }; + if (rule.clearMark) marks = marks.filter(function (m) { + return !rule.clearMark(m); + });else marks = marks.concat(_this3.parser.schema.marks[rule.mark].create(rule.attrs)); + if (rule.consuming === false) _after = rule;else { + after = _after; + return 0; + } + after = _after; + }, + _ret; + for (var after = undefined;;) { + _ret = _loop4(after); + if (_ret === 0) break; + if (_ret) return _ret.v; + } + } + } + return marks; + } + }, { + key: "addElementByRule", + value: function addElementByRule(dom, rule, marks, continueAfter) { + var _this4 = this; + var sync, nodeType; + if (rule.node) { + nodeType = this.parser.schema.nodes[rule.node]; + if (!nodeType.isLeaf) { + var inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace); + if (inner) { + sync = true; + marks = inner; + } + } else if (!this.insertNode(nodeType.create(rule.attrs), marks)) { + this.leafFallback(dom, marks); + } + } else { + var markType = this.parser.schema.marks[rule.mark]; + marks = marks.concat(markType.create(rule.attrs)); + } + var startIn = this.top; + if (nodeType && nodeType.isLeaf) { + this.findInside(dom); + } else if (continueAfter) { + this.addElement(dom, marks, continueAfter); + } else if (rule.getContent) { + this.findInside(dom); + rule.getContent(dom, this.parser.schema).forEach(function (node) { + return _this4.insertNode(node, marks); + }); + } else { + var contentDOM = dom; + if (typeof rule.contentElement == "string") contentDOM = dom.querySelector(rule.contentElement);else if (typeof rule.contentElement == "function") contentDOM = rule.contentElement(dom);else if (rule.contentElement) contentDOM = rule.contentElement; + this.findAround(dom, contentDOM, true); + this.addAll(contentDOM, marks); + this.findAround(dom, contentDOM, false); + } + if (sync && this.sync(startIn)) this.open--; + } + }, { + key: "addAll", + value: function addAll(parent, marks, startIndex, endIndex) { + var index = startIndex || 0; + for (var dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) { + this.findAtPoint(parent, index); + this.addDOM(dom, marks); + } + this.findAtPoint(parent, index); + } + }, { + key: "findPlace", + value: function findPlace(node, marks) { + var route, sync; + for (var depth = this.open; depth >= 0; depth--) { + var cx = this.nodes[depth]; + var _found2 = cx.findWrapping(node); + if (_found2 && (!route || route.length > _found2.length)) { + route = _found2; + sync = cx; + if (!_found2.length) break; + } + if (cx.solid) break; + } + if (!route) return null; + this.sync(sync); + for (var i = 0; i < route.length; i++) marks = this.enterInner(route[i], null, marks, false); + return marks; + } + }, { + key: "insertNode", + value: function insertNode(node, marks) { + if (node.isInline && this.needsBlock && !this.top.type) { + var block = this.textblockFromContext(); + if (block) marks = this.enterInner(block, null, marks); + } + var innerMarks = this.findPlace(node, marks); + if (innerMarks) { + this.closeExtra(); + var top = this.top; + if (top.match) top.match = top.match.matchType(node.type); + var nodeMarks = Mark.none; + var _iterator = _createForOfIteratorHelper(innerMarks.concat(node.marks)), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var m = _step.value; + if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type)) nodeMarks = m.addToSet(nodeMarks); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + top.content.push(node.mark(nodeMarks)); + return true; + } + return false; + } + }, { + key: "enter", + value: function enter(type, attrs, marks, preserveWS) { + var innerMarks = this.findPlace(type.create(attrs), marks); + if (innerMarks) innerMarks = this.enterInner(type, attrs, marks, true, preserveWS); + return innerMarks; + } + }, { + key: "enterInner", + value: function enterInner(type, attrs, marks) { + var solid = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + var preserveWS = arguments.length > 4 ? arguments[4] : undefined; + this.closeExtra(); + var top = this.top; + top.match = top.match && top.match.matchType(type); + var options = wsOptionsFor(type, preserveWS, top.options); + if (top.options & OPT_OPEN_LEFT && top.content.length == 0) options |= OPT_OPEN_LEFT; + var applyMarks = Mark.none; + marks = marks.filter(function (m) { + if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) { + applyMarks = m.addToSet(applyMarks); + return false; + } + return true; + }); + this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options)); + this.open++; + return marks; + } + }, { + key: "closeExtra", + value: function closeExtra() { + var openEnd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var i = this.nodes.length - 1; + if (i > this.open) { + for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)); + this.nodes.length = this.open + 1; + } + } + }, { + key: "finish", + value: function finish() { + this.open = 0; + this.closeExtra(this.isOpen); + return this.nodes[0].finish(this.isOpen || this.options.topOpen); + } + }, { + key: "sync", + value: function sync(to) { + for (var i = this.open; i >= 0; i--) if (this.nodes[i] == to) { + this.open = i; + return true; + } + return false; + } + }, { + key: "currentPos", + get: function get() { + this.closeExtra(); + var pos = 0; + for (var i = this.open; i >= 0; i--) { + var content = this.nodes[i].content; + for (var j = content.length - 1; j >= 0; j--) pos += content[j].nodeSize; + if (i) pos++; + } + return pos; + } + }, { + key: "findAtPoint", + value: function findAtPoint(parent, offset) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == parent && this.find[i].offset == offset) this.find[i].pos = this.currentPos; + } + } + }, { + key: "findInside", + value: function findInside(parent) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) this.find[i].pos = this.currentPos; + } + } + }, { + key: "findAround", + value: function findAround(parent, content, before) { + if (parent != content && this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) { + var pos = content.compareDocumentPosition(this.find[i].node); + if (pos & (before ? 2 : 4)) this.find[i].pos = this.currentPos; + } + } + } + }, { + key: "findInText", + value: function findInText(textNode) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == textNode) this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset); + } + } + }, { + key: "matchesContext", + value: function matchesContext(context) { + var _this5 = this; + if (context.indexOf("|") > -1) return context.split(/\s*\|\s*/).some(this.matchesContext, this); + var parts = context.split("/"); + var option = this.options.context; + var useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type); + var minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1); + var match = function match(i, depth) { + for (; i >= 0; i--) { + var part = parts[i]; + if (part == "") { + if (i == parts.length - 1 || i == 0) continue; + for (; depth >= minDepth; depth--) if (match(i - 1, depth)) return true; + return false; + } else { + var next = depth > 0 || depth == 0 && useRoot ? _this5.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null; + if (!next || next.name != part && !next.isInGroup(part)) return false; + depth--; + } + } + return true; + }; + return match(parts.length - 1, this.open); + } + }, { + key: "textblockFromContext", + value: function textblockFromContext() { + var $context = this.options.context; + if ($context) for (var d = $context.depth; d >= 0; d--) { + var deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType; + if (deflt && deflt.isTextblock && deflt.defaultAttrs) return deflt; + } + for (var name in this.parser.schema.nodes) { + var type = this.parser.schema.nodes[name]; + if (type.isTextblock && type.defaultAttrs) return type; + } + } + }]); + return ParseContext; +}(); +function normalizeList(dom) { + for (var child = dom.firstChild, prevItem = null; child; child = child.nextSibling) { + var name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null; + if (name && listTags.hasOwnProperty(name) && prevItem) { + prevItem.appendChild(child); + child = prevItem; + } else if (name == "li") { + prevItem = child; + } else if (name) { + prevItem = null; + } + } +} +function matches(dom, selector) { + return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector); +} +function copy(obj) { + var copy = {}; + for (var prop in obj) copy[prop] = obj[prop]; + return copy; +} +function markMayApply(markType, nodeType) { + var nodes = nodeType.schema.nodes; + var _loop5 = function _loop5() { + var parent = nodes[name]; + if (!parent.allowsMarkType(markType)) return 0; + var seen = [], + scan = function scan(match) { + seen.push(match); + for (var i = 0; i < match.edgeCount; i++) { + var _match$edge = match.edge(i), + type = _match$edge.type, + next = _match$edge.next; + if (type == nodeType) return true; + if (seen.indexOf(next) < 0 && scan(next)) return true; + } + }; + if (scan(parent.contentMatch)) return { + v: true + }; + }, + _ret2; + for (var name in nodes) { + _ret2 = _loop5(); + if (_ret2 === 0) continue; + if (_ret2) return _ret2.v; + } +} +var DOMSerializer = function () { + function DOMSerializer(nodes, marks) { + _classCallCheck(this, DOMSerializer); + this.nodes = nodes; + this.marks = marks; + } + _createClass(DOMSerializer, [{ + key: "serializeFragment", + value: function serializeFragment(fragment) { + var _this6 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var target = arguments.length > 2 ? arguments[2] : undefined; + if (!target) target = doc(options).createDocumentFragment(); + var top = target, + active = []; + fragment.forEach(function (node) { + if (active.length || node.marks.length) { + var keep = 0, + rendered = 0; + while (keep < active.length && rendered < node.marks.length) { + var next = node.marks[rendered]; + if (!_this6.marks[next.type.name]) { + rendered++; + continue; + } + if (!next.eq(active[keep][0]) || next.type.spec.spanning === false) break; + keep++; + rendered++; + } + while (keep < active.length) top = active.pop()[1]; + while (rendered < node.marks.length) { + var add = node.marks[rendered++]; + var markDOM = _this6.serializeMark(add, node.isInline, options); + if (markDOM) { + active.push([add, top]); + top.appendChild(markDOM.dom); + top = markDOM.contentDOM || markDOM.dom; + } + } + } + top.appendChild(_this6.serializeNodeInner(node, options)); + }); + return target; + } + }, { + key: "serializeNodeInner", + value: function serializeNodeInner(node, options) { + var _renderSpec2 = _renderSpec(doc(options), this.nodes[node.type.name](node), null, node.attrs), + dom = _renderSpec2.dom, + contentDOM = _renderSpec2.contentDOM; + if (contentDOM) { + if (node.isLeaf) throw new RangeError("Content hole not allowed in a leaf node spec"); + this.serializeFragment(node.content, options, contentDOM); + } + return dom; + } + }, { + key: "serializeNode", + value: function serializeNode(node) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var dom = this.serializeNodeInner(node, options); + for (var i = node.marks.length - 1; i >= 0; i--) { + var wrap = this.serializeMark(node.marks[i], node.isInline, options); + if (wrap) { + (wrap.contentDOM || wrap.dom).appendChild(dom); + dom = wrap.dom; + } + } + return dom; + } + }, { + key: "serializeMark", + value: function serializeMark(mark, inline) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var toDOM = this.marks[mark.type.name]; + return toDOM && _renderSpec(doc(options), toDOM(mark, inline), null, mark.attrs); + } + }], [{ + key: "renderSpec", + value: function renderSpec(doc, structure) { + var xmlNS = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var blockArraysIn = arguments.length > 3 ? arguments[3] : undefined; + return _renderSpec(doc, structure, xmlNS, blockArraysIn); + } + }, { + key: "fromSchema", + value: function fromSchema(schema) { + return schema.cached.domSerializer || (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema))); + } + }, { + key: "nodesFromSchema", + value: function nodesFromSchema(schema) { + var result = gatherToDOM(schema.nodes); + if (!result.text) result.text = function (node) { + return node.text; + }; + return result; + } + }, { + key: "marksFromSchema", + value: function marksFromSchema(schema) { + return gatherToDOM(schema.marks); + } + }]); + return DOMSerializer; +}(); +function gatherToDOM(obj) { + var result = {}; + for (var name in obj) { + var toDOM = obj[name].spec.toDOM; + if (toDOM) result[name] = toDOM; + } + return result; +} +function doc(options) { + return options.document || window.document; +} +var suspiciousAttributeCache = new WeakMap(); +function suspiciousAttributes(attrs) { + var value = suspiciousAttributeCache.get(attrs); + if (value === undefined) suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs)); + return value; +} +function suspiciousAttributesInner(attrs) { + var result = null; + function scan(value) { + if (value && _typeof(value) == "object") { + if (Array.isArray(value)) { + if (typeof value[0] == "string") { + if (!result) result = []; + result.push(value); + } else { + for (var i = 0; i < value.length; i++) scan(value[i]); + } + } else { + for (var prop in value) scan(value[prop]); + } + } + } + scan(attrs); + return result; +} +function _renderSpec(doc, structure, xmlNS, blockArraysIn) { + if (typeof structure == "string") return { + dom: doc.createTextNode(structure) + }; + if (structure.nodeType != null) return { + dom: structure + }; + if (structure.dom && structure.dom.nodeType != null) return structure; + var tagName = structure[0], + suspicious; + if (typeof tagName != "string") throw new RangeError("Invalid array passed to renderSpec"); + if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1) throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack."); + var space = tagName.indexOf(" "); + if (space > 0) { + xmlNS = tagName.slice(0, space); + tagName = tagName.slice(space + 1); + } + var contentDOM; + var dom = xmlNS ? doc.createElementNS(xmlNS, tagName) : doc.createElement(tagName); + var attrs = structure[1], + start = 1; + if (attrs && _typeof(attrs) == "object" && attrs.nodeType == null && !Array.isArray(attrs)) { + start = 2; + for (var name in attrs) if (attrs[name] != null) { + var _space = name.indexOf(" "); + if (_space > 0) dom.setAttributeNS(name.slice(0, _space), name.slice(_space + 1), attrs[name]);else dom.setAttribute(name, attrs[name]); + } + } + for (var i = start; i < structure.length; i++) { + var child = structure[i]; + if (child === 0) { + if (i < structure.length - 1 || i > start) throw new RangeError("Content hole must be the only child of its parent node"); + return { + dom: dom, + contentDOM: dom + }; + } else { + var _renderSpec3 = _renderSpec(doc, child, xmlNS, blockArraysIn), + inner = _renderSpec3.dom, + innerContent = _renderSpec3.contentDOM; + dom.appendChild(inner); + if (innerContent) { + if (contentDOM) throw new RangeError("Multiple content holes"); + contentDOM = innerContent; + } + } + } + return { + dom: dom, + contentDOM: contentDOM + }; +} +exports.ContentMatch = ContentMatch; +exports.DOMParser = DOMParser; +exports.DOMSerializer = DOMSerializer; +exports.Fragment = Fragment; +exports.Mark = Mark; +exports.MarkType = MarkType; +exports.Node = Node; +exports.NodeRange = NodeRange; +exports.NodeType = NodeType; +exports.ReplaceError = ReplaceError; +exports.ResolvedPos = ResolvedPos; +exports.Schema = Schema; +exports.Slice = Slice; + +}); +define("prosemirror-schema-list",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorState = require('prosemirror-state'); +var olDOM = ["ol", 0], + ulDOM = ["ul", 0], + liDOM = ["li", 0]; +var orderedList = { + attrs: { + order: { + "default": 1, + validate: "number" + } + }, + parseDOM: [{ + tag: "ol", + getAttrs: function getAttrs(dom) { + return { + order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1 + }; + } + }], + toDOM: function toDOM(node) { + return node.attrs.order == 1 ? olDOM : ["ol", { + start: node.attrs.order + }, 0]; + } +}; +var bulletList = { + parseDOM: [{ + tag: "ul" + }], + toDOM: function toDOM() { + return ulDOM; + } +}; +var listItem = { + parseDOM: [{ + tag: "li" + }], + toDOM: function toDOM() { + return liDOM; + }, + defining: true +}; +function add(obj, props) { + var copy = {}; + for (var prop in obj) copy[prop] = obj[prop]; + for (var _prop in props) copy[_prop] = props[_prop]; + return copy; +} +function addListNodes(nodes, itemContent, listGroup) { + return nodes.append({ + ordered_list: add(orderedList, { + content: "list_item+", + group: listGroup + }), + bullet_list: add(bulletList, { + content: "list_item+", + group: listGroup + }), + list_item: add(listItem, { + content: itemContent + }) + }); +} +function wrapInList(listType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var _state$selection = state.selection, + $from = _state$selection.$from, + $to = _state$selection.$to; + var range = $from.blockRange($to), + doJoin = false, + outerRange = range; + if (!range) return false; + if (range.depth >= 2 && $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex == 0) { + if ($from.index(range.depth - 1) == 0) return false; + var $insert = state.doc.resolve(range.start - 2); + outerRange = new prosemirrorModel.NodeRange($insert, $insert, range.depth); + if (range.endIndex < range.parent.childCount) range = new prosemirrorModel.NodeRange($from, state.doc.resolve($to.end(range.depth)), range.depth); + doJoin = true; + } + var wrap = prosemirrorTransform.findWrapping(outerRange, listType, attrs, range); + if (!wrap) return false; + if (dispatch) dispatch(doWrapInList(state.tr, range, wrap, doJoin, listType).scrollIntoView()); + return true; + }; +} +function doWrapInList(tr, range, wrappers, joinBefore, listType) { + var content = prosemirrorModel.Fragment.empty; + for (var i = wrappers.length - 1; i >= 0; i--) content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); + tr.step(new prosemirrorTransform.ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true)); + var found = 0; + for (var _i = 0; _i < wrappers.length; _i++) if (wrappers[_i].type == listType) found = _i + 1; + var splitDepth = wrappers.length - found; + var splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), + parent = range.parent; + for (var _i2 = range.startIndex, e = range.endIndex, first = true; _i2 < e; _i2++, first = false) { + if (!first && prosemirrorTransform.canSplit(tr.doc, splitPos, splitDepth)) { + tr.split(splitPos, splitDepth); + splitPos += 2 * splitDepth; + } + splitPos += parent.child(_i2).nodeSize; + } + return tr; +} +function splitListItem(itemType, itemAttrs) { + return function (state, dispatch) { + var _state$selection2 = state.selection, + $from = _state$selection2.$from, + $to = _state$selection2.$to, + node = _state$selection2.node; + if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; + var grandParent = $from.node(-1); + if (grandParent.type != itemType) return false; + if ($from.parent.content.size == 0 && $from.node(-1).childCount == $from.indexAfter(-1)) { + if ($from.depth == 3 || $from.node(-3).type != itemType || $from.index(-2) != $from.node(-2).childCount - 1) return false; + if (dispatch) { + var wrap = prosemirrorModel.Fragment.empty; + var depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3; + for (var d = $from.depth - depthBefore; d >= $from.depth - 3; d--) wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); + var depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3; + wrap = wrap.append(prosemirrorModel.Fragment.from(itemType.createAndFill())); + var start = $from.before($from.depth - (depthBefore - 1)); + var _tr = state.tr.replace(start, $from.after(-depthAfter), new prosemirrorModel.Slice(wrap, 4 - depthBefore, 0)); + var sel = -1; + _tr.doc.nodesBetween(start, _tr.doc.content.size, function (node, pos) { + if (sel > -1) return false; + if (node.isTextblock && node.content.size == 0) sel = pos + 1; + }); + if (sel > -1) _tr.setSelection(prosemirrorState.Selection.near(_tr.doc.resolve(sel))); + dispatch(_tr.scrollIntoView()); + } + return true; + } + var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt(0).defaultType : null; + var tr = state.tr["delete"]($from.pos, $to.pos); + var types = nextType ? [itemAttrs ? { + type: itemType, + attrs: itemAttrs + } : null, { + type: nextType + }] : undefined; + if (!prosemirrorTransform.canSplit(tr.doc, $from.pos, 2, types)) return false; + if (dispatch) dispatch(tr.split($from.pos, 2, types).scrollIntoView()); + return true; + }; +} +function splitListItemKeepMarks(itemType, itemAttrs) { + var split = splitListItem(itemType, itemAttrs); + return function (state, dispatch) { + return split(state, dispatch && function (tr) { + var marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks(); + if (marks) tr.ensureMarks(marks); + dispatch(tr); + }); + }; +} +function liftListItem(itemType) { + return function (state, dispatch) { + var _state$selection3 = state.selection, + $from = _state$selection3.$from, + $to = _state$selection3.$to; + var range = $from.blockRange($to, function (node) { + return node.childCount > 0 && node.firstChild.type == itemType; + }); + if (!range) return false; + if (!dispatch) return true; + if ($from.node(range.depth - 1).type == itemType) return liftToOuterList(state, dispatch, itemType, range);else return liftOutOfList(state, dispatch, range); + }; +} +function liftToOuterList(state, dispatch, itemType, range) { + var tr = state.tr, + end = range.end, + endOfList = range.$to.end(range.depth); + if (end < endOfList) { + tr.step(new prosemirrorTransform.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true)); + range = new prosemirrorModel.NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth); + } + var target = prosemirrorTransform.liftTarget(range); + if (target == null) return false; + tr.lift(range, target); + var after = tr.mapping.map(end, -1) - 1; + if (prosemirrorTransform.canJoin(tr.doc, after)) tr.join(after); + dispatch(tr.scrollIntoView()); + return true; +} +function liftOutOfList(state, dispatch, range) { + var tr = state.tr, + list = range.parent; + for (var pos = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) { + pos -= list.child(i).nodeSize; + tr["delete"](pos - 1, pos + 1); + } + var $start = tr.doc.resolve(range.start), + item = $start.nodeAfter; + if (tr.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) return false; + var atStart = range.startIndex == 0, + atEnd = range.endIndex == list.childCount; + var parent = $start.node(-1), + indexBefore = $start.index(-1); + if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list)))) return false; + var start = $start.pos, + end = start + item.nodeSize; + tr.step(new prosemirrorTransform.ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new prosemirrorModel.Slice((atStart ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list.copy(prosemirrorModel.Fragment.empty))).append(atEnd ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list.copy(prosemirrorModel.Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1)); + dispatch(tr.scrollIntoView()); + return true; +} +function sinkListItem(itemType) { + return function (state, dispatch) { + var _state$selection4 = state.selection, + $from = _state$selection4.$from, + $to = _state$selection4.$to; + var range = $from.blockRange($to, function (node) { + return node.childCount > 0 && node.firstChild.type == itemType; + }); + if (!range) return false; + var startIndex = range.startIndex; + if (startIndex == 0) return false; + var parent = range.parent, + nodeBefore = parent.child(startIndex - 1); + if (nodeBefore.type != itemType) return false; + if (dispatch) { + var nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type; + var inner = prosemirrorModel.Fragment.from(nestedBefore ? itemType.create() : null); + var slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(itemType.create(null, prosemirrorModel.Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0); + var before = range.start, + after = range.end; + dispatch(state.tr.step(new prosemirrorTransform.ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice, 1, true)).scrollIntoView()); + } + return true; + }; +} +exports.addListNodes = addListNodes; +exports.bulletList = bulletList; +exports.liftListItem = liftListItem; +exports.listItem = listItem; +exports.orderedList = orderedList; +exports.sinkListItem = sinkListItem; +exports.splitListItem = splitListItem; +exports.splitListItemKeepMarks = splitListItemKeepMarks; +exports.wrapInList = wrapInList; + +}); +define("prosemirror-state",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } + +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } + +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorModel = require('prosemirror-model'); + +var prosemirrorTransform = require('prosemirror-transform'); + +var classesById = Object.create(null); + +var Selection = function () { + function Selection($anchor, $head, ranges) { + _classCallCheck(this, Selection); + + this.$anchor = $anchor; + this.$head = $head; + this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))]; + } + + _createClass(Selection, [{ + key: "anchor", + get: function get() { + return this.$anchor.pos; + } + }, { + key: "head", + get: function get() { + return this.$head.pos; + } + }, { + key: "from", + get: function get() { + return this.$from.pos; + } + }, { + key: "to", + get: function get() { + return this.$to.pos; + } + }, { + key: "$from", + get: function get() { + return this.ranges[0].$from; + } + }, { + key: "$to", + get: function get() { + return this.ranges[0].$to; + } + }, { + key: "empty", + get: function get() { + var ranges = this.ranges; + + for (var i = 0; i < ranges.length; i++) { + if (ranges[i].$from.pos != ranges[i].$to.pos) return false; + } + + return true; + } + }, { + key: "content", + value: function content() { + return this.$from.doc.slice(this.from, this.to, true); + } + }, { + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + var lastNode = content.content.lastChild, + lastParent = null; + + for (var i = 0; i < content.openEnd; i++) { + lastParent = lastNode; + lastNode = lastNode.lastChild; + } + + var mapFrom = tr.steps.length, + ranges = this.ranges; + + for (var _i = 0; _i < ranges.length; _i++) { + var _ranges$_i = ranges[_i], + $from = _ranges$_i.$from, + $to = _ranges$_i.$to, + mapping = tr.mapping.slice(mapFrom); + tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), _i ? prosemirrorModel.Slice.empty : content); + if (_i == 0) selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1); + } + } + }, { + key: "replaceWith", + value: function replaceWith(tr, node) { + var mapFrom = tr.steps.length, + ranges = this.ranges; + + for (var i = 0; i < ranges.length; i++) { + var _ranges$i = ranges[i], + $from = _ranges$i.$from, + $to = _ranges$i.$to, + mapping = tr.mapping.slice(mapFrom); + var from = mapping.map($from.pos), + to = mapping.map($to.pos); + + if (i) { + tr.deleteRange(from, to); + } else { + tr.replaceRangeWith(from, to, node); + selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1); + } + } + } + }, { + key: "getBookmark", + value: function getBookmark() { + return TextSelection.between(this.$anchor, this.$head).getBookmark(); + } + }], [{ + key: "findFrom", + value: function findFrom($pos, dir) { + var textOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly); + if (inner) return inner; + + for (var depth = $pos.depth - 1; depth >= 0; depth--) { + var found = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly); + if (found) return found; + } + + return null; + } + }, { + key: "near", + value: function near($pos) { + var bias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0)); + } + }, { + key: "atStart", + value: function atStart(doc) { + return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc); + } + }, { + key: "atEnd", + value: function atEnd(doc) { + return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc); + } + }, { + key: "fromJSON", + value: function fromJSON(doc, json) { + if (!json || !json.type) throw new RangeError("Invalid input for Selection.fromJSON"); + var cls = classesById[json.type]; + if (!cls) throw new RangeError("No selection type ".concat(json.type, " defined")); + return cls.fromJSON(doc, json); + } + }, { + key: "jsonID", + value: function jsonID(id, selectionClass) { + if (id in classesById) throw new RangeError("Duplicate use of selection JSON ID " + id); + classesById[id] = selectionClass; + selectionClass.prototype.jsonID = id; + return selectionClass; + } + }]); + + return Selection; +}(); + +Selection.prototype.visible = true; + +var SelectionRange = _createClass(function SelectionRange($from, $to) { + _classCallCheck(this, SelectionRange); + + this.$from = $from; + this.$to = $to; +}); + +var warnedAboutTextSelection = false; + +function checkTextSelection($pos) { + if (!warnedAboutTextSelection && !$pos.parent.inlineContent) { + warnedAboutTextSelection = true; + console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")"); + } +} + +var TextSelection = function (_Selection) { + _inherits(TextSelection, _Selection); + + var _super = _createSuper(TextSelection); + + function TextSelection($anchor) { + var $head = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchor; + + _classCallCheck(this, TextSelection); + + checkTextSelection($anchor); + checkTextSelection($head); + return _super.call(this, $anchor, $head); + } + + _createClass(TextSelection, [{ + key: "$cursor", + get: function get() { + return this.$anchor.pos == this.$head.pos ? this.$head : null; + } + }, { + key: "map", + value: function map(doc, mapping) { + var $head = doc.resolve(mapping.map(this.head)); + if (!$head.parent.inlineContent) return Selection.near($head); + var $anchor = doc.resolve(mapping.map(this.anchor)); + return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head); + } + }, { + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + + _get(_getPrototypeOf(TextSelection.prototype), "replace", this).call(this, tr, content); + + if (content == prosemirrorModel.Slice.empty) { + var marks = this.$from.marksAcross(this.$to); + if (marks) tr.ensureMarks(marks); + } + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new TextBookmark(this.anchor, this.head); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "text", + anchor: this.anchor, + head: this.head + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.anchor != "number" || typeof json.head != "number") throw new RangeError("Invalid input for TextSelection.fromJSON"); + return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head)); + } + }, { + key: "create", + value: function create(doc, anchor) { + var head = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : anchor; + var $anchor = doc.resolve(anchor); + return new this($anchor, head == anchor ? $anchor : doc.resolve(head)); + } + }, { + key: "between", + value: function between($anchor, $head, bias) { + var dPos = $anchor.pos - $head.pos; + if (!bias || dPos) bias = dPos >= 0 ? 1 : -1; + + if (!$head.parent.inlineContent) { + var found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true); + if (found) $head = found.$head;else return Selection.near($head, bias); + } + + if (!$anchor.parent.inlineContent) { + if (dPos == 0) { + $anchor = $head; + } else { + $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor; + if ($anchor.pos < $head.pos != dPos < 0) $anchor = $head; + } + } + + return new TextSelection($anchor, $head); + } + }]); + + return TextSelection; +}(Selection); + +Selection.jsonID("text", TextSelection); + +var TextBookmark = function () { + function TextBookmark(anchor, head) { + _classCallCheck(this, TextBookmark); + + this.anchor = anchor; + this.head = head; + } + + _createClass(TextBookmark, [{ + key: "map", + value: function map(mapping) { + return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head)); + } + }, { + key: "resolve", + value: function resolve(doc) { + return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head)); + } + }]); + + return TextBookmark; +}(); + +var NodeSelection = function (_Selection2) { + _inherits(NodeSelection, _Selection2); + + var _super2 = _createSuper(NodeSelection); + + function NodeSelection($pos) { + var _this; + + _classCallCheck(this, NodeSelection); + + var node = $pos.nodeAfter; + var $end = $pos.node(0).resolve($pos.pos + node.nodeSize); + _this = _super2.call(this, $pos, $end); + _this.node = node; + return _this; + } + + _createClass(NodeSelection, [{ + key: "map", + value: function map(doc, mapping) { + var _mapping$mapResult = mapping.mapResult(this.anchor), + deleted = _mapping$mapResult.deleted, + pos = _mapping$mapResult.pos; + + var $pos = doc.resolve(pos); + if (deleted) return Selection.near($pos); + return new NodeSelection($pos); + } + }, { + key: "content", + value: function content() { + return new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(this.node), 0, 0); + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof NodeSelection && other.anchor == this.anchor; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "node", + anchor: this.anchor + }; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new NodeBookmark(this.anchor); + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.anchor != "number") throw new RangeError("Invalid input for NodeSelection.fromJSON"); + return new NodeSelection(doc.resolve(json.anchor)); + } + }, { + key: "create", + value: function create(doc, from) { + return new NodeSelection(doc.resolve(from)); + } + }, { + key: "isSelectable", + value: function isSelectable(node) { + return !node.isText && node.type.spec.selectable !== false; + } + }]); + + return NodeSelection; +}(Selection); + +NodeSelection.prototype.visible = false; +Selection.jsonID("node", NodeSelection); + +var NodeBookmark = function () { + function NodeBookmark(anchor) { + _classCallCheck(this, NodeBookmark); + + this.anchor = anchor; + } + + _createClass(NodeBookmark, [{ + key: "map", + value: function map(mapping) { + var _mapping$mapResult2 = mapping.mapResult(this.anchor), + deleted = _mapping$mapResult2.deleted, + pos = _mapping$mapResult2.pos; + + return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos); + } + }, { + key: "resolve", + value: function resolve(doc) { + var $pos = doc.resolve(this.anchor), + node = $pos.nodeAfter; + if (node && NodeSelection.isSelectable(node)) return new NodeSelection($pos); + return Selection.near($pos); + } + }]); + + return NodeBookmark; +}(); + +var AllSelection = function (_Selection3) { + _inherits(AllSelection, _Selection3); + + var _super3 = _createSuper(AllSelection); + + function AllSelection(doc) { + _classCallCheck(this, AllSelection); + + return _super3.call(this, doc.resolve(0), doc.resolve(doc.content.size)); + } + + _createClass(AllSelection, [{ + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + + if (content == prosemirrorModel.Slice.empty) { + tr["delete"](0, tr.doc.content.size); + var sel = Selection.atStart(tr.doc); + if (!sel.eq(tr.selection)) tr.setSelection(sel); + } else { + _get(_getPrototypeOf(AllSelection.prototype), "replace", this).call(this, tr, content); + } + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "all" + }; + } + }, { + key: "map", + value: function map(doc) { + return new AllSelection(doc); + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof AllSelection; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return AllBookmark; + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc) { + return new AllSelection(doc); + } + }]); + + return AllSelection; +}(Selection); + +Selection.jsonID("all", AllSelection); +var AllBookmark = { + map: function map() { + return this; + }, + resolve: function resolve(doc) { + return new AllSelection(doc); + } +}; + +function findSelectionIn(doc, node, pos, index, dir) { + var text = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; + if (node.inlineContent) return TextSelection.create(doc, pos); + + for (var i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) { + var child = node.child(i); + + if (!child.isAtom) { + var inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text); + if (inner) return inner; + } else if (!text && NodeSelection.isSelectable(child)) { + return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0)); + } + + pos += child.nodeSize * dir; + } + + return null; +} + +function selectionToInsertionEnd(tr, startLen, bias) { + var last = tr.steps.length - 1; + if (last < startLen) return; + var step = tr.steps[last]; + if (!(step instanceof prosemirrorTransform.ReplaceStep || step instanceof prosemirrorTransform.ReplaceAroundStep)) return; + var map = tr.mapping.maps[last], + end; + map.forEach(function (_from, _to, _newFrom, newTo) { + if (end == null) end = newTo; + }); + tr.setSelection(Selection.near(tr.doc.resolve(end), bias)); +} + +var UPDATED_SEL = 1, + UPDATED_MARKS = 2, + UPDATED_SCROLL = 4; + +var Transaction = function (_prosemirrorTransform) { + _inherits(Transaction, _prosemirrorTransform); + + var _super4 = _createSuper(Transaction); + + function Transaction(state) { + var _this2; + + _classCallCheck(this, Transaction); + + _this2 = _super4.call(this, state.doc); + _this2.curSelectionFor = 0; + _this2.updated = 0; + _this2.meta = Object.create(null); + _this2.time = Date.now(); + _this2.curSelection = state.selection; + _this2.storedMarks = state.storedMarks; + return _this2; + } + + _createClass(Transaction, [{ + key: "selection", + get: function get() { + if (this.curSelectionFor < this.steps.length) { + this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)); + this.curSelectionFor = this.steps.length; + } + + return this.curSelection; + } + }, { + key: "setSelection", + value: function setSelection(selection) { + if (selection.$from.doc != this.doc) throw new RangeError("Selection passed to setSelection must point at the current document"); + this.curSelection = selection; + this.curSelectionFor = this.steps.length; + this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS; + this.storedMarks = null; + return this; + } + }, { + key: "selectionSet", + get: function get() { + return (this.updated & UPDATED_SEL) > 0; + } + }, { + key: "setStoredMarks", + value: function setStoredMarks(marks) { + this.storedMarks = marks; + this.updated |= UPDATED_MARKS; + return this; + } + }, { + key: "ensureMarks", + value: function ensureMarks(marks) { + if (!prosemirrorModel.Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks)) this.setStoredMarks(marks); + return this; + } + }, { + key: "addStoredMark", + value: function addStoredMark(mark) { + return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks())); + } + }, { + key: "removeStoredMark", + value: function removeStoredMark(mark) { + return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks())); + } + }, { + key: "storedMarksSet", + get: function get() { + return (this.updated & UPDATED_MARKS) > 0; + } + }, { + key: "addStep", + value: function addStep(step, doc) { + _get(_getPrototypeOf(Transaction.prototype), "addStep", this).call(this, step, doc); + + this.updated = this.updated & ~UPDATED_MARKS; + this.storedMarks = null; + } + }, { + key: "setTime", + value: function setTime(time) { + this.time = time; + return this; + } + }, { + key: "replaceSelection", + value: function replaceSelection(slice) { + this.selection.replace(this, slice); + return this; + } + }, { + key: "replaceSelectionWith", + value: function replaceSelectionWith(node) { + var inheritMarks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var selection = this.selection; + if (inheritMarks) node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : selection.$from.marksAcross(selection.$to) || prosemirrorModel.Mark.none)); + selection.replaceWith(this, node); + return this; + } + }, { + key: "deleteSelection", + value: function deleteSelection() { + this.selection.replace(this); + return this; + } + }, { + key: "insertText", + value: function insertText(text, from, to) { + var schema = this.doc.type.schema; + + if (from == null) { + if (!text) return this.deleteSelection(); + return this.replaceSelectionWith(schema.text(text), true); + } else { + if (to == null) to = from; + to = to == null ? from : to; + if (!text) return this.deleteRange(from, to); + var marks = this.storedMarks; + + if (!marks) { + var $from = this.doc.resolve(from); + marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to)); + } + + this.replaceRangeWith(from, to, schema.text(text, marks)); + if (!this.selection.empty) this.setSelection(Selection.near(this.selection.$to)); + return this; + } + } + }, { + key: "setMeta", + value: function setMeta(key, value) { + this.meta[typeof key == "string" ? key : key.key] = value; + return this; + } + }, { + key: "getMeta", + value: function getMeta(key) { + return this.meta[typeof key == "string" ? key : key.key]; + } + }, { + key: "isGeneric", + get: function get() { + for (var _ in this.meta) { + return false; + } + + return true; + } + }, { + key: "scrollIntoView", + value: function scrollIntoView() { + this.updated |= UPDATED_SCROLL; + return this; + } + }, { + key: "scrolledIntoView", + get: function get() { + return (this.updated & UPDATED_SCROLL) > 0; + } + }]); + + return Transaction; +}(prosemirrorTransform.Transform); + +function bind(f, self) { + return !self || !f ? f : f.bind(self); +} + +var FieldDesc = _createClass(function FieldDesc(name, desc, self) { + _classCallCheck(this, FieldDesc); + + this.name = name; + this.init = bind(desc.init, self); + this.apply = bind(desc.apply, self); +}); + +var baseFields = [new FieldDesc("doc", { + init: function init(config) { + return config.doc || config.schema.topNodeType.createAndFill(); + }, + apply: function apply(tr) { + return tr.doc; + } +}), new FieldDesc("selection", { + init: function init(config, instance) { + return config.selection || Selection.atStart(instance.doc); + }, + apply: function apply(tr) { + return tr.selection; + } +}), new FieldDesc("storedMarks", { + init: function init(config) { + return config.storedMarks || null; + }, + apply: function apply(tr, _marks, _old, state) { + return state.selection.$cursor ? tr.storedMarks : null; + } +}), new FieldDesc("scrollToSelection", { + init: function init() { + return 0; + }, + apply: function apply(tr, prev) { + return tr.scrolledIntoView ? prev + 1 : prev; + } +})]; + +var Configuration = _createClass(function Configuration(schema, plugins) { + var _this3 = this; + + _classCallCheck(this, Configuration); + + this.schema = schema; + this.plugins = []; + this.pluginsByKey = Object.create(null); + this.fields = baseFields.slice(); + if (plugins) plugins.forEach(function (plugin) { + if (_this3.pluginsByKey[plugin.key]) throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")"); + + _this3.plugins.push(plugin); + + _this3.pluginsByKey[plugin.key] = plugin; + if (plugin.spec.state) _this3.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin)); + }); +}); + +var EditorState = function () { + function EditorState(config) { + _classCallCheck(this, EditorState); + + this.config = config; + } + + _createClass(EditorState, [{ + key: "schema", + get: function get() { + return this.config.schema; + } + }, { + key: "plugins", + get: function get() { + return this.config.plugins; + } + }, { + key: "apply", + value: function apply(tr) { + return this.applyTransaction(tr).state; + } + }, { + key: "filterTransaction", + value: function filterTransaction(tr) { + var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; + + for (var i = 0; i < this.config.plugins.length; i++) { + if (i != ignore) { + var plugin = this.config.plugins[i]; + if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this)) return false; + } + } + + return true; + } + }, { + key: "applyTransaction", + value: function applyTransaction(rootTr) { + if (!this.filterTransaction(rootTr)) return { + state: this, + transactions: [] + }; + var trs = [rootTr], + newState = this.applyInner(rootTr), + seen = null; + + for (;;) { + var haveNew = false; + + for (var i = 0; i < this.config.plugins.length; i++) { + var plugin = this.config.plugins[i]; + + if (plugin.spec.appendTransaction) { + var n = seen ? seen[i].n : 0, + oldState = seen ? seen[i].state : this; + var tr = n < trs.length && plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState); + + if (tr && newState.filterTransaction(tr, i)) { + tr.setMeta("appendedTransaction", rootTr); + + if (!seen) { + seen = []; + + for (var j = 0; j < this.config.plugins.length; j++) { + seen.push(j < i ? { + state: newState, + n: trs.length + } : { + state: this, + n: 0 + }); + } + } + + trs.push(tr); + newState = newState.applyInner(tr); + haveNew = true; + } + + if (seen) seen[i] = { + state: newState, + n: trs.length + }; + } + } + + if (!haveNew) return { + state: newState, + transactions: trs + }; + } + } + }, { + key: "applyInner", + value: function applyInner(tr) { + if (!tr.before.eq(this.doc)) throw new RangeError("Applying a mismatched transaction"); + var newInstance = new EditorState(this.config), + fields = this.config.fields; + + for (var i = 0; i < fields.length; i++) { + var field = fields[i]; + newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance); + } + + return newInstance; + } + }, { + key: "tr", + get: function get() { + return new Transaction(this); + } + }, { + key: "reconfigure", + value: function reconfigure(config) { + var $config = new Configuration(this.schema, config.plugins); + var fields = $config.fields, + instance = new EditorState($config); + + for (var i = 0; i < fields.length; i++) { + var name = fields[i].name; + instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance); + } + + return instance; + } + }, { + key: "toJSON", + value: function toJSON(pluginFields) { + var result = { + doc: this.doc.toJSON(), + selection: this.selection.toJSON() + }; + if (this.storedMarks) result.storedMarks = this.storedMarks.map(function (m) { + return m.toJSON(); + }); + if (pluginFields && _typeof(pluginFields) == 'object') for (var prop in pluginFields) { + if (prop == "doc" || prop == "selection") throw new RangeError("The JSON fields `doc` and `selection` are reserved"); + var plugin = pluginFields[prop], + state = plugin.spec.state; + if (state && state.toJSON) result[prop] = state.toJSON.call(plugin, this[plugin.key]); + } + return result; + } + }], [{ + key: "create", + value: function create(config) { + var $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins); + var instance = new EditorState($config); + + for (var i = 0; i < $config.fields.length; i++) { + instance[$config.fields[i].name] = $config.fields[i].init(config, instance); + } + + return instance; + } + }, { + key: "fromJSON", + value: function fromJSON(config, json, pluginFields) { + if (!json) throw new RangeError("Invalid input for EditorState.fromJSON"); + if (!config.schema) throw new RangeError("Required config field 'schema' missing"); + var $config = new Configuration(config.schema, config.plugins); + var instance = new EditorState($config); + $config.fields.forEach(function (field) { + if (field.name == "doc") { + instance.doc = prosemirrorModel.Node.fromJSON(config.schema, json.doc); + } else if (field.name == "selection") { + instance.selection = Selection.fromJSON(instance.doc, json.selection); + } else if (field.name == "storedMarks") { + if (json.storedMarks) instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON); + } else { + if (pluginFields) for (var prop in pluginFields) { + var plugin = pluginFields[prop], + state = plugin.spec.state; + + if (plugin.key == field.name && state && state.fromJSON && Object.prototype.hasOwnProperty.call(json, prop)) { + instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance); + return; + } + } + instance[field.name] = field.init(config, instance); + } + }); + return instance; + } + }]); + + return EditorState; +}(); + +function bindProps(obj, self, target) { + for (var prop in obj) { + var val = obj[prop]; + if (val instanceof Function) val = val.bind(self);else if (prop == "handleDOMEvents") val = bindProps(val, self, {}); + target[prop] = val; + } + + return target; +} + +var Plugin = function () { + function Plugin(spec) { + _classCallCheck(this, Plugin); + + this.spec = spec; + this.props = {}; + if (spec.props) bindProps(spec.props, this, this.props); + this.key = spec.key ? spec.key.key : createKey("plugin"); + } + + _createClass(Plugin, [{ + key: "getState", + value: function getState(state) { + return state[this.key]; + } + }]); + + return Plugin; +}(); + +var keys = Object.create(null); + +function createKey(name) { + if (name in keys) return name + "$" + ++keys[name]; + keys[name] = 0; + return name + "$"; +} + +var PluginKey = function () { + function PluginKey() { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "key"; + + _classCallCheck(this, PluginKey); + + this.key = createKey(name); + } + + _createClass(PluginKey, [{ + key: "get", + value: function get(state) { + return state.config.pluginsByKey[this.key]; + } + }, { + key: "getState", + value: function getState(state) { + return state[this.key]; + } + }]); + + return PluginKey; +}(); + +exports.AllSelection = AllSelection; +exports.EditorState = EditorState; +exports.NodeSelection = NodeSelection; +exports.Plugin = Plugin; +exports.PluginKey = PluginKey; +exports.Selection = Selection; +exports.SelectionRange = SelectionRange; +exports.TextSelection = TextSelection; +exports.Transaction = Transaction; + +}); +define("prosemirror-transform",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } +function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorModel = require('prosemirror-model'); +var lower16 = 0xffff; +var factor16 = Math.pow(2, 16); +function makeRecover(index, offset) { + return index + offset * factor16; +} +function recoverIndex(value) { + return value & lower16; +} +function recoverOffset(value) { + return (value - (value & lower16)) / factor16; +} +var DEL_BEFORE = 1, + DEL_AFTER = 2, + DEL_ACROSS = 4, + DEL_SIDE = 8; +var MapResult = function () { + function MapResult(pos, delInfo, recover) { + _classCallCheck(this, MapResult); + this.pos = pos; + this.delInfo = delInfo; + this.recover = recover; + } + _createClass(MapResult, [{ + key: "deleted", + get: function get() { + return (this.delInfo & DEL_SIDE) > 0; + } + }, { + key: "deletedBefore", + get: function get() { + return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; + } + }, { + key: "deletedAfter", + get: function get() { + return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; + } + }, { + key: "deletedAcross", + get: function get() { + return (this.delInfo & DEL_ACROSS) > 0; + } + }]); + return MapResult; +}(); +var StepMap = function () { + function StepMap(ranges) { + var inverted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + _classCallCheck(this, StepMap); + this.ranges = ranges; + this.inverted = inverted; + if (!ranges.length && StepMap.empty) return StepMap.empty; + } + _createClass(StepMap, [{ + key: "recover", + value: function recover(value) { + var diff = 0, + index = recoverIndex(value); + if (!this.inverted) for (var i = 0; i < index; i++) diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1]; + return this.ranges[index * 3] + diff + recoverOffset(value); + } + }, { + key: "mapResult", + value: function mapResult(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, false); + } + }, { + key: "map", + value: function map(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, true); + } + }, { + key: "_map", + value: function _map(pos, assoc, simple) { + var diff = 0, + oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) break; + var oldSize = this.ranges[i + oldIndex], + newSize = this.ranges[i + newIndex], + end = start + oldSize; + if (pos <= end) { + var side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc; + var result = start + diff + (side < 0 ? 0 : newSize); + if (simple) return result; + var recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start); + var del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS; + if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE; + return new MapResult(result, del, recover); + } + diff += newSize - oldSize; + } + return simple ? pos + diff : new MapResult(pos + diff, 0, null); + } + }, { + key: "touches", + value: function touches(pos, recover) { + var diff = 0, + index = recoverIndex(recover); + var oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) break; + var oldSize = this.ranges[i + oldIndex], + end = start + oldSize; + if (pos <= end && i == index * 3) return true; + diff += this.ranges[i + newIndex] - oldSize; + } + return false; + } + }, { + key: "forEach", + value: function forEach(f) { + var oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0, diff = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i], + oldStart = start - (this.inverted ? diff : 0), + newStart = start + (this.inverted ? 0 : diff); + var oldSize = this.ranges[i + oldIndex], + newSize = this.ranges[i + newIndex]; + f(oldStart, oldStart + oldSize, newStart, newStart + newSize); + diff += newSize - oldSize; + } + } + }, { + key: "invert", + value: function invert() { + return new StepMap(this.ranges, !this.inverted); + } + }, { + key: "toString", + value: function toString() { + return (this.inverted ? "-" : "") + JSON.stringify(this.ranges); + } + }], [{ + key: "offset", + value: function offset(n) { + return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]); + } + }]); + return StepMap; +}(); +StepMap.empty = new StepMap([]); +var Mapping = function () { + function Mapping() { + var maps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var mirror = arguments.length > 1 ? arguments[1] : undefined; + var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : maps.length; + _classCallCheck(this, Mapping); + this.maps = maps; + this.mirror = mirror; + this.from = from; + this.to = to; + } + _createClass(Mapping, [{ + key: "slice", + value: function slice() { + var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.maps.length; + return new Mapping(this.maps, this.mirror, from, to); + } + }, { + key: "copy", + value: function copy() { + return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to); + } + }, { + key: "appendMap", + value: function appendMap(map, mirrors) { + this.to = this.maps.push(map); + if (mirrors != null) this.setMirror(this.maps.length - 1, mirrors); + } + }, { + key: "appendMapping", + value: function appendMapping(mapping) { + for (var i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : undefined); + } + } + }, { + key: "getMirror", + value: function getMirror(n) { + if (this.mirror) for (var i = 0; i < this.mirror.length; i++) if (this.mirror[i] == n) return this.mirror[i + (i % 2 ? -1 : 1)]; + } + }, { + key: "setMirror", + value: function setMirror(n, m) { + if (!this.mirror) this.mirror = []; + this.mirror.push(n, m); + } + }, { + key: "appendMappingInverted", + value: function appendMappingInverted(mapping) { + for (var i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined); + } + } + }, { + key: "invert", + value: function invert() { + var inverse = new Mapping(); + inverse.appendMappingInverted(this); + return inverse; + } + }, { + key: "map", + value: function map(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + if (this.mirror) return this._map(pos, assoc, true); + for (var i = this.from; i < this.to; i++) pos = this.maps[i].map(pos, assoc); + return pos; + } + }, { + key: "mapResult", + value: function mapResult(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, false); + } + }, { + key: "_map", + value: function _map(pos, assoc, simple) { + var delInfo = 0; + for (var i = this.from; i < this.to; i++) { + var map = this.maps[i], + result = map.mapResult(pos, assoc); + if (result.recover != null) { + var corr = this.getMirror(i); + if (corr != null && corr > i && corr < this.to) { + i = corr; + pos = this.maps[corr].recover(result.recover); + continue; + } + } + delInfo |= result.delInfo; + pos = result.pos; + } + return simple ? pos : new MapResult(pos, delInfo, null); + } + }]); + return Mapping; +}(); +var stepsByID = Object.create(null); +var Step = function () { + function Step() { + _classCallCheck(this, Step); + } + _createClass(Step, [{ + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "merge", + value: function merge(other) { + return null; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json || !json.stepType) throw new RangeError("Invalid input for Step.fromJSON"); + var type = stepsByID[json.stepType]; + if (!type) throw new RangeError("No step type ".concat(json.stepType, " defined")); + return type.fromJSON(schema, json); + } + }, { + key: "jsonID", + value: function jsonID(id, stepClass) { + if (id in stepsByID) throw new RangeError("Duplicate use of step JSON ID " + id); + stepsByID[id] = stepClass; + stepClass.prototype.jsonID = id; + return stepClass; + } + }]); + return Step; +}(); +var StepResult = function () { + function StepResult(doc, failed) { + _classCallCheck(this, StepResult); + this.doc = doc; + this.failed = failed; + } + _createClass(StepResult, null, [{ + key: "ok", + value: function ok(doc) { + return new StepResult(doc, null); + } + }, { + key: "fail", + value: function fail(message) { + return new StepResult(null, message); + } + }, { + key: "fromReplace", + value: function fromReplace(doc, from, to, slice) { + try { + return StepResult.ok(doc.replace(from, to, slice)); + } catch (e) { + if (e instanceof prosemirrorModel.ReplaceError) return StepResult.fail(e.message); + throw e; + } + } + }]); + return StepResult; +}(); +function mapFragment(fragment, f, parent) { + var mapped = []; + for (var i = 0; i < fragment.childCount; i++) { + var child = fragment.child(i); + if (child.content.size) child = child.copy(mapFragment(child.content, f, child)); + if (child.isInline) child = f(child, parent, i); + mapped.push(child); + } + return prosemirrorModel.Fragment.fromArray(mapped); +} +var AddMarkStep = function (_Step) { + _inherits(AddMarkStep, _Step); + var _super = _createSuper(AddMarkStep); + function AddMarkStep(from, to, mark) { + var _this; + _classCallCheck(this, AddMarkStep); + _this = _super.call(this); + _this.from = from; + _this.to = to; + _this.mark = mark; + return _this; + } + _createClass(AddMarkStep, [{ + key: "apply", + value: function apply(doc) { + var _this2 = this; + var oldSlice = doc.slice(this.from, this.to), + $from = doc.resolve(this.from); + var parent = $from.node($from.sharedDepth(this.to)); + var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node, parent) { + if (!node.isAtom || !parent.type.allowsMarkType(_this2.mark.type)) return node; + return node.mark(_this2.mark.addToSet(node.marks)); + }, parent), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice); + } + }, { + key: "invert", + value: function invert() { + return new RemoveMarkStep(this.from, this.to, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) return null; + return new AddMarkStep(from.pos, to.pos, this.mark); + } + }, { + key: "merge", + value: function merge(other) { + if (other instanceof AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); + return null; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "addMark", + mark: this.mark.toJSON(), + from: this.from, + to: this.to + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for AddMarkStep.fromJSON"); + return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); + } + }]); + return AddMarkStep; +}(Step); +Step.jsonID("addMark", AddMarkStep); +var RemoveMarkStep = function (_Step2) { + _inherits(RemoveMarkStep, _Step2); + var _super2 = _createSuper(RemoveMarkStep); + function RemoveMarkStep(from, to, mark) { + var _this3; + _classCallCheck(this, RemoveMarkStep); + _this3 = _super2.call(this); + _this3.from = from; + _this3.to = to; + _this3.mark = mark; + return _this3; + } + _createClass(RemoveMarkStep, [{ + key: "apply", + value: function apply(doc) { + var _this4 = this; + var oldSlice = doc.slice(this.from, this.to); + var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node) { + return node.mark(_this4.mark.removeFromSet(node.marks)); + }, doc), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice); + } + }, { + key: "invert", + value: function invert() { + return new AddMarkStep(this.from, this.to, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) return null; + return new RemoveMarkStep(from.pos, to.pos, this.mark); + } + }, { + key: "merge", + value: function merge(other) { + if (other instanceof RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); + return null; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "removeMark", + mark: this.mark.toJSON(), + from: this.from, + to: this.to + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for RemoveMarkStep.fromJSON"); + return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); + } + }]); + return RemoveMarkStep; +}(Step); +Step.jsonID("removeMark", RemoveMarkStep); +var AddNodeMarkStep = function (_Step3) { + _inherits(AddNodeMarkStep, _Step3); + var _super3 = _createSuper(AddNodeMarkStep); + function AddNodeMarkStep(pos, mark) { + var _this5; + _classCallCheck(this, AddNodeMarkStep); + _this5 = _super3.call(this); + _this5.pos = pos; + _this5.mark = mark; + return _this5; + } + _createClass(AddNodeMarkStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at mark step's position"); + var updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks)); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "invert", + value: function invert(doc) { + var node = doc.nodeAt(this.pos); + if (node) { + var newSet = this.mark.addToSet(node.marks); + if (newSet.length == node.marks.length) { + for (var i = 0; i < node.marks.length; i++) if (!node.marks[i].isInSet(newSet)) return new AddNodeMarkStep(this.pos, node.marks[i]); + return new AddNodeMarkStep(this.pos, this.mark); + } + } + return new RemoveNodeMarkStep(this.pos, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "addNodeMark", + pos: this.pos, + mark: this.mark.toJSON() + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON"); + return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); + } + }]); + return AddNodeMarkStep; +}(Step); +Step.jsonID("addNodeMark", AddNodeMarkStep); +var RemoveNodeMarkStep = function (_Step4) { + _inherits(RemoveNodeMarkStep, _Step4); + var _super4 = _createSuper(RemoveNodeMarkStep); + function RemoveNodeMarkStep(pos, mark) { + var _this6; + _classCallCheck(this, RemoveNodeMarkStep); + _this6 = _super4.call(this); + _this6.pos = pos; + _this6.mark = mark; + return _this6; + } + _createClass(RemoveNodeMarkStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at mark step's position"); + var updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks)); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "invert", + value: function invert(doc) { + var node = doc.nodeAt(this.pos); + if (!node || !this.mark.isInSet(node.marks)) return this; + return new AddNodeMarkStep(this.pos, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "removeNodeMark", + pos: this.pos, + mark: this.mark.toJSON() + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON"); + return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); + } + }]); + return RemoveNodeMarkStep; +}(Step); +Step.jsonID("removeNodeMark", RemoveNodeMarkStep); +var ReplaceStep = function (_Step5) { + _inherits(ReplaceStep, _Step5); + var _super5 = _createSuper(ReplaceStep); + function ReplaceStep(from, to, slice) { + var _this7; + var structure = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + _classCallCheck(this, ReplaceStep); + _this7 = _super5.call(this); + _this7.from = from; + _this7.to = to; + _this7.slice = slice; + _this7.structure = structure; + return _this7; + } + _createClass(ReplaceStep, [{ + key: "apply", + value: function apply(doc) { + if (this.structure && contentBetween(doc, this.from, this.to)) return StepResult.fail("Structure replace would overwrite content"); + return StepResult.fromReplace(doc, this.from, this.to, this.slice); + } + }, { + key: "getMap", + value: function getMap() { + return new StepMap([this.from, this.to - this.from, this.slice.size]); + } + }, { + key: "invert", + value: function invert(doc) { + return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to)); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deletedAcross && to.deletedAcross) return null; + return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice); + } + }, { + key: "merge", + value: function merge(other) { + if (!(other instanceof ReplaceStep) || other.structure || this.structure) return null; + if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) { + var slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd); + return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure); + } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) { + var _slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd); + return new ReplaceStep(other.from, this.to, _slice, this.structure); + } else { + return null; + } + } + }, { + key: "toJSON", + value: function toJSON() { + var json = { + stepType: "replace", + from: this.from, + to: this.to + }; + if (this.slice.size) json.slice = this.slice.toJSON(); + if (this.structure) json.structure = true; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for ReplaceStep.fromJSON"); + return new ReplaceStep(json.from, json.to, prosemirrorModel.Slice.fromJSON(schema, json.slice), !!json.structure); + } + }]); + return ReplaceStep; +}(Step); +Step.jsonID("replace", ReplaceStep); +var ReplaceAroundStep = function (_Step6) { + _inherits(ReplaceAroundStep, _Step6); + var _super6 = _createSuper(ReplaceAroundStep); + function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert) { + var _this8; + var structure = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false; + _classCallCheck(this, ReplaceAroundStep); + _this8 = _super6.call(this); + _this8.from = from; + _this8.to = to; + _this8.gapFrom = gapFrom; + _this8.gapTo = gapTo; + _this8.slice = slice; + _this8.insert = insert; + _this8.structure = structure; + return _this8; + } + _createClass(ReplaceAroundStep, [{ + key: "apply", + value: function apply(doc) { + if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to))) return StepResult.fail("Structure gap-replace would overwrite content"); + var gap = doc.slice(this.gapFrom, this.gapTo); + if (gap.openStart || gap.openEnd) return StepResult.fail("Gap is not a flat range"); + var inserted = this.slice.insertAt(this.insert, gap.content); + if (!inserted) return StepResult.fail("Content does not fit in gap"); + return StepResult.fromReplace(doc, this.from, this.to, inserted); + } + }, { + key: "getMap", + value: function getMap() { + return new StepMap([this.from, this.gapFrom - this.from, this.insert, this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]); + } + }, { + key: "invert", + value: function invert(doc) { + var gap = this.gapTo - this.gapFrom; + return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + var gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1); + var gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1); + if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos) return null; + return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure); + } + }, { + key: "toJSON", + value: function toJSON() { + var json = { + stepType: "replaceAround", + from: this.from, + to: this.to, + gapFrom: this.gapFrom, + gapTo: this.gapTo, + insert: this.insert + }; + if (this.slice.size) json.slice = this.slice.toJSON(); + if (this.structure) json.structure = true; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON"); + return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, prosemirrorModel.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure); + } + }]); + return ReplaceAroundStep; +}(Step); +Step.jsonID("replaceAround", ReplaceAroundStep); +function contentBetween(doc, from, to) { + var $from = doc.resolve(from), + dist = to - from, + depth = $from.depth; + while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) { + depth--; + dist--; + } + if (dist > 0) { + var next = $from.node(depth).maybeChild($from.indexAfter(depth)); + while (dist > 0) { + if (!next || next.isLeaf) return true; + next = next.firstChild; + dist--; + } + } + return false; +} +function _addMark(tr, from, to, mark) { + var removed = [], + added = []; + var removing, adding; + tr.doc.nodesBetween(from, to, function (node, pos, parent) { + if (!node.isInline) return; + var marks = node.marks; + if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) { + var start = Math.max(pos, from), + end = Math.min(pos + node.nodeSize, to); + var newSet = mark.addToSet(marks); + for (var i = 0; i < marks.length; i++) { + if (!marks[i].isInSet(newSet)) { + if (removing && removing.to == start && removing.mark.eq(marks[i])) removing.to = end;else removed.push(removing = new RemoveMarkStep(start, end, marks[i])); + } + } + if (adding && adding.to == start) adding.to = end;else added.push(adding = new AddMarkStep(start, end, mark)); + } + }); + removed.forEach(function (s) { + return tr.step(s); + }); + added.forEach(function (s) { + return tr.step(s); + }); +} +function _removeMark(tr, from, to, mark) { + var matched = [], + step = 0; + tr.doc.nodesBetween(from, to, function (node, pos) { + if (!node.isInline) return; + step++; + var toRemove = null; + if (mark instanceof prosemirrorModel.MarkType) { + var set = node.marks, + found; + while (found = mark.isInSet(set)) { + (toRemove || (toRemove = [])).push(found); + set = found.removeFromSet(set); + } + } else if (mark) { + if (mark.isInSet(node.marks)) toRemove = [mark]; + } else { + toRemove = node.marks; + } + if (toRemove && toRemove.length) { + var end = Math.min(pos + node.nodeSize, to); + for (var i = 0; i < toRemove.length; i++) { + var style = toRemove[i], + _found = void 0; + for (var j = 0; j < matched.length; j++) { + var m = matched[j]; + if (m.step == step - 1 && style.eq(matched[j].style)) _found = m; + } + if (_found) { + _found.to = end; + _found.step = step; + } else { + matched.push({ + style: style, + from: Math.max(pos, from), + to: end, + step: step + }); + } + } + } + }); + matched.forEach(function (m) { + return tr.step(new RemoveMarkStep(m.from, m.to, m.style)); + }); +} +function _clearIncompatible(tr, pos, parentType) { + var match = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : parentType.contentMatch; + var clearNewlines = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; + var node = tr.doc.nodeAt(pos); + var replSteps = [], + cur = pos + 1; + for (var i = 0; i < node.childCount; i++) { + var child = node.child(i), + end = cur + child.nodeSize; + var allowed = match.matchType(child.type); + if (!allowed) { + replSteps.push(new ReplaceStep(cur, end, prosemirrorModel.Slice.empty)); + } else { + match = allowed; + for (var j = 0; j < child.marks.length; j++) if (!parentType.allowsMarkType(child.marks[j].type)) tr.step(new RemoveMarkStep(cur, end, child.marks[j])); + if (clearNewlines && child.isText && parentType.whitespace != "pre") { + var m = void 0, + newline = /\r?\n|\r/g, + slice = void 0; + while (m = newline.exec(child.text)) { + if (!slice) slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0); + replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice)); + } + } + } + cur = end; + } + if (!match.validEnd) { + var fill = match.fillBefore(prosemirrorModel.Fragment.empty, true); + tr.replace(cur, cur, new prosemirrorModel.Slice(fill, 0, 0)); + } + for (var _i = replSteps.length - 1; _i >= 0; _i--) tr.step(replSteps[_i]); +} +function canCut(node, start, end) { + return (start == 0 || node.canReplace(start, node.childCount)) && (end == node.childCount || node.canReplace(0, end)); +} +function liftTarget(range) { + var parent = range.parent; + var content = parent.content.cutByIndex(range.startIndex, range.endIndex); + for (var depth = range.depth;; --depth) { + var node = range.$from.node(depth); + var index = range.$from.index(depth), + endIndex = range.$to.indexAfter(depth); + if (depth < range.depth && node.canReplace(index, endIndex, content)) return depth; + if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break; + } + return null; +} +function _lift(tr, range, target) { + var $from = range.$from, + $to = range.$to, + depth = range.depth; + var gapStart = $from.before(depth + 1), + gapEnd = $to.after(depth + 1); + var start = gapStart, + end = gapEnd; + var before = prosemirrorModel.Fragment.empty, + openStart = 0; + for (var d = depth, splitting = false; d > target; d--) if (splitting || $from.index(d) > 0) { + splitting = true; + before = prosemirrorModel.Fragment.from($from.node(d).copy(before)); + openStart++; + } else { + start--; + } + var after = prosemirrorModel.Fragment.empty, + openEnd = 0; + for (var _d = depth, _splitting = false; _d > target; _d--) if (_splitting || $to.after(_d + 1) < $to.end(_d)) { + _splitting = true; + after = prosemirrorModel.Fragment.from($to.node(_d).copy(after)); + openEnd++; + } else { + end++; + } + tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new prosemirrorModel.Slice(before.append(after), openStart, openEnd), before.size - openStart, true)); +} +function findWrapping(range, nodeType) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var innerRange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : range; + var around = findWrappingOutside(range, nodeType); + var inner = around && findWrappingInside(innerRange, nodeType); + if (!inner) return null; + return around.map(withAttrs).concat({ + type: nodeType, + attrs: attrs + }).concat(inner.map(withAttrs)); +} +function withAttrs(type) { + return { + type: type, + attrs: null + }; +} +function findWrappingOutside(range, type) { + var parent = range.parent, + startIndex = range.startIndex, + endIndex = range.endIndex; + var around = parent.contentMatchAt(startIndex).findWrapping(type); + if (!around) return null; + var outer = around.length ? around[0] : type; + return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null; +} +function findWrappingInside(range, type) { + var parent = range.parent, + startIndex = range.startIndex, + endIndex = range.endIndex; + var inner = parent.child(startIndex); + var inside = type.contentMatch.findWrapping(inner.type); + if (!inside) return null; + var lastType = inside.length ? inside[inside.length - 1] : type; + var innerMatch = lastType.contentMatch; + for (var i = startIndex; innerMatch && i < endIndex; i++) innerMatch = innerMatch.matchType(parent.child(i).type); + if (!innerMatch || !innerMatch.validEnd) return null; + return inside; +} +function _wrap2(tr, range, wrappers) { + var content = prosemirrorModel.Fragment.empty; + for (var i = wrappers.length - 1; i >= 0; i--) { + if (content.size) { + var match = wrappers[i].type.contentMatch.matchFragment(content); + if (!match || !match.validEnd) throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper"); + } + content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); + } + var start = range.start, + end = range.end; + tr.step(new ReplaceAroundStep(start, end, start, end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true)); +} +function _setBlockType(tr, from, to, type, attrs) { + if (!type.isTextblock) throw new RangeError("Type given to setBlockType should be a textblock"); + var mapFrom = tr.steps.length; + tr.doc.nodesBetween(from, to, function (node, pos) { + var attrsHere = typeof attrs == "function" ? attrs(node) : attrs; + if (node.isTextblock && !node.hasMarkup(type, attrsHere) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) { + var convertNewlines = null; + if (type.schema.linebreakReplacement) { + var pre = type.whitespace == "pre", + supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement); + if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true; + } + if (convertNewlines === false) replaceLinebreaks(tr, node, pos, mapFrom); + _clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null); + var mapping = tr.mapping.slice(mapFrom); + var startM = mapping.map(pos, 1), + endM = mapping.map(pos + node.nodeSize, 1); + tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true)); + if (convertNewlines === true) replaceNewlines(tr, node, pos, mapFrom); + return false; + } + }); +} +function replaceNewlines(tr, node, pos, mapFrom) { + node.forEach(function (child, offset) { + if (child.isText) { + var m, + newline = /\r?\n|\r/g; + while (m = newline.exec(child.text)) { + var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index); + tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create()); + } + } + }); +} +function replaceLinebreaks(tr, node, pos, mapFrom) { + node.forEach(function (child, offset) { + if (child.type == child.type.schema.linebreakReplacement) { + var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset); + tr.replaceWith(start, start + 1, node.type.schema.text("\n")); + } + }); +} +function canChangeType(doc, pos, type) { + var $pos = doc.resolve(pos), + index = $pos.index(); + return $pos.parent.canReplaceWith(index, index + 1, type); +} +function _setNodeMarkup(tr, pos, type, attrs, marks) { + var node = tr.doc.nodeAt(pos); + if (!node) throw new RangeError("No node at given position"); + if (!type) type = node.type; + var newNode = type.create(attrs, null, marks || node.marks); + if (node.isLeaf) return tr.replaceWith(pos, pos + node.nodeSize, newNode); + if (!type.validContent(node.content)) throw new RangeError("Invalid content for node type " + type.name); + tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(newNode), 0, 0), 1, true)); +} +function canSplit(doc, pos) { + var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; + var typesAfter = arguments.length > 3 ? arguments[3] : undefined; + var $pos = doc.resolve(pos), + base = $pos.depth - depth; + var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; + if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; + for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { + var node = $pos.node(d), + _index = $pos.index(d); + if (node.type.spec.isolating) return false; + var rest = node.content.cutByIndex(_index, node.childCount); + var overrideChild = typesAfter && typesAfter[i + 1]; + if (overrideChild) rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs)); + var after = typesAfter && typesAfter[i] || node; + if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false; + } + var index = $pos.indexAfter(base); + var baseType = typesAfter && typesAfter[0]; + return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); +} +function _split(tr, pos) { + var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; + var typesAfter = arguments.length > 3 ? arguments[3] : undefined; + var $pos = tr.doc.resolve(pos), + before = prosemirrorModel.Fragment.empty, + after = prosemirrorModel.Fragment.empty; + for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) { + before = prosemirrorModel.Fragment.from($pos.node(d).copy(before)); + var typeAfter = typesAfter && typesAfter[i]; + after = prosemirrorModel.Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after)); + } + tr.step(new ReplaceStep(pos, pos, new prosemirrorModel.Slice(before.append(after), depth, depth), true)); +} +function canJoin(doc, pos) { + var $pos = doc.resolve(pos), + index = $pos.index(); + return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1); +} +function canAppendWithSubstitutedLinebreaks(a, b) { + if (!b.content.size) a.type.compatibleContent(b.type); + var match = a.contentMatchAt(a.childCount); + var linebreakReplacement = a.type.schema.linebreakReplacement; + for (var i = 0; i < b.childCount; i++) { + var child = b.child(i); + var type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type; + match = match.matchType(type); + if (!match) return false; + if (!a.type.allowsMarks(child.marks)) return false; + } + return match.validEnd; +} +function joinable(a, b) { + return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b)); +} +function joinPoint(doc, pos) { + var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; + var $pos = doc.resolve(pos); + for (var d = $pos.depth;; d--) { + var before = void 0, + after = void 0, + index = $pos.index(d); + if (d == $pos.depth) { + before = $pos.nodeBefore; + after = $pos.nodeAfter; + } else if (dir > 0) { + before = $pos.node(d + 1); + index++; + after = $pos.node(d).maybeChild(index); + } else { + before = $pos.node(d).maybeChild(index - 1); + after = $pos.node(d + 1); + } + if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1)) return pos; + if (d == 0) break; + pos = dir < 0 ? $pos.before(d) : $pos.after(d); + } +} +function _join(tr, pos, depth) { + var convertNewlines = null; + var linebreakReplacement = tr.doc.type.schema.linebreakReplacement; + var $before = tr.doc.resolve(pos - depth), + beforeType = $before.node().type; + if (linebreakReplacement && beforeType.inlineContent) { + var pre = beforeType.whitespace == "pre"; + var supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement); + if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true; + } + var mapFrom = tr.steps.length; + if (convertNewlines === false) { + var $after = tr.doc.resolve(pos + depth); + replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom); + } + if (beforeType.inlineContent) _clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null); + var mapping = tr.mapping.slice(mapFrom), + start = mapping.map(pos - depth); + tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), prosemirrorModel.Slice.empty, true)); + if (convertNewlines === true) { + var $full = tr.doc.resolve(start); + replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length); + } + return tr; +} +function insertPoint(doc, pos, nodeType) { + var $pos = doc.resolve(pos); + if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) return pos; + if ($pos.parentOffset == 0) for (var d = $pos.depth - 1; d >= 0; d--) { + var index = $pos.index(d); + if ($pos.node(d).canReplaceWith(index, index, nodeType)) return $pos.before(d + 1); + if (index > 0) return null; + } + if ($pos.parentOffset == $pos.parent.content.size) for (var _d2 = $pos.depth - 1; _d2 >= 0; _d2--) { + var _index2 = $pos.indexAfter(_d2); + if ($pos.node(_d2).canReplaceWith(_index2, _index2, nodeType)) return $pos.after(_d2 + 1); + if (_index2 < $pos.node(_d2).childCount) return null; + } + return null; +} +function dropPoint(doc, pos, slice) { + var $pos = doc.resolve(pos); + if (!slice.content.size) return pos; + var content = slice.content; + for (var i = 0; i < slice.openStart; i++) content = content.firstChild.content; + for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) { + for (var d = $pos.depth; d >= 0; d--) { + var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1; + var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0); + var parent = $pos.node(d), + fits = false; + if (pass == 1) { + fits = parent.canReplace(insertPos, insertPos, content); + } else { + var wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type); + fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]); + } + if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1); + } + } + return null; +} +function replaceStep(doc, from) { + var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : from; + var slice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prosemirrorModel.Slice.empty; + if (from == to && !slice.size) return null; + var $from = doc.resolve(from), + $to = doc.resolve(to); + if (fitsTrivially($from, $to, slice)) return new ReplaceStep(from, to, slice); + return new Fitter($from, $to, slice).fit(); +} +function fitsTrivially($from, $to, slice) { + return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content); +} +var Fitter = function () { + function Fitter($from, $to, unplaced) { + _classCallCheck(this, Fitter); + this.$from = $from; + this.$to = $to; + this.unplaced = unplaced; + this.frontier = []; + this.placed = prosemirrorModel.Fragment.empty; + for (var i = 0; i <= $from.depth; i++) { + var node = $from.node(i); + this.frontier.push({ + type: node.type, + match: node.contentMatchAt($from.indexAfter(i)) + }); + } + for (var _i2 = $from.depth; _i2 > 0; _i2--) this.placed = prosemirrorModel.Fragment.from($from.node(_i2).copy(this.placed)); + } + _createClass(Fitter, [{ + key: "depth", + get: function get() { + return this.frontier.length - 1; + } + }, { + key: "fit", + value: function fit() { + while (this.unplaced.size) { + var fit = this.findFittable(); + if (fit) this.placeNodes(fit);else this.openMore() || this.dropNode(); + } + var moveInline = this.mustMoveInline(), + placedSize = this.placed.size - this.depth - this.$from.depth; + var $from = this.$from, + $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline)); + if (!$to) return null; + var content = this.placed, + openStart = $from.depth, + openEnd = $to.depth; + while (openStart && openEnd && content.childCount == 1) { + content = content.firstChild.content; + openStart--; + openEnd--; + } + var slice = new prosemirrorModel.Slice(content, openStart, openEnd); + if (moveInline > -1) return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize); + if (slice.size || $from.pos != this.$to.pos) return new ReplaceStep($from.pos, $to.pos, slice); + return null; + } + }, { + key: "findFittable", + value: function findFittable() { + var startDepth = this.unplaced.openStart; + for (var cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) { + var node = cur.firstChild; + if (cur.childCount > 1) openEnd = 0; + if (node.type.spec.isolating && openEnd <= d) { + startDepth = d; + break; + } + cur = node.content; + } + for (var pass = 1; pass <= 2; pass++) { + for (var sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) { + var fragment = void 0, + parent = null; + if (sliceDepth) { + parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild; + fragment = parent.content; + } else { + fragment = this.unplaced.content; + } + var first = fragment.firstChild; + for (var frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) { + var _this$frontier$fronti = this.frontier[frontierDepth], + type = _this$frontier$fronti.type, + match = _this$frontier$fronti.match, + _wrap = void 0, + inject = null; + if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(prosemirrorModel.Fragment.from(first), false)) : parent && type.compatibleContent(parent.type))) return { + sliceDepth: sliceDepth, + frontierDepth: frontierDepth, + parent: parent, + inject: inject + };else if (pass == 2 && first && (_wrap = match.findWrapping(first.type))) return { + sliceDepth: sliceDepth, + frontierDepth: frontierDepth, + parent: parent, + wrap: _wrap + }; + if (parent && match.matchType(parent.type)) break; + } + } + } + } + }, { + key: "openMore", + value: function openMore() { + var _this$unplaced = this.unplaced, + content = _this$unplaced.content, + openStart = _this$unplaced.openStart, + openEnd = _this$unplaced.openEnd; + var inner = contentAt(content, openStart); + if (!inner.childCount || inner.firstChild.isLeaf) return false; + this.unplaced = new prosemirrorModel.Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0)); + return true; + } + }, { + key: "dropNode", + value: function dropNode() { + var _this$unplaced2 = this.unplaced, + content = _this$unplaced2.content, + openStart = _this$unplaced2.openStart, + openEnd = _this$unplaced2.openEnd; + var inner = contentAt(content, openStart); + if (inner.childCount <= 1 && openStart > 0) { + var openAtEnd = content.size - openStart <= openStart + inner.size; + this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd); + } else { + this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart, 1), openStart, openEnd); + } + } + }, { + key: "placeNodes", + value: function placeNodes(_ref) { + var sliceDepth = _ref.sliceDepth, + frontierDepth = _ref.frontierDepth, + parent = _ref.parent, + inject = _ref.inject, + wrap = _ref.wrap; + while (this.depth > frontierDepth) this.closeFrontierNode(); + if (wrap) for (var i = 0; i < wrap.length; i++) this.openFrontierNode(wrap[i]); + var slice = this.unplaced, + fragment = parent ? parent.content : slice.content; + var openStart = slice.openStart - sliceDepth; + var taken = 0, + add = []; + var _this$frontier$fronti2 = this.frontier[frontierDepth], + match = _this$frontier$fronti2.match, + type = _this$frontier$fronti2.type; + if (inject) { + for (var _i3 = 0; _i3 < inject.childCount; _i3++) add.push(inject.child(_i3)); + match = match.matchFragment(inject); + } + var openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd); + while (taken < fragment.childCount) { + var next = fragment.child(taken), + matches = match.matchType(next.type); + if (!matches) break; + taken++; + if (taken > 1 || openStart == 0 || next.content.size) { + match = matches; + add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1)); + } + } + var toEnd = taken == fragment.childCount; + if (!toEnd) openEndCount = -1; + this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add)); + this.frontier[frontierDepth].match = match; + if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode(); + for (var _i4 = 0, cur = fragment; _i4 < openEndCount; _i4++) { + var node = cur.lastChild; + this.frontier.push({ + type: node.type, + match: node.contentMatchAt(node.childCount) + }); + cur = node.content; + } + this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1); + } + }, { + key: "mustMoveInline", + value: function mustMoveInline() { + if (!this.$to.parent.isTextblock) return -1; + var top = this.frontier[this.depth], + level; + if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth) return -1; + var depth = this.$to.depth, + after = this.$to.after(depth); + while (depth > 1 && after == this.$to.end(--depth)) ++after; + return after; + } + }, { + key: "findCloseLevel", + value: function findCloseLevel($to) { + scan: for (var i = Math.min(this.depth, $to.depth); i >= 0; i--) { + var _this$frontier$i = this.frontier[i], + match = _this$frontier$i.match, + type = _this$frontier$i.type; + var dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1)); + var fit = contentAfterFits($to, i, type, match, dropInner); + if (!fit) continue; + for (var d = i - 1; d >= 0; d--) { + var _this$frontier$d = this.frontier[d], + _match = _this$frontier$d.match, + _type = _this$frontier$d.type; + var matches = contentAfterFits($to, d, _type, _match, true); + if (!matches || matches.childCount) continue scan; + } + return { + depth: i, + fit: fit, + move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to + }; + } + } + }, { + key: "close", + value: function close($to) { + var close = this.findCloseLevel($to); + if (!close) return null; + while (this.depth > close.depth) this.closeFrontierNode(); + if (close.fit.childCount) this.placed = addToFragment(this.placed, close.depth, close.fit); + $to = close.move; + for (var d = close.depth + 1; d <= $to.depth; d++) { + var node = $to.node(d), + add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d)); + this.openFrontierNode(node.type, node.attrs, add); + } + return $to; + } + }, { + key: "openFrontierNode", + value: function openFrontierNode(type) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var content = arguments.length > 2 ? arguments[2] : undefined; + var top = this.frontier[this.depth]; + top.match = top.match.matchType(type); + this.placed = addToFragment(this.placed, this.depth, prosemirrorModel.Fragment.from(type.create(attrs, content))); + this.frontier.push({ + type: type, + match: type.contentMatch + }); + } + }, { + key: "closeFrontierNode", + value: function closeFrontierNode() { + var open = this.frontier.pop(); + var add = open.match.fillBefore(prosemirrorModel.Fragment.empty, true); + if (add.childCount) this.placed = addToFragment(this.placed, this.frontier.length, add); + } + }]); + return Fitter; +}(); +function dropFromFragment(fragment, depth, count) { + if (depth == 0) return fragment.cutByIndex(count, fragment.childCount); + return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count))); +} +function addToFragment(fragment, depth, content) { + if (depth == 0) return fragment.append(content); + return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content))); +} +function contentAt(fragment, depth) { + for (var i = 0; i < depth; i++) fragment = fragment.firstChild.content; + return fragment; +} +function closeNodeStart(node, openStart, openEnd) { + if (openStart <= 0) return node; + var frag = node.content; + if (openStart > 1) frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0)); + if (openStart > 0) { + frag = node.type.contentMatch.fillBefore(frag).append(frag); + if (openEnd <= 0) frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(prosemirrorModel.Fragment.empty, true)); + } + return node.copy(frag); +} +function contentAfterFits($to, depth, type, match, open) { + var node = $to.node(depth), + index = open ? $to.indexAfter(depth) : $to.index(depth); + if (index == node.childCount && !type.compatibleContent(node.type)) return null; + var fit = match.fillBefore(node.content, true, index); + return fit && !invalidMarks(type, node.content, index) ? fit : null; +} +function invalidMarks(type, fragment, start) { + for (var i = start; i < fragment.childCount; i++) if (!type.allowsMarks(fragment.child(i).marks)) return true; + return false; +} +function definesContent(type) { + return type.spec.defining || type.spec.definingForContent; +} +function _replaceRange(tr, from, to, slice) { + if (!slice.size) return tr.deleteRange(from, to); + var $from = tr.doc.resolve(from), + $to = tr.doc.resolve(to); + if (fitsTrivially($from, $to, slice)) return tr.step(new ReplaceStep(from, to, slice)); + var targetDepths = coveredDepths($from, tr.doc.resolve(to)); + if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop(); + var preferredTarget = -($from.depth + 1); + targetDepths.unshift(preferredTarget); + for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) { + var spec = $from.node(d).type.spec; + if (spec.defining || spec.definingAsContext || spec.isolating) break; + if (targetDepths.indexOf(d) > -1) preferredTarget = d;else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d); + } + var preferredTargetIndex = targetDepths.indexOf(preferredTarget); + var leftNodes = [], + preferredDepth = slice.openStart; + for (var content = slice.content, i = 0;; i++) { + var node = content.firstChild; + leftNodes.push(node); + if (i == slice.openStart) break; + content = node.content; + } + for (var _d3 = preferredDepth - 1; _d3 >= 0; _d3--) { + var leftNode = leftNodes[_d3], + def = definesContent(leftNode.type); + if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = _d3;else if (def || !leftNode.type.isTextblock) break; + } + for (var j = slice.openStart; j >= 0; j--) { + var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1); + var insert = leftNodes[openDepth]; + if (!insert) continue; + for (var _i5 = 0; _i5 < targetDepths.length; _i5++) { + var targetDepth = targetDepths[(_i5 + preferredTargetIndex) % targetDepths.length], + expand = true; + if (targetDepth < 0) { + expand = false; + targetDepth = -targetDepth; + } + var parent = $from.node(targetDepth - 1), + index = $from.index(targetDepth - 1); + if (parent.canReplaceWith(index, index, insert.type, insert.marks)) return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new prosemirrorModel.Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd)); + } + } + var startSteps = tr.steps.length; + for (var _i6 = targetDepths.length - 1; _i6 >= 0; _i6--) { + tr.replace(from, to, slice); + if (tr.steps.length > startSteps) break; + var depth = targetDepths[_i6]; + if (depth < 0) continue; + from = $from.before(depth); + to = $to.after(depth); + } +} +function closeFragment(fragment, depth, oldOpen, newOpen, parent) { + if (depth < oldOpen) { + var first = fragment.firstChild; + fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first))); + } + if (depth > newOpen) { + var match = parent.contentMatchAt(0); + var start = match.fillBefore(fragment).append(fragment); + fragment = start.append(match.matchFragment(start).fillBefore(prosemirrorModel.Fragment.empty, true)); + } + return fragment; +} +function _replaceRangeWith(tr, from, to, node) { + if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) { + var point = insertPoint(tr.doc, from, node.type); + if (point != null) from = to = point; + } + tr.replaceRange(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(node), 0, 0)); +} +function _deleteRange(tr, from, to) { + var $from = tr.doc.resolve(from), + $to = tr.doc.resolve(to); + var covered = coveredDepths($from, $to); + for (var i = 0; i < covered.length; i++) { + var depth = covered[i], + last = i == covered.length - 1; + if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) return tr["delete"]($from.start(depth), $to.end(depth)); + if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) return tr["delete"]($from.before(depth), $to.after(depth)); + } + for (var d = 1; d <= $from.depth && d <= $to.depth; d++) { + if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d && $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1))) return tr["delete"]($from.before(d), to); + } + tr["delete"](from, to); +} +function coveredDepths($from, $to) { + var result = [], + minDepth = Math.min($from.depth, $to.depth); + for (var d = minDepth; d >= 0; d--) { + var start = $from.start(d); + if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating) break; + if (start == $to.start(d) || d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent && d && $to.start(d - 1) == start - 1) result.push(d); + } + return result; +} +var AttrStep = function (_Step7) { + _inherits(AttrStep, _Step7); + var _super7 = _createSuper(AttrStep); + function AttrStep(pos, attr, value) { + var _this9; + _classCallCheck(this, AttrStep); + _this9 = _super7.call(this); + _this9.pos = pos; + _this9.attr = attr; + _this9.value = value; + return _this9; + } + _createClass(AttrStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at attribute step's position"); + var attrs = Object.create(null); + for (var name in node.attrs) attrs[name] = node.attrs[name]; + attrs[this.attr] = this.value; + var updated = node.type.create(attrs, null, node.marks); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "invert", + value: function invert(doc) { + return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "attr", + pos: this.pos, + attr: this.attr, + value: this.value + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number" || typeof json.attr != "string") throw new RangeError("Invalid input for AttrStep.fromJSON"); + return new AttrStep(json.pos, json.attr, json.value); + } + }]); + return AttrStep; +}(Step); +Step.jsonID("attr", AttrStep); +var DocAttrStep = function (_Step8) { + _inherits(DocAttrStep, _Step8); + var _super8 = _createSuper(DocAttrStep); + function DocAttrStep(attr, value) { + var _this10; + _classCallCheck(this, DocAttrStep); + _this10 = _super8.call(this); + _this10.attr = attr; + _this10.value = value; + return _this10; + } + _createClass(DocAttrStep, [{ + key: "apply", + value: function apply(doc) { + var attrs = Object.create(null); + for (var name in doc.attrs) attrs[name] = doc.attrs[name]; + attrs[this.attr] = this.value; + var updated = doc.type.create(attrs, doc.content, doc.marks); + return StepResult.ok(updated); + } + }, { + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "invert", + value: function invert(doc) { + return new DocAttrStep(this.attr, doc.attrs[this.attr]); + } + }, { + key: "map", + value: function map(mapping) { + return this; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "docAttr", + attr: this.attr, + value: this.value + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.attr != "string") throw new RangeError("Invalid input for DocAttrStep.fromJSON"); + return new DocAttrStep(json.attr, json.value); + } + }]); + return DocAttrStep; +}(Step); +Step.jsonID("docAttr", DocAttrStep); +exports.TransformError = function (_Error) { + _inherits(TransformError, _Error); + var _super9 = _createSuper(TransformError); + function TransformError() { + _classCallCheck(this, TransformError); + return _super9.apply(this, arguments); + } + return _createClass(TransformError); +}(_wrapNativeSuper(Error)); +exports.TransformError = function TransformError(message) { + var err = Error.call(this, message); + err.__proto__ = TransformError.prototype; + return err; +}; +exports.TransformError.prototype = Object.create(Error.prototype); +exports.TransformError.prototype.constructor = exports.TransformError; +exports.TransformError.prototype.name = "TransformError"; +var Transform = function () { + function Transform(doc) { + _classCallCheck(this, Transform); + this.doc = doc; + this.steps = []; + this.docs = []; + this.mapping = new Mapping(); + } + _createClass(Transform, [{ + key: "before", + get: function get() { + return this.docs.length ? this.docs[0] : this.doc; + } + }, { + key: "step", + value: function step(_step) { + var result = this.maybeStep(_step); + if (result.failed) throw new exports.TransformError(result.failed); + return this; + } + }, { + key: "maybeStep", + value: function maybeStep(step) { + var result = step.apply(this.doc); + if (!result.failed) this.addStep(step, result.doc); + return result; + } + }, { + key: "docChanged", + get: function get() { + return this.steps.length > 0; + } + }, { + key: "addStep", + value: function addStep(step, doc) { + this.docs.push(this.doc); + this.steps.push(step); + this.mapping.appendMap(step.getMap()); + this.doc = doc; + } + }, { + key: "replace", + value: function replace(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from; + var slice = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : prosemirrorModel.Slice.empty; + var step = replaceStep(this.doc, from, to, slice); + if (step) this.step(step); + return this; + } + }, { + key: "replaceWith", + value: function replaceWith(from, to, content) { + return this.replace(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(content), 0, 0)); + } + }, { + key: "delete", + value: function _delete(from, to) { + return this.replace(from, to, prosemirrorModel.Slice.empty); + } + }, { + key: "insert", + value: function insert(pos, content) { + return this.replaceWith(pos, pos, content); + } + }, { + key: "replaceRange", + value: function replaceRange(from, to, slice) { + _replaceRange(this, from, to, slice); + return this; + } + }, { + key: "replaceRangeWith", + value: function replaceRangeWith(from, to, node) { + _replaceRangeWith(this, from, to, node); + return this; + } + }, { + key: "deleteRange", + value: function deleteRange(from, to) { + _deleteRange(this, from, to); + return this; + } + }, { + key: "lift", + value: function lift(range, target) { + _lift(this, range, target); + return this; + } + }, { + key: "join", + value: function join(pos) { + var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + _join(this, pos, depth); + return this; + } + }, { + key: "wrap", + value: function wrap(range, wrappers) { + _wrap2(this, range, wrappers); + return this; + } + }, { + key: "setBlockType", + value: function setBlockType(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from; + var type = arguments.length > 2 ? arguments[2] : undefined; + var attrs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _setBlockType(this, from, to, type, attrs); + return this; + } + }, { + key: "setNodeMarkup", + value: function setNodeMarkup(pos, type) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var marks = arguments.length > 3 ? arguments[3] : undefined; + _setNodeMarkup(this, pos, type, attrs, marks); + return this; + } + }, { + key: "setNodeAttribute", + value: function setNodeAttribute(pos, attr, value) { + this.step(new AttrStep(pos, attr, value)); + return this; + } + }, { + key: "setDocAttribute", + value: function setDocAttribute(attr, value) { + this.step(new DocAttrStep(attr, value)); + return this; + } + }, { + key: "addNodeMark", + value: function addNodeMark(pos, mark) { + this.step(new AddNodeMarkStep(pos, mark)); + return this; + } + }, { + key: "removeNodeMark", + value: function removeNodeMark(pos, mark) { + if (!(mark instanceof prosemirrorModel.Mark)) { + var node = this.doc.nodeAt(pos); + if (!node) throw new RangeError("No node at position " + pos); + mark = mark.isInSet(node.marks); + if (!mark) return this; + } + this.step(new RemoveNodeMarkStep(pos, mark)); + return this; + } + }, { + key: "split", + value: function split(pos) { + var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var typesAfter = arguments.length > 2 ? arguments[2] : undefined; + _split(this, pos, depth, typesAfter); + return this; + } + }, { + key: "addMark", + value: function addMark(from, to, mark) { + _addMark(this, from, to, mark); + return this; + } + }, { + key: "removeMark", + value: function removeMark(from, to, mark) { + _removeMark(this, from, to, mark); + return this; + } + }, { + key: "clearIncompatible", + value: function clearIncompatible(pos, parentType, match) { + _clearIncompatible(this, pos, parentType, match); + return this; + } + }]); + return Transform; +}(); +exports.AddMarkStep = AddMarkStep; +exports.AddNodeMarkStep = AddNodeMarkStep; +exports.AttrStep = AttrStep; +exports.DocAttrStep = DocAttrStep; +exports.MapResult = MapResult; +exports.Mapping = Mapping; +exports.RemoveMarkStep = RemoveMarkStep; +exports.RemoveNodeMarkStep = RemoveNodeMarkStep; +exports.ReplaceAroundStep = ReplaceAroundStep; +exports.ReplaceStep = ReplaceStep; +exports.Step = Step; +exports.StepMap = StepMap; +exports.StepResult = StepResult; +exports.Transform = Transform; +exports.canJoin = canJoin; +exports.canSplit = canSplit; +exports.dropPoint = dropPoint; +exports.findWrapping = findWrapping; +exports.insertPoint = insertPoint; +exports.joinPoint = joinPoint; +exports.liftTarget = liftTarget; +exports.replaceStep = replaceStep; + +}); +define("prosemirror-view",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorState = require('prosemirror-state'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorTransform = require('prosemirror-transform'); +var domIndex = function domIndex(node) { + for (var index = 0;; index++) { + node = node.previousSibling; + if (!node) return index; + } +}; +var parentNode = function parentNode(node) { + var parent = node.assignedSlot || node.parentNode; + return parent && parent.nodeType == 11 ? parent.host : parent; +}; +var reusedRange = null; +var textRange = function textRange(node, from, to) { + var range = reusedRange || (reusedRange = document.createRange()); + range.setEnd(node, to == null ? node.nodeValue.length : to); + range.setStart(node, from || 0); + return range; +}; +var clearReusedRange = function clearReusedRange() { + reusedRange = null; +}; +var isEquivalentPosition = function isEquivalentPosition(node, off, targetNode, targetOff) { + return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1)); +}; +var atomElements = /^(img|br|input|textarea|hr)$/i; +function scanFor(node, off, targetNode, targetOff, dir) { + for (;;) { + if (node == targetNode && off == targetOff) return true; + if (off == (dir < 0 ? 0 : nodeSize(node))) { + var parent = node.parentNode; + if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false; + off = domIndex(node) + (dir < 0 ? 0 : 1); + node = parent; + } else if (node.nodeType == 1) { + node = node.childNodes[off + (dir < 0 ? -1 : 0)]; + if (node.contentEditable == "false") return false; + off = dir < 0 ? nodeSize(node) : 0; + } else { + return false; + } + } +} +function nodeSize(node) { + return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; +} +function textNodeBefore$1(node, offset) { + for (;;) { + if (node.nodeType == 3 && offset) return node; + if (node.nodeType == 1 && offset > 0) { + if (node.contentEditable == "false") return null; + node = node.childNodes[offset - 1]; + offset = nodeSize(node); + } else if (node.parentNode && !hasBlockDesc(node)) { + offset = domIndex(node); + node = node.parentNode; + } else { + return null; + } + } +} +function textNodeAfter$1(node, offset) { + for (;;) { + if (node.nodeType == 3 && offset < node.nodeValue.length) return node; + if (node.nodeType == 1 && offset < node.childNodes.length) { + if (node.contentEditable == "false") return null; + node = node.childNodes[offset]; + offset = 0; + } else if (node.parentNode && !hasBlockDesc(node)) { + offset = domIndex(node) + 1; + node = node.parentNode; + } else { + return null; + } + } +} +function isOnEdge(node, offset, parent) { + for (var atStart = offset == 0, atEnd = offset == nodeSize(node); atStart || atEnd;) { + if (node == parent) return true; + var index = domIndex(node); + node = node.parentNode; + if (!node) return false; + atStart = atStart && index == 0; + atEnd = atEnd && index == nodeSize(node); + } +} +function hasBlockDesc(dom) { + var desc; + for (var cur = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break; + return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom); +} +var selectionCollapsed = function selectionCollapsed(domSel) { + return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset); +}; +function keyEvent(keyCode, key) { + var event = document.createEvent("Event"); + event.initEvent("keydown", true, true); + event.keyCode = keyCode; + event.key = event.code = key; + return event; +} +function deepActiveElement(doc) { + var elt = doc.activeElement; + while (elt && elt.shadowRoot) elt = elt.shadowRoot.activeElement; + return elt; +} +function caretFromPoint(doc, x, y) { + if (doc.caretPositionFromPoint) { + try { + var pos = doc.caretPositionFromPoint(x, y); + if (pos) return { + node: pos.offsetNode, + offset: Math.min(nodeSize(pos.offsetNode), pos.offset) + }; + } catch (_) {} + } + if (doc.caretRangeFromPoint) { + var range = doc.caretRangeFromPoint(x, y); + if (range) return { + node: range.startContainer, + offset: Math.min(nodeSize(range.startContainer), range.startOffset) + }; + } +} +var nav = typeof navigator != "undefined" ? navigator : null; +var doc = typeof document != "undefined" ? document : null; +var agent = nav && nav.userAgent || ""; +var ie_edge = /Edge\/(\d+)/.exec(agent); +var ie_upto10 = /MSIE \d/.exec(agent); +var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent); +var ie = !!(ie_upto10 || ie_11up || ie_edge); +var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0; +var gecko = !ie && /gecko\/(\d+)/i.test(agent); +gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1]; +var _chrome = !ie && /Chrome\/(\d+)/.exec(agent); +var chrome = !!_chrome; +var chrome_version = _chrome ? +_chrome[1] : 0; +var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor); +var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2); +var mac = ios || (nav ? /Mac/.test(nav.platform) : false); +var windows = nav ? /Win/.test(nav.platform) : false; +var android = /Android \d/.test(agent); +var webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style; +var webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0; +function windowRect(doc) { + var vp = doc.defaultView && doc.defaultView.visualViewport; + if (vp) return { + left: 0, + right: vp.width, + top: 0, + bottom: vp.height + }; + return { + left: 0, + right: doc.documentElement.clientWidth, + top: 0, + bottom: doc.documentElement.clientHeight + }; +} +function getSide(value, side) { + return typeof value == "number" ? value : value[side]; +} +function clientRect(node) { + var rect = node.getBoundingClientRect(); + var scaleX = rect.width / node.offsetWidth || 1; + var scaleY = rect.height / node.offsetHeight || 1; + return { + left: rect.left, + right: rect.left + node.clientWidth * scaleX, + top: rect.top, + bottom: rect.top + node.clientHeight * scaleY + }; +} +function scrollRectIntoView(view, rect, startDOM) { + var scrollThreshold = view.someProp("scrollThreshold") || 0, + scrollMargin = view.someProp("scrollMargin") || 5; + var doc = view.dom.ownerDocument; + for (var parent = startDOM || view.dom;; parent = parentNode(parent)) { + if (!parent) break; + if (parent.nodeType != 1) continue; + var elt = parent; + var atTop = elt == doc.body; + var bounding = atTop ? windowRect(doc) : clientRect(elt); + var moveX = 0, + moveY = 0; + if (rect.top < bounding.top + getSide(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top"));else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom"); + if (rect.left < bounding.left + getSide(scrollThreshold, "left")) moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left"));else if (rect.right > bounding.right - getSide(scrollThreshold, "right")) moveX = rect.right - bounding.right + getSide(scrollMargin, "right"); + if (moveX || moveY) { + if (atTop) { + doc.defaultView.scrollBy(moveX, moveY); + } else { + var startX = elt.scrollLeft, + startY = elt.scrollTop; + if (moveY) elt.scrollTop += moveY; + if (moveX) elt.scrollLeft += moveX; + var dX = elt.scrollLeft - startX, + dY = elt.scrollTop - startY; + rect = { + left: rect.left - dX, + top: rect.top - dY, + right: rect.right - dX, + bottom: rect.bottom - dY + }; + } + } + if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position)) break; + } +} +function storeScrollPos(view) { + var rect = view.dom.getBoundingClientRect(), + startY = Math.max(0, rect.top); + var refDOM, refTop; + for (var x = (rect.left + rect.right) / 2, y = startY + 1; y < Math.min(innerHeight, rect.bottom); y += 5) { + var dom = view.root.elementFromPoint(x, y); + if (!dom || dom == view.dom || !view.dom.contains(dom)) continue; + var localRect = dom.getBoundingClientRect(); + if (localRect.top >= startY - 20) { + refDOM = dom; + refTop = localRect.top; + break; + } + } + return { + refDOM: refDOM, + refTop: refTop, + stack: scrollStack(view.dom) + }; +} +function scrollStack(dom) { + var stack = [], + doc = dom.ownerDocument; + for (var cur = dom; cur; cur = parentNode(cur)) { + stack.push({ + dom: cur, + top: cur.scrollTop, + left: cur.scrollLeft + }); + if (dom == doc) break; + } + return stack; +} +function resetScrollPos(_ref) { + var refDOM = _ref.refDOM, + refTop = _ref.refTop, + stack = _ref.stack; + var newRefTop = refDOM ? refDOM.getBoundingClientRect().top : 0; + restoreScrollStack(stack, newRefTop == 0 ? 0 : newRefTop - refTop); +} +function restoreScrollStack(stack, dTop) { + for (var i = 0; i < stack.length; i++) { + var _stack$i = stack[i], + dom = _stack$i.dom, + top = _stack$i.top, + left = _stack$i.left; + if (dom.scrollTop != top + dTop) dom.scrollTop = top + dTop; + if (dom.scrollLeft != left) dom.scrollLeft = left; + } +} +var preventScrollSupported = null; +function focusPreventScroll(dom) { + if (dom.setActive) return dom.setActive(); + if (preventScrollSupported) return dom.focus(preventScrollSupported); + var stored = scrollStack(dom); + dom.focus(preventScrollSupported == null ? { + get preventScroll() { + preventScrollSupported = { + preventScroll: true + }; + return true; + } + } : undefined); + if (!preventScrollSupported) { + preventScrollSupported = false; + restoreScrollStack(stored, 0); + } +} +function findOffsetInNode(node, coords) { + var closest, + dxClosest = 2e8, + coordsClosest, + offset = 0; + var rowBot = coords.top, + rowTop = coords.top; + var firstBelow, coordsBelow; + for (var child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) { + var rects = void 0; + if (child.nodeType == 1) rects = child.getClientRects();else if (child.nodeType == 3) rects = textRange(child).getClientRects();else continue; + for (var i = 0; i < rects.length; i++) { + var rect = rects[i]; + if (rect.top <= rowBot && rect.bottom >= rowTop) { + rowBot = Math.max(rect.bottom, rowBot); + rowTop = Math.min(rect.top, rowTop); + var dx = rect.left > coords.left ? rect.left - coords.left : rect.right < coords.left ? coords.left - rect.right : 0; + if (dx < dxClosest) { + closest = child; + dxClosest = dx; + coordsClosest = dx && closest.nodeType == 3 ? { + left: rect.right < coords.left ? rect.right : rect.left, + top: coords.top + } : coords; + if (child.nodeType == 1 && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0); + continue; + } + } else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) { + firstBelow = child; + coordsBelow = { + left: Math.max(rect.left, Math.min(rect.right, coords.left)), + top: rect.top + }; + } + if (!closest && (coords.left >= rect.right && coords.top >= rect.top || coords.left >= rect.left && coords.top >= rect.bottom)) offset = childIndex + 1; + } + } + if (!closest && firstBelow) { + closest = firstBelow; + coordsClosest = coordsBelow; + dxClosest = 0; + } + if (closest && closest.nodeType == 3) return findOffsetInText(closest, coordsClosest); + if (!closest || dxClosest && closest.nodeType == 1) return { + node: node, + offset: offset + }; + return findOffsetInNode(closest, coordsClosest); +} +function findOffsetInText(node, coords) { + var len = node.nodeValue.length; + var range = document.createRange(); + for (var i = 0; i < len; i++) { + range.setEnd(node, i + 1); + range.setStart(node, i); + var rect = singleRect(range, 1); + if (rect.top == rect.bottom) continue; + if (inRect(coords, rect)) return { + node: node, + offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) + }; + } + return { + node: node, + offset: 0 + }; +} +function inRect(coords, rect) { + return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1; +} +function targetKludge(dom, coords) { + var parent = dom.parentNode; + if (parent && /^li$/i.test(parent.nodeName) && coords.left < dom.getBoundingClientRect().left) return parent; + return dom; +} +function posFromElement(view, elt, coords) { + var _findOffsetInNode = findOffsetInNode(elt, coords), + node = _findOffsetInNode.node, + offset = _findOffsetInNode.offset, + bias = -1; + if (node.nodeType == 1 && !node.firstChild) { + var rect = node.getBoundingClientRect(); + bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1; + } + return view.docView.posFromDOM(node, offset, bias); +} +function posFromCaret(view, node, offset, coords) { + var outsideBlock = -1; + for (var cur = node, sawBlock = false;;) { + if (cur == view.dom) break; + var desc = view.docView.nearestDesc(cur, true); + if (!desc) return null; + if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) { + var rect = desc.dom.getBoundingClientRect(); + if (desc.node.isBlock && desc.parent) { + if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter; + sawBlock = true; + } + if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) { + var before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2; + return before ? desc.posBefore : desc.posAfter; + } + } + cur = desc.dom.parentNode; + } + return outsideBlock > -1 ? outsideBlock : view.docView.posFromDOM(node, offset, -1); +} +function elementFromPoint(element, coords, box) { + var len = element.childNodes.length; + if (len && box.top < box.bottom) { + for (var startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) { + var child = element.childNodes[i]; + if (child.nodeType == 1) { + var rects = child.getClientRects(); + for (var j = 0; j < rects.length; j++) { + var rect = rects[j]; + if (inRect(coords, rect)) return elementFromPoint(child, coords, rect); + } + } + if ((i = (i + 1) % len) == startI) break; + } + } + return element; +} +function _posAtCoords(view, coords) { + var doc = view.dom.ownerDocument, + node, + offset = 0; + var caret = caretFromPoint(doc, coords.left, coords.top); + if (caret) { + node = caret.node; + offset = caret.offset; + } + var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top); + var pos; + if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) { + var box = view.dom.getBoundingClientRect(); + if (!inRect(coords, box)) return null; + elt = elementFromPoint(view.dom, coords, box); + if (!elt) return null; + } + if (safari) { + for (var p = elt; node && p; p = parentNode(p)) if (p.draggable) node = undefined; + } + elt = targetKludge(elt, coords); + if (node) { + if (gecko && node.nodeType == 1) { + offset = Math.min(offset, node.childNodes.length); + if (offset < node.childNodes.length) { + var next = node.childNodes[offset], + _box; + if (next.nodeName == "IMG" && (_box = next.getBoundingClientRect()).right <= coords.left && _box.bottom > coords.top) offset++; + } + } + var prev; + if (webkit && offset && node.nodeType == 1 && (prev = node.childNodes[offset - 1]).nodeType == 1 && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--; + if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords); + } + if (pos == null) pos = posFromElement(view, elt, coords); + var desc = view.docView.nearestDesc(elt, true); + return { + pos: pos, + inside: desc ? desc.posAtStart - desc.border : -1 + }; +} +function nonZero(rect) { + return rect.top < rect.bottom || rect.left < rect.right; +} +function singleRect(target, bias) { + var rects = target.getClientRects(); + if (rects.length) { + var first = rects[bias < 0 ? 0 : rects.length - 1]; + if (nonZero(first)) return first; + } + return Array.prototype.find.call(rects, nonZero) || target.getBoundingClientRect(); +} +var BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/; +function _coordsAtPos(view, pos, side) { + var _view$docView$domFrom = view.docView.domFromPos(pos, side < 0 ? -1 : 1), + node = _view$docView$domFrom.node, + offset = _view$docView$domFrom.offset, + atom = _view$docView$domFrom.atom; + var supportEmptyRange = webkit || gecko; + if (node.nodeType == 3) { + if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) { + var rect = singleRect(textRange(node, offset, offset), side); + if (gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) { + var rectBefore = singleRect(textRange(node, offset - 1, offset - 1), -1); + if (rectBefore.top == rect.top) { + var rectAfter = singleRect(textRange(node, offset, offset + 1), -1); + if (rectAfter.top != rect.top) return flattenV(rectAfter, rectAfter.left < rectBefore.left); + } + } + return rect; + } else { + var from = offset, + to = offset, + takeSide = side < 0 ? 1 : -1; + if (side < 0 && !offset) { + to++; + takeSide = -1; + } else if (side >= 0 && offset == node.nodeValue.length) { + from--; + takeSide = 1; + } else if (side < 0) { + from--; + } else { + to++; + } + return flattenV(singleRect(textRange(node, from, to), takeSide), takeSide < 0); + } + } + var $dom = view.state.doc.resolve(pos - (atom || 0)); + if (!$dom.parent.inlineContent) { + if (atom == null && offset && (side < 0 || offset == nodeSize(node))) { + var before = node.childNodes[offset - 1]; + if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false); + } + if (atom == null && offset < nodeSize(node)) { + var after = node.childNodes[offset]; + if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true); + } + return flattenH(node.getBoundingClientRect(), side >= 0); + } + if (atom == null && offset && (side < 0 || offset == nodeSize(node))) { + var _before = node.childNodes[offset - 1]; + var target = _before.nodeType == 3 ? textRange(_before, nodeSize(_before) - (supportEmptyRange ? 0 : 1)) : _before.nodeType == 1 && (_before.nodeName != "BR" || !_before.nextSibling) ? _before : null; + if (target) return flattenV(singleRect(target, 1), false); + } + if (atom == null && offset < nodeSize(node)) { + var _after = node.childNodes[offset]; + while (_after.pmViewDesc && _after.pmViewDesc.ignoreForCoords) _after = _after.nextSibling; + var _target = !_after ? null : _after.nodeType == 3 ? textRange(_after, 0, supportEmptyRange ? 0 : 1) : _after.nodeType == 1 ? _after : null; + if (_target) return flattenV(singleRect(_target, -1), true); + } + return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0); +} +function flattenV(rect, left) { + if (rect.width == 0) return rect; + var x = left ? rect.left : rect.right; + return { + top: rect.top, + bottom: rect.bottom, + left: x, + right: x + }; +} +function flattenH(rect, top) { + if (rect.height == 0) return rect; + var y = top ? rect.top : rect.bottom; + return { + top: y, + bottom: y, + left: rect.left, + right: rect.right + }; +} +function withFlushedState(view, state, f) { + var viewState = view.state, + active = view.root.activeElement; + if (viewState != state) view.updateState(state); + if (active != view.dom) view.focus(); + try { + return f(); + } finally { + if (viewState != state) view.updateState(viewState); + if (active != view.dom && active) active.focus(); + } +} +function endOfTextblockVertical(view, state, dir) { + var sel = state.selection; + var $pos = dir == "up" ? sel.$from : sel.$to; + return withFlushedState(view, state, function () { + var _view$docView$domFrom2 = view.docView.domFromPos($pos.pos, dir == "up" ? -1 : 1), + dom = _view$docView$domFrom2.node; + for (;;) { + var nearest = view.docView.nearestDesc(dom, true); + if (!nearest) break; + if (nearest.node.isBlock) { + dom = nearest.contentDOM || nearest.dom; + break; + } + dom = nearest.dom.parentNode; + } + var coords = _coordsAtPos(view, $pos.pos, 1); + for (var child = dom.firstChild; child; child = child.nextSibling) { + var boxes = void 0; + if (child.nodeType == 1) boxes = child.getClientRects();else if (child.nodeType == 3) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();else continue; + for (var i = 0; i < boxes.length; i++) { + var box = boxes[i]; + if (box.bottom > box.top + 1 && (dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2 : box.bottom - coords.bottom > (coords.bottom - box.top) * 2)) return false; + } + } + return true; + }); +} +var maybeRTL = /[\u0590-\u08ac]/; +function endOfTextblockHorizontal(view, state, dir) { + var $head = state.selection.$head; + if (!$head.parent.isTextblock) return false; + var offset = $head.parentOffset, + atStart = !offset, + atEnd = offset == $head.parent.content.size; + var sel = view.domSelection(); + if (!sel) return $head.pos == $head.start() || $head.pos == $head.end(); + if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd; + return withFlushedState(view, state, function () { + var _view$domSelectionRan = view.domSelectionRange(), + oldNode = _view$domSelectionRan.focusNode, + oldOff = _view$domSelectionRan.focusOffset, + anchorNode = _view$domSelectionRan.anchorNode, + anchorOffset = _view$domSelectionRan.anchorOffset; + var oldBidiLevel = sel.caretBidiLevel; + sel.modify("move", dir, "character"); + var parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom; + var _view$domSelectionRan2 = view.domSelectionRange(), + newNode = _view$domSelectionRan2.focusNode, + newOff = _view$domSelectionRan2.focusOffset; + var result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff; + try { + sel.collapse(anchorNode, anchorOffset); + if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff); + } catch (_) {} + if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel; + return result; + }); +} +var cachedState = null; +var cachedDir = null; +var cachedResult = false; +function _endOfTextblock(view, state, dir) { + if (cachedState == state && cachedDir == dir) return cachedResult; + cachedState = state; + cachedDir = dir; + return cachedResult = dir == "up" || dir == "down" ? endOfTextblockVertical(view, state, dir) : endOfTextblockHorizontal(view, state, dir); +} +var NOT_DIRTY = 0, + CHILD_DIRTY = 1, + CONTENT_DIRTY = 2, + NODE_DIRTY = 3; +var ViewDesc = function () { + function ViewDesc(parent, children, dom, contentDOM) { + _classCallCheck(this, ViewDesc); + this.parent = parent; + this.children = children; + this.dom = dom; + this.contentDOM = contentDOM; + this.dirty = NOT_DIRTY; + dom.pmViewDesc = this; + } + _createClass(ViewDesc, [{ + key: "matchesWidget", + value: function matchesWidget(widget) { + return false; + } + }, { + key: "matchesMark", + value: function matchesMark(mark) { + return false; + } + }, { + key: "matchesNode", + value: function matchesNode(node, outerDeco, innerDeco) { + return false; + } + }, { + key: "matchesHack", + value: function matchesHack(nodeName) { + return false; + } + }, { + key: "parseRule", + value: function parseRule() { + return null; + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + return false; + } + }, { + key: "size", + get: function get() { + var size = 0; + for (var i = 0; i < this.children.length; i++) size += this.children[i].size; + return size; + } + }, { + key: "border", + get: function get() { + return 0; + } + }, { + key: "destroy", + value: function destroy() { + this.parent = undefined; + if (this.dom.pmViewDesc == this) this.dom.pmViewDesc = undefined; + for (var i = 0; i < this.children.length; i++) this.children[i].destroy(); + } + }, { + key: "posBeforeChild", + value: function posBeforeChild(child) { + for (var i = 0, pos = this.posAtStart;; i++) { + var cur = this.children[i]; + if (cur == child) return pos; + pos += cur.size; + } + } + }, { + key: "posBefore", + get: function get() { + return this.parent.posBeforeChild(this); + } + }, { + key: "posAtStart", + get: function get() { + return this.parent ? this.parent.posBeforeChild(this) + this.border : 0; + } + }, { + key: "posAfter", + get: function get() { + return this.posBefore + this.size; + } + }, { + key: "posAtEnd", + get: function get() { + return this.posAtStart + this.size - 2 * this.border; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset, bias) { + if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) { + if (bias < 0) { + var domBefore, desc; + if (dom == this.contentDOM) { + domBefore = dom.childNodes[offset - 1]; + } else { + while (dom.parentNode != this.contentDOM) dom = dom.parentNode; + domBefore = dom.previousSibling; + } + while (domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this)) domBefore = domBefore.previousSibling; + return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart; + } else { + var domAfter, _desc; + if (dom == this.contentDOM) { + domAfter = dom.childNodes[offset]; + } else { + while (dom.parentNode != this.contentDOM) dom = dom.parentNode; + domAfter = dom.nextSibling; + } + while (domAfter && !((_desc = domAfter.pmViewDesc) && _desc.parent == this)) domAfter = domAfter.nextSibling; + return domAfter ? this.posBeforeChild(_desc) : this.posAtEnd; + } + } + var atEnd; + if (dom == this.dom && this.contentDOM) { + atEnd = offset > domIndex(this.contentDOM); + } else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) { + atEnd = dom.compareDocumentPosition(this.contentDOM) & 2; + } else if (this.dom.firstChild) { + if (offset == 0) for (var search = dom;; search = search.parentNode) { + if (search == this.dom) { + atEnd = false; + break; + } + if (search.previousSibling) break; + } + if (atEnd == null && offset == dom.childNodes.length) for (var _search = dom;; _search = _search.parentNode) { + if (_search == this.dom) { + atEnd = true; + break; + } + if (_search.nextSibling) break; + } + } + return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart; + } + }, { + key: "nearestDesc", + value: function nearestDesc(dom) { + var onlyNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + for (var first = true, cur = dom; cur; cur = cur.parentNode) { + var desc = this.getDesc(cur), + nodeDOM = void 0; + if (desc && (!onlyNodes || desc.node)) { + if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first = false;else return desc; + } + } + } + }, { + key: "getDesc", + value: function getDesc(dom) { + var desc = dom.pmViewDesc; + for (var cur = desc; cur; cur = cur.parent) if (cur == this) return desc; + } + }, { + key: "posFromDOM", + value: function posFromDOM(dom, offset, bias) { + for (var scan = dom; scan; scan = scan.parentNode) { + var desc = this.getDesc(scan); + if (desc) return desc.localPosFromDOM(dom, offset, bias); + } + return -1; + } + }, { + key: "descAt", + value: function descAt(pos) { + for (var i = 0, offset = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (offset == pos && end != offset) { + while (!child.border && child.children.length) child = child.children[0]; + return child; + } + if (pos < end) return child.descAt(pos - offset - child.border); + offset = end; + } + } + }, { + key: "domFromPos", + value: function domFromPos(pos, side) { + if (!this.contentDOM) return { + node: this.dom, + offset: 0, + atom: pos + 1 + }; + var i = 0, + offset = 0; + for (var curPos = 0; i < this.children.length; i++) { + var child = this.children[i], + end = curPos + child.size; + if (end > pos || child instanceof TrailingHackViewDesc) { + offset = pos - curPos; + break; + } + curPos = end; + } + if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side); + for (var prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--) {} + if (side <= 0) { + var _prev, + enter = true; + for (;; i--, enter = false) { + _prev = i ? this.children[i - 1] : null; + if (!_prev || _prev.dom.parentNode == this.contentDOM) break; + } + if (_prev && side && enter && !_prev.border && !_prev.domAtom) return _prev.domFromPos(_prev.size, side); + return { + node: this.contentDOM, + offset: _prev ? domIndex(_prev.dom) + 1 : 0 + }; + } else { + var next, + _enter = true; + for (;; i++, _enter = false) { + next = i < this.children.length ? this.children[i] : null; + if (!next || next.dom.parentNode == this.contentDOM) break; + } + if (next && _enter && !next.border && !next.domAtom) return next.domFromPos(0, side); + return { + node: this.contentDOM, + offset: next ? domIndex(next.dom) : this.contentDOM.childNodes.length + }; + } + } + }, { + key: "parseRange", + value: function parseRange(from, to) { + var base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + if (this.children.length == 0) return { + node: this.contentDOM, + from: from, + to: to, + fromOffset: 0, + toOffset: this.contentDOM.childNodes.length + }; + var fromOffset = -1, + toOffset = -1; + for (var offset = base, i = 0;; i++) { + var child = this.children[i], + end = offset + child.size; + if (fromOffset == -1 && from <= end) { + var childBase = offset + child.border; + if (from >= childBase && to <= end - child.border && child.node && child.contentDOM && this.contentDOM.contains(child.contentDOM)) return child.parseRange(from, to, childBase); + from = offset; + for (var j = i; j > 0; j--) { + var prev = this.children[j - 1]; + if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) { + fromOffset = domIndex(prev.dom) + 1; + break; + } + from -= prev.size; + } + if (fromOffset == -1) fromOffset = 0; + } + if (fromOffset > -1 && (end > to || i == this.children.length - 1)) { + to = end; + for (var _j = i + 1; _j < this.children.length; _j++) { + var next = this.children[_j]; + if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) { + toOffset = domIndex(next.dom); + break; + } + to += next.size; + } + if (toOffset == -1) toOffset = this.contentDOM.childNodes.length; + break; + } + offset = end; + } + return { + node: this.contentDOM, + from: from, + to: to, + fromOffset: fromOffset, + toOffset: toOffset + }; + } + }, { + key: "emptyChildAt", + value: function emptyChildAt(side) { + if (this.border || !this.contentDOM || !this.children.length) return false; + var child = this.children[side < 0 ? 0 : this.children.length - 1]; + return child.size == 0 || child.emptyChildAt(side); + } + }, { + key: "domAfterPos", + value: function domAfterPos(pos) { + var _this$domFromPos = this.domFromPos(pos, 0), + node = _this$domFromPos.node, + offset = _this$domFromPos.offset; + if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos); + return node.childNodes[offset]; + } + }, { + key: "setSelection", + value: function setSelection(anchor, head, root) { + var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + var from = Math.min(anchor, head), + to = Math.max(anchor, head); + for (var i = 0, offset = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (from > offset && to < end) return child.setSelection(anchor - offset - child.border, head - offset - child.border, root, force); + offset = end; + } + var anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1); + var headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1); + var domSel = root.getSelection(); + var brKludge = false; + if ((gecko || safari) && anchor == head) { + var _anchorDOM = anchorDOM, + node = _anchorDOM.node, + _offset = _anchorDOM.offset; + if (node.nodeType == 3) { + brKludge = !!(_offset && node.nodeValue[_offset - 1] == "\n"); + if (brKludge && _offset == node.nodeValue.length) { + for (var scan = node, after; scan; scan = scan.parentNode) { + if (after = scan.nextSibling) { + if (after.nodeName == "BR") anchorDOM = headDOM = { + node: after.parentNode, + offset: domIndex(after) + 1 + }; + break; + } + var desc = scan.pmViewDesc; + if (desc && desc.node && desc.node.isBlock) break; + } + } + } else { + var prev = node.childNodes[_offset - 1]; + brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false"); + } + } + if (gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) { + var _after2 = domSel.focusNode.childNodes[domSel.focusOffset]; + if (_after2 && _after2.contentEditable == "false") force = true; + } + if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, domSel.focusNode, domSel.focusOffset)) return; + var domSelExtended = false; + if ((domSel.extend || anchor == head) && !brKludge) { + domSel.collapse(anchorDOM.node, anchorDOM.offset); + try { + if (anchor != head) domSel.extend(headDOM.node, headDOM.offset); + domSelExtended = true; + } catch (_) {} + } + if (!domSelExtended) { + if (anchor > head) { + var tmp = anchorDOM; + anchorDOM = headDOM; + headDOM = tmp; + } + var range = document.createRange(); + range.setEnd(headDOM.node, headDOM.offset); + range.setStart(anchorDOM.node, anchorDOM.offset); + domSel.removeAllRanges(); + domSel.addRange(range); + } + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return !this.contentDOM && mutation.type != "selection"; + } + }, { + key: "contentLost", + get: function get() { + return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + for (var offset = 0, i = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (offset == end ? from <= end && to >= offset : from < end && to > offset) { + var startInside = offset + child.border, + endInside = end - child.border; + if (from >= startInside && to <= endInside) { + this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY; + if (from == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY;else child.markDirty(from - startInside, to - startInside); + return; + } else { + child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY; + } + } + offset = end; + } + this.dirty = CONTENT_DIRTY; + } + }, { + key: "markParentsDirty", + value: function markParentsDirty() { + var level = 1; + for (var node = this.parent; node; node = node.parent, level++) { + var dirty = level == 1 ? CONTENT_DIRTY : CHILD_DIRTY; + if (node.dirty < dirty) node.dirty = dirty; + } + } + }, { + key: "domAtom", + get: function get() { + return false; + } + }, { + key: "ignoreForCoords", + get: function get() { + return false; + } + }, { + key: "isText", + value: function isText(text) { + return false; + } + }]); + return ViewDesc; +}(); +var WidgetViewDesc = function (_ViewDesc) { + _inherits(WidgetViewDesc, _ViewDesc); + var _super = _createSuper(WidgetViewDesc); + function WidgetViewDesc(parent, widget, view, pos) { + var _this; + _classCallCheck(this, WidgetViewDesc); + var self, + dom = widget.type.toDOM; + if (typeof dom == "function") dom = dom(view, function () { + if (!self) return pos; + if (self.parent) return self.parent.posBeforeChild(self); + }); + if (!widget.type.spec.raw) { + if (dom.nodeType != 1) { + var wrap = document.createElement("span"); + wrap.appendChild(dom); + dom = wrap; + } + dom.contentEditable = "false"; + dom.classList.add("ProseMirror-widget"); + } + _this = _super.call(this, parent, [], dom, null); + _this.widget = widget; + _this.widget = widget; + self = _assertThisInitialized(_this); + return _this; + } + _createClass(WidgetViewDesc, [{ + key: "matchesWidget", + value: function matchesWidget(widget) { + return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type); + } + }, { + key: "parseRule", + value: function parseRule() { + return { + ignore: true + }; + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + var stop = this.widget.spec.stopEvent; + return stop ? stop(event) : false; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return mutation.type != "selection" || this.widget.spec.ignoreSelection; + } + }, { + key: "destroy", + value: function destroy() { + this.widget.type.destroy(this.dom); + _get(_getPrototypeOf(WidgetViewDesc.prototype), "destroy", this).call(this); + } + }, { + key: "domAtom", + get: function get() { + return true; + } + }, { + key: "side", + get: function get() { + return this.widget.type.side; + } + }]); + return WidgetViewDesc; +}(ViewDesc); +var CompositionViewDesc = function (_ViewDesc2) { + _inherits(CompositionViewDesc, _ViewDesc2); + var _super2 = _createSuper(CompositionViewDesc); + function CompositionViewDesc(parent, dom, textDOM, text) { + var _this2; + _classCallCheck(this, CompositionViewDesc); + _this2 = _super2.call(this, parent, [], dom, null); + _this2.textDOM = textDOM; + _this2.text = text; + return _this2; + } + _createClass(CompositionViewDesc, [{ + key: "size", + get: function get() { + return this.text.length; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset) { + if (dom != this.textDOM) return this.posAtStart + (offset ? this.size : 0); + return this.posAtStart + offset; + } + }, { + key: "domFromPos", + value: function domFromPos(pos) { + return { + node: this.textDOM, + offset: pos + }; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mut) { + return mut.type === 'characterData' && mut.target.nodeValue == mut.oldValue; + } + }]); + return CompositionViewDesc; +}(ViewDesc); +var MarkViewDesc = function (_ViewDesc3) { + _inherits(MarkViewDesc, _ViewDesc3); + var _super3 = _createSuper(MarkViewDesc); + function MarkViewDesc(parent, mark, dom, contentDOM) { + var _this3; + _classCallCheck(this, MarkViewDesc); + _this3 = _super3.call(this, parent, [], dom, contentDOM); + _this3.mark = mark; + return _this3; + } + _createClass(MarkViewDesc, [{ + key: "parseRule", + value: function parseRule() { + if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null; + return { + mark: this.mark.type.name, + attrs: this.mark.attrs, + contentElement: this.contentDOM + }; + } + }, { + key: "matchesMark", + value: function matchesMark(mark) { + return this.dirty != NODE_DIRTY && this.mark.eq(mark); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + _get(_getPrototypeOf(MarkViewDesc.prototype), "markDirty", this).call(this, from, to); + if (this.dirty != NOT_DIRTY) { + var parent = this.parent; + while (!parent.node) parent = parent.parent; + if (parent.dirty < this.dirty) parent.dirty = this.dirty; + this.dirty = NOT_DIRTY; + } + } + }, { + key: "slice", + value: function slice(from, to, view) { + var copy = MarkViewDesc.create(this.parent, this.mark, true, view); + var nodes = this.children, + size = this.size; + if (to < size) nodes = replaceNodes(nodes, to, size, view); + if (from > 0) nodes = replaceNodes(nodes, 0, from, view); + for (var i = 0; i < nodes.length; i++) nodes[i].parent = copy; + copy.children = nodes; + return copy; + } + }], [{ + key: "create", + value: function create(parent, mark, inline, view) { + var custom = view.nodeViews[mark.type.name]; + var spec = custom && custom(mark, view, inline); + if (!spec || !spec.dom) spec = prosemirrorModel.DOMSerializer.renderSpec(document, mark.type.spec.toDOM(mark, inline), null, mark.attrs); + return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom); + } + }]); + return MarkViewDesc; +}(ViewDesc); +var NodeViewDesc = function (_ViewDesc4) { + _inherits(NodeViewDesc, _ViewDesc4); + var _super4 = _createSuper(NodeViewDesc); + function NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos) { + var _this4; + _classCallCheck(this, NodeViewDesc); + _this4 = _super4.call(this, parent, [], dom, contentDOM); + _this4.node = node; + _this4.outerDeco = outerDeco; + _this4.innerDeco = innerDeco; + _this4.nodeDOM = nodeDOM; + return _this4; + } + _createClass(NodeViewDesc, [{ + key: "parseRule", + value: function parseRule() { + var _this5 = this; + if (this.node.type.spec.reparseInView) return null; + var rule = { + node: this.node.type.name, + attrs: this.node.attrs + }; + if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full"; + if (!this.contentDOM) { + rule.getContent = function () { + return _this5.node.content; + }; + } else if (!this.contentLost) { + rule.contentElement = this.contentDOM; + } else { + for (var i = this.children.length - 1; i >= 0; i--) { + var child = this.children[i]; + if (this.dom.contains(child.dom.parentNode)) { + rule.contentElement = child.dom.parentNode; + break; + } + } + if (!rule.contentElement) rule.getContent = function () { + return prosemirrorModel.Fragment.empty; + }; + } + return rule; + } + }, { + key: "matchesNode", + value: function matchesNode(node, outerDeco, innerDeco) { + return this.dirty == NOT_DIRTY && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco); + } + }, { + key: "size", + get: function get() { + return this.node.nodeSize; + } + }, { + key: "border", + get: function get() { + return this.node.isLeaf ? 0 : 1; + } + }, { + key: "updateChildren", + value: function updateChildren(view, pos) { + var _this6 = this; + var inline = this.node.inlineContent, + off = pos; + var composition = view.composing ? this.localCompositionInfo(view, pos) : null; + var localComposition = composition && composition.pos > -1 ? composition : null; + var compositionInChild = composition && composition.pos < 0; + var updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view); + iterDeco(this.node, this.innerDeco, function (widget, i, insideNode) { + if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == _this6.node.childCount ? prosemirrorModel.Mark.none : _this6.node.child(i).marks, inline, view); + updater.placeWidget(widget, view, off); + }, function (child, outerDeco, innerDeco, i) { + updater.syncToMarks(child.marks, inline, view); + var compIndex; + if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ;else if (compositionInChild && view.state.selection.from > off && view.state.selection.to < off + child.nodeSize && (compIndex = updater.findIndexWithChild(composition.node)) > -1 && updater.updateNodeAt(child, outerDeco, innerDeco, compIndex, view)) ;else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off)) ;else { + updater.addNode(child, outerDeco, innerDeco, view, off); + } + off += child.nodeSize; + }); + updater.syncToMarks([], inline, view); + if (this.node.isTextblock) updater.addTextblockHacks(); + updater.destroyRest(); + if (updater.changed || this.dirty == CONTENT_DIRTY) { + if (localComposition) this.protectLocalComposition(view, localComposition); + renderDescs(this.contentDOM, this.children, view); + if (ios) iosHacks(this.dom); + } + } + }, { + key: "localCompositionInfo", + value: function localCompositionInfo(view, pos) { + var _view$state$selection = view.state.selection, + from = _view$state$selection.from, + to = _view$state$selection.to; + if (!(view.state.selection instanceof prosemirrorState.TextSelection) || from < pos || to > pos + this.node.content.size) return null; + var textNode = view.input.compositionNode; + if (!textNode || !this.dom.contains(textNode.parentNode)) return null; + if (this.node.inlineContent) { + var text = textNode.nodeValue; + var textPos = findTextInFragment(this.node.content, text, from - pos, to - pos); + return textPos < 0 ? null : { + node: textNode, + pos: textPos, + text: text + }; + } else { + return { + node: textNode, + pos: -1, + text: "" + }; + } + } + }, { + key: "protectLocalComposition", + value: function protectLocalComposition(view, _ref2) { + var node = _ref2.node, + pos = _ref2.pos, + text = _ref2.text; + if (this.getDesc(node)) return; + var topNode = node; + for (;; topNode = topNode.parentNode) { + if (topNode.parentNode == this.contentDOM) break; + while (topNode.previousSibling) topNode.parentNode.removeChild(topNode.previousSibling); + while (topNode.nextSibling) topNode.parentNode.removeChild(topNode.nextSibling); + if (topNode.pmViewDesc) topNode.pmViewDesc = undefined; + } + var desc = new CompositionViewDesc(this, topNode, node, text); + view.input.compositionNodes.push(desc); + this.children = replaceNodes(this.children, pos, pos + text.length, view, desc); + } + }, { + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY || !node.sameMarkup(this.node)) return false; + this.updateInner(node, outerDeco, innerDeco, view); + return true; + } + }, { + key: "updateInner", + value: function updateInner(node, outerDeco, innerDeco, view) { + this.updateOuterDeco(outerDeco); + this.node = node; + this.innerDeco = innerDeco; + if (this.contentDOM) this.updateChildren(view, this.posAtStart); + this.dirty = NOT_DIRTY; + } + }, { + key: "updateOuterDeco", + value: function updateOuterDeco(outerDeco) { + if (sameOuterDeco(outerDeco, this.outerDeco)) return; + var needsWrap = this.nodeDOM.nodeType != 1; + var oldDOM = this.dom; + this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap)); + if (this.dom != oldDOM) { + oldDOM.pmViewDesc = undefined; + this.dom.pmViewDesc = this; + } + this.outerDeco = outerDeco; + } + }, { + key: "selectNode", + value: function selectNode() { + if (this.nodeDOM.nodeType == 1) this.nodeDOM.classList.add("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) this.dom.draggable = true; + } + }, { + key: "deselectNode", + value: function deselectNode() { + if (this.nodeDOM.nodeType == 1) { + this.nodeDOM.classList.remove("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) this.dom.removeAttribute("draggable"); + } + } + }, { + key: "domAtom", + get: function get() { + return this.node.isAtom; + } + }], [{ + key: "create", + value: function create(parent, node, outerDeco, innerDeco, view, pos) { + var custom = view.nodeViews[node.type.name], + descObj; + var spec = custom && custom(node, view, function () { + if (!descObj) return pos; + if (descObj.parent) return descObj.parent.posBeforeChild(descObj); + }, outerDeco, innerDeco); + var dom = spec && spec.dom, + contentDOM = spec && spec.contentDOM; + if (node.isText) { + if (!dom) dom = document.createTextNode(node.text);else if (dom.nodeType != 3) throw new RangeError("Text must be rendered as a DOM text node"); + } else if (!dom) { + var _spec = prosemirrorModel.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs); + dom = _spec.dom; + contentDOM = _spec.contentDOM; + } + if (!contentDOM && !node.isText && dom.nodeName != "BR") { + if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false"; + if (node.type.spec.draggable) dom.draggable = true; + } + var nodeDOM = dom; + dom = applyOuterDeco(dom, outerDeco, node); + if (spec) return descObj = new CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, spec, view, pos + 1);else if (node.isText) return new TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view);else return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, view, pos + 1); + } + }]); + return NodeViewDesc; +}(ViewDesc); +function docViewDesc(doc, outerDeco, innerDeco, dom, view) { + applyOuterDeco(dom, outerDeco, doc); + var docView = new NodeViewDesc(undefined, doc, outerDeco, innerDeco, dom, dom, dom, view, 0); + if (docView.contentDOM) docView.updateChildren(view, 0); + return docView; +} +var TextViewDesc = function (_NodeViewDesc) { + _inherits(TextViewDesc, _NodeViewDesc); + var _super5 = _createSuper(TextViewDesc); + function TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) { + _classCallCheck(this, TextViewDesc); + return _super5.call(this, parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view, 0); + } + _createClass(TextViewDesc, [{ + key: "parseRule", + value: function parseRule() { + var skip = this.nodeDOM.parentNode; + while (skip && skip != this.dom && !skip.pmIsDeco) skip = skip.parentNode; + return { + skip: skip || true + }; + } + }, { + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY || this.dirty != NOT_DIRTY && !this.inParent() || !node.sameMarkup(this.node)) return false; + this.updateOuterDeco(outerDeco); + if ((this.dirty != NOT_DIRTY || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) { + this.nodeDOM.nodeValue = node.text; + if (view.trackWrites == this.nodeDOM) view.trackWrites = null; + } + this.node = node; + this.dirty = NOT_DIRTY; + return true; + } + }, { + key: "inParent", + value: function inParent() { + var parentDOM = this.parent.contentDOM; + for (var n = this.nodeDOM; n; n = n.parentNode) if (n == parentDOM) return true; + return false; + } + }, { + key: "domFromPos", + value: function domFromPos(pos) { + return { + node: this.nodeDOM, + offset: pos + }; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset, bias) { + if (dom == this.nodeDOM) return this.posAtStart + Math.min(offset, this.node.text.length); + return _get(_getPrototypeOf(TextViewDesc.prototype), "localPosFromDOM", this).call(this, dom, offset, bias); + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return mutation.type != "characterData" && mutation.type != "selection"; + } + }, { + key: "slice", + value: function slice(from, to, view) { + var node = this.node.cut(from, to), + dom = document.createTextNode(node.text); + return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + _get(_getPrototypeOf(TextViewDesc.prototype), "markDirty", this).call(this, from, to); + if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY; + } + }, { + key: "domAtom", + get: function get() { + return false; + } + }, { + key: "isText", + value: function isText(text) { + return this.node.text == text; + } + }]); + return TextViewDesc; +}(NodeViewDesc); +var TrailingHackViewDesc = function (_ViewDesc5) { + _inherits(TrailingHackViewDesc, _ViewDesc5); + var _super6 = _createSuper(TrailingHackViewDesc); + function TrailingHackViewDesc() { + _classCallCheck(this, TrailingHackViewDesc); + return _super6.apply(this, arguments); + } + _createClass(TrailingHackViewDesc, [{ + key: "parseRule", + value: function parseRule() { + return { + ignore: true + }; + } + }, { + key: "matchesHack", + value: function matchesHack(nodeName) { + return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName; + } + }, { + key: "domAtom", + get: function get() { + return true; + } + }, { + key: "ignoreForCoords", + get: function get() { + return this.dom.nodeName == "IMG"; + } + }]); + return TrailingHackViewDesc; +}(ViewDesc); +var CustomNodeViewDesc = function (_NodeViewDesc2) { + _inherits(CustomNodeViewDesc, _NodeViewDesc2); + var _super7 = _createSuper(CustomNodeViewDesc); + function CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec, view, pos) { + var _this7; + _classCallCheck(this, CustomNodeViewDesc); + _this7 = _super7.call(this, parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos); + _this7.spec = spec; + return _this7; + } + _createClass(CustomNodeViewDesc, [{ + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY) return false; + if (this.spec.update) { + var result = this.spec.update(node, outerDeco, innerDeco); + if (result) this.updateInner(node, outerDeco, innerDeco, view); + return result; + } else if (!this.contentDOM && !node.isLeaf) { + return false; + } else { + return _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "update", this).call(this, node, outerDeco, innerDeco, view); + } + } + }, { + key: "selectNode", + value: function selectNode() { + this.spec.selectNode ? this.spec.selectNode() : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "selectNode", this).call(this); + } + }, { + key: "deselectNode", + value: function deselectNode() { + this.spec.deselectNode ? this.spec.deselectNode() : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "deselectNode", this).call(this); + } + }, { + key: "setSelection", + value: function setSelection(anchor, head, root, force) { + this.spec.setSelection ? this.spec.setSelection(anchor, head, root) : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "setSelection", this).call(this, anchor, head, root, force); + } + }, { + key: "destroy", + value: function destroy() { + if (this.spec.destroy) this.spec.destroy(); + _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "destroy", this).call(this); + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + return this.spec.stopEvent ? this.spec.stopEvent(event) : false; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "ignoreMutation", this).call(this, mutation); + } + }]); + return CustomNodeViewDesc; +}(NodeViewDesc); +function renderDescs(parentDOM, descs, view) { + var dom = parentDOM.firstChild, + written = false; + for (var i = 0; i < descs.length; i++) { + var desc = descs[i], + childDOM = desc.dom; + if (childDOM.parentNode == parentDOM) { + while (childDOM != dom) { + dom = rm(dom); + written = true; + } + dom = dom.nextSibling; + } else { + written = true; + parentDOM.insertBefore(childDOM, dom); + } + if (desc instanceof MarkViewDesc) { + var pos = dom ? dom.previousSibling : parentDOM.lastChild; + renderDescs(desc.contentDOM, desc.children, view); + dom = pos ? pos.nextSibling : parentDOM.firstChild; + } + } + while (dom) { + dom = rm(dom); + written = true; + } + if (written && view.trackWrites == parentDOM) view.trackWrites = null; +} +var OuterDecoLevel = function OuterDecoLevel(nodeName) { + if (nodeName) this.nodeName = nodeName; +}; +OuterDecoLevel.prototype = Object.create(null); +var noDeco = [new OuterDecoLevel()]; +function computeOuterDeco(outerDeco, node, needsWrap) { + if (outerDeco.length == 0) return noDeco; + var top = needsWrap ? noDeco[0] : new OuterDecoLevel(), + result = [top]; + for (var i = 0; i < outerDeco.length; i++) { + var attrs = outerDeco[i].type.attrs; + if (!attrs) continue; + if (attrs.nodeName) result.push(top = new OuterDecoLevel(attrs.nodeName)); + for (var name in attrs) { + var val = attrs[name]; + if (val == null) continue; + if (needsWrap && result.length == 1) result.push(top = new OuterDecoLevel(node.isInline ? "span" : "div")); + if (name == "class") top["class"] = (top["class"] ? top["class"] + " " : "") + val;else if (name == "style") top.style = (top.style ? top.style + ";" : "") + val;else if (name != "nodeName") top[name] = val; + } + } + return result; +} +function patchOuterDeco(outerDOM, nodeDOM, prevComputed, curComputed) { + if (prevComputed == noDeco && curComputed == noDeco) return nodeDOM; + var curDOM = nodeDOM; + for (var i = 0; i < curComputed.length; i++) { + var deco = curComputed[i], + prev = prevComputed[i]; + if (i) { + var parent = void 0; + if (prev && prev.nodeName == deco.nodeName && curDOM != outerDOM && (parent = curDOM.parentNode) && parent.nodeName.toLowerCase() == deco.nodeName) { + curDOM = parent; + } else { + parent = document.createElement(deco.nodeName); + parent.pmIsDeco = true; + parent.appendChild(curDOM); + prev = noDeco[0]; + curDOM = parent; + } + } + patchAttributes(curDOM, prev || noDeco[0], deco); + } + return curDOM; +} +function patchAttributes(dom, prev, cur) { + for (var name in prev) if (name != "class" && name != "style" && name != "nodeName" && !(name in cur)) dom.removeAttribute(name); + for (var _name in cur) if (_name != "class" && _name != "style" && _name != "nodeName" && cur[_name] != prev[_name]) dom.setAttribute(_name, cur[_name]); + if (prev["class"] != cur["class"]) { + var prevList = prev["class"] ? prev["class"].split(" ").filter(Boolean) : []; + var curList = cur["class"] ? cur["class"].split(" ").filter(Boolean) : []; + for (var i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) dom.classList.remove(prevList[i]); + for (var _i = 0; _i < curList.length; _i++) if (prevList.indexOf(curList[_i]) == -1) dom.classList.add(curList[_i]); + if (dom.classList.length == 0) dom.removeAttribute("class"); + } + if (prev.style != cur.style) { + if (prev.style) { + var prop = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, + m; + while (m = prop.exec(prev.style)) dom.style.removeProperty(m[1]); + } + if (cur.style) dom.style.cssText += cur.style; + } +} +function applyOuterDeco(dom, deco, node) { + return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1)); +} +function sameOuterDeco(a, b) { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!a[i].type.eq(b[i].type)) return false; + return true; +} +function rm(dom) { + var next = dom.nextSibling; + dom.parentNode.removeChild(dom); + return next; +} +var ViewTreeUpdater = function () { + function ViewTreeUpdater(top, lock, view) { + _classCallCheck(this, ViewTreeUpdater); + this.lock = lock; + this.view = view; + this.index = 0; + this.stack = []; + this.changed = false; + this.top = top; + this.preMatch = preMatch(top.node.content, top); + } + _createClass(ViewTreeUpdater, [{ + key: "destroyBetween", + value: function destroyBetween(start, end) { + if (start == end) return; + for (var i = start; i < end; i++) this.top.children[i].destroy(); + this.top.children.splice(start, end - start); + this.changed = true; + } + }, { + key: "destroyRest", + value: function destroyRest() { + this.destroyBetween(this.index, this.top.children.length); + } + }, { + key: "syncToMarks", + value: function syncToMarks(marks, inline, view) { + var keep = 0, + depth = this.stack.length >> 1; + var maxKeep = Math.min(depth, marks.length); + while (keep < maxKeep && (keep == depth - 1 ? this.top : this.stack[keep + 1 << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) keep++; + while (keep < depth) { + this.destroyRest(); + this.top.dirty = NOT_DIRTY; + this.index = this.stack.pop(); + this.top = this.stack.pop(); + depth--; + } + while (depth < marks.length) { + this.stack.push(this.top, this.index + 1); + var found = -1; + for (var i = this.index; i < Math.min(this.index + 3, this.top.children.length); i++) { + var next = this.top.children[i]; + if (next.matchesMark(marks[depth]) && !this.isLocked(next.dom)) { + found = i; + break; + } + } + if (found > -1) { + if (found > this.index) { + this.changed = true; + this.destroyBetween(this.index, found); + } + this.top = this.top.children[this.index]; + } else { + var markDesc = MarkViewDesc.create(this.top, marks[depth], inline, view); + this.top.children.splice(this.index, 0, markDesc); + this.top = markDesc; + this.changed = true; + } + this.index = 0; + depth++; + } + } + }, { + key: "findNodeMatch", + value: function findNodeMatch(node, outerDeco, innerDeco, index) { + var found = -1, + targetDesc; + if (index >= this.preMatch.index && (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top && targetDesc.matchesNode(node, outerDeco, innerDeco)) { + found = this.top.children.indexOf(targetDesc, this.index); + } else { + for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) { + var child = this.top.children[i]; + if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) { + found = i; + break; + } + } + } + if (found < 0) return false; + this.destroyBetween(this.index, found); + this.index++; + return true; + } + }, { + key: "updateNodeAt", + value: function updateNodeAt(node, outerDeco, innerDeco, index, view) { + var child = this.top.children[index]; + if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY; + if (!child.update(node, outerDeco, innerDeco, view)) return false; + this.destroyBetween(this.index, index); + this.index++; + return true; + } + }, { + key: "findIndexWithChild", + value: function findIndexWithChild(domNode) { + for (;;) { + var parent = domNode.parentNode; + if (!parent) return -1; + if (parent == this.top.contentDOM) { + var desc = domNode.pmViewDesc; + if (desc) for (var i = this.index; i < this.top.children.length; i++) { + if (this.top.children[i] == desc) return i; + } + return -1; + } + domNode = parent; + } + } + }, { + key: "updateNextNode", + value: function updateNextNode(node, outerDeco, innerDeco, view, index, pos) { + for (var i = this.index; i < this.top.children.length; i++) { + var next = this.top.children[i]; + if (next instanceof NodeViewDesc) { + var _preMatch = this.preMatch.matched.get(next); + if (_preMatch != null && _preMatch != index) return false; + var nextDOM = next.dom, + updated = void 0; + var locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && next.dirty != NODE_DIRTY && sameOuterDeco(outerDeco, next.outerDeco)); + if (!locked && next.update(node, outerDeco, innerDeco, view)) { + this.destroyBetween(this.index, i); + if (next.dom != nextDOM) this.changed = true; + this.index++; + return true; + } else if (!locked && (updated = this.recreateWrapper(next, node, outerDeco, innerDeco, view, pos))) { + this.destroyBetween(this.index, i); + this.top.children[this.index] = updated; + if (updated.contentDOM) { + updated.dirty = CONTENT_DIRTY; + updated.updateChildren(view, pos + 1); + updated.dirty = NOT_DIRTY; + } + this.changed = true; + this.index++; + return true; + } + break; + } + } + return false; + } + }, { + key: "recreateWrapper", + value: function recreateWrapper(next, node, outerDeco, innerDeco, view, pos) { + if (next.dirty || node.isAtom || !next.children.length || !next.node.content.eq(node.content) || !sameOuterDeco(outerDeco, next.outerDeco) || !innerDeco.eq(next.innerDeco)) return null; + var wrapper = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); + if (wrapper.contentDOM) { + wrapper.children = next.children; + next.children = []; + var _iterator = _createForOfIteratorHelper(wrapper.children), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var ch = _step.value; + ch.parent = wrapper; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + next.destroy(); + return wrapper; + } + }, { + key: "addNode", + value: function addNode(node, outerDeco, innerDeco, view, pos) { + var desc = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); + if (desc.contentDOM) desc.updateChildren(view, pos + 1); + this.top.children.splice(this.index++, 0, desc); + this.changed = true; + } + }, { + key: "placeWidget", + value: function placeWidget(widget, view, pos) { + var next = this.index < this.top.children.length ? this.top.children[this.index] : null; + if (next && next.matchesWidget(widget) && (widget == next.widget || !next.widget.type.toDOM.parentNode)) { + this.index++; + } else { + var desc = new WidgetViewDesc(this.top, widget, view, pos); + this.top.children.splice(this.index++, 0, desc); + this.changed = true; + } + } + }, { + key: "addTextblockHacks", + value: function addTextblockHacks() { + var lastChild = this.top.children[this.index - 1], + parent = this.top; + while (lastChild instanceof MarkViewDesc) { + parent = lastChild; + lastChild = parent.children[parent.children.length - 1]; + } + if (!lastChild || !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(lastChild.node.text)) { + if ((safari || chrome) && lastChild && lastChild.dom.contentEditable == "false") this.addHackNode("IMG", parent); + this.addHackNode("BR", this.top); + } + } + }, { + key: "addHackNode", + value: function addHackNode(nodeName, parent) { + if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) { + this.index++; + } else { + var dom = document.createElement(nodeName); + if (nodeName == "IMG") { + dom.className = "ProseMirror-separator"; + dom.alt = ""; + } + if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak"; + var hack = new TrailingHackViewDesc(this.top, [], dom, null); + if (parent != this.top) parent.children.push(hack);else parent.children.splice(this.index++, 0, hack); + this.changed = true; + } + } + }, { + key: "isLocked", + value: function isLocked(node) { + return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode)); + } + }]); + return ViewTreeUpdater; +}(); +function preMatch(frag, parentDesc) { + var curDesc = parentDesc, + descI = curDesc.children.length; + var fI = frag.childCount, + matched = new Map(), + matches = []; + outer: while (fI > 0) { + var desc = void 0; + for (;;) { + if (descI) { + var next = curDesc.children[descI - 1]; + if (next instanceof MarkViewDesc) { + curDesc = next; + descI = next.children.length; + } else { + desc = next; + descI--; + break; + } + } else if (curDesc == parentDesc) { + break outer; + } else { + descI = curDesc.parent.children.indexOf(curDesc); + curDesc = curDesc.parent; + } + } + var node = desc.node; + if (!node) continue; + if (node != frag.child(fI - 1)) break; + --fI; + matched.set(desc, fI); + matches.push(desc); + } + return { + index: fI, + matched: matched, + matches: matches.reverse() + }; +} +function compareSide(a, b) { + return a.type.side - b.type.side; +} +function iterDeco(parent, deco, onWidget, onNode) { + var locals = deco.locals(parent), + offset = 0; + if (locals.length == 0) { + for (var i = 0; i < parent.childCount; i++) { + var child = parent.child(i); + onNode(child, locals, deco.forChild(offset, child), i); + offset += child.nodeSize; + } + return; + } + var decoIndex = 0, + active = [], + restNode = null; + for (var parentIndex = 0;;) { + var widget = void 0, + widgets = void 0; + while (decoIndex < locals.length && locals[decoIndex].to == offset) { + var next = locals[decoIndex++]; + if (next.widget) { + if (!widget) widget = next;else (widgets || (widgets = [widget])).push(next); + } + } + if (widget) { + if (widgets) { + widgets.sort(compareSide); + for (var _i2 = 0; _i2 < widgets.length; _i2++) onWidget(widgets[_i2], parentIndex, !!restNode); + } else { + onWidget(widget, parentIndex, !!restNode); + } + } + var _child = void 0, + index = void 0; + if (restNode) { + index = -1; + _child = restNode; + restNode = null; + } else if (parentIndex < parent.childCount) { + index = parentIndex; + _child = parent.child(parentIndex++); + } else { + break; + } + for (var _i3 = 0; _i3 < active.length; _i3++) if (active[_i3].to <= offset) active.splice(_i3--, 1); + while (decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset) active.push(locals[decoIndex++]); + var end = offset + _child.nodeSize; + if (_child.isText) { + var cutAt = end; + if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from; + for (var _i4 = 0; _i4 < active.length; _i4++) if (active[_i4].to < cutAt) cutAt = active[_i4].to; + if (cutAt < end) { + restNode = _child.cut(cutAt - offset); + _child = _child.cut(0, cutAt - offset); + end = cutAt; + index = -1; + } + } else { + while (decoIndex < locals.length && locals[decoIndex].to < end) decoIndex++; + } + var outerDeco = _child.isInline && !_child.isLeaf ? active.filter(function (d) { + return !d.inline; + }) : active.slice(); + onNode(_child, outerDeco, deco.forChild(offset, _child), index); + offset = end; + } +} +function iosHacks(dom) { + if (dom.nodeName == "UL" || dom.nodeName == "OL") { + var oldCSS = dom.style.cssText; + dom.style.cssText = oldCSS + "; list-style: square !important"; + window.getComputedStyle(dom).listStyle; + dom.style.cssText = oldCSS; + } +} +function findTextInFragment(frag, text, from, to) { + for (var i = 0, pos = 0; i < frag.childCount && pos <= to;) { + var child = frag.child(i++), + childStart = pos; + pos += child.nodeSize; + if (!child.isText) continue; + var str = child.text; + while (i < frag.childCount) { + var next = frag.child(i++); + pos += next.nodeSize; + if (!next.isText) break; + str += next.text; + } + if (pos >= from) { + if (pos >= to && str.slice(to - text.length - childStart, to - childStart) == text) return to - text.length; + var found = childStart < to ? str.lastIndexOf(text, to - childStart - 1) : -1; + if (found >= 0 && found + text.length + childStart >= from) return childStart + found; + if (from == to && str.length >= to + text.length - childStart && str.slice(to - childStart, to - childStart + text.length) == text) return to; + } + } + return -1; +} +function replaceNodes(nodes, from, to, view, replacement) { + var result = []; + for (var i = 0, off = 0; i < nodes.length; i++) { + var child = nodes[i], + start = off, + end = off += child.size; + if (start >= to || end <= from) { + result.push(child); + } else { + if (start < from) result.push(child.slice(0, from - start, view)); + if (replacement) { + result.push(replacement); + replacement = undefined; + } + if (end > to) result.push(child.slice(to - start, child.size, view)); + } + } + return result; +} +function selectionFromDOM(view) { + var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var domSel = view.domSelectionRange(), + doc = view.state.doc; + if (!domSel.focusNode) return null; + var nearestDesc = view.docView.nearestDesc(domSel.focusNode), + inWidget = nearestDesc && nearestDesc.size == 0; + var head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1); + if (head < 0) return null; + var $head = doc.resolve(head), + anchor, + selection; + if (selectionCollapsed(domSel)) { + anchor = head; + while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent; + var nearestDescNode = nearestDesc.node; + if (nearestDesc && nearestDescNode.isAtom && prosemirrorState.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) { + var pos = nearestDesc.posBefore; + selection = new prosemirrorState.NodeSelection(head == pos ? $head : doc.resolve(pos)); + } + } else { + if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) { + var min = head, + max = head; + for (var i = 0; i < domSel.rangeCount; i++) { + var range = domSel.getRangeAt(i); + min = Math.min(min, view.docView.posFromDOM(range.startContainer, range.startOffset, 1)); + max = Math.max(max, view.docView.posFromDOM(range.endContainer, range.endOffset, -1)); + } + if (min < 0) return null; + var _ref3 = max == view.state.selection.anchor ? [max, min] : [min, max]; + var _ref4 = _slicedToArray(_ref3, 2); + anchor = _ref4[0]; + head = _ref4[1]; + $head = doc.resolve(head); + } else { + anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1); + } + if (anchor < 0) return null; + } + var $anchor = doc.resolve(anchor); + if (!selection) { + var bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1; + selection = selectionBetween(view, $anchor, $head, bias); + } + return selection; +} +function editorOwnsSelection(view) { + return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom); +} +function selectionToDOM(view) { + var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var sel = view.state.selection; + syncNodeSelection(view, sel); + if (!editorOwnsSelection(view)) return; + if (!force && view.input.mouseDown && view.input.mouseDown.allowDefault && chrome) { + var domSel = view.domSelectionRange(), + curSel = view.domObserver.currentSelection; + if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset)) { + view.input.mouseDown.delayedSelectionSync = true; + view.domObserver.setCurSelection(); + return; + } + } + view.domObserver.disconnectSelection(); + if (view.cursorWrapper) { + selectCursorWrapper(view); + } else { + var anchor = sel.anchor, + head = sel.head, + resetEditableFrom, + resetEditableTo; + if (brokenSelectBetweenUneditable && !(sel instanceof prosemirrorState.TextSelection)) { + if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from); + if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to); + } + view.docView.setSelection(anchor, head, view.root, force); + if (brokenSelectBetweenUneditable) { + if (resetEditableFrom) resetEditable(resetEditableFrom); + if (resetEditableTo) resetEditable(resetEditableTo); + } + if (sel.visible) { + view.dom.classList.remove("ProseMirror-hideselection"); + } else { + view.dom.classList.add("ProseMirror-hideselection"); + if ("onselectionchange" in document) removeClassOnSelectionChange(view); + } + } + view.domObserver.setCurSelection(); + view.domObserver.connectSelection(); +} +var brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63; +function temporarilyEditableNear(view, pos) { + var _view$docView$domFrom3 = view.docView.domFromPos(pos, 0), + node = _view$docView$domFrom3.node, + offset = _view$docView$domFrom3.offset; + var after = offset < node.childNodes.length ? node.childNodes[offset] : null; + var before = offset ? node.childNodes[offset - 1] : null; + if (safari && after && after.contentEditable == "false") return setEditable(after); + if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) { + if (after) return setEditable(after);else if (before) return setEditable(before); + } +} +function setEditable(element) { + element.contentEditable = "true"; + if (safari && element.draggable) { + element.draggable = false; + element.wasDraggable = true; + } + return element; +} +function resetEditable(element) { + element.contentEditable = "false"; + if (element.wasDraggable) { + element.draggable = true; + element.wasDraggable = null; + } +} +function removeClassOnSelectionChange(view) { + var doc = view.dom.ownerDocument; + doc.removeEventListener("selectionchange", view.input.hideSelectionGuard); + var domSel = view.domSelectionRange(); + var node = domSel.anchorNode, + offset = domSel.anchorOffset; + doc.addEventListener("selectionchange", view.input.hideSelectionGuard = function () { + if (domSel.anchorNode != node || domSel.anchorOffset != offset) { + doc.removeEventListener("selectionchange", view.input.hideSelectionGuard); + setTimeout(function () { + if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection"); + }, 20); + } + }); +} +function selectCursorWrapper(view) { + var domSel = view.domSelection(), + range = document.createRange(); + if (!domSel) return; + var node = view.cursorWrapper.dom, + img = node.nodeName == "IMG"; + if (img) range.setStart(node.parentNode, domIndex(node) + 1);else range.setStart(node, 0); + range.collapse(true); + domSel.removeAllRanges(); + domSel.addRange(range); + if (!img && !view.state.selection.visible && ie && ie_version <= 11) { + node.disabled = true; + node.disabled = false; + } +} +function syncNodeSelection(view, sel) { + if (sel instanceof prosemirrorState.NodeSelection) { + var desc = view.docView.descAt(sel.from); + if (desc != view.lastSelectedViewDesc) { + clearNodeSelection(view); + if (desc) desc.selectNode(); + view.lastSelectedViewDesc = desc; + } + } else { + clearNodeSelection(view); + } +} +function clearNodeSelection(view) { + if (view.lastSelectedViewDesc) { + if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode(); + view.lastSelectedViewDesc = undefined; + } +} +function selectionBetween(view, $anchor, $head, bias) { + return view.someProp("createSelectionBetween", function (f) { + return f(view, $anchor, $head); + }) || prosemirrorState.TextSelection.between($anchor, $head, bias); +} +function hasFocusAndSelection(view) { + if (view.editable && !view.hasFocus()) return false; + return hasSelection(view); +} +function hasSelection(view) { + var sel = view.domSelectionRange(); + if (!sel.anchorNode) return false; + try { + return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode)); + } catch (_) { + return false; + } +} +function anchorInRightPlace(view) { + var anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0); + var domSel = view.domSelectionRange(); + return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset); +} +function moveSelectionBlock(state, dir) { + var _state$selection = state.selection, + $anchor = _state$selection.$anchor, + $head = _state$selection.$head; + var $side = dir > 0 ? $anchor.max($head) : $anchor.min($head); + var $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null; + return $start && prosemirrorState.Selection.findFrom($start, dir); +} +function apply(view, sel) { + view.dispatch(view.state.tr.setSelection(sel).scrollIntoView()); + return true; +} +function selectHorizontally(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirrorState.TextSelection) { + if (mods.indexOf("s") > -1) { + var $head = sel.$head, + node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter; + if (!node || node.isText || !node.isLeaf) return false; + var $newHead = view.state.doc.resolve($head.pos + node.nodeSize * (dir < 0 ? -1 : 1)); + return apply(view, new prosemirrorState.TextSelection(sel.$anchor, $newHead)); + } else if (!sel.empty) { + return false; + } else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) { + var next = moveSelectionBlock(view.state, dir); + if (next && next instanceof prosemirrorState.NodeSelection) return apply(view, next); + return false; + } else if (!(mac && mods.indexOf("m") > -1)) { + var _$head = sel.$head, + _node = _$head.textOffset ? null : dir < 0 ? _$head.nodeBefore : _$head.nodeAfter, + desc; + if (!_node || _node.isText) return false; + var nodePos = dir < 0 ? _$head.pos - _node.nodeSize : _$head.pos; + if (!(_node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false; + if (prosemirrorState.NodeSelection.isSelectable(_node)) { + return apply(view, new prosemirrorState.NodeSelection(dir < 0 ? view.state.doc.resolve(_$head.pos - _node.nodeSize) : _$head)); + } else if (webkit) { + return apply(view, new prosemirrorState.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + _node.nodeSize))); + } else { + return false; + } + } + } else if (sel instanceof prosemirrorState.NodeSelection && sel.node.isInline) { + return apply(view, new prosemirrorState.TextSelection(dir > 0 ? sel.$to : sel.$from)); + } else { + var _next = moveSelectionBlock(view.state, dir); + if (_next) return apply(view, _next); + return false; + } +} +function nodeLen(node) { + return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; +} +function isIgnorable(dom, dir) { + var desc = dom.pmViewDesc; + return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR"); +} +function skipIgnoredNodes(view, dir) { + return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view); +} +function skipIgnoredNodesBefore(view) { + var sel = view.domSelectionRange(); + var node = sel.focusNode, + offset = sel.focusOffset; + if (!node) return; + var moveNode, + moveOffset, + force = false; + if (gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset], -1)) force = true; + for (;;) { + if (offset > 0) { + if (node.nodeType != 1) { + break; + } else { + var before = node.childNodes[offset - 1]; + if (isIgnorable(before, -1)) { + moveNode = node; + moveOffset = --offset; + } else if (before.nodeType == 3) { + node = before; + offset = node.nodeValue.length; + } else break; + } + } else if (isBlockNode(node)) { + break; + } else { + var prev = node.previousSibling; + while (prev && isIgnorable(prev, -1)) { + moveNode = node.parentNode; + moveOffset = domIndex(prev); + prev = prev.previousSibling; + } + if (!prev) { + node = node.parentNode; + if (node == view.dom) break; + offset = 0; + } else { + node = prev; + offset = nodeLen(node); + } + } + } + if (force) setSelFocus(view, node, offset);else if (moveNode) setSelFocus(view, moveNode, moveOffset); +} +function skipIgnoredNodesAfter(view) { + var sel = view.domSelectionRange(); + var node = sel.focusNode, + offset = sel.focusOffset; + if (!node) return; + var len = nodeLen(node); + var moveNode, moveOffset; + for (;;) { + if (offset < len) { + if (node.nodeType != 1) break; + var after = node.childNodes[offset]; + if (isIgnorable(after, 1)) { + moveNode = node; + moveOffset = ++offset; + } else break; + } else if (isBlockNode(node)) { + break; + } else { + var next = node.nextSibling; + while (next && isIgnorable(next, 1)) { + moveNode = next.parentNode; + moveOffset = domIndex(next) + 1; + next = next.nextSibling; + } + if (!next) { + node = node.parentNode; + if (node == view.dom) break; + offset = len = 0; + } else { + node = next; + offset = 0; + len = nodeLen(node); + } + } + } + if (moveNode) setSelFocus(view, moveNode, moveOffset); +} +function isBlockNode(dom) { + var desc = dom.pmViewDesc; + return desc && desc.node && desc.node.isBlock; +} +function textNodeAfter(node, offset) { + while (node && offset == node.childNodes.length && !hasBlockDesc(node)) { + offset = domIndex(node) + 1; + node = node.parentNode; + } + while (node && offset < node.childNodes.length) { + var next = node.childNodes[offset]; + if (next.nodeType == 3) return next; + if (next.nodeType == 1 && next.contentEditable == "false") break; + node = next; + offset = 0; + } +} +function textNodeBefore(node, offset) { + while (node && !offset && !hasBlockDesc(node)) { + offset = domIndex(node); + node = node.parentNode; + } + while (node && offset) { + var next = node.childNodes[offset - 1]; + if (next.nodeType == 3) return next; + if (next.nodeType == 1 && next.contentEditable == "false") break; + node = next; + offset = node.childNodes.length; + } +} +function setSelFocus(view, node, offset) { + if (node.nodeType != 3) { + var before, after; + if (after = textNodeAfter(node, offset)) { + node = after; + offset = 0; + } else if (before = textNodeBefore(node, offset)) { + node = before; + offset = before.nodeValue.length; + } + } + var sel = view.domSelection(); + if (!sel) return; + if (selectionCollapsed(sel)) { + var range = document.createRange(); + range.setEnd(node, offset); + range.setStart(node, offset); + sel.removeAllRanges(); + sel.addRange(range); + } else if (sel.extend) { + sel.extend(node, offset); + } + view.domObserver.setCurSelection(); + var state = view.state; + setTimeout(function () { + if (view.state == state) selectionToDOM(view); + }, 50); +} +function findDirection(view, pos) { + var $pos = view.state.doc.resolve(pos); + if (!(chrome || windows) && $pos.parent.inlineContent) { + var coords = view.coordsAtPos(pos); + if (pos > $pos.start()) { + var before = view.coordsAtPos(pos - 1); + var mid = (before.top + before.bottom) / 2; + if (mid > coords.top && mid < coords.bottom && Math.abs(before.left - coords.left) > 1) return before.left < coords.left ? "ltr" : "rtl"; + } + if (pos < $pos.end()) { + var after = view.coordsAtPos(pos + 1); + var _mid = (after.top + after.bottom) / 2; + if (_mid > coords.top && _mid < coords.bottom && Math.abs(after.left - coords.left) > 1) return after.left > coords.left ? "ltr" : "rtl"; + } + } + var computed = getComputedStyle(view.dom).direction; + return computed == "rtl" ? "rtl" : "ltr"; +} +function selectVertically(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirrorState.TextSelection && !sel.empty || mods.indexOf("s") > -1) return false; + if (mac && mods.indexOf("m") > -1) return false; + var $from = sel.$from, + $to = sel.$to; + if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) { + var next = moveSelectionBlock(view.state, dir); + if (next && next instanceof prosemirrorState.NodeSelection) return apply(view, next); + } + if (!$from.parent.inlineContent) { + var side = dir < 0 ? $from : $to; + var beyond = sel instanceof prosemirrorState.AllSelection ? prosemirrorState.Selection.near(side, dir) : prosemirrorState.Selection.findFrom(side, dir); + return beyond ? apply(view, beyond) : false; + } + return false; +} +function stopNativeHorizontalDelete(view, dir) { + if (!(view.state.selection instanceof prosemirrorState.TextSelection)) return true; + var _view$state$selection2 = view.state.selection, + $head = _view$state$selection2.$head, + $anchor = _view$state$selection2.$anchor, + empty = _view$state$selection2.empty; + if (!$head.sameParent($anchor)) return true; + if (!empty) return false; + if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) return true; + var nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter); + if (nextNode && !nextNode.isText) { + var tr = view.state.tr; + if (dir < 0) tr["delete"]($head.pos - nextNode.nodeSize, $head.pos);else tr["delete"]($head.pos, $head.pos + nextNode.nodeSize); + view.dispatch(tr); + return true; + } + return false; +} +function switchEditable(view, node, state) { + view.domObserver.stop(); + node.contentEditable = state; + view.domObserver.start(); +} +function safariDownArrowBug(view) { + if (!safari || view.state.selection.$head.parentOffset > 0) return false; + var _view$domSelectionRan3 = view.domSelectionRange(), + focusNode = _view$domSelectionRan3.focusNode, + focusOffset = _view$domSelectionRan3.focusOffset; + if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") { + var child = focusNode.firstChild; + switchEditable(view, child, "true"); + setTimeout(function () { + return switchEditable(view, child, "false"); + }, 20); + } + return false; +} +function getMods(event) { + var result = ""; + if (event.ctrlKey) result += "c"; + if (event.metaKey) result += "m"; + if (event.altKey) result += "a"; + if (event.shiftKey) result += "s"; + return result; +} +function captureKeyDown(view, event) { + var code = event.keyCode, + mods = getMods(event); + if (code == 8 || mac && code == 72 && mods == "c") { + return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodes(view, -1); + } else if (code == 46 && !event.shiftKey || mac && code == 68 && mods == "c") { + return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodes(view, 1); + } else if (code == 13 || code == 27) { + return true; + } else if (code == 37 || mac && code == 66 && mods == "c") { + var dir = code == 37 ? findDirection(view, view.state.selection.from) == "ltr" ? -1 : 1 : -1; + return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir); + } else if (code == 39 || mac && code == 70 && mods == "c") { + var _dir = code == 39 ? findDirection(view, view.state.selection.from) == "ltr" ? 1 : -1 : 1; + return selectHorizontally(view, _dir, mods) || skipIgnoredNodes(view, _dir); + } else if (code == 38 || mac && code == 80 && mods == "c") { + return selectVertically(view, -1, mods) || skipIgnoredNodes(view, -1); + } else if (code == 40 || mac && code == 78 && mods == "c") { + return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodes(view, 1); + } else if (mods == (mac ? "m" : "c") && (code == 66 || code == 73 || code == 89 || code == 90)) { + return true; + } + return false; +} +function serializeForClipboard(view, slice) { + view.someProp("transformCopied", function (f) { + slice = f(slice, view); + }); + var context = [], + _slice = slice, + content = _slice.content, + openStart = _slice.openStart, + openEnd = _slice.openEnd; + while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) { + openStart--; + openEnd--; + var node = content.firstChild; + context.push(node.type.name, node.attrs != node.type.defaultAttrs ? node.attrs : null); + content = node.content; + } + var serializer = view.someProp("clipboardSerializer") || prosemirrorModel.DOMSerializer.fromSchema(view.state.schema); + var doc = detachedDoc(), + wrap = doc.createElement("div"); + wrap.appendChild(serializer.serializeFragment(content, { + document: doc + })); + var firstChild = wrap.firstChild, + needsWrap, + wrappers = 0; + while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) { + for (var i = needsWrap.length - 1; i >= 0; i--) { + var wrapper = doc.createElement(needsWrap[i]); + while (wrap.firstChild) wrapper.appendChild(wrap.firstChild); + wrap.appendChild(wrapper); + wrappers++; + } + firstChild = wrap.firstChild; + } + if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", "".concat(openStart, " ").concat(openEnd).concat(wrappers ? " -".concat(wrappers) : "", " ").concat(JSON.stringify(context))); + var text = view.someProp("clipboardTextSerializer", function (f) { + return f(slice, view); + }) || slice.content.textBetween(0, slice.content.size, "\n\n"); + return { + dom: wrap, + text: text, + slice: slice + }; +} +function parseFromClipboard(view, text, html, plainText, $context) { + var inCode = $context.parent.type.spec.code; + var dom, slice; + if (!html && !text) return null; + var asText = text && (plainText || inCode || !html); + if (asText) { + view.someProp("transformPastedText", function (f) { + text = f(text, inCode || plainText, view); + }); + if (inCode) return text ? new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : prosemirrorModel.Slice.empty; + var parsed = view.someProp("clipboardTextParser", function (f) { + return f(text, $context, plainText, view); + }); + if (parsed) { + slice = parsed; + } else { + var marks = $context.marks(); + var schema = view.state.schema, + serializer = prosemirrorModel.DOMSerializer.fromSchema(schema); + dom = document.createElement("div"); + text.split(/(?:\r\n?|\n)+/).forEach(function (block) { + var p = dom.appendChild(document.createElement("p")); + if (block) p.appendChild(serializer.serializeNode(schema.text(block, marks))); + }); + } + } else { + view.someProp("transformPastedHTML", function (f) { + html = f(html, view); + }); + dom = readHTML(html); + if (webkit) restoreReplacedSpaces(dom); + } + var contextNode = dom && dom.querySelector("[data-pm-slice]"); + var sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || ""); + if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0; i--) { + var child = dom.firstChild; + while (child && child.nodeType != 1) child = child.nextSibling; + if (!child) break; + dom = child; + } + if (!slice) { + var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema); + slice = parser.parseSlice(dom, { + preserveWhitespace: !!(asText || sliceData), + context: $context, + ruleFromNode: function ruleFromNode(dom) { + if (dom.nodeName == "BR" && !dom.nextSibling && dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) return { + ignore: true + }; + return null; + } + }); + } + if (sliceData) { + slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[4]); + } else { + slice = prosemirrorModel.Slice.maxOpen(normalizeSiblings(slice.content, $context), true); + if (slice.openStart || slice.openEnd) { + var openStart = 0, + openEnd = 0; + for (var node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating; openStart++, node = node.firstChild) {} + for (var _node2 = slice.content.lastChild; openEnd < slice.openEnd && !_node2.type.spec.isolating; openEnd++, _node2 = _node2.lastChild) {} + slice = closeSlice(slice, openStart, openEnd); + } + } + view.someProp("transformPasted", function (f) { + slice = f(slice, view); + }); + return slice; +} +var inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i; +function normalizeSiblings(fragment, $context) { + if (fragment.childCount < 2) return fragment; + var _loop = function _loop() { + var parent = $context.node(d); + var match = parent.contentMatchAt($context.index(d)); + var lastWrap, + result = []; + fragment.forEach(function (node) { + if (!result) return; + var wrap = match.findWrapping(node.type), + inLast; + if (!wrap) return result = null; + if (inLast = result.length && lastWrap.length && addToSibling(wrap, lastWrap, node, result[result.length - 1], 0)) { + result[result.length - 1] = inLast; + } else { + if (result.length) result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length); + var wrapped = withWrappers(node, wrap); + result.push(wrapped); + match = match.matchType(wrapped.type); + lastWrap = wrap; + } + }); + if (result) return { + v: prosemirrorModel.Fragment.from(result) + }; + }, + _ret; + for (var d = $context.depth; d >= 0; d--) { + _ret = _loop(); + if (_ret) return _ret.v; + } + return fragment; +} +function withWrappers(node, wrap) { + var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + for (var i = wrap.length - 1; i >= from; i--) node = wrap[i].create(null, prosemirrorModel.Fragment.from(node)); + return node; +} +function addToSibling(wrap, lastWrap, node, sibling, depth) { + if (depth < wrap.length && depth < lastWrap.length && wrap[depth] == lastWrap[depth]) { + var inner = addToSibling(wrap, lastWrap, node, sibling.lastChild, depth + 1); + if (inner) return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner)); + var match = sibling.contentMatchAt(sibling.childCount); + if (match.matchType(depth == wrap.length - 1 ? node.type : wrap[depth + 1])) return sibling.copy(sibling.content.append(prosemirrorModel.Fragment.from(withWrappers(node, wrap, depth + 1)))); + } +} +function closeRight(node, depth) { + if (depth == 0) return node; + var fragment = node.content.replaceChild(node.childCount - 1, closeRight(node.lastChild, depth - 1)); + var fill = node.contentMatchAt(node.childCount).fillBefore(prosemirrorModel.Fragment.empty, true); + return node.copy(fragment.append(fill)); +} +function closeRange(fragment, side, from, to, depth, openEnd) { + var node = side < 0 ? fragment.firstChild : fragment.lastChild, + inner = node.content; + if (fragment.childCount > 1) openEnd = 0; + if (depth < to - 1) inner = closeRange(inner, side, from, to, depth + 1, openEnd); + if (depth >= from) inner = side < 0 ? node.contentMatchAt(0).fillBefore(inner, openEnd <= depth).append(inner) : inner.append(node.contentMatchAt(node.childCount).fillBefore(prosemirrorModel.Fragment.empty, true)); + return fragment.replaceChild(side < 0 ? 0 : fragment.childCount - 1, node.copy(inner)); +} +function closeSlice(slice, openStart, openEnd) { + if (openStart < slice.openStart) slice = new prosemirrorModel.Slice(closeRange(slice.content, -1, openStart, slice.openStart, 0, slice.openEnd), openStart, slice.openEnd); + if (openEnd < slice.openEnd) slice = new prosemirrorModel.Slice(closeRange(slice.content, 1, openEnd, slice.openEnd, 0, 0), slice.openStart, openEnd); + return slice; +} +var wrapMap = { + thead: ["table"], + tbody: ["table"], + tfoot: ["table"], + caption: ["table"], + colgroup: ["table"], + col: ["table", "colgroup"], + tr: ["table", "tbody"], + td: ["table", "tbody", "tr"], + th: ["table", "tbody", "tr"] +}; +var _detachedDoc = null; +function detachedDoc() { + return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title")); +} +function maybeWrapTrusted(html) { + var trustedTypes = window.trustedTypes; + if (!trustedTypes) return html; + return trustedTypes.createPolicy("detachedDocument", { + createHTML: function createHTML(s) { + return s; + } + }).createHTML(html); +} +function readHTML(html) { + var metas = /^(\s*]*>)*/.exec(html); + if (metas) html = html.slice(metas[0].length); + var elt = detachedDoc().createElement("div"); + var firstTag = /<([a-z][^>\s]+)/i.exec(html), + wrap; + if (wrap = firstTag && wrapMap[firstTag[1].toLowerCase()]) html = wrap.map(function (n) { + return "<" + n + ">"; + }).join("") + html + wrap.map(function (n) { + return ""; + }).reverse().join(""); + elt.innerHTML = maybeWrapTrusted(html); + if (wrap) for (var i = 0; i < wrap.length; i++) elt = elt.querySelector(wrap[i]) || elt; + return elt; +} +function restoreReplacedSpaces(dom) { + var nodes = dom.querySelectorAll(chrome ? "span:not([class]):not([style])" : "span.Apple-converted-space"); + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + if (node.childNodes.length == 1 && node.textContent == "\xA0" && node.parentNode) node.parentNode.replaceChild(dom.ownerDocument.createTextNode(" "), node); + } +} +function addContext(slice, context) { + if (!slice.size) return slice; + var schema = slice.content.firstChild.type.schema, + array; + try { + array = JSON.parse(context); + } catch (e) { + return slice; + } + var content = slice.content, + openStart = slice.openStart, + openEnd = slice.openEnd; + for (var i = array.length - 2; i >= 0; i -= 2) { + var type = schema.nodes[array[i]]; + if (!type || type.hasRequiredAttrs()) break; + content = prosemirrorModel.Fragment.from(type.create(array[i + 1], content)); + openStart++; + openEnd++; + } + return new prosemirrorModel.Slice(content, openStart, openEnd); +} +var handlers = {}; +var editHandlers = {}; +var passiveHandlers = { + touchstart: true, + touchmove: true +}; +var InputState = _createClass(function InputState() { + _classCallCheck(this, InputState); + this.shiftKey = false; + this.mouseDown = null; + this.lastKeyCode = null; + this.lastKeyCodeTime = 0; + this.lastClick = { + time: 0, + x: 0, + y: 0, + type: "" + }; + this.lastSelectionOrigin = null; + this.lastSelectionTime = 0; + this.lastIOSEnter = 0; + this.lastIOSEnterFallbackTimeout = -1; + this.lastFocus = 0; + this.lastTouch = 0; + this.lastAndroidDelete = 0; + this.composing = false; + this.compositionNode = null; + this.composingTimeout = -1; + this.compositionNodes = []; + this.compositionEndedAt = -2e8; + this.compositionID = 1; + this.compositionPendingChanges = 0; + this.domChangeCount = 0; + this.eventHandlers = Object.create(null); + this.hideSelectionGuard = null; +}); +function initInput(view) { + var _loop2 = function _loop2() { + var handler = handlers[event]; + view.dom.addEventListener(event, view.input.eventHandlers[event] = function (event) { + if (eventBelongsToView(view, event) && !runCustomHandler(view, event) && (view.editable || !(event.type in editHandlers))) handler(view, event); + }, passiveHandlers[event] ? { + passive: true + } : undefined); + }; + for (var event in handlers) { + _loop2(); + } + if (safari) view.dom.addEventListener("input", function () { + return null; + }); + ensureListeners(view); +} +function setSelectionOrigin(view, origin) { + view.input.lastSelectionOrigin = origin; + view.input.lastSelectionTime = Date.now(); +} +function destroyInput(view) { + view.domObserver.stop(); + for (var type in view.input.eventHandlers) view.dom.removeEventListener(type, view.input.eventHandlers[type]); + clearTimeout(view.input.composingTimeout); + clearTimeout(view.input.lastIOSEnterFallbackTimeout); +} +function ensureListeners(view) { + view.someProp("handleDOMEvents", function (currentHandlers) { + for (var type in currentHandlers) if (!view.input.eventHandlers[type]) view.dom.addEventListener(type, view.input.eventHandlers[type] = function (event) { + return runCustomHandler(view, event); + }); + }); +} +function runCustomHandler(view, event) { + return view.someProp("handleDOMEvents", function (handlers) { + var handler = handlers[event.type]; + return handler ? handler(view, event) || event.defaultPrevented : false; + }); +} +function eventBelongsToView(view, event) { + if (!event.bubbles) return true; + if (event.defaultPrevented) return false; + for (var node = event.target; node != view.dom; node = node.parentNode) if (!node || node.nodeType == 11 || node.pmViewDesc && node.pmViewDesc.stopEvent(event)) return false; + return true; +} +function _dispatchEvent(view, event) { + if (!runCustomHandler(view, event) && handlers[event.type] && (view.editable || !(event.type in editHandlers))) handlers[event.type](view, event); +} +editHandlers.keydown = function (view, _event) { + var event = _event; + view.input.shiftKey = event.keyCode == 16 || event.shiftKey; + if (inOrNearComposition(view, event)) return; + view.input.lastKeyCode = event.keyCode; + view.input.lastKeyCodeTime = Date.now(); + if (android && chrome && event.keyCode == 13) return; + if (view.domObserver.selectionChanged(view.domSelectionRange())) view.domObserver.flush();else if (event.keyCode != 229) view.domObserver.forceFlush(); + if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) { + var now = Date.now(); + view.input.lastIOSEnter = now; + view.input.lastIOSEnterFallbackTimeout = setTimeout(function () { + if (view.input.lastIOSEnter == now) { + view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + }); + view.input.lastIOSEnter = 0; + } + }, 200); + } else if (view.someProp("handleKeyDown", function (f) { + return f(view, event); + }) || captureKeyDown(view, event)) { + event.preventDefault(); + } else { + setSelectionOrigin(view, "key"); + } +}; +editHandlers.keyup = function (view, event) { + if (event.keyCode == 16) view.input.shiftKey = false; +}; +editHandlers.keypress = function (view, _event) { + var event = _event; + if (inOrNearComposition(view, event) || !event.charCode || event.ctrlKey && !event.altKey || mac && event.metaKey) return; + if (view.someProp("handleKeyPress", function (f) { + return f(view, event); + })) { + event.preventDefault(); + return; + } + var sel = view.state.selection; + if (!(sel instanceof prosemirrorState.TextSelection) || !sel.$from.sameParent(sel.$to)) { + var text = String.fromCharCode(event.charCode); + if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", function (f) { + return f(view, sel.$from.pos, sel.$to.pos, text); + })) view.dispatch(view.state.tr.insertText(text).scrollIntoView()); + event.preventDefault(); + } +}; +function eventCoords(event) { + return { + left: event.clientX, + top: event.clientY + }; +} +function isNear(event, click) { + var dx = click.x - event.clientX, + dy = click.y - event.clientY; + return dx * dx + dy * dy < 100; +} +function runHandlerOnContext(view, propName, pos, inside, event) { + if (inside == -1) return false; + var $pos = view.state.doc.resolve(inside); + var _loop3 = function _loop3(i) { + if (view.someProp(propName, function (f) { + return i > $pos.depth ? f(view, pos, $pos.nodeAfter, $pos.before(i), event, true) : f(view, pos, $pos.node(i), $pos.before(i), event, false); + })) return { + v: true + }; + }, + _ret2; + for (var i = $pos.depth + 1; i > 0; i--) { + _ret2 = _loop3(i); + if (_ret2) return _ret2.v; + } + return false; +} +function updateSelection(view, selection, origin) { + if (!view.focused) view.focus(); + if (view.state.selection.eq(selection)) return; + var tr = view.state.tr.setSelection(selection); + if (origin == "pointer") tr.setMeta("pointer", true); + view.dispatch(tr); +} +function selectClickedLeaf(view, inside) { + if (inside == -1) return false; + var $pos = view.state.doc.resolve(inside), + node = $pos.nodeAfter; + if (node && node.isAtom && prosemirrorState.NodeSelection.isSelectable(node)) { + updateSelection(view, new prosemirrorState.NodeSelection($pos), "pointer"); + return true; + } + return false; +} +function selectClickedNode(view, inside) { + if (inside == -1) return false; + var sel = view.state.selection, + selectedNode, + selectAt; + if (sel instanceof prosemirrorState.NodeSelection) selectedNode = sel.node; + var $pos = view.state.doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + if (prosemirrorState.NodeSelection.isSelectable(node)) { + if (selectedNode && sel.$from.depth > 0 && i >= sel.$from.depth && $pos.before(sel.$from.depth + 1) == sel.$from.pos) selectAt = $pos.before(sel.$from.depth);else selectAt = $pos.before(i); + break; + } + } + if (selectAt != null) { + updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt), "pointer"); + return true; + } else { + return false; + } +} +function handleSingleClick(view, pos, inside, event, selectNode) { + return runHandlerOnContext(view, "handleClickOn", pos, inside, event) || view.someProp("handleClick", function (f) { + return f(view, pos, event); + }) || (selectNode ? selectClickedNode(view, inside) : selectClickedLeaf(view, inside)); +} +function handleDoubleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", function (f) { + return f(view, pos, event); + }); +} +function handleTripleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", function (f) { + return f(view, pos, event); + }) || defaultTripleClick(view, inside, event); +} +function defaultTripleClick(view, inside, event) { + if (event.button != 0) return false; + var doc = view.state.doc; + if (inside == -1) { + if (doc.inlineContent) { + updateSelection(view, prosemirrorState.TextSelection.create(doc, 0, doc.content.size), "pointer"); + return true; + } + return false; + } + var $pos = doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + var nodePos = $pos.before(i); + if (node.inlineContent) updateSelection(view, prosemirrorState.TextSelection.create(doc, nodePos + 1, nodePos + 1 + node.content.size), "pointer");else if (prosemirrorState.NodeSelection.isSelectable(node)) updateSelection(view, prosemirrorState.NodeSelection.create(doc, nodePos), "pointer");else continue; + return true; + } +} +function forceDOMFlush(view) { + return endComposition(view); +} +var selectNodeModifier = mac ? "metaKey" : "ctrlKey"; +handlers.mousedown = function (view, _event) { + var event = _event; + view.input.shiftKey = event.shiftKey; + var flushed = forceDOMFlush(view); + var now = Date.now(), + type = "singleClick"; + if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier]) { + if (view.input.lastClick.type == "singleClick") type = "doubleClick";else if (view.input.lastClick.type == "doubleClick") type = "tripleClick"; + } + view.input.lastClick = { + time: now, + x: event.clientX, + y: event.clientY, + type: type + }; + var pos = view.posAtCoords(eventCoords(event)); + if (!pos) return; + if (type == "singleClick") { + if (view.input.mouseDown) view.input.mouseDown.done(); + view.input.mouseDown = new MouseDown(view, pos, event, !!flushed); + } else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) { + event.preventDefault(); + } else { + setSelectionOrigin(view, "pointer"); + } +}; +var MouseDown = function () { + function MouseDown(view, pos, event, flushed) { + var _this8 = this; + _classCallCheck(this, MouseDown); + this.view = view; + this.pos = pos; + this.event = event; + this.flushed = flushed; + this.delayedSelectionSync = false; + this.mightDrag = null; + this.startDoc = view.state.doc; + this.selectNode = !!event[selectNodeModifier]; + this.allowDefault = event.shiftKey; + var targetNode, targetPos; + if (pos.inside > -1) { + targetNode = view.state.doc.nodeAt(pos.inside); + targetPos = pos.inside; + } else { + var $pos = view.state.doc.resolve(pos.pos); + targetNode = $pos.parent; + targetPos = $pos.depth ? $pos.before() : 0; + } + var target = flushed ? null : event.target; + var targetDesc = target ? view.docView.nearestDesc(target, true) : null; + this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null; + var selection = view.state.selection; + if (event.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos) this.mightDrag = { + node: targetNode, + pos: targetPos, + addAttr: !!(this.target && !this.target.draggable), + setUneditable: !!(this.target && gecko && !this.target.hasAttribute("contentEditable")) + }; + if (this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable)) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) this.target.draggable = true; + if (this.mightDrag.setUneditable) setTimeout(function () { + if (_this8.view.input.mouseDown == _this8) _this8.target.setAttribute("contentEditable", "false"); + }, 20); + this.view.domObserver.start(); + } + view.root.addEventListener("mouseup", this.up = this.up.bind(this)); + view.root.addEventListener("mousemove", this.move = this.move.bind(this)); + setSelectionOrigin(view, "pointer"); + } + _createClass(MouseDown, [{ + key: "done", + value: function done() { + var _this9 = this; + this.view.root.removeEventListener("mouseup", this.up); + this.view.root.removeEventListener("mousemove", this.move); + if (this.mightDrag && this.target) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) this.target.removeAttribute("draggable"); + if (this.mightDrag.setUneditable) this.target.removeAttribute("contentEditable"); + this.view.domObserver.start(); + } + if (this.delayedSelectionSync) setTimeout(function () { + return selectionToDOM(_this9.view); + }); + this.view.input.mouseDown = null; + } + }, { + key: "up", + value: function up(event) { + this.done(); + if (!this.view.dom.contains(event.target)) return; + var pos = this.pos; + if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event)); + this.updateAllowDefault(event); + if (this.allowDefault || !pos) { + setSelectionOrigin(this.view, "pointer"); + } else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) { + event.preventDefault(); + } else if (event.button == 0 && (this.flushed || safari && this.mightDrag && !this.mightDrag.node.isAtom || chrome && !this.view.state.selection.visible && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) { + updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer"); + event.preventDefault(); + } else { + setSelectionOrigin(this.view, "pointer"); + } + } + }, { + key: "move", + value: function move(event) { + this.updateAllowDefault(event); + setSelectionOrigin(this.view, "pointer"); + if (event.buttons == 0) this.done(); + } + }, { + key: "updateAllowDefault", + value: function updateAllowDefault(event) { + if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true; + } + }]); + return MouseDown; +}(); +handlers.touchstart = function (view) { + view.input.lastTouch = Date.now(); + forceDOMFlush(view); + setSelectionOrigin(view, "pointer"); +}; +handlers.touchmove = function (view) { + view.input.lastTouch = Date.now(); + setSelectionOrigin(view, "pointer"); +}; +handlers.contextmenu = function (view) { + return forceDOMFlush(view); +}; +function inOrNearComposition(view, event) { + if (view.composing) return true; + if (safari && Math.abs(event.timeStamp - view.input.compositionEndedAt) < 500) { + view.input.compositionEndedAt = -2e8; + return true; + } + return false; +} +var timeoutComposition = android ? 5000 : -1; +editHandlers.compositionstart = editHandlers.compositionupdate = function (view) { + if (!view.composing) { + view.domObserver.flush(); + var state = view.state, + $pos = state.selection.$to; + if (state.selection instanceof prosemirrorState.TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(function (m) { + return m.type.spec.inclusive === false; + }))) { + view.markCursor = view.state.storedMarks || $pos.marks(); + endComposition(view, true); + view.markCursor = null; + } else { + endComposition(view, !state.selection.empty); + if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) { + var sel = view.domSelectionRange(); + for (var node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) { + var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1]; + if (!before) break; + if (before.nodeType == 3) { + var _sel = view.domSelection(); + if (_sel) _sel.collapse(before, before.nodeValue.length); + break; + } else { + node = before; + offset = -1; + } + } + } + } + view.input.composing = true; + } + scheduleComposeEnd(view, timeoutComposition); +}; +editHandlers.compositionend = function (view, event) { + if (view.composing) { + view.input.composing = false; + view.input.compositionEndedAt = event.timeStamp; + view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0; + view.input.compositionNode = null; + if (view.input.compositionPendingChanges) Promise.resolve().then(function () { + return view.domObserver.flush(); + }); + view.input.compositionID++; + scheduleComposeEnd(view, 20); + } +}; +function scheduleComposeEnd(view, delay) { + clearTimeout(view.input.composingTimeout); + if (delay > -1) view.input.composingTimeout = setTimeout(function () { + return endComposition(view); + }, delay); +} +function clearComposition(view) { + if (view.composing) { + view.input.composing = false; + view.input.compositionEndedAt = timestampFromCustomEvent(); + } + while (view.input.compositionNodes.length > 0) view.input.compositionNodes.pop().markParentsDirty(); +} +function findCompositionNode(view) { + var sel = view.domSelectionRange(); + if (!sel.focusNode) return null; + var textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset); + var textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset); + if (textBefore && textAfter && textBefore != textAfter) { + var descAfter = textAfter.pmViewDesc, + lastChanged = view.domObserver.lastChangedTextNode; + if (textBefore == lastChanged || textAfter == lastChanged) return lastChanged; + if (!descAfter || !descAfter.isText(textAfter.nodeValue)) { + return textAfter; + } else if (view.input.compositionNode == textAfter) { + var descBefore = textBefore.pmViewDesc; + if (!(!descBefore || !descBefore.isText(textBefore.nodeValue))) return textAfter; + } + } + return textBefore || textAfter; +} +function timestampFromCustomEvent() { + var event = document.createEvent("Event"); + event.initEvent("event", true, true); + return event.timeStamp; +} +function endComposition(view) { + var restarting = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + if (android && view.domObserver.flushingSoon >= 0) return; + view.domObserver.forceFlush(); + clearComposition(view); + if (restarting || view.docView && view.docView.dirty) { + var sel = selectionFromDOM(view); + if (sel && !sel.eq(view.state.selection)) view.dispatch(view.state.tr.setSelection(sel));else if ((view.markCursor || restarting) && !view.state.selection.empty) view.dispatch(view.state.tr.deleteSelection());else view.updateState(view.state); + return true; + } + return false; +} +function captureCopy(view, dom) { + if (!view.dom.parentNode) return; + var wrap = view.dom.parentNode.appendChild(document.createElement("div")); + wrap.appendChild(dom); + wrap.style.cssText = "position: fixed; left: -10000px; top: 10px"; + var sel = getSelection(), + range = document.createRange(); + range.selectNodeContents(dom); + view.dom.blur(); + sel.removeAllRanges(); + sel.addRange(range); + setTimeout(function () { + if (wrap.parentNode) wrap.parentNode.removeChild(wrap); + view.focus(); + }, 50); +} +var brokenClipboardAPI = ie && ie_version < 15 || ios && webkit_version < 604; +handlers.copy = editHandlers.cut = function (view, _event) { + var event = _event; + var sel = view.state.selection, + cut = event.type == "cut"; + if (sel.empty) return; + var data = brokenClipboardAPI ? null : event.clipboardData; + var slice = sel.content(), + _serializeForClipboar = serializeForClipboard(view, slice), + dom = _serializeForClipboar.dom, + text = _serializeForClipboar.text; + if (data) { + event.preventDefault(); + data.clearData(); + data.setData("text/html", dom.innerHTML); + data.setData("text/plain", text); + } else { + captureCopy(view, dom); + } + if (cut) view.dispatch(view.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut")); +}; +function sliceSingleNode(slice) { + return slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1 ? slice.content.firstChild : null; +} +function capturePaste(view, event) { + if (!view.dom.parentNode) return; + var plainText = view.input.shiftKey || view.state.selection.$from.parent.type.spec.code; + var target = view.dom.parentNode.appendChild(document.createElement(plainText ? "textarea" : "div")); + if (!plainText) target.contentEditable = "true"; + target.style.cssText = "position: fixed; left: -10000px; top: 10px"; + target.focus(); + var plain = view.input.shiftKey && view.input.lastKeyCode != 45; + setTimeout(function () { + view.focus(); + if (target.parentNode) target.parentNode.removeChild(target); + if (plainText) doPaste(view, target.value, null, plain, event);else doPaste(view, target.textContent, target.innerHTML, plain, event); + }, 50); +} +function doPaste(view, text, html, preferPlain, event) { + var slice = parseFromClipboard(view, text, html, preferPlain, view.state.selection.$from); + if (view.someProp("handlePaste", function (f) { + return f(view, event, slice || prosemirrorModel.Slice.empty); + })) return true; + if (!slice) return false; + var singleNode = sliceSingleNode(slice); + var tr = singleNode ? view.state.tr.replaceSelectionWith(singleNode, preferPlain) : view.state.tr.replaceSelection(slice); + view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste")); + return true; +} +function getText(clipboardData) { + var text = clipboardData.getData("text/plain") || clipboardData.getData("Text"); + if (text) return text; + var uris = clipboardData.getData("text/uri-list"); + return uris ? uris.replace(/\r?\n/g, " ") : ""; +} +editHandlers.paste = function (view, _event) { + var event = _event; + if (view.composing && !android) return; + var data = brokenClipboardAPI ? null : event.clipboardData; + var plain = view.input.shiftKey && view.input.lastKeyCode != 45; + if (data && doPaste(view, getText(data), data.getData("text/html"), plain, event)) event.preventDefault();else capturePaste(view, event); +}; +var Dragging = _createClass(function Dragging(slice, move, node) { + _classCallCheck(this, Dragging); + this.slice = slice; + this.move = move; + this.node = node; +}); +var dragCopyModifier = mac ? "altKey" : "ctrlKey"; +handlers.dragstart = function (view, _event) { + var event = _event; + var mouseDown = view.input.mouseDown; + if (mouseDown) mouseDown.done(); + if (!event.dataTransfer) return; + var sel = view.state.selection; + var pos = sel.empty ? null : view.posAtCoords(eventCoords(event)); + var node; + if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof prosemirrorState.NodeSelection ? sel.to - 1 : sel.to)) ;else if (mouseDown && mouseDown.mightDrag) { + node = prosemirrorState.NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos); + } else if (event.target && event.target.nodeType == 1) { + var desc = view.docView.nearestDesc(event.target, true); + if (desc && desc.node.type.spec.draggable && desc != view.docView) node = prosemirrorState.NodeSelection.create(view.state.doc, desc.posBefore); + } + var draggedSlice = (node || view.state.selection).content(); + var _serializeForClipboar2 = serializeForClipboard(view, draggedSlice), + dom = _serializeForClipboar2.dom, + text = _serializeForClipboar2.text, + slice = _serializeForClipboar2.slice; + if (!event.dataTransfer.files.length || !chrome || chrome_version > 120) event.dataTransfer.clearData(); + event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML); + event.dataTransfer.effectAllowed = "copyMove"; + if (!brokenClipboardAPI) event.dataTransfer.setData("text/plain", text); + view.dragging = new Dragging(slice, !event[dragCopyModifier], node); +}; +handlers.dragend = function (view) { + var dragging = view.dragging; + window.setTimeout(function () { + if (view.dragging == dragging) view.dragging = null; + }, 50); +}; +editHandlers.dragover = editHandlers.dragenter = function (_, e) { + return e.preventDefault(); +}; +editHandlers.drop = function (view, _event) { + var event = _event; + var dragging = view.dragging; + view.dragging = null; + if (!event.dataTransfer) return; + var eventPos = view.posAtCoords(eventCoords(event)); + if (!eventPos) return; + var $mouse = view.state.doc.resolve(eventPos.pos); + var slice = dragging && dragging.slice; + if (slice) { + view.someProp("transformPasted", function (f) { + slice = f(slice, view); + }); + } else { + slice = parseFromClipboard(view, getText(event.dataTransfer), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse); + } + var move = !!(dragging && !event[dragCopyModifier]); + if (view.someProp("handleDrop", function (f) { + return f(view, event, slice || prosemirrorModel.Slice.empty, move); + })) { + event.preventDefault(); + return; + } + if (!slice) return; + event.preventDefault(); + var insertPos = slice ? prosemirrorTransform.dropPoint(view.state.doc, $mouse.pos, slice) : $mouse.pos; + if (insertPos == null) insertPos = $mouse.pos; + var tr = view.state.tr; + if (move) { + var node = dragging.node; + if (node) node.replace(tr);else tr.deleteSelection(); + } + var pos = tr.mapping.map(insertPos); + var isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1; + var beforeInsert = tr.doc; + if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild);else tr.replaceRange(pos, pos, slice); + if (tr.doc.eq(beforeInsert)) return; + var $pos = tr.doc.resolve(pos); + if (isNode && prosemirrorState.NodeSelection.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) { + tr.setSelection(new prosemirrorState.NodeSelection($pos)); + } else { + var end = tr.mapping.map(insertPos); + tr.mapping.maps[tr.mapping.maps.length - 1].forEach(function (_from, _to, _newFrom, newTo) { + return end = newTo; + }); + tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end))); + } + view.focus(); + view.dispatch(tr.setMeta("uiEvent", "drop")); +}; +handlers.focus = function (view) { + view.input.lastFocus = Date.now(); + if (!view.focused) { + view.domObserver.stop(); + view.dom.classList.add("ProseMirror-focused"); + view.domObserver.start(); + view.focused = true; + setTimeout(function () { + if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.domSelectionRange())) selectionToDOM(view); + }, 20); + } +}; +handlers.blur = function (view, _event) { + var event = _event; + if (view.focused) { + view.domObserver.stop(); + view.dom.classList.remove("ProseMirror-focused"); + view.domObserver.start(); + if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domObserver.currentSelection.clear(); + view.focused = false; + } +}; +handlers.beforeinput = function (view, _event) { + var event = _event; + if (chrome && android && event.inputType == "deleteContentBackward") { + view.domObserver.flushSoon(); + var domChangeCount = view.input.domChangeCount; + setTimeout(function () { + if (view.input.domChangeCount != domChangeCount) return; + view.dom.blur(); + view.focus(); + if (view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(8, "Backspace")); + })) return; + var $cursor = view.state.selection.$cursor; + if ($cursor && $cursor.pos > 0) view.dispatch(view.state.tr["delete"]($cursor.pos - 1, $cursor.pos).scrollIntoView()); + }, 50); + } +}; +for (var prop in editHandlers) handlers[prop] = editHandlers[prop]; +function compareObjs(a, b) { + if (a == b) return true; + for (var p in a) if (a[p] !== b[p]) return false; + for (var _p in b) if (!(_p in a)) return false; + return true; +} +var WidgetType = function () { + function WidgetType(toDOM, spec) { + _classCallCheck(this, WidgetType); + this.toDOM = toDOM; + this.spec = spec || noSpec; + this.side = this.spec.side || 0; + } + _createClass(WidgetType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var _mapping$mapResult = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1), + pos = _mapping$mapResult.pos, + deleted = _mapping$mapResult.deleted; + return deleted ? null : new Decoration(pos - offset, pos - offset, this); + } + }, { + key: "valid", + value: function valid() { + return true; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof WidgetType && (this.spec.key && this.spec.key == other.spec.key || this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)); + } + }, { + key: "destroy", + value: function destroy(node) { + if (this.spec.destroy) this.spec.destroy(node); + } + }]); + return WidgetType; +}(); +var InlineType = function () { + function InlineType(attrs, spec) { + _classCallCheck(this, InlineType); + this.attrs = attrs; + this.spec = spec || noSpec; + } + _createClass(InlineType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var from = mapping.map(span.from + oldOffset, this.spec.inclusiveStart ? -1 : 1) - offset; + var to = mapping.map(span.to + oldOffset, this.spec.inclusiveEnd ? 1 : -1) - offset; + return from >= to ? null : new Decoration(from, to, this); + } + }, { + key: "valid", + value: function valid(_, span) { + return span.from < span.to; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof InlineType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); + } + }, { + key: "destroy", + value: function destroy() {} + }], [{ + key: "is", + value: function is(span) { + return span.type instanceof InlineType; + } + }]); + return InlineType; +}(); +var NodeType = function () { + function NodeType(attrs, spec) { + _classCallCheck(this, NodeType); + this.attrs = attrs; + this.spec = spec || noSpec; + } + _createClass(NodeType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var from = mapping.mapResult(span.from + oldOffset, 1); + if (from.deleted) return null; + var to = mapping.mapResult(span.to + oldOffset, -1); + if (to.deleted || to.pos <= from.pos) return null; + return new Decoration(from.pos - offset, to.pos - offset, this); + } + }, { + key: "valid", + value: function valid(node, span) { + var _node$content$findInd = node.content.findIndex(span.from), + index = _node$content$findInd.index, + offset = _node$content$findInd.offset, + child; + return offset == span.from && !(child = node.child(index)).isText && offset + child.nodeSize == span.to; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof NodeType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); + } + }, { + key: "destroy", + value: function destroy() {} + }]); + return NodeType; +}(); +var Decoration = function () { + function Decoration(from, to, type) { + _classCallCheck(this, Decoration); + this.from = from; + this.to = to; + this.type = type; + } + _createClass(Decoration, [{ + key: "copy", + value: function copy(from, to) { + return new Decoration(from, to, this.type); + } + }, { + key: "eq", + value: function eq(other) { + var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return this.type.eq(other.type) && this.from + offset == other.from && this.to + offset == other.to; + } + }, { + key: "map", + value: function map(mapping, offset, oldOffset) { + return this.type.map(mapping, this, offset, oldOffset); + } + }, { + key: "spec", + get: function get() { + return this.type.spec; + } + }, { + key: "inline", + get: function get() { + return this.type instanceof InlineType; + } + }, { + key: "widget", + get: function get() { + return this.type instanceof WidgetType; + } + }], [{ + key: "widget", + value: function widget(pos, toDOM, spec) { + return new Decoration(pos, pos, new WidgetType(toDOM, spec)); + } + }, { + key: "inline", + value: function inline(from, to, attrs, spec) { + return new Decoration(from, to, new InlineType(attrs, spec)); + } + }, { + key: "node", + value: function node(from, to, attrs, spec) { + return new Decoration(from, to, new NodeType(attrs, spec)); + } + }]); + return Decoration; +}(); +var none = [], + noSpec = {}; +var DecorationSet = function () { + function DecorationSet(local, children) { + _classCallCheck(this, DecorationSet); + this.local = local.length ? local : none; + this.children = children.length ? children : none; + } + _createClass(DecorationSet, [{ + key: "find", + value: function find(start, end, predicate) { + var result = []; + this.findInner(start == null ? 0 : start, end == null ? 1e9 : end, result, 0, predicate); + return result; + } + }, { + key: "findInner", + value: function findInner(start, end, result, offset, predicate) { + for (var i = 0; i < this.local.length; i++) { + var span = this.local[i]; + if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset, span.to + offset)); + } + for (var _i5 = 0; _i5 < this.children.length; _i5 += 3) { + if (this.children[_i5] < end && this.children[_i5 + 1] > start) { + var childOff = this.children[_i5] + 1; + this.children[_i5 + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate); + } + } + } + }, { + key: "map", + value: function map(mapping, doc, options) { + if (this == empty || mapping.maps.length == 0) return this; + return this.mapInner(mapping, doc, 0, 0, options || noSpec); + } + }, { + key: "mapInner", + value: function mapInner(mapping, node, offset, oldOffset, options) { + var newLocal; + for (var i = 0; i < this.local.length; i++) { + var mapped = this.local[i].map(mapping, offset, oldOffset); + if (mapped && mapped.type.valid(node, mapped)) (newLocal || (newLocal = [])).push(mapped);else if (options.onRemove) options.onRemove(this.local[i].spec); + } + if (this.children.length) return mapChildren(this.children, newLocal || [], mapping, node, offset, oldOffset, options);else return newLocal ? new DecorationSet(newLocal.sort(byPos), none) : empty; + } + }, { + key: "add", + value: function add(doc, decorations) { + if (!decorations.length) return this; + if (this == empty) return DecorationSet.create(doc, decorations); + return this.addInner(doc, decorations, 0); + } + }, { + key: "addInner", + value: function addInner(doc, decorations, offset) { + var _this10 = this; + var children, + childIndex = 0; + doc.forEach(function (childNode, childOffset) { + var baseOffset = childOffset + offset, + found; + if (!(found = takeSpansForNode(decorations, childNode, baseOffset))) return; + if (!children) children = _this10.children.slice(); + while (childIndex < children.length && children[childIndex] < childOffset) childIndex += 3; + if (children[childIndex] == childOffset) children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found, baseOffset + 1);else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec)); + childIndex += 3; + }); + var local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset); + for (var i = 0; i < local.length; i++) if (!local[i].type.valid(doc, local[i])) local.splice(i--, 1); + return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, children || this.children); + } + }, { + key: "remove", + value: function remove(decorations) { + if (decorations.length == 0 || this == empty) return this; + return this.removeInner(decorations, 0); + } + }, { + key: "removeInner", + value: function removeInner(decorations, offset) { + var children = this.children, + local = this.local; + for (var i = 0; i < children.length; i += 3) { + var found = void 0; + var from = children[i] + offset, + to = children[i + 1] + offset; + for (var j = 0, span; j < decorations.length; j++) if (span = decorations[j]) { + if (span.from > from && span.to < to) { + decorations[j] = null; + (found || (found = [])).push(span); + } + } + if (!found) continue; + if (children == this.children) children = this.children.slice(); + var removed = children[i + 2].removeInner(found, from + 1); + if (removed != empty) { + children[i + 2] = removed; + } else { + children.splice(i, 3); + i -= 3; + } + } + if (local.length) for (var _i6 = 0, _span; _i6 < decorations.length; _i6++) if (_span = decorations[_i6]) { + for (var _j2 = 0; _j2 < local.length; _j2++) if (local[_j2].eq(_span, offset)) { + if (local == this.local) local = this.local.slice(); + local.splice(_j2--, 1); + } + } + if (children == this.children && local == this.local) return this; + return local.length || children.length ? new DecorationSet(local, children) : empty; + } + }, { + key: "forChild", + value: function forChild(offset, node) { + if (this == empty) return this; + if (node.isLeaf) return DecorationSet.empty; + var child, local; + for (var i = 0; i < this.children.length; i += 3) if (this.children[i] >= offset) { + if (this.children[i] == offset) child = this.children[i + 2]; + break; + } + var start = offset + 1, + end = start + node.content.size; + for (var _i7 = 0; _i7 < this.local.length; _i7++) { + var dec = this.local[_i7]; + if (dec.from < end && dec.to > start && dec.type instanceof InlineType) { + var from = Math.max(start, dec.from) - start, + to = Math.min(end, dec.to) - start; + if (from < to) (local || (local = [])).push(dec.copy(from, to)); + } + } + if (local) { + var localSet = new DecorationSet(local.sort(byPos), none); + return child ? new DecorationGroup([localSet, child]) : localSet; + } + return child || empty; + } + }, { + key: "eq", + value: function eq(other) { + if (this == other) return true; + if (!(other instanceof DecorationSet) || this.local.length != other.local.length || this.children.length != other.children.length) return false; + for (var i = 0; i < this.local.length; i++) if (!this.local[i].eq(other.local[i])) return false; + for (var _i8 = 0; _i8 < this.children.length; _i8 += 3) if (this.children[_i8] != other.children[_i8] || this.children[_i8 + 1] != other.children[_i8 + 1] || !this.children[_i8 + 2].eq(other.children[_i8 + 2])) return false; + return true; + } + }, { + key: "locals", + value: function locals(node) { + return removeOverlap(this.localsInner(node)); + } + }, { + key: "localsInner", + value: function localsInner(node) { + if (this == empty) return none; + if (node.inlineContent || !this.local.some(InlineType.is)) return this.local; + var result = []; + for (var i = 0; i < this.local.length; i++) { + if (!(this.local[i].type instanceof InlineType)) result.push(this.local[i]); + } + return result; + } + }, { + key: "forEachSet", + value: function forEachSet(f) { + f(this); + } + }], [{ + key: "create", + value: function create(doc, decorations) { + return decorations.length ? buildTree(decorations, doc, 0, noSpec) : empty; + } + }]); + return DecorationSet; +}(); +DecorationSet.empty = new DecorationSet([], []); +DecorationSet.removeOverlap = removeOverlap; +var empty = DecorationSet.empty; +var DecorationGroup = function () { + function DecorationGroup(members) { + _classCallCheck(this, DecorationGroup); + this.members = members; + } + _createClass(DecorationGroup, [{ + key: "map", + value: function map(mapping, doc) { + var mappedDecos = this.members.map(function (member) { + return member.map(mapping, doc, noSpec); + }); + return DecorationGroup.from(mappedDecos); + } + }, { + key: "forChild", + value: function forChild(offset, child) { + if (child.isLeaf) return DecorationSet.empty; + var found = []; + for (var i = 0; i < this.members.length; i++) { + var result = this.members[i].forChild(offset, child); + if (result == empty) continue; + if (result instanceof DecorationGroup) found = found.concat(result.members);else found.push(result); + } + return DecorationGroup.from(found); + } + }, { + key: "eq", + value: function eq(other) { + if (!(other instanceof DecorationGroup) || other.members.length != this.members.length) return false; + for (var i = 0; i < this.members.length; i++) if (!this.members[i].eq(other.members[i])) return false; + return true; + } + }, { + key: "locals", + value: function locals(node) { + var result, + sorted = true; + for (var i = 0; i < this.members.length; i++) { + var locals = this.members[i].localsInner(node); + if (!locals.length) continue; + if (!result) { + result = locals; + } else { + if (sorted) { + result = result.slice(); + sorted = false; + } + for (var j = 0; j < locals.length; j++) result.push(locals[j]); + } + } + return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none; + } + }, { + key: "forEachSet", + value: function forEachSet(f) { + for (var i = 0; i < this.members.length; i++) this.members[i].forEachSet(f); + } + }], [{ + key: "from", + value: function from(members) { + switch (members.length) { + case 0: + return empty; + case 1: + return members[0]; + default: + return new DecorationGroup(members.every(function (m) { + return m instanceof DecorationSet; + }) ? members : members.reduce(function (r, m) { + return r.concat(m instanceof DecorationSet ? m : m.members); + }, [])); + } + } + }]); + return DecorationGroup; +}(); +function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) { + var children = oldChildren.slice(); + var _loop4 = function _loop4(_baseOffset) { + var moved = 0; + mapping.maps[i].forEach(function (oldStart, oldEnd, newStart, newEnd) { + var dSize = newEnd - newStart - (oldEnd - oldStart); + for (var _i12 = 0; _i12 < children.length; _i12 += 3) { + var end = children[_i12 + 1]; + if (end < 0 || oldStart > end + _baseOffset - moved) continue; + var start = children[_i12] + _baseOffset - moved; + if (oldEnd >= start) { + children[_i12 + 1] = oldStart <= start ? -2 : -1; + } else if (oldStart >= _baseOffset && dSize) { + children[_i12] += dSize; + children[_i12 + 1] += dSize; + } + } + moved += dSize; + }); + _baseOffset = mapping.maps[i].map(_baseOffset, -1); + baseOffset = _baseOffset; + }; + for (var i = 0, baseOffset = oldOffset; i < mapping.maps.length; i++) { + _loop4(baseOffset); + } + var mustRebuild = false; + for (var _i9 = 0; _i9 < children.length; _i9 += 3) if (children[_i9 + 1] < 0) { + if (children[_i9 + 1] == -2) { + mustRebuild = true; + children[_i9 + 1] = -1; + continue; + } + var from = mapping.map(oldChildren[_i9] + oldOffset), + fromLocal = from - offset; + if (fromLocal < 0 || fromLocal >= node.content.size) { + mustRebuild = true; + continue; + } + var to = mapping.map(oldChildren[_i9 + 1] + oldOffset, -1), + toLocal = to - offset; + var _node$content$findInd2 = node.content.findIndex(fromLocal), + index = _node$content$findInd2.index, + childOffset = _node$content$findInd2.offset; + var childNode = node.maybeChild(index); + if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) { + var mapped = children[_i9 + 2].mapInner(mapping, childNode, from + 1, oldChildren[_i9] + oldOffset + 1, options); + if (mapped != empty) { + children[_i9] = fromLocal; + children[_i9 + 1] = toLocal; + children[_i9 + 2] = mapped; + } else { + children[_i9 + 1] = -2; + mustRebuild = true; + } + } else { + mustRebuild = true; + } + } + if (mustRebuild) { + var decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal, mapping, offset, oldOffset, options); + var built = buildTree(decorations, node, 0, options); + newLocal = built.local; + for (var _i10 = 0; _i10 < children.length; _i10 += 3) if (children[_i10 + 1] < 0) { + children.splice(_i10, 3); + _i10 -= 3; + } + for (var _i11 = 0, j = 0; _i11 < built.children.length; _i11 += 3) { + var _from2 = built.children[_i11]; + while (j < children.length && children[j] < _from2) j += 3; + children.splice(j, 0, built.children[_i11], built.children[_i11 + 1], built.children[_i11 + 2]); + } + } + return new DecorationSet(newLocal.sort(byPos), children); +} +function moveSpans(spans, offset) { + if (!offset || !spans.length) return spans; + var result = []; + for (var i = 0; i < spans.length; i++) { + var span = spans[i]; + result.push(new Decoration(span.from + offset, span.to + offset, span.type)); + } + return result; +} +function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) { + function gather(set, oldOffset) { + for (var i = 0; i < set.local.length; i++) { + var mapped = set.local[i].map(mapping, offset, oldOffset); + if (mapped) decorations.push(mapped);else if (options.onRemove) options.onRemove(set.local[i].spec); + } + for (var _i13 = 0; _i13 < set.children.length; _i13 += 3) gather(set.children[_i13 + 2], set.children[_i13] + oldOffset + 1); + } + for (var i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1); + return decorations; +} +function takeSpansForNode(spans, node, offset) { + if (node.isLeaf) return null; + var end = offset + node.nodeSize, + found = null; + for (var i = 0, span; i < spans.length; i++) { + if ((span = spans[i]) && span.from > offset && span.to < end) { + (found || (found = [])).push(span); + spans[i] = null; + } + } + return found; +} +function withoutNulls(array) { + var result = []; + for (var i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]); + return result; +} +function buildTree(spans, node, offset, options) { + var children = [], + hasNulls = false; + node.forEach(function (childNode, localStart) { + var found = takeSpansForNode(spans, childNode, localStart + offset); + if (found) { + hasNulls = true; + var subtree = buildTree(found, childNode, offset + localStart + 1, options); + if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree); + } + }); + var locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos); + for (var i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i])) { + if (options.onRemove) options.onRemove(locals[i].spec); + locals.splice(i--, 1); + } + return locals.length || children.length ? new DecorationSet(locals, children) : empty; +} +function byPos(a, b) { + return a.from - b.from || a.to - b.to; +} +function removeOverlap(spans) { + var working = spans; + for (var i = 0; i < working.length - 1; i++) { + var span = working[i]; + if (span.from != span.to) for (var j = i + 1; j < working.length; j++) { + var next = working[j]; + if (next.from == span.from) { + if (next.to != span.to) { + if (working == spans) working = spans.slice(); + working[j] = next.copy(next.from, span.to); + insertAhead(working, j + 1, next.copy(span.to, next.to)); + } + continue; + } else { + if (next.from < span.to) { + if (working == spans) working = spans.slice(); + working[i] = span.copy(span.from, next.from); + insertAhead(working, j, span.copy(next.from, span.to)); + } + break; + } + } + } + return working; +} +function insertAhead(array, i, deco) { + while (i < array.length && byPos(deco, array[i]) > 0) i++; + array.splice(i, 0, deco); +} +function viewDecorations(view) { + var found = []; + view.someProp("decorations", function (f) { + var result = f(view.state); + if (result && result != empty) found.push(result); + }); + if (view.cursorWrapper) found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco])); + return DecorationGroup.from(found); +} +var observeOptions = { + childList: true, + characterData: true, + characterDataOldValue: true, + attributes: true, + attributeOldValue: true, + subtree: true +}; +var useCharData = ie && ie_version <= 11; +var SelectionState = function () { + function SelectionState() { + _classCallCheck(this, SelectionState); + this.anchorNode = null; + this.anchorOffset = 0; + this.focusNode = null; + this.focusOffset = 0; + } + _createClass(SelectionState, [{ + key: "set", + value: function set(sel) { + this.anchorNode = sel.anchorNode; + this.anchorOffset = sel.anchorOffset; + this.focusNode = sel.focusNode; + this.focusOffset = sel.focusOffset; + } + }, { + key: "clear", + value: function clear() { + this.anchorNode = this.focusNode = null; + } + }, { + key: "eq", + value: function eq(sel) { + return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset; + } + }]); + return SelectionState; +}(); +var DOMObserver = function () { + function DOMObserver(view, handleDOMChange) { + var _this11 = this; + _classCallCheck(this, DOMObserver); + this.view = view; + this.handleDOMChange = handleDOMChange; + this.queue = []; + this.flushingSoon = -1; + this.observer = null; + this.currentSelection = new SelectionState(); + this.onCharData = null; + this.suppressingSelectionUpdates = false; + this.lastChangedTextNode = null; + this.observer = window.MutationObserver && new window.MutationObserver(function (mutations) { + for (var i = 0; i < mutations.length; i++) _this11.queue.push(mutations[i]); + if (ie && ie_version <= 11 && mutations.some(function (m) { + return m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length; + })) _this11.flushSoon();else _this11.flush(); + }); + if (useCharData) { + this.onCharData = function (e) { + _this11.queue.push({ + target: e.target, + type: "characterData", + oldValue: e.prevValue + }); + _this11.flushSoon(); + }; + } + this.onSelectionChange = this.onSelectionChange.bind(this); + } + _createClass(DOMObserver, [{ + key: "flushSoon", + value: function flushSoon() { + var _this12 = this; + if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(function () { + _this12.flushingSoon = -1; + _this12.flush(); + }, 20); + } + }, { + key: "forceFlush", + value: function forceFlush() { + if (this.flushingSoon > -1) { + window.clearTimeout(this.flushingSoon); + this.flushingSoon = -1; + this.flush(); + } + } + }, { + key: "start", + value: function start() { + if (this.observer) { + this.observer.takeRecords(); + this.observer.observe(this.view.dom, observeOptions); + } + if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData); + this.connectSelection(); + } + }, { + key: "stop", + value: function stop() { + var _this13 = this; + if (this.observer) { + var take = this.observer.takeRecords(); + if (take.length) { + for (var i = 0; i < take.length; i++) this.queue.push(take[i]); + window.setTimeout(function () { + return _this13.flush(); + }, 20); + } + this.observer.disconnect(); + } + if (this.onCharData) this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData); + this.disconnectSelection(); + } + }, { + key: "connectSelection", + value: function connectSelection() { + this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange); + } + }, { + key: "disconnectSelection", + value: function disconnectSelection() { + this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange); + } + }, { + key: "suppressSelectionUpdates", + value: function suppressSelectionUpdates() { + var _this14 = this; + this.suppressingSelectionUpdates = true; + setTimeout(function () { + return _this14.suppressingSelectionUpdates = false; + }, 50); + } + }, { + key: "onSelectionChange", + value: function onSelectionChange() { + if (!hasFocusAndSelection(this.view)) return; + if (this.suppressingSelectionUpdates) return selectionToDOM(this.view); + if (ie && ie_version <= 11 && !this.view.state.selection.empty) { + var sel = this.view.domSelectionRange(); + if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon(); + } + this.flush(); + } + }, { + key: "setCurSelection", + value: function setCurSelection() { + this.currentSelection.set(this.view.domSelectionRange()); + } + }, { + key: "ignoreSelectionChange", + value: function ignoreSelectionChange(sel) { + if (!sel.focusNode) return true; + var ancestors = new Set(), + container; + for (var scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan); + for (var _scan = sel.anchorNode; _scan; _scan = parentNode(_scan)) if (ancestors.has(_scan)) { + container = _scan; + break; + } + var desc = container && this.view.docView.nearestDesc(container); + if (desc && desc.ignoreMutation({ + type: "selection", + target: container.nodeType == 3 ? container.parentNode : container + })) { + this.setCurSelection(); + return true; + } + } + }, { + key: "pendingRecords", + value: function pendingRecords() { + if (this.observer) { + var _iterator2 = _createForOfIteratorHelper(this.observer.takeRecords()), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var mut = _step2.value; + this.queue.push(mut); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + return this.queue; + } + }, { + key: "selectionChanged", + value: function selectionChanged(sel) { + return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel); + } + }, { + key: "flush", + value: function flush() { + var view = this.view; + if (!view.docView || this.flushingSoon > -1) return; + var mutations = this.pendingRecords(); + if (mutations.length) this.queue = []; + var sel = view.domSelectionRange(), + newSel = this.selectionChanged(sel); + var from = -1, + to = -1, + typeOver = false, + added = []; + if (view.editable) { + for (var i = 0; i < mutations.length; i++) { + var result = this.registerMutation(mutations[i], added); + if (result) { + from = from < 0 ? result.from : Math.min(result.from, from); + to = to < 0 ? result.to : Math.max(result.to, to); + if (result.typeOver) typeOver = true; + } + } + } + if (gecko && added.length) { + var brs = added.filter(function (n) { + return n.nodeName == "BR"; + }); + if (brs.length == 2) { + var _brs = _slicedToArray(brs, 2), + a = _brs[0], + b = _brs[1]; + if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();else a.remove(); + } else { + var focusNode = this.currentSelection.focusNode; + var _iterator3 = _createForOfIteratorHelper(brs), + _step3; + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var br = _step3.value; + var parent = br.parentNode; + if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove(); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + } + var readSel = null; + if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(prosemirrorState.Selection.near(view.state.doc.resolve(0), 1))) { + view.input.lastFocus = 0; + selectionToDOM(view); + this.currentSelection.set(sel); + view.scrollToSelection(); + } else if (from > -1 || newSel) { + if (from > -1) { + view.docView.markDirty(from, to); + checkCSS(view); + } + this.handleDOMChange(from, to, typeOver, added); + if (view.docView && view.docView.dirty) view.updateState(view.state);else if (!this.currentSelection.eq(sel)) selectionToDOM(view); + this.currentSelection.set(sel); + } + } + }, { + key: "registerMutation", + value: function registerMutation(mut, added) { + if (added.indexOf(mut.target) > -1) return null; + var desc = this.view.docView.nearestDesc(mut.target); + if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null; + if (!desc || desc.ignoreMutation(mut)) return null; + if (mut.type == "childList") { + for (var i = 0; i < mut.addedNodes.length; i++) { + var node = mut.addedNodes[i]; + added.push(node); + if (node.nodeType == 3) this.lastChangedTextNode = node; + } + if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return { + from: desc.posBefore, + to: desc.posAfter + }; + var prev = mut.previousSibling, + next = mut.nextSibling; + if (ie && ie_version <= 11 && mut.addedNodes.length) { + for (var _i14 = 0; _i14 < mut.addedNodes.length; _i14++) { + var _mut$addedNodes$_i = mut.addedNodes[_i14], + previousSibling = _mut$addedNodes$_i.previousSibling, + nextSibling = _mut$addedNodes$_i.nextSibling; + if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling; + if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) next = nextSibling; + } + } + var fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0; + var from = desc.localPosFromDOM(mut.target, fromOffset, -1); + var toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length; + var to = desc.localPosFromDOM(mut.target, toOffset, 1); + return { + from: from, + to: to + }; + } else if (mut.type == "attributes") { + return { + from: desc.posAtStart - desc.border, + to: desc.posAtEnd + desc.border + }; + } else { + this.lastChangedTextNode = mut.target; + return { + from: desc.posAtStart, + to: desc.posAtEnd, + typeOver: mut.target.nodeValue == mut.oldValue + }; + } + } + }]); + return DOMObserver; +}(); +var cssChecked = new WeakMap(); +var cssCheckWarned = false; +function checkCSS(view) { + if (cssChecked.has(view)) return; + cssChecked.set(view, null); + if (['normal', 'nowrap', 'pre-line'].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) { + view.requiresGeckoHackNode = gecko; + if (cssCheckWarned) return; + console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."); + cssCheckWarned = true; + } +} +function rangeToSelectionRange(view, range) { + var anchorNode = range.startContainer, + anchorOffset = range.startOffset; + var focusNode = range.endContainer, + focusOffset = range.endOffset; + var currentAnchor = view.domAtPos(view.state.selection.anchor); + if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) { + var _ref5 = [focusNode, focusOffset, anchorNode, anchorOffset]; + anchorNode = _ref5[0]; + anchorOffset = _ref5[1]; + focusNode = _ref5[2]; + focusOffset = _ref5[3]; + } + return { + anchorNode: anchorNode, + anchorOffset: anchorOffset, + focusNode: focusNode, + focusOffset: focusOffset + }; +} +function safariShadowSelectionRange(view, selection) { + if (selection.getComposedRanges) { + var range = selection.getComposedRanges(view.root)[0]; + if (range) return rangeToSelectionRange(view, range); + } + var found; + function read(event) { + event.preventDefault(); + event.stopImmediatePropagation(); + found = event.getTargetRanges()[0]; + } + view.dom.addEventListener("beforeinput", read, true); + document.execCommand("indent"); + view.dom.removeEventListener("beforeinput", read, true); + return found ? rangeToSelectionRange(view, found) : null; +} +function blockParent(view, node) { + for (var p = node.parentNode; p && p != view.dom; p = p.parentNode) { + var desc = view.docView.nearestDesc(p, true); + if (desc && desc.node.isBlock) return p; + } + return null; +} +function parseBetween(view, from_, to_) { + var _view$docView$parseRa = view.docView.parseRange(from_, to_), + parent = _view$docView$parseRa.node, + fromOffset = _view$docView$parseRa.fromOffset, + toOffset = _view$docView$parseRa.toOffset, + from = _view$docView$parseRa.from, + to = _view$docView$parseRa.to; + var domSel = view.domSelectionRange(); + var find; + var anchor = domSel.anchorNode; + if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) { + find = [{ + node: anchor, + offset: domSel.anchorOffset + }]; + if (!selectionCollapsed(domSel)) find.push({ + node: domSel.focusNode, + offset: domSel.focusOffset + }); + } + if (chrome && view.input.lastKeyCode === 8) { + for (var off = toOffset; off > fromOffset; off--) { + var node = parent.childNodes[off - 1], + desc = node.pmViewDesc; + if (node.nodeName == "BR" && !desc) { + toOffset = off; + break; + } + if (!desc || desc.size) break; + } + } + var startDoc = view.state.doc; + var parser = view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema); + var $from = startDoc.resolve(from); + var sel = null, + doc = parser.parse(parent, { + topNode: $from.parent, + topMatch: $from.parent.contentMatchAt($from.index()), + topOpen: true, + from: fromOffset, + to: toOffset, + preserveWhitespace: $from.parent.type.whitespace == "pre" ? "full" : true, + findPositions: find, + ruleFromNode: ruleFromNode, + context: $from + }); + if (find && find[0].pos != null) { + var _anchor = find[0].pos, + head = find[1] && find[1].pos; + if (head == null) head = _anchor; + sel = { + anchor: _anchor + from, + head: head + from + }; + } + return { + doc: doc, + sel: sel, + from: from, + to: to + }; +} +function ruleFromNode(dom) { + var desc = dom.pmViewDesc; + if (desc) { + return desc.parseRule(); + } else if (dom.nodeName == "BR" && dom.parentNode) { + if (safari && /^(ul|ol)$/i.test(dom.parentNode.nodeName)) { + var skip = document.createElement("div"); + skip.appendChild(document.createElement("li")); + return { + skip: skip + }; + } else if (dom.parentNode.lastChild == dom || safari && /^(tr|table)$/i.test(dom.parentNode.nodeName)) { + return { + ignore: true + }; + } + } else if (dom.nodeName == "IMG" && dom.getAttribute("mark-placeholder")) { + return { + ignore: true + }; + } + return null; +} +var isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i; +function readDOMChange(view, from, to, typeOver, addedNodes) { + var compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0); + view.input.compositionPendingChanges = 0; + if (from < 0) { + var origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null; + var newSel = selectionFromDOM(view, origin); + if (newSel && !view.state.selection.eq(newSel)) { + if (chrome && android && view.input.lastKeyCode === 13 && Date.now() - 100 < view.input.lastKeyCodeTime && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) return; + var _tr = view.state.tr.setSelection(newSel); + if (origin == "pointer") _tr.setMeta("pointer", true);else if (origin == "key") _tr.scrollIntoView(); + if (compositionID) _tr.setMeta("composition", compositionID); + view.dispatch(_tr); + } + return; + } + var $before = view.state.doc.resolve(from); + var shared = $before.sharedDepth(to); + from = $before.before(shared + 1); + to = view.state.doc.resolve(to).after(shared + 1); + var sel = view.state.selection; + var parse = parseBetween(view, from, to); + var doc = view.state.doc, + compare = doc.slice(parse.from, parse.to); + var preferredPos, preferredSide; + if (view.input.lastKeyCode === 8 && Date.now() - 100 < view.input.lastKeyCodeTime) { + preferredPos = view.state.selection.to; + preferredSide = "end"; + } else { + preferredPos = view.state.selection.from; + preferredSide = "start"; + } + view.input.lastKeyCode = null; + var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide); + if (change) view.input.domChangeCount++; + if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) { + return n.nodeType == 1 && !isInline.test(n.nodeName); + }) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) { + view.input.lastIOSEnter = 0; + return; + } + if (!change) { + if (typeOver && sel instanceof prosemirrorState.TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) { + change = { + start: sel.from, + endA: sel.to, + endB: sel.to + }; + } else { + if (parse.sel) { + var _sel2 = resolveSelection(view, view.state.doc, parse.sel); + if (_sel2 && !_sel2.eq(view.state.selection)) { + var _tr2 = view.state.tr.setSelection(_sel2); + if (compositionID) _tr2.setMeta("composition", compositionID); + view.dispatch(_tr2); + } + } + return; + } + } + if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof prosemirrorState.TextSelection) { + if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) { + change.start = view.state.selection.from; + } else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse.to) { + change.endB += view.state.selection.to - change.endA; + change.endA = view.state.selection.to; + } + } + if (ie && ie_version <= 11 && change.endB == change.start + 1 && change.endA == change.start && change.start > parse.from && parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == " \xA0") { + change.start--; + change.endA--; + change.endB--; + } + var $from = parse.doc.resolveNoCache(change.start - parse.from); + var $to = parse.doc.resolveNoCache(change.endB - parse.from); + var $fromA = doc.resolve(change.start); + var inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA; + var nextSel; + if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some(function (n) { + return n.nodeName == "DIV" || n.nodeName == "P"; + })) || !inlineChange && $from.pos < parse.doc.content.size && !$from.sameParent($to) && (nextSel = prosemirrorState.Selection.findFrom(parse.doc.resolve($from.pos + 1), 1, true)) && nextSel.head == $to.pos) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) { + view.input.lastIOSEnter = 0; + return; + } + if (view.state.selection.anchor > change.start && looksLikeBackspace(doc, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(8, "Backspace")); + })) { + if (android && chrome) view.domObserver.suppressSelectionUpdates(); + return; + } + if (chrome && android && change.endB == change.start) view.input.lastAndroidDelete = Date.now(); + if (android && !inlineChange && $from.start() != $to.start() && $to.parentOffset == 0 && $from.depth == $to.depth && parse.sel && parse.sel.anchor == parse.sel.head && parse.sel.head == change.endA) { + change.endB -= 2; + $to = parse.doc.resolveNoCache(change.endB - parse.from); + setTimeout(function () { + view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + }); + }, 20); + } + var chFrom = change.start, + chTo = change.endA; + var tr, storedMarks, markChange; + if (inlineChange) { + if ($from.pos == $to.pos) { + if (ie && ie_version <= 11 && $from.parentOffset == 0) { + view.domObserver.suppressSelectionUpdates(); + setTimeout(function () { + return selectionToDOM(view); + }, 20); + } + tr = view.state.tr["delete"](chFrom, chTo); + storedMarks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA)); + } else if (change.endA == change.endB && (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), $fromA.parent.content.cut($fromA.parentOffset, change.endA - $fromA.start())))) { + tr = view.state.tr; + if (markChange.type == "add") tr.addMark(chFrom, chTo, markChange.mark);else tr.removeMark(chFrom, chTo, markChange.mark); + } else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) { + var text = $from.parent.textBetween($from.parentOffset, $to.parentOffset); + if (view.someProp("handleTextInput", function (f) { + return f(view, chFrom, chTo, text); + })) return; + tr = view.state.tr.insertText(text, chFrom, chTo); + } + } + if (!tr) tr = view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from)); + if (parse.sel) { + var _sel3 = resolveSelection(view, tr.doc, parse.sel); + if (_sel3 && !(chrome && android && view.composing && _sel3.empty && (change.start != change.endB || view.input.lastAndroidDelete < Date.now() - 100) && (_sel3.head == chFrom || _sel3.head == tr.mapping.map(chTo) - 1) || ie && _sel3.empty && _sel3.head == chFrom)) tr.setSelection(_sel3); + } + if (storedMarks) tr.ensureMarks(storedMarks); + if (compositionID) tr.setMeta("composition", compositionID); + view.dispatch(tr.scrollIntoView()); +} +function resolveSelection(view, doc, parsedSel) { + if (Math.max(parsedSel.anchor, parsedSel.head) > doc.content.size) return null; + return selectionBetween(view, doc.resolve(parsedSel.anchor), doc.resolve(parsedSel.head)); +} +function isMarkChange(cur, prev) { + var curMarks = cur.firstChild.marks, + prevMarks = prev.firstChild.marks; + var added = curMarks, + removed = prevMarks, + type, + mark, + update; + for (var i = 0; i < prevMarks.length; i++) added = prevMarks[i].removeFromSet(added); + for (var _i15 = 0; _i15 < curMarks.length; _i15++) removed = curMarks[_i15].removeFromSet(removed); + if (added.length == 1 && removed.length == 0) { + mark = added[0]; + type = "add"; + update = function update(node) { + return node.mark(mark.addToSet(node.marks)); + }; + } else if (added.length == 0 && removed.length == 1) { + mark = removed[0]; + type = "remove"; + update = function update(node) { + return node.mark(mark.removeFromSet(node.marks)); + }; + } else { + return null; + } + var updated = []; + for (var _i16 = 0; _i16 < prev.childCount; _i16++) updated.push(update(prev.child(_i16))); + if (prosemirrorModel.Fragment.from(updated).eq(cur)) return { + mark: mark, + type: type + }; +} +function looksLikeBackspace(old, start, end, $newStart, $newEnd) { + if (end - start <= $newEnd.pos - $newStart.pos || skipClosingAndOpening($newStart, true, false) < $newEnd.pos) return false; + var $start = old.resolve(start); + if (!$newStart.parent.isTextblock) { + var after = $start.nodeAfter; + return after != null && end == start + after.nodeSize; + } + if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock) return false; + var $next = old.resolve(skipClosingAndOpening($start, true, true)); + if (!$next.parent.isTextblock || $next.pos > end || skipClosingAndOpening($next, true, false) < end) return false; + return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content); +} +function skipClosingAndOpening($pos, fromEnd, mayOpen) { + var depth = $pos.depth, + end = fromEnd ? $pos.end() : $pos.pos; + while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) { + depth--; + end++; + fromEnd = false; + } + if (mayOpen) { + var next = $pos.node(depth).maybeChild($pos.indexAfter(depth)); + while (next && !next.isLeaf) { + next = next.firstChild; + end++; + } + } + return end; +} +function findDiff(a, b, pos, preferredPos, preferredSide) { + var start = a.findDiffStart(b, pos); + if (start == null) return null; + var _a$findDiffEnd = a.findDiffEnd(b, pos + a.size, pos + b.size), + endA = _a$findDiffEnd.a, + endB = _a$findDiffEnd.b; + if (preferredSide == "end") { + var adjust = Math.max(0, start - Math.min(endA, endB)); + preferredPos -= endA + adjust - start; + } + if (endA < start && a.size < b.size) { + var move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0; + start -= move; + if (start && start < b.size && isSurrogatePair(b.textBetween(start - 1, start + 1))) start += move ? 1 : -1; + endB = start + (endB - endA); + endA = start; + } else if (endB < start) { + var _move = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0; + start -= _move; + if (start && start < a.size && isSurrogatePair(a.textBetween(start - 1, start + 1))) start += _move ? 1 : -1; + endA = start + (endA - endB); + endB = start; + } + return { + start: start, + endA: endA, + endB: endB + }; +} +function isSurrogatePair(str) { + if (str.length != 2) return false; + var a = str.charCodeAt(0), + b = str.charCodeAt(1); + return a >= 0xDC00 && a <= 0xDFFF && b >= 0xD800 && b <= 0xDBFF; +} +var __serializeForClipboard = serializeForClipboard; +var __parseFromClipboard = parseFromClipboard; +var __endComposition = endComposition; +var EditorView = function () { + function EditorView(place, props) { + var _this15 = this; + _classCallCheck(this, EditorView); + this._root = null; + this.focused = false; + this.trackWrites = null; + this.mounted = false; + this.markCursor = null; + this.cursorWrapper = null; + this.lastSelectedViewDesc = undefined; + this.input = new InputState(); + this.prevDirectPlugins = []; + this.pluginViews = []; + this.requiresGeckoHackNode = false; + this.dragging = null; + this._props = props; + this.state = props.state; + this.directPlugins = props.plugins || []; + this.directPlugins.forEach(checkStateComponent); + this.dispatch = this.dispatch.bind(this); + this.dom = place && place.mount || document.createElement("div"); + if (place) { + if (place.appendChild) place.appendChild(this.dom);else if (typeof place == "function") place(this.dom);else if (place.mount) this.mounted = true; + } + this.editable = getEditable(this); + updateCursorWrapper(this); + this.nodeViews = buildNodeViews(this); + this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this); + this.domObserver = new DOMObserver(this, function (from, to, typeOver, added) { + return readDOMChange(_this15, from, to, typeOver, added); + }); + this.domObserver.start(); + initInput(this); + this.updatePluginViews(); + } + _createClass(EditorView, [{ + key: "composing", + get: function get() { + return this.input.composing; + } + }, { + key: "props", + get: function get() { + if (this._props.state != this.state) { + var prev = this._props; + this._props = {}; + for (var name in prev) this._props[name] = prev[name]; + this._props.state = this.state; + } + return this._props; + } + }, { + key: "update", + value: function update(props) { + if (props.handleDOMEvents != this._props.handleDOMEvents) ensureListeners(this); + var prevProps = this._props; + this._props = props; + if (props.plugins) { + props.plugins.forEach(checkStateComponent); + this.directPlugins = props.plugins; + } + this.updateStateInner(props.state, prevProps); + } + }, { + key: "setProps", + value: function setProps(props) { + var updated = {}; + for (var name in this._props) updated[name] = this._props[name]; + updated.state = this.state; + for (var _name2 in props) updated[_name2] = props[_name2]; + this.update(updated); + } + }, { + key: "updateState", + value: function updateState(state) { + this.updateStateInner(state, this._props); + } + }, { + key: "updateStateInner", + value: function updateStateInner(state, prevProps) { + var _a; + var prev = this.state, + redraw = false, + updateSel = false; + if (state.storedMarks && this.composing) { + clearComposition(this); + updateSel = true; + } + this.state = state; + var pluginsChanged = prev.plugins != state.plugins || this._props.plugins != prevProps.plugins; + if (pluginsChanged || this._props.plugins != prevProps.plugins || this._props.nodeViews != prevProps.nodeViews) { + var nodeViews = buildNodeViews(this); + if (changedNodeViews(nodeViews, this.nodeViews)) { + this.nodeViews = nodeViews; + redraw = true; + } + } + if (pluginsChanged || prevProps.handleDOMEvents != this._props.handleDOMEvents) { + ensureListeners(this); + } + this.editable = getEditable(this); + updateCursorWrapper(this); + var innerDeco = viewDecorations(this), + outerDeco = computeDocDeco(this); + var scroll = prev.plugins != state.plugins && !prev.doc.eq(state.doc) ? "reset" : state.scrollToSelection > prev.scrollToSelection ? "to selection" : "preserve"; + var updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco); + if (updateDoc || !state.selection.eq(prev.selection)) updateSel = true; + var oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this); + if (updateSel) { + this.domObserver.stop(); + var forceSelUpdate = updateDoc && (ie || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection); + if (updateDoc) { + var chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null; + if (this.composing) this.input.compositionNode = findCompositionNode(this); + if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) { + this.docView.updateOuterDeco(outerDeco); + this.docView.destroy(); + this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this); + } + if (chromeKludge && !this.trackWrites) forceSelUpdate = true; + } + if (forceSelUpdate || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && anchorInRightPlace(this))) { + selectionToDOM(this, forceSelUpdate); + } else { + syncNodeSelection(this, state.selection); + this.domObserver.setCurSelection(); + } + this.domObserver.start(); + } + this.updatePluginViews(prev); + if (((_a = this.dragging) === null || _a === void 0 ? void 0 : _a.node) && !prev.doc.eq(state.doc)) this.updateDraggedNode(this.dragging, prev); + if (scroll == "reset") { + this.dom.scrollTop = 0; + } else if (scroll == "to selection") { + this.scrollToSelection(); + } else if (oldScrollPos) { + resetScrollPos(oldScrollPos); + } + } + }, { + key: "scrollToSelection", + value: function scrollToSelection() { + var _this16 = this; + var startDOM = this.domSelectionRange().focusNode; + if (this.someProp("handleScrollToSelection", function (f) { + return f(_this16); + })) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) { + var target = this.docView.domAfterPos(this.state.selection.from); + if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM); + } else { + scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM); + } + } + }, { + key: "destroyPluginViews", + value: function destroyPluginViews() { + var view; + while (view = this.pluginViews.pop()) if (view.destroy) view.destroy(); + } + }, { + key: "updatePluginViews", + value: function updatePluginViews(prevState) { + if (!prevState || prevState.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) { + this.prevDirectPlugins = this.directPlugins; + this.destroyPluginViews(); + for (var i = 0; i < this.directPlugins.length; i++) { + var plugin = this.directPlugins[i]; + if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this)); + } + for (var _i17 = 0; _i17 < this.state.plugins.length; _i17++) { + var _plugin = this.state.plugins[_i17]; + if (_plugin.spec.view) this.pluginViews.push(_plugin.spec.view(this)); + } + } else { + for (var _i18 = 0; _i18 < this.pluginViews.length; _i18++) { + var pluginView = this.pluginViews[_i18]; + if (pluginView.update) pluginView.update(this, prevState); + } + } + } + }, { + key: "updateDraggedNode", + value: function updateDraggedNode(dragging, prev) { + var sel = dragging.node, + found = -1; + if (this.state.doc.nodeAt(sel.from) == sel.node) { + found = sel.from; + } else { + var movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size); + var moved = movedPos > 0 && this.state.doc.nodeAt(movedPos); + if (moved == sel.node) found = movedPos; + } + this.dragging = new Dragging(dragging.slice, dragging.move, found < 0 ? undefined : prosemirrorState.NodeSelection.create(this.state.doc, found)); + } + }, { + key: "someProp", + value: function someProp(propName, f) { + var prop = this._props && this._props[propName], + value; + if (prop != null && (value = f ? f(prop) : prop)) return value; + for (var i = 0; i < this.directPlugins.length; i++) { + var _prop = this.directPlugins[i].props[propName]; + if (_prop != null && (value = f ? f(_prop) : _prop)) return value; + } + var plugins = this.state.plugins; + if (plugins) for (var _i19 = 0; _i19 < plugins.length; _i19++) { + var _prop2 = plugins[_i19].props[propName]; + if (_prop2 != null && (value = f ? f(_prop2) : _prop2)) return value; + } + } + }, { + key: "hasFocus", + value: function hasFocus() { + if (ie) { + var node = this.root.activeElement; + if (node == this.dom) return true; + if (!node || !this.dom.contains(node)) return false; + while (node && this.dom != node && this.dom.contains(node)) { + if (node.contentEditable == 'false') return false; + node = node.parentElement; + } + return true; + } + return this.root.activeElement == this.dom; + } + }, { + key: "focus", + value: function focus() { + this.domObserver.stop(); + if (this.editable) focusPreventScroll(this.dom); + selectionToDOM(this); + this.domObserver.start(); + } + }, { + key: "root", + get: function get() { + var _this17 = this; + var cached = this._root; + if (cached == null) { + var _loop5 = function _loop5(search) { + if (search.nodeType == 9 || search.nodeType == 11 && search.host) { + if (!search.getSelection) Object.getPrototypeOf(search).getSelection = function () { + return search.ownerDocument.getSelection(); + }; + return { + v: _this17._root = search + }; + } + }, + _ret3; + for (var search = this.dom.parentNode; search; search = search.parentNode) { + _ret3 = _loop5(search); + if (_ret3) return _ret3.v; + } + } + return cached || document; + } + }, { + key: "updateRoot", + value: function updateRoot() { + this._root = null; + } + }, { + key: "posAtCoords", + value: function posAtCoords(coords) { + return _posAtCoords(this, coords); + } + }, { + key: "coordsAtPos", + value: function coordsAtPos(pos) { + var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return _coordsAtPos(this, pos, side); + } + }, { + key: "domAtPos", + value: function domAtPos(pos) { + var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return this.docView.domFromPos(pos, side); + } + }, { + key: "nodeDOM", + value: function nodeDOM(pos) { + var desc = this.docView.descAt(pos); + return desc ? desc.nodeDOM : null; + } + }, { + key: "posAtDOM", + value: function posAtDOM(node, offset) { + var bias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; + var pos = this.docView.posFromDOM(node, offset, bias); + if (pos == null) throw new RangeError("DOM position not inside the editor"); + return pos; + } + }, { + key: "endOfTextblock", + value: function endOfTextblock(dir, state) { + return _endOfTextblock(this, state || this.state, dir); + } + }, { + key: "pasteHTML", + value: function pasteHTML(html, event) { + return doPaste(this, "", html, false, event || new ClipboardEvent("paste")); + } + }, { + key: "pasteText", + value: function pasteText(text, event) { + return doPaste(this, text, null, true, event || new ClipboardEvent("paste")); + } + }, { + key: "destroy", + value: function destroy() { + if (!this.docView) return; + destroyInput(this); + this.destroyPluginViews(); + if (this.mounted) { + this.docView.update(this.state.doc, [], viewDecorations(this), this); + this.dom.textContent = ""; + } else if (this.dom.parentNode) { + this.dom.parentNode.removeChild(this.dom); + } + this.docView.destroy(); + this.docView = null; + clearReusedRange(); + } + }, { + key: "isDestroyed", + get: function get() { + return this.docView == null; + } + }, { + key: "dispatchEvent", + value: function dispatchEvent(event) { + return _dispatchEvent(this, event); + } + }, { + key: "dispatch", + value: function dispatch(tr) { + var dispatchTransaction = this._props.dispatchTransaction; + if (dispatchTransaction) dispatchTransaction.call(this, tr);else this.updateState(this.state.apply(tr)); + } + }, { + key: "domSelectionRange", + value: function domSelectionRange() { + var sel = this.domSelection(); + if (!sel) return { + focusNode: null, + focusOffset: 0, + anchorNode: null, + anchorOffset: 0 + }; + return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel; + } + }, { + key: "domSelection", + value: function domSelection() { + return this.root.getSelection(); + } + }]); + return EditorView; +}(); +function computeDocDeco(view) { + var attrs = Object.create(null); + attrs["class"] = "ProseMirror"; + attrs.contenteditable = String(view.editable); + view.someProp("attributes", function (value) { + if (typeof value == "function") value = value(view.state); + if (value) for (var attr in value) { + if (attr == "class") attrs["class"] += " " + value[attr];else if (attr == "style") attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") attrs[attr] = String(value[attr]); + } + }); + if (!attrs.translate) attrs.translate = "no"; + return [Decoration.node(0, view.state.doc.content.size, attrs)]; +} +function updateCursorWrapper(view) { + if (view.markCursor) { + var dom = document.createElement("img"); + dom.className = "ProseMirror-separator"; + dom.setAttribute("mark-placeholder", "true"); + dom.setAttribute("alt", ""); + view.cursorWrapper = { + dom: dom, + deco: Decoration.widget(view.state.selection.from, dom, { + raw: true, + marks: view.markCursor + }) + }; + } else { + view.cursorWrapper = null; + } +} +function getEditable(view) { + return !view.someProp("editable", function (value) { + return value(view.state) === false; + }); +} +function selectionContextChanged(sel1, sel2) { + var depth = Math.min(sel1.$anchor.sharedDepth(sel1.head), sel2.$anchor.sharedDepth(sel2.head)); + return sel1.$anchor.start(depth) != sel2.$anchor.start(depth); +} +function buildNodeViews(view) { + var result = Object.create(null); + function add(obj) { + for (var _prop3 in obj) if (!Object.prototype.hasOwnProperty.call(result, _prop3)) result[_prop3] = obj[_prop3]; + } + view.someProp("nodeViews", add); + view.someProp("markViews", add); + return result; +} +function changedNodeViews(a, b) { + var nA = 0, + nB = 0; + for (var _prop4 in a) { + if (a[_prop4] != b[_prop4]) return true; + nA++; + } + for (var _ in b) nB++; + return nA != nB; +} +function checkStateComponent(plugin) { + if (plugin.spec.state || plugin.spec.filterTransaction || plugin.spec.appendTransaction) throw new RangeError("Plugins passed directly to the view must not have a state component"); +} +exports.Decoration = Decoration; +exports.DecorationSet = DecorationSet; +exports.EditorView = EditorView; +exports.__endComposition = __endComposition; +exports.__parseFromClipboard = __parseFromClipboard; +exports.__serializeForClipboard = __serializeForClipboard; + +}); +define("linkify-it",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var uc_micro = require('uc.micro'); + +function reFactory (opts) { + const re = {}; + opts = opts || {}; + + re.src_Any = uc_micro.Any.source; + re.src_Cc = uc_micro.Cc.source; + re.src_Z = uc_micro.Z.source; + re.src_P = uc_micro.P.source; + + // \p{\Z\P\Cc\CF} (white spaces + control + format + punctuation) + re.src_ZPCc = [re.src_Z, re.src_P, re.src_Cc].join('|'); + + // \p{\Z\Cc} (white spaces + control) + re.src_ZCc = [re.src_Z, re.src_Cc].join('|'); + + // Experimental. List of chars, completely prohibited in links + // because can separate it from other part of text + const text_separators = '[><\uff5c]'; + + // All possible word characters (everything without punctuation, spaces & controls) + // Defined via punctuation & spaces to save space + // Should be something like \p{\L\N\S\M} (\w but without `_`) + re.src_pseudo_letter = '(?:(?!' + text_separators + '|' + re.src_ZPCc + ')' + re.src_Any + ')'; + // The same as abothe but without [0-9] + // var src_pseudo_letter_non_d = '(?:(?![0-9]|' + src_ZPCc + ')' + src_Any + ')'; + + re.src_ip4 = + + '(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; + + // Prohibit any of "@/[]()" in user/pass to avoid wrong domain fetch. + re.src_auth = '(?:(?:(?!' + re.src_ZCc + '|[@/\\[\\]()]).)+@)?'; + + re.src_port = + + '(?::(?:6(?:[0-4]\\d{3}|5(?:[0-4]\\d{2}|5(?:[0-2]\\d|3[0-5])))|[1-5]?\\d{1,4}))?'; + + re.src_host_terminator = + + '(?=$|' + text_separators + '|' + re.src_ZPCc + ')' + + '(?!' + (opts['---'] ? '-(?!--)|' : '-|') + '_|:\\d|\\.-|\\.(?!$|' + re.src_ZPCc + '))'; + + re.src_path = + + '(?:' + + '[/?#]' + + '(?:' + + '(?!' + re.src_ZCc + '|' + text_separators + '|[()[\\]{}.,"\'?!\\-;]).|' + + '\\[(?:(?!' + re.src_ZCc + '|\\]).)*\\]|' + + '\\((?:(?!' + re.src_ZCc + '|[)]).)*\\)|' + + '\\{(?:(?!' + re.src_ZCc + '|[}]).)*\\}|' + + '\\"(?:(?!' + re.src_ZCc + '|["]).)+\\"|' + + "\\'(?:(?!" + re.src_ZCc + "|[']).)+\\'|" + + + // allow `I'm_king` if no pair found + "\\'(?=" + re.src_pseudo_letter + '|[-])|' + + + // google has many dots in "google search" links (#66, #81). + // github has ... in commit range links, + // Restrict to + // - english + // - percent-encoded + // - parts of file path + // - params separator + // until more examples found. + '\\.{2,}[a-zA-Z0-9%/&]|' + + + '\\.(?!' + re.src_ZCc + '|[.]|$)|' + + (opts['---'] + ? '\\-(?!--(?:[^-]|$))(?:-*)|' // `---` => long dash, terminate + : '\\-+|' + ) + + // allow `,,,` in paths + ',(?!' + re.src_ZCc + '|$)|' + + + // allow `;` if not followed by space-like char + ';(?!' + re.src_ZCc + '|$)|' + + + // allow `!!!` in paths, but not at the end + '\\!+(?!' + re.src_ZCc + '|[!]|$)|' + + + '\\?(?!' + re.src_ZCc + '|[?]|$)' + + ')+' + + '|\\/' + + ')?'; + + // Allow anything in markdown spec, forbid quote (") at the first position + // because emails enclosed in quotes are far more common + re.src_email_name = + + '[\\-;:&=\\+\\$,\\.a-zA-Z0-9_][\\-;:&=\\+\\$,\\"\\.a-zA-Z0-9_]*'; + + re.src_xn = + + 'xn--[a-z0-9\\-]{1,59}'; + + // More to read about domain names + // http://serverfault.com/questions/638260/ + + re.src_domain_root = + + // Allow letters & digits (http://test1) + '(?:' + + re.src_xn + + '|' + + re.src_pseudo_letter + '{1,63}' + + ')'; + + re.src_domain = + + '(?:' + + re.src_xn + + '|' + + '(?:' + re.src_pseudo_letter + ')' + + '|' + + '(?:' + re.src_pseudo_letter + '(?:-|' + re.src_pseudo_letter + '){0,61}' + re.src_pseudo_letter + ')' + + ')'; + + re.src_host = + + '(?:' + + // Don't need IP check, because digits are already allowed in normal domain names + // src_ip4 + + // '|' + + '(?:(?:(?:' + re.src_domain + ')\\.)*' + re.src_domain/* _root */ + ')' + + ')'; + + re.tpl_host_fuzzy = + + '(?:' + + re.src_ip4 + + '|' + + '(?:(?:(?:' + re.src_domain + ')\\.)+(?:%TLDS%))' + + ')'; + + re.tpl_host_no_ip_fuzzy = + + '(?:(?:(?:' + re.src_domain + ')\\.)+(?:%TLDS%))'; + + re.src_host_strict = + + re.src_host + re.src_host_terminator; + + re.tpl_host_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_host_terminator; + + re.src_host_port_strict = + + re.src_host + re.src_port + re.src_host_terminator; + + re.tpl_host_port_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_port + re.src_host_terminator; + + re.tpl_host_port_no_ip_fuzzy_strict = + + re.tpl_host_no_ip_fuzzy + re.src_port + re.src_host_terminator; + + // + // Main rules + // + + // Rude test fuzzy links by host, for quick deny + re.tpl_host_fuzzy_test = + + 'localhost|www\\.|\\.\\d{1,3}\\.|(?:\\.(?:%TLDS%)(?:' + re.src_ZPCc + '|>|$))'; + + re.tpl_email_fuzzy = + + '(^|' + text_separators + '|"|\\(|' + re.src_ZCc + ')' + + '(' + re.src_email_name + '@' + re.tpl_host_fuzzy_strict + ')'; + + re.tpl_link_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + re.src_ZPCc + '))' + + '((?![$+<=>^`|\uff5c])' + re.tpl_host_port_fuzzy_strict + re.src_path + ')'; + + re.tpl_link_no_ip_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + re.src_ZPCc + '))' + + '((?![$+<=>^`|\uff5c])' + re.tpl_host_port_no_ip_fuzzy_strict + re.src_path + ')'; + + return re +} + +// +// Helpers +// + +// Merge objects +// +function assign (obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1); + + sources.forEach(function (source) { + if (!source) { return } + + Object.keys(source).forEach(function (key) { + obj[key] = source[key]; + }); + }); + + return obj +} + +function _class (obj) { return Object.prototype.toString.call(obj) } +function isString (obj) { return _class(obj) === '[object String]' } +function isObject (obj) { return _class(obj) === '[object Object]' } +function isRegExp (obj) { return _class(obj) === '[object RegExp]' } +function isFunction (obj) { return _class(obj) === '[object Function]' } + +function escapeRE (str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&') } + +// + +const defaultOptions = { + fuzzyLink: true, + fuzzyEmail: true, + fuzzyIP: false +}; + +function isOptionsObj (obj) { + return Object.keys(obj || {}).reduce(function (acc, k) { + /* eslint-disable-next-line no-prototype-builtins */ + return acc || defaultOptions.hasOwnProperty(k) + }, false) +} + +const defaultSchemas = { + 'http:': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.http = new RegExp( + '^\\/\\/' + self.re.src_auth + self.re.src_host_port_strict + self.re.src_path, 'i' + ); + } + if (self.re.http.test(tail)) { + return tail.match(self.re.http)[0].length + } + return 0 + } + }, + 'https:': 'http:', + 'ftp:': 'http:', + '//': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.no_http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.no_http = new RegExp( + '^' + + self.re.src_auth + + // Don't allow single-level domains, because of false positives like '//test' + // with code comments + '(?:localhost|(?:(?:' + self.re.src_domain + ')\\.)+' + self.re.src_domain_root + ')' + + self.re.src_port + + self.re.src_host_terminator + + self.re.src_path, + + 'i' + ); + } + + if (self.re.no_http.test(tail)) { + // should not be `://` & `///`, that protects from errors in protocol name + if (pos >= 3 && text[pos - 3] === ':') { return 0 } + if (pos >= 3 && text[pos - 3] === '/') { return 0 } + return tail.match(self.re.no_http)[0].length + } + return 0 + } + }, + 'mailto:': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.mailto) { + self.re.mailto = new RegExp( + '^' + self.re.src_email_name + '@' + self.re.src_host_strict, 'i' + ); + } + if (self.re.mailto.test(tail)) { + return tail.match(self.re.mailto)[0].length + } + return 0 + } + } +}; + +// RE pattern for 2-character tlds (autogenerated by ./support/tlds_2char_gen.js) +/* eslint-disable-next-line max-len */ +const tlds_2ch_src_re = 'a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]'; + +// DON'T try to make PRs with changes. Extend TLDs with LinkifyIt.tlds() instead +const tlds_default = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|'); + +function resetScanCache (self) { + self.__index__ = -1; + self.__text_cache__ = ''; +} + +function createValidator (re) { + return function (text, pos) { + const tail = text.slice(pos); + + if (re.test(tail)) { + return tail.match(re)[0].length + } + return 0 + } +} + +function createNormalizer () { + return function (match, self) { + self.normalize(match); + } +} + +// Schemas compiler. Build regexps. +// +function compile (self) { + // Load & clone RE patterns. + const re = self.re = reFactory(self.__opts__); + + // Define dynamic patterns + const tlds = self.__tlds__.slice(); + + self.onCompile(); + + if (!self.__tlds_replaced__) { + tlds.push(tlds_2ch_src_re); + } + tlds.push(re.src_xn); + + re.src_tlds = tlds.join('|'); + + function untpl (tpl) { return tpl.replace('%TLDS%', re.src_tlds) } + + re.email_fuzzy = RegExp(untpl(re.tpl_email_fuzzy), 'i'); + re.link_fuzzy = RegExp(untpl(re.tpl_link_fuzzy), 'i'); + re.link_no_ip_fuzzy = RegExp(untpl(re.tpl_link_no_ip_fuzzy), 'i'); + re.host_fuzzy_test = RegExp(untpl(re.tpl_host_fuzzy_test), 'i'); + + // + // Compile each schema + // + + const aliases = []; + + self.__compiled__ = {}; // Reset compiled data + + function schemaError (name, val) { + throw new Error('(LinkifyIt) Invalid schema "' + name + '": ' + val) + } + + Object.keys(self.__schemas__).forEach(function (name) { + const val = self.__schemas__[name]; + + // skip disabled methods + if (val === null) { return } + + const compiled = { validate: null, link: null }; + + self.__compiled__[name] = compiled; + + if (isObject(val)) { + if (isRegExp(val.validate)) { + compiled.validate = createValidator(val.validate); + } else if (isFunction(val.validate)) { + compiled.validate = val.validate; + } else { + schemaError(name, val); + } + + if (isFunction(val.normalize)) { + compiled.normalize = val.normalize; + } else if (!val.normalize) { + compiled.normalize = createNormalizer(); + } else { + schemaError(name, val); + } + + return + } + + if (isString(val)) { + aliases.push(name); + return + } + + schemaError(name, val); + }); + + // + // Compile postponed aliases + // + + aliases.forEach(function (alias) { + if (!self.__compiled__[self.__schemas__[alias]]) { + // Silently fail on missed schemas to avoid errons on disable. + // schemaError(alias, self.__schemas__[alias]); + return + } + + self.__compiled__[alias].validate = + self.__compiled__[self.__schemas__[alias]].validate; + self.__compiled__[alias].normalize = + self.__compiled__[self.__schemas__[alias]].normalize; + }); + + // + // Fake record for guessed links + // + self.__compiled__[''] = { validate: null, normalize: createNormalizer() }; + + // + // Build schema condition + // + const slist = Object.keys(self.__compiled__) + .filter(function (name) { + // Filter disabled & fake schemas + return name.length > 0 && self.__compiled__[name] + }) + .map(escapeRE) + .join('|'); + // (?!_) cause 1.5x slowdown + self.re.schema_test = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'i'); + self.re.schema_search = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'ig'); + self.re.schema_at_start = RegExp('^' + self.re.schema_search.source, 'i'); + + self.re.pretest = RegExp( + '(' + self.re.schema_test.source + ')|(' + self.re.host_fuzzy_test.source + ')|@', + 'i' + ); + + // + // Cleanup + // + + resetScanCache(self); +} + +/** + * class Match + * + * Match result. Single element of array, returned by [[LinkifyIt#match]] + **/ +function Match (self, shift) { + const start = self.__index__; + const end = self.__last_index__; + const text = self.__text_cache__.slice(start, end); + + /** + * Match#schema -> String + * + * Prefix (protocol) for matched string. + **/ + this.schema = self.__schema__.toLowerCase(); + /** + * Match#index -> Number + * + * First position of matched string. + **/ + this.index = start + shift; + /** + * Match#lastIndex -> Number + * + * Next position after matched string. + **/ + this.lastIndex = end + shift; + /** + * Match#raw -> String + * + * Matched string. + **/ + this.raw = text; + /** + * Match#text -> String + * + * Notmalized text of matched string. + **/ + this.text = text; + /** + * Match#url -> String + * + * Normalized url of matched string. + **/ + this.url = text; +} + +function createMatch (self, shift) { + const match = new Match(self, shift); + + self.__compiled__[match.schema].normalize(match, self); + + return match +} + +/** + * class LinkifyIt + **/ + +/** + * new LinkifyIt(schemas, options) + * - schemas (Object): Optional. Additional schemas to validate (prefix/validator) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Creates new linkifier instance with optional additional schemas. + * Can be called without `new` keyword for convenience. + * + * By default understands: + * + * - `http(s)://...` , `ftp://...`, `mailto:...` & `//...` links + * - "fuzzy" links and emails (example.com, foo@bar.com). + * + * `schemas` is an object, where each key/value describes protocol/rule: + * + * - __key__ - link prefix (usually, protocol name with `:` at the end, `skype:` + * for example). `linkify-it` makes shure that prefix is not preceeded with + * alphanumeric char and symbols. Only whitespaces and punctuation allowed. + * - __value__ - rule to check tail after link prefix + * - _String_ - just alias to existing rule + * - _Object_ + * - _validate_ - validator function (should return matched length on success), + * or `RegExp`. + * - _normalize_ - optional function to normalize text & url of matched result + * (for example, for @twitter mentions). + * + * `options`: + * + * - __fuzzyLink__ - recognige URL-s without `http(s):` prefix. Default `true`. + * - __fuzzyIP__ - allow IPs in fuzzy links above. Can conflict with some texts + * like version numbers. Default `false`. + * - __fuzzyEmail__ - recognize emails without `mailto:` prefix. + * + **/ +function LinkifyIt (schemas, options) { + if (!(this instanceof LinkifyIt)) { + return new LinkifyIt(schemas, options) + } + + if (!options) { + if (isOptionsObj(schemas)) { + options = schemas; + schemas = {}; + } + } + + this.__opts__ = assign({}, defaultOptions, options); + + // Cache last tested result. Used to skip repeating steps on next `match` call. + this.__index__ = -1; + this.__last_index__ = -1; // Next scan position + this.__schema__ = ''; + this.__text_cache__ = ''; + + this.__schemas__ = assign({}, defaultSchemas, schemas); + this.__compiled__ = {}; + + this.__tlds__ = tlds_default; + this.__tlds_replaced__ = false; + + this.re = {}; + + compile(this); +} + +/** chainable + * LinkifyIt#add(schema, definition) + * - schema (String): rule name (fixed pattern prefix) + * - definition (String|RegExp|Object): schema definition + * + * Add new rule definition. See constructor description for details. + **/ +LinkifyIt.prototype.add = function add (schema, definition) { + this.__schemas__[schema] = definition; + compile(this); + return this +}; + +/** chainable + * LinkifyIt#set(options) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Set recognition options for links without schema. + **/ +LinkifyIt.prototype.set = function set (options) { + this.__opts__ = assign(this.__opts__, options); + return this +}; + +/** + * LinkifyIt#test(text) -> Boolean + * + * Searches linkifiable pattern and returns `true` on success or `false` on fail. + **/ +LinkifyIt.prototype.test = function test (text) { + // Reset scan cache + this.__text_cache__ = text; + this.__index__ = -1; + + if (!text.length) { return false } + + let m, ml, me, len, shift, next, re, tld_pos, at_pos; + + // try to scan for link with schema - that's the most simple rule + if (this.re.schema_test.test(text)) { + re = this.re.schema_search; + re.lastIndex = 0; + while ((m = re.exec(text)) !== null) { + len = this.testSchemaAt(text, m[2], re.lastIndex); + if (len) { + this.__schema__ = m[2]; + this.__index__ = m.index + m[1].length; + this.__last_index__ = m.index + m[0].length + len; + break + } + } + } + + if (this.__opts__.fuzzyLink && this.__compiled__['http:']) { + // guess schemaless links + tld_pos = text.search(this.re.host_fuzzy_test); + if (tld_pos >= 0) { + // if tld is located after found link - no need to check fuzzy pattern + if (this.__index__ < 0 || tld_pos < this.__index__) { + if ((ml = text.match(this.__opts__.fuzzyIP ? this.re.link_fuzzy : this.re.link_no_ip_fuzzy)) !== null) { + shift = ml.index + ml[1].length; + + if (this.__index__ < 0 || shift < this.__index__) { + this.__schema__ = ''; + this.__index__ = shift; + this.__last_index__ = ml.index + ml[0].length; + } + } + } + } + } + + if (this.__opts__.fuzzyEmail && this.__compiled__['mailto:']) { + // guess schemaless emails + at_pos = text.indexOf('@'); + if (at_pos >= 0) { + // We can't skip this check, because this cases are possible: + // 192.168.1.1@gmail.com, my.in@example.com + if ((me = text.match(this.re.email_fuzzy)) !== null) { + shift = me.index + me[1].length; + next = me.index + me[0].length; + + if (this.__index__ < 0 || shift < this.__index__ || + (shift === this.__index__ && next > this.__last_index__)) { + this.__schema__ = 'mailto:'; + this.__index__ = shift; + this.__last_index__ = next; + } + } + } + } + + return this.__index__ >= 0 +}; + +/** + * LinkifyIt#pretest(text) -> Boolean + * + * Very quick check, that can give false positives. Returns true if link MAY BE + * can exists. Can be used for speed optimization, when you need to check that + * link NOT exists. + **/ +LinkifyIt.prototype.pretest = function pretest (text) { + return this.re.pretest.test(text) +}; + +/** + * LinkifyIt#testSchemaAt(text, name, position) -> Number + * - text (String): text to scan + * - name (String): rule (schema) name + * - position (Number): text offset to check from + * + * Similar to [[LinkifyIt#test]] but checks only specific protocol tail exactly + * at given position. Returns length of found pattern (0 on fail). + **/ +LinkifyIt.prototype.testSchemaAt = function testSchemaAt (text, schema, pos) { + // If not supported schema check requested - terminate + if (!this.__compiled__[schema.toLowerCase()]) { + return 0 + } + return this.__compiled__[schema.toLowerCase()].validate(text, pos, this) +}; + +/** + * LinkifyIt#match(text) -> Array|null + * + * Returns array of found link descriptions or `null` on fail. We strongly + * recommend to use [[LinkifyIt#test]] first, for best speed. + * + * ##### Result match description + * + * - __schema__ - link schema, can be empty for fuzzy links, or `//` for + * protocol-neutral links. + * - __index__ - offset of matched text + * - __lastIndex__ - index of next char after mathch end + * - __raw__ - matched text + * - __text__ - normalized text + * - __url__ - link, generated from matched text + **/ +LinkifyIt.prototype.match = function match (text) { + const result = []; + let shift = 0; + + // Try to take previous element from cache, if .test() called before + if (this.__index__ >= 0 && this.__text_cache__ === text) { + result.push(createMatch(this, shift)); + shift = this.__last_index__; + } + + // Cut head if cache was used + let tail = shift ? text.slice(shift) : text; + + // Scan string until end reached + while (this.test(tail)) { + result.push(createMatch(this, shift)); + + tail = tail.slice(this.__last_index__); + shift += this.__last_index__; + } + + if (result.length) { + return result + } + + return null +}; + +/** + * LinkifyIt#matchAtStart(text) -> Match|null + * + * Returns fully-formed (not fuzzy) link if it starts at the beginning + * of the string, and null otherwise. + **/ +LinkifyIt.prototype.matchAtStart = function matchAtStart (text) { + // Reset scan cache + this.__text_cache__ = text; + this.__index__ = -1; + + if (!text.length) return null + + const m = this.re.schema_at_start.exec(text); + if (!m) return null + + const len = this.testSchemaAt(text, m[2], m[0].length); + if (!len) return null + + this.__schema__ = m[2]; + this.__index__ = m.index + m[1].length; + this.__last_index__ = m.index + m[0].length + len; + + return createMatch(this, 0) +}; + +/** chainable + * LinkifyIt#tlds(list [, keepOld]) -> this + * - list (Array): list of tlds + * - keepOld (Boolean): merge with current list if `true` (`false` by default) + * + * Load (or merge) new tlds list. Those are user for fuzzy links (without prefix) + * to avoid false positives. By default this algorythm used: + * + * - hostname with any 2-letter root zones are ok. + * - biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф + * are ok. + * - encoded (`xn--...`) root zones are ok. + * + * If list is replaced, then exact match for 2-chars root zones will be checked. + **/ +LinkifyIt.prototype.tlds = function tlds (list, keepOld) { + list = Array.isArray(list) ? list : [list]; + + if (!keepOld) { + this.__tlds__ = list.slice(); + this.__tlds_replaced__ = true; + compile(this); + return this + } + + this.__tlds__ = this.__tlds__.concat(list) + .sort() + .filter(function (el, idx, arr) { + return el !== arr[idx - 1] + }) + .reverse(); + + compile(this); + return this +}; + +/** + * LinkifyIt#normalize(match) + * + * Default normalizer (if schema does not define it's own). + **/ +LinkifyIt.prototype.normalize = function normalize (match) { + // Do minimal possible changes by default. Need to collect feedback prior + // to move forward https://github.com/markdown-it/linkify-it/issues/1 + + if (!match.schema) { match.url = 'http://' + match.url; } + + if (match.schema === 'mailto:' && !/^mailto:/i.test(match.url)) { + match.url = 'mailto:' + match.url; + } +}; + +/** + * LinkifyIt#onCompile() + * + * Override to modify basic RegExp-s. + **/ +LinkifyIt.prototype.onCompile = function onCompile () { +}; + +module.exports = LinkifyIt; + +}); +define("markdown-it",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var mdurl = require('mdurl'); +var ucmicro = require('uc.micro'); +var entities = require('entities'); +var LinkifyIt = require('linkify-it'); +var punycode = require('punycode.js'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var mdurl__namespace = /*#__PURE__*/_interopNamespaceDefault(mdurl); +var ucmicro__namespace = /*#__PURE__*/_interopNamespaceDefault(ucmicro); + +// Utilities +// + +function _class(obj) { + return Object.prototype.toString.call(obj); +} +function isString(obj) { + return _class(obj) === '[object String]'; +} +const _hasOwnProperty = Object.prototype.hasOwnProperty; +function has(object, key) { + return _hasOwnProperty.call(object, key); +} + +// Merge objects +// +function assign(obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1); + sources.forEach(function (source) { + if (!source) { + return; + } + if (typeof source !== 'object') { + throw new TypeError(source + 'must be object'); + } + Object.keys(source).forEach(function (key) { + obj[key] = source[key]; + }); + }); + return obj; +} + +// Remove element from array and put another array at those position. +// Useful for some operations with tokens +function arrayReplaceAt(src, pos, newElements) { + return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)); +} +function isValidEntityCode(c) { + /* eslint no-bitwise:0 */ + // broken sequence + if (c >= 0xD800 && c <= 0xDFFF) { + return false; + } + // never used + if (c >= 0xFDD0 && c <= 0xFDEF) { + return false; + } + if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { + return false; + } + // control codes + if (c >= 0x00 && c <= 0x08) { + return false; + } + if (c === 0x0B) { + return false; + } + if (c >= 0x0E && c <= 0x1F) { + return false; + } + if (c >= 0x7F && c <= 0x9F) { + return false; + } + // out of range + if (c > 0x10FFFF) { + return false; + } + return true; +} +function fromCodePoint(c) { + /* eslint no-bitwise:0 */ + if (c > 0xffff) { + c -= 0x10000; + const surrogate1 = 0xd800 + (c >> 10); + const surrogate2 = 0xdc00 + (c & 0x3ff); + return String.fromCharCode(surrogate1, surrogate2); + } + return String.fromCharCode(c); +} +const UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g; +const ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; +const UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi'); +const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i; +function replaceEntityPattern(match, name) { + if (name.charCodeAt(0) === 0x23 /* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { + const code = name[1].toLowerCase() === 'x' ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10); + if (isValidEntityCode(code)) { + return fromCodePoint(code); + } + return match; + } + const decoded = entities.decodeHTML(match); + if (decoded !== match) { + return decoded; + } + return match; +} + +/* function replaceEntities(str) { + if (str.indexOf('&') < 0) { return str; } + + return str.replace(ENTITY_RE, replaceEntityPattern); +} */ + +function unescapeMd(str) { + if (str.indexOf('\\') < 0) { + return str; + } + return str.replace(UNESCAPE_MD_RE, '$1'); +} +function unescapeAll(str) { + if (str.indexOf('\\') < 0 && str.indexOf('&') < 0) { + return str; + } + return str.replace(UNESCAPE_ALL_RE, function (match, escaped, entity) { + if (escaped) { + return escaped; + } + return replaceEntityPattern(match, entity); + }); +} +const HTML_ESCAPE_TEST_RE = /[&<>"]/; +const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; +const HTML_REPLACEMENTS = { + '&': '&', + '<': '<', + '>': '>', + '"': '"' +}; +function replaceUnsafeChar(ch) { + return HTML_REPLACEMENTS[ch]; +} +function escapeHtml(str) { + if (HTML_ESCAPE_TEST_RE.test(str)) { + return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); + } + return str; +} +const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g; +function escapeRE(str) { + return str.replace(REGEXP_ESCAPE_RE, '\\$&'); +} +function isSpace(code) { + switch (code) { + case 0x09: + case 0x20: + return true; + } + return false; +} + +// Zs (unicode class) || [\t\f\v\r\n] +function isWhiteSpace(code) { + if (code >= 0x2000 && code <= 0x200A) { + return true; + } + switch (code) { + case 0x09: // \t + case 0x0A: // \n + case 0x0B: // \v + case 0x0C: // \f + case 0x0D: // \r + case 0x20: + case 0xA0: + case 0x1680: + case 0x202F: + case 0x205F: + case 0x3000: + return true; + } + return false; +} + +/* eslint-disable max-len */ + +// Currently without astral characters support. +function isPunctChar(ch) { + return ucmicro__namespace.P.test(ch) || ucmicro__namespace.S.test(ch); +} + +// Markdown ASCII punctuation characters. +// +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +// +// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range. +// +function isMdAsciiPunct(ch) { + switch (ch) { + case 0x21 /* ! */: + case 0x22 /* " */: + case 0x23 /* # */: + case 0x24 /* $ */: + case 0x25 /* % */: + case 0x26 /* & */: + case 0x27 /* ' */: + case 0x28 /* ( */: + case 0x29 /* ) */: + case 0x2A /* * */: + case 0x2B /* + */: + case 0x2C /* , */: + case 0x2D /* - */: + case 0x2E /* . */: + case 0x2F /* / */: + case 0x3A /* : */: + case 0x3B /* ; */: + case 0x3C /* < */: + case 0x3D /* = */: + case 0x3E /* > */: + case 0x3F /* ? */: + case 0x40 /* @ */: + case 0x5B /* [ */: + case 0x5C /* \ */: + case 0x5D /* ] */: + case 0x5E /* ^ */: + case 0x5F /* _ */: + case 0x60 /* ` */: + case 0x7B /* { */: + case 0x7C /* | */: + case 0x7D /* } */: + case 0x7E /* ~ */: + return true; + default: + return false; + } +} + +// Hepler to unify [reference labels]. +// +function normalizeReference(str) { + // Trim and collapse whitespace + // + str = str.trim().replace(/\s+/g, ' '); + + // In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug + // fixed in v12 (couldn't find any details). + // + // So treat this one as a special case + // (remove this when node v10 is no longer supported). + // + if ('ẞ'.toLowerCase() === 'Ṿ') { + str = str.replace(/ẞ/g, 'ß'); + } + + // .toLowerCase().toUpperCase() should get rid of all differences + // between letter variants. + // + // Simple .toLowerCase() doesn't normalize 125 code points correctly, + // and .toUpperCase doesn't normalize 6 of them (list of exceptions: + // İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently + // uppercased versions). + // + // Here's an example showing how it happens. Lets take greek letter omega: + // uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ) + // + // Unicode entries: + // 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8; + // 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398 + // 03D1;GREEK THETA SYMBOL;Ll;0;L; 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398 + // 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L; 0398;;;;N;;;;03B8; + // + // Case-insensitive comparison should treat all of them as equivalent. + // + // But .toLowerCase() doesn't change ϑ (it's already lowercase), + // and .toUpperCase() doesn't change ϴ (already uppercase). + // + // Applying first lower then upper case normalizes any character: + // '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398' + // + // Note: this is equivalent to unicode case folding; unicode normalization + // is a different step that is not required here. + // + // Final result should be uppercased, because it's later stored in an object + // (this avoid a conflict with Object.prototype members, + // most notably, `__proto__`) + // + return str.toLowerCase().toUpperCase(); +} + +// Re-export libraries commonly used in both markdown-it and its plugins, +// so plugins won't have to depend on them explicitly, which reduces their +// bundled size (e.g. a browser build). +// +const lib = { + mdurl: mdurl__namespace, + ucmicro: ucmicro__namespace +}; + +var utils = /*#__PURE__*/Object.freeze({ + __proto__: null, + arrayReplaceAt: arrayReplaceAt, + assign: assign, + escapeHtml: escapeHtml, + escapeRE: escapeRE, + fromCodePoint: fromCodePoint, + has: has, + isMdAsciiPunct: isMdAsciiPunct, + isPunctChar: isPunctChar, + isSpace: isSpace, + isString: isString, + isValidEntityCode: isValidEntityCode, + isWhiteSpace: isWhiteSpace, + lib: lib, + normalizeReference: normalizeReference, + unescapeAll: unescapeAll, + unescapeMd: unescapeMd +}); + +// Parse link label +// +// this function assumes that first character ("[") already matches; +// returns the end of the label +// + +function parseLinkLabel(state, start, disableNested) { + let level, found, marker, prevPos; + const max = state.posMax; + const oldPos = state.pos; + state.pos = start + 1; + level = 1; + while (state.pos < max) { + marker = state.src.charCodeAt(state.pos); + if (marker === 0x5D /* ] */) { + level--; + if (level === 0) { + found = true; + break; + } + } + prevPos = state.pos; + state.md.inline.skipToken(state); + if (marker === 0x5B /* [ */) { + if (prevPos === state.pos - 1) { + // increase level if we find text `[`, which is not a part of any token + level++; + } else if (disableNested) { + state.pos = oldPos; + return -1; + } + } + } + let labelEnd = -1; + if (found) { + labelEnd = state.pos; + } + + // restore old state + state.pos = oldPos; + return labelEnd; +} + +// Parse link destination +// + +function parseLinkDestination(str, start, max) { + let code; + let pos = start; + const result = { + ok: false, + pos: 0, + str: '' + }; + if (str.charCodeAt(pos) === 0x3C /* < */) { + pos++; + while (pos < max) { + code = str.charCodeAt(pos); + if (code === 0x0A /* \n */) { + return result; + } + if (code === 0x3C /* < */) { + return result; + } + if (code === 0x3E /* > */) { + result.pos = pos + 1; + result.str = unescapeAll(str.slice(start + 1, pos)); + result.ok = true; + return result; + } + if (code === 0x5C /* \ */ && pos + 1 < max) { + pos += 2; + continue; + } + pos++; + } + + // no closing '>' + return result; + } + + // this should be ... } else { ... branch + + let level = 0; + while (pos < max) { + code = str.charCodeAt(pos); + if (code === 0x20) { + break; + } + + // ascii control characters + if (code < 0x20 || code === 0x7F) { + break; + } + if (code === 0x5C /* \ */ && pos + 1 < max) { + if (str.charCodeAt(pos + 1) === 0x20) { + break; + } + pos += 2; + continue; + } + if (code === 0x28 /* ( */) { + level++; + if (level > 32) { + return result; + } + } + if (code === 0x29 /* ) */) { + if (level === 0) { + break; + } + level--; + } + pos++; + } + if (start === pos) { + return result; + } + if (level !== 0) { + return result; + } + result.str = unescapeAll(str.slice(start, pos)); + result.pos = pos; + result.ok = true; + return result; +} + +// Parse link title +// + + +// Parse link title within `str` in [start, max] range, +// or continue previous parsing if `prev_state` is defined (equal to result of last execution). +// +function parseLinkTitle(str, start, max, prev_state) { + let code; + let pos = start; + const state = { + // if `true`, this is a valid link title + ok: false, + // if `true`, this link can be continued on the next line + can_continue: false, + // if `ok`, it's the position of the first character after the closing marker + pos: 0, + // if `ok`, it's the unescaped title + str: '', + // expected closing marker character code + marker: 0 + }; + if (prev_state) { + // this is a continuation of a previous parseLinkTitle call on the next line, + // used in reference links only + state.str = prev_state.str; + state.marker = prev_state.marker; + } else { + if (pos >= max) { + return state; + } + let marker = str.charCodeAt(pos); + if (marker !== 0x22 /* " */ && marker !== 0x27 /* ' */ && marker !== 0x28 /* ( */) { + return state; + } + start++; + pos++; + + // if opening marker is "(", switch it to closing marker ")" + if (marker === 0x28) { + marker = 0x29; + } + state.marker = marker; + } + while (pos < max) { + code = str.charCodeAt(pos); + if (code === state.marker) { + state.pos = pos + 1; + state.str += unescapeAll(str.slice(start, pos)); + state.ok = true; + return state; + } else if (code === 0x28 /* ( */ && state.marker === 0x29 /* ) */) { + return state; + } else if (code === 0x5C /* \ */ && pos + 1 < max) { + pos++; + } + pos++; + } + + // no closing marker found, but this link title may continue on the next line (for references) + state.can_continue = true; + state.str += unescapeAll(str.slice(start, pos)); + return state; +} + +// Just a shortcut for bulk export + +var helpers = /*#__PURE__*/Object.freeze({ + __proto__: null, + parseLinkDestination: parseLinkDestination, + parseLinkLabel: parseLinkLabel, + parseLinkTitle: parseLinkTitle +}); + +/** + * class Renderer + * + * Generates HTML from parsed token stream. Each instance has independent + * copy of rules. Those can be rewritten with ease. Also, you can add new + * rules if you create plugin and adds new token types. + **/ + +const default_rules = {}; +default_rules.code_inline = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + return '' + escapeHtml(token.content) + ''; +}; +default_rules.code_block = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + return '' + escapeHtml(tokens[idx].content) + '\n'; +}; +default_rules.fence = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + const info = token.info ? unescapeAll(token.info).trim() : ''; + let langName = ''; + let langAttrs = ''; + if (info) { + const arr = info.split(/(\s+)/g); + langName = arr[0]; + langAttrs = arr.slice(2).join(''); + } + let highlighted; + if (options.highlight) { + highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content); + } else { + highlighted = escapeHtml(token.content); + } + if (highlighted.indexOf('${highlighted}\n`; + } + return `
${highlighted}
\n`; +}; +default_rules.image = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + + // "alt" attr MUST be set, even if empty. Because it's mandatory and + // should be placed on proper position for tests. + // + // Replace content with actual value + + token.attrs[token.attrIndex('alt')][1] = slf.renderInlineAsText(token.children, options, env); + return slf.renderToken(tokens, idx, options); +}; +default_rules.hardbreak = function (tokens, idx, options /*, env */) { + return options.xhtmlOut ? '
\n' : '
\n'; +}; +default_rules.softbreak = function (tokens, idx, options /*, env */) { + return options.breaks ? options.xhtmlOut ? '
\n' : '
\n' : '\n'; +}; +default_rules.text = function (tokens, idx /*, options, env */) { + return escapeHtml(tokens[idx].content); +}; +default_rules.html_block = function (tokens, idx /*, options, env */) { + return tokens[idx].content; +}; +default_rules.html_inline = function (tokens, idx /*, options, env */) { + return tokens[idx].content; +}; + +/** + * new Renderer() + * + * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults. + **/ +function Renderer() { + /** + * Renderer#rules -> Object + * + * Contains render rules for tokens. Can be updated and extended. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.renderer.rules.strong_open = function () { return ''; }; + * md.renderer.rules.strong_close = function () { return ''; }; + * + * var result = md.renderInline(...); + * ``` + * + * Each rule is called as independent static function with fixed signature: + * + * ```javascript + * function my_token_render(tokens, idx, options, env, renderer) { + * // ... + * return renderedHTML; + * } + * ``` + * + * See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs) + * for more details and examples. + **/ + this.rules = assign({}, default_rules); +} + +/** + * Renderer.renderAttrs(token) -> String + * + * Render token attributes to string. + **/ +Renderer.prototype.renderAttrs = function renderAttrs(token) { + let i, l, result; + if (!token.attrs) { + return ''; + } + result = ''; + for (i = 0, l = token.attrs.length; i < l; i++) { + result += ' ' + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"'; + } + return result; +}; + +/** + * Renderer.renderToken(tokens, idx, options) -> String + * - tokens (Array): list of tokens + * - idx (Numbed): token index to render + * - options (Object): params of parser instance + * + * Default token renderer. Can be overriden by custom function + * in [[Renderer#rules]]. + **/ +Renderer.prototype.renderToken = function renderToken(tokens, idx, options) { + const token = tokens[idx]; + let result = ''; + + // Tight list paragraphs + if (token.hidden) { + return ''; + } + + // Insert a newline between hidden paragraph and subsequent opening + // block-level tag. + // + // For example, here we should insert a newline before blockquote: + // - a + // > + // + if (token.block && token.nesting !== -1 && idx && tokens[idx - 1].hidden) { + result += '\n'; + } + + // Add token name, e.g. ``. + // + needLf = false; + } + } + } + } + result += needLf ? '>\n' : '>'; + return result; +}; + +/** + * Renderer.renderInline(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * The same as [[Renderer.render]], but for single token of `inline` type. + **/ +Renderer.prototype.renderInline = function (tokens, options, env) { + let result = ''; + const rules = this.rules; + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type; + if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this); + } else { + result += this.renderToken(tokens, i, options); + } + } + return result; +}; + +/** internal + * Renderer.renderInlineAsText(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Special kludge for image `alt` attributes to conform CommonMark spec. + * Don't try to use it! Spec requires to show `alt` content with stripped markup, + * instead of simple escaping. + **/ +Renderer.prototype.renderInlineAsText = function (tokens, options, env) { + let result = ''; + for (let i = 0, len = tokens.length; i < len; i++) { + switch (tokens[i].type) { + case 'text': + result += tokens[i].content; + break; + case 'image': + result += this.renderInlineAsText(tokens[i].children, options, env); + break; + case 'html_inline': + case 'html_block': + result += tokens[i].content; + break; + case 'softbreak': + case 'hardbreak': + result += '\n'; + break; + // all other tokens are skipped + } + } + return result; +}; + +/** + * Renderer.render(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Takes token stream and generates HTML. Probably, you will never need to call + * this method directly. + **/ +Renderer.prototype.render = function (tokens, options, env) { + let result = ''; + const rules = this.rules; + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type; + if (type === 'inline') { + result += this.renderInline(tokens[i].children, options, env); + } else if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this); + } else { + result += this.renderToken(tokens, i, options, env); + } + } + return result; +}; + +/** + * class Ruler + * + * Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and + * [[MarkdownIt#inline]] to manage sequences of functions (rules): + * + * - keep rules in defined order + * - assign the name to each rule + * - enable/disable rules + * - add/replace rules + * - allow assign rules to additional named chains (in the same) + * - cacheing lists of active rules + * + * You will not need use this class directly until write plugins. For simple + * rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and + * [[MarkdownIt.use]]. + **/ + +/** + * new Ruler() + **/ +function Ruler() { + // List of added rules. Each element is: + // + // { + // name: XXX, + // enabled: Boolean, + // fn: Function(), + // alt: [ name2, name3 ] + // } + // + this.__rules__ = []; + + // Cached rule chains. + // + // First level - chain name, '' for default. + // Second level - diginal anchor for fast filtering by charcodes. + // + this.__cache__ = null; +} + +// Helper methods, should not be used directly + +// Find rule index by name +// +Ruler.prototype.__find__ = function (name) { + for (let i = 0; i < this.__rules__.length; i++) { + if (this.__rules__[i].name === name) { + return i; + } + } + return -1; +}; + +// Build rules lookup cache +// +Ruler.prototype.__compile__ = function () { + const self = this; + const chains = ['']; + + // collect unique names + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { + return; + } + rule.alt.forEach(function (altName) { + if (chains.indexOf(altName) < 0) { + chains.push(altName); + } + }); + }); + self.__cache__ = {}; + chains.forEach(function (chain) { + self.__cache__[chain] = []; + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { + return; + } + if (chain && rule.alt.indexOf(chain) < 0) { + return; + } + self.__cache__[chain].push(rule.fn); + }); + }); +}; + +/** + * Ruler.at(name, fn [, options]) + * - name (String): rule name to replace. + * - fn (Function): new rule function. + * - options (Object): new rule options (not mandatory). + * + * Replace rule by name with new function & options. Throws error if name not + * found. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * Replace existing typographer replacement rule with new one: + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.at('replacements', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.at = function (name, fn, options) { + const index = this.__find__(name); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + name); + } + this.__rules__[index].fn = fn; + this.__rules__[index].alt = opt.alt || []; + this.__cache__ = null; +}; + +/** + * Ruler.before(beforeName, ruleName, fn [, options]) + * - beforeName (String): new rule will be added before this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain before one with given name. See also + * [[Ruler.after]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.block.ruler.before('paragraph', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.before = function (beforeName, ruleName, fn, options) { + const index = this.__find__(beforeName); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + beforeName); + } + this.__rules__.splice(index, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.after(afterName, ruleName, fn [, options]) + * - afterName (String): new rule will be added after this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain after one with given name. See also + * [[Ruler.before]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.inline.ruler.after('text', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.after = function (afterName, ruleName, fn, options) { + const index = this.__find__(afterName); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + afterName); + } + this.__rules__.splice(index + 1, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.push(ruleName, fn [, options]) + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Push new rule to the end of chain. See also + * [[Ruler.before]], [[Ruler.after]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.push('my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.push = function (ruleName, fn, options) { + const opt = options || {}; + this.__rules__.push({ + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.enable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to enable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.disable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.enable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + const result = []; + + // Search by name and enable + list.forEach(function (name) { + const idx = this.__find__(name); + if (idx < 0) { + if (ignoreInvalid) { + return; + } + throw new Error('Rules manager: invalid rule name ' + name); + } + this.__rules__[idx].enabled = true; + result.push(name); + }, this); + this.__cache__ = null; + return result; +}; + +/** + * Ruler.enableOnly(list [, ignoreInvalid]) + * - list (String|Array): list of rule names to enable (whitelist). + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names, and disable everything else. If any rule name + * not found - throw Error. Errors can be disabled by second param. + * + * See also [[Ruler.disable]], [[Ruler.enable]]. + **/ +Ruler.prototype.enableOnly = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + this.__rules__.forEach(function (rule) { + rule.enabled = false; + }); + this.enable(list, ignoreInvalid); +}; + +/** + * Ruler.disable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Disable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.enable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.disable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + const result = []; + + // Search by name and disable + list.forEach(function (name) { + const idx = this.__find__(name); + if (idx < 0) { + if (ignoreInvalid) { + return; + } + throw new Error('Rules manager: invalid rule name ' + name); + } + this.__rules__[idx].enabled = false; + result.push(name); + }, this); + this.__cache__ = null; + return result; +}; + +/** + * Ruler.getRules(chainName) -> Array + * + * Return array of active functions (rules) for given chain name. It analyzes + * rules configuration, compiles caches if not exists and returns result. + * + * Default chain name is `''` (empty string). It can't be skipped. That's + * done intentionally, to keep signature monomorphic for high speed. + **/ +Ruler.prototype.getRules = function (chainName) { + if (this.__cache__ === null) { + this.__compile__(); + } + + // Chain can be empty, if rules disabled. But we still have to return Array. + return this.__cache__[chainName] || []; +}; + +// Token class + +/** + * class Token + **/ + +/** + * new Token(type, tag, nesting) + * + * Create new token and fill passed properties. + **/ +function Token(type, tag, nesting) { + /** + * Token#type -> String + * + * Type of the token (string, e.g. "paragraph_open") + **/ + this.type = type; + + /** + * Token#tag -> String + * + * html tag name, e.g. "p" + **/ + this.tag = tag; + + /** + * Token#attrs -> Array + * + * Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]` + **/ + this.attrs = null; + + /** + * Token#map -> Array + * + * Source map info. Format: `[ line_begin, line_end ]` + **/ + this.map = null; + + /** + * Token#nesting -> Number + * + * Level change (number in {-1, 0, 1} set), where: + * + * - `1` means the tag is opening + * - `0` means the tag is self-closing + * - `-1` means the tag is closing + **/ + this.nesting = nesting; + + /** + * Token#level -> Number + * + * nesting level, the same as `state.level` + **/ + this.level = 0; + + /** + * Token#children -> Array + * + * An array of child nodes (inline and img tokens) + **/ + this.children = null; + + /** + * Token#content -> String + * + * In a case of self-closing tag (code, html, fence, etc.), + * it has contents of this tag. + **/ + this.content = ''; + + /** + * Token#markup -> String + * + * '*' or '_' for emphasis, fence string for fence, etc. + **/ + this.markup = ''; + + /** + * Token#info -> String + * + * Additional information: + * + * - Info string for "fence" tokens + * - The value "auto" for autolink "link_open" and "link_close" tokens + * - The string value of the item marker for ordered-list "list_item_open" tokens + **/ + this.info = ''; + + /** + * Token#meta -> Object + * + * A place for plugins to store an arbitrary data + **/ + this.meta = null; + + /** + * Token#block -> Boolean + * + * True for block-level tokens, false for inline tokens. + * Used in renderer to calculate line breaks + **/ + this.block = false; + + /** + * Token#hidden -> Boolean + * + * If it's true, ignore this element when rendering. Used for tight lists + * to hide paragraphs. + **/ + this.hidden = false; +} + +/** + * Token.attrIndex(name) -> Number + * + * Search attribute index by name. + **/ +Token.prototype.attrIndex = function attrIndex(name) { + if (!this.attrs) { + return -1; + } + const attrs = this.attrs; + for (let i = 0, len = attrs.length; i < len; i++) { + if (attrs[i][0] === name) { + return i; + } + } + return -1; +}; + +/** + * Token.attrPush(attrData) + * + * Add `[ name, value ]` attribute to list. Init attrs if necessary + **/ +Token.prototype.attrPush = function attrPush(attrData) { + if (this.attrs) { + this.attrs.push(attrData); + } else { + this.attrs = [attrData]; + } +}; + +/** + * Token.attrSet(name, value) + * + * Set `name` attribute to `value`. Override old value if exists. + **/ +Token.prototype.attrSet = function attrSet(name, value) { + const idx = this.attrIndex(name); + const attrData = [name, value]; + if (idx < 0) { + this.attrPush(attrData); + } else { + this.attrs[idx] = attrData; + } +}; + +/** + * Token.attrGet(name) + * + * Get the value of attribute `name`, or null if it does not exist. + **/ +Token.prototype.attrGet = function attrGet(name) { + const idx = this.attrIndex(name); + let value = null; + if (idx >= 0) { + value = this.attrs[idx][1]; + } + return value; +}; + +/** + * Token.attrJoin(name, value) + * + * Join value to existing attribute via space. Or create new attribute if not + * exists. Useful to operate with token classes. + **/ +Token.prototype.attrJoin = function attrJoin(name, value) { + const idx = this.attrIndex(name); + if (idx < 0) { + this.attrPush([name, value]); + } else { + this.attrs[idx][1] = this.attrs[idx][1] + ' ' + value; + } +}; + +// Core state object +// + +function StateCore(src, md, env) { + this.src = src; + this.env = env; + this.tokens = []; + this.inlineMode = false; + this.md = md; // link to parser instance +} + +// re-export Token class to use in core rules +StateCore.prototype.Token = Token; + +// Normalize input string + +// https://spec.commonmark.org/0.29/#line-ending +const NEWLINES_RE = /\r\n?|\n/g; +const NULL_RE = /\0/g; +function normalize(state) { + let str; + + // Normalize newlines + str = state.src.replace(NEWLINES_RE, '\n'); + + // Replace NULL characters + str = str.replace(NULL_RE, '\uFFFD'); + state.src = str; +} + +function block(state) { + let token; + if (state.inlineMode) { + token = new state.Token('inline', '', 0); + token.content = state.src; + token.map = [0, 1]; + token.children = []; + state.tokens.push(token); + } else { + state.md.block.parse(state.src, state.md, state.env, state.tokens); + } +} + +function inline(state) { + const tokens = state.tokens; + + // Parse inlines + for (let i = 0, l = tokens.length; i < l; i++) { + const tok = tokens[i]; + if (tok.type === 'inline') { + state.md.inline.parse(tok.content, state.md, state.env, tok.children); + } + } +} + +// Replace link-like texts with link nodes. +// +// Currently restricted by `md.validateLink()` to http/https/ftp +// + +function isLinkOpen$1(str) { + return /^\s]/i.test(str); +} +function isLinkClose$1(str) { + return /^<\/a\s*>/i.test(str); +} +function linkify$1(state) { + const blockTokens = state.tokens; + if (!state.md.options.linkify) { + return; + } + for (let j = 0, l = blockTokens.length; j < l; j++) { + if (blockTokens[j].type !== 'inline' || !state.md.linkify.pretest(blockTokens[j].content)) { + continue; + } + let tokens = blockTokens[j].children; + let htmlLinkLevel = 0; + + // We scan from the end, to keep position when new tags added. + // Use reversed logic in links start/end match + for (let i = tokens.length - 1; i >= 0; i--) { + const currentToken = tokens[i]; + + // Skip content of markdown links + if (currentToken.type === 'link_close') { + i--; + while (tokens[i].level !== currentToken.level && tokens[i].type !== 'link_open') { + i--; + } + continue; + } + + // Skip content of html tag links + if (currentToken.type === 'html_inline') { + if (isLinkOpen$1(currentToken.content) && htmlLinkLevel > 0) { + htmlLinkLevel--; + } + if (isLinkClose$1(currentToken.content)) { + htmlLinkLevel++; + } + } + if (htmlLinkLevel > 0) { + continue; + } + if (currentToken.type === 'text' && state.md.linkify.test(currentToken.content)) { + const text = currentToken.content; + let links = state.md.linkify.match(text); + + // Now split string to nodes + const nodes = []; + let level = currentToken.level; + let lastPos = 0; + + // forbid escape sequence at the start of the string, + // this avoids http\://example.com/ from being linkified as + // http://example.com/ + if (links.length > 0 && links[0].index === 0 && i > 0 && tokens[i - 1].type === 'text_special') { + links = links.slice(1); + } + for (let ln = 0; ln < links.length; ln++) { + const url = links[ln].url; + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) { + continue; + } + let urlText = links[ln].text; + + // Linkifier might send raw hostnames like "example.com", where url + // starts with domain name. So we prepend http:// in those cases, + // and remove it afterwards. + // + if (!links[ln].schema) { + urlText = state.md.normalizeLinkText('http://' + urlText).replace(/^http:\/\//, ''); + } else if (links[ln].schema === 'mailto:' && !/^mailto:/i.test(urlText)) { + urlText = state.md.normalizeLinkText('mailto:' + urlText).replace(/^mailto:/, ''); + } else { + urlText = state.md.normalizeLinkText(urlText); + } + const pos = links[ln].index; + if (pos > lastPos) { + const token = new state.Token('text', '', 0); + token.content = text.slice(lastPos, pos); + token.level = level; + nodes.push(token); + } + const token_o = new state.Token('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.level = level++; + token_o.markup = 'linkify'; + token_o.info = 'auto'; + nodes.push(token_o); + const token_t = new state.Token('text', '', 0); + token_t.content = urlText; + token_t.level = level; + nodes.push(token_t); + const token_c = new state.Token('link_close', 'a', -1); + token_c.level = --level; + token_c.markup = 'linkify'; + token_c.info = 'auto'; + nodes.push(token_c); + lastPos = links[ln].lastIndex; + } + if (lastPos < text.length) { + const token = new state.Token('text', '', 0); + token.content = text.slice(lastPos); + token.level = level; + nodes.push(token); + } + + // replace current node + blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes); + } + } + } +} + +// Simple typographic replacements +// +// (c) (C) → © +// (tm) (TM) → ™ +// (r) (R) → ® +// +- → ± +// ... → … (also ?.... → ?.., !.... → !..) +// ???????? → ???, !!!!! → !!!, `,,` → `,` +// -- → –, --- → — +// + +// TODO: +// - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾ +// - multiplications 2 x 4 -> 2 × 4 + +const RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/; + +// Workaround for phantomjs - need regex without /g flag, +// or root check will fail every second time +const SCOPED_ABBR_TEST_RE = /\((c|tm|r)\)/i; +const SCOPED_ABBR_RE = /\((c|tm|r)\)/ig; +const SCOPED_ABBR = { + c: '©', + r: '®', + tm: '™' +}; +function replaceFn(match, name) { + return SCOPED_ABBR[name.toLowerCase()]; +} +function replace_scoped(inlineTokens) { + let inside_autolink = 0; + for (let i = inlineTokens.length - 1; i >= 0; i--) { + const token = inlineTokens[i]; + if (token.type === 'text' && !inside_autolink) { + token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn); + } + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } + } +} +function replace_rare(inlineTokens) { + let inside_autolink = 0; + for (let i = inlineTokens.length - 1; i >= 0; i--) { + const token = inlineTokens[i]; + if (token.type === 'text' && !inside_autolink) { + if (RARE_RE.test(token.content)) { + token.content = token.content.replace(/\+-/g, '±') + // .., ..., ....... -> … + // but ?..... & !..... -> ?.. & !.. + .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..').replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') + // em-dash + .replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014') + // en-dash + .replace(/(^|\s)--(?=\s|$)/mg, '$1\u2013').replace(/(^|[^-\s])--(?=[^-\s]|$)/mg, '$1\u2013'); + } + } + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } + } +} +function replace(state) { + let blkIdx; + if (!state.md.options.typographer) { + return; + } + for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { + if (state.tokens[blkIdx].type !== 'inline') { + continue; + } + if (SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) { + replace_scoped(state.tokens[blkIdx].children); + } + if (RARE_RE.test(state.tokens[blkIdx].content)) { + replace_rare(state.tokens[blkIdx].children); + } + } +} + +// Convert straight quotation marks to typographic ones +// + +const QUOTE_TEST_RE = /['"]/; +const QUOTE_RE = /['"]/g; +const APOSTROPHE = '\u2019'; /* ’ */ + +function replaceAt(str, index, ch) { + return str.slice(0, index) + ch + str.slice(index + 1); +} +function process_inlines(tokens, state) { + let j; + const stack = []; + for (let i = 0; i < tokens.length; i++) { + const token = tokens[i]; + const thisLevel = tokens[i].level; + for (j = stack.length - 1; j >= 0; j--) { + if (stack[j].level <= thisLevel) { + break; + } + } + stack.length = j + 1; + if (token.type !== 'text') { + continue; + } + let text = token.content; + let pos = 0; + let max = text.length; + + /* eslint no-labels:0,block-scoped-var:0 */ + OUTER: while (pos < max) { + QUOTE_RE.lastIndex = pos; + const t = QUOTE_RE.exec(text); + if (!t) { + break; + } + let canOpen = true; + let canClose = true; + pos = t.index + 1; + const isSingle = t[0] === "'"; + + // Find previous character, + // default to space if it's the beginning of the line + // + let lastChar = 0x20; + if (t.index - 1 >= 0) { + lastChar = text.charCodeAt(t.index - 1); + } else { + for (j = i - 1; j >= 0; j--) { + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // lastChar defaults to 0x20 + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' + + lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1); + break; + } + } + + // Find next character, + // default to space if it's the end of the line + // + let nextChar = 0x20; + if (pos < max) { + nextChar = text.charCodeAt(pos); + } else { + for (j = i + 1; j < tokens.length; j++) { + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // nextChar defaults to 0x20 + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' + + nextChar = tokens[j].content.charCodeAt(0); + break; + } + } + const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)); + const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)); + const isLastWhiteSpace = isWhiteSpace(lastChar); + const isNextWhiteSpace = isWhiteSpace(nextChar); + if (isNextWhiteSpace) { + canOpen = false; + } else if (isNextPunctChar) { + if (!(isLastWhiteSpace || isLastPunctChar)) { + canOpen = false; + } + } + if (isLastWhiteSpace) { + canClose = false; + } else if (isLastPunctChar) { + if (!(isNextWhiteSpace || isNextPunctChar)) { + canClose = false; + } + } + if (nextChar === 0x22 /* " */ && t[0] === '"') { + if (lastChar >= 0x30 /* 0 */ && lastChar <= 0x39 /* 9 */) { + // special case: 1"" - count first quote as an inch + canClose = canOpen = false; + } + } + if (canOpen && canClose) { + // Replace quotes in the middle of punctuation sequence, but not + // in the middle of the words, i.e.: + // + // 1. foo " bar " baz - not replaced + // 2. foo-"-bar-"-baz - replaced + // 3. foo"bar"baz - not replaced + // + canOpen = isLastPunctChar; + canClose = isNextPunctChar; + } + if (!canOpen && !canClose) { + // middle of word + if (isSingle) { + token.content = replaceAt(token.content, t.index, APOSTROPHE); + } + continue; + } + if (canClose) { + // this could be a closing quote, rewind the stack to get a match + for (j = stack.length - 1; j >= 0; j--) { + let item = stack[j]; + if (stack[j].level < thisLevel) { + break; + } + if (item.single === isSingle && stack[j].level === thisLevel) { + item = stack[j]; + let openQuote; + let closeQuote; + if (isSingle) { + openQuote = state.md.options.quotes[2]; + closeQuote = state.md.options.quotes[3]; + } else { + openQuote = state.md.options.quotes[0]; + closeQuote = state.md.options.quotes[1]; + } + + // replace token.content *before* tokens[item.token].content, + // because, if they are pointing at the same token, replaceAt + // could mess up indices when quote length != 1 + token.content = replaceAt(token.content, t.index, closeQuote); + tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, openQuote); + pos += closeQuote.length - 1; + if (item.token === i) { + pos += openQuote.length - 1; + } + text = token.content; + max = text.length; + stack.length = j; + continue OUTER; + } + } + } + if (canOpen) { + stack.push({ + token: i, + pos: t.index, + single: isSingle, + level: thisLevel + }); + } else if (canClose && isSingle) { + token.content = replaceAt(token.content, t.index, APOSTROPHE); + } + } + } +} +function smartquotes(state) { + /* eslint max-depth:0 */ + if (!state.md.options.typographer) { + return; + } + for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { + if (state.tokens[blkIdx].type !== 'inline' || !QUOTE_TEST_RE.test(state.tokens[blkIdx].content)) { + continue; + } + process_inlines(state.tokens[blkIdx].children, state); + } +} + +// Join raw text tokens with the rest of the text +// +// This is set as a separate rule to provide an opportunity for plugins +// to run text replacements after text join, but before escape join. +// +// For example, `\:)` shouldn't be replaced with an emoji. +// + +function text_join(state) { + let curr, last; + const blockTokens = state.tokens; + const l = blockTokens.length; + for (let j = 0; j < l; j++) { + if (blockTokens[j].type !== 'inline') continue; + const tokens = blockTokens[j].children; + const max = tokens.length; + for (curr = 0; curr < max; curr++) { + if (tokens[curr].type === 'text_special') { + tokens[curr].type = 'text'; + } + } + for (curr = last = 0; curr < max; curr++) { + if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { + // collapse two adjacent text nodes + tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content; + } else { + if (curr !== last) { + tokens[last] = tokens[curr]; + } + last++; + } + } + if (curr !== last) { + tokens.length = last; + } + } +} + +/** internal + * class Core + * + * Top-level rules executor. Glues block/inline parsers and does intermediate + * transformations. + **/ + +const _rules$2 = [['normalize', normalize], ['block', block], ['inline', inline], ['linkify', linkify$1], ['replacements', replace], ['smartquotes', smartquotes], +// `text_join` finds `text_special` tokens (for escape sequences) +// and joins them with the rest of the text +['text_join', text_join]]; + +/** + * new Core() + **/ +function Core() { + /** + * Core#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of core rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules$2.length; i++) { + this.ruler.push(_rules$2[i][0], _rules$2[i][1]); + } +} + +/** + * Core.process(state) + * + * Executes core chain rules. + **/ +Core.prototype.process = function (state) { + const rules = this.ruler.getRules(''); + for (let i = 0, l = rules.length; i < l; i++) { + rules[i](state); + } +}; +Core.prototype.State = StateCore; + +// Parser state class + +function StateBlock(src, md, env, tokens) { + this.src = src; + + // link to parser instance + this.md = md; + this.env = env; + + // + // Internal state vartiables + // + + this.tokens = tokens; + this.bMarks = []; // line begin offsets for fast jumps + this.eMarks = []; // line end offsets for fast jumps + this.tShift = []; // offsets of the first non-space characters (tabs not expanded) + this.sCount = []; // indents for each line (tabs expanded) + + // An amount of virtual spaces (tabs expanded) between beginning + // of each line (bMarks) and real beginning of that line. + // + // It exists only as a hack because blockquotes override bMarks + // losing information in the process. + // + // It's used only when expanding tabs, you can think about it as + // an initial tab length, e.g. bsCount=21 applied to string `\t123` + // means first tab should be expanded to 4-21%4 === 3 spaces. + // + this.bsCount = []; + + // block parser variables + + // required block content indent (for example, if we are + // inside a list, it would be positioned after list marker) + this.blkIndent = 0; + this.line = 0; // line index in src + this.lineMax = 0; // lines count + this.tight = false; // loose/tight mode for lists + this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any) + this.listIndent = -1; // indent of the current list block (-1 if there isn't any) + + // can be 'blockquote', 'list', 'root', 'paragraph' or 'reference' + // used in lists to determine if they interrupt a paragraph + this.parentType = 'root'; + this.level = 0; + + // Create caches + // Generate markers. + const s = this.src; + for (let start = 0, pos = 0, indent = 0, offset = 0, len = s.length, indent_found = false; pos < len; pos++) { + const ch = s.charCodeAt(pos); + if (!indent_found) { + if (isSpace(ch)) { + indent++; + if (ch === 0x09) { + offset += 4 - offset % 4; + } else { + offset++; + } + continue; + } else { + indent_found = true; + } + } + if (ch === 0x0A || pos === len - 1) { + if (ch !== 0x0A) { + pos++; + } + this.bMarks.push(start); + this.eMarks.push(pos); + this.tShift.push(indent); + this.sCount.push(offset); + this.bsCount.push(0); + indent_found = false; + indent = 0; + offset = 0; + start = pos + 1; + } + } + + // Push fake entry to simplify cache bounds checks + this.bMarks.push(s.length); + this.eMarks.push(s.length); + this.tShift.push(0); + this.sCount.push(0); + this.bsCount.push(0); + this.lineMax = this.bMarks.length - 1; // don't count last fake line +} + +// Push new token to "stream". +// +StateBlock.prototype.push = function (type, tag, nesting) { + const token = new Token(type, tag, nesting); + token.block = true; + if (nesting < 0) this.level--; // closing tag + token.level = this.level; + if (nesting > 0) this.level++; // opening tag + + this.tokens.push(token); + return token; +}; +StateBlock.prototype.isEmpty = function isEmpty(line) { + return this.bMarks[line] + this.tShift[line] >= this.eMarks[line]; +}; +StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) { + for (let max = this.lineMax; from < max; from++) { + if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) { + break; + } + } + return from; +}; + +// Skip spaces from given position. +StateBlock.prototype.skipSpaces = function skipSpaces(pos) { + for (let max = this.src.length; pos < max; pos++) { + const ch = this.src.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + } + return pos; +}; + +// Skip spaces from given position in reverse. +StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) { + if (pos <= min) { + return pos; + } + while (pos > min) { + if (!isSpace(this.src.charCodeAt(--pos))) { + return pos + 1; + } + } + return pos; +}; + +// Skip char codes from given position +StateBlock.prototype.skipChars = function skipChars(pos, code) { + for (let max = this.src.length; pos < max; pos++) { + if (this.src.charCodeAt(pos) !== code) { + break; + } + } + return pos; +}; + +// Skip char codes reverse from given position - 1 +StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) { + if (pos <= min) { + return pos; + } + while (pos > min) { + if (code !== this.src.charCodeAt(--pos)) { + return pos + 1; + } + } + return pos; +}; + +// cut lines range from source. +StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) { + if (begin >= end) { + return ''; + } + const queue = new Array(end - begin); + for (let i = 0, line = begin; line < end; line++, i++) { + let lineIndent = 0; + const lineStart = this.bMarks[line]; + let first = lineStart; + let last; + if (line + 1 < end || keepLastLF) { + // No need for bounds check because we have fake entry on tail. + last = this.eMarks[line] + 1; + } else { + last = this.eMarks[line]; + } + while (first < last && lineIndent < indent) { + const ch = this.src.charCodeAt(first); + if (isSpace(ch)) { + if (ch === 0x09) { + lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4; + } else { + lineIndent++; + } + } else if (first - lineStart < this.tShift[line]) { + // patched tShift masked characters to look like spaces (blockquotes, list markers) + lineIndent++; + } else { + break; + } + first++; + } + if (lineIndent > indent) { + // partially expanding tabs in code blocks, e.g '\t\tfoobar' + // with indent=2 becomes ' \tfoobar' + queue[i] = new Array(lineIndent - indent + 1).join(' ') + this.src.slice(first, last); + } else { + queue[i] = this.src.slice(first, last); + } + } + return queue.join(''); +}; + +// re-export Token class to use in block rules +StateBlock.prototype.Token = Token; + +// GFM table, https://github.github.com/gfm/#tables-extension- + + +// Limit the amount of empty autocompleted cells in a table, +// see https://github.com/markdown-it/markdown-it/issues/1000, +// +// Both pulldown-cmark and commonmark-hs limit the number of cells this way to ~200k. +// We set it to 65k, which can expand user input by a factor of x370 +// (256x256 square is 1.8kB expanded into 650kB). +const MAX_AUTOCOMPLETED_CELLS = 0x10000; +function getLine(state, line) { + const pos = state.bMarks[line] + state.tShift[line]; + const max = state.eMarks[line]; + return state.src.slice(pos, max); +} +function escapedSplit(str) { + const result = []; + const max = str.length; + let pos = 0; + let ch = str.charCodeAt(pos); + let isEscaped = false; + let lastPos = 0; + let current = ''; + while (pos < max) { + if (ch === 0x7c /* | */) { + if (!isEscaped) { + // pipe separating cells, '|' + result.push(current + str.substring(lastPos, pos)); + current = ''; + lastPos = pos + 1; + } else { + // escaped pipe, '\|' + current += str.substring(lastPos, pos - 1); + lastPos = pos; + } + } + isEscaped = ch === 0x5c /* \ */; + pos++; + ch = str.charCodeAt(pos); + } + result.push(current + str.substring(lastPos)); + return result; +} +function table(state, startLine, endLine, silent) { + // should have at least two lines + if (startLine + 2 > endLine) { + return false; + } + let nextLine = startLine + 1; + if (state.sCount[nextLine] < state.blkIndent) { + return false; + } + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + return false; + } + + // first character of the second line should be '|', '-', ':', + // and no other characters are allowed but spaces; + // basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp + + let pos = state.bMarks[nextLine] + state.tShift[nextLine]; + if (pos >= state.eMarks[nextLine]) { + return false; + } + const firstCh = state.src.charCodeAt(pos++); + if (firstCh !== 0x7C /* | */ && firstCh !== 0x2D /* - */ && firstCh !== 0x3A /* : */) { + return false; + } + if (pos >= state.eMarks[nextLine]) { + return false; + } + const secondCh = state.src.charCodeAt(pos++); + if (secondCh !== 0x7C /* | */ && secondCh !== 0x2D /* - */ && secondCh !== 0x3A /* : */ && !isSpace(secondCh)) { + return false; + } + + // if first character is '-', then second character must not be a space + // (due to parsing ambiguity with list) + if (firstCh === 0x2D /* - */ && isSpace(secondCh)) { + return false; + } + while (pos < state.eMarks[nextLine]) { + const ch = state.src.charCodeAt(pos); + if (ch !== 0x7C /* | */ && ch !== 0x2D /* - */ && ch !== 0x3A /* : */ && !isSpace(ch)) { + return false; + } + pos++; + } + let lineText = getLine(state, startLine + 1); + let columns = lineText.split('|'); + const aligns = []; + for (let i = 0; i < columns.length; i++) { + const t = columns[i].trim(); + if (!t) { + // allow empty columns before and after table, but not in between columns; + // e.g. allow ` |---| `, disallow ` ---||--- ` + if (i === 0 || i === columns.length - 1) { + continue; + } else { + return false; + } + } + if (!/^:?-+:?$/.test(t)) { + return false; + } + if (t.charCodeAt(t.length - 1) === 0x3A /* : */) { + aligns.push(t.charCodeAt(0) === 0x3A /* : */ ? 'center' : 'right'); + } else if (t.charCodeAt(0) === 0x3A /* : */) { + aligns.push('left'); + } else { + aligns.push(''); + } + } + lineText = getLine(state, startLine).trim(); + if (lineText.indexOf('|') === -1) { + return false; + } + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + columns = escapedSplit(lineText); + if (columns.length && columns[0] === '') columns.shift(); + if (columns.length && columns[columns.length - 1] === '') columns.pop(); + + // header row will define an amount of columns in the entire table, + // and align row should be exactly the same (the rest of the rows can differ) + const columnCount = columns.length; + if (columnCount === 0 || columnCount !== aligns.length) { + return false; + } + if (silent) { + return true; + } + const oldParentType = state.parentType; + state.parentType = 'table'; + + // use 'blockquote' lists for termination because it's + // the most similar to tables + const terminatorRules = state.md.block.ruler.getRules('blockquote'); + const token_to = state.push('table_open', 'table', 1); + const tableLines = [startLine, 0]; + token_to.map = tableLines; + const token_tho = state.push('thead_open', 'thead', 1); + token_tho.map = [startLine, startLine + 1]; + const token_htro = state.push('tr_open', 'tr', 1); + token_htro.map = [startLine, startLine + 1]; + for (let i = 0; i < columns.length; i++) { + const token_ho = state.push('th_open', 'th', 1); + if (aligns[i]) { + token_ho.attrs = [['style', 'text-align:' + aligns[i]]]; + } + const token_il = state.push('inline', '', 0); + token_il.content = columns[i].trim(); + token_il.children = []; + state.push('th_close', 'th', -1); + } + state.push('tr_close', 'tr', -1); + state.push('thead_close', 'thead', -1); + let tbodyLines; + let autocompletedCells = 0; + for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + lineText = getLine(state, nextLine).trim(); + if (!lineText) { + break; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + break; + } + columns = escapedSplit(lineText); + if (columns.length && columns[0] === '') columns.shift(); + if (columns.length && columns[columns.length - 1] === '') columns.pop(); + + // note: autocomplete count can be negative if user specifies more columns than header, + // but that does not affect intended use (which is limiting expansion) + autocompletedCells += columnCount - columns.length; + if (autocompletedCells > MAX_AUTOCOMPLETED_CELLS) { + break; + } + if (nextLine === startLine + 2) { + const token_tbo = state.push('tbody_open', 'tbody', 1); + token_tbo.map = tbodyLines = [startLine + 2, 0]; + } + const token_tro = state.push('tr_open', 'tr', 1); + token_tro.map = [nextLine, nextLine + 1]; + for (let i = 0; i < columnCount; i++) { + const token_tdo = state.push('td_open', 'td', 1); + if (aligns[i]) { + token_tdo.attrs = [['style', 'text-align:' + aligns[i]]]; + } + const token_il = state.push('inline', '', 0); + token_il.content = columns[i] ? columns[i].trim() : ''; + token_il.children = []; + state.push('td_close', 'td', -1); + } + state.push('tr_close', 'tr', -1); + } + if (tbodyLines) { + state.push('tbody_close', 'tbody', -1); + tbodyLines[1] = nextLine; + } + state.push('table_close', 'table', -1); + tableLines[1] = nextLine; + state.parentType = oldParentType; + state.line = nextLine; + return true; +} + +// Code block (4 spaces padded) + +function code(state, startLine, endLine /*, silent */) { + if (state.sCount[startLine] - state.blkIndent < 4) { + return false; + } + let nextLine = startLine + 1; + let last = nextLine; + while (nextLine < endLine) { + if (state.isEmpty(nextLine)) { + nextLine++; + continue; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + nextLine++; + last = nextLine; + continue; + } + break; + } + state.line = last; + const token = state.push('code_block', 'code', 0); + token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + '\n'; + token.map = [startLine, state.line]; + return true; +} + +// fences (``` lang, ~~~ lang) + +function fence(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (pos + 3 > max) { + return false; + } + const marker = state.src.charCodeAt(pos); + if (marker !== 0x7E /* ~ */ && marker !== 0x60 /* ` */) { + return false; + } + + // scan marker length + let mem = pos; + pos = state.skipChars(pos, marker); + let len = pos - mem; + if (len < 3) { + return false; + } + const markup = state.src.slice(mem, pos); + const params = state.src.slice(pos, max); + if (marker === 0x60 /* ` */) { + if (params.indexOf(String.fromCharCode(marker)) >= 0) { + return false; + } + } + + // Since start is found, we can report success here in validation mode + if (silent) { + return true; + } + + // search end of block + let nextLine = startLine; + let haveEndMarker = false; + for (;;) { + nextLine++; + if (nextLine >= endLine) { + // unclosed block should be autoclosed by end of document. + // also block seems to be autoclosed by end of parent + break; + } + pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + if (pos < max && state.sCount[nextLine] < state.blkIndent) { + // non-empty line with negative indent should stop the list: + // - ``` + // test + break; + } + if (state.src.charCodeAt(pos) !== marker) { + continue; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + // closing fence should be indented less than 4 spaces + continue; + } + pos = state.skipChars(pos, marker); + + // closing code fence must be at least as long as the opening one + if (pos - mem < len) { + continue; + } + + // make sure tail has spaces only + pos = state.skipSpaces(pos); + if (pos < max) { + continue; + } + haveEndMarker = true; + // found! + break; + } + + // If a fence has heading spaces, they should be removed from its inner block + len = state.sCount[startLine]; + state.line = nextLine + (haveEndMarker ? 1 : 0); + const token = state.push('fence', 'code', 0); + token.info = params; + token.content = state.getLines(startLine + 1, nextLine, len, true); + token.markup = markup; + token.map = [startLine, state.line]; + return true; +} + +// Block quotes + +function blockquote(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + const oldLineMax = state.lineMax; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + + // check the block quote marker + if (state.src.charCodeAt(pos) !== 0x3E /* > */) { + return false; + } + + // we know that it's going to be a valid blockquote, + // so no point trying to find the end of it in silent mode + if (silent) { + return true; + } + const oldBMarks = []; + const oldBSCount = []; + const oldSCount = []; + const oldTShift = []; + const terminatorRules = state.md.block.ruler.getRules('blockquote'); + const oldParentType = state.parentType; + state.parentType = 'blockquote'; + let lastLineEmpty = false; + let nextLine; + + // Search the end of the block + // + // Block ends with either: + // 1. an empty line outside: + // ``` + // > test + // + // ``` + // 2. an empty line inside: + // ``` + // > + // test + // ``` + // 3. another tag: + // ``` + // > test + // - - - + // ``` + for (nextLine = startLine; nextLine < endLine; nextLine++) { + // check if it's outdented, i.e. it's inside list item and indented + // less than said list item: + // + // ``` + // 1. anything + // > current blockquote + // 2. checking this line + // ``` + const isOutdented = state.sCount[nextLine] < state.blkIndent; + pos = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + if (pos >= max) { + // Case 1: line is not inside the blockquote, and this line is empty. + break; + } + if (state.src.charCodeAt(pos++) === 0x3E /* > */ && !isOutdented) { + // This line is inside the blockquote. + + // set offset past spaces and ">" + let initial = state.sCount[nextLine] + 1; + let spaceAfterMarker; + let adjustTab; + + // skip one optional space after '>' + if (state.src.charCodeAt(pos) === 0x20 /* space */) { + // ' > test ' + // ^ -- position start of line here: + pos++; + initial++; + adjustTab = false; + spaceAfterMarker = true; + } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { + spaceAfterMarker = true; + if ((state.bsCount[nextLine] + initial) % 4 === 3) { + // ' >\t test ' + // ^ -- position start of line here (tab has width===1) + pos++; + initial++; + adjustTab = false; + } else { + // ' >\t test ' + // ^ -- position start of line here + shift bsCount slightly + // to make extra space appear + adjustTab = true; + } + } else { + spaceAfterMarker = false; + } + let offset = initial; + oldBMarks.push(state.bMarks[nextLine]); + state.bMarks[nextLine] = pos; + while (pos < max) { + const ch = state.src.charCodeAt(pos); + if (isSpace(ch)) { + if (ch === 0x09) { + offset += 4 - (offset + state.bsCount[nextLine] + (adjustTab ? 1 : 0)) % 4; + } else { + offset++; + } + } else { + break; + } + pos++; + } + lastLineEmpty = pos >= max; + oldBSCount.push(state.bsCount[nextLine]); + state.bsCount[nextLine] = state.sCount[nextLine] + 1 + (spaceAfterMarker ? 1 : 0); + oldSCount.push(state.sCount[nextLine]); + state.sCount[nextLine] = offset - initial; + oldTShift.push(state.tShift[nextLine]); + state.tShift[nextLine] = pos - state.bMarks[nextLine]; + continue; + } + + // Case 2: line is not inside the blockquote, and the last line was empty. + if (lastLineEmpty) { + break; + } + + // Case 3: another tag found. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + // Quirk to enforce "hard termination mode" for paragraphs; + // normally if you call `tokenize(state, startLine, nextLine)`, + // paragraphs will look below nextLine for paragraph continuation, + // but if blockquote is terminated by another tag, they shouldn't + state.lineMax = nextLine; + if (state.blkIndent !== 0) { + // state.blkIndent was non-zero, we now set it to zero, + // so we need to re-calculate all offsets to appear as + // if indent wasn't changed + oldBMarks.push(state.bMarks[nextLine]); + oldBSCount.push(state.bsCount[nextLine]); + oldTShift.push(state.tShift[nextLine]); + oldSCount.push(state.sCount[nextLine]); + state.sCount[nextLine] -= state.blkIndent; + } + break; + } + oldBMarks.push(state.bMarks[nextLine]); + oldBSCount.push(state.bsCount[nextLine]); + oldTShift.push(state.tShift[nextLine]); + oldSCount.push(state.sCount[nextLine]); + + // A negative indentation means that this is a paragraph continuation + // + state.sCount[nextLine] = -1; + } + const oldIndent = state.blkIndent; + state.blkIndent = 0; + const token_o = state.push('blockquote_open', 'blockquote', 1); + token_o.markup = '>'; + const lines = [startLine, 0]; + token_o.map = lines; + state.md.block.tokenize(state, startLine, nextLine); + const token_c = state.push('blockquote_close', 'blockquote', -1); + token_c.markup = '>'; + state.lineMax = oldLineMax; + state.parentType = oldParentType; + lines[1] = state.line; + + // Restore original tShift; this might not be necessary since the parser + // has already been here, but just to make sure we can do that. + for (let i = 0; i < oldTShift.length; i++) { + state.bMarks[i + startLine] = oldBMarks[i]; + state.tShift[i + startLine] = oldTShift[i]; + state.sCount[i + startLine] = oldSCount[i]; + state.bsCount[i + startLine] = oldBSCount[i]; + } + state.blkIndent = oldIndent; + return true; +} + +// Horizontal rule + +function hr(state, startLine, endLine, silent) { + const max = state.eMarks[startLine]; + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + let pos = state.bMarks[startLine] + state.tShift[startLine]; + const marker = state.src.charCodeAt(pos++); + + // Check hr marker + if (marker !== 0x2A /* * */ && marker !== 0x2D /* - */ && marker !== 0x5F /* _ */) { + return false; + } + + // markers can be mixed with spaces, but there should be at least 3 of them + + let cnt = 1; + while (pos < max) { + const ch = state.src.charCodeAt(pos++); + if (ch !== marker && !isSpace(ch)) { + return false; + } + if (ch === marker) { + cnt++; + } + } + if (cnt < 3) { + return false; + } + if (silent) { + return true; + } + state.line = startLine + 1; + const token = state.push('hr', 'hr', 0); + token.map = [startLine, state.line]; + token.markup = Array(cnt + 1).join(String.fromCharCode(marker)); + return true; +} + +// Lists + + +// Search `[-+*][\n ]`, returns next pos after marker on success +// or -1 on fail. +function skipBulletListMarker(state, startLine) { + const max = state.eMarks[startLine]; + let pos = state.bMarks[startLine] + state.tShift[startLine]; + const marker = state.src.charCodeAt(pos++); + // Check bullet + if (marker !== 0x2A /* * */ && marker !== 0x2D /* - */ && marker !== 0x2B /* + */) { + return -1; + } + if (pos < max) { + const ch = state.src.charCodeAt(pos); + if (!isSpace(ch)) { + // " -test " - is not a list item + return -1; + } + } + return pos; +} + +// Search `\d+[.)][\n ]`, returns next pos after marker on success +// or -1 on fail. +function skipOrderedListMarker(state, startLine) { + const start = state.bMarks[startLine] + state.tShift[startLine]; + const max = state.eMarks[startLine]; + let pos = start; + + // List marker should have at least 2 chars (digit + dot) + if (pos + 1 >= max) { + return -1; + } + let ch = state.src.charCodeAt(pos++); + if (ch < 0x30 /* 0 */ || ch > 0x39 /* 9 */) { + return -1; + } + for (;;) { + // EOL -> fail + if (pos >= max) { + return -1; + } + ch = state.src.charCodeAt(pos++); + if (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) { + // List marker should have no more than 9 digits + // (prevents integer overflow in browsers) + if (pos - start >= 10) { + return -1; + } + continue; + } + + // found valid marker + if (ch === 0x29 /* ) */ || ch === 0x2e /* . */) { + break; + } + return -1; + } + if (pos < max) { + ch = state.src.charCodeAt(pos); + if (!isSpace(ch)) { + // " 1.test " - is not a list item + return -1; + } + } + return pos; +} +function markTightParagraphs(state, idx) { + const level = state.level + 2; + for (let i = idx + 2, l = state.tokens.length - 2; i < l; i++) { + if (state.tokens[i].level === level && state.tokens[i].type === 'paragraph_open') { + state.tokens[i + 2].hidden = true; + state.tokens[i].hidden = true; + i += 2; + } + } +} +function list(state, startLine, endLine, silent) { + let max, pos, start, token; + let nextLine = startLine; + let tight = true; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + return false; + } + + // Special case: + // - item 1 + // - item 2 + // - item 3 + // - item 4 + // - this one is a paragraph continuation + if (state.listIndent >= 0 && state.sCount[nextLine] - state.listIndent >= 4 && state.sCount[nextLine] < state.blkIndent) { + return false; + } + let isTerminatingParagraph = false; + + // limit conditions when list can interrupt + // a paragraph (validation mode only) + if (silent && state.parentType === 'paragraph') { + // Next list item should still terminate previous list item; + // + // This code can fail if plugins use blkIndent as well as lists, + // but I hope the spec gets fixed long before that happens. + // + if (state.sCount[nextLine] >= state.blkIndent) { + isTerminatingParagraph = true; + } + } + + // Detect list type and position after marker + let isOrdered; + let markerValue; + let posAfterMarker; + if ((posAfterMarker = skipOrderedListMarker(state, nextLine)) >= 0) { + isOrdered = true; + start = state.bMarks[nextLine] + state.tShift[nextLine]; + markerValue = Number(state.src.slice(start, posAfterMarker - 1)); + + // If we're starting a new ordered list right after + // a paragraph, it should start with 1. + if (isTerminatingParagraph && markerValue !== 1) return false; + } else if ((posAfterMarker = skipBulletListMarker(state, nextLine)) >= 0) { + isOrdered = false; + } else { + return false; + } + + // If we're starting a new unordered list right after + // a paragraph, first line should not be empty. + if (isTerminatingParagraph) { + if (state.skipSpaces(posAfterMarker) >= state.eMarks[nextLine]) return false; + } + + // For validation mode we can terminate immediately + if (silent) { + return true; + } + + // We should terminate list on style change. Remember first one to compare. + const markerCharCode = state.src.charCodeAt(posAfterMarker - 1); + + // Start list + const listTokIdx = state.tokens.length; + if (isOrdered) { + token = state.push('ordered_list_open', 'ol', 1); + if (markerValue !== 1) { + token.attrs = [['start', markerValue]]; + } + } else { + token = state.push('bullet_list_open', 'ul', 1); + } + const listLines = [nextLine, 0]; + token.map = listLines; + token.markup = String.fromCharCode(markerCharCode); + + // + // Iterate list items + // + + let prevEmptyEnd = false; + const terminatorRules = state.md.block.ruler.getRules('list'); + const oldParentType = state.parentType; + state.parentType = 'list'; + while (nextLine < endLine) { + pos = posAfterMarker; + max = state.eMarks[nextLine]; + const initial = state.sCount[nextLine] + posAfterMarker - (state.bMarks[nextLine] + state.tShift[nextLine]); + let offset = initial; + while (pos < max) { + const ch = state.src.charCodeAt(pos); + if (ch === 0x09) { + offset += 4 - (offset + state.bsCount[nextLine]) % 4; + } else if (ch === 0x20) { + offset++; + } else { + break; + } + pos++; + } + const contentStart = pos; + let indentAfterMarker; + if (contentStart >= max) { + // trimming space in "- \n 3" case, indent is 1 here + indentAfterMarker = 1; + } else { + indentAfterMarker = offset - initial; + } + + // If we have more than 4 spaces, the indent is 1 + // (the rest is just indented code block) + if (indentAfterMarker > 4) { + indentAfterMarker = 1; + } + + // " - test" + // ^^^^^ - calculating total length of this thing + const indent = initial + indentAfterMarker; + + // Run subparser & write tokens + token = state.push('list_item_open', 'li', 1); + token.markup = String.fromCharCode(markerCharCode); + const itemLines = [nextLine, 0]; + token.map = itemLines; + if (isOrdered) { + token.info = state.src.slice(start, posAfterMarker - 1); + } + + // change current state, then restore it after parser subcall + const oldTight = state.tight; + const oldTShift = state.tShift[nextLine]; + const oldSCount = state.sCount[nextLine]; + + // - example list + // ^ listIndent position will be here + // ^ blkIndent position will be here + // + const oldListIndent = state.listIndent; + state.listIndent = state.blkIndent; + state.blkIndent = indent; + state.tight = true; + state.tShift[nextLine] = contentStart - state.bMarks[nextLine]; + state.sCount[nextLine] = offset; + if (contentStart >= max && state.isEmpty(nextLine + 1)) { + // workaround for this case + // (list item is empty, list terminates before "foo"): + // ~~~~~~~~ + // - + // + // foo + // ~~~~~~~~ + state.line = Math.min(state.line + 2, endLine); + } else { + state.md.block.tokenize(state, nextLine, endLine, true); + } + + // If any of list item is tight, mark list as tight + if (!state.tight || prevEmptyEnd) { + tight = false; + } + // Item become loose if finish with empty line, + // but we should filter last element, because it means list finish + prevEmptyEnd = state.line - nextLine > 1 && state.isEmpty(state.line - 1); + state.blkIndent = state.listIndent; + state.listIndent = oldListIndent; + state.tShift[nextLine] = oldTShift; + state.sCount[nextLine] = oldSCount; + state.tight = oldTight; + token = state.push('list_item_close', 'li', -1); + token.markup = String.fromCharCode(markerCharCode); + nextLine = state.line; + itemLines[1] = nextLine; + if (nextLine >= endLine) { + break; + } + + // + // Try to check if list is terminated or continued. + // + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + break; + } + + // fail if terminating block found + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + + // fail if list has another type + if (isOrdered) { + posAfterMarker = skipOrderedListMarker(state, nextLine); + if (posAfterMarker < 0) { + break; + } + start = state.bMarks[nextLine] + state.tShift[nextLine]; + } else { + posAfterMarker = skipBulletListMarker(state, nextLine); + if (posAfterMarker < 0) { + break; + } + } + if (markerCharCode !== state.src.charCodeAt(posAfterMarker - 1)) { + break; + } + } + + // Finalize list + if (isOrdered) { + token = state.push('ordered_list_close', 'ol', -1); + } else { + token = state.push('bullet_list_close', 'ul', -1); + } + token.markup = String.fromCharCode(markerCharCode); + listLines[1] = nextLine; + state.line = nextLine; + state.parentType = oldParentType; + + // mark paragraphs tight if needed + if (tight) { + markTightParagraphs(state, listTokIdx); + } + return true; +} + +function reference(state, startLine, _endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + let nextLine = startLine + 1; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (state.src.charCodeAt(pos) !== 0x5B /* [ */) { + return false; + } + function getNextLine(nextLine) { + const endLine = state.lineMax; + if (nextLine >= endLine || state.isEmpty(nextLine)) { + // empty line or end of input + return null; + } + let isContinuation = false; + + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + isContinuation = true; + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + isContinuation = true; + } + if (!isContinuation) { + const terminatorRules = state.md.block.ruler.getRules('reference'); + const oldParentType = state.parentType; + state.parentType = 'reference'; + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + state.parentType = oldParentType; + if (terminate) { + // terminated by another block + return null; + } + } + const pos = state.bMarks[nextLine] + state.tShift[nextLine]; + const max = state.eMarks[nextLine]; + + // max + 1 explicitly includes the newline + return state.src.slice(pos, max + 1); + } + let str = state.src.slice(pos, max + 1); + max = str.length; + let labelEnd = -1; + for (pos = 1; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x5B /* [ */) { + return false; + } else if (ch === 0x5D /* ] */) { + labelEnd = pos; + break; + } else if (ch === 0x0A /* \n */) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (ch === 0x5C /* \ */) { + pos++; + if (pos < max && str.charCodeAt(pos) === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } + } + } + if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 0x3A /* : */) { + return false; + } + + // [label]: destination 'title' + // ^^^ skip optional whitespace here + for (pos = labelEnd + 2; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (isSpace(ch)) ; else { + break; + } + } + + // [label]: destination 'title' + // ^^^^^^^^^^^ parse this + const destRes = state.md.helpers.parseLinkDestination(str, pos, max); + if (!destRes.ok) { + return false; + } + const href = state.md.normalizeLink(destRes.str); + if (!state.md.validateLink(href)) { + return false; + } + pos = destRes.pos; + + // save cursor state, we could require to rollback later + const destEndPos = pos; + const destEndLineNo = nextLine; + + // [label]: destination 'title' + // ^^^ skipping those spaces + const start = pos; + for (; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (isSpace(ch)) ; else { + break; + } + } + + // [label]: destination 'title' + // ^^^^^^^ parse this + let titleRes = state.md.helpers.parseLinkTitle(str, pos, max); + while (titleRes.can_continue) { + const lineContent = getNextLine(nextLine); + if (lineContent === null) break; + str += lineContent; + pos = max; + max = str.length; + nextLine++; + titleRes = state.md.helpers.parseLinkTitle(str, pos, max, titleRes); + } + let title; + if (pos < max && start !== pos && titleRes.ok) { + title = titleRes.str; + pos = titleRes.pos; + } else { + title = ''; + pos = destEndPos; + nextLine = destEndLineNo; + } + + // skip trailing spaces until the rest of the line + while (pos < max) { + const ch = str.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + pos++; + } + if (pos < max && str.charCodeAt(pos) !== 0x0A) { + if (title) { + // garbage at the end of the line after title, + // but it could still be a valid reference if we roll back + title = ''; + pos = destEndPos; + nextLine = destEndLineNo; + while (pos < max) { + const ch = str.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + pos++; + } + } + } + if (pos < max && str.charCodeAt(pos) !== 0x0A) { + // garbage at the end of the line + return false; + } + const label = normalizeReference(str.slice(1, labelEnd)); + if (!label) { + // CommonMark 0.20 disallows empty labels + return false; + } + + // Reference can not terminate anything. This check is for safety only. + /* istanbul ignore if */ + if (silent) { + return true; + } + if (typeof state.env.references === 'undefined') { + state.env.references = {}; + } + if (typeof state.env.references[label] === 'undefined') { + state.env.references[label] = { + title, + href + }; + } + state.line = nextLine; + return true; +} + +// List of valid html blocks names, according to commonmark spec +// https://spec.commonmark.org/0.30/#html-blocks + +var block_names = ['address', 'article', 'aside', 'base', 'basefont', 'blockquote', 'body', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dialog', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'iframe', 'legend', 'li', 'link', 'main', 'menu', 'menuitem', 'nav', 'noframes', 'ol', 'optgroup', 'option', 'p', 'param', 'search', 'section', 'summary', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']; + +// Regexps to match html elements + +const attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; +const unquoted = '[^"\'=<>`\\x00-\\x20]+'; +const single_quoted = "'[^']*'"; +const double_quoted = '"[^"]*"'; +const attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')'; +const attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)'; +const open_tag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>'; +const close_tag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>'; +const comment = ''; +const processing = '<[?][\\s\\S]*?[?]>'; +const declaration = ']*>'; +const cdata = ''; +const HTML_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + '|' + comment + '|' + processing + '|' + declaration + '|' + cdata + ')'); +const HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')'); + +// HTML block + + +// An array of opening and corresponding closing sequences for html tags, +// last argument defines whether it can terminate a paragraph or not +// +const HTML_SEQUENCES = [[/^<(script|pre|style|textarea)(?=(\s|>|$))/i, /<\/(script|pre|style|textarea)>/i, true], [/^/, true], [/^<\?/, /\?>/, true], [/^/, true], [/^/, true], [new RegExp('^|$))', 'i'), /^$/, true], [new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false]]; +function html_block(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (!state.md.options.html) { + return false; + } + if (state.src.charCodeAt(pos) !== 0x3C /* < */) { + return false; + } + let lineText = state.src.slice(pos, max); + let i = 0; + for (; i < HTML_SEQUENCES.length; i++) { + if (HTML_SEQUENCES[i][0].test(lineText)) { + break; + } + } + if (i === HTML_SEQUENCES.length) { + return false; + } + if (silent) { + // true if this sequence can be a terminator, false otherwise + return HTML_SEQUENCES[i][2]; + } + let nextLine = startLine + 1; + + // If we are here - we detected HTML block. + // Let's roll down till block end. + if (!HTML_SEQUENCES[i][1].test(lineText)) { + for (; nextLine < endLine; nextLine++) { + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + pos = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + lineText = state.src.slice(pos, max); + if (HTML_SEQUENCES[i][1].test(lineText)) { + if (lineText.length !== 0) { + nextLine++; + } + break; + } + } + } + state.line = nextLine; + const token = state.push('html_block', '', 0); + token.map = [startLine, nextLine]; + token.content = state.getLines(startLine, nextLine, state.blkIndent, true); + return true; +} + +// heading (#, ##, ...) + +function heading(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + let ch = state.src.charCodeAt(pos); + if (ch !== 0x23 /* # */ || pos >= max) { + return false; + } + + // count heading level + let level = 1; + ch = state.src.charCodeAt(++pos); + while (ch === 0x23 /* # */ && pos < max && level <= 6) { + level++; + ch = state.src.charCodeAt(++pos); + } + if (level > 6 || pos < max && !isSpace(ch)) { + return false; + } + if (silent) { + return true; + } + + // Let's cut tails like ' ### ' from the end of string + + max = state.skipSpacesBack(max, pos); + const tmp = state.skipCharsBack(max, 0x23, pos); // # + if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) { + max = tmp; + } + state.line = startLine + 1; + const token_o = state.push('heading_open', 'h' + String(level), 1); + token_o.markup = '########'.slice(0, level); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = state.src.slice(pos, max).trim(); + token_i.map = [startLine, state.line]; + token_i.children = []; + const token_c = state.push('heading_close', 'h' + String(level), -1); + token_c.markup = '########'.slice(0, level); + return true; +} + +// lheading (---, ===) + +function lheading(state, startLine, endLine /*, silent */) { + const terminatorRules = state.md.block.ruler.getRules('paragraph'); + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + const oldParentType = state.parentType; + state.parentType = 'paragraph'; // use paragraph to match terminatorRules + + // jump line-by-line until empty one or EOF + let level = 0; + let marker; + let nextLine = startLine + 1; + for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + continue; + } + + // + // Check for underline in setext header + // + if (state.sCount[nextLine] >= state.blkIndent) { + let pos = state.bMarks[nextLine] + state.tShift[nextLine]; + const max = state.eMarks[nextLine]; + if (pos < max) { + marker = state.src.charCodeAt(pos); + if (marker === 0x2D /* - */ || marker === 0x3D /* = */) { + pos = state.skipChars(pos, marker); + pos = state.skipSpaces(pos); + if (pos >= max) { + level = marker === 0x3D /* = */ ? 1 : 2; + break; + } + } + } + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + continue; + } + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + } + if (!level) { + // Didn't find valid underline + return false; + } + const content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); + state.line = nextLine + 1; + const token_o = state.push('heading_open', 'h' + String(level), 1); + token_o.markup = String.fromCharCode(marker); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = content; + token_i.map = [startLine, state.line - 1]; + token_i.children = []; + const token_c = state.push('heading_close', 'h' + String(level), -1); + token_c.markup = String.fromCharCode(marker); + state.parentType = oldParentType; + return true; +} + +// Paragraph + +function paragraph(state, startLine, endLine) { + const terminatorRules = state.md.block.ruler.getRules('paragraph'); + const oldParentType = state.parentType; + let nextLine = startLine + 1; + state.parentType = 'paragraph'; + + // jump line-by-line until empty one or EOF + for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + continue; + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + continue; + } + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + } + const content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); + state.line = nextLine; + const token_o = state.push('paragraph_open', 'p', 1); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = content; + token_i.map = [startLine, state.line]; + token_i.children = []; + state.push('paragraph_close', 'p', -1); + state.parentType = oldParentType; + return true; +} + +/** internal + * class ParserBlock + * + * Block-level tokenizer. + **/ + +const _rules$1 = [ +// First 2 params - rule name & source. Secondary array - list of rules, +// which can be terminated by this one. +['table', table, ['paragraph', 'reference']], ['code', code], ['fence', fence, ['paragraph', 'reference', 'blockquote', 'list']], ['blockquote', blockquote, ['paragraph', 'reference', 'blockquote', 'list']], ['hr', hr, ['paragraph', 'reference', 'blockquote', 'list']], ['list', list, ['paragraph', 'reference', 'blockquote']], ['reference', reference], ['html_block', html_block, ['paragraph', 'reference', 'blockquote']], ['heading', heading, ['paragraph', 'reference', 'blockquote']], ['lheading', lheading], ['paragraph', paragraph]]; + +/** + * new ParserBlock() + **/ +function ParserBlock() { + /** + * ParserBlock#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of block rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules$1.length; i++) { + this.ruler.push(_rules$1[i][0], _rules$1[i][1], { + alt: (_rules$1[i][2] || []).slice() + }); + } +} + +// Generate tokens for input range +// +ParserBlock.prototype.tokenize = function (state, startLine, endLine) { + const rules = this.ruler.getRules(''); + const len = rules.length; + const maxNesting = state.md.options.maxNesting; + let line = startLine; + let hasEmptyLines = false; + while (line < endLine) { + state.line = line = state.skipEmptyLines(line); + if (line >= endLine) { + break; + } + + // Termination condition for nested calls. + // Nested calls currently used for blockquotes & lists + if (state.sCount[line] < state.blkIndent) { + break; + } + + // If nesting level exceeded - skip tail to the end. That's not ordinary + // situation and we should not care about content. + if (state.level >= maxNesting) { + state.line = endLine; + break; + } + + // Try all possible rules. + // On success, rule should: + // + // - update `state.line` + // - update `state.tokens` + // - return true + const prevLine = state.line; + let ok = false; + for (let i = 0; i < len; i++) { + ok = rules[i](state, line, endLine, false); + if (ok) { + if (prevLine >= state.line) { + throw new Error("block rule didn't increment state.line"); + } + break; + } + } + + // this can only happen if user disables paragraph rule + if (!ok) throw new Error('none of the block rules matched'); + + // set state.tight if we had an empty line before current tag + // i.e. latest empty line should not count + state.tight = !hasEmptyLines; + + // paragraph might "eat" one newline after it in nested lists + if (state.isEmpty(state.line - 1)) { + hasEmptyLines = true; + } + line = state.line; + if (line < endLine && state.isEmpty(line)) { + hasEmptyLines = true; + line++; + state.line = line; + } + } +}; + +/** + * ParserBlock.parse(str, md, env, outTokens) + * + * Process input string and push block tokens into `outTokens` + **/ +ParserBlock.prototype.parse = function (src, md, env, outTokens) { + if (!src) { + return; + } + const state = new this.State(src, md, env, outTokens); + this.tokenize(state, state.line, state.lineMax); +}; +ParserBlock.prototype.State = StateBlock; + +// Inline parser state + +function StateInline(src, md, env, outTokens) { + this.src = src; + this.env = env; + this.md = md; + this.tokens = outTokens; + this.tokens_meta = Array(outTokens.length); + this.pos = 0; + this.posMax = this.src.length; + this.level = 0; + this.pending = ''; + this.pendingLevel = 0; + + // Stores { start: end } pairs. Useful for backtrack + // optimization of pairs parse (emphasis, strikes). + this.cache = {}; + + // List of emphasis-like delimiters for current tag + this.delimiters = []; + + // Stack of delimiter lists for upper level tags + this._prev_delimiters = []; + + // backtick length => last seen position + this.backticks = {}; + this.backticksScanned = false; + + // Counter used to disable inline linkify-it execution + // inside and markdown links + this.linkLevel = 0; +} + +// Flush pending text +// +StateInline.prototype.pushPending = function () { + const token = new Token('text', '', 0); + token.content = this.pending; + token.level = this.pendingLevel; + this.tokens.push(token); + this.pending = ''; + return token; +}; + +// Push new token to "stream". +// If pending text exists - flush it as text token +// +StateInline.prototype.push = function (type, tag, nesting) { + if (this.pending) { + this.pushPending(); + } + const token = new Token(type, tag, nesting); + let token_meta = null; + if (nesting < 0) { + // closing tag + this.level--; + this.delimiters = this._prev_delimiters.pop(); + } + token.level = this.level; + if (nesting > 0) { + // opening tag + this.level++; + this._prev_delimiters.push(this.delimiters); + this.delimiters = []; + token_meta = { + delimiters: this.delimiters + }; + } + this.pendingLevel = this.level; + this.tokens.push(token); + this.tokens_meta.push(token_meta); + return token; +}; + +// Scan a sequence of emphasis-like markers, and determine whether +// it can start an emphasis sequence or end an emphasis sequence. +// +// - start - position to scan from (it should point at a valid marker); +// - canSplitWord - determine if these markers can be found inside a word +// +StateInline.prototype.scanDelims = function (start, canSplitWord) { + const max = this.posMax; + const marker = this.src.charCodeAt(start); + + // treat beginning of the line as a whitespace + const lastChar = start > 0 ? this.src.charCodeAt(start - 1) : 0x20; + let pos = start; + while (pos < max && this.src.charCodeAt(pos) === marker) { + pos++; + } + const count = pos - start; + + // treat end of the line as a whitespace + const nextChar = pos < max ? this.src.charCodeAt(pos) : 0x20; + const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)); + const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)); + const isLastWhiteSpace = isWhiteSpace(lastChar); + const isNextWhiteSpace = isWhiteSpace(nextChar); + const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar); + const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar); + const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar); + const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar); + return { + can_open, + can_close, + length: count + }; +}; + +// re-export Token class to use in block rules +StateInline.prototype.Token = Token; + +// Skip text characters for text token, place those to pending buffer +// and increment current pos + +// Rule to skip pure text +// '{}$%@~+=:' reserved for extentions + +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ + +// !!!! Don't confuse with "Markdown ASCII Punctuation" chars +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +function isTerminatorChar(ch) { + switch (ch) { + case 0x0A /* \n */: + case 0x21 /* ! */: + case 0x23 /* # */: + case 0x24 /* $ */: + case 0x25 /* % */: + case 0x26 /* & */: + case 0x2A /* * */: + case 0x2B /* + */: + case 0x2D /* - */: + case 0x3A /* : */: + case 0x3C /* < */: + case 0x3D /* = */: + case 0x3E /* > */: + case 0x40 /* @ */: + case 0x5B /* [ */: + case 0x5C /* \ */: + case 0x5D /* ] */: + case 0x5E /* ^ */: + case 0x5F /* _ */: + case 0x60 /* ` */: + case 0x7B /* { */: + case 0x7D /* } */: + case 0x7E /* ~ */: + return true; + default: + return false; + } +} +function text(state, silent) { + let pos = state.pos; + while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) { + pos++; + } + if (pos === state.pos) { + return false; + } + if (!silent) { + state.pending += state.src.slice(state.pos, pos); + } + state.pos = pos; + return true; +} + +// Alternative implementation, for memory. +// +// It costs 10% of performance, but allows extend terminators list, if place it +// to `ParserInline` property. Probably, will switch to it sometime, such +// flexibility required. + +/* +var TERMINATOR_RE = /[\n!#$%&*+\-:<=>@[\\\]^_`{}~]/; + +module.exports = function text(state, silent) { + var pos = state.pos, + idx = state.src.slice(pos).search(TERMINATOR_RE); + + // first char is terminator -> empty text + if (idx === 0) { return false; } + + // no terminator -> text till end of string + if (idx < 0) { + if (!silent) { state.pending += state.src.slice(pos); } + state.pos = state.src.length; + return true; + } + + if (!silent) { state.pending += state.src.slice(pos, pos + idx); } + + state.pos += idx; + + return true; +}; */ + +// Process links like https://example.org/ + +// RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) +const SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i; +function linkify(state, silent) { + if (!state.md.options.linkify) return false; + if (state.linkLevel > 0) return false; + const pos = state.pos; + const max = state.posMax; + if (pos + 3 > max) return false; + if (state.src.charCodeAt(pos) !== 0x3A /* : */) return false; + if (state.src.charCodeAt(pos + 1) !== 0x2F /* / */) return false; + if (state.src.charCodeAt(pos + 2) !== 0x2F /* / */) return false; + const match = state.pending.match(SCHEME_RE); + if (!match) return false; + const proto = match[1]; + const link = state.md.linkify.matchAtStart(state.src.slice(pos - proto.length)); + if (!link) return false; + let url = link.url; + + // invalid link, but still detected by linkify somehow; + // need to check to prevent infinite loop below + if (url.length <= proto.length) return false; + + // disallow '*' at the end of the link (conflicts with emphasis) + url = url.replace(/\*+$/, ''); + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) return false; + if (!silent) { + state.pending = state.pending.slice(0, -proto.length); + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'linkify'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'linkify'; + token_c.info = 'auto'; + } + state.pos += url.length - proto.length; + return true; +} + +// Proceess '\n' + +function newline(state, silent) { + let pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x0A /* \n */) { + return false; + } + const pmax = state.pending.length - 1; + const max = state.posMax; + + // ' \n' -> hardbreak + // Lookup in pending chars is bad practice! Don't copy to other rules! + // Pending string is stored in concat mode, indexed lookups will cause + // convertion to flat mode. + if (!silent) { + if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) { + if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) { + // Find whitespaces tail of pending chars. + let ws = pmax - 1; + while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 0x20) ws--; + state.pending = state.pending.slice(0, ws); + state.push('hardbreak', 'br', 0); + } else { + state.pending = state.pending.slice(0, -1); + state.push('softbreak', 'br', 0); + } + } else { + state.push('softbreak', 'br', 0); + } + } + pos++; + + // skip heading spaces for next line + while (pos < max && isSpace(state.src.charCodeAt(pos))) { + pos++; + } + state.pos = pos; + return true; +} + +// Process escaped chars and hardbreaks + +const ESCAPED = []; +for (let i = 0; i < 256; i++) { + ESCAPED.push(0); +} +'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-'.split('').forEach(function (ch) { + ESCAPED[ch.charCodeAt(0)] = 1; +}); +function escape(state, silent) { + let pos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(pos) !== 0x5C /* \ */) return false; + pos++; + + // '\' at the end of the inline block + if (pos >= max) return false; + let ch1 = state.src.charCodeAt(pos); + if (ch1 === 0x0A) { + if (!silent) { + state.push('hardbreak', 'br', 0); + } + pos++; + // skip leading whitespaces from next line + while (pos < max) { + ch1 = state.src.charCodeAt(pos); + if (!isSpace(ch1)) break; + pos++; + } + state.pos = pos; + return true; + } + let escapedStr = state.src[pos]; + if (ch1 >= 0xD800 && ch1 <= 0xDBFF && pos + 1 < max) { + const ch2 = state.src.charCodeAt(pos + 1); + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + escapedStr += state.src[pos + 1]; + pos++; + } + } + const origStr = '\\' + escapedStr; + if (!silent) { + const token = state.push('text_special', '', 0); + if (ch1 < 256 && ESCAPED[ch1] !== 0) { + token.content = escapedStr; + } else { + token.content = origStr; + } + token.markup = origStr; + token.info = 'escape'; + } + state.pos = pos + 1; + return true; +} + +// Parse backticks + +function backtick(state, silent) { + let pos = state.pos; + const ch = state.src.charCodeAt(pos); + if (ch !== 0x60 /* ` */) { + return false; + } + const start = pos; + pos++; + const max = state.posMax; + + // scan marker length + while (pos < max && state.src.charCodeAt(pos) === 0x60 /* ` */) { + pos++; + } + const marker = state.src.slice(start, pos); + const openerLength = marker.length; + if (state.backticksScanned && (state.backticks[openerLength] || 0) <= start) { + if (!silent) state.pending += marker; + state.pos += openerLength; + return true; + } + let matchEnd = pos; + let matchStart; + + // Nothing found in the cache, scan until the end of the line (or until marker is found) + while ((matchStart = state.src.indexOf('`', matchEnd)) !== -1) { + matchEnd = matchStart + 1; + + // scan marker length + while (matchEnd < max && state.src.charCodeAt(matchEnd) === 0x60 /* ` */) { + matchEnd++; + } + const closerLength = matchEnd - matchStart; + if (closerLength === openerLength) { + // Found matching closer length. + if (!silent) { + const token = state.push('code_inline', 'code', 0); + token.markup = marker; + token.content = state.src.slice(pos, matchStart).replace(/\n/g, ' ').replace(/^ (.+) $/, '$1'); + } + state.pos = matchEnd; + return true; + } + + // Some different length found, put it in cache as upper limit of where closer can be found + state.backticks[closerLength] = matchStart; + } + + // Scanned through the end, didn't find anything + state.backticksScanned = true; + if (!silent) state.pending += marker; + state.pos += openerLength; + return true; +} + +// ~~strike through~~ +// + +// Insert each marker as a separate text token, and add it to delimiter list +// +function strikethrough_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent) { + return false; + } + if (marker !== 0x7E /* ~ */) { + return false; + } + const scanned = state.scanDelims(state.pos, true); + let len = scanned.length; + const ch = String.fromCharCode(marker); + if (len < 2) { + return false; + } + let token; + if (len % 2) { + token = state.push('text', '', 0); + token.content = ch; + len--; + } + for (let i = 0; i < len; i += 2) { + token = state.push('text', '', 0); + token.content = ch + ch; + state.delimiters.push({ + marker, + length: 0, + // disable "rule of 3" length checks meant for emphasis + token: state.tokens.length - 1, + end: -1, + open: scanned.can_open, + close: scanned.can_close + }); + } + state.pos += scanned.length; + return true; +} +function postProcess$1(state, delimiters) { + let token; + const loneMarkers = []; + const max = delimiters.length; + for (let i = 0; i < max; i++) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x7E /* ~ */) { + continue; + } + if (startDelim.end === -1) { + continue; + } + const endDelim = delimiters[startDelim.end]; + token = state.tokens[startDelim.token]; + token.type = 's_open'; + token.tag = 's'; + token.nesting = 1; + token.markup = '~~'; + token.content = ''; + token = state.tokens[endDelim.token]; + token.type = 's_close'; + token.tag = 's'; + token.nesting = -1; + token.markup = '~~'; + token.content = ''; + if (state.tokens[endDelim.token - 1].type === 'text' && state.tokens[endDelim.token - 1].content === '~') { + loneMarkers.push(endDelim.token - 1); + } + } + + // If a marker sequence has an odd number of characters, it's splitted + // like this: `~~~~~` -> `~` + `~~` + `~~`, leaving one marker at the + // start of the sequence. + // + // So, we have to move all those markers after subsequent s_close tags. + // + while (loneMarkers.length) { + const i = loneMarkers.pop(); + let j = i + 1; + while (j < state.tokens.length && state.tokens[j].type === 's_close') { + j++; + } + j--; + if (i !== j) { + token = state.tokens[j]; + state.tokens[j] = state.tokens[i]; + state.tokens[i] = token; + } + } +} + +// Walk through delimiter list and replace text tokens with tags +// +function strikethrough_postProcess(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess$1(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + postProcess$1(state, tokens_meta[curr].delimiters); + } + } +} +var r_strikethrough = { + tokenize: strikethrough_tokenize, + postProcess: strikethrough_postProcess +}; + +// Process *this* and _that_ +// + +// Insert each marker as a separate text token, and add it to delimiter list +// +function emphasis_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent) { + return false; + } + if (marker !== 0x5F /* _ */ && marker !== 0x2A /* * */) { + return false; + } + const scanned = state.scanDelims(state.pos, marker === 0x2A); + for (let i = 0; i < scanned.length; i++) { + const token = state.push('text', '', 0); + token.content = String.fromCharCode(marker); + state.delimiters.push({ + // Char code of the starting marker (number). + // + marker, + // Total length of these series of delimiters. + // + length: scanned.length, + // A position of the token this delimiter corresponds to. + // + token: state.tokens.length - 1, + // If this delimiter is matched as a valid opener, `end` will be + // equal to its position, otherwise it's `-1`. + // + end: -1, + // Boolean flags that determine if this delimiter could open or close + // an emphasis. + // + open: scanned.can_open, + close: scanned.can_close + }); + } + state.pos += scanned.length; + return true; +} +function postProcess(state, delimiters) { + const max = delimiters.length; + for (let i = max - 1; i >= 0; i--) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x5F /* _ */ && startDelim.marker !== 0x2A /* * */) { + continue; + } + + // Process only opening markers + if (startDelim.end === -1) { + continue; + } + const endDelim = delimiters[startDelim.end]; + + // If the previous delimiter has the same marker and is adjacent to this one, + // merge those into one strong delimiter. + // + // `whatever` -> `whatever` + // + const isStrong = i > 0 && delimiters[i - 1].end === startDelim.end + 1 && + // check that first two markers match and adjacent + delimiters[i - 1].marker === startDelim.marker && delimiters[i - 1].token === startDelim.token - 1 && + // check that last two markers are adjacent (we can safely assume they match) + delimiters[startDelim.end + 1].token === endDelim.token + 1; + const ch = String.fromCharCode(startDelim.marker); + const token_o = state.tokens[startDelim.token]; + token_o.type = isStrong ? 'strong_open' : 'em_open'; + token_o.tag = isStrong ? 'strong' : 'em'; + token_o.nesting = 1; + token_o.markup = isStrong ? ch + ch : ch; + token_o.content = ''; + const token_c = state.tokens[endDelim.token]; + token_c.type = isStrong ? 'strong_close' : 'em_close'; + token_c.tag = isStrong ? 'strong' : 'em'; + token_c.nesting = -1; + token_c.markup = isStrong ? ch + ch : ch; + token_c.content = ''; + if (isStrong) { + state.tokens[delimiters[i - 1].token].content = ''; + state.tokens[delimiters[startDelim.end + 1].token].content = ''; + i--; + } + } +} + +// Walk through delimiter list and replace text tokens with tags +// +function emphasis_post_process(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + postProcess(state, tokens_meta[curr].delimiters); + } + } +} +var r_emphasis = { + tokenize: emphasis_tokenize, + postProcess: emphasis_post_process +}; + +// Process [link]( "stuff") + +function link(state, silent) { + let code, label, res, ref; + let href = ''; + let title = ''; + let start = state.pos; + let parseReference = true; + if (state.src.charCodeAt(state.pos) !== 0x5B /* [ */) { + return false; + } + const oldPos = state.pos; + const max = state.posMax; + const labelStart = state.pos + 1; + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true); + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { + return false; + } + let pos = labelEnd + 1; + if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) { + // + // Inline link + // + + // might have found a valid shortcut link, disable reference parsing + parseReference = false; + + // [link]( "title" ) + // ^^ skipping these spaces + pos++; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + if (pos >= max) { + return false; + } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos; + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax); + if (res.ok) { + href = state.md.normalizeLink(res.str); + if (state.md.validateLink(href)) { + pos = res.pos; + } else { + href = ''; + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); + if (pos < max && start !== pos && res.ok) { + title = res.str; + pos = res.pos; + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + } + } + if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) { + // parsing a valid shortcut link failed, fallback to reference + parseReference = true; + } + pos++; + } + if (parseReference) { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { + return false; + } + if (pos < max && state.src.charCodeAt(pos) === 0x5B /* [ */) { + start = pos + 1; + pos = state.md.helpers.parseLinkLabel(state, pos); + if (pos >= 0) { + label = state.src.slice(start, pos++); + } else { + pos = labelEnd + 1; + } + } else { + pos = labelEnd + 1; + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { + label = state.src.slice(labelStart, labelEnd); + } + ref = state.env.references[normalizeReference(label)]; + if (!ref) { + state.pos = oldPos; + return false; + } + href = ref.href; + title = ref.title; + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + state.pos = labelStart; + state.posMax = labelEnd; + const token_o = state.push('link_open', 'a', 1); + const attrs = [['href', href]]; + token_o.attrs = attrs; + if (title) { + attrs.push(['title', title]); + } + state.linkLevel++; + state.md.inline.tokenize(state); + state.linkLevel--; + state.push('link_close', 'a', -1); + } + state.pos = pos; + state.posMax = max; + return true; +} + +// Process ![image]( "title") + +function image(state, silent) { + let code, content, label, pos, ref, res, title, start; + let href = ''; + const oldPos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(state.pos) !== 0x21 /* ! */) { + return false; + } + if (state.src.charCodeAt(state.pos + 1) !== 0x5B /* [ */) { + return false; + } + const labelStart = state.pos + 2; + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false); + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { + return false; + } + pos = labelEnd + 1; + if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) { + // + // Inline link + // + + // [link]( "title" ) + // ^^ skipping these spaces + pos++; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + if (pos >= max) { + return false; + } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos; + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax); + if (res.ok) { + href = state.md.normalizeLink(res.str); + if (state.md.validateLink(href)) { + pos = res.pos; + } else { + href = ''; + } + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); + if (pos < max && start !== pos && res.ok) { + title = res.str; + pos = res.pos; + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + } else { + title = ''; + } + if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) { + state.pos = oldPos; + return false; + } + pos++; + } else { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { + return false; + } + if (pos < max && state.src.charCodeAt(pos) === 0x5B /* [ */) { + start = pos + 1; + pos = state.md.helpers.parseLinkLabel(state, pos); + if (pos >= 0) { + label = state.src.slice(start, pos++); + } else { + pos = labelEnd + 1; + } + } else { + pos = labelEnd + 1; + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { + label = state.src.slice(labelStart, labelEnd); + } + ref = state.env.references[normalizeReference(label)]; + if (!ref) { + state.pos = oldPos; + return false; + } + href = ref.href; + title = ref.title; + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + content = state.src.slice(labelStart, labelEnd); + const tokens = []; + state.md.inline.parse(content, state.md, state.env, tokens); + const token = state.push('image', 'img', 0); + const attrs = [['src', href], ['alt', '']]; + token.attrs = attrs; + token.children = tokens; + token.content = content; + if (title) { + attrs.push(['title', title]); + } + } + state.pos = pos; + state.posMax = max; + return true; +} + +// Process autolinks '' + +/* eslint max-len:0 */ +const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/; +/* eslint-disable-next-line no-control-regex */ +const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/; +function autolink(state, silent) { + let pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x3C /* < */) { + return false; + } + const start = state.pos; + const max = state.posMax; + for (;;) { + if (++pos >= max) return false; + const ch = state.src.charCodeAt(pos); + if (ch === 0x3C /* < */) return false; + if (ch === 0x3E /* > */) break; + } + const url = state.src.slice(start + 1, pos); + if (AUTOLINK_RE.test(url)) { + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) { + return false; + } + if (!silent) { + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'autolink'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'autolink'; + token_c.info = 'auto'; + } + state.pos += url.length + 2; + return true; + } + if (EMAIL_RE.test(url)) { + const fullUrl = state.md.normalizeLink('mailto:' + url); + if (!state.md.validateLink(fullUrl)) { + return false; + } + if (!silent) { + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'autolink'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'autolink'; + token_c.info = 'auto'; + } + state.pos += url.length + 2; + return true; + } + return false; +} + +// Process html tags + +function isLinkOpen(str) { + return /^\s]/i.test(str); +} +function isLinkClose(str) { + return /^<\/a\s*>/i.test(str); +} +function isLetter(ch) { + /* eslint no-bitwise:0 */ + const lc = ch | 0x20; // to lower case + return lc >= 0x61 /* a */ && lc <= 0x7a /* z */; +} +function html_inline(state, silent) { + if (!state.md.options.html) { + return false; + } + + // Check start + const max = state.posMax; + const pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x3C /* < */ || pos + 2 >= max) { + return false; + } + + // Quick fail on second char + const ch = state.src.charCodeAt(pos + 1); + if (ch !== 0x21 /* ! */ && ch !== 0x3F /* ? */ && ch !== 0x2F /* / */ && !isLetter(ch)) { + return false; + } + const match = state.src.slice(pos).match(HTML_TAG_RE); + if (!match) { + return false; + } + if (!silent) { + const token = state.push('html_inline', '', 0); + token.content = match[0]; + if (isLinkOpen(token.content)) state.linkLevel++; + if (isLinkClose(token.content)) state.linkLevel--; + } + state.pos += match[0].length; + return true; +} + +// Process html entity - {, ¯, ", ... + +const DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i; +const NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i; +function entity(state, silent) { + const pos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(pos) !== 0x26 /* & */) return false; + if (pos + 1 >= max) return false; + const ch = state.src.charCodeAt(pos + 1); + if (ch === 0x23 /* # */) { + const match = state.src.slice(pos).match(DIGITAL_RE); + if (match) { + if (!silent) { + const code = match[1][0].toLowerCase() === 'x' ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10); + const token = state.push('text_special', '', 0); + token.content = isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD); + token.markup = match[0]; + token.info = 'entity'; + } + state.pos += match[0].length; + return true; + } + } else { + const match = state.src.slice(pos).match(NAMED_RE); + if (match) { + const decoded = entities.decodeHTML(match[0]); + if (decoded !== match[0]) { + if (!silent) { + const token = state.push('text_special', '', 0); + token.content = decoded; + token.markup = match[0]; + token.info = 'entity'; + } + state.pos += match[0].length; + return true; + } + } + } + return false; +} + +// For each opening emphasis-like marker find a matching closing one +// + +function processDelimiters(delimiters) { + const openersBottom = {}; + const max = delimiters.length; + if (!max) return; + + // headerIdx is the first delimiter of the current (where closer is) delimiter run + let headerIdx = 0; + let lastTokenIdx = -2; // needs any value lower than -1 + const jumps = []; + for (let closerIdx = 0; closerIdx < max; closerIdx++) { + const closer = delimiters[closerIdx]; + jumps.push(0); + + // markers belong to same delimiter run if: + // - they have adjacent tokens + // - AND markers are the same + // + if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) { + headerIdx = closerIdx; + } + lastTokenIdx = closer.token; + + // Length is only used for emphasis-specific "rule of 3", + // if it's not defined (in strikethrough or 3rd party plugins), + // we can default it to 0 to disable those checks. + // + closer.length = closer.length || 0; + if (!closer.close) continue; + + // Previously calculated lower bounds (previous fails) + // for each marker, each delimiter length modulo 3, + // and for whether this closer can be an opener; + // https://github.com/commonmark/cmark/commit/34250e12ccebdc6372b8b49c44fab57c72443460 + /* eslint-disable-next-line no-prototype-builtins */ + if (!openersBottom.hasOwnProperty(closer.marker)) { + openersBottom[closer.marker] = [-1, -1, -1, -1, -1, -1]; + } + const minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + closer.length % 3]; + let openerIdx = headerIdx - jumps[headerIdx] - 1; + let newMinOpenerIdx = openerIdx; + for (; openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) { + const opener = delimiters[openerIdx]; + if (opener.marker !== closer.marker) continue; + if (opener.open && opener.end < 0) { + let isOddMatch = false; + + // from spec: + // + // If one of the delimiters can both open and close emphasis, then the + // sum of the lengths of the delimiter runs containing the opening and + // closing delimiters must not be a multiple of 3 unless both lengths + // are multiples of 3. + // + if (opener.close || closer.open) { + if ((opener.length + closer.length) % 3 === 0) { + if (opener.length % 3 !== 0 || closer.length % 3 !== 0) { + isOddMatch = true; + } + } + } + if (!isOddMatch) { + // If previous delimiter cannot be an opener, we can safely skip + // the entire sequence in future checks. This is required to make + // sure algorithm has linear complexity (see *_*_*_*_*_... case). + // + const lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? jumps[openerIdx - 1] + 1 : 0; + jumps[closerIdx] = closerIdx - openerIdx + lastJump; + jumps[openerIdx] = lastJump; + closer.open = false; + opener.end = closerIdx; + opener.close = false; + newMinOpenerIdx = -1; + // treat next token as start of run, + // it optimizes skips in **<...>**a**<...>** pathological case + lastTokenIdx = -2; + break; + } + } + } + if (newMinOpenerIdx !== -1) { + // If match for this delimiter run failed, we want to set lower bound for + // future lookups. This is required to make sure algorithm has linear + // complexity. + // + // See details here: + // https://github.com/commonmark/cmark/issues/178#issuecomment-270417442 + // + openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length || 0) % 3] = newMinOpenerIdx; + } + } +} +function link_pairs(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + processDelimiters(state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + processDelimiters(tokens_meta[curr].delimiters); + } + } +} + +// Clean up tokens after emphasis and strikethrough postprocessing: +// merge adjacent text nodes into one and re-calculate all token levels +// +// This is necessary because initially emphasis delimiter markers (*, _, ~) +// are treated as their own separate text tokens. Then emphasis rule either +// leaves them as text (needed to merge with adjacent text) or turns them +// into opening/closing tags (which messes up levels inside). +// + +function fragments_join(state) { + let curr, last; + let level = 0; + const tokens = state.tokens; + const max = state.tokens.length; + for (curr = last = 0; curr < max; curr++) { + // re-calculate levels after emphasis/strikethrough turns some text nodes + // into opening/closing tags + if (tokens[curr].nesting < 0) level--; // closing tag + tokens[curr].level = level; + if (tokens[curr].nesting > 0) level++; // opening tag + + if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { + // collapse two adjacent text nodes + tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content; + } else { + if (curr !== last) { + tokens[last] = tokens[curr]; + } + last++; + } + } + if (curr !== last) { + tokens.length = last; + } +} + +/** internal + * class ParserInline + * + * Tokenizes paragraph content. + **/ + + +// Parser rules + +const _rules = [['text', text], ['linkify', linkify], ['newline', newline], ['escape', escape], ['backticks', backtick], ['strikethrough', r_strikethrough.tokenize], ['emphasis', r_emphasis.tokenize], ['link', link], ['image', image], ['autolink', autolink], ['html_inline', html_inline], ['entity', entity]]; + +// `rule2` ruleset was created specifically for emphasis/strikethrough +// post-processing and may be changed in the future. +// +// Don't use this for anything except pairs (plugins working with `balance_pairs`). +// +const _rules2 = [['balance_pairs', link_pairs], ['strikethrough', r_strikethrough.postProcess], ['emphasis', r_emphasis.postProcess], +// rules for pairs separate '**' into its own text tokens, which may be left unused, +// rule below merges unused segments back with the rest of the text +['fragments_join', fragments_join]]; + +/** + * new ParserInline() + **/ +function ParserInline() { + /** + * ParserInline#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of inline rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules.length; i++) { + this.ruler.push(_rules[i][0], _rules[i][1]); + } + + /** + * ParserInline#ruler2 -> Ruler + * + * [[Ruler]] instance. Second ruler used for post-processing + * (e.g. in emphasis-like rules). + **/ + this.ruler2 = new Ruler(); + for (let i = 0; i < _rules2.length; i++) { + this.ruler2.push(_rules2[i][0], _rules2[i][1]); + } +} + +// Skip single token by running all rules in validation mode; +// returns `true` if any rule reported success +// +ParserInline.prototype.skipToken = function (state) { + const pos = state.pos; + const rules = this.ruler.getRules(''); + const len = rules.length; + const maxNesting = state.md.options.maxNesting; + const cache = state.cache; + if (typeof cache[pos] !== 'undefined') { + state.pos = cache[pos]; + return; + } + let ok = false; + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + // Increment state.level and decrement it later to limit recursion. + // It's harmless to do here, because no tokens are created. But ideally, + // we'd need a separate private state variable for this purpose. + // + state.level++; + ok = rules[i](state, true); + state.level--; + if (ok) { + if (pos >= state.pos) { + throw new Error("inline rule didn't increment state.pos"); + } + break; + } + } + } else { + // Too much nesting, just skip until the end of the paragraph. + // + // NOTE: this will cause links to behave incorrectly in the following case, + // when an amount of `[` is exactly equal to `maxNesting + 1`: + // + // [[[[[[[[[[[[[[[[[[[[[foo]() + // + // TODO: remove this workaround when CM standard will allow nested links + // (we can replace it by preventing links from being parsed in + // validation mode) + // + state.pos = state.posMax; + } + if (!ok) { + state.pos++; + } + cache[pos] = state.pos; +}; + +// Generate tokens for input range +// +ParserInline.prototype.tokenize = function (state) { + const rules = this.ruler.getRules(''); + const len = rules.length; + const end = state.posMax; + const maxNesting = state.md.options.maxNesting; + while (state.pos < end) { + // Try all possible rules. + // On success, rule should: + // + // - update `state.pos` + // - update `state.tokens` + // - return true + const prevPos = state.pos; + let ok = false; + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + ok = rules[i](state, false); + if (ok) { + if (prevPos >= state.pos) { + throw new Error("inline rule didn't increment state.pos"); + } + break; + } + } + } + if (ok) { + if (state.pos >= end) { + break; + } + continue; + } + state.pending += state.src[state.pos++]; + } + if (state.pending) { + state.pushPending(); + } +}; + +/** + * ParserInline.parse(str, md, env, outTokens) + * + * Process input string and push inline tokens into `outTokens` + **/ +ParserInline.prototype.parse = function (str, md, env, outTokens) { + const state = new this.State(str, md, env, outTokens); + this.tokenize(state); + const rules = this.ruler2.getRules(''); + const len = rules.length; + for (let i = 0; i < len; i++) { + rules[i](state); + } +}; +ParserInline.prototype.State = StateInline; + +// markdown-it default options + +var cfg_default = { + options: { + // Enable HTML tags in source + html: false, + // Use '/' to close single tags (
) + xhtmlOut: false, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: false, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: true, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with = 0) { + try { + parsed.hostname = punycode.toASCII(parsed.hostname); + } catch (er) {/**/} + } + } + return mdurl__namespace.encode(mdurl__namespace.format(parsed)); +} +function normalizeLinkText(url) { + const parsed = mdurl__namespace.parse(url, true); + if (parsed.hostname) { + // Encode hostnames in urls like: + // `http://host/`, `https://host/`, `mailto:user@host`, `//host/` + // + // We don't encode unknown schemas, because it's likely that we encode + // something we shouldn't (e.g. `skype:name` treated as `skype:host`) + // + if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) { + try { + parsed.hostname = punycode.toUnicode(parsed.hostname); + } catch (er) {/**/} + } + } + + // add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720 + return mdurl__namespace.decode(mdurl__namespace.format(parsed), mdurl__namespace.decode.defaultChars + '%'); +} + +/** + * class MarkdownIt + * + * Main parser/renderer class. + * + * ##### Usage + * + * ```javascript + * // node.js, "classic" way: + * var MarkdownIt = require('markdown-it'), + * md = new MarkdownIt(); + * var result = md.render('# markdown-it rulezz!'); + * + * // node.js, the same, but with sugar: + * var md = require('markdown-it')(); + * var result = md.render('# markdown-it rulezz!'); + * + * // browser without AMD, added to "window" on script load + * // Note, there are no dash. + * var md = window.markdownit(); + * var result = md.render('# markdown-it rulezz!'); + * ``` + * + * Single line rendering, without paragraph wrap: + * + * ```javascript + * var md = require('markdown-it')(); + * var result = md.renderInline('__markdown-it__ rulezz!'); + * ``` + **/ + +/** + * new MarkdownIt([presetName, options]) + * - presetName (String): optional, `commonmark` / `zero` + * - options (Object) + * + * Creates parser instanse with given config. Can be called without `new`. + * + * ##### presetName + * + * MarkdownIt provides named presets as a convenience to quickly + * enable/disable active syntax rules and options for common use cases. + * + * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.mjs) - + * configures parser to strict [CommonMark](http://commonmark.org/) mode. + * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.mjs) - + * similar to GFM, used when no preset name given. Enables all available rules, + * but still without html, typographer & autolinker. + * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.mjs) - + * all rules disabled. Useful to quickly setup your config via `.enable()`. + * For example, when you need only `bold` and `italic` markup and nothing else. + * + * ##### options: + * + * - __html__ - `false`. Set `true` to enable HTML tags in source. Be careful! + * That's not safe! You may need external sanitizer to protect output from XSS. + * It's better to extend features via plugins, instead of enabling HTML. + * - __xhtmlOut__ - `false`. Set `true` to add '/' when closing single tags + * (`
`). This is needed only for full CommonMark compatibility. In real + * world you will need HTML output. + * - __breaks__ - `false`. Set `true` to convert `\n` in paragraphs into `
`. + * - __langPrefix__ - `language-`. CSS language class prefix for fenced blocks. + * Can be useful for external highlighters. + * - __linkify__ - `false`. Set `true` to autoconvert URL-like text to links. + * - __typographer__ - `false`. Set `true` to enable [some language-neutral + * replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs) + + * quotes beautification (smartquotes). + * - __quotes__ - `“”‘’`, String or Array. Double + single quotes replacement + * pairs, when typographer enabled and smartquotes on. For example, you can + * use `'«»„“'` for Russian, `'„“‚‘'` for German, and + * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp). + * - __highlight__ - `null`. Highlighter function for fenced code blocks. + * Highlighter `function (str, lang)` should return escaped HTML. It can also + * return empty string if the source was not changed and should be escaped + * externaly. If result starts with ` or ``): + * + * ```javascript + * var hljs = require('highlight.js') // https://highlightjs.org/ + * + * // Actual default values + * var md = require('markdown-it')({ + * highlight: function (str, lang) { + * if (lang && hljs.getLanguage(lang)) { + * try { + * return '
' +
+ *                hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+ *                '
'; + * } catch (__) {} + * } + * + * return '
' + md.utils.escapeHtml(str) + '
'; + * } + * }); + * ``` + * + **/ +function MarkdownIt(presetName, options) { + if (!(this instanceof MarkdownIt)) { + return new MarkdownIt(presetName, options); + } + if (!options) { + if (!isString(presetName)) { + options = presetName || {}; + presetName = 'default'; + } + } + + /** + * MarkdownIt#inline -> ParserInline + * + * Instance of [[ParserInline]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.inline = new ParserInline(); + + /** + * MarkdownIt#block -> ParserBlock + * + * Instance of [[ParserBlock]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.block = new ParserBlock(); + + /** + * MarkdownIt#core -> Core + * + * Instance of [[Core]] chain executor. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.core = new Core(); + + /** + * MarkdownIt#renderer -> Renderer + * + * Instance of [[Renderer]]. Use it to modify output look. Or to add rendering + * rules for new token types, generated by plugins. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * function myToken(tokens, idx, options, env, self) { + * //... + * return result; + * }; + * + * md.renderer.rules['my_token'] = myToken + * ``` + * + * See [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs). + **/ + this.renderer = new Renderer(); + + /** + * MarkdownIt#linkify -> LinkifyIt + * + * [linkify-it](https://github.com/markdown-it/linkify-it) instance. + * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.mjs) + * rule. + **/ + this.linkify = new LinkifyIt(); + + /** + * MarkdownIt#validateLink(url) -> Boolean + * + * Link validation function. CommonMark allows too much in links. By default + * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas + * except some embedded image types. + * + * You can change this behaviour: + * + * ```javascript + * var md = require('markdown-it')(); + * // enable everything + * md.validateLink = function () { return true; } + * ``` + **/ + this.validateLink = validateLink; + + /** + * MarkdownIt#normalizeLink(url) -> String + * + * Function used to encode link url to a machine-readable format, + * which includes url-encoding, punycode, etc. + **/ + this.normalizeLink = normalizeLink; + + /** + * MarkdownIt#normalizeLinkText(url) -> String + * + * Function used to decode link url to a human-readable format` + **/ + this.normalizeLinkText = normalizeLinkText; + + // Expose utils & helpers for easy acces from plugins + + /** + * MarkdownIt#utils -> utils + * + * Assorted utility functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs). + **/ + this.utils = utils; + + /** + * MarkdownIt#helpers -> helpers + * + * Link components parser functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers). + **/ + this.helpers = assign({}, helpers); + this.options = {}; + this.configure(presetName); + if (options) { + this.set(options); + } +} + +/** chainable + * MarkdownIt.set(options) + * + * Set parser options (in the same format as in constructor). Probably, you + * will never need it, but you can change options after constructor call. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .set({ html: true, breaks: true }) + * .set({ typographer, true }); + * ``` + * + * __Note:__ To achieve the best possible performance, don't modify a + * `markdown-it` instance options on the fly. If you need multiple configurations + * it's best to create multiple instances and initialize each with separate + * config. + **/ +MarkdownIt.prototype.set = function (options) { + assign(this.options, options); + return this; +}; + +/** chainable, internal + * MarkdownIt.configure(presets) + * + * Batch load of all options and compenent settings. This is internal method, + * and you probably will not need it. But if you will - see available presets + * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets) + * + * We strongly recommend to use presets instead of direct config loads. That + * will give better compatibility with next versions. + **/ +MarkdownIt.prototype.configure = function (presets) { + const self = this; + if (isString(presets)) { + const presetName = presets; + presets = config[presetName]; + if (!presets) { + throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name'); + } + } + if (!presets) { + throw new Error('Wrong `markdown-it` preset, can\'t be empty'); + } + if (presets.options) { + self.set(presets.options); + } + if (presets.components) { + Object.keys(presets.components).forEach(function (name) { + if (presets.components[name].rules) { + self[name].ruler.enableOnly(presets.components[name].rules); + } + if (presets.components[name].rules2) { + self[name].ruler2.enableOnly(presets.components[name].rules2); + } + }); + } + return this; +}; + +/** chainable + * MarkdownIt.enable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to enable + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable list or rules. It will automatically find appropriate components, + * containing rules with given names. If rule not found, and `ignoreInvalid` + * not set - throws exception. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .enable(['sub', 'sup']) + * .disable('smartquotes'); + * ``` + **/ +MarkdownIt.prototype.enable = function (list, ignoreInvalid) { + let result = []; + if (!Array.isArray(list)) { + list = [list]; + } + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.enable(list, true)); + }, this); + result = result.concat(this.inline.ruler2.enable(list, true)); + const missed = list.filter(function (name) { + return result.indexOf(name) < 0; + }); + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to enable unknown rule(s): ' + missed); + } + return this; +}; + +/** chainable + * MarkdownIt.disable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * The same as [[MarkdownIt.enable]], but turn specified rules off. + **/ +MarkdownIt.prototype.disable = function (list, ignoreInvalid) { + let result = []; + if (!Array.isArray(list)) { + list = [list]; + } + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.disable(list, true)); + }, this); + result = result.concat(this.inline.ruler2.disable(list, true)); + const missed = list.filter(function (name) { + return result.indexOf(name) < 0; + }); + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to disable unknown rule(s): ' + missed); + } + return this; +}; + +/** chainable + * MarkdownIt.use(plugin, params) + * + * Load specified plugin with given params into current parser instance. + * It's just a sugar to call `plugin(md, params)` with curring. + * + * ##### Example + * + * ```javascript + * var iterator = require('markdown-it-for-inline'); + * var md = require('markdown-it')() + * .use(iterator, 'foo_replace', 'text', function (tokens, idx) { + * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar'); + * }); + * ``` + **/ +MarkdownIt.prototype.use = function (plugin /*, params, ... */) { + const args = [this].concat(Array.prototype.slice.call(arguments, 1)); + plugin.apply(plugin, args); + return this; +}; + +/** internal + * MarkdownIt.parse(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * Parse input string and return list of block tokens (special token type + * "inline" will contain list of inline tokens). You should not call this + * method directly, until you write custom renderer (for example, to produce + * AST). + * + * `env` is used to pass data between "distributed" rules and return additional + * metadata like reference info, needed for the renderer. It also can be used to + * inject data in specific cases. Usually, you will be ok to pass `{}`, + * and then pass updated object to renderer. + **/ +MarkdownIt.prototype.parse = function (src, env) { + if (typeof src !== 'string') { + throw new Error('Input data should be a String'); + } + const state = new this.core.State(src, this, env); + this.core.process(state); + return state.tokens; +}; + +/** + * MarkdownIt.render(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Render markdown string into html. It does all magic for you :). + * + * `env` can be used to inject additional metadata (`{}` by default). + * But you will not need it with high probability. See also comment + * in [[MarkdownIt.parse]]. + **/ +MarkdownIt.prototype.render = function (src, env) { + env = env || {}; + return this.renderer.render(this.parse(src, env), this.options, env); +}; + +/** internal + * MarkdownIt.parseInline(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * The same as [[MarkdownIt.parse]] but skip all block rules. It returns the + * block tokens list with the single `inline` element, containing parsed inline + * tokens in `children` property. Also updates `env` object. + **/ +MarkdownIt.prototype.parseInline = function (src, env) { + const state = new this.core.State(src, this, env); + state.inlineMode = true; + this.core.process(state); + return state.tokens; +}; + +/** + * MarkdownIt.renderInline(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Similar to [[MarkdownIt.render]] but for single paragraph content. Result + * will NOT be wrapped into `

` tags. + **/ +MarkdownIt.prototype.renderInline = function (src, env) { + env = env || {}; + return this.renderer.render(this.parseInline(src, env), this.options, env); +}; + +module.exports = MarkdownIt; + +}); +define("mdurl",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +/* eslint-disable no-bitwise */ + +const decodeCache = {}; + +function getDecodeCache (exclude) { + let cache = decodeCache[exclude]; + if (cache) { return cache } + + cache = decodeCache[exclude] = []; + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i); + cache.push(ch); + } + + for (let i = 0; i < exclude.length; i++) { + const ch = exclude.charCodeAt(i); + cache[ch] = '%' + ('0' + ch.toString(16).toUpperCase()).slice(-2); + } + + return cache +} + +// Decode percent-encoded string. +// +function decode (string, exclude) { + if (typeof exclude !== 'string') { + exclude = decode.defaultChars; + } + + const cache = getDecodeCache(exclude); + + return string.replace(/(%[a-f0-9]{2})+/gi, function (seq) { + let result = ''; + + for (let i = 0, l = seq.length; i < l; i += 3) { + const b1 = parseInt(seq.slice(i + 1, i + 3), 16); + + if (b1 < 0x80) { + result += cache[b1]; + continue + } + + if ((b1 & 0xE0) === 0xC0 && (i + 3 < l)) { + // 110xxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + + if ((b2 & 0xC0) === 0x80) { + const chr = ((b1 << 6) & 0x7C0) | (b2 & 0x3F); + + if (chr < 0x80) { + result += '\ufffd\ufffd'; + } else { + result += String.fromCharCode(chr); + } + + i += 3; + continue + } + } + + if ((b1 & 0xF0) === 0xE0 && (i + 6 < l)) { + // 1110xxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + const b3 = parseInt(seq.slice(i + 7, i + 9), 16); + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) { + const chr = ((b1 << 12) & 0xF000) | ((b2 << 6) & 0xFC0) | (b3 & 0x3F); + + if (chr < 0x800 || (chr >= 0xD800 && chr <= 0xDFFF)) { + result += '\ufffd\ufffd\ufffd'; + } else { + result += String.fromCharCode(chr); + } + + i += 6; + continue + } + } + + if ((b1 & 0xF8) === 0xF0 && (i + 9 < l)) { + // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + const b3 = parseInt(seq.slice(i + 7, i + 9), 16); + const b4 = parseInt(seq.slice(i + 10, i + 12), 16); + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80 && (b4 & 0xC0) === 0x80) { + let chr = ((b1 << 18) & 0x1C0000) | ((b2 << 12) & 0x3F000) | ((b3 << 6) & 0xFC0) | (b4 & 0x3F); + + if (chr < 0x10000 || chr > 0x10FFFF) { + result += '\ufffd\ufffd\ufffd\ufffd'; + } else { + chr -= 0x10000; + result += String.fromCharCode(0xD800 + (chr >> 10), 0xDC00 + (chr & 0x3FF)); + } + + i += 9; + continue + } + } + + result += '\ufffd'; + } + + return result + }) +} + +decode.defaultChars = ';/?:@&=+$,#'; +decode.componentChars = ''; + +const encodeCache = {}; + +// Create a lookup array where anything but characters in `chars` string +// and alphanumeric chars is percent-encoded. +// +function getEncodeCache (exclude) { + let cache = encodeCache[exclude]; + if (cache) { return cache } + + cache = encodeCache[exclude] = []; + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i); + + if (/^[0-9a-z]$/i.test(ch)) { + // always allow unencoded alphanumeric characters + cache.push(ch); + } else { + cache.push('%' + ('0' + i.toString(16).toUpperCase()).slice(-2)); + } + } + + for (let i = 0; i < exclude.length; i++) { + cache[exclude.charCodeAt(i)] = exclude[i]; + } + + return cache +} + +// Encode unsafe characters with percent-encoding, skipping already +// encoded sequences. +// +// - string - string to encode +// - exclude - list of characters to ignore (in addition to a-zA-Z0-9) +// - keepEscaped - don't encode '%' in a correct escape sequence (default: true) +// +function encode (string, exclude, keepEscaped) { + if (typeof exclude !== 'string') { + // encode(string, keepEscaped) + keepEscaped = exclude; + exclude = encode.defaultChars; + } + + if (typeof keepEscaped === 'undefined') { + keepEscaped = true; + } + + const cache = getEncodeCache(exclude); + let result = ''; + + for (let i = 0, l = string.length; i < l; i++) { + const code = string.charCodeAt(i); + + if (keepEscaped && code === 0x25 /* % */ && i + 2 < l) { + if (/^[0-9a-f]{2}$/i.test(string.slice(i + 1, i + 3))) { + result += string.slice(i, i + 3); + i += 2; + continue + } + } + + if (code < 128) { + result += cache[code]; + continue + } + + if (code >= 0xD800 && code <= 0xDFFF) { + if (code >= 0xD800 && code <= 0xDBFF && i + 1 < l) { + const nextCode = string.charCodeAt(i + 1); + if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) { + result += encodeURIComponent(string[i] + string[i + 1]); + i++; + continue + } + } + result += '%EF%BF%BD'; + continue + } + + result += encodeURIComponent(string[i]); + } + + return result +} + +encode.defaultChars = ";/?:@&=+$,-_.!~*'()#"; +encode.componentChars = "-_.!~*'()"; + +function format (url) { + let result = ''; + + result += url.protocol || ''; + result += url.slashes ? '//' : ''; + result += url.auth ? url.auth + '@' : ''; + + if (url.hostname && url.hostname.indexOf(':') !== -1) { + // ipv6 address + result += '[' + url.hostname + ']'; + } else { + result += url.hostname || ''; + } + + result += url.port ? ':' + url.port : ''; + result += url.pathname || ''; + result += url.search || ''; + result += url.hash || ''; + + return result +} + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// +// Changes from joyent/node: +// +// 1. No leading slash in paths, +// e.g. in `url.parse('http://foo?bar')` pathname is ``, not `/` +// +// 2. Backslashes are not replaced with slashes, +// so `http:\\example.org\` is treated like a relative path +// +// 3. Trailing colon is treated like a part of the path, +// i.e. in `http://example.org:foo` pathname is `:foo` +// +// 4. Nothing is URL-encoded in the resulting object, +// (in joyent/node some chars in auth and paths are encoded) +// +// 5. `url.parse()` does not have `parseQueryString` argument +// +// 6. Removed extraneous result properties: `host`, `path`, `query`, etc., +// which can be constructed using other parts of the url. +// + +function Url () { + this.protocol = null; + this.slashes = null; + this.auth = null; + this.port = null; + this.hostname = null; + this.hash = null; + this.search = null; + this.pathname = null; +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +const protocolPattern = /^([a-z0-9.+-]+:)/i; +const portPattern = /:[0-9]*$/; + +// Special case for a simple path URL +/* eslint-disable-next-line no-useless-escape */ +const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/; + +// RFC 2396: characters reserved for delimiting URLs. +// We actually just auto-escape these. +const delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t']; + +// RFC 2396: characters not allowed for various reasons. +const unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims); + +// Allowed by RFCs, but cause of XSS attacks. Always escape these. +const autoEscape = ['\''].concat(unwise); +// Characters that are never ever allowed in a hostname. +// Note that any invalid chars are also handled, but these +// are the ones that are *expected* to be seen, so we fast-path +// them. +const nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape); +const hostEndingChars = ['/', '?', '#']; +const hostnameMaxLen = 255; +const hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/; +const hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/; +// protocols that can allow "unsafe" and "unwise" chars. +// protocols that never have a hostname. +const hostlessProtocol = { + javascript: true, + 'javascript:': true +}; +// protocols that always contain a // bit. +const slashedProtocol = { + http: true, + https: true, + ftp: true, + gopher: true, + file: true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true +}; + +function urlParse (url, slashesDenoteHost) { + if (url && url instanceof Url) return url + + const u = new Url(); + u.parse(url, slashesDenoteHost); + return u +} + +Url.prototype.parse = function (url, slashesDenoteHost) { + let lowerProto, hec, slashes; + let rest = url; + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim(); + + if (!slashesDenoteHost && url.split('#').length === 1) { + // Try fast path regexp + const simplePath = simplePathPattern.exec(rest); + if (simplePath) { + this.pathname = simplePath[1]; + if (simplePath[2]) { + this.search = simplePath[2]; + } + return this + } + } + + let proto = protocolPattern.exec(rest); + if (proto) { + proto = proto[0]; + lowerProto = proto.toLowerCase(); + this.protocol = proto; + rest = rest.substr(proto.length); + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + /* eslint-disable-next-line no-useless-escape */ + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + slashes = rest.substr(0, 2) === '//'; + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2); + this.slashes = true; + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + let hostEnd = -1; + for (let i = 0; i < hostEndingChars.length; i++) { + hec = rest.indexOf(hostEndingChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec; + } + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + let auth, atSign; + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@'); + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd); + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign); + rest = rest.slice(atSign + 1); + this.auth = auth; + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1; + for (let i = 0; i < nonHostChars.length; i++) { + hec = rest.indexOf(nonHostChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec; + } + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) { + hostEnd = rest.length; + } + + if (rest[hostEnd - 1] === ':') { hostEnd--; } + const host = rest.slice(0, hostEnd); + rest = rest.slice(hostEnd); + + // pull out port. + this.parseHost(host); + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || ''; + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + const ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']'; + + // validate a little. + if (!ipv6Hostname) { + const hostparts = this.hostname.split(/\./); + for (let i = 0, l = hostparts.length; i < l; i++) { + const part = hostparts[i]; + if (!part) { continue } + if (!part.match(hostnamePartPattern)) { + let newpart = ''; + for (let j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x'; + } else { + newpart += part[j]; + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + const validParts = hostparts.slice(0, i); + const notHost = hostparts.slice(i + 1); + const bit = part.match(hostnamePartStart); + if (bit) { + validParts.push(bit[1]); + notHost.unshift(bit[2]); + } + if (notHost.length) { + rest = notHost.join('.') + rest; + } + this.hostname = validParts.join('.'); + break + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = ''; + } + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2); + } + } + + // chop off from the tail first. + const hash = rest.indexOf('#'); + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash); + rest = rest.slice(0, hash); + } + const qm = rest.indexOf('?'); + if (qm !== -1) { + this.search = rest.substr(qm); + rest = rest.slice(0, qm); + } + if (rest) { this.pathname = rest; } + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = ''; + } + + return this +}; + +Url.prototype.parseHost = function (host) { + let port = portPattern.exec(host); + if (port) { + port = port[0]; + if (port !== ':') { + this.port = port.substr(1); + } + host = host.substr(0, host.length - port.length); + } + if (host) { this.hostname = host; } +}; + +exports.decode = decode; +exports.encode = encode; +exports.format = format; +exports.parse = urlParse; + +}); +define("orderedmap",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +// ::- Persistent data structure representing an ordered mapping from +// strings to values, with some convenient update methods. +function OrderedMap(content) { + this.content = content; +} + +OrderedMap.prototype = { + constructor: OrderedMap, + + find: function(key) { + for (var i = 0; i < this.content.length; i += 2) + if (this.content[i] === key) return i + return -1 + }, + + // :: (string) → ?any + // Retrieve the value stored under `key`, or return undefined when + // no such key exists. + get: function(key) { + var found = this.find(key); + return found == -1 ? undefined : this.content[found + 1] + }, + + // :: (string, any, ?string) → OrderedMap + // Create a new map by replacing the value of `key` with a new + // value, or adding a binding to the end of the map. If `newKey` is + // given, the key of the binding will be replaced with that key. + update: function(key, value, newKey) { + var self = newKey && newKey != key ? this.remove(newKey) : this; + var found = self.find(key), content = self.content.slice(); + if (found == -1) { + content.push(newKey || key, value); + } else { + content[found + 1] = value; + if (newKey) content[found] = newKey; + } + return new OrderedMap(content) + }, + + // :: (string) → OrderedMap + // Return a map with the given key removed, if it existed. + remove: function(key) { + var found = this.find(key); + if (found == -1) return this + var content = this.content.slice(); + content.splice(found, 2); + return new OrderedMap(content) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the start of the map. + addToStart: function(key, value) { + return new OrderedMap([key, value].concat(this.remove(key).content)) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the end of the map. + addToEnd: function(key, value) { + var content = this.remove(key).content.slice(); + content.push(key, value); + return new OrderedMap(content) + }, + + // :: (string, string, any) → OrderedMap + // Add a key after the given key. If `place` is not found, the new + // key is added to the end. + addBefore: function(place, key, value) { + var without = this.remove(key), content = without.content.slice(); + var found = without.find(place); + content.splice(found == -1 ? content.length : found, 0, key, value); + return new OrderedMap(content) + }, + + // :: ((key: string, value: any)) + // Call the given function for each key/value pair in the map, in + // order. + forEach: function(f) { + for (var i = 0; i < this.content.length; i += 2) + f(this.content[i], this.content[i + 1]); + }, + + // :: (union) → OrderedMap + // Create a new map by prepending the keys in this map that don't + // appear in `map` before the keys in `map`. + prepend: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(map.content.concat(this.subtract(map).content)) + }, + + // :: (union) → OrderedMap + // Create a new map by appending the keys in this map that don't + // appear in `map` after the keys in `map`. + append: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(this.subtract(map).content.concat(map.content)) + }, + + // :: (union) → OrderedMap + // Create a map containing all the keys in this map that don't + // appear in `map`. + subtract: function(map) { + var result = this; + map = OrderedMap.from(map); + for (var i = 0; i < map.content.length; i += 2) + result = result.remove(map.content[i]); + return result + }, + + // :: () → Object + // Turn ordered map into a plain object. + toObject: function() { + var result = {}; + this.forEach(function(key, value) { result[key] = value; }); + return result + }, + + // :: number + // The amount of keys in this map. + get size() { + return this.content.length >> 1 + } +}; + +// :: (?union) → OrderedMap +// Return a map with the given content. If null, create an empty +// map. If given an ordered map, return that map itself. If given an +// object, create a map from the object's properties. +OrderedMap.from = function(value) { + if (value instanceof OrderedMap) return value + var content = []; + if (value) for (var prop in value) content.push(prop, value[prop]); + return new OrderedMap(content) +}; + +module.exports = OrderedMap; + +}); +define("punycode.js",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +/** Highest positive signed 32-bit float value */ +const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 + +/** Bootstring parameters */ +const base = 36; +const tMin = 1; +const tMax = 26; +const skew = 38; +const damp = 700; +const initialBias = 72; +const initialN = 128; // 0x80 +const delimiter = '-'; // '\x2D' + +/** Regular expressions */ +const regexPunycode = /^xn--/; +const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too. +const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators + +/** Error messages */ +const errors = { + 'overflow': 'Overflow: input needs wider integers to process', + 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', + 'invalid-input': 'Invalid input' +}; + +/** Convenience shortcuts */ +const baseMinusTMin = base - tMin; +const floor = Math.floor; +const stringFromCharCode = String.fromCharCode; + +/*--------------------------------------------------------------------------*/ + +/** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ +function error(type) { + throw new RangeError(errors[type]); +} + +/** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ +function map(array, callback) { + const result = []; + let length = array.length; + while (length--) { + result[length] = callback(array[length]); + } + return result; +} + +/** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {String} A new string of characters returned by the callback + * function. + */ +function mapDomain(domain, callback) { + const parts = domain.split('@'); + let result = ''; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + '@'; + domain = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + domain = domain.replace(regexSeparators, '\x2E'); + const labels = domain.split('.'); + const encoded = map(labels, callback).join('.'); + return result + encoded; +} + +/** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ +function ucs2decode(string) { + const output = []; + let counter = 0; + const length = string.length; + while (counter < length) { + const value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + // It's a high surrogate, and there is a next character. + const extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { // Low surrogate. + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + // It's an unmatched surrogate; only append this code unit, in case the + // next code unit is the high surrogate of a surrogate pair. + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; +} + +/** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ +const ucs2encode = codePoints => String.fromCodePoint(...codePoints); + +/** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ +const basicToDigit = function(codePoint) { + if (codePoint >= 0x30 && codePoint < 0x3A) { + return 26 + (codePoint - 0x30); + } + if (codePoint >= 0x41 && codePoint < 0x5B) { + return codePoint - 0x41; + } + if (codePoint >= 0x61 && codePoint < 0x7B) { + return codePoint - 0x61; + } + return base; +}; + +/** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ +const digitToBasic = function(digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); +}; + +/** + * Bias adaptation function as per section 3.4 of RFC 3492. + * https://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ +const adapt = function(delta, numPoints, firstTime) { + let k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); +}; + +/** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ +const decode = function(input) { + // Don't use UCS-2. + const output = []; + const inputLength = input.length; + let i = 0; + let n = initialN; + let bias = initialBias; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + let basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + + for (let j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 0x80) { + error('not-basic'); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + const oldi = i; + for (let w = 1, k = base; /* no condition */; k += base) { + + if (index >= inputLength) { + error('invalid-input'); + } + + const digit = basicToDigit(input.charCodeAt(index++)); + + if (digit >= base) { + error('invalid-input'); + } + if (digit > floor((maxInt - i) / w)) { + error('overflow'); + } + + i += digit * w; + const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + + if (digit < t) { + break; + } + + const baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error('overflow'); + } + + w *= baseMinusT; + + } + + const out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error('overflow'); + } + + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output. + output.splice(i++, 0, n); + + } + + return String.fromCodePoint(...output); +}; + +/** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ +const encode = function(input) { + const output = []; + + // Convert the input in UCS-2 to an array of Unicode code points. + input = ucs2decode(input); + + // Cache the length. + const inputLength = input.length; + + // Initialize the state. + let n = initialN; + let delta = 0; + let bias = initialBias; + + // Handle the basic code points. + for (const currentValue of input) { + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); + } + } + + const basicLength = output.length; + let handledCPCount = basicLength; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string with a delimiter unless it's empty. + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + + // All non-basic code points < n have been handled already. Find the next + // larger one: + let m = maxInt; + for (const currentValue of input) { + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow. + const handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error('overflow'); + } + + delta += (m - n) * handledCPCountPlusOne; + n = m; + + for (const currentValue of input) { + if (currentValue < n && ++delta > maxInt) { + error('overflow'); + } + if (currentValue === n) { + // Represent delta as a generalized variable-length integer. + let q = delta; + for (let k = base; /* no condition */; k += base) { + const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + if (q < t) { + break; + } + const qMinusT = q - t; + const baseMinusT = base - t; + output.push( + stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) + ); + q = floor(qMinusT / baseMinusT); + } + + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength); + delta = 0; + ++handledCPCount; + } + } + + ++delta; + ++n; + + } + return output.join(''); +}; + +/** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ +const toUnicode = function(input) { + return mapDomain(input, function(string) { + return regexPunycode.test(string) + ? decode(string.slice(4).toLowerCase()) + : string; + }); +}; + +/** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ +const toASCII = function(input) { + return mapDomain(input, function(string) { + return regexNonASCII.test(string) + ? 'xn--' + encode(string) + : string; + }); +}; + +/*--------------------------------------------------------------------------*/ + +/** Define the public API */ +const punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + 'version': '2.3.1', + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + 'ucs2': { + 'decode': ucs2decode, + 'encode': ucs2encode + }, + 'decode': decode, + 'encode': encode, + 'toASCII': toASCII, + 'toUnicode': toUnicode +}; + +module.exports = punycode; + +}); +define("rope-sequence",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var GOOD_LEAF_SIZE = 200; + +// :: class A rope sequence is a persistent sequence data structure +// that supports appending, prepending, and slicing without doing a +// full copy. It is represented as a mostly-balanced tree. +var RopeSequence = function RopeSequence () {}; + +RopeSequence.prototype.append = function append (other) { + if (!other.length) { return this } + other = RopeSequence.from(other); + + return (!this.length && other) || + (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) || + (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) || + this.appendInner(other) +}; + +// :: (union<[T], RopeSequence>) → RopeSequence +// Prepend an array or other rope to this one, returning a new rope. +RopeSequence.prototype.prepend = function prepend (other) { + if (!other.length) { return this } + return RopeSequence.from(other).append(this) +}; + +RopeSequence.prototype.appendInner = function appendInner (other) { + return new Append(this, other) +}; + +// :: (?number, ?number) → RopeSequence +// Create a rope repesenting a sub-sequence of this rope. +RopeSequence.prototype.slice = function slice (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from >= to) { return RopeSequence.empty } + return this.sliceInner(Math.max(0, from), Math.min(this.length, to)) +}; + +// :: (number) → T +// Retrieve the element at the given position from this rope. +RopeSequence.prototype.get = function get (i) { + if (i < 0 || i >= this.length) { return undefined } + return this.getInner(i) +}; + +// :: ((element: T, index: number) → ?bool, ?number, ?number) +// Call the given function for each element between the given +// indices. This tends to be more efficient than looping over the +// indices and calling `get`, because it doesn't have to descend the +// tree for every element. +RopeSequence.prototype.forEach = function forEach (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from <= to) + { this.forEachInner(f, from, to, 0); } + else + { this.forEachInvertedInner(f, from, to, 0); } +}; + +// :: ((element: T, index: number) → U, ?number, ?number) → [U] +// Map the given functions over the elements of the rope, producing +// a flat array. +RopeSequence.prototype.map = function map (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + var result = []; + this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to); + return result +}; + +// :: (?union<[T], RopeSequence>) → RopeSequence +// Create a rope representing the given array, or return the rope +// itself if a rope was given. +RopeSequence.from = function from (values) { + if (values instanceof RopeSequence) { return values } + return values && values.length ? new Leaf(values) : RopeSequence.empty +}; + +var Leaf = /*@__PURE__*/(function (RopeSequence) { + function Leaf(values) { + RopeSequence.call(this); + this.values = values; + } + + if ( RopeSequence ) Leaf.__proto__ = RopeSequence; + Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Leaf.prototype.constructor = Leaf; + + var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } }; + + Leaf.prototype.flatten = function flatten () { + return this.values + }; + + Leaf.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + return new Leaf(this.values.slice(from, to)) + }; + + Leaf.prototype.getInner = function getInner (i) { + return this.values[i] + }; + + Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) { + for (var i = from; i < to; i++) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + for (var i = from - 1; i >= to; i--) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.leafAppend = function leafAppend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(this.values.concat(other.flatten())) } + }; + + Leaf.prototype.leafPrepend = function leafPrepend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(other.flatten().concat(this.values)) } + }; + + prototypeAccessors.length.get = function () { return this.values.length }; + + prototypeAccessors.depth.get = function () { return 0 }; + + Object.defineProperties( Leaf.prototype, prototypeAccessors ); + + return Leaf; +}(RopeSequence)); + +// :: RopeSequence +// The empty rope sequence. +RopeSequence.empty = new Leaf([]); + +var Append = /*@__PURE__*/(function (RopeSequence) { + function Append(left, right) { + RopeSequence.call(this); + this.left = left; + this.right = right; + this.length = left.length + right.length; + this.depth = Math.max(left.depth, right.depth) + 1; + } + + if ( RopeSequence ) Append.__proto__ = RopeSequence; + Append.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Append.prototype.constructor = Append; + + Append.prototype.flatten = function flatten () { + return this.left.flatten().concat(this.right.flatten()) + }; + + Append.prototype.getInner = function getInner (i) { + return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length) + }; + + Append.prototype.forEachInner = function forEachInner (f, from, to, start) { + var leftLen = this.left.length; + if (from < leftLen && + this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false) + { return false } + if (to > leftLen && + this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) + { return false } + }; + + Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + var leftLen = this.left.length; + if (from > leftLen && + this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) + { return false } + if (to < leftLen && + this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false) + { return false } + }; + + Append.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + var leftLen = this.left.length; + if (to <= leftLen) { return this.left.slice(from, to) } + if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) } + return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen)) + }; + + Append.prototype.leafAppend = function leafAppend (other) { + var inner = this.right.leafAppend(other); + if (inner) { return new Append(this.left, inner) } + }; + + Append.prototype.leafPrepend = function leafPrepend (other) { + var inner = this.left.leafPrepend(other); + if (inner) { return new Append(inner, this.right) } + }; + + Append.prototype.appendInner = function appendInner (other) { + if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) + { return new Append(this.left, new Append(this.right, other)) } + return new Append(this, other) + }; + + return Append; +}(RopeSequence)); + +module.exports = RopeSequence; + +}); +define("uc.micro",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var regex$5 = /[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; + +var regex$4 = /[\0-\x1F\x7F-\x9F]/; + +var regex$3 = /[\xAD\u0600-\u0605\u061C\u06DD\u070F\u0890\u0891\u08E2\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF\uFFF9-\uFFFB]|\uD804[\uDCBD\uDCCD]|\uD80D[\uDC30-\uDC3F]|\uD82F[\uDCA0-\uDCA3]|\uD834[\uDD73-\uDD7A]|\uDB40[\uDC01\uDC20-\uDC7F]/; + +var regex$2 = /[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/; + +var regex$1 = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC2\uFD40-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA]/; + +var regex = /[ \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/; + +exports.Any = regex$5; +exports.Cc = regex$4; +exports.Cf = regex$3; +exports.P = regex$2; +exports.S = regex$1; +exports.Z = regex; + +}); +define("w3c-keyname",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var base = { + 8: "Backspace", + 9: "Tab", + 10: "Enter", + 12: "NumLock", + 13: "Enter", + 16: "Shift", + 17: "Control", + 18: "Alt", + 20: "CapsLock", + 27: "Escape", + 32: " ", + 33: "PageUp", + 34: "PageDown", + 35: "End", + 36: "Home", + 37: "ArrowLeft", + 38: "ArrowUp", + 39: "ArrowRight", + 40: "ArrowDown", + 44: "PrintScreen", + 45: "Insert", + 46: "Delete", + 59: ";", + 61: "=", + 91: "Meta", + 92: "Meta", + 106: "*", + 107: "+", + 108: ",", + 109: "-", + 110: ".", + 111: "/", + 144: "NumLock", + 145: "ScrollLock", + 160: "Shift", + 161: "Shift", + 162: "Control", + 163: "Control", + 164: "Alt", + 165: "Alt", + 173: "-", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" +}; + +var shift = { + 48: ")", + 49: "!", + 50: "@", + 51: "#", + 52: "$", + 53: "%", + 54: "^", + 55: "&", + 56: "*", + 57: "(", + 59: ":", + 61: "+", + 173: "_", + 186: ":", + 187: "+", + 188: "<", + 189: "_", + 190: ">", + 191: "?", + 192: "~", + 219: "{", + 220: "|", + 221: "}", + 222: "\"" +}; + +var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform); +var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); + +// Fill in the digit keys +for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i); + +// The function keys +for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i; + +// And the alphabetic keys +for (var i = 65; i <= 90; i++) { + base[i] = String.fromCharCode(i + 32); + shift[i] = String.fromCharCode(i); +} + +// For each code that doesn't have a shift-equivalent, copy the base name +for (var code in base) if (!shift.hasOwnProperty(code)) shift[code] = base[code]; + +function keyName(event) { + // On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`. + // On IE, shift effect is never included in `.key`. + var ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || + ie && event.shiftKey && event.key && event.key.length == 1 || + event.key == "Unidentified"; + var name = (!ignoreKey && event.key) || + (event.shiftKey ? shift : base)[event.keyCode] || + event.key || "Unidentified"; + // Edge sometimes produces wrong names (Issue #3) + if (name == "Esc") name = "Escape"; + if (name == "Del") name = "Delete"; + // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/ + if (name == "Left") name = "ArrowLeft"; + if (name == "Up") name = "ArrowUp"; + if (name == "Right") name = "ArrowRight"; + if (name == "Down") name = "ArrowDown"; + return name +} + +exports.base = base; +exports.keyName = keyName; +exports.shift = shift; + +}); +define("entities",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLAttribute = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.DecodingMode = exports.EntityDecoder = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.EntityLevel = void 0; +var decode_js_1 = require("./decode.js"); +var encode_js_1 = require("./encode.js"); +var escape_js_1 = require("./escape.js"); +/** The level of entities to support. */ +var EntityLevel; +(function (EntityLevel) { + /** Support only XML entities. */ + EntityLevel[EntityLevel["XML"] = 0] = "XML"; + /** Support HTML entities, which are a superset of XML entities. */ + EntityLevel[EntityLevel["HTML"] = 1] = "HTML"; +})(EntityLevel = exports.EntityLevel || (exports.EntityLevel = {})); +var EncodingMode; +(function (EncodingMode) { + /** + * The output is UTF-8 encoded. Only characters that need escaping within + * XML will be escaped. + */ + EncodingMode[EncodingMode["UTF8"] = 0] = "UTF8"; + /** + * The output consists only of ASCII characters. Characters that need + * escaping within HTML, and characters that aren't ASCII characters will + * be escaped. + */ + EncodingMode[EncodingMode["ASCII"] = 1] = "ASCII"; + /** + * Encode all characters that have an equivalent entity, as well as all + * characters that are not ASCII characters. + */ + EncodingMode[EncodingMode["Extensive"] = 2] = "Extensive"; + /** + * Encode all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + EncodingMode[EncodingMode["Attribute"] = 3] = "Attribute"; + /** + * Encode all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + EncodingMode[EncodingMode["Text"] = 4] = "Text"; +})(EncodingMode = exports.EncodingMode || (exports.EncodingMode = {})); +/** + * Decodes a string with entities. + * + * @param data String to decode. + * @param options Decoding options. + */ +function decode(data, options) { + if (options === void 0) { options = EntityLevel.XML; } + var level = typeof options === "number" ? options : options.level; + if (level === EntityLevel.HTML) { + var mode = typeof options === "object" ? options.mode : undefined; + return (0, decode_js_1.decodeHTML)(data, mode); + } + return (0, decode_js_1.decodeXML)(data); +} +exports.decode = decode; +/** + * Decodes a string with entities. Does not allow missing trailing semicolons for entities. + * + * @param data String to decode. + * @param options Decoding options. + * @deprecated Use `decode` with the `mode` set to `Strict`. + */ +function decodeStrict(data, options) { + var _a; + if (options === void 0) { options = EntityLevel.XML; } + var opts = typeof options === "number" ? { level: options } : options; + (_a = opts.mode) !== null && _a !== void 0 ? _a : (opts.mode = decode_js_1.DecodingMode.Strict); + return decode(data, opts); +} +exports.decodeStrict = decodeStrict; +/** + * Encodes a string with entities. + * + * @param data String to encode. + * @param options Encoding options. + */ +function encode(data, options) { + if (options === void 0) { options = EntityLevel.XML; } + var opts = typeof options === "number" ? { level: options } : options; + // Mode `UTF8` just escapes XML entities + if (opts.mode === EncodingMode.UTF8) + return (0, escape_js_1.escapeUTF8)(data); + if (opts.mode === EncodingMode.Attribute) + return (0, escape_js_1.escapeAttribute)(data); + if (opts.mode === EncodingMode.Text) + return (0, escape_js_1.escapeText)(data); + if (opts.level === EntityLevel.HTML) { + if (opts.mode === EncodingMode.ASCII) { + return (0, encode_js_1.encodeNonAsciiHTML)(data); + } + return (0, encode_js_1.encodeHTML)(data); + } + // ASCII and Extensive are equivalent + return (0, escape_js_1.encodeXML)(data); +} +exports.encode = encode; +var escape_js_2 = require("./escape.js"); +Object.defineProperty(exports, "encodeXML", { enumerable: true, get: function () { return escape_js_2.encodeXML; } }); +Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return escape_js_2.escape; } }); +Object.defineProperty(exports, "escapeUTF8", { enumerable: true, get: function () { return escape_js_2.escapeUTF8; } }); +Object.defineProperty(exports, "escapeAttribute", { enumerable: true, get: function () { return escape_js_2.escapeAttribute; } }); +Object.defineProperty(exports, "escapeText", { enumerable: true, get: function () { return escape_js_2.escapeText; } }); +var encode_js_2 = require("./encode.js"); +Object.defineProperty(exports, "encodeHTML", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +Object.defineProperty(exports, "encodeNonAsciiHTML", { enumerable: true, get: function () { return encode_js_2.encodeNonAsciiHTML; } }); +// Legacy aliases (deprecated) +Object.defineProperty(exports, "encodeHTML4", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +Object.defineProperty(exports, "encodeHTML5", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +var decode_js_2 = require("./decode.js"); +Object.defineProperty(exports, "EntityDecoder", { enumerable: true, get: function () { return decode_js_2.EntityDecoder; } }); +Object.defineProperty(exports, "DecodingMode", { enumerable: true, get: function () { return decode_js_2.DecodingMode; } }); +Object.defineProperty(exports, "decodeXML", { enumerable: true, get: function () { return decode_js_2.decodeXML; } }); +Object.defineProperty(exports, "decodeHTML", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTMLStrict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeHTMLAttribute", { enumerable: true, get: function () { return decode_js_2.decodeHTMLAttribute; } }); +// Legacy aliases (deprecated) +Object.defineProperty(exports, "decodeHTML4", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTML5", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTML4Strict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeHTML5Strict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeXMLStrict", { enumerable: true, get: function () { return decode_js_2.decodeXML; } }); + +}); +define("entities/decode",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTMLAttribute = exports.decodeHTML = exports.determineBranch = exports.EntityDecoder = exports.DecodingMode = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0; +var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js")); +exports.htmlDecodeTree = decode_data_html_js_1.default; +var decode_data_xml_js_1 = __importDefault(require("./generated/decode-data-xml.js")); +exports.xmlDecodeTree = decode_data_xml_js_1.default; +var decode_codepoint_js_1 = __importStar(require("./decode_codepoint.js")); +exports.decodeCodePoint = decode_codepoint_js_1.default; +var decode_codepoint_js_2 = require("./decode_codepoint.js"); +Object.defineProperty(exports, "replaceCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } }); +Object.defineProperty(exports, "fromCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.fromCodePoint; } }); +var CharCodes; +(function (CharCodes) { + CharCodes[CharCodes["NUM"] = 35] = "NUM"; + CharCodes[CharCodes["SEMI"] = 59] = "SEMI"; + CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS"; + CharCodes[CharCodes["ZERO"] = 48] = "ZERO"; + CharCodes[CharCodes["NINE"] = 57] = "NINE"; + CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A"; + CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F"; + CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X"; + CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z"; + CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A"; + CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F"; + CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z"; +})(CharCodes || (CharCodes = {})); +/** Bit that needs to be set to convert an upper case ASCII character to lower case */ +var TO_LOWER_BIT = 32; +var BinTrieFlags; +(function (BinTrieFlags) { + BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH"; + BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH"; + BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE"; +})(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {})); +function isNumber(code) { + return code >= CharCodes.ZERO && code <= CharCodes.NINE; +} +function isHexadecimalCharacter(code) { + return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F)); +} +function isAsciiAlphaNumeric(code) { + return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) || + isNumber(code)); +} +/** + * Checks if the given character is a valid end character for an entity in an attribute. + * + * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error. + * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state + */ +function isEntityInAttributeInvalidEnd(code) { + return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code); +} +var EntityDecoderState; +(function (EntityDecoderState) { + EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart"; + EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart"; + EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal"; + EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex"; + EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity"; +})(EntityDecoderState || (EntityDecoderState = {})); +var DecodingMode; +(function (DecodingMode) { + /** Entities in text nodes that can end with any character. */ + DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy"; + /** Only allow entities terminated with a semicolon. */ + DecodingMode[DecodingMode["Strict"] = 1] = "Strict"; + /** Entities in attributes have limitations on ending characters. */ + DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute"; +})(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {})); +/** + * Token decoder with support of writing partial entities. + */ +var EntityDecoder = /** @class */ (function () { + function EntityDecoder( + /** The tree used to decode entities. */ + decodeTree, + /** + * The function that is called when a codepoint is decoded. + * + * For multi-byte named entities, this will be called multiple times, + * with the second codepoint, and the same `consumed` value. + * + * @param codepoint The decoded codepoint. + * @param consumed The number of bytes consumed by the decoder. + */ + emitCodePoint, + /** An object that is used to produce errors. */ + errors) { + this.decodeTree = decodeTree; + this.emitCodePoint = emitCodePoint; + this.errors = errors; + /** The current state of the decoder. */ + this.state = EntityDecoderState.EntityStart; + /** Characters that were consumed while parsing an entity. */ + this.consumed = 1; + /** + * The result of the entity. + * + * Either the result index of a numeric entity, or the codepoint of a + * numeric entity. + */ + this.result = 0; + /** The current index in the decode tree. */ + this.treeIndex = 0; + /** The number of characters that were consumed in excess. */ + this.excess = 1; + /** The mode in which the decoder is operating. */ + this.decodeMode = DecodingMode.Strict; + } + /** Resets the instance to make it reusable. */ + EntityDecoder.prototype.startEntity = function (decodeMode) { + this.decodeMode = decodeMode; + this.state = EntityDecoderState.EntityStart; + this.result = 0; + this.treeIndex = 0; + this.excess = 1; + this.consumed = 1; + }; + /** + * Write an entity to the decoder. This can be called multiple times with partial entities. + * If the entity is incomplete, the decoder will return -1. + * + * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the + * entity is incomplete, and resume when the next string is written. + * + * @param string The string containing the entity (or a continuation of the entity). + * @param offset The offset at which the entity begins. Should be 0 if this is not the first call. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.write = function (str, offset) { + switch (this.state) { + case EntityDecoderState.EntityStart: { + if (str.charCodeAt(offset) === CharCodes.NUM) { + this.state = EntityDecoderState.NumericStart; + this.consumed += 1; + return this.stateNumericStart(str, offset + 1); + } + this.state = EntityDecoderState.NamedEntity; + return this.stateNamedEntity(str, offset); + } + case EntityDecoderState.NumericStart: { + return this.stateNumericStart(str, offset); + } + case EntityDecoderState.NumericDecimal: { + return this.stateNumericDecimal(str, offset); + } + case EntityDecoderState.NumericHex: { + return this.stateNumericHex(str, offset); + } + case EntityDecoderState.NamedEntity: { + return this.stateNamedEntity(str, offset); + } + } + }; + /** + * Switches between the numeric decimal and hexadecimal states. + * + * Equivalent to the `Numeric character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericStart = function (str, offset) { + if (offset >= str.length) { + return -1; + } + if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) { + this.state = EntityDecoderState.NumericHex; + this.consumed += 1; + return this.stateNumericHex(str, offset + 1); + } + this.state = EntityDecoderState.NumericDecimal; + return this.stateNumericDecimal(str, offset); + }; + EntityDecoder.prototype.addToNumericResult = function (str, start, end, base) { + if (start !== end) { + var digitCount = end - start; + this.result = + this.result * Math.pow(base, digitCount) + + parseInt(str.substr(start, digitCount), base); + this.consumed += digitCount; + } + }; + /** + * Parses a hexadecimal numeric entity. + * + * Equivalent to the `Hexademical character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericHex = function (str, offset) { + var startIdx = offset; + while (offset < str.length) { + var char = str.charCodeAt(offset); + if (isNumber(char) || isHexadecimalCharacter(char)) { + offset += 1; + } + else { + this.addToNumericResult(str, startIdx, offset, 16); + return this.emitNumericEntity(char, 3); + } + } + this.addToNumericResult(str, startIdx, offset, 16); + return -1; + }; + /** + * Parses a decimal numeric entity. + * + * Equivalent to the `Decimal character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericDecimal = function (str, offset) { + var startIdx = offset; + while (offset < str.length) { + var char = str.charCodeAt(offset); + if (isNumber(char)) { + offset += 1; + } + else { + this.addToNumericResult(str, startIdx, offset, 10); + return this.emitNumericEntity(char, 2); + } + } + this.addToNumericResult(str, startIdx, offset, 10); + return -1; + }; + /** + * Validate and emit a numeric entity. + * + * Implements the logic from the `Hexademical character reference start + * state` and `Numeric character reference end state` in the HTML spec. + * + * @param lastCp The last code point of the entity. Used to see if the + * entity was terminated with a semicolon. + * @param expectedLength The minimum number of characters that should be + * consumed. Used to validate that at least one digit + * was consumed. + * @returns The number of characters that were consumed. + */ + EntityDecoder.prototype.emitNumericEntity = function (lastCp, expectedLength) { + var _a; + // Ensure we consumed at least one digit. + if (this.consumed <= expectedLength) { + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); + return 0; + } + // Figure out if this is a legit end of the entity + if (lastCp === CharCodes.SEMI) { + this.consumed += 1; + } + else if (this.decodeMode === DecodingMode.Strict) { + return 0; + } + this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed); + if (this.errors) { + if (lastCp !== CharCodes.SEMI) { + this.errors.missingSemicolonAfterCharacterReference(); + } + this.errors.validateNumericCharacterReference(this.result); + } + return this.consumed; + }; + /** + * Parses a named entity. + * + * Equivalent to the `Named character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNamedEntity = function (str, offset) { + var decodeTree = this.decodeTree; + var current = decodeTree[this.treeIndex]; + // The mask is the number of bytes of the value, including the current byte. + var valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + for (; offset < str.length; offset++, this.excess++) { + var char = str.charCodeAt(offset); + this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char); + if (this.treeIndex < 0) { + return this.result === 0 || + // If we are parsing an attribute + (this.decodeMode === DecodingMode.Attribute && + // We shouldn't have consumed any characters after the entity, + (valueLength === 0 || + // And there should be no invalid characters. + isEntityInAttributeInvalidEnd(char))) + ? 0 + : this.emitNotTerminatedNamedEntity(); + } + current = decodeTree[this.treeIndex]; + valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + // If the branch is a value, store it and continue + if (valueLength !== 0) { + // If the entity is terminated by a semicolon, we are done. + if (char === CharCodes.SEMI) { + return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess); + } + // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it. + if (this.decodeMode !== DecodingMode.Strict) { + this.result = this.treeIndex; + this.consumed += this.excess; + this.excess = 0; + } + } + } + return -1; + }; + /** + * Emit a named entity that was not terminated with a semicolon. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.emitNotTerminatedNamedEntity = function () { + var _a; + var _b = this, result = _b.result, decodeTree = _b.decodeTree; + var valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14; + this.emitNamedEntityData(result, valueLength, this.consumed); + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference(); + return this.consumed; + }; + /** + * Emit a named entity. + * + * @param result The index of the entity in the decode tree. + * @param valueLength The number of bytes in the entity. + * @param consumed The number of characters consumed. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.emitNamedEntityData = function (result, valueLength, consumed) { + var decodeTree = this.decodeTree; + this.emitCodePoint(valueLength === 1 + ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH + : decodeTree[result + 1], consumed); + if (valueLength === 3) { + // For multi-byte values, we need to emit the second byte. + this.emitCodePoint(decodeTree[result + 2], consumed); + } + return consumed; + }; + /** + * Signal to the parser that the end of the input was reached. + * + * Remaining data will be emitted and relevant errors will be produced. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.end = function () { + var _a; + switch (this.state) { + case EntityDecoderState.NamedEntity: { + // Emit a named entity if we have one. + return this.result !== 0 && + (this.decodeMode !== DecodingMode.Attribute || + this.result === this.treeIndex) + ? this.emitNotTerminatedNamedEntity() + : 0; + } + // Otherwise, emit a numeric entity if we have one. + case EntityDecoderState.NumericDecimal: { + return this.emitNumericEntity(0, 2); + } + case EntityDecoderState.NumericHex: { + return this.emitNumericEntity(0, 3); + } + case EntityDecoderState.NumericStart: { + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); + return 0; + } + case EntityDecoderState.EntityStart: { + // Return 0 if we have no entity. + return 0; + } + } + }; + return EntityDecoder; +}()); +exports.EntityDecoder = EntityDecoder; +/** + * Creates a function that decodes entities in a string. + * + * @param decodeTree The decode tree. + * @returns A function that decodes entities in a string. + */ +function getDecoder(decodeTree) { + var ret = ""; + var decoder = new EntityDecoder(decodeTree, function (str) { return (ret += (0, decode_codepoint_js_1.fromCodePoint)(str)); }); + return function decodeWithTrie(str, decodeMode) { + var lastIndex = 0; + var offset = 0; + while ((offset = str.indexOf("&", offset)) >= 0) { + ret += str.slice(lastIndex, offset); + decoder.startEntity(decodeMode); + var len = decoder.write(str, + // Skip the "&" + offset + 1); + if (len < 0) { + lastIndex = offset + decoder.end(); + break; + } + lastIndex = offset + len; + // If `len` is 0, skip the current `&` and continue. + offset = len === 0 ? lastIndex + 1 : lastIndex; + } + var result = ret + str.slice(lastIndex); + // Make sure we don't keep a reference to the final string. + ret = ""; + return result; + }; +} +/** + * Determines the branch of the current node that is taken given the current + * character. This function is used to traverse the trie. + * + * @param decodeTree The trie. + * @param current The current node. + * @param nodeIdx The index right after the current node and its value. + * @param char The current character. + * @returns The index of the next node, or -1 if no branch is taken. + */ +function determineBranch(decodeTree, current, nodeIdx, char) { + var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; + var jumpOffset = current & BinTrieFlags.JUMP_TABLE; + // Case 1: Single branch encoded in jump offset + if (branchCount === 0) { + return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1; + } + // Case 2: Multiple branches encoded in jump table + if (jumpOffset) { + var value = char - jumpOffset; + return value < 0 || value >= branchCount + ? -1 + : decodeTree[nodeIdx + value] - 1; + } + // Case 3: Multiple branches encoded in dictionary + // Binary search for the character. + var lo = nodeIdx; + var hi = lo + branchCount - 1; + while (lo <= hi) { + var mid = (lo + hi) >>> 1; + var midVal = decodeTree[mid]; + if (midVal < char) { + lo = mid + 1; + } + else if (midVal > char) { + hi = mid - 1; + } + else { + return decodeTree[mid + branchCount]; + } + } + return -1; +} +exports.determineBranch = determineBranch; +var htmlDecoder = getDecoder(decode_data_html_js_1.default); +var xmlDecoder = getDecoder(decode_data_xml_js_1.default); +/** + * Decodes an HTML string. + * + * @param str The string to decode. + * @param mode The decoding mode. + * @returns The decoded string. + */ +function decodeHTML(str, mode) { + if (mode === void 0) { mode = DecodingMode.Legacy; } + return htmlDecoder(str, mode); +} +exports.decodeHTML = decodeHTML; +/** + * Decodes an HTML string in an attribute. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeHTMLAttribute(str) { + return htmlDecoder(str, DecodingMode.Attribute); +} +exports.decodeHTMLAttribute = decodeHTMLAttribute; +/** + * Decodes an HTML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeHTMLStrict(str) { + return htmlDecoder(str, DecodingMode.Strict); +} +exports.decodeHTMLStrict = decodeHTMLStrict; +/** + * Decodes an XML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeXML(str) { + return xmlDecoder(str, DecodingMode.Strict); +} +exports.decodeXML = decodeXML; + +}); +define("entities/encode",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.encodeNonAsciiHTML = exports.encodeHTML = void 0; +var encode_html_js_1 = __importDefault(require("./generated/encode-html.js")); +var escape_js_1 = require("./escape.js"); +var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g; +/** + * Encodes all characters in the input using HTML entities. This includes + * characters that are valid ASCII characters in HTML documents, such as `#`. + * + * To get a more compact output, consider using the `encodeNonAsciiHTML` + * function, which will only encode characters that are not valid in HTML + * documents, as well as non-ASCII characters. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +function encodeHTML(data) { + return encodeHTMLTrieRe(htmlReplacer, data); +} +exports.encodeHTML = encodeHTML; +/** + * Encodes all non-ASCII characters, as well as characters not valid in HTML + * documents using HTML entities. This function will not encode characters that + * are valid in HTML documents, such as `#`. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +function encodeNonAsciiHTML(data) { + return encodeHTMLTrieRe(escape_js_1.xmlReplacer, data); +} +exports.encodeNonAsciiHTML = encodeNonAsciiHTML; +function encodeHTMLTrieRe(regExp, str) { + var ret = ""; + var lastIdx = 0; + var match; + while ((match = regExp.exec(str)) !== null) { + var i = match.index; + ret += str.substring(lastIdx, i); + var char = str.charCodeAt(i); + var next = encode_html_js_1.default.get(char); + if (typeof next === "object") { + // We are in a branch. Try to match the next char. + if (i + 1 < str.length) { + var nextChar = str.charCodeAt(i + 1); + var value = typeof next.n === "number" + ? next.n === nextChar + ? next.o + : undefined + : next.n.get(nextChar); + if (value !== undefined) { + ret += value; + lastIdx = regExp.lastIndex += 1; + continue; + } + } + next = next.v; + } + // We might have a tree node without a value; skip and use a numeric entity. + if (next !== undefined) { + ret += next; + lastIdx = i + 1; + } + else { + var cp = (0, escape_js_1.getCodePoint)(str, i); + ret += "&#x".concat(cp.toString(16), ";"); + // Increase by 1 if we have a surrogate pair + lastIdx = regExp.lastIndex += Number(cp !== char); + } + } + return ret + str.substr(lastIdx); +} + +}); +define("entities/escape",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.getCodePoint = exports.xmlReplacer = void 0; +exports.xmlReplacer = /["&'<>$\x80-\uFFFF]/g; +var xmlCodeMap = new Map([ + [34, """], + [38, "&"], + [39, "'"], + [60, "<"], + [62, ">"], +]); +// For compatibility with node < 4, we wrap `codePointAt` +exports.getCodePoint = +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition +String.prototype.codePointAt != null + ? function (str, index) { return str.codePointAt(index); } + : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + function (c, index) { + return (c.charCodeAt(index) & 0xfc00) === 0xd800 + ? (c.charCodeAt(index) - 0xd800) * 0x400 + + c.charCodeAt(index + 1) - + 0xdc00 + + 0x10000 + : c.charCodeAt(index); + }; +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using XML entities. + * + * If a character has no equivalent entity, a + * numeric hexadecimal reference (eg. `ü`) will be used. + */ +function encodeXML(str) { + var ret = ""; + var lastIdx = 0; + var match; + while ((match = exports.xmlReplacer.exec(str)) !== null) { + var i = match.index; + var char = str.charCodeAt(i); + var next = xmlCodeMap.get(char); + if (next !== undefined) { + ret += str.substring(lastIdx, i) + next; + lastIdx = i + 1; + } + else { + ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";"); + // Increase by 1 if we have a surrogate pair + lastIdx = exports.xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800); + } + } + return ret + str.substr(lastIdx); +} +exports.encodeXML = encodeXML; +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using numeric hexadecimal reference (eg. `ü`). + * + * Have a look at `escapeUTF8` if you want a more concise output at the expense + * of reduced transportability. + * + * @param data String to escape. + */ +exports.escape = encodeXML; +/** + * Creates a function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + * + * @param regex Regular expression to match characters to escape. + * @param map Map of characters to escape to their entities. + * + * @returns Function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + */ +function getEscaper(regex, map) { + return function escape(data) { + var match; + var lastIdx = 0; + var result = ""; + while ((match = regex.exec(data))) { + if (lastIdx !== match.index) { + result += data.substring(lastIdx, match.index); + } + // We know that this character will be in the map. + result += map.get(match[0].charCodeAt(0)); + // Every match will be of length 1 + lastIdx = match.index + 1; + } + return result + data.substring(lastIdx); + }; +} +/** + * Encodes all characters not valid in XML documents using XML entities. + * + * Note that the output will be character-set dependent. + * + * @param data String to escape. + */ +exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap); +/** + * Encodes all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([ + [34, """], + [38, "&"], + [160, " "], +])); +/** + * Encodes all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([ + [38, "&"], + [60, "<"], + [62, ">"], + [160, " "], +])); + +}); +define("entities/decode_codepoint",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 +var _a; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceCodePoint = exports.fromCodePoint = void 0; +var decodeMap = new Map([ + [0, 65533], + // C1 Unicode control character reference replacements + [128, 8364], + [130, 8218], + [131, 402], + [132, 8222], + [133, 8230], + [134, 8224], + [135, 8225], + [136, 710], + [137, 8240], + [138, 352], + [139, 8249], + [140, 338], + [142, 381], + [145, 8216], + [146, 8217], + [147, 8220], + [148, 8221], + [149, 8226], + [150, 8211], + [151, 8212], + [152, 732], + [153, 8482], + [154, 353], + [155, 8250], + [156, 339], + [158, 382], + [159, 376], +]); +/** + * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point. + */ +exports.fromCodePoint = +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins +(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) { + var output = ""; + if (codePoint > 0xffff) { + codePoint -= 0x10000; + output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800); + codePoint = 0xdc00 | (codePoint & 0x3ff); + } + output += String.fromCharCode(codePoint); + return output; +}; +/** + * Replace the given code point with a replacement character if it is a + * surrogate or is outside the valid range. Otherwise return the code + * point unchanged. + */ +function replaceCodePoint(codePoint) { + var _a; + if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) { + return 0xfffd; + } + return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint; +} +exports.replaceCodePoint = replaceCodePoint; +/** + * Replace the code point if relevant, then convert it to a string. + * + * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead. + * @param codePoint The code point to decode. + * @returns The decoded code point. + */ +function decodeCodePoint(codePoint) { + return (0, exports.fromCodePoint)(replaceCodePoint(codePoint)); +} +exports.default = decodeCodePoint; + +}); +define("entities/generated/decode-data-html",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-decode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = new Uint16Array( +// prettier-ignore +"\u1d41<\xd5\u0131\u028a\u049d\u057b\u05d0\u0675\u06de\u07a2\u07d6\u080f\u0a4a\u0a91\u0da1\u0e6d\u0f09\u0f26\u10ca\u1228\u12e1\u1415\u149d\u14c3\u14df\u1525\0\0\0\0\0\0\u156b\u16cd\u198d\u1c12\u1ddd\u1f7e\u2060\u21b0\u228d\u23c0\u23fb\u2442\u2824\u2912\u2d08\u2e48\u2fce\u3016\u32ba\u3639\u37ac\u38fe\u3a28\u3a71\u3ae0\u3b2e\u0800EMabcfglmnoprstu\\bfms\x7f\x84\x8b\x90\x95\x98\xa6\xb3\xb9\xc8\xcflig\u803b\xc6\u40c6P\u803b&\u4026cute\u803b\xc1\u40c1reve;\u4102\u0100iyx}rc\u803b\xc2\u40c2;\u4410r;\uc000\ud835\udd04rave\u803b\xc0\u40c0pha;\u4391acr;\u4100d;\u6a53\u0100gp\x9d\xa1on;\u4104f;\uc000\ud835\udd38plyFunction;\u6061ing\u803b\xc5\u40c5\u0100cs\xbe\xc3r;\uc000\ud835\udc9cign;\u6254ilde\u803b\xc3\u40c3ml\u803b\xc4\u40c4\u0400aceforsu\xe5\xfb\xfe\u0117\u011c\u0122\u0127\u012a\u0100cr\xea\xf2kslash;\u6216\u0176\xf6\xf8;\u6ae7ed;\u6306y;\u4411\u0180crt\u0105\u010b\u0114ause;\u6235noullis;\u612ca;\u4392r;\uc000\ud835\udd05pf;\uc000\ud835\udd39eve;\u42d8c\xf2\u0113mpeq;\u624e\u0700HOacdefhilorsu\u014d\u0151\u0156\u0180\u019e\u01a2\u01b5\u01b7\u01ba\u01dc\u0215\u0273\u0278\u027ecy;\u4427PY\u803b\xa9\u40a9\u0180cpy\u015d\u0162\u017aute;\u4106\u0100;i\u0167\u0168\u62d2talDifferentialD;\u6145leys;\u612d\u0200aeio\u0189\u018e\u0194\u0198ron;\u410cdil\u803b\xc7\u40c7rc;\u4108nint;\u6230ot;\u410a\u0100dn\u01a7\u01adilla;\u40b8terDot;\u40b7\xf2\u017fi;\u43a7rcle\u0200DMPT\u01c7\u01cb\u01d1\u01d6ot;\u6299inus;\u6296lus;\u6295imes;\u6297o\u0100cs\u01e2\u01f8kwiseContourIntegral;\u6232eCurly\u0100DQ\u0203\u020foubleQuote;\u601duote;\u6019\u0200lnpu\u021e\u0228\u0247\u0255on\u0100;e\u0225\u0226\u6237;\u6a74\u0180git\u022f\u0236\u023aruent;\u6261nt;\u622fourIntegral;\u622e\u0100fr\u024c\u024e;\u6102oduct;\u6210nterClockwiseContourIntegral;\u6233oss;\u6a2fcr;\uc000\ud835\udc9ep\u0100;C\u0284\u0285\u62d3ap;\u624d\u0580DJSZacefios\u02a0\u02ac\u02b0\u02b4\u02b8\u02cb\u02d7\u02e1\u02e6\u0333\u048d\u0100;o\u0179\u02a5trahd;\u6911cy;\u4402cy;\u4405cy;\u440f\u0180grs\u02bf\u02c4\u02c7ger;\u6021r;\u61a1hv;\u6ae4\u0100ay\u02d0\u02d5ron;\u410e;\u4414l\u0100;t\u02dd\u02de\u6207a;\u4394r;\uc000\ud835\udd07\u0100af\u02eb\u0327\u0100cm\u02f0\u0322ritical\u0200ADGT\u0300\u0306\u0316\u031ccute;\u40b4o\u0174\u030b\u030d;\u42d9bleAcute;\u42ddrave;\u4060ilde;\u42dcond;\u62c4ferentialD;\u6146\u0470\u033d\0\0\0\u0342\u0354\0\u0405f;\uc000\ud835\udd3b\u0180;DE\u0348\u0349\u034d\u40a8ot;\u60dcqual;\u6250ble\u0300CDLRUV\u0363\u0372\u0382\u03cf\u03e2\u03f8ontourIntegra\xec\u0239o\u0274\u0379\0\0\u037b\xbb\u0349nArrow;\u61d3\u0100eo\u0387\u03a4ft\u0180ART\u0390\u0396\u03a1rrow;\u61d0ightArrow;\u61d4e\xe5\u02cang\u0100LR\u03ab\u03c4eft\u0100AR\u03b3\u03b9rrow;\u67f8ightArrow;\u67faightArrow;\u67f9ight\u0100AT\u03d8\u03derrow;\u61d2ee;\u62a8p\u0241\u03e9\0\0\u03efrrow;\u61d1ownArrow;\u61d5erticalBar;\u6225n\u0300ABLRTa\u0412\u042a\u0430\u045e\u047f\u037crrow\u0180;BU\u041d\u041e\u0422\u6193ar;\u6913pArrow;\u61f5reve;\u4311eft\u02d2\u043a\0\u0446\0\u0450ightVector;\u6950eeVector;\u695eector\u0100;B\u0459\u045a\u61bdar;\u6956ight\u01d4\u0467\0\u0471eeVector;\u695fector\u0100;B\u047a\u047b\u61c1ar;\u6957ee\u0100;A\u0486\u0487\u62a4rrow;\u61a7\u0100ct\u0492\u0497r;\uc000\ud835\udc9frok;\u4110\u0800NTacdfglmopqstux\u04bd\u04c0\u04c4\u04cb\u04de\u04e2\u04e7\u04ee\u04f5\u0521\u052f\u0536\u0552\u055d\u0560\u0565G;\u414aH\u803b\xd0\u40d0cute\u803b\xc9\u40c9\u0180aiy\u04d2\u04d7\u04dcron;\u411arc\u803b\xca\u40ca;\u442dot;\u4116r;\uc000\ud835\udd08rave\u803b\xc8\u40c8ement;\u6208\u0100ap\u04fa\u04fecr;\u4112ty\u0253\u0506\0\0\u0512mallSquare;\u65fberySmallSquare;\u65ab\u0100gp\u0526\u052aon;\u4118f;\uc000\ud835\udd3csilon;\u4395u\u0100ai\u053c\u0549l\u0100;T\u0542\u0543\u6a75ilde;\u6242librium;\u61cc\u0100ci\u0557\u055ar;\u6130m;\u6a73a;\u4397ml\u803b\xcb\u40cb\u0100ip\u056a\u056fsts;\u6203onentialE;\u6147\u0280cfios\u0585\u0588\u058d\u05b2\u05ccy;\u4424r;\uc000\ud835\udd09lled\u0253\u0597\0\0\u05a3mallSquare;\u65fcerySmallSquare;\u65aa\u0370\u05ba\0\u05bf\0\0\u05c4f;\uc000\ud835\udd3dAll;\u6200riertrf;\u6131c\xf2\u05cb\u0600JTabcdfgorst\u05e8\u05ec\u05ef\u05fa\u0600\u0612\u0616\u061b\u061d\u0623\u066c\u0672cy;\u4403\u803b>\u403emma\u0100;d\u05f7\u05f8\u4393;\u43dcreve;\u411e\u0180eiy\u0607\u060c\u0610dil;\u4122rc;\u411c;\u4413ot;\u4120r;\uc000\ud835\udd0a;\u62d9pf;\uc000\ud835\udd3eeater\u0300EFGLST\u0635\u0644\u064e\u0656\u065b\u0666qual\u0100;L\u063e\u063f\u6265ess;\u62dbullEqual;\u6267reater;\u6aa2ess;\u6277lantEqual;\u6a7eilde;\u6273cr;\uc000\ud835\udca2;\u626b\u0400Aacfiosu\u0685\u068b\u0696\u069b\u069e\u06aa\u06be\u06caRDcy;\u442a\u0100ct\u0690\u0694ek;\u42c7;\u405eirc;\u4124r;\u610clbertSpace;\u610b\u01f0\u06af\0\u06b2f;\u610dizontalLine;\u6500\u0100ct\u06c3\u06c5\xf2\u06a9rok;\u4126mp\u0144\u06d0\u06d8ownHum\xf0\u012fqual;\u624f\u0700EJOacdfgmnostu\u06fa\u06fe\u0703\u0707\u070e\u071a\u071e\u0721\u0728\u0744\u0778\u078b\u078f\u0795cy;\u4415lig;\u4132cy;\u4401cute\u803b\xcd\u40cd\u0100iy\u0713\u0718rc\u803b\xce\u40ce;\u4418ot;\u4130r;\u6111rave\u803b\xcc\u40cc\u0180;ap\u0720\u072f\u073f\u0100cg\u0734\u0737r;\u412ainaryI;\u6148lie\xf3\u03dd\u01f4\u0749\0\u0762\u0100;e\u074d\u074e\u622c\u0100gr\u0753\u0758ral;\u622bsection;\u62c2isible\u0100CT\u076c\u0772omma;\u6063imes;\u6062\u0180gpt\u077f\u0783\u0788on;\u412ef;\uc000\ud835\udd40a;\u4399cr;\u6110ilde;\u4128\u01eb\u079a\0\u079ecy;\u4406l\u803b\xcf\u40cf\u0280cfosu\u07ac\u07b7\u07bc\u07c2\u07d0\u0100iy\u07b1\u07b5rc;\u4134;\u4419r;\uc000\ud835\udd0dpf;\uc000\ud835\udd41\u01e3\u07c7\0\u07ccr;\uc000\ud835\udca5rcy;\u4408kcy;\u4404\u0380HJacfos\u07e4\u07e8\u07ec\u07f1\u07fd\u0802\u0808cy;\u4425cy;\u440cppa;\u439a\u0100ey\u07f6\u07fbdil;\u4136;\u441ar;\uc000\ud835\udd0epf;\uc000\ud835\udd42cr;\uc000\ud835\udca6\u0580JTaceflmost\u0825\u0829\u082c\u0850\u0863\u09b3\u09b8\u09c7\u09cd\u0a37\u0a47cy;\u4409\u803b<\u403c\u0280cmnpr\u0837\u083c\u0841\u0844\u084dute;\u4139bda;\u439bg;\u67ealacetrf;\u6112r;\u619e\u0180aey\u0857\u085c\u0861ron;\u413ddil;\u413b;\u441b\u0100fs\u0868\u0970t\u0500ACDFRTUVar\u087e\u08a9\u08b1\u08e0\u08e6\u08fc\u092f\u095b\u0390\u096a\u0100nr\u0883\u088fgleBracket;\u67e8row\u0180;BR\u0899\u089a\u089e\u6190ar;\u61e4ightArrow;\u61c6eiling;\u6308o\u01f5\u08b7\0\u08c3bleBracket;\u67e6n\u01d4\u08c8\0\u08d2eeVector;\u6961ector\u0100;B\u08db\u08dc\u61c3ar;\u6959loor;\u630aight\u0100AV\u08ef\u08f5rrow;\u6194ector;\u694e\u0100er\u0901\u0917e\u0180;AV\u0909\u090a\u0910\u62a3rrow;\u61a4ector;\u695aiangle\u0180;BE\u0924\u0925\u0929\u62b2ar;\u69cfqual;\u62b4p\u0180DTV\u0937\u0942\u094cownVector;\u6951eeVector;\u6960ector\u0100;B\u0956\u0957\u61bfar;\u6958ector\u0100;B\u0965\u0966\u61bcar;\u6952ight\xe1\u039cs\u0300EFGLST\u097e\u098b\u0995\u099d\u09a2\u09adqualGreater;\u62daullEqual;\u6266reater;\u6276ess;\u6aa1lantEqual;\u6a7dilde;\u6272r;\uc000\ud835\udd0f\u0100;e\u09bd\u09be\u62d8ftarrow;\u61daidot;\u413f\u0180npw\u09d4\u0a16\u0a1bg\u0200LRlr\u09de\u09f7\u0a02\u0a10eft\u0100AR\u09e6\u09ecrrow;\u67f5ightArrow;\u67f7ightArrow;\u67f6eft\u0100ar\u03b3\u0a0aight\xe1\u03bfight\xe1\u03caf;\uc000\ud835\udd43er\u0100LR\u0a22\u0a2ceftArrow;\u6199ightArrow;\u6198\u0180cht\u0a3e\u0a40\u0a42\xf2\u084c;\u61b0rok;\u4141;\u626a\u0400acefiosu\u0a5a\u0a5d\u0a60\u0a77\u0a7c\u0a85\u0a8b\u0a8ep;\u6905y;\u441c\u0100dl\u0a65\u0a6fiumSpace;\u605flintrf;\u6133r;\uc000\ud835\udd10nusPlus;\u6213pf;\uc000\ud835\udd44c\xf2\u0a76;\u439c\u0480Jacefostu\u0aa3\u0aa7\u0aad\u0ac0\u0b14\u0b19\u0d91\u0d97\u0d9ecy;\u440acute;\u4143\u0180aey\u0ab4\u0ab9\u0aberon;\u4147dil;\u4145;\u441d\u0180gsw\u0ac7\u0af0\u0b0eative\u0180MTV\u0ad3\u0adf\u0ae8ediumSpace;\u600bhi\u0100cn\u0ae6\u0ad8\xeb\u0ad9eryThi\xee\u0ad9ted\u0100GL\u0af8\u0b06reaterGreate\xf2\u0673essLes\xf3\u0a48Line;\u400ar;\uc000\ud835\udd11\u0200Bnpt\u0b22\u0b28\u0b37\u0b3areak;\u6060BreakingSpace;\u40a0f;\u6115\u0680;CDEGHLNPRSTV\u0b55\u0b56\u0b6a\u0b7c\u0ba1\u0beb\u0c04\u0c5e\u0c84\u0ca6\u0cd8\u0d61\u0d85\u6aec\u0100ou\u0b5b\u0b64ngruent;\u6262pCap;\u626doubleVerticalBar;\u6226\u0180lqx\u0b83\u0b8a\u0b9bement;\u6209ual\u0100;T\u0b92\u0b93\u6260ilde;\uc000\u2242\u0338ists;\u6204reater\u0380;EFGLST\u0bb6\u0bb7\u0bbd\u0bc9\u0bd3\u0bd8\u0be5\u626fqual;\u6271ullEqual;\uc000\u2267\u0338reater;\uc000\u226b\u0338ess;\u6279lantEqual;\uc000\u2a7e\u0338ilde;\u6275ump\u0144\u0bf2\u0bfdownHump;\uc000\u224e\u0338qual;\uc000\u224f\u0338e\u0100fs\u0c0a\u0c27tTriangle\u0180;BE\u0c1a\u0c1b\u0c21\u62eaar;\uc000\u29cf\u0338qual;\u62ecs\u0300;EGLST\u0c35\u0c36\u0c3c\u0c44\u0c4b\u0c58\u626equal;\u6270reater;\u6278ess;\uc000\u226a\u0338lantEqual;\uc000\u2a7d\u0338ilde;\u6274ested\u0100GL\u0c68\u0c79reaterGreater;\uc000\u2aa2\u0338essLess;\uc000\u2aa1\u0338recedes\u0180;ES\u0c92\u0c93\u0c9b\u6280qual;\uc000\u2aaf\u0338lantEqual;\u62e0\u0100ei\u0cab\u0cb9verseElement;\u620cghtTriangle\u0180;BE\u0ccb\u0ccc\u0cd2\u62ebar;\uc000\u29d0\u0338qual;\u62ed\u0100qu\u0cdd\u0d0cuareSu\u0100bp\u0ce8\u0cf9set\u0100;E\u0cf0\u0cf3\uc000\u228f\u0338qual;\u62e2erset\u0100;E\u0d03\u0d06\uc000\u2290\u0338qual;\u62e3\u0180bcp\u0d13\u0d24\u0d4eset\u0100;E\u0d1b\u0d1e\uc000\u2282\u20d2qual;\u6288ceeds\u0200;EST\u0d32\u0d33\u0d3b\u0d46\u6281qual;\uc000\u2ab0\u0338lantEqual;\u62e1ilde;\uc000\u227f\u0338erset\u0100;E\u0d58\u0d5b\uc000\u2283\u20d2qual;\u6289ilde\u0200;EFT\u0d6e\u0d6f\u0d75\u0d7f\u6241qual;\u6244ullEqual;\u6247ilde;\u6249erticalBar;\u6224cr;\uc000\ud835\udca9ilde\u803b\xd1\u40d1;\u439d\u0700Eacdfgmoprstuv\u0dbd\u0dc2\u0dc9\u0dd5\u0ddb\u0de0\u0de7\u0dfc\u0e02\u0e20\u0e22\u0e32\u0e3f\u0e44lig;\u4152cute\u803b\xd3\u40d3\u0100iy\u0dce\u0dd3rc\u803b\xd4\u40d4;\u441eblac;\u4150r;\uc000\ud835\udd12rave\u803b\xd2\u40d2\u0180aei\u0dee\u0df2\u0df6cr;\u414cga;\u43a9cron;\u439fpf;\uc000\ud835\udd46enCurly\u0100DQ\u0e0e\u0e1aoubleQuote;\u601cuote;\u6018;\u6a54\u0100cl\u0e27\u0e2cr;\uc000\ud835\udcaaash\u803b\xd8\u40d8i\u016c\u0e37\u0e3cde\u803b\xd5\u40d5es;\u6a37ml\u803b\xd6\u40d6er\u0100BP\u0e4b\u0e60\u0100ar\u0e50\u0e53r;\u603eac\u0100ek\u0e5a\u0e5c;\u63deet;\u63b4arenthesis;\u63dc\u0480acfhilors\u0e7f\u0e87\u0e8a\u0e8f\u0e92\u0e94\u0e9d\u0eb0\u0efcrtialD;\u6202y;\u441fr;\uc000\ud835\udd13i;\u43a6;\u43a0usMinus;\u40b1\u0100ip\u0ea2\u0eadncareplan\xe5\u069df;\u6119\u0200;eio\u0eb9\u0eba\u0ee0\u0ee4\u6abbcedes\u0200;EST\u0ec8\u0ec9\u0ecf\u0eda\u627aqual;\u6aaflantEqual;\u627cilde;\u627eme;\u6033\u0100dp\u0ee9\u0eeeuct;\u620fortion\u0100;a\u0225\u0ef9l;\u621d\u0100ci\u0f01\u0f06r;\uc000\ud835\udcab;\u43a8\u0200Ufos\u0f11\u0f16\u0f1b\u0f1fOT\u803b\"\u4022r;\uc000\ud835\udd14pf;\u611acr;\uc000\ud835\udcac\u0600BEacefhiorsu\u0f3e\u0f43\u0f47\u0f60\u0f73\u0fa7\u0faa\u0fad\u1096\u10a9\u10b4\u10bearr;\u6910G\u803b\xae\u40ae\u0180cnr\u0f4e\u0f53\u0f56ute;\u4154g;\u67ebr\u0100;t\u0f5c\u0f5d\u61a0l;\u6916\u0180aey\u0f67\u0f6c\u0f71ron;\u4158dil;\u4156;\u4420\u0100;v\u0f78\u0f79\u611cerse\u0100EU\u0f82\u0f99\u0100lq\u0f87\u0f8eement;\u620builibrium;\u61cbpEquilibrium;\u696fr\xbb\u0f79o;\u43a1ght\u0400ACDFTUVa\u0fc1\u0feb\u0ff3\u1022\u1028\u105b\u1087\u03d8\u0100nr\u0fc6\u0fd2gleBracket;\u67e9row\u0180;BL\u0fdc\u0fdd\u0fe1\u6192ar;\u61e5eftArrow;\u61c4eiling;\u6309o\u01f5\u0ff9\0\u1005bleBracket;\u67e7n\u01d4\u100a\0\u1014eeVector;\u695dector\u0100;B\u101d\u101e\u61c2ar;\u6955loor;\u630b\u0100er\u102d\u1043e\u0180;AV\u1035\u1036\u103c\u62a2rrow;\u61a6ector;\u695biangle\u0180;BE\u1050\u1051\u1055\u62b3ar;\u69d0qual;\u62b5p\u0180DTV\u1063\u106e\u1078ownVector;\u694feeVector;\u695cector\u0100;B\u1082\u1083\u61bear;\u6954ector\u0100;B\u1091\u1092\u61c0ar;\u6953\u0100pu\u109b\u109ef;\u611dndImplies;\u6970ightarrow;\u61db\u0100ch\u10b9\u10bcr;\u611b;\u61b1leDelayed;\u69f4\u0680HOacfhimoqstu\u10e4\u10f1\u10f7\u10fd\u1119\u111e\u1151\u1156\u1161\u1167\u11b5\u11bb\u11bf\u0100Cc\u10e9\u10eeHcy;\u4429y;\u4428FTcy;\u442ccute;\u415a\u0280;aeiy\u1108\u1109\u110e\u1113\u1117\u6abcron;\u4160dil;\u415erc;\u415c;\u4421r;\uc000\ud835\udd16ort\u0200DLRU\u112a\u1134\u113e\u1149ownArrow\xbb\u041eeftArrow\xbb\u089aightArrow\xbb\u0fddpArrow;\u6191gma;\u43a3allCircle;\u6218pf;\uc000\ud835\udd4a\u0272\u116d\0\0\u1170t;\u621aare\u0200;ISU\u117b\u117c\u1189\u11af\u65a1ntersection;\u6293u\u0100bp\u118f\u119eset\u0100;E\u1197\u1198\u628fqual;\u6291erset\u0100;E\u11a8\u11a9\u6290qual;\u6292nion;\u6294cr;\uc000\ud835\udcaear;\u62c6\u0200bcmp\u11c8\u11db\u1209\u120b\u0100;s\u11cd\u11ce\u62d0et\u0100;E\u11cd\u11d5qual;\u6286\u0100ch\u11e0\u1205eeds\u0200;EST\u11ed\u11ee\u11f4\u11ff\u627bqual;\u6ab0lantEqual;\u627dilde;\u627fTh\xe1\u0f8c;\u6211\u0180;es\u1212\u1213\u1223\u62d1rset\u0100;E\u121c\u121d\u6283qual;\u6287et\xbb\u1213\u0580HRSacfhiors\u123e\u1244\u1249\u1255\u125e\u1271\u1276\u129f\u12c2\u12c8\u12d1ORN\u803b\xde\u40deADE;\u6122\u0100Hc\u124e\u1252cy;\u440by;\u4426\u0100bu\u125a\u125c;\u4009;\u43a4\u0180aey\u1265\u126a\u126fron;\u4164dil;\u4162;\u4422r;\uc000\ud835\udd17\u0100ei\u127b\u1289\u01f2\u1280\0\u1287efore;\u6234a;\u4398\u0100cn\u128e\u1298kSpace;\uc000\u205f\u200aSpace;\u6009lde\u0200;EFT\u12ab\u12ac\u12b2\u12bc\u623cqual;\u6243ullEqual;\u6245ilde;\u6248pf;\uc000\ud835\udd4bipleDot;\u60db\u0100ct\u12d6\u12dbr;\uc000\ud835\udcafrok;\u4166\u0ae1\u12f7\u130e\u131a\u1326\0\u132c\u1331\0\0\0\0\0\u1338\u133d\u1377\u1385\0\u13ff\u1404\u140a\u1410\u0100cr\u12fb\u1301ute\u803b\xda\u40dar\u0100;o\u1307\u1308\u619fcir;\u6949r\u01e3\u1313\0\u1316y;\u440eve;\u416c\u0100iy\u131e\u1323rc\u803b\xdb\u40db;\u4423blac;\u4170r;\uc000\ud835\udd18rave\u803b\xd9\u40d9acr;\u416a\u0100di\u1341\u1369er\u0100BP\u1348\u135d\u0100ar\u134d\u1350r;\u405fac\u0100ek\u1357\u1359;\u63dfet;\u63b5arenthesis;\u63ddon\u0100;P\u1370\u1371\u62c3lus;\u628e\u0100gp\u137b\u137fon;\u4172f;\uc000\ud835\udd4c\u0400ADETadps\u1395\u13ae\u13b8\u13c4\u03e8\u13d2\u13d7\u13f3rrow\u0180;BD\u1150\u13a0\u13a4ar;\u6912ownArrow;\u61c5ownArrow;\u6195quilibrium;\u696eee\u0100;A\u13cb\u13cc\u62a5rrow;\u61a5own\xe1\u03f3er\u0100LR\u13de\u13e8eftArrow;\u6196ightArrow;\u6197i\u0100;l\u13f9\u13fa\u43d2on;\u43a5ing;\u416ecr;\uc000\ud835\udcb0ilde;\u4168ml\u803b\xdc\u40dc\u0480Dbcdefosv\u1427\u142c\u1430\u1433\u143e\u1485\u148a\u1490\u1496ash;\u62abar;\u6aeby;\u4412ash\u0100;l\u143b\u143c\u62a9;\u6ae6\u0100er\u1443\u1445;\u62c1\u0180bty\u144c\u1450\u147aar;\u6016\u0100;i\u144f\u1455cal\u0200BLST\u1461\u1465\u146a\u1474ar;\u6223ine;\u407ceparator;\u6758ilde;\u6240ThinSpace;\u600ar;\uc000\ud835\udd19pf;\uc000\ud835\udd4dcr;\uc000\ud835\udcb1dash;\u62aa\u0280cefos\u14a7\u14ac\u14b1\u14b6\u14bcirc;\u4174dge;\u62c0r;\uc000\ud835\udd1apf;\uc000\ud835\udd4ecr;\uc000\ud835\udcb2\u0200fios\u14cb\u14d0\u14d2\u14d8r;\uc000\ud835\udd1b;\u439epf;\uc000\ud835\udd4fcr;\uc000\ud835\udcb3\u0480AIUacfosu\u14f1\u14f5\u14f9\u14fd\u1504\u150f\u1514\u151a\u1520cy;\u442fcy;\u4407cy;\u442ecute\u803b\xdd\u40dd\u0100iy\u1509\u150drc;\u4176;\u442br;\uc000\ud835\udd1cpf;\uc000\ud835\udd50cr;\uc000\ud835\udcb4ml;\u4178\u0400Hacdefos\u1535\u1539\u153f\u154b\u154f\u155d\u1560\u1564cy;\u4416cute;\u4179\u0100ay\u1544\u1549ron;\u417d;\u4417ot;\u417b\u01f2\u1554\0\u155boWidt\xe8\u0ad9a;\u4396r;\u6128pf;\u6124cr;\uc000\ud835\udcb5\u0be1\u1583\u158a\u1590\0\u15b0\u15b6\u15bf\0\0\0\0\u15c6\u15db\u15eb\u165f\u166d\0\u1695\u169b\u16b2\u16b9\0\u16becute\u803b\xe1\u40e1reve;\u4103\u0300;Ediuy\u159c\u159d\u15a1\u15a3\u15a8\u15ad\u623e;\uc000\u223e\u0333;\u623frc\u803b\xe2\u40e2te\u80bb\xb4\u0306;\u4430lig\u803b\xe6\u40e6\u0100;r\xb2\u15ba;\uc000\ud835\udd1erave\u803b\xe0\u40e0\u0100ep\u15ca\u15d6\u0100fp\u15cf\u15d4sym;\u6135\xe8\u15d3ha;\u43b1\u0100ap\u15dfc\u0100cl\u15e4\u15e7r;\u4101g;\u6a3f\u0264\u15f0\0\0\u160a\u0280;adsv\u15fa\u15fb\u15ff\u1601\u1607\u6227nd;\u6a55;\u6a5clope;\u6a58;\u6a5a\u0380;elmrsz\u1618\u1619\u161b\u161e\u163f\u164f\u1659\u6220;\u69a4e\xbb\u1619sd\u0100;a\u1625\u1626\u6221\u0461\u1630\u1632\u1634\u1636\u1638\u163a\u163c\u163e;\u69a8;\u69a9;\u69aa;\u69ab;\u69ac;\u69ad;\u69ae;\u69aft\u0100;v\u1645\u1646\u621fb\u0100;d\u164c\u164d\u62be;\u699d\u0100pt\u1654\u1657h;\u6222\xbb\xb9arr;\u637c\u0100gp\u1663\u1667on;\u4105f;\uc000\ud835\udd52\u0380;Eaeiop\u12c1\u167b\u167d\u1682\u1684\u1687\u168a;\u6a70cir;\u6a6f;\u624ad;\u624bs;\u4027rox\u0100;e\u12c1\u1692\xf1\u1683ing\u803b\xe5\u40e5\u0180cty\u16a1\u16a6\u16a8r;\uc000\ud835\udcb6;\u402amp\u0100;e\u12c1\u16af\xf1\u0288ilde\u803b\xe3\u40e3ml\u803b\xe4\u40e4\u0100ci\u16c2\u16c8onin\xf4\u0272nt;\u6a11\u0800Nabcdefiklnoprsu\u16ed\u16f1\u1730\u173c\u1743\u1748\u1778\u177d\u17e0\u17e6\u1839\u1850\u170d\u193d\u1948\u1970ot;\u6aed\u0100cr\u16f6\u171ek\u0200ceps\u1700\u1705\u170d\u1713ong;\u624cpsilon;\u43f6rime;\u6035im\u0100;e\u171a\u171b\u623dq;\u62cd\u0176\u1722\u1726ee;\u62bded\u0100;g\u172c\u172d\u6305e\xbb\u172drk\u0100;t\u135c\u1737brk;\u63b6\u0100oy\u1701\u1741;\u4431quo;\u601e\u0280cmprt\u1753\u175b\u1761\u1764\u1768aus\u0100;e\u010a\u0109ptyv;\u69b0s\xe9\u170cno\xf5\u0113\u0180ahw\u176f\u1771\u1773;\u43b2;\u6136een;\u626cr;\uc000\ud835\udd1fg\u0380costuvw\u178d\u179d\u17b3\u17c1\u17d5\u17db\u17de\u0180aiu\u1794\u1796\u179a\xf0\u0760rc;\u65efp\xbb\u1371\u0180dpt\u17a4\u17a8\u17adot;\u6a00lus;\u6a01imes;\u6a02\u0271\u17b9\0\0\u17becup;\u6a06ar;\u6605riangle\u0100du\u17cd\u17d2own;\u65bdp;\u65b3plus;\u6a04e\xe5\u1444\xe5\u14adarow;\u690d\u0180ako\u17ed\u1826\u1835\u0100cn\u17f2\u1823k\u0180lst\u17fa\u05ab\u1802ozenge;\u69ebriangle\u0200;dlr\u1812\u1813\u1818\u181d\u65b4own;\u65beeft;\u65c2ight;\u65b8k;\u6423\u01b1\u182b\0\u1833\u01b2\u182f\0\u1831;\u6592;\u65914;\u6593ck;\u6588\u0100eo\u183e\u184d\u0100;q\u1843\u1846\uc000=\u20e5uiv;\uc000\u2261\u20e5t;\u6310\u0200ptwx\u1859\u185e\u1867\u186cf;\uc000\ud835\udd53\u0100;t\u13cb\u1863om\xbb\u13cctie;\u62c8\u0600DHUVbdhmptuv\u1885\u1896\u18aa\u18bb\u18d7\u18db\u18ec\u18ff\u1905\u190a\u1910\u1921\u0200LRlr\u188e\u1890\u1892\u1894;\u6557;\u6554;\u6556;\u6553\u0280;DUdu\u18a1\u18a2\u18a4\u18a6\u18a8\u6550;\u6566;\u6569;\u6564;\u6567\u0200LRlr\u18b3\u18b5\u18b7\u18b9;\u655d;\u655a;\u655c;\u6559\u0380;HLRhlr\u18ca\u18cb\u18cd\u18cf\u18d1\u18d3\u18d5\u6551;\u656c;\u6563;\u6560;\u656b;\u6562;\u655fox;\u69c9\u0200LRlr\u18e4\u18e6\u18e8\u18ea;\u6555;\u6552;\u6510;\u650c\u0280;DUdu\u06bd\u18f7\u18f9\u18fb\u18fd;\u6565;\u6568;\u652c;\u6534inus;\u629flus;\u629eimes;\u62a0\u0200LRlr\u1919\u191b\u191d\u191f;\u655b;\u6558;\u6518;\u6514\u0380;HLRhlr\u1930\u1931\u1933\u1935\u1937\u1939\u193b\u6502;\u656a;\u6561;\u655e;\u653c;\u6524;\u651c\u0100ev\u0123\u1942bar\u803b\xa6\u40a6\u0200ceio\u1951\u1956\u195a\u1960r;\uc000\ud835\udcb7mi;\u604fm\u0100;e\u171a\u171cl\u0180;bh\u1968\u1969\u196b\u405c;\u69c5sub;\u67c8\u016c\u1974\u197el\u0100;e\u1979\u197a\u6022t\xbb\u197ap\u0180;Ee\u012f\u1985\u1987;\u6aae\u0100;q\u06dc\u06db\u0ce1\u19a7\0\u19e8\u1a11\u1a15\u1a32\0\u1a37\u1a50\0\0\u1ab4\0\0\u1ac1\0\0\u1b21\u1b2e\u1b4d\u1b52\0\u1bfd\0\u1c0c\u0180cpr\u19ad\u19b2\u19ddute;\u4107\u0300;abcds\u19bf\u19c0\u19c4\u19ca\u19d5\u19d9\u6229nd;\u6a44rcup;\u6a49\u0100au\u19cf\u19d2p;\u6a4bp;\u6a47ot;\u6a40;\uc000\u2229\ufe00\u0100eo\u19e2\u19e5t;\u6041\xee\u0693\u0200aeiu\u19f0\u19fb\u1a01\u1a05\u01f0\u19f5\0\u19f8s;\u6a4don;\u410ddil\u803b\xe7\u40e7rc;\u4109ps\u0100;s\u1a0c\u1a0d\u6a4cm;\u6a50ot;\u410b\u0180dmn\u1a1b\u1a20\u1a26il\u80bb\xb8\u01adptyv;\u69b2t\u8100\xa2;e\u1a2d\u1a2e\u40a2r\xe4\u01b2r;\uc000\ud835\udd20\u0180cei\u1a3d\u1a40\u1a4dy;\u4447ck\u0100;m\u1a47\u1a48\u6713ark\xbb\u1a48;\u43c7r\u0380;Ecefms\u1a5f\u1a60\u1a62\u1a6b\u1aa4\u1aaa\u1aae\u65cb;\u69c3\u0180;el\u1a69\u1a6a\u1a6d\u42c6q;\u6257e\u0261\u1a74\0\0\u1a88rrow\u0100lr\u1a7c\u1a81eft;\u61baight;\u61bb\u0280RSacd\u1a92\u1a94\u1a96\u1a9a\u1a9f\xbb\u0f47;\u64c8st;\u629birc;\u629aash;\u629dnint;\u6a10id;\u6aefcir;\u69c2ubs\u0100;u\u1abb\u1abc\u6663it\xbb\u1abc\u02ec\u1ac7\u1ad4\u1afa\0\u1b0aon\u0100;e\u1acd\u1ace\u403a\u0100;q\xc7\xc6\u026d\u1ad9\0\0\u1ae2a\u0100;t\u1ade\u1adf\u402c;\u4040\u0180;fl\u1ae8\u1ae9\u1aeb\u6201\xee\u1160e\u0100mx\u1af1\u1af6ent\xbb\u1ae9e\xf3\u024d\u01e7\u1afe\0\u1b07\u0100;d\u12bb\u1b02ot;\u6a6dn\xf4\u0246\u0180fry\u1b10\u1b14\u1b17;\uc000\ud835\udd54o\xe4\u0254\u8100\xa9;s\u0155\u1b1dr;\u6117\u0100ao\u1b25\u1b29rr;\u61b5ss;\u6717\u0100cu\u1b32\u1b37r;\uc000\ud835\udcb8\u0100bp\u1b3c\u1b44\u0100;e\u1b41\u1b42\u6acf;\u6ad1\u0100;e\u1b49\u1b4a\u6ad0;\u6ad2dot;\u62ef\u0380delprvw\u1b60\u1b6c\u1b77\u1b82\u1bac\u1bd4\u1bf9arr\u0100lr\u1b68\u1b6a;\u6938;\u6935\u0270\u1b72\0\0\u1b75r;\u62dec;\u62dfarr\u0100;p\u1b7f\u1b80\u61b6;\u693d\u0300;bcdos\u1b8f\u1b90\u1b96\u1ba1\u1ba5\u1ba8\u622arcap;\u6a48\u0100au\u1b9b\u1b9ep;\u6a46p;\u6a4aot;\u628dr;\u6a45;\uc000\u222a\ufe00\u0200alrv\u1bb5\u1bbf\u1bde\u1be3rr\u0100;m\u1bbc\u1bbd\u61b7;\u693cy\u0180evw\u1bc7\u1bd4\u1bd8q\u0270\u1bce\0\0\u1bd2re\xe3\u1b73u\xe3\u1b75ee;\u62ceedge;\u62cfen\u803b\xa4\u40a4earrow\u0100lr\u1bee\u1bf3eft\xbb\u1b80ight\xbb\u1bbde\xe4\u1bdd\u0100ci\u1c01\u1c07onin\xf4\u01f7nt;\u6231lcty;\u632d\u0980AHabcdefhijlorstuwz\u1c38\u1c3b\u1c3f\u1c5d\u1c69\u1c75\u1c8a\u1c9e\u1cac\u1cb7\u1cfb\u1cff\u1d0d\u1d7b\u1d91\u1dab\u1dbb\u1dc6\u1dcdr\xf2\u0381ar;\u6965\u0200glrs\u1c48\u1c4d\u1c52\u1c54ger;\u6020eth;\u6138\xf2\u1133h\u0100;v\u1c5a\u1c5b\u6010\xbb\u090a\u016b\u1c61\u1c67arow;\u690fa\xe3\u0315\u0100ay\u1c6e\u1c73ron;\u410f;\u4434\u0180;ao\u0332\u1c7c\u1c84\u0100gr\u02bf\u1c81r;\u61catseq;\u6a77\u0180glm\u1c91\u1c94\u1c98\u803b\xb0\u40b0ta;\u43b4ptyv;\u69b1\u0100ir\u1ca3\u1ca8sht;\u697f;\uc000\ud835\udd21ar\u0100lr\u1cb3\u1cb5\xbb\u08dc\xbb\u101e\u0280aegsv\u1cc2\u0378\u1cd6\u1cdc\u1ce0m\u0180;os\u0326\u1cca\u1cd4nd\u0100;s\u0326\u1cd1uit;\u6666amma;\u43ddin;\u62f2\u0180;io\u1ce7\u1ce8\u1cf8\u40f7de\u8100\xf7;o\u1ce7\u1cf0ntimes;\u62c7n\xf8\u1cf7cy;\u4452c\u026f\u1d06\0\0\u1d0arn;\u631eop;\u630d\u0280lptuw\u1d18\u1d1d\u1d22\u1d49\u1d55lar;\u4024f;\uc000\ud835\udd55\u0280;emps\u030b\u1d2d\u1d37\u1d3d\u1d42q\u0100;d\u0352\u1d33ot;\u6251inus;\u6238lus;\u6214quare;\u62a1blebarwedg\xe5\xfan\u0180adh\u112e\u1d5d\u1d67ownarrow\xf3\u1c83arpoon\u0100lr\u1d72\u1d76ef\xf4\u1cb4igh\xf4\u1cb6\u0162\u1d7f\u1d85karo\xf7\u0f42\u026f\u1d8a\0\0\u1d8ern;\u631fop;\u630c\u0180cot\u1d98\u1da3\u1da6\u0100ry\u1d9d\u1da1;\uc000\ud835\udcb9;\u4455l;\u69f6rok;\u4111\u0100dr\u1db0\u1db4ot;\u62f1i\u0100;f\u1dba\u1816\u65bf\u0100ah\u1dc0\u1dc3r\xf2\u0429a\xf2\u0fa6angle;\u69a6\u0100ci\u1dd2\u1dd5y;\u445fgrarr;\u67ff\u0900Dacdefglmnopqrstux\u1e01\u1e09\u1e19\u1e38\u0578\u1e3c\u1e49\u1e61\u1e7e\u1ea5\u1eaf\u1ebd\u1ee1\u1f2a\u1f37\u1f44\u1f4e\u1f5a\u0100Do\u1e06\u1d34o\xf4\u1c89\u0100cs\u1e0e\u1e14ute\u803b\xe9\u40e9ter;\u6a6e\u0200aioy\u1e22\u1e27\u1e31\u1e36ron;\u411br\u0100;c\u1e2d\u1e2e\u6256\u803b\xea\u40ealon;\u6255;\u444dot;\u4117\u0100Dr\u1e41\u1e45ot;\u6252;\uc000\ud835\udd22\u0180;rs\u1e50\u1e51\u1e57\u6a9aave\u803b\xe8\u40e8\u0100;d\u1e5c\u1e5d\u6a96ot;\u6a98\u0200;ils\u1e6a\u1e6b\u1e72\u1e74\u6a99nters;\u63e7;\u6113\u0100;d\u1e79\u1e7a\u6a95ot;\u6a97\u0180aps\u1e85\u1e89\u1e97cr;\u4113ty\u0180;sv\u1e92\u1e93\u1e95\u6205et\xbb\u1e93p\u01001;\u1e9d\u1ea4\u0133\u1ea1\u1ea3;\u6004;\u6005\u6003\u0100gs\u1eaa\u1eac;\u414bp;\u6002\u0100gp\u1eb4\u1eb8on;\u4119f;\uc000\ud835\udd56\u0180als\u1ec4\u1ece\u1ed2r\u0100;s\u1eca\u1ecb\u62d5l;\u69e3us;\u6a71i\u0180;lv\u1eda\u1edb\u1edf\u43b5on\xbb\u1edb;\u43f5\u0200csuv\u1eea\u1ef3\u1f0b\u1f23\u0100io\u1eef\u1e31rc\xbb\u1e2e\u0269\u1ef9\0\0\u1efb\xed\u0548ant\u0100gl\u1f02\u1f06tr\xbb\u1e5dess\xbb\u1e7a\u0180aei\u1f12\u1f16\u1f1als;\u403dst;\u625fv\u0100;D\u0235\u1f20D;\u6a78parsl;\u69e5\u0100Da\u1f2f\u1f33ot;\u6253rr;\u6971\u0180cdi\u1f3e\u1f41\u1ef8r;\u612fo\xf4\u0352\u0100ah\u1f49\u1f4b;\u43b7\u803b\xf0\u40f0\u0100mr\u1f53\u1f57l\u803b\xeb\u40ebo;\u60ac\u0180cip\u1f61\u1f64\u1f67l;\u4021s\xf4\u056e\u0100eo\u1f6c\u1f74ctatio\xee\u0559nential\xe5\u0579\u09e1\u1f92\0\u1f9e\0\u1fa1\u1fa7\0\0\u1fc6\u1fcc\0\u1fd3\0\u1fe6\u1fea\u2000\0\u2008\u205allingdotse\xf1\u1e44y;\u4444male;\u6640\u0180ilr\u1fad\u1fb3\u1fc1lig;\u8000\ufb03\u0269\u1fb9\0\0\u1fbdg;\u8000\ufb00ig;\u8000\ufb04;\uc000\ud835\udd23lig;\u8000\ufb01lig;\uc000fj\u0180alt\u1fd9\u1fdc\u1fe1t;\u666dig;\u8000\ufb02ns;\u65b1of;\u4192\u01f0\u1fee\0\u1ff3f;\uc000\ud835\udd57\u0100ak\u05bf\u1ff7\u0100;v\u1ffc\u1ffd\u62d4;\u6ad9artint;\u6a0d\u0100ao\u200c\u2055\u0100cs\u2011\u2052\u03b1\u201a\u2030\u2038\u2045\u2048\0\u2050\u03b2\u2022\u2025\u2027\u202a\u202c\0\u202e\u803b\xbd\u40bd;\u6153\u803b\xbc\u40bc;\u6155;\u6159;\u615b\u01b3\u2034\0\u2036;\u6154;\u6156\u02b4\u203e\u2041\0\0\u2043\u803b\xbe\u40be;\u6157;\u615c5;\u6158\u01b6\u204c\0\u204e;\u615a;\u615d8;\u615el;\u6044wn;\u6322cr;\uc000\ud835\udcbb\u0880Eabcdefgijlnorstv\u2082\u2089\u209f\u20a5\u20b0\u20b4\u20f0\u20f5\u20fa\u20ff\u2103\u2112\u2138\u0317\u213e\u2152\u219e\u0100;l\u064d\u2087;\u6a8c\u0180cmp\u2090\u2095\u209dute;\u41f5ma\u0100;d\u209c\u1cda\u43b3;\u6a86reve;\u411f\u0100iy\u20aa\u20aerc;\u411d;\u4433ot;\u4121\u0200;lqs\u063e\u0642\u20bd\u20c9\u0180;qs\u063e\u064c\u20c4lan\xf4\u0665\u0200;cdl\u0665\u20d2\u20d5\u20e5c;\u6aa9ot\u0100;o\u20dc\u20dd\u6a80\u0100;l\u20e2\u20e3\u6a82;\u6a84\u0100;e\u20ea\u20ed\uc000\u22db\ufe00s;\u6a94r;\uc000\ud835\udd24\u0100;g\u0673\u061bmel;\u6137cy;\u4453\u0200;Eaj\u065a\u210c\u210e\u2110;\u6a92;\u6aa5;\u6aa4\u0200Eaes\u211b\u211d\u2129\u2134;\u6269p\u0100;p\u2123\u2124\u6a8arox\xbb\u2124\u0100;q\u212e\u212f\u6a88\u0100;q\u212e\u211bim;\u62e7pf;\uc000\ud835\udd58\u0100ci\u2143\u2146r;\u610am\u0180;el\u066b\u214e\u2150;\u6a8e;\u6a90\u8300>;cdlqr\u05ee\u2160\u216a\u216e\u2173\u2179\u0100ci\u2165\u2167;\u6aa7r;\u6a7aot;\u62d7Par;\u6995uest;\u6a7c\u0280adels\u2184\u216a\u2190\u0656\u219b\u01f0\u2189\0\u218epro\xf8\u209er;\u6978q\u0100lq\u063f\u2196les\xf3\u2088i\xed\u066b\u0100en\u21a3\u21adrtneqq;\uc000\u2269\ufe00\xc5\u21aa\u0500Aabcefkosy\u21c4\u21c7\u21f1\u21f5\u21fa\u2218\u221d\u222f\u2268\u227dr\xf2\u03a0\u0200ilmr\u21d0\u21d4\u21d7\u21dbrs\xf0\u1484f\xbb\u2024il\xf4\u06a9\u0100dr\u21e0\u21e4cy;\u444a\u0180;cw\u08f4\u21eb\u21efir;\u6948;\u61adar;\u610firc;\u4125\u0180alr\u2201\u220e\u2213rts\u0100;u\u2209\u220a\u6665it\xbb\u220alip;\u6026con;\u62b9r;\uc000\ud835\udd25s\u0100ew\u2223\u2229arow;\u6925arow;\u6926\u0280amopr\u223a\u223e\u2243\u225e\u2263rr;\u61fftht;\u623bk\u0100lr\u2249\u2253eftarrow;\u61a9ightarrow;\u61aaf;\uc000\ud835\udd59bar;\u6015\u0180clt\u226f\u2274\u2278r;\uc000\ud835\udcbdas\xe8\u21f4rok;\u4127\u0100bp\u2282\u2287ull;\u6043hen\xbb\u1c5b\u0ae1\u22a3\0\u22aa\0\u22b8\u22c5\u22ce\0\u22d5\u22f3\0\0\u22f8\u2322\u2367\u2362\u237f\0\u2386\u23aa\u23b4cute\u803b\xed\u40ed\u0180;iy\u0771\u22b0\u22b5rc\u803b\xee\u40ee;\u4438\u0100cx\u22bc\u22bfy;\u4435cl\u803b\xa1\u40a1\u0100fr\u039f\u22c9;\uc000\ud835\udd26rave\u803b\xec\u40ec\u0200;ino\u073e\u22dd\u22e9\u22ee\u0100in\u22e2\u22e6nt;\u6a0ct;\u622dfin;\u69dcta;\u6129lig;\u4133\u0180aop\u22fe\u231a\u231d\u0180cgt\u2305\u2308\u2317r;\u412b\u0180elp\u071f\u230f\u2313in\xe5\u078ear\xf4\u0720h;\u4131f;\u62b7ed;\u41b5\u0280;cfot\u04f4\u232c\u2331\u233d\u2341are;\u6105in\u0100;t\u2338\u2339\u621eie;\u69dddo\xf4\u2319\u0280;celp\u0757\u234c\u2350\u235b\u2361al;\u62ba\u0100gr\u2355\u2359er\xf3\u1563\xe3\u234darhk;\u6a17rod;\u6a3c\u0200cgpt\u236f\u2372\u2376\u237by;\u4451on;\u412ff;\uc000\ud835\udd5aa;\u43b9uest\u803b\xbf\u40bf\u0100ci\u238a\u238fr;\uc000\ud835\udcben\u0280;Edsv\u04f4\u239b\u239d\u23a1\u04f3;\u62f9ot;\u62f5\u0100;v\u23a6\u23a7\u62f4;\u62f3\u0100;i\u0777\u23aelde;\u4129\u01eb\u23b8\0\u23bccy;\u4456l\u803b\xef\u40ef\u0300cfmosu\u23cc\u23d7\u23dc\u23e1\u23e7\u23f5\u0100iy\u23d1\u23d5rc;\u4135;\u4439r;\uc000\ud835\udd27ath;\u4237pf;\uc000\ud835\udd5b\u01e3\u23ec\0\u23f1r;\uc000\ud835\udcbfrcy;\u4458kcy;\u4454\u0400acfghjos\u240b\u2416\u2422\u2427\u242d\u2431\u2435\u243bppa\u0100;v\u2413\u2414\u43ba;\u43f0\u0100ey\u241b\u2420dil;\u4137;\u443ar;\uc000\ud835\udd28reen;\u4138cy;\u4445cy;\u445cpf;\uc000\ud835\udd5ccr;\uc000\ud835\udcc0\u0b80ABEHabcdefghjlmnoprstuv\u2470\u2481\u2486\u248d\u2491\u250e\u253d\u255a\u2580\u264e\u265e\u2665\u2679\u267d\u269a\u26b2\u26d8\u275d\u2768\u278b\u27c0\u2801\u2812\u0180art\u2477\u247a\u247cr\xf2\u09c6\xf2\u0395ail;\u691barr;\u690e\u0100;g\u0994\u248b;\u6a8bar;\u6962\u0963\u24a5\0\u24aa\0\u24b1\0\0\0\0\0\u24b5\u24ba\0\u24c6\u24c8\u24cd\0\u24f9ute;\u413amptyv;\u69b4ra\xee\u084cbda;\u43bbg\u0180;dl\u088e\u24c1\u24c3;\u6991\xe5\u088e;\u6a85uo\u803b\xab\u40abr\u0400;bfhlpst\u0899\u24de\u24e6\u24e9\u24eb\u24ee\u24f1\u24f5\u0100;f\u089d\u24e3s;\u691fs;\u691d\xeb\u2252p;\u61abl;\u6939im;\u6973l;\u61a2\u0180;ae\u24ff\u2500\u2504\u6aabil;\u6919\u0100;s\u2509\u250a\u6aad;\uc000\u2aad\ufe00\u0180abr\u2515\u2519\u251drr;\u690crk;\u6772\u0100ak\u2522\u252cc\u0100ek\u2528\u252a;\u407b;\u405b\u0100es\u2531\u2533;\u698bl\u0100du\u2539\u253b;\u698f;\u698d\u0200aeuy\u2546\u254b\u2556\u2558ron;\u413e\u0100di\u2550\u2554il;\u413c\xec\u08b0\xe2\u2529;\u443b\u0200cqrs\u2563\u2566\u256d\u257da;\u6936uo\u0100;r\u0e19\u1746\u0100du\u2572\u2577har;\u6967shar;\u694bh;\u61b2\u0280;fgqs\u258b\u258c\u0989\u25f3\u25ff\u6264t\u0280ahlrt\u2598\u25a4\u25b7\u25c2\u25e8rrow\u0100;t\u0899\u25a1a\xe9\u24f6arpoon\u0100du\u25af\u25b4own\xbb\u045ap\xbb\u0966eftarrows;\u61c7ight\u0180ahs\u25cd\u25d6\u25derrow\u0100;s\u08f4\u08a7arpoon\xf3\u0f98quigarro\xf7\u21f0hreetimes;\u62cb\u0180;qs\u258b\u0993\u25falan\xf4\u09ac\u0280;cdgs\u09ac\u260a\u260d\u261d\u2628c;\u6aa8ot\u0100;o\u2614\u2615\u6a7f\u0100;r\u261a\u261b\u6a81;\u6a83\u0100;e\u2622\u2625\uc000\u22da\ufe00s;\u6a93\u0280adegs\u2633\u2639\u263d\u2649\u264bppro\xf8\u24c6ot;\u62d6q\u0100gq\u2643\u2645\xf4\u0989gt\xf2\u248c\xf4\u099bi\xed\u09b2\u0180ilr\u2655\u08e1\u265asht;\u697c;\uc000\ud835\udd29\u0100;E\u099c\u2663;\u6a91\u0161\u2669\u2676r\u0100du\u25b2\u266e\u0100;l\u0965\u2673;\u696alk;\u6584cy;\u4459\u0280;acht\u0a48\u2688\u268b\u2691\u2696r\xf2\u25c1orne\xf2\u1d08ard;\u696bri;\u65fa\u0100io\u269f\u26a4dot;\u4140ust\u0100;a\u26ac\u26ad\u63b0che\xbb\u26ad\u0200Eaes\u26bb\u26bd\u26c9\u26d4;\u6268p\u0100;p\u26c3\u26c4\u6a89rox\xbb\u26c4\u0100;q\u26ce\u26cf\u6a87\u0100;q\u26ce\u26bbim;\u62e6\u0400abnoptwz\u26e9\u26f4\u26f7\u271a\u272f\u2741\u2747\u2750\u0100nr\u26ee\u26f1g;\u67ecr;\u61fdr\xeb\u08c1g\u0180lmr\u26ff\u270d\u2714eft\u0100ar\u09e6\u2707ight\xe1\u09f2apsto;\u67fcight\xe1\u09fdparrow\u0100lr\u2725\u2729ef\xf4\u24edight;\u61ac\u0180afl\u2736\u2739\u273dr;\u6985;\uc000\ud835\udd5dus;\u6a2dimes;\u6a34\u0161\u274b\u274fst;\u6217\xe1\u134e\u0180;ef\u2757\u2758\u1800\u65cange\xbb\u2758ar\u0100;l\u2764\u2765\u4028t;\u6993\u0280achmt\u2773\u2776\u277c\u2785\u2787r\xf2\u08a8orne\xf2\u1d8car\u0100;d\u0f98\u2783;\u696d;\u600eri;\u62bf\u0300achiqt\u2798\u279d\u0a40\u27a2\u27ae\u27bbquo;\u6039r;\uc000\ud835\udcc1m\u0180;eg\u09b2\u27aa\u27ac;\u6a8d;\u6a8f\u0100bu\u252a\u27b3o\u0100;r\u0e1f\u27b9;\u601arok;\u4142\u8400<;cdhilqr\u082b\u27d2\u2639\u27dc\u27e0\u27e5\u27ea\u27f0\u0100ci\u27d7\u27d9;\u6aa6r;\u6a79re\xe5\u25f2mes;\u62c9arr;\u6976uest;\u6a7b\u0100Pi\u27f5\u27f9ar;\u6996\u0180;ef\u2800\u092d\u181b\u65c3r\u0100du\u2807\u280dshar;\u694ahar;\u6966\u0100en\u2817\u2821rtneqq;\uc000\u2268\ufe00\xc5\u281e\u0700Dacdefhilnopsu\u2840\u2845\u2882\u288e\u2893\u28a0\u28a5\u28a8\u28da\u28e2\u28e4\u0a83\u28f3\u2902Dot;\u623a\u0200clpr\u284e\u2852\u2863\u287dr\u803b\xaf\u40af\u0100et\u2857\u2859;\u6642\u0100;e\u285e\u285f\u6720se\xbb\u285f\u0100;s\u103b\u2868to\u0200;dlu\u103b\u2873\u2877\u287bow\xee\u048cef\xf4\u090f\xf0\u13d1ker;\u65ae\u0100oy\u2887\u288cmma;\u6a29;\u443cash;\u6014asuredangle\xbb\u1626r;\uc000\ud835\udd2ao;\u6127\u0180cdn\u28af\u28b4\u28c9ro\u803b\xb5\u40b5\u0200;acd\u1464\u28bd\u28c0\u28c4s\xf4\u16a7ir;\u6af0ot\u80bb\xb7\u01b5us\u0180;bd\u28d2\u1903\u28d3\u6212\u0100;u\u1d3c\u28d8;\u6a2a\u0163\u28de\u28e1p;\u6adb\xf2\u2212\xf0\u0a81\u0100dp\u28e9\u28eeels;\u62a7f;\uc000\ud835\udd5e\u0100ct\u28f8\u28fdr;\uc000\ud835\udcc2pos\xbb\u159d\u0180;lm\u2909\u290a\u290d\u43bctimap;\u62b8\u0c00GLRVabcdefghijlmoprstuvw\u2942\u2953\u297e\u2989\u2998\u29da\u29e9\u2a15\u2a1a\u2a58\u2a5d\u2a83\u2a95\u2aa4\u2aa8\u2b04\u2b07\u2b44\u2b7f\u2bae\u2c34\u2c67\u2c7c\u2ce9\u0100gt\u2947\u294b;\uc000\u22d9\u0338\u0100;v\u2950\u0bcf\uc000\u226b\u20d2\u0180elt\u295a\u2972\u2976ft\u0100ar\u2961\u2967rrow;\u61cdightarrow;\u61ce;\uc000\u22d8\u0338\u0100;v\u297b\u0c47\uc000\u226a\u20d2ightarrow;\u61cf\u0100Dd\u298e\u2993ash;\u62afash;\u62ae\u0280bcnpt\u29a3\u29a7\u29ac\u29b1\u29ccla\xbb\u02deute;\u4144g;\uc000\u2220\u20d2\u0280;Eiop\u0d84\u29bc\u29c0\u29c5\u29c8;\uc000\u2a70\u0338d;\uc000\u224b\u0338s;\u4149ro\xf8\u0d84ur\u0100;a\u29d3\u29d4\u666el\u0100;s\u29d3\u0b38\u01f3\u29df\0\u29e3p\u80bb\xa0\u0b37mp\u0100;e\u0bf9\u0c00\u0280aeouy\u29f4\u29fe\u2a03\u2a10\u2a13\u01f0\u29f9\0\u29fb;\u6a43on;\u4148dil;\u4146ng\u0100;d\u0d7e\u2a0aot;\uc000\u2a6d\u0338p;\u6a42;\u443dash;\u6013\u0380;Aadqsx\u0b92\u2a29\u2a2d\u2a3b\u2a41\u2a45\u2a50rr;\u61d7r\u0100hr\u2a33\u2a36k;\u6924\u0100;o\u13f2\u13f0ot;\uc000\u2250\u0338ui\xf6\u0b63\u0100ei\u2a4a\u2a4ear;\u6928\xed\u0b98ist\u0100;s\u0ba0\u0b9fr;\uc000\ud835\udd2b\u0200Eest\u0bc5\u2a66\u2a79\u2a7c\u0180;qs\u0bbc\u2a6d\u0be1\u0180;qs\u0bbc\u0bc5\u2a74lan\xf4\u0be2i\xed\u0bea\u0100;r\u0bb6\u2a81\xbb\u0bb7\u0180Aap\u2a8a\u2a8d\u2a91r\xf2\u2971rr;\u61aear;\u6af2\u0180;sv\u0f8d\u2a9c\u0f8c\u0100;d\u2aa1\u2aa2\u62fc;\u62facy;\u445a\u0380AEadest\u2ab7\u2aba\u2abe\u2ac2\u2ac5\u2af6\u2af9r\xf2\u2966;\uc000\u2266\u0338rr;\u619ar;\u6025\u0200;fqs\u0c3b\u2ace\u2ae3\u2aeft\u0100ar\u2ad4\u2ad9rro\xf7\u2ac1ightarro\xf7\u2a90\u0180;qs\u0c3b\u2aba\u2aealan\xf4\u0c55\u0100;s\u0c55\u2af4\xbb\u0c36i\xed\u0c5d\u0100;r\u0c35\u2afei\u0100;e\u0c1a\u0c25i\xe4\u0d90\u0100pt\u2b0c\u2b11f;\uc000\ud835\udd5f\u8180\xac;in\u2b19\u2b1a\u2b36\u40acn\u0200;Edv\u0b89\u2b24\u2b28\u2b2e;\uc000\u22f9\u0338ot;\uc000\u22f5\u0338\u01e1\u0b89\u2b33\u2b35;\u62f7;\u62f6i\u0100;v\u0cb8\u2b3c\u01e1\u0cb8\u2b41\u2b43;\u62fe;\u62fd\u0180aor\u2b4b\u2b63\u2b69r\u0200;ast\u0b7b\u2b55\u2b5a\u2b5flle\xec\u0b7bl;\uc000\u2afd\u20e5;\uc000\u2202\u0338lint;\u6a14\u0180;ce\u0c92\u2b70\u2b73u\xe5\u0ca5\u0100;c\u0c98\u2b78\u0100;e\u0c92\u2b7d\xf1\u0c98\u0200Aait\u2b88\u2b8b\u2b9d\u2ba7r\xf2\u2988rr\u0180;cw\u2b94\u2b95\u2b99\u619b;\uc000\u2933\u0338;\uc000\u219d\u0338ghtarrow\xbb\u2b95ri\u0100;e\u0ccb\u0cd6\u0380chimpqu\u2bbd\u2bcd\u2bd9\u2b04\u0b78\u2be4\u2bef\u0200;cer\u0d32\u2bc6\u0d37\u2bc9u\xe5\u0d45;\uc000\ud835\udcc3ort\u026d\u2b05\0\0\u2bd6ar\xe1\u2b56m\u0100;e\u0d6e\u2bdf\u0100;q\u0d74\u0d73su\u0100bp\u2beb\u2bed\xe5\u0cf8\xe5\u0d0b\u0180bcp\u2bf6\u2c11\u2c19\u0200;Ees\u2bff\u2c00\u0d22\u2c04\u6284;\uc000\u2ac5\u0338et\u0100;e\u0d1b\u2c0bq\u0100;q\u0d23\u2c00c\u0100;e\u0d32\u2c17\xf1\u0d38\u0200;Ees\u2c22\u2c23\u0d5f\u2c27\u6285;\uc000\u2ac6\u0338et\u0100;e\u0d58\u2c2eq\u0100;q\u0d60\u2c23\u0200gilr\u2c3d\u2c3f\u2c45\u2c47\xec\u0bd7lde\u803b\xf1\u40f1\xe7\u0c43iangle\u0100lr\u2c52\u2c5ceft\u0100;e\u0c1a\u2c5a\xf1\u0c26ight\u0100;e\u0ccb\u2c65\xf1\u0cd7\u0100;m\u2c6c\u2c6d\u43bd\u0180;es\u2c74\u2c75\u2c79\u4023ro;\u6116p;\u6007\u0480DHadgilrs\u2c8f\u2c94\u2c99\u2c9e\u2ca3\u2cb0\u2cb6\u2cd3\u2ce3ash;\u62adarr;\u6904p;\uc000\u224d\u20d2ash;\u62ac\u0100et\u2ca8\u2cac;\uc000\u2265\u20d2;\uc000>\u20d2nfin;\u69de\u0180Aet\u2cbd\u2cc1\u2cc5rr;\u6902;\uc000\u2264\u20d2\u0100;r\u2cca\u2ccd\uc000<\u20d2ie;\uc000\u22b4\u20d2\u0100At\u2cd8\u2cdcrr;\u6903rie;\uc000\u22b5\u20d2im;\uc000\u223c\u20d2\u0180Aan\u2cf0\u2cf4\u2d02rr;\u61d6r\u0100hr\u2cfa\u2cfdk;\u6923\u0100;o\u13e7\u13e5ear;\u6927\u1253\u1a95\0\0\0\0\0\0\0\0\0\0\0\0\0\u2d2d\0\u2d38\u2d48\u2d60\u2d65\u2d72\u2d84\u1b07\0\0\u2d8d\u2dab\0\u2dc8\u2dce\0\u2ddc\u2e19\u2e2b\u2e3e\u2e43\u0100cs\u2d31\u1a97ute\u803b\xf3\u40f3\u0100iy\u2d3c\u2d45r\u0100;c\u1a9e\u2d42\u803b\xf4\u40f4;\u443e\u0280abios\u1aa0\u2d52\u2d57\u01c8\u2d5alac;\u4151v;\u6a38old;\u69bclig;\u4153\u0100cr\u2d69\u2d6dir;\u69bf;\uc000\ud835\udd2c\u036f\u2d79\0\0\u2d7c\0\u2d82n;\u42dbave\u803b\xf2\u40f2;\u69c1\u0100bm\u2d88\u0df4ar;\u69b5\u0200acit\u2d95\u2d98\u2da5\u2da8r\xf2\u1a80\u0100ir\u2d9d\u2da0r;\u69beoss;\u69bbn\xe5\u0e52;\u69c0\u0180aei\u2db1\u2db5\u2db9cr;\u414dga;\u43c9\u0180cdn\u2dc0\u2dc5\u01cdron;\u43bf;\u69b6pf;\uc000\ud835\udd60\u0180ael\u2dd4\u2dd7\u01d2r;\u69b7rp;\u69b9\u0380;adiosv\u2dea\u2deb\u2dee\u2e08\u2e0d\u2e10\u2e16\u6228r\xf2\u1a86\u0200;efm\u2df7\u2df8\u2e02\u2e05\u6a5dr\u0100;o\u2dfe\u2dff\u6134f\xbb\u2dff\u803b\xaa\u40aa\u803b\xba\u40bagof;\u62b6r;\u6a56lope;\u6a57;\u6a5b\u0180clo\u2e1f\u2e21\u2e27\xf2\u2e01ash\u803b\xf8\u40f8l;\u6298i\u016c\u2e2f\u2e34de\u803b\xf5\u40f5es\u0100;a\u01db\u2e3as;\u6a36ml\u803b\xf6\u40f6bar;\u633d\u0ae1\u2e5e\0\u2e7d\0\u2e80\u2e9d\0\u2ea2\u2eb9\0\0\u2ecb\u0e9c\0\u2f13\0\0\u2f2b\u2fbc\0\u2fc8r\u0200;ast\u0403\u2e67\u2e72\u0e85\u8100\xb6;l\u2e6d\u2e6e\u40b6le\xec\u0403\u0269\u2e78\0\0\u2e7bm;\u6af3;\u6afdy;\u443fr\u0280cimpt\u2e8b\u2e8f\u2e93\u1865\u2e97nt;\u4025od;\u402eil;\u6030enk;\u6031r;\uc000\ud835\udd2d\u0180imo\u2ea8\u2eb0\u2eb4\u0100;v\u2ead\u2eae\u43c6;\u43d5ma\xf4\u0a76ne;\u660e\u0180;tv\u2ebf\u2ec0\u2ec8\u43c0chfork\xbb\u1ffd;\u43d6\u0100au\u2ecf\u2edfn\u0100ck\u2ed5\u2eddk\u0100;h\u21f4\u2edb;\u610e\xf6\u21f4s\u0480;abcdemst\u2ef3\u2ef4\u1908\u2ef9\u2efd\u2f04\u2f06\u2f0a\u2f0e\u402bcir;\u6a23ir;\u6a22\u0100ou\u1d40\u2f02;\u6a25;\u6a72n\u80bb\xb1\u0e9dim;\u6a26wo;\u6a27\u0180ipu\u2f19\u2f20\u2f25ntint;\u6a15f;\uc000\ud835\udd61nd\u803b\xa3\u40a3\u0500;Eaceinosu\u0ec8\u2f3f\u2f41\u2f44\u2f47\u2f81\u2f89\u2f92\u2f7e\u2fb6;\u6ab3p;\u6ab7u\xe5\u0ed9\u0100;c\u0ece\u2f4c\u0300;acens\u0ec8\u2f59\u2f5f\u2f66\u2f68\u2f7eppro\xf8\u2f43urlye\xf1\u0ed9\xf1\u0ece\u0180aes\u2f6f\u2f76\u2f7approx;\u6ab9qq;\u6ab5im;\u62e8i\xed\u0edfme\u0100;s\u2f88\u0eae\u6032\u0180Eas\u2f78\u2f90\u2f7a\xf0\u2f75\u0180dfp\u0eec\u2f99\u2faf\u0180als\u2fa0\u2fa5\u2faalar;\u632eine;\u6312urf;\u6313\u0100;t\u0efb\u2fb4\xef\u0efbrel;\u62b0\u0100ci\u2fc0\u2fc5r;\uc000\ud835\udcc5;\u43c8ncsp;\u6008\u0300fiopsu\u2fda\u22e2\u2fdf\u2fe5\u2feb\u2ff1r;\uc000\ud835\udd2epf;\uc000\ud835\udd62rime;\u6057cr;\uc000\ud835\udcc6\u0180aeo\u2ff8\u3009\u3013t\u0100ei\u2ffe\u3005rnion\xf3\u06b0nt;\u6a16st\u0100;e\u3010\u3011\u403f\xf1\u1f19\xf4\u0f14\u0a80ABHabcdefhilmnoprstux\u3040\u3051\u3055\u3059\u30e0\u310e\u312b\u3147\u3162\u3172\u318e\u3206\u3215\u3224\u3229\u3258\u326e\u3272\u3290\u32b0\u32b7\u0180art\u3047\u304a\u304cr\xf2\u10b3\xf2\u03ddail;\u691car\xf2\u1c65ar;\u6964\u0380cdenqrt\u3068\u3075\u3078\u307f\u308f\u3094\u30cc\u0100eu\u306d\u3071;\uc000\u223d\u0331te;\u4155i\xe3\u116emptyv;\u69b3g\u0200;del\u0fd1\u3089\u308b\u308d;\u6992;\u69a5\xe5\u0fd1uo\u803b\xbb\u40bbr\u0580;abcfhlpstw\u0fdc\u30ac\u30af\u30b7\u30b9\u30bc\u30be\u30c0\u30c3\u30c7\u30cap;\u6975\u0100;f\u0fe0\u30b4s;\u6920;\u6933s;\u691e\xeb\u225d\xf0\u272el;\u6945im;\u6974l;\u61a3;\u619d\u0100ai\u30d1\u30d5il;\u691ao\u0100;n\u30db\u30dc\u6236al\xf3\u0f1e\u0180abr\u30e7\u30ea\u30eer\xf2\u17e5rk;\u6773\u0100ak\u30f3\u30fdc\u0100ek\u30f9\u30fb;\u407d;\u405d\u0100es\u3102\u3104;\u698cl\u0100du\u310a\u310c;\u698e;\u6990\u0200aeuy\u3117\u311c\u3127\u3129ron;\u4159\u0100di\u3121\u3125il;\u4157\xec\u0ff2\xe2\u30fa;\u4440\u0200clqs\u3134\u3137\u313d\u3144a;\u6937dhar;\u6969uo\u0100;r\u020e\u020dh;\u61b3\u0180acg\u314e\u315f\u0f44l\u0200;ips\u0f78\u3158\u315b\u109cn\xe5\u10bbar\xf4\u0fa9t;\u65ad\u0180ilr\u3169\u1023\u316esht;\u697d;\uc000\ud835\udd2f\u0100ao\u3177\u3186r\u0100du\u317d\u317f\xbb\u047b\u0100;l\u1091\u3184;\u696c\u0100;v\u318b\u318c\u43c1;\u43f1\u0180gns\u3195\u31f9\u31fcht\u0300ahlrst\u31a4\u31b0\u31c2\u31d8\u31e4\u31eerrow\u0100;t\u0fdc\u31ada\xe9\u30c8arpoon\u0100du\u31bb\u31bfow\xee\u317ep\xbb\u1092eft\u0100ah\u31ca\u31d0rrow\xf3\u0feaarpoon\xf3\u0551ightarrows;\u61c9quigarro\xf7\u30cbhreetimes;\u62ccg;\u42daingdotse\xf1\u1f32\u0180ahm\u320d\u3210\u3213r\xf2\u0feaa\xf2\u0551;\u600foust\u0100;a\u321e\u321f\u63b1che\xbb\u321fmid;\u6aee\u0200abpt\u3232\u323d\u3240\u3252\u0100nr\u3237\u323ag;\u67edr;\u61fer\xeb\u1003\u0180afl\u3247\u324a\u324er;\u6986;\uc000\ud835\udd63us;\u6a2eimes;\u6a35\u0100ap\u325d\u3267r\u0100;g\u3263\u3264\u4029t;\u6994olint;\u6a12ar\xf2\u31e3\u0200achq\u327b\u3280\u10bc\u3285quo;\u603ar;\uc000\ud835\udcc7\u0100bu\u30fb\u328ao\u0100;r\u0214\u0213\u0180hir\u3297\u329b\u32a0re\xe5\u31f8mes;\u62cai\u0200;efl\u32aa\u1059\u1821\u32ab\u65b9tri;\u69celuhar;\u6968;\u611e\u0d61\u32d5\u32db\u32df\u332c\u3338\u3371\0\u337a\u33a4\0\0\u33ec\u33f0\0\u3428\u3448\u345a\u34ad\u34b1\u34ca\u34f1\0\u3616\0\0\u3633cute;\u415bqu\xef\u27ba\u0500;Eaceinpsy\u11ed\u32f3\u32f5\u32ff\u3302\u330b\u330f\u331f\u3326\u3329;\u6ab4\u01f0\u32fa\0\u32fc;\u6ab8on;\u4161u\xe5\u11fe\u0100;d\u11f3\u3307il;\u415frc;\u415d\u0180Eas\u3316\u3318\u331b;\u6ab6p;\u6abaim;\u62e9olint;\u6a13i\xed\u1204;\u4441ot\u0180;be\u3334\u1d47\u3335\u62c5;\u6a66\u0380Aacmstx\u3346\u334a\u3357\u335b\u335e\u3363\u336drr;\u61d8r\u0100hr\u3350\u3352\xeb\u2228\u0100;o\u0a36\u0a34t\u803b\xa7\u40a7i;\u403bwar;\u6929m\u0100in\u3369\xf0nu\xf3\xf1t;\u6736r\u0100;o\u3376\u2055\uc000\ud835\udd30\u0200acoy\u3382\u3386\u3391\u33a0rp;\u666f\u0100hy\u338b\u338fcy;\u4449;\u4448rt\u026d\u3399\0\0\u339ci\xe4\u1464ara\xec\u2e6f\u803b\xad\u40ad\u0100gm\u33a8\u33b4ma\u0180;fv\u33b1\u33b2\u33b2\u43c3;\u43c2\u0400;deglnpr\u12ab\u33c5\u33c9\u33ce\u33d6\u33de\u33e1\u33e6ot;\u6a6a\u0100;q\u12b1\u12b0\u0100;E\u33d3\u33d4\u6a9e;\u6aa0\u0100;E\u33db\u33dc\u6a9d;\u6a9fe;\u6246lus;\u6a24arr;\u6972ar\xf2\u113d\u0200aeit\u33f8\u3408\u340f\u3417\u0100ls\u33fd\u3404lsetm\xe9\u336ahp;\u6a33parsl;\u69e4\u0100dl\u1463\u3414e;\u6323\u0100;e\u341c\u341d\u6aaa\u0100;s\u3422\u3423\u6aac;\uc000\u2aac\ufe00\u0180flp\u342e\u3433\u3442tcy;\u444c\u0100;b\u3438\u3439\u402f\u0100;a\u343e\u343f\u69c4r;\u633ff;\uc000\ud835\udd64a\u0100dr\u344d\u0402es\u0100;u\u3454\u3455\u6660it\xbb\u3455\u0180csu\u3460\u3479\u349f\u0100au\u3465\u346fp\u0100;s\u1188\u346b;\uc000\u2293\ufe00p\u0100;s\u11b4\u3475;\uc000\u2294\ufe00u\u0100bp\u347f\u348f\u0180;es\u1197\u119c\u3486et\u0100;e\u1197\u348d\xf1\u119d\u0180;es\u11a8\u11ad\u3496et\u0100;e\u11a8\u349d\xf1\u11ae\u0180;af\u117b\u34a6\u05b0r\u0165\u34ab\u05b1\xbb\u117car\xf2\u1148\u0200cemt\u34b9\u34be\u34c2\u34c5r;\uc000\ud835\udcc8tm\xee\xf1i\xec\u3415ar\xe6\u11be\u0100ar\u34ce\u34d5r\u0100;f\u34d4\u17bf\u6606\u0100an\u34da\u34edight\u0100ep\u34e3\u34eapsilo\xee\u1ee0h\xe9\u2eafs\xbb\u2852\u0280bcmnp\u34fb\u355e\u1209\u358b\u358e\u0480;Edemnprs\u350e\u350f\u3511\u3515\u351e\u3523\u352c\u3531\u3536\u6282;\u6ac5ot;\u6abd\u0100;d\u11da\u351aot;\u6ac3ult;\u6ac1\u0100Ee\u3528\u352a;\u6acb;\u628alus;\u6abfarr;\u6979\u0180eiu\u353d\u3552\u3555t\u0180;en\u350e\u3545\u354bq\u0100;q\u11da\u350feq\u0100;q\u352b\u3528m;\u6ac7\u0100bp\u355a\u355c;\u6ad5;\u6ad3c\u0300;acens\u11ed\u356c\u3572\u3579\u357b\u3326ppro\xf8\u32faurlye\xf1\u11fe\xf1\u11f3\u0180aes\u3582\u3588\u331bppro\xf8\u331aq\xf1\u3317g;\u666a\u0680123;Edehlmnps\u35a9\u35ac\u35af\u121c\u35b2\u35b4\u35c0\u35c9\u35d5\u35da\u35df\u35e8\u35ed\u803b\xb9\u40b9\u803b\xb2\u40b2\u803b\xb3\u40b3;\u6ac6\u0100os\u35b9\u35bct;\u6abeub;\u6ad8\u0100;d\u1222\u35c5ot;\u6ac4s\u0100ou\u35cf\u35d2l;\u67c9b;\u6ad7arr;\u697bult;\u6ac2\u0100Ee\u35e4\u35e6;\u6acc;\u628blus;\u6ac0\u0180eiu\u35f4\u3609\u360ct\u0180;en\u121c\u35fc\u3602q\u0100;q\u1222\u35b2eq\u0100;q\u35e7\u35e4m;\u6ac8\u0100bp\u3611\u3613;\u6ad4;\u6ad6\u0180Aan\u361c\u3620\u362drr;\u61d9r\u0100hr\u3626\u3628\xeb\u222e\u0100;o\u0a2b\u0a29war;\u692alig\u803b\xdf\u40df\u0be1\u3651\u365d\u3660\u12ce\u3673\u3679\0\u367e\u36c2\0\0\0\0\0\u36db\u3703\0\u3709\u376c\0\0\0\u3787\u0272\u3656\0\0\u365bget;\u6316;\u43c4r\xeb\u0e5f\u0180aey\u3666\u366b\u3670ron;\u4165dil;\u4163;\u4442lrec;\u6315r;\uc000\ud835\udd31\u0200eiko\u3686\u369d\u36b5\u36bc\u01f2\u368b\0\u3691e\u01004f\u1284\u1281a\u0180;sv\u3698\u3699\u369b\u43b8ym;\u43d1\u0100cn\u36a2\u36b2k\u0100as\u36a8\u36aeppro\xf8\u12c1im\xbb\u12acs\xf0\u129e\u0100as\u36ba\u36ae\xf0\u12c1rn\u803b\xfe\u40fe\u01ec\u031f\u36c6\u22e7es\u8180\xd7;bd\u36cf\u36d0\u36d8\u40d7\u0100;a\u190f\u36d5r;\u6a31;\u6a30\u0180eps\u36e1\u36e3\u3700\xe1\u2a4d\u0200;bcf\u0486\u36ec\u36f0\u36f4ot;\u6336ir;\u6af1\u0100;o\u36f9\u36fc\uc000\ud835\udd65rk;\u6ada\xe1\u3362rime;\u6034\u0180aip\u370f\u3712\u3764d\xe5\u1248\u0380adempst\u3721\u374d\u3740\u3751\u3757\u375c\u375fngle\u0280;dlqr\u3730\u3731\u3736\u3740\u3742\u65b5own\xbb\u1dbbeft\u0100;e\u2800\u373e\xf1\u092e;\u625cight\u0100;e\u32aa\u374b\xf1\u105aot;\u65ecinus;\u6a3alus;\u6a39b;\u69cdime;\u6a3bezium;\u63e2\u0180cht\u3772\u377d\u3781\u0100ry\u3777\u377b;\uc000\ud835\udcc9;\u4446cy;\u445brok;\u4167\u0100io\u378b\u378ex\xf4\u1777head\u0100lr\u3797\u37a0eftarro\xf7\u084fightarrow\xbb\u0f5d\u0900AHabcdfghlmoprstuw\u37d0\u37d3\u37d7\u37e4\u37f0\u37fc\u380e\u381c\u3823\u3834\u3851\u385d\u386b\u38a9\u38cc\u38d2\u38ea\u38f6r\xf2\u03edar;\u6963\u0100cr\u37dc\u37e2ute\u803b\xfa\u40fa\xf2\u1150r\u01e3\u37ea\0\u37edy;\u445eve;\u416d\u0100iy\u37f5\u37farc\u803b\xfb\u40fb;\u4443\u0180abh\u3803\u3806\u380br\xf2\u13adlac;\u4171a\xf2\u13c3\u0100ir\u3813\u3818sht;\u697e;\uc000\ud835\udd32rave\u803b\xf9\u40f9\u0161\u3827\u3831r\u0100lr\u382c\u382e\xbb\u0957\xbb\u1083lk;\u6580\u0100ct\u3839\u384d\u026f\u383f\0\0\u384arn\u0100;e\u3845\u3846\u631cr\xbb\u3846op;\u630fri;\u65f8\u0100al\u3856\u385acr;\u416b\u80bb\xa8\u0349\u0100gp\u3862\u3866on;\u4173f;\uc000\ud835\udd66\u0300adhlsu\u114b\u3878\u387d\u1372\u3891\u38a0own\xe1\u13b3arpoon\u0100lr\u3888\u388cef\xf4\u382digh\xf4\u382fi\u0180;hl\u3899\u389a\u389c\u43c5\xbb\u13faon\xbb\u389aparrows;\u61c8\u0180cit\u38b0\u38c4\u38c8\u026f\u38b6\0\0\u38c1rn\u0100;e\u38bc\u38bd\u631dr\xbb\u38bdop;\u630eng;\u416fri;\u65f9cr;\uc000\ud835\udcca\u0180dir\u38d9\u38dd\u38e2ot;\u62f0lde;\u4169i\u0100;f\u3730\u38e8\xbb\u1813\u0100am\u38ef\u38f2r\xf2\u38a8l\u803b\xfc\u40fcangle;\u69a7\u0780ABDacdeflnoprsz\u391c\u391f\u3929\u392d\u39b5\u39b8\u39bd\u39df\u39e4\u39e8\u39f3\u39f9\u39fd\u3a01\u3a20r\xf2\u03f7ar\u0100;v\u3926\u3927\u6ae8;\u6ae9as\xe8\u03e1\u0100nr\u3932\u3937grt;\u699c\u0380eknprst\u34e3\u3946\u394b\u3952\u395d\u3964\u3996app\xe1\u2415othin\xe7\u1e96\u0180hir\u34eb\u2ec8\u3959op\xf4\u2fb5\u0100;h\u13b7\u3962\xef\u318d\u0100iu\u3969\u396dgm\xe1\u33b3\u0100bp\u3972\u3984setneq\u0100;q\u397d\u3980\uc000\u228a\ufe00;\uc000\u2acb\ufe00setneq\u0100;q\u398f\u3992\uc000\u228b\ufe00;\uc000\u2acc\ufe00\u0100hr\u399b\u399fet\xe1\u369ciangle\u0100lr\u39aa\u39afeft\xbb\u0925ight\xbb\u1051y;\u4432ash\xbb\u1036\u0180elr\u39c4\u39d2\u39d7\u0180;be\u2dea\u39cb\u39cfar;\u62bbq;\u625alip;\u62ee\u0100bt\u39dc\u1468a\xf2\u1469r;\uc000\ud835\udd33tr\xe9\u39aesu\u0100bp\u39ef\u39f1\xbb\u0d1c\xbb\u0d59pf;\uc000\ud835\udd67ro\xf0\u0efbtr\xe9\u39b4\u0100cu\u3a06\u3a0br;\uc000\ud835\udccb\u0100bp\u3a10\u3a18n\u0100Ee\u3980\u3a16\xbb\u397en\u0100Ee\u3992\u3a1e\xbb\u3990igzag;\u699a\u0380cefoprs\u3a36\u3a3b\u3a56\u3a5b\u3a54\u3a61\u3a6airc;\u4175\u0100di\u3a40\u3a51\u0100bg\u3a45\u3a49ar;\u6a5fe\u0100;q\u15fa\u3a4f;\u6259erp;\u6118r;\uc000\ud835\udd34pf;\uc000\ud835\udd68\u0100;e\u1479\u3a66at\xe8\u1479cr;\uc000\ud835\udccc\u0ae3\u178e\u3a87\0\u3a8b\0\u3a90\u3a9b\0\0\u3a9d\u3aa8\u3aab\u3aaf\0\0\u3ac3\u3ace\0\u3ad8\u17dc\u17dftr\xe9\u17d1r;\uc000\ud835\udd35\u0100Aa\u3a94\u3a97r\xf2\u03c3r\xf2\u09f6;\u43be\u0100Aa\u3aa1\u3aa4r\xf2\u03b8r\xf2\u09eba\xf0\u2713is;\u62fb\u0180dpt\u17a4\u3ab5\u3abe\u0100fl\u3aba\u17a9;\uc000\ud835\udd69im\xe5\u17b2\u0100Aa\u3ac7\u3acar\xf2\u03cer\xf2\u0a01\u0100cq\u3ad2\u17b8r;\uc000\ud835\udccd\u0100pt\u17d6\u3adcr\xe9\u17d4\u0400acefiosu\u3af0\u3afd\u3b08\u3b0c\u3b11\u3b15\u3b1b\u3b21c\u0100uy\u3af6\u3afbte\u803b\xfd\u40fd;\u444f\u0100iy\u3b02\u3b06rc;\u4177;\u444bn\u803b\xa5\u40a5r;\uc000\ud835\udd36cy;\u4457pf;\uc000\ud835\udd6acr;\uc000\ud835\udcce\u0100cm\u3b26\u3b29y;\u444el\u803b\xff\u40ff\u0500acdefhiosw\u3b42\u3b48\u3b54\u3b58\u3b64\u3b69\u3b6d\u3b74\u3b7a\u3b80cute;\u417a\u0100ay\u3b4d\u3b52ron;\u417e;\u4437ot;\u417c\u0100et\u3b5d\u3b61tr\xe6\u155fa;\u43b6r;\uc000\ud835\udd37cy;\u4436grarr;\u61ddpf;\uc000\ud835\udd6bcr;\uc000\ud835\udccf\u0100jn\u3b85\u3b87;\u600dj;\u600c" + .split("") + .map(function (c) { return c.charCodeAt(0); })); + +}); +define("entities/generated/encode-html",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-encode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +function restoreDiff(arr) { + for (var i = 1; i < arr.length; i++) { + arr[i][0] += arr[i - 1][0] + 1; + } + return arr; +} +// prettier-ignore +exports.default = new Map(/* #__PURE__ */ restoreDiff([[9, " "], [0, " "], [22, "!"], [0, """], [0, "#"], [0, "$"], [0, "%"], [0, "&"], [0, "'"], [0, "("], [0, ")"], [0, "*"], [0, "+"], [0, ","], [1, "."], [0, "/"], [10, ":"], [0, ";"], [0, { v: "<", n: 8402, o: "<⃒" }], [0, { v: "=", n: 8421, o: "=⃥" }], [0, { v: ">", n: 8402, o: ">⃒" }], [0, "?"], [0, "@"], [26, "["], [0, "\"], [0, "]"], [0, "^"], [0, "_"], [0, "`"], [5, { n: 106, o: "fj" }], [20, "{"], [0, "|"], [0, "}"], [34, " "], [0, "¡"], [0, "¢"], [0, "£"], [0, "¤"], [0, "¥"], [0, "¦"], [0, "§"], [0, "¨"], [0, "©"], [0, "ª"], [0, "«"], [0, "¬"], [0, "­"], [0, "®"], [0, "¯"], [0, "°"], [0, "±"], [0, "²"], [0, "³"], [0, "´"], [0, "µ"], [0, "¶"], [0, "·"], [0, "¸"], [0, "¹"], [0, "º"], [0, "»"], [0, "¼"], [0, "½"], [0, "¾"], [0, "¿"], [0, "À"], [0, "Á"], [0, "Â"], [0, "Ã"], [0, "Ä"], [0, "Å"], [0, "Æ"], [0, "Ç"], [0, "È"], [0, "É"], [0, "Ê"], [0, "Ë"], [0, "Ì"], [0, "Í"], [0, "Î"], [0, "Ï"], [0, "Ð"], [0, "Ñ"], [0, "Ò"], [0, "Ó"], [0, "Ô"], [0, "Õ"], [0, "Ö"], [0, "×"], [0, "Ø"], [0, "Ù"], [0, "Ú"], [0, "Û"], [0, "Ü"], [0, "Ý"], [0, "Þ"], [0, "ß"], [0, "à"], [0, "á"], [0, "â"], [0, "ã"], [0, "ä"], [0, "å"], [0, "æ"], [0, "ç"], [0, "è"], [0, "é"], [0, "ê"], [0, "ë"], [0, "ì"], [0, "í"], [0, "î"], [0, "ï"], [0, "ð"], [0, "ñ"], [0, "ò"], [0, "ó"], [0, "ô"], [0, "õ"], [0, "ö"], [0, "÷"], [0, "ø"], [0, "ù"], [0, "ú"], [0, "û"], [0, "ü"], [0, "ý"], [0, "þ"], [0, "ÿ"], [0, "Ā"], [0, "ā"], [0, "Ă"], [0, "ă"], [0, "Ą"], [0, "ą"], [0, "Ć"], [0, "ć"], [0, "Ĉ"], [0, "ĉ"], [0, "Ċ"], [0, "ċ"], [0, "Č"], [0, "č"], [0, "Ď"], [0, "ď"], [0, "Đ"], [0, "đ"], [0, "Ē"], [0, "ē"], [2, "Ė"], [0, "ė"], [0, "Ę"], [0, "ę"], [0, "Ě"], [0, "ě"], [0, "Ĝ"], [0, "ĝ"], [0, "Ğ"], [0, "ğ"], [0, "Ġ"], [0, "ġ"], [0, "Ģ"], [1, "Ĥ"], [0, "ĥ"], [0, "Ħ"], [0, "ħ"], [0, "Ĩ"], [0, "ĩ"], [0, "Ī"], [0, "ī"], [2, "Į"], [0, "į"], [0, "İ"], [0, "ı"], [0, "IJ"], [0, "ij"], [0, "Ĵ"], [0, "ĵ"], [0, "Ķ"], [0, "ķ"], [0, "ĸ"], [0, "Ĺ"], [0, "ĺ"], [0, "Ļ"], [0, "ļ"], [0, "Ľ"], [0, "ľ"], [0, "Ŀ"], [0, "ŀ"], [0, "Ł"], [0, "ł"], [0, "Ń"], [0, "ń"], [0, "Ņ"], [0, "ņ"], [0, "Ň"], [0, "ň"], [0, "ʼn"], [0, "Ŋ"], [0, "ŋ"], [0, "Ō"], [0, "ō"], [2, "Ő"], [0, "ő"], [0, "Œ"], [0, "œ"], [0, "Ŕ"], [0, "ŕ"], [0, "Ŗ"], [0, "ŗ"], [0, "Ř"], [0, "ř"], [0, "Ś"], [0, "ś"], [0, "Ŝ"], [0, "ŝ"], [0, "Ş"], [0, "ş"], [0, "Š"], [0, "š"], [0, "Ţ"], [0, "ţ"], [0, "Ť"], [0, "ť"], [0, "Ŧ"], [0, "ŧ"], [0, "Ũ"], [0, "ũ"], [0, "Ū"], [0, "ū"], [0, "Ŭ"], [0, "ŭ"], [0, "Ů"], [0, "ů"], [0, "Ű"], [0, "ű"], [0, "Ų"], [0, "ų"], [0, "Ŵ"], [0, "ŵ"], [0, "Ŷ"], [0, "ŷ"], [0, "Ÿ"], [0, "Ź"], [0, "ź"], [0, "Ż"], [0, "ż"], [0, "Ž"], [0, "ž"], [19, "ƒ"], [34, "Ƶ"], [63, "ǵ"], [65, "ȷ"], [142, "ˆ"], [0, "ˇ"], [16, "˘"], [0, "˙"], [0, "˚"], [0, "˛"], [0, "˜"], [0, "˝"], [51, "̑"], [127, "Α"], [0, "Β"], [0, "Γ"], [0, "Δ"], [0, "Ε"], [0, "Ζ"], [0, "Η"], [0, "Θ"], [0, "Ι"], [0, "Κ"], [0, "Λ"], [0, "Μ"], [0, "Ν"], [0, "Ξ"], [0, "Ο"], [0, "Π"], [0, "Ρ"], [1, "Σ"], [0, "Τ"], [0, "Υ"], [0, "Φ"], [0, "Χ"], [0, "Ψ"], [0, "Ω"], [7, "α"], [0, "β"], [0, "γ"], [0, "δ"], [0, "ε"], [0, "ζ"], [0, "η"], [0, "θ"], [0, "ι"], [0, "κ"], [0, "λ"], [0, "μ"], [0, "ν"], [0, "ξ"], [0, "ο"], [0, "π"], [0, "ρ"], [0, "ς"], [0, "σ"], [0, "τ"], [0, "υ"], [0, "φ"], [0, "χ"], [0, "ψ"], [0, "ω"], [7, "ϑ"], [0, "ϒ"], [2, "ϕ"], [0, "ϖ"], [5, "Ϝ"], [0, "ϝ"], [18, "ϰ"], [0, "ϱ"], [3, "ϵ"], [0, "϶"], [10, "Ё"], [0, "Ђ"], [0, "Ѓ"], [0, "Є"], [0, "Ѕ"], [0, "І"], [0, "Ї"], [0, "Ј"], [0, "Љ"], [0, "Њ"], [0, "Ћ"], [0, "Ќ"], [1, "Ў"], [0, "Џ"], [0, "А"], [0, "Б"], [0, "В"], [0, "Г"], [0, "Д"], [0, "Е"], [0, "Ж"], [0, "З"], [0, "И"], [0, "Й"], [0, "К"], [0, "Л"], [0, "М"], [0, "Н"], [0, "О"], [0, "П"], [0, "Р"], [0, "С"], [0, "Т"], [0, "У"], [0, "Ф"], [0, "Х"], [0, "Ц"], [0, "Ч"], [0, "Ш"], [0, "Щ"], [0, "Ъ"], [0, "Ы"], [0, "Ь"], [0, "Э"], [0, "Ю"], [0, "Я"], [0, "а"], [0, "б"], [0, "в"], [0, "г"], [0, "д"], [0, "е"], [0, "ж"], [0, "з"], [0, "и"], [0, "й"], [0, "к"], [0, "л"], [0, "м"], [0, "н"], [0, "о"], [0, "п"], [0, "р"], [0, "с"], [0, "т"], [0, "у"], [0, "ф"], [0, "х"], [0, "ц"], [0, "ч"], [0, "ш"], [0, "щ"], [0, "ъ"], [0, "ы"], [0, "ь"], [0, "э"], [0, "ю"], [0, "я"], [1, "ё"], [0, "ђ"], [0, "ѓ"], [0, "є"], [0, "ѕ"], [0, "і"], [0, "ї"], [0, "ј"], [0, "љ"], [0, "њ"], [0, "ћ"], [0, "ќ"], [1, "ў"], [0, "џ"], [7074, " "], [0, " "], [0, " "], [0, " "], [1, " "], [0, " "], [0, " "], [0, " "], [0, "​"], [0, "‌"], [0, "‍"], [0, "‎"], [0, "‏"], [0, "‐"], [2, "–"], [0, "—"], [0, "―"], [0, "‖"], [1, "‘"], [0, "’"], [0, "‚"], [1, "“"], [0, "”"], [0, "„"], [1, "†"], [0, "‡"], [0, "•"], [2, "‥"], [0, "…"], [9, "‰"], [0, "‱"], [0, "′"], [0, "″"], [0, "‴"], [0, "‵"], [3, "‹"], [0, "›"], [3, "‾"], [2, "⁁"], [1, "⁃"], [0, "⁄"], [10, "⁏"], [7, "⁗"], [7, { v: " ", n: 8202, o: "  " }], [0, "⁠"], [0, "⁡"], [0, "⁢"], [0, "⁣"], [72, "€"], [46, "⃛"], [0, "⃜"], [37, "ℂ"], [2, "℅"], [4, "ℊ"], [0, "ℋ"], [0, "ℌ"], [0, "ℍ"], [0, "ℎ"], [0, "ℏ"], [0, "ℐ"], [0, "ℑ"], [0, "ℒ"], [0, "ℓ"], [1, "ℕ"], [0, "№"], [0, "℗"], [0, "℘"], [0, "ℙ"], [0, "ℚ"], [0, "ℛ"], [0, "ℜ"], [0, "ℝ"], [0, "℞"], [3, "™"], [1, "ℤ"], [2, "℧"], [0, "ℨ"], [0, "℩"], [2, "ℬ"], [0, "ℭ"], [1, "ℯ"], [0, "ℰ"], [0, "ℱ"], [1, "ℳ"], [0, "ℴ"], [0, "ℵ"], [0, "ℶ"], [0, "ℷ"], [0, "ℸ"], [12, "ⅅ"], [0, "ⅆ"], [0, "ⅇ"], [0, "ⅈ"], [10, "⅓"], [0, "⅔"], [0, "⅕"], [0, "⅖"], [0, "⅗"], [0, "⅘"], [0, "⅙"], [0, "⅚"], [0, "⅛"], [0, "⅜"], [0, "⅝"], [0, "⅞"], [49, "←"], [0, "↑"], [0, "→"], [0, "↓"], [0, "↔"], [0, "↕"], [0, "↖"], [0, "↗"], [0, "↘"], [0, "↙"], [0, "↚"], [0, "↛"], [1, { v: "↝", n: 824, o: "↝̸" }], [0, "↞"], [0, "↟"], [0, "↠"], [0, "↡"], [0, "↢"], [0, "↣"], [0, "↤"], [0, "↥"], [0, "↦"], [0, "↧"], [1, "↩"], [0, "↪"], [0, "↫"], [0, "↬"], [0, "↭"], [0, "↮"], [1, "↰"], [0, "↱"], [0, "↲"], [0, "↳"], [1, "↵"], [0, "↶"], [0, "↷"], [2, "↺"], [0, "↻"], [0, "↼"], [0, "↽"], [0, "↾"], [0, "↿"], [0, "⇀"], [0, "⇁"], [0, "⇂"], [0, "⇃"], [0, "⇄"], [0, "⇅"], [0, "⇆"], [0, "⇇"], [0, "⇈"], [0, "⇉"], [0, "⇊"], [0, "⇋"], [0, "⇌"], [0, "⇍"], [0, "⇎"], [0, "⇏"], [0, "⇐"], [0, "⇑"], [0, "⇒"], [0, "⇓"], [0, "⇔"], [0, "⇕"], [0, "⇖"], [0, "⇗"], [0, "⇘"], [0, "⇙"], [0, "⇚"], [0, "⇛"], [1, "⇝"], [6, "⇤"], [0, "⇥"], [15, "⇵"], [7, "⇽"], [0, "⇾"], [0, "⇿"], [0, "∀"], [0, "∁"], [0, { v: "∂", n: 824, o: "∂̸" }], [0, "∃"], [0, "∄"], [0, "∅"], [1, "∇"], [0, "∈"], [0, "∉"], [1, "∋"], [0, "∌"], [2, "∏"], [0, "∐"], [0, "∑"], [0, "−"], [0, "∓"], [0, "∔"], [1, "∖"], [0, "∗"], [0, "∘"], [1, "√"], [2, "∝"], [0, "∞"], [0, "∟"], [0, { v: "∠", n: 8402, o: "∠⃒" }], [0, "∡"], [0, "∢"], [0, "∣"], [0, "∤"], [0, "∥"], [0, "∦"], [0, "∧"], [0, "∨"], [0, { v: "∩", n: 65024, o: "∩︀" }], [0, { v: "∪", n: 65024, o: "∪︀" }], [0, "∫"], [0, "∬"], [0, "∭"], [0, "∮"], [0, "∯"], [0, "∰"], [0, "∱"], [0, "∲"], [0, "∳"], [0, "∴"], [0, "∵"], [0, "∶"], [0, "∷"], [0, "∸"], [1, "∺"], [0, "∻"], [0, { v: "∼", n: 8402, o: "∼⃒" }], [0, { v: "∽", n: 817, o: "∽̱" }], [0, { v: "∾", n: 819, o: "∾̳" }], [0, "∿"], [0, "≀"], [0, "≁"], [0, { v: "≂", n: 824, o: "≂̸" }], [0, "≃"], [0, "≄"], [0, "≅"], [0, "≆"], [0, "≇"], [0, "≈"], [0, "≉"], [0, "≊"], [0, { v: "≋", n: 824, o: "≋̸" }], [0, "≌"], [0, { v: "≍", n: 8402, o: "≍⃒" }], [0, { v: "≎", n: 824, o: "≎̸" }], [0, { v: "≏", n: 824, o: "≏̸" }], [0, { v: "≐", n: 824, o: "≐̸" }], [0, "≑"], [0, "≒"], [0, "≓"], [0, "≔"], [0, "≕"], [0, "≖"], [0, "≗"], [1, "≙"], [0, "≚"], [1, "≜"], [2, "≟"], [0, "≠"], [0, { v: "≡", n: 8421, o: "≡⃥" }], [0, "≢"], [1, { v: "≤", n: 8402, o: "≤⃒" }], [0, { v: "≥", n: 8402, o: "≥⃒" }], [0, { v: "≦", n: 824, o: "≦̸" }], [0, { v: "≧", n: 824, o: "≧̸" }], [0, { v: "≨", n: 65024, o: "≨︀" }], [0, { v: "≩", n: 65024, o: "≩︀" }], [0, { v: "≪", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≪̸"], [7577, "≪⃒"]])) }], [0, { v: "≫", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≫̸"], [7577, "≫⃒"]])) }], [0, "≬"], [0, "≭"], [0, "≮"], [0, "≯"], [0, "≰"], [0, "≱"], [0, "≲"], [0, "≳"], [0, "≴"], [0, "≵"], [0, "≶"], [0, "≷"], [0, "≸"], [0, "≹"], [0, "≺"], [0, "≻"], [0, "≼"], [0, "≽"], [0, "≾"], [0, { v: "≿", n: 824, o: "≿̸" }], [0, "⊀"], [0, "⊁"], [0, { v: "⊂", n: 8402, o: "⊂⃒" }], [0, { v: "⊃", n: 8402, o: "⊃⃒" }], [0, "⊄"], [0, "⊅"], [0, "⊆"], [0, "⊇"], [0, "⊈"], [0, "⊉"], [0, { v: "⊊", n: 65024, o: "⊊︀" }], [0, { v: "⊋", n: 65024, o: "⊋︀" }], [1, "⊍"], [0, "⊎"], [0, { v: "⊏", n: 824, o: "⊏̸" }], [0, { v: "⊐", n: 824, o: "⊐̸" }], [0, "⊑"], [0, "⊒"], [0, { v: "⊓", n: 65024, o: "⊓︀" }], [0, { v: "⊔", n: 65024, o: "⊔︀" }], [0, "⊕"], [0, "⊖"], [0, "⊗"], [0, "⊘"], [0, "⊙"], [0, "⊚"], [0, "⊛"], [1, "⊝"], [0, "⊞"], [0, "⊟"], [0, "⊠"], [0, "⊡"], [0, "⊢"], [0, "⊣"], [0, "⊤"], [0, "⊥"], [1, "⊧"], [0, "⊨"], [0, "⊩"], [0, "⊪"], [0, "⊫"], [0, "⊬"], [0, "⊭"], [0, "⊮"], [0, "⊯"], [0, "⊰"], [1, "⊲"], [0, "⊳"], [0, { v: "⊴", n: 8402, o: "⊴⃒" }], [0, { v: "⊵", n: 8402, o: "⊵⃒" }], [0, "⊶"], [0, "⊷"], [0, "⊸"], [0, "⊹"], [0, "⊺"], [0, "⊻"], [1, "⊽"], [0, "⊾"], [0, "⊿"], [0, "⋀"], [0, "⋁"], [0, "⋂"], [0, "⋃"], [0, "⋄"], [0, "⋅"], [0, "⋆"], [0, "⋇"], [0, "⋈"], [0, "⋉"], [0, "⋊"], [0, "⋋"], [0, "⋌"], [0, "⋍"], [0, "⋎"], [0, "⋏"], [0, "⋐"], [0, "⋑"], [0, "⋒"], [0, "⋓"], [0, "⋔"], [0, "⋕"], [0, "⋖"], [0, "⋗"], [0, { v: "⋘", n: 824, o: "⋘̸" }], [0, { v: "⋙", n: 824, o: "⋙̸" }], [0, { v: "⋚", n: 65024, o: "⋚︀" }], [0, { v: "⋛", n: 65024, o: "⋛︀" }], [2, "⋞"], [0, "⋟"], [0, "⋠"], [0, "⋡"], [0, "⋢"], [0, "⋣"], [2, "⋦"], [0, "⋧"], [0, "⋨"], [0, "⋩"], [0, "⋪"], [0, "⋫"], [0, "⋬"], [0, "⋭"], [0, "⋮"], [0, "⋯"], [0, "⋰"], [0, "⋱"], [0, "⋲"], [0, "⋳"], [0, "⋴"], [0, { v: "⋵", n: 824, o: "⋵̸" }], [0, "⋶"], [0, "⋷"], [1, { v: "⋹", n: 824, o: "⋹̸" }], [0, "⋺"], [0, "⋻"], [0, "⋼"], [0, "⋽"], [0, "⋾"], [6, "⌅"], [0, "⌆"], [1, "⌈"], [0, "⌉"], [0, "⌊"], [0, "⌋"], [0, "⌌"], [0, "⌍"], [0, "⌎"], [0, "⌏"], [0, "⌐"], [1, "⌒"], [0, "⌓"], [1, "⌕"], [0, "⌖"], [5, "⌜"], [0, "⌝"], [0, "⌞"], [0, "⌟"], [2, "⌢"], [0, "⌣"], [9, "⌭"], [0, "⌮"], [7, "⌶"], [6, "⌽"], [1, "⌿"], [60, "⍼"], [51, "⎰"], [0, "⎱"], [2, "⎴"], [0, "⎵"], [0, "⎶"], [37, "⏜"], [0, "⏝"], [0, "⏞"], [0, "⏟"], [2, "⏢"], [4, "⏧"], [59, "␣"], [164, "Ⓢ"], [55, "─"], [1, "│"], [9, "┌"], [3, "┐"], [3, "└"], [3, "┘"], [3, "├"], [7, "┤"], [7, "┬"], [7, "┴"], [7, "┼"], [19, "═"], [0, "║"], [0, "╒"], [0, "╓"], [0, "╔"], [0, "╕"], [0, "╖"], [0, "╗"], [0, "╘"], [0, "╙"], [0, "╚"], [0, "╛"], [0, "╜"], [0, "╝"], [0, "╞"], [0, "╟"], [0, "╠"], [0, "╡"], [0, "╢"], [0, "╣"], [0, "╤"], [0, "╥"], [0, "╦"], [0, "╧"], [0, "╨"], [0, "╩"], [0, "╪"], [0, "╫"], [0, "╬"], [19, "▀"], [3, "▄"], [3, "█"], [8, "░"], [0, "▒"], [0, "▓"], [13, "□"], [8, "▪"], [0, "▫"], [1, "▭"], [0, "▮"], [2, "▱"], [1, "△"], [0, "▴"], [0, "▵"], [2, "▸"], [0, "▹"], [3, "▽"], [0, "▾"], [0, "▿"], [2, "◂"], [0, "◃"], [6, "◊"], [0, "○"], [32, "◬"], [2, "◯"], [8, "◸"], [0, "◹"], [0, "◺"], [0, "◻"], [0, "◼"], [8, "★"], [0, "☆"], [7, "☎"], [49, "♀"], [1, "♂"], [29, "♠"], [2, "♣"], [1, "♥"], [0, "♦"], [3, "♪"], [2, "♭"], [0, "♮"], [0, "♯"], [163, "✓"], [3, "✗"], [8, "✠"], [21, "✶"], [33, "❘"], [25, "❲"], [0, "❳"], [84, "⟈"], [0, "⟉"], [28, "⟦"], [0, "⟧"], [0, "⟨"], [0, "⟩"], [0, "⟪"], [0, "⟫"], [0, "⟬"], [0, "⟭"], [7, "⟵"], [0, "⟶"], [0, "⟷"], [0, "⟸"], [0, "⟹"], [0, "⟺"], [1, "⟼"], [2, "⟿"], [258, "⤂"], [0, "⤃"], [0, "⤄"], [0, "⤅"], [6, "⤌"], [0, "⤍"], [0, "⤎"], [0, "⤏"], [0, "⤐"], [0, "⤑"], [0, "⤒"], [0, "⤓"], [2, "⤖"], [2, "⤙"], [0, "⤚"], [0, "⤛"], [0, "⤜"], [0, "⤝"], [0, "⤞"], [0, "⤟"], [0, "⤠"], [2, "⤣"], [0, "⤤"], [0, "⤥"], [0, "⤦"], [0, "⤧"], [0, "⤨"], [0, "⤩"], [0, "⤪"], [8, { v: "⤳", n: 824, o: "⤳̸" }], [1, "⤵"], [0, "⤶"], [0, "⤷"], [0, "⤸"], [0, "⤹"], [2, "⤼"], [0, "⤽"], [7, "⥅"], [2, "⥈"], [0, "⥉"], [0, "⥊"], [0, "⥋"], [2, "⥎"], [0, "⥏"], [0, "⥐"], [0, "⥑"], [0, "⥒"], [0, "⥓"], [0, "⥔"], [0, "⥕"], [0, "⥖"], [0, "⥗"], [0, "⥘"], [0, "⥙"], [0, "⥚"], [0, "⥛"], [0, "⥜"], [0, "⥝"], [0, "⥞"], [0, "⥟"], [0, "⥠"], [0, "⥡"], [0, "⥢"], [0, "⥣"], [0, "⥤"], [0, "⥥"], [0, "⥦"], [0, "⥧"], [0, "⥨"], [0, "⥩"], [0, "⥪"], [0, "⥫"], [0, "⥬"], [0, "⥭"], [0, "⥮"], [0, "⥯"], [0, "⥰"], [0, "⥱"], [0, "⥲"], [0, "⥳"], [0, "⥴"], [0, "⥵"], [0, "⥶"], [1, "⥸"], [0, "⥹"], [1, "⥻"], [0, "⥼"], [0, "⥽"], [0, "⥾"], [0, "⥿"], [5, "⦅"], [0, "⦆"], [4, "⦋"], [0, "⦌"], [0, "⦍"], [0, "⦎"], [0, "⦏"], [0, "⦐"], [0, "⦑"], [0, "⦒"], [0, "⦓"], [0, "⦔"], [0, "⦕"], [0, "⦖"], [3, "⦚"], [1, "⦜"], [0, "⦝"], [6, "⦤"], [0, "⦥"], [0, "⦦"], [0, "⦧"], [0, "⦨"], [0, "⦩"], [0, "⦪"], [0, "⦫"], [0, "⦬"], [0, "⦭"], [0, "⦮"], [0, "⦯"], [0, "⦰"], [0, "⦱"], [0, "⦲"], [0, "⦳"], [0, "⦴"], [0, "⦵"], [0, "⦶"], [0, "⦷"], [1, "⦹"], [1, "⦻"], [0, "⦼"], [1, "⦾"], [0, "⦿"], [0, "⧀"], [0, "⧁"], [0, "⧂"], [0, "⧃"], [0, "⧄"], [0, "⧅"], [3, "⧉"], [3, "⧍"], [0, "⧎"], [0, { v: "⧏", n: 824, o: "⧏̸" }], [0, { v: "⧐", n: 824, o: "⧐̸" }], [11, "⧜"], [0, "⧝"], [0, "⧞"], [4, "⧣"], [0, "⧤"], [0, "⧥"], [5, "⧫"], [8, "⧴"], [1, "⧶"], [9, "⨀"], [0, "⨁"], [0, "⨂"], [1, "⨄"], [1, "⨆"], [5, "⨌"], [0, "⨍"], [2, "⨐"], [0, "⨑"], [0, "⨒"], [0, "⨓"], [0, "⨔"], [0, "⨕"], [0, "⨖"], [0, "⨗"], [10, "⨢"], [0, "⨣"], [0, "⨤"], [0, "⨥"], [0, "⨦"], [0, "⨧"], [1, "⨩"], [0, "⨪"], [2, "⨭"], [0, "⨮"], [0, "⨯"], [0, "⨰"], [0, "⨱"], [1, "⨳"], [0, "⨴"], [0, "⨵"], [0, "⨶"], [0, "⨷"], [0, "⨸"], [0, "⨹"], [0, "⨺"], [0, "⨻"], [0, "⨼"], [2, "⨿"], [0, "⩀"], [1, "⩂"], [0, "⩃"], [0, "⩄"], [0, "⩅"], [0, "⩆"], [0, "⩇"], [0, "⩈"], [0, "⩉"], [0, "⩊"], [0, "⩋"], [0, "⩌"], [0, "⩍"], [2, "⩐"], [2, "⩓"], [0, "⩔"], [0, "⩕"], [0, "⩖"], [0, "⩗"], [0, "⩘"], [1, "⩚"], [0, "⩛"], [0, "⩜"], [0, "⩝"], [1, "⩟"], [6, "⩦"], [3, "⩪"], [2, { v: "⩭", n: 824, o: "⩭̸" }], [0, "⩮"], [0, "⩯"], [0, { v: "⩰", n: 824, o: "⩰̸" }], [0, "⩱"], [0, "⩲"], [0, "⩳"], [0, "⩴"], [0, "⩵"], [1, "⩷"], [0, "⩸"], [0, "⩹"], [0, "⩺"], [0, "⩻"], [0, "⩼"], [0, { v: "⩽", n: 824, o: "⩽̸" }], [0, { v: "⩾", n: 824, o: "⩾̸" }], [0, "⩿"], [0, "⪀"], [0, "⪁"], [0, "⪂"], [0, "⪃"], [0, "⪄"], [0, "⪅"], [0, "⪆"], [0, "⪇"], [0, "⪈"], [0, "⪉"], [0, "⪊"], [0, "⪋"], [0, "⪌"], [0, "⪍"], [0, "⪎"], [0, "⪏"], [0, "⪐"], [0, "⪑"], [0, "⪒"], [0, "⪓"], [0, "⪔"], [0, "⪕"], [0, "⪖"], [0, "⪗"], [0, "⪘"], [0, "⪙"], [0, "⪚"], [2, "⪝"], [0, "⪞"], [0, "⪟"], [0, "⪠"], [0, { v: "⪡", n: 824, o: "⪡̸" }], [0, { v: "⪢", n: 824, o: "⪢̸" }], [1, "⪤"], [0, "⪥"], [0, "⪦"], [0, "⪧"], [0, "⪨"], [0, "⪩"], [0, "⪪"], [0, "⪫"], [0, { v: "⪬", n: 65024, o: "⪬︀" }], [0, { v: "⪭", n: 65024, o: "⪭︀" }], [0, "⪮"], [0, { v: "⪯", n: 824, o: "⪯̸" }], [0, { v: "⪰", n: 824, o: "⪰̸" }], [2, "⪳"], [0, "⪴"], [0, "⪵"], [0, "⪶"], [0, "⪷"], [0, "⪸"], [0, "⪹"], [0, "⪺"], [0, "⪻"], [0, "⪼"], [0, "⪽"], [0, "⪾"], [0, "⪿"], [0, "⫀"], [0, "⫁"], [0, "⫂"], [0, "⫃"], [0, "⫄"], [0, { v: "⫅", n: 824, o: "⫅̸" }], [0, { v: "⫆", n: 824, o: "⫆̸" }], [0, "⫇"], [0, "⫈"], [2, { v: "⫋", n: 65024, o: "⫋︀" }], [0, { v: "⫌", n: 65024, o: "⫌︀" }], [2, "⫏"], [0, "⫐"], [0, "⫑"], [0, "⫒"], [0, "⫓"], [0, "⫔"], [0, "⫕"], [0, "⫖"], [0, "⫗"], [0, "⫘"], [0, "⫙"], [0, "⫚"], [0, "⫛"], [8, "⫤"], [1, "⫦"], [0, "⫧"], [0, "⫨"], [0, "⫩"], [1, "⫫"], [0, "⫬"], [0, "⫭"], [0, "⫮"], [0, "⫯"], [0, "⫰"], [0, "⫱"], [0, "⫲"], [0, "⫳"], [9, { v: "⫽", n: 8421, o: "⫽⃥" }], [44343, { n: new Map(/* #__PURE__ */ restoreDiff([[56476, "𝒜"], [1, "𝒞"], [0, "𝒟"], [2, "𝒢"], [2, "𝒥"], [0, "𝒦"], [2, "𝒩"], [0, "𝒪"], [0, "𝒫"], [0, "𝒬"], [1, "𝒮"], [0, "𝒯"], [0, "𝒰"], [0, "𝒱"], [0, "𝒲"], [0, "𝒳"], [0, "𝒴"], [0, "𝒵"], [0, "𝒶"], [0, "𝒷"], [0, "𝒸"], [0, "𝒹"], [1, "𝒻"], [1, "𝒽"], [0, "𝒾"], [0, "𝒿"], [0, "𝓀"], [0, "𝓁"], [0, "𝓂"], [0, "𝓃"], [1, "𝓅"], [0, "𝓆"], [0, "𝓇"], [0, "𝓈"], [0, "𝓉"], [0, "𝓊"], [0, "𝓋"], [0, "𝓌"], [0, "𝓍"], [0, "𝓎"], [0, "𝓏"], [52, "𝔄"], [0, "𝔅"], [1, "𝔇"], [0, "𝔈"], [0, "𝔉"], [0, "𝔊"], [2, "𝔍"], [0, "𝔎"], [0, "𝔏"], [0, "𝔐"], [0, "𝔑"], [0, "𝔒"], [0, "𝔓"], [0, "𝔔"], [1, "𝔖"], [0, "𝔗"], [0, "𝔘"], [0, "𝔙"], [0, "𝔚"], [0, "𝔛"], [0, "𝔜"], [1, "𝔞"], [0, "𝔟"], [0, "𝔠"], [0, "𝔡"], [0, "𝔢"], [0, "𝔣"], [0, "𝔤"], [0, "𝔥"], [0, "𝔦"], [0, "𝔧"], [0, "𝔨"], [0, "𝔩"], [0, "𝔪"], [0, "𝔫"], [0, "𝔬"], [0, "𝔭"], [0, "𝔮"], [0, "𝔯"], [0, "𝔰"], [0, "𝔱"], [0, "𝔲"], [0, "𝔳"], [0, "𝔴"], [0, "𝔵"], [0, "𝔶"], [0, "𝔷"], [0, "𝔸"], [0, "𝔹"], [1, "𝔻"], [0, "𝔼"], [0, "𝔽"], [0, "𝔾"], [1, "𝕀"], [0, "𝕁"], [0, "𝕂"], [0, "𝕃"], [0, "𝕄"], [1, "𝕆"], [3, "𝕊"], [0, "𝕋"], [0, "𝕌"], [0, "𝕍"], [0, "𝕎"], [0, "𝕏"], [0, "𝕐"], [1, "𝕒"], [0, "𝕓"], [0, "𝕔"], [0, "𝕕"], [0, "𝕖"], [0, "𝕗"], [0, "𝕘"], [0, "𝕙"], [0, "𝕚"], [0, "𝕛"], [0, "𝕜"], [0, "𝕝"], [0, "𝕞"], [0, "𝕟"], [0, "𝕠"], [0, "𝕡"], [0, "𝕢"], [0, "𝕣"], [0, "𝕤"], [0, "𝕥"], [0, "𝕦"], [0, "𝕧"], [0, "𝕨"], [0, "𝕩"], [0, "𝕪"], [0, "𝕫"]])) }], [8906, "ff"], [0, "fi"], [0, "fl"], [0, "ffi"], [0, "ffl"]])); + +}); +define("entities/generated/decode-data-xml",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-decode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = new Uint16Array( +// prettier-ignore +"\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022" + .split("") + .map(function (c) { return c.charCodeAt(0); })); + +}); +/* + * Support for source maps in V8 stack traces + * https://github.com/evanw/node-source-map-support + */ +/* + The buffer module from node.js, for the browser. + + @author Feross Aboukhadijeh + license MIT +*/ +(this.define||function(R,U){this.sourceMapSupport=U()})("browser-source-map-support",function(R){(function e(C,J,A){function p(f,c){if(!J[f]){if(!C[f]){var l="function"==typeof require&&require;if(!c&&l)return l(f,!0);if(t)return t(f,!0);throw Error("Cannot find module '"+f+"'");}l=J[f]={exports:{}};C[f][0].call(l.exports,function(q){var r=C[f][1][q];return p(r?r:q)},l,l.exports,e,C,J,A)}return J[f].exports}for(var t="function"==typeof require&&require,m=0;mm)return-1;if(58>m)return m-48+52;if(91>m)return m-65;if(123>m)return m-97+26}var t="undefined"!==typeof Uint8Array?Uint8Array:Array;e.toByteArray=function(m){function f(d){q[k++]=d}if(0>16);f((u&65280)>>8);f(u&255)}2===l?(u=p(m.charAt(c))<<2|p(m.charAt(c+1))>>4,f(u&255)):1===l&&(u=p(m.charAt(c))<<10|p(m.charAt(c+1))<<4|p(m.charAt(c+2))>>2,f(u>>8&255),f(u&255));return q};e.fromByteArray=function(m){var f=m.length%3,c="",l;var q=0;for(l=m.length-f;q> +18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r&63);c+=r}switch(f){case 1:r=m[m.length-1];c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>2);c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r<<4&63);c+="==";break;case 2:r=(m[m.length-2]<<8)+ +m[m.length-1],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>10),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>4&63),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r<<2&63),c+="="}return c}})("undefined"===typeof A?this.base64js={}:A)},{}],3:[function(C,J,A){},{}],4:[function(C,J,A){(function(e){var p=Object.prototype.toString,t="function"===typeof e.alloc&&"function"===typeof e.allocUnsafe&&"function"=== +typeof e.from;J.exports=function(m,f,c){if("number"===typeof m)throw new TypeError('"value" argument must not be a number');if("ArrayBuffer"===p.call(m).slice(8,-1)){f>>>=0;var l=m.byteLength-f;if(0>l)throw new RangeError("'offset' is out of bounds");if(void 0===c)c=l;else if(c>>>=0,c>l)throw new RangeError("'length' is out of bounds");return t?e.from(m.slice(f,f+c)):new e(new Uint8Array(m.slice(f,f+c)))}if("string"===typeof m){c=f;if("string"!==typeof c||""===c)c="utf8";if(!e.isEncoding(c))throw new TypeError('"encoding" must be a valid string encoding'); +return t?e.from(m,c):new e(m,c)}return t?e.from(m):new e(m)}}).call(this,C("buffer").Buffer)},{buffer:5}],5:[function(C,J,A){function e(a,b,h){if(!(this instanceof e))return new e(a,b,h);var w=typeof a;if("number"===w)var y=0>>0:0;else if("string"===w){if("base64"===b)for(a=(a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")).replace(L,"");0!==a.length%4;)a+="=";y=e.byteLength(a,b)}else if("object"===w&&null!==a)"Buffer"===a.type&&z(a.data)&&(a=a.data),y=0<+a.length?Math.floor(+a.length):0;else throw new TypeError("must start with number, buffer, array or string"); +if(this.length>G)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+G.toString(16)+" bytes");if(e.TYPED_ARRAY_SUPPORT)var I=e._augment(new Uint8Array(y));else I=this,I.length=y,I._isBuffer=!0;if(e.TYPED_ARRAY_SUPPORT&&"number"===typeof a.byteLength)I._set(a);else{var K=a;if(z(K)||e.isBuffer(K)||K&&"object"===typeof K&&"number"===typeof K.length)if(e.isBuffer(a))for(b=0;ba)throw new RangeError("offset is not uint");if(a+b>h)throw new RangeError("Trying to access beyond buffer length");}function m(a,b,h,w,y,I){if(!e.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>y||ba.length)throw new TypeError("index out of range"); +}function f(a,b,h,w){0>b&&(b=65535+b+1);for(var y=0,I=Math.min(a.length-h,2);y>>8*(w?y:1-y)}function c(a,b,h,w){0>b&&(b=4294967295+b+1);for(var y=0,I=Math.min(a.length-h,4);y>>8*(w?y:3-y)&255}function l(a,b,h,w,y,I){if(b>y||ba.length)throw new TypeError("index out of range");}function q(a,b,h,w,y){y||l(a,b,h,4,3.4028234663852886E38,-3.4028234663852886E38);v.write(a,b,h,w,23,4);return h+4}function r(a, +b,h,w,y){y||l(a,b,h,8,1.7976931348623157E308,-1.7976931348623157E308);v.write(a,b,h,w,52,8);return h+8}function k(a){for(var b=[],h=0;h=w)b.push(w);else{var y=h;55296<=w&&57343>=w&&h++;w=encodeURIComponent(a.slice(y,h+1)).substr(1).split("%");for(y=0;y=b.length||y>=a.length);y++)b[y+ +h]=a[y];return y}function g(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}var n=C("base64-js"),v=C("ieee754"),z=C("is-array");A.Buffer=e;A.SlowBuffer=e;A.INSPECT_MAX_BYTES=50;e.poolSize=8192;var G=1073741823;e.TYPED_ARRAY_SUPPORT=function(){try{var a=new ArrayBuffer(0),b=new Uint8Array(a);b.foo=function(){return 42};return 42===b.foo()&&"function"===typeof b.subarray&&0===(new Uint8Array(1)).subarray(1,1).byteLength}catch(h){return!1}}();e.isBuffer=function(a){return!(null== +a||!a._isBuffer)};e.compare=function(a,b){if(!e.isBuffer(a)||!e.isBuffer(b))throw new TypeError("Arguments must be Buffers");for(var h=a.length,w=b.length,y=0,I=Math.min(h,w);y>>1;break;case "utf8":case "utf-8":h=k(a).length;break;case "base64":h=n.toByteArray(a).length; +break;default:h=a.length}return h};e.prototype.length=void 0;e.prototype.parent=void 0;e.prototype.toString=function(a,b,h){var w=!1;b>>>=0;h=void 0===h||Infinity===h?this.length:h>>>0;a||(a="utf8");0>b&&(b=0);h>this.length&&(h=this.length);if(h<=b)return"";for(;;)switch(a){case "hex":a=b;b=h;h=this.length;if(!a||0>a)a=0;if(!b||0>b||b>h)b=h;w="";for(h=a;hw?"0"+w.toString(16):w.toString(16),w=a+w;return w;case "utf8":case "utf-8":w=a="";for(h=Math.min(this.length,h);b= +this[b]?(a+=g(w)+String.fromCharCode(this[b]),w=""):w+="%"+this[b].toString(16);return a+g(w);case "ascii":return p(this,b,h);case "binary":return p(this,b,h);case "base64":return b=0===b&&h===this.length?n.fromByteArray(this):n.fromByteArray(this.slice(b,h)),b;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":b=this.slice(b,h);h="";for(a=0;ab&&(a+=" ... "));return""};e.prototype.compare=function(a){if(!e.isBuffer(a))throw new TypeError("Argument must be a Buffer");return e.compare(this,a)};e.prototype.get=function(a){console.log(".get() is deprecated. Access using array indexes instead."); +return this.readUInt8(a)};e.prototype.set=function(a,b){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(a,b)};e.prototype.write=function(a,b,h,w){if(isFinite(b))isFinite(h)||(w=h,h=void 0);else{var y=w;w=b;b=h;h=y}b=Number(b)||0;y=this.length-b;h?(h=Number(h),h>y&&(h=y)):h=y;w=String(w||"utf8").toLowerCase();switch(w){case "hex":b=Number(b)||0;w=this.length-b;h?(h=Number(h),h>w&&(h=w)):h=w;w=a.length;if(0!==w%2)throw Error("Invalid hex string");h>w/ +2&&(h=w/2);for(w=0;w>8;K%=256;y.push(K);y.push(w)}a=d(y,this,b,h,2);break;default:throw new TypeError("Unknown encoding: "+ +w);}return a};e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};e.prototype.slice=function(a,b){var h=this.length;a=~~a;b=void 0===b?h:~~b;0>a?(a+=h,0>a&&(a=0)):a>h&&(a=h);0>b?(b+=h,0>b&&(b=0)):b>h&&(b=h);b>>=0;h||m(this,a,b,1,255,0);e.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));this[b]=a;return b+1};e.prototype.writeUInt16LE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,2,65535,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):f(this,a,b,!0);return b+2};e.prototype.writeUInt16BE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,2,65535,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):f(this,a,b,!1);return b+2};e.prototype.writeUInt32LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,4294967295,0);e.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=a):c(this,a,b,!0);return b+4};e.prototype.writeUInt32BE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,4,4294967295,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):c(this,a,b,!1);return b+4};e.prototype.writeInt8=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,1,127,-128);e.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));0>a&&(a=255+a+1);this[b]=a;return b+1};e.prototype.writeInt16LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,2,32767,-32768);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):f(this,a,b,!0);return b+2};e.prototype.writeInt16BE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,2,32767,-32768);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):f(this,a,b,!1);return b+2};e.prototype.writeInt32LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,2147483647,-2147483648);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):c(this,a,b,!0);return b+4};e.prototype.writeInt32BE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,2147483647,-2147483648);0>a&&(a=4294967295+a+1);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+ +2]=a>>>8,this[b+3]=a):c(this,a,b,!1);return b+4};e.prototype.writeFloatLE=function(a,b,h){return q(this,a,b,!0,h)};e.prototype.writeFloatBE=function(a,b,h){return q(this,a,b,!1,h)};e.prototype.writeDoubleLE=function(a,b,h){return r(this,a,b,!0,h)};e.prototype.writeDoubleBE=function(a,b,h){return r(this,a,b,!1,h)};e.prototype.copy=function(a,b,h,w){h||(h=0);w||0===w||(w=this.length);b||(b=0);if(w!==h&&0!==a.length&&0!==this.length){if(wb||b>=a.length)throw new TypeError("targetStart out of bounds"); +if(0>h||h>=this.length)throw new TypeError("sourceStart out of bounds");if(0>w||w>this.length)throw new TypeError("sourceEnd out of bounds");w>this.length&&(w=this.length);a.length-bw||!e.TYPED_ARRAY_SUPPORT)for(var y=0;yb||b>=this.length)throw new TypeError("start out of bounds"); +if(0>h||h>this.length)throw new TypeError("end out of bounds");if("number"===typeof a)for(;b>1,r=-7;f=t?f-1:0;var k=t?-1:1,u=e[p+f];f+=k;t=u&(1<<-r)-1;u>>=-r;for(r+=c;0>=-r;for(r+=m;0>1,u=23===f?Math.pow(2,-24)-Math.pow(2,-77):0;c=m?0:c-1;var d=m?1:-1,g=0>p||0===p&&0>1/p?1:0;p=Math.abs(p);isNaN(p)||Infinity===p?(p=isNaN(p)?1:0,m=r):(m=Math.floor(Math.log(p)/Math.LN2),1>p*(l=Math.pow(2,-m))&&(m--,l*=2),p=1<=m+k?p+u/l:p+u*Math.pow(2,1-k),2<=p*l&&(m++,l/=2),m+k>=r?(p=0,m=r):1<=m+k?(p=(p*l-1)*Math.pow(2,f),m+=k):(p=p*Math.pow(2,k-1)*Math.pow(2,f),m=0));for(;8<=f;e[t+c]=p&255,c+= +d,p/=256,f-=8);m=m<z?[]:n.slice(v,z-v+1)}c=A.resolve(c).substr(1);l=A.resolve(l).substr(1); +for(var r=q(c.split("/")),k=q(l.split("/")),u=Math.min(r.length,k.length),d=u,g=0;gl&&(l=c.length+l);return c.substr(l,q)}}).call(this,C("g5I+bs"))},{"g5I+bs":9}],9:[function(C,J,A){function e(){}C=J.exports={};C.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(t){return window.setImmediate(t)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var p=[];window.addEventListener("message",function(t){var m=t.source;m!==window&&null!== +m||"process-tick"!==t.data||(t.stopPropagation(),0p?(-p<<1)+1:p<<1;do p=m&31,m>>>=5,0=f)throw Error("Expected more digits in base 64 VLQ value.");var q=e.decode(p.charCodeAt(t++));if(-1===q)throw Error("Invalid base64 digit: "+p.charAt(t-1));var r=!!(q&32);q&=31;c+=q<>1;m.value=1===(c&1)?-p:p;m.rest=t}},{"./base64":12}],12:[function(C, +J,A){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");A.encode=function(p){if(0<=p&&p=p?p-65:97<=p&&122>=p?p-97+26:48<=p&&57>=p?p-48+52:43==p?62:47==p?63:-1}},{}],13:[function(C,J,A){function e(p,t,m,f,c,l){var q=Math.floor((t-p)/2)+p,r=c(m,f[q],!0);return 0===r?q:0p?-1:p}A.GREATEST_LOWER_BOUND=1;A.LEAST_UPPER_BOUND=2;A.search=function(p,t,m,f){if(0===t.length)return-1;p=e(-1,t.length,p,t,m,f||A.GREATEST_LOWER_BOUND);if(0>p)return-1;for(;0<=p-1&&0===m(t[p],t[p-1],!0);)--p;return p}},{}],14:[function(C,J,A){function e(){this._array=[];this._sorted=!0;this._last={generatedLine:-1,generatedColumn:0}}var p=C("./util");e.prototype.unsortedForEach=function(t,m){this._array.forEach(t,m)};e.prototype.add=function(t){var m=this._last,f=m.generatedLine, +c=t.generatedLine,l=m.generatedColumn,q=t.generatedColumn;c>f||c==f&&q>=l||0>=p.compareByGeneratedPositionsInflated(m,t)?this._last=t:this._sorted=!1;this._array.push(t)};e.prototype.toArray=function(){this._sorted||(this._array.sort(p.compareByGeneratedPositionsInflated),this._sorted=!0);return this._array};A.MappingList=e},{"./util":19}],15:[function(C,J,A){function e(t,m,f){var c=t[m];t[m]=t[f];t[f]=c}function p(t,m,f,c){if(f=m(t[r],q)&&(l+=1,e(t,l,r));e(t,l+1,r);l+=1;p(t,m,f,l-1);p(t,m,l+1,c)}}A.quickSort=function(t,m){p(t,m,0,t.length-1)}},{}],16:[function(C,J,A){function e(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));return null!=d.sections?new m(d,u):new p(d,u)}function p(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));var g=f.getArg(d,"version"),n=f.getArg(d,"sources"),v=f.getArg(d,"names",[]),z=f.getArg(d,"sourceRoot",null),G=f.getArg(d,"sourcesContent",null),D=f.getArg(d, +"mappings");d=f.getArg(d,"file",null);if(g!=this._version)throw Error("Unsupported version: "+g);z&&(z=f.normalize(z));n=n.map(String).map(f.normalize).map(function(L){return z&&f.isAbsolute(z)&&f.isAbsolute(L)?f.relative(z,L):L});this._names=l.fromArray(v.map(String),!0);this._sources=l.fromArray(n,!0);this.sourceRoot=z;this.sourcesContent=G;this._mappings=D;this._sourceMapURL=u;this.file=d}function t(){this.generatedColumn=this.generatedLine=0;this.name=this.originalColumn=this.originalLine=this.source= +null}function m(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));var g=f.getArg(d,"version");d=f.getArg(d,"sections");if(g!=this._version)throw Error("Unsupported version: "+g);this._sources=new l;this._names=new l;var n={line:-1,column:0};this._sections=d.map(function(v){if(v.url)throw Error("Support for url field in sections not implemented.");var z=f.getArg(v,"offset"),G=f.getArg(z,"line"),D=f.getArg(z,"column");if(G=k[d])throw new TypeError("Line must be greater than or equal to 1, got "+ +k[d]);if(0>k[g])throw new TypeError("Column must be greater than or equal to 0, got "+k[g]);return c.search(k,u,n,v)};p.prototype.computeColumnSpans=function(){for(var k=0;k=this._sources.size()&&!this.sourcesContent.some(function(k){return null==k}):!1};p.prototype.sourceContentFor=function(k,u){if(!this.sourcesContent)return null;var d=k;null!=this.sourceRoot&&(d=f.relative(this.sourceRoot,d));if(this._sources.has(d))return this.sourcesContent[this._sources.indexOf(d)]; +var g=this.sources,n;for(n=0;n +g||95!==d.charCodeAt(g-1)||95!==d.charCodeAt(g-2)||111!==d.charCodeAt(g-3)||116!==d.charCodeAt(g-4)||111!==d.charCodeAt(g-5)||114!==d.charCodeAt(g-6)||112!==d.charCodeAt(g-7)||95!==d.charCodeAt(g-8)||95!==d.charCodeAt(g-9))return!1;for(g-=10;0<=g;g--)if(36!==d.charCodeAt(g))return!1;return!0}function r(d,g){return d===g?0:null===d?1:null===g?-1:d>g?1:-1}A.getArg=function(d,g,n){if(g in d)return d[g];if(3===arguments.length)return n;throw Error('"'+g+'" is a required argument.');};var k=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/, +u=/^data:.+,.+$/;A.urlParse=e;A.urlGenerate=p;A.normalize=t;A.join=m;A.isAbsolute=function(d){return"/"===d.charAt(0)||k.test(d)};A.relative=function(d,g){""===d&&(d=".");d=d.replace(/\/$/,"");for(var n=0;0!==g.indexOf(d+"/");){var v=d.lastIndexOf("/");if(0>v)return g;d=d.slice(0,v);if(d.match(/^([^\/]+:\/)?\/*$/))return g;++n}return Array(n+1).join("../")+g.substr(d.length+1)};C=!("__proto__"in Object.create(null));A.toSetString=C?f:c;A.fromSetString=C?f:l;A.compareByOriginalPositions=function(d, +g,n){var v=r(d.source,g.source);if(0!==v)return v;v=d.originalLine-g.originalLine;if(0!==v)return v;v=d.originalColumn-g.originalColumn;if(0!==v||n)return v;v=d.generatedColumn-g.generatedColumn;if(0!==v)return v;v=d.generatedLine-g.generatedLine;return 0!==v?v:r(d.name,g.name)};A.compareByGeneratedPositionsDeflated=function(d,g,n){var v=d.generatedLine-g.generatedLine;if(0!==v)return v;v=d.generatedColumn-g.generatedColumn;if(0!==v||n)return v;v=r(d.source,g.source);if(0!==v)return v;v=d.originalLine- +g.originalLine;if(0!==v)return v;v=d.originalColumn-g.originalColumn;return 0!==v?v:r(d.name,g.name)};A.compareByGeneratedPositionsInflated=function(d,g){var n=d.generatedLine-g.generatedLine;if(0!==n)return n;n=d.generatedColumn-g.generatedColumn;if(0!==n)return n;n=r(d.source,g.source);if(0!==n)return n;n=d.originalLine-g.originalLine;if(0!==n)return n;n=d.originalColumn-g.originalColumn;return 0!==n?n:r(d.name,g.name)};A.parseSourceMapInput=function(d){return JSON.parse(d.replace(/^\)]}'[^\n]*\n/, +""))};A.computeSourceURL=function(d,g,n){g=g||"";d&&("/"!==d[d.length-1]&&"/"!==g[0]&&(d+="/"),g=d+g);if(n){d=e(n);if(!d)throw Error("sourceMapURL could not be parsed");d.path&&(n=d.path.lastIndexOf("/"),0<=n&&(d.path=d.path.substring(0,n+1)));g=m(p(d),g)}return t(g)}},{}],20:[function(C,J,A){A.SourceMapGenerator=C("./lib/source-map-generator").SourceMapGenerator;A.SourceMapConsumer=C("./lib/source-map-consumer").SourceMapConsumer;A.SourceNode=C("./lib/source-node").SourceNode},{"./lib/source-map-consumer":16, +"./lib/source-map-generator":17,"./lib/source-node":18}],21:[function(C,J,A){(function(e){function p(){return"browser"===a?!0:"node"===a?!1:"undefined"!==typeof window&&"function"===typeof XMLHttpRequest&&!(window.require&&window.module&&window.process&&"renderer"===window.process.type)}function t(x){return function(B){for(var F=0;F";B=this.getLineNumber();null!=B&&(x+=":"+B,(B= +this.getColumnNumber())&&(x+=":"+B))}B="";var F=this.getFunctionName(),E=!0,H=this.isConstructor();if(this.isToplevel()||H)H?B+="new "+(F||""):F?B+=F:(B+=x,E=!1);else{H=this.getTypeName();"[object Object]"===H&&(H="null");var M=this.getMethodName();F?(H&&0!=F.indexOf(H)&&(B+=H+"."),B+=F,M&&F.indexOf("."+M)!=F.length-M.length-1&&(B+=" [as "+M+"]")):B+=H+"."+(M||"")}E&&(B+=" ("+x+")");return B}function q(x){var B={};Object.getOwnPropertyNames(Object.getPrototypeOf(x)).forEach(function(F){B[F]= +/^(?:is|get)/.test(F)?function(){return x[F].call(x)}:x[F]});B.toString=l;return B}function r(x,B){void 0===B&&(B={nextPosition:null,curPosition:null});if(x.isNative())return B.curPosition=null,x;var F=x.getFileName()||x.getScriptNameOrSourceURL();if(F){var E=x.getLineNumber(),H=x.getColumnNumber()-1,M=/^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/,S=M.test;var V="object"===typeof e&&null!==e?e.version:"";M=S.call(M,V)?0:62;1===E&&H>M&&!p()&&!x.isEval()&&(H-=M);var O= +f({source:F,line:E,column:H});B.curPosition=O;x=q(x);var T=x.getFunctionName;x.getFunctionName=function(){return null==B.nextPosition?T():B.nextPosition.name||T()};x.getFileName=function(){return O.source};x.getLineNumber=function(){return O.line};x.getColumnNumber=function(){return O.column+1};x.getScriptNameOrSourceURL=function(){return O.source};return x}var Q=x.isEval()&&x.getEvalOrigin();Q&&(Q=c(Q),x=q(x),x.getEvalOrigin=function(){return Q});return x}function k(x,B){L&&(b={},h={});for(var F= +(x.name||"Error")+": "+(x.message||""),E={nextPosition:null,curPosition:null},H=[],M=B.length-1;0<=M;M--)H.push("\n at "+r(B[M],E)),E.nextPosition=E.curPosition;E.curPosition=E.nextPosition=null;return F+H.reverse().join("")}function u(x){var B=/\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(x.stack);if(B){x=B[1];var F=+B[2];B=+B[3];var E=b[x];if(!E&&v&&v.existsSync(x))try{E=v.readFileSync(x,"utf8")}catch(H){E=""}if(E&&(E=E.split(/(?:\r\n|\r|\n)/)[F-1]))return x+":"+F+"\n"+E+"\n"+Array(B).join(" ")+ +"^"}return null}function d(){var x=e.emit;e.emit=function(B){if("uncaughtException"===B){var F=arguments[1]&&arguments[1].stack,E=0{}) +define("crelt",[],()=>{}) diff --git a/beta/lang/en-nz.js b/beta/lang/en-nz.js new file mode 100644 index 0000000..c13ee38 --- /dev/null +++ b/beta/lang/en-nz.js @@ -0,0 +1 @@ +(function(factory){if(typeof module==="object"&&typeof module.exports==="object"){var v=factory(require, exports);if(v!==undefined)module.exports=v}else if(typeof define==="function"&&define.amd){define(["require","exports"],factory);}})(function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});let s=t=>typeof t=="string"?t:Array.isArray(t)?t.map(s).join(""):typeof t.content=="object"?s(t.content):t.content;let ii=u=>(typeof u=="object"||typeof u=="function")&&Symbol.iterator in u;let c=c=>({content:c,toString(){return s(this.content)}});let j=(a,s,v)=>{a=(!a?[]:Array.isArray(a)?a:ii(a)?[...a]:[a]);return (v?a.map(v):a).flatMap((v,i)=>i!v?0:typeof v.length=="number"?v.length:typeof v.size=="number"?v.size:ii(v)?[...v].length:typeof v=="object"?Object.keys(v).length:0;var q={"fluff4me/title":_=>c([{content:"fluff4.me / Tell your story!"}]),"home/label":_=>c([{content:"home"}]),"shared/preview":_=>c([{content:"Preview"}]),"shared/prompt/confirm":_=>c([{content:"Are you sure?"}]),"shared/prompt/reauth":_=>c([{content:"To perform this action, reauthenticate to verify your identity:"}]),"shared/term/chapters":_=>c([{content:"Chapters"}]),"shared/action/login-or-signup":_=>c([{content:"Log In or Sign Up"}]),"shared/action/view":_=>c([{content:"View"}]),"shared/action/love":_=>c([{content:"Love"}]),"shared/action/edit":_=>c([{content:"Edit"}]),"shared/action/follow":_=>c([{content:"Follow"}]),"shared/action/ignore":_=>c([{content:"Ignore"}]),"shared/action/delete":(...a)=>c([{content:"Delete"},{content:(a[0]?[{content:" "},a[0]]:[])}]),"shared/action/save":_=>c([{content:"Save Changes"}]),"shared/action/create":_=>c([{content:"Create!"}]),"shared/action/cancel":_=>c([{content:"Cancel"}]),"shared/action/confirm":_=>c([{content:"Confirm"}]),"shared/toast/failed-to-save":(...a)=>c([{content:"Failed to save "},{content:a[0]}]),"shared/toast/saved":(...a)=>c([{content:"Saved "},{content:a[0]}]),"shared/form/name/label":_=>c([{content:"Name"}]),"shared/form/vanity/label":_=>c([{content:"Vanity"}]),"shared/form/description/label":_=>c([{content:"Description"}]),"shared/form/body/label":_=>c([{content:"Body"}]),"component/popover/button":(...a)=>c([{content:"open "},{content:(a[0]?a[0]:[{content:"details"}])},{content:(a[1]?[{content:" "},a[1]]:[])}]),"component/popover":(...a)=>c([{content:(a[0]?a[0]:[{content:"details"}])}]),"component/paginator/error":_=>c([{content:"Failed to load content."}]),"component/paginator/error/retry":_=>c([{content:"Retry"}]),"component/text-editor/toolbar/group/inline":_=>c([{content:"inline formatting"}]),"component/text-editor/toolbar/button/strong":_=>c([{content:"strong (bold)"}]),"component/text-editor/toolbar/button/em":_=>c([{content:"emphasis (italic)"}]),"component/text-editor/toolbar/button/underline":_=>c([{content:"underline"}]),"component/text-editor/toolbar/button/strikethrough":_=>c([{content:"strikethrough"}]),"component/text-editor/toolbar/button/subscript":_=>c([{content:"subscript"}]),"component/text-editor/toolbar/button/superscript":_=>c([{content:"superscript"}]),"component/text-editor/toolbar/button/code":_=>c([{content:"code"}]),"component/text-editor/toolbar/button/link":_=>c([{content:"link"}]),"component/text-editor/toolbar/button/other-formatting":_=>c([{content:"other formatting options"}]),"component/text-editor/toolbar/group/block":_=>c([{content:"block formatting"}]),"component/text-editor/toolbar/button/align":(...a)=>c([{content:"text align (currently "},{content:a[0]},{content:")"}]),"component/text-editor/toolbar/button/align-left":_=>c([{content:"align left"}]),"component/text-editor/toolbar/button/align-centre":_=>c([{content:"centre"}]),"component/text-editor/toolbar/button/align-right":_=>c([{content:"align right"}]),"component/text-editor/toolbar/button/align/currently/left":_=>c([{content:"aligned left"}]),"component/text-editor/toolbar/button/align/currently/right":_=>c([{content:"aligned right"}]),"component/text-editor/toolbar/button/align/currently/centre":_=>c([{content:"centred"}]),"component/text-editor/toolbar/button/align/currently/mixed":_=>c([{content:"mixed"}]),"component/text-editor/toolbar/button/block-type":(...a)=>c([{content:"block type (currently "},{content:a[0]},{content:")"}]),"component/text-editor/toolbar/button/code-block":_=>c([{content:"code block"}]),"component/text-editor/toolbar/button/paragraph":_=>c([{content:"paragraph"}]),"component/text-editor/toolbar/button/block-type/currently/code-block":_=>c([{content:"code block"}]),"component/text-editor/toolbar/button/block-type/currently/paragraph":_=>c([{content:"paragraph"}]),"component/text-editor/toolbar/button/block-type/currently/mixed":_=>c([{content:"mixed"}]),"component/text-editor/toolbar/group/wrapper":_=>c([{content:"block wrappers"}]),"component/text-editor/toolbar/button/lift":_=>c([{content:"unwrap"}]),"component/text-editor/toolbar/button/bullet-list":_=>c([{content:"wrap in list"}]),"component/text-editor/toolbar/button/ordered-list":_=>c([{content:"wrap in ordered list"}]),"component/text-editor/toolbar/button/blockquote":_=>c([{content:"wrap in block quote"}]),"component/text-editor/toolbar/group/insert":_=>c([{content:"insert"}]),"component/text-editor/toolbar/button/hr":_=>c([{content:"horizontal rule"}]),"component/text-editor/toolbar/group/actions":_=>c([{content:"actions"}]),"component/text-editor/toolbar/button/undo":_=>c([{content:"undo"}]),"component/text-editor/toolbar/button/redo":_=>c([{content:"redo"}]),"component/text-editor/toolbar/button/fullscreen":_=>c([{content:"fullscreen"}]),"component/text-editor/toolbar/button/unfullscreen":_=>c([{content:"exit fullscreen"}]),"component/text-editor/formatting/none":_=>c([{content:"no formatting"}]),"component/text-editor/formatting/strong":_=>c([{content:"strong (bolded)"}]),"component/text-editor/formatting/em":_=>c([{content:"emphasised (italic)"}]),"component/text-editor/formatting/underline":_=>c([{content:"underlined"}]),"component/text-editor/formatting/strikethrough":_=>c([{content:"strikethrough"}]),"component/text-editor/formatting/subscript":_=>c([{content:"subscript"}]),"component/text-editor/formatting/superscript":_=>c([{content:"superscript"}]),"component/text-editor/formatting/code":_=>c([{content:"code"}]),"component/text-editor/formatting/link":_=>c([{content:"link"}]),"masthead/skip-navigation":_=>c([{content:"Skip Navigation"}]),"masthead/user/notifications/alt":_=>c([{content:"notifications"}]),"masthead/primary-nav/alt":_=>c([{content:"primary"}]),"masthead/user/profile/alt":_=>c([{content:"profile"}]),"masthead/user/profile/popover/login":(...a) => q["shared/action/login-or-signup"](...a),"masthead/user/profile/popover/profile":_=>c([{content:"View Profile"}]),"masthead/user/profile/popover/account":_=>c([{content:"Account Settings"}]),"work/chapters/label":(...a) => q["shared/term/chapters"](...a),"work/description/empty":_=>c([{content:"This work has no description."}]),"author/description/empty":_=>c([{content:"This author prefers to remain elusive and mysterious..."}]),"view/container/alt":_=>c([{content:"main content"}]),"view/shared/login-required/title":_=>c([{content:"Log-in required"}]),"view/shared/login-required/description":_=>c([{content:"You must log in or sign up to view this content."}]),"view/shared/login-required/action":(...a) => q["shared/action/login-or-signup"](...a),"view/error/title":(...a)=>c([{content:"Error "},{content:a[0]?.CODE}]),"view/error/description-404":_=>c([{content:"Your adventure has come to a close, your questions left unanswered, your goals unfulfilled. What will you do?"}]),"view/feed/main/title":_=>c([{content:"Recent Updates"}]),"view/feed/content/empty":_=>c([{content:"And all was quiet..."}]),"view/account/name/label":(...a) => q["shared/form/name/label"](...a),"view/account/name/hint":_=>c([{content:"Your display name or penname — the name your comments and works are attributed to. This can be changed whenever you like, and doesn't have to be unique."}]),"view/account/vanity/label":(...a) => q["shared/form/vanity/label"](...a),"view/account/vanity/hint":_=>c([{content:"Your username, and what people use to "},{content:[{content:"@ping"}],tag:`B`},{content:" you in comments. This "},{content:[{content:"can"}],tag:`I`},{content:" be changed whenever you like, but "},{content:[{content:"must always be unique"}],tag:`B`},{content:"."}]),"view/account/vanity/url-preview":(...a) => q["shared/preview"](...a),"view/account/description/label":(...a) => q["shared/form/description/label"](...a),"view/account/description/hint":_=>c([{content:"This bio will appear on your profile above any works."}]),"view/account/support-link/label":_=>c([{content:"Support Link"}]),"view/account/support-link/hint":_=>c([{content:"An optional link that people can use to support you. You could link directly to a payment or subscription platform, or you could use a service like Linktree."}]),"view/account/support-message/label":_=>c([{content:"Message"}]),"view/account/support-message/hint":_=>c([{content:"A message to display instead of the support link itself. This is required, and will default to \"Support My Writing.\"\nIf you want it to actually display the link, for whatever reason, you can put the link here as well."}]),"view/account/support-message/placeholder":_=>c([{content:"Support My Writing"}]),"view/account/pronouns/label":_=>c([{content:"Pronouns"}]),"view/account/pronouns/hint":_=>c([{content:"The pronouns that others should refer to you with. These will appear next to your name, usually."}]),"view/account/action/logout":_=>c([{content:"Log Out"}]),"view/account/action/delete":_=>c([{content:"Delete Account"}]),"view/account/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](_=>c([{content:"| account data"}]), ...a),"view/account/toast/saved":(...a) => q["shared/toast/saved"](_=>c([{content:"| account data"}]), ...a),"view/account/auth/service/accessibility/connect":(...a)=>c([{content:"connect "},{content:a[0]}]),"view/account/auth/service/accessibility/disconnect":(...a)=>c([{content:"disconnect "},{content:a[0]},{content:" account "},{content:a[1]}]),"view/account/auth/none/title":_=>c([{content:"Log in or sign up"}]),"view/account/auth/none/description":_=>c([{content:"fluff4.me does not store an email address or password for your account. You must authenticate with a third-party service to begin."}]),"view/account/auth/has-authorisations/title":_=>c([{content:"Authorisations"}]),"view/account/auth/has-authorisations/description":_=>c([{content:"Your authorisation(s) are not currently associated with a fluff4.me account. You may authenticate with additional third party services to log in or sign up."}]),"view/account/auth/logged-in/title":_=>c([{content:"Authorisations"}]),"view/account/auth/logged-in/description":_=>c([{content:"These third party service accounts are linked to your fluff4.me account and may be used to log in."}]),"view/account/create/title":_=>c([{content:"Create account"}]),"view/account/create/description":_=>c([{content:"The "},{content:[{content:"connected third party service accounts"}],tag:`LINK(#authorisations)`},{content:" will be used for login."}]),"view/account/create/submit":_=>c([{content:"Sign Up!"}]),"view/account/update/title":_=>c([{content:"Update profile"}]),"view/account/update/submit":(...a) => q["shared/action/save"](...a),"view/author/works/title":_=>c([{content:"Works"}]),"view/author/works/content/empty":_=>c([{content:"This author has not yet shared any work..."}]),"view/author/works/action/label/new":_=>c([{content:"New Work"}]),"view/author/works/action/label/view":(...a) => q["shared/action/view"](...a),"view/author/works/action/label/edit":(...a) => q["shared/action/edit"](...a),"view/author/works/action/label/follow":(...a) => q["shared/action/follow"](...a),"view/author/works/action/label/ignore":(...a) => q["shared/action/ignore"](...a),"view/author/works/action/label/delete":(...a) => q["shared/action/delete"](...a),"view/work-edit/shared/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](...a),"view/work-edit/shared/toast/saved":(...a) => q["shared/toast/saved"](...a),"view/work-edit/shared/form/name/label":(...a) => q["shared/form/name/label"](...a),"view/work-edit/shared/form/name/hint":_=>c([{content:"The name of your work. This does not have to be unique."}]),"view/work-edit/shared/form/vanity/label":(...a) => q["shared/form/vanity/label"](...a),"view/work-edit/shared/form/vanity/hint":_=>c([{content:"The identifier for this work, which will appear in its URL."}]),"view/work-edit/shared/form/vanity/url-preview":(...a) => q["shared/preview"](...a),"view/work-edit/shared/form/description/label":(...a) => q["shared/form/description/label"](...a),"view/work-edit/shared/form/description/hint":_=>c([{content:"A simple 1-2 sentence description of the work. This will be the only descriptive text shown when works are displayed in lists."}]),"view/work-edit/shared/form/synopsis/label":_=>c([{content:"Synopsis"}]),"view/work-edit/shared/form/synopsis/hint":_=>c([{content:"The full text describing this work. This will only appear in the full work view."}]),"view/work-edit/create/title":_=>c([{content:"Create work"}]),"view/work-edit/create/submit":(...a) => q["shared/action/create"](...a),"view/work-edit/update/title":_=>c([{content:"Edit work"}]),"view/work-edit/update/submit":(...a) => q["shared/action/save"](...a),"view/work-edit/update/action/delete":_=>c([{content:"Delete Work"}]),"view/work/chapters/title":(...a) => q["shared/term/chapters"](...a),"view/work/chapters/content/empty":_=>c([{content:"This work does not contain any chapters."}]),"view/work/chapters/action/label/new":_=>c([{content:"New Chapter"}]),"view/work/chapters/action/label/view":(...a) => q["shared/action/view"](...a),"view/work/chapters/action/label/love":(...a) => q["shared/action/love"](...a),"view/work/chapters/action/label/edit":(...a) => q["shared/action/edit"](...a),"view/work/chapters/action/label/delete":(...a) => q["shared/action/delete"](...a),"view/chapter-edit/shared/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](_=>c([{content:"| chapter"}]), ...a),"view/chapter-edit/shared/toast/saved":(...a) => q["shared/toast/saved"](_=>c([{content:"| chapter"}]), ...a),"view/chapter-edit/shared/form/name/label":(...a) => q["shared/form/name/label"](...a),"view/chapter-edit/shared/form/name/hint":_=>c([{content:"The name of this chapter. This does not have to be unique."}]),"view/chapter-edit/shared/form/body/label":(...a) => q["shared/form/body/label"](...a),"view/chapter-edit/shared/form/body/hint":_=>c([{content:"The content of this chapter. There is no specific character count limit, but if your chapter exceeds 1MB it will be rejected. You will probably never run into this."}]),"view/chapter-edit/create/title":_=>c([{content:"Create chapter"}]),"view/chapter-edit/create/submit":(...a) => q["shared/action/create"](...a),"view/chapter-edit/update/title":_=>c([{content:"Edit chapter"}]),"view/chapter-edit/update/submit":(...a) => q["shared/action/save"](...a),"view/chapter-edit/update/action/delete":_=>c([{content:"Delete Chapter"}]),"view/chapter/title":(...a)=>c([...a[0]?[{content:a[0]},{content:". "}]:[],{content:a[1]}]),};exports.default=q}) \ No newline at end of file diff --git a/beta/oembed.json b/beta/oembed.json new file mode 100644 index 0000000..1c06a0c --- /dev/null +++ b/beta/oembed.json @@ -0,0 +1,6 @@ +{ + "author_name": "Tell your story!", + "provider_name": "fluff4.me", + "provider_url": "https://fluff4.me", + "type": "photo" +} \ No newline at end of file diff --git a/beta/style/index.css b/beta/style/index.css new file mode 100644 index 0000000..ae0f3b7 --- /dev/null +++ b/beta/style/index.css @@ -0,0 +1,2743 @@ +@import url("https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"); +@import url("https://fonts.googleapis.com/css2?family=Kanit&display=swap"); + +@property --transition-duration { + syntax: "

+
where js go???
+
it not here...
+
+ + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..d19fdbe --- /dev/null +++ b/index.js @@ -0,0 +1,11453 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +define("utility/Env", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class Env { + get isDev() { + return this.ENVIRONMENT === "dev"; + } + async load() { + const origin = location.origin; + const root = location.pathname.startsWith("/beta/") ? "/beta/" : "/"; + Object.assign(this, await fetch(origin + root + "env.json").then(response => response.json())); + document.documentElement.classList.add(`environment-${this.ENVIRONMENT}`); + } + } + exports.default = new Env; +}); +define("utility/Type", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +}); +define("utility/Objects", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Objects; + (function (Objects) { + Objects.EMPTY = {}; + function keys(object) { + return Object.keys(object); + } + Objects.keys = keys; + function values(object) { + return Object.values(object); + } + Objects.values = values; + function inherit(obj, inherits) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + Object.setPrototypeOf(obj, inherits.prototype); + return obj; + } + Objects.inherit = inherit; + function filterNullish(object) { + return filter(object, p => p[1] !== null && p[1] !== undefined); + } + Objects.filterNullish = filterNullish; + function filter(object, filter) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unnecessary-type-assertion + return Object.fromEntries(Object.entries(object).filter(filter)); + } + Objects.filter = filter; + function map(object, mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unnecessary-type-assertion + return Object.fromEntries(Object.entries(object).map(mapper)); + } + Objects.map = map; + async function mapAsync(object, mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return Object.fromEntries(await Promise.all(Object.entries(object).map(mapper))); + } + Objects.mapAsync = mapAsync; + function followPath(obj, keys) { + for (const key of keys) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + obj = obj?.[key]; + return obj; + } + Objects.followPath = followPath; + function applyJIT(obj, key, compute) { + const get = (() => { + const promise = compute(); + delete obj[key]; + obj[key] = promise; + if (promise instanceof Promise) + void promise.then(value => obj[key] = value); + return promise; + }); + get.compute = compute; + Object.defineProperty(obj, key, { + configurable: true, + get, + }); + } + Objects.applyJIT = applyJIT; + function copyJIT(target, from, key) { + const descriptor = Object.getOwnPropertyDescriptor(from, key); + if (!descriptor) + return; + if ("value" in descriptor) { + target[key] = from[key]; + return; + } + const compute = descriptor.get?.compute; + if (!compute) + return; + applyJIT(target, key, compute); + } + Objects.copyJIT = copyJIT; + Objects.assign = function (target, ...sources) { + for (const source of sources) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + for (const key of Object.keys(source)) { + const descriptor = Object.getOwnPropertyDescriptor(target, key); + if (!descriptor || descriptor.writable) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + target[key] = source[key]; + } + } + } + return target; + }; + function merge(a, b) { + if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || Array.isArray(a) || Array.isArray(b)) + return (b === undefined ? a : b); + const result = {}; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + result[key] = merge(a[key], b[key]); + return result; + } + Objects.merge = merge; + })(Objects || (Objects = {})); + exports.default = Objects; +}); +define("utility/string/MarkdownItHTML", ["require", "exports", "entities"], function (require, exports, entities_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + entities_1 = __importDefault(entities_1); + const html = Object.assign(((md, options) => { + const state = { + block: undefined, + inline: undefined, + i: 0, + l: 0, + e: 0, + src: "", + silent: false, + options: { + ...html.defaultOptions, + ...options, + }, + }; + md.block.ruler.at("html_block", (block, startLine, endLine, silent) => { + state.block = block; + state.src = state.block.src; + state.l = startLine; + state.i = state.block.bMarks[state.l] + state.block.tShift[state.l]; + state.e = state.src.length; + state.silent = silent; + const result = html.consumeBlock(state); + state.block = undefined; + return result; + }, { alt: ["paragraph"] }); + md.inline.ruler.at("html_inline", (inline, silent) => { + state.inline = inline; + state.e = inline.posMax; + state.i = inline.pos; + state.src = inline.src; + state.silent = silent; + const result = html.consumeInline(state); + state.inline = undefined; + return result; + }); + }), { + regexCSSProperty: /^[-a-zA-Z_][a-zA-Z0-9_-]*$/, + defaultOptions: { + voidElements: [ + "area", + "base", + "br", + "col", + "embed", + "hr", + "img", + "input", + "link", + "meta", + "source", + "track", + "wbr", + ], + allowedTags: [ + // headings + "hgroup", + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + // layout + "div", + "p", + "br", + "wbr", + "hr", + "details", + "summary", + "label", + // lists + "ol", + "ul", + "li", + // tables + "table", + "tr", + "th", + "td", + "caption", + "thead", + "tbody", + "tfoot", + // text + "span", + // text style + "i", + "b", + "u", + "s", + "strike", + "sup", + "sub", + "em", + "mark", + "small", + "strong", + // quoting/referencing + "q", + "cite", + "blockquote", + // links + "a", + // definitions + "abbr", + "dfn", + "dd", + "dt", + "dl", + // code + "code", + "samp", + "kbd", + // images + "img", + "figure", + "figcaption", + "area", + "map", + ], + allTagsAllowedAttributes: [ + "title", + "name", + "style", + "aria-label", + "aria-labelledby", + "aria-describedby", + "aria-hidden", + ], + allTagsAllowedAttributeValues: {}, + perTagAllowedAttributes: { + "a": ["href"], + "img": ["src", "alt", "usemap", "width", "height"], + "area": ["shape", "coords"], + "details": ["open"], + "ol": ["type", "start", "reversed"], + "li": ["value"], + "th": ["colspan", "rowspan", "headers", "scope", "abbr"], + "td": ["colspan", "rowspan", "headers"], + "q": ["cite"], + }, + perTagAllowedAttributeValues: { + "a": { "href": /^https?:/ }, + "img": { "src": /^https?:/ }, + "area": { "href": /^https?:/ }, + "q": { "cite": /^https?:/ }, + "blockquote": { "cite": /^https?:/ }, + }, + allTagsAllowedStyleProperties: [ + "color", + "text-align", + "font-family", + "font-style", + "font-weight", + "text-decoration", + "text-transform", + "line-height", + "letter-spacing", + "word-spacing", + "vertical-align", + "background-color", + "opacity", + "margin", + "padding", + "width", + "height", + "vertical-align", + "box-shadow", + "border-width", + "border-style", + "border-color", + "border-radius", + "text-indent", + "display", + "position", + ], + allTagsAllowedStylePropertyValues: { + "position": ["relative", "absolute", "sticky"], + }, + perTagAllowedStyleProperties: {}, + perTagAllowedStylePropertyValues: {}, + }, + Options(options) { + const factory = Object.assign({ ...structuredClone(html.defaultOptions), ...options }, { + disallowTags(...tags) { + const disallowed = tags.map(tag => tag.toLowerCase()); + factory.allowedTags = factory.allowedTags.filter(tag => !disallowed.includes(tag)); + return factory; + }, + allowTags(...tags) { + factory.allowedTags = [...new Set([...factory.allowedTags, ...tags.map(tag => tag.toLowerCase())])]; + return factory; + }, + disallowAttributes(...attributes) { + const disallowed = attributes.map(attr => attr.toLowerCase()); + factory.allTagsAllowedAttributes = factory.allTagsAllowedAttributes.filter(attr => !disallowed.includes(attr)); + for (const [tag, allowedAttributes] of Object.entries(factory.perTagAllowedAttributes)) + factory.perTagAllowedAttributes[tag] = allowedAttributes.filter(attr => !disallowed.includes(attr)); + return factory; + }, + allowAttributes(...attributes) { + factory.allTagsAllowedAttributes = [...new Set([...factory.allTagsAllowedAttributes, ...attributes.map(attr => attr.toLowerCase())])]; + return factory; + }, + }); + return factory; + }, + use(md, options) { + return md.use(html, options); + }, + consumeBlock(state) { + if (!state.block) + return false; + html.consumeInlineWhitespace(state); + if (state.silent) + return html.consumeTerminator(state); + const result = html.consumeTagsLine(state); + if (!result) + return false; + state.l++; + state.block.line = state.l; + const indent = html.consumeInlineWhitespace(state) || 0; + if (indent >= state.block.blkIndent + 4) + state.block.blkIndent = indent - 4; // allow for indented code blocks within html block + else + state.block.blkIndent = indent; + return true; + }, + consumeInline(state) { + if (!state.inline || state.src[state.i] !== "<") + return false; + const tag = html.consumeTag(state); + if (!tag) + return false; + state.inline.pos = state.i; + return true; + }, + consumeTerminator(state) { + const noSetBlockIndent = new Error().stack?.split("\n")?.at(4)?.includes("Array.lheading"); + const indent = html.consumeInlineWhitespace(state) || 0; + if (!html.consumeTagsLine(state)) + return false; + if (!noSetBlockIndent && state.block) + state.block.blkIndent = indent; + return true; + }, + consumeTagsLine(state) { + let consumed = false; + const tokens = []; + let token; + while (token = html.consumeTag(state)) { + if (typeof token === "object") + tokens.push(token); + consumed = true; + html.consumeInlineWhitespace(state); + } + if (!consumed) + return undefined; + if (state.i < state.src.length && !html.consumeNewline(state)) { + // a line of tags MUST end in a newline — if this doesn't, remove all the tokens we added and don't match + if (tokens.length) + state.block?.tokens.splice(0, Infinity, ...state.block.tokens + .filter(token => !tokens.includes(token))); + return undefined; + } + return { + tokens, + }; + }, + consumeNewline(state) { + if (state.inline) + return false; + if (state.src[state.i] === "\n") { + state.i++; + return true; + } + if (state.src[state.i] !== "\r") + return false; + state.i++; + if (state.src[state.i] === "\n") + state.i++; + return true; + }, + consumeWhitespace(state) { + if (state.inline) + return !!html.consumeInlineWhitespace(state); + const start = state.i; + if (state.i >= state.e) + return false; + for (state.i; state.i < state.e; state.i++) { + if (!html.isWhitespace(state)) + break; + if (html.consumeNewline(state)) { + state.l++; + state.i--; + } + } + return state.i > start; + }, + consumeInlineWhitespace(state) { + if (state.i >= state.e) + return undefined; + let indent = 0; + for (state.i; state.i < state.e; state.i++) { + if (state.src[state.i] === " ") + indent++; + else if (state.src[state.i] === "\t") + indent += 4; + else + break; + } + return indent || undefined; + }, + consumeTag(state) { + if (state.src[state.i] !== "<") + return undefined; + state.i++; + return html.consumeOpenTag(state) ?? html.consumeCloseTag(state); + }, + consumeOpenTag(state) { + const start = state.i; + const tagNameRaw = html.consumeTagName(state); + if (!tagNameRaw) + return undefined; + const tagName = tagNameRaw.toLowerCase(); + const o = state.options; + if (!o.allowedTags.includes(tagNameRaw)) { + state.i = start; + return undefined; + } + const attributes = []; + let style; + while (html.consumeWhitespace(state)) { + const attribute = html.consumeAttribute(state); + if (!attribute) + break; + let [name, value] = attribute; + name = name.toLowerCase(); + if (!o.allTagsAllowedAttributes.includes(name) && !o.perTagAllowedAttributes[tagName]?.includes(name)) + continue; + value = entities_1.default.decodeHTML5Strict(value); + if (name !== "style") { + const allowedValues = o.perTagAllowedAttributeValues[tagName]?.[name] ?? o.allTagsAllowedAttributeValues[name]; + if (allowedValues !== undefined && !html.matchesAllowedValues(value, allowedValues)) + continue; + attributes.push(attribute); + continue; + } + style = html.parseStyleAttributeValue(value); + let styleValue = ""; + for (let [property, value] of style) { + property = property.toLowerCase(); + if (!o.allTagsAllowedStyleProperties.includes(property) && !o.perTagAllowedStyleProperties[tagName]?.includes(property)) + continue; + const importantToken = "!important"; + const important = value.slice(-importantToken.length).toLowerCase() === importantToken; + if (important) + value = value.slice(0, -importantToken.length).trim(); + const allowedValues = o.perTagAllowedStylePropertyValues[tagName]?.[property] ?? o.allTagsAllowedStylePropertyValues[property]; + if (allowedValues !== undefined && !html.matchesAllowedValues(value, allowedValues)) + continue; + styleValue += `${property}:${value}${important ? importantToken : ""};`; + } + if (styleValue.length) + attributes.push(["style", styleValue.slice(0, -1)]); + } + if (state.src[state.i] === "/") + state.i++; + if (state.src[state.i] !== ">") { + state.i = start; + return undefined; + } + state.i++; + const nesting = state.options.voidElements.includes(tagName) ? 0 : 1; + if (state.silent) + return true; + let type = `html_${state.block ? "block" : "inline"}${nesting ? "_open" : ""}`; + if (tagName === "br") + type = "softbreak"; + const mdState = state.block ?? state.inline; + const token = mdState.push(type, tagName, nesting); + Object.assign(token, { + style, + raw: state.src.slice(start - 1, state.i), + }); + for (const attribute of attributes) + token.attrPush(attribute); + return token; + }, + consumeCloseTag(state) { + const start = state.i; + if (state.src[state.i] !== "/") + return undefined; + state.i++; + const tagNameRaw = html.consumeTagName(state); + if (!tagNameRaw) + return undefined; + if (state.src[state.i] !== ">") { + state.i = start; + return undefined; + } + state.i++; + const tagName = tagNameRaw.toLowerCase(); + if (!state.options.allowedTags.includes(tagName)) { + state.i = start; + return undefined; + } + if (state.silent || state.options.voidElements.includes(tagName)) + return true; + const type = `html_${state.block ? "block" : "inline"}_close`; + const mdState = state.block ?? state.inline; + const token = mdState.push(type, tagName, -1); + Object.assign(token, { raw: state.src.slice(start - 1, state.i) }); + if (state.inline && !state.inline.delimiters) + state.inline.delimiters = []; + return token; + }, + consumeTagName(state) { + const start = state.i; + if (state.i >= state.e) + return undefined; + if (!html.isAlpha(state)) + return undefined; + for (state.i++; state.i < state.e; state.i++) + if (!html.isAlphaNumeric(state)) + break; + return state.src.slice(start, state.i); + }, + consumeAttribute(state) { + const start = state.i; + const name = html.consumeAttributeName(state); + if (!name) + return undefined; + const valueStart = state.i; + html.consumeWhitespace(state); + if (state.src[state.i] !== "=") { + state.i = valueStart; + return [name, ""]; + } + state.i++; + html.consumeWhitespace(state); + const value = html.consumeAttributeValue(state); + if (!value) { + state.i = start; + return undefined; + } + return [name, value]; + }, + consumeAttributeName(state) { + const start = state.i; + if (state.i >= state.e) + return undefined; + for (state.i; state.i < state.e; state.i++) { + const charCode = state.src.charCodeAt(state.i); + const isInvalidChar = false + || charCode === 0x0020 // SPACE + || charCode === 0x0022 // " + || charCode === 0x0027 // ' + || charCode === 0x003E // > + || charCode === 0x002F // / + || charCode === 0x003D // = + || html.isNonCharacter(state, charCode) + || html.isControl(state, charCode); + if (isInvalidChar) + break; + } + return state.i > start ? state.src.slice(start, state.i) : undefined; + }, + consumeAttributeValue(state) { + return false + || html.consumeUnquotedAttributeValue(state) + || html.consumeQuotedAttributeValue(state) + || undefined; + }, + consumeUnquotedAttributeValue(state) { + let result = ""; + while (state.i < state.e) { + const charCode = state.src.charCodeAt(state.i); + // Check for invalid characters in unquoted attribute values + const isInvalidChar = false + || charCode === 0x0022 // " + || charCode === 0x0027 // ' + || charCode === 0x003D // = + || charCode === 0x003C // < + || charCode === 0x003E // > + || charCode === 0x0060 // ` + || html.isWhitespace(state, charCode); // ASCII whitespace + if (isInvalidChar) + break; + if (charCode !== 0x0026) { // not & + result += state.src[state.i]; + state.i++; + continue; + } + const charRef = html.consumeCharacterReference(state); + if (!charRef) { + result += "&"; + state.i++; + continue; + } + result += charRef; + // `i` is already at the next pos + } + return result || undefined; + }, + consumeQuotedAttributeValue(state) { + const start = state.i; + const quoteChar = state.src[state.i]; + if (quoteChar !== "'" && quoteChar !== '"') + return undefined; + state.i++; + let result = ""; + while (state.i < state.e) { + const charCode = state.src.charCodeAt(state.i); + if (state.src[state.i] === quoteChar) { + state.i++; + return result; + } + if (charCode !== 0x0026) { // not & + const charStart = state.i; + if (html.consumeNewline(state)) { + state.l++; + result += state.src.slice(charStart, state.i); + continue; + } + const isNewlineInInlineMode = state.inline && html.isWhitespace(state) && state.src[state.i] !== " " && state.src[state.i] !== "\t"; + if (isNewlineInInlineMode) { + state.i = start; + return undefined; + } + result += state.src[state.i]; + state.i++; + continue; + } + const charRef = html.consumeCharacterReference(state); + if (!charRef) { + result += "&"; + state.i++; + continue; + } + result += charRef; + // `i` is already at the next pos + } + // no closing quote before the end of `src` + state.i = start; + return undefined; + }, + consumeCharacterReference(state) { + const start = state.i; + if (state.src[state.i] !== "&") + return undefined; + state.i++; + const isValid = html.consumeNumericCharacterReference(state) || html.consumeNamedCharacterReference(state); + if (!isValid) { + state.i = start; + return undefined; + } + return state.src.slice(start, state.i); + }, + consumeNamedCharacterReference(state) { + const nameStart = state.i; + for (state.i; state.i < state.e; state.i++) + if (!html.isAlpha(state)) + break; + if (state.i === nameStart || state.src[state.i] !== ";") + return false; + state.i++; + return true; + }, + consumeNumericCharacterReference(state) { + if (state.src[state.i] !== "#") + return false; + state.i++; + const isHex = state.src[state.i] === "x" || state.src[state.i] === "X"; + if (isHex) + state.i++; + const digitsStart = state.i; + for (state.i; state.i < state.e; state.i++) + if (isHex ? !html.isHexadecimal(state) : !html.isNumeric(state)) + break; + if (state.i === digitsStart || state.src[state.i] !== ";") + return false; + const codePoint = parseInt(state.src.slice(digitsStart, state.i), isHex ? 16 : 10); + if (codePoint === 0x000D || html.isNonCharacter(state, codePoint) || (html.isControl(state, codePoint) && !html.isWhitespace(state, codePoint))) + return false; + state.i++; + return true; + }, + parseStyleAttributeValue: ((style) => { + if (style === undefined || style === null) + return undefined; + const styles = new Map(); + let key = ""; + let value = ""; + let inValue = false; + let isEscaped = false; + let isQuoted = false; + let isComment = false; + let quoteChar = ""; + let parenCount = 0; + for (let i = 0; i < style.length; i++) { + const char = style[i]; + if (isComment) { + if (char !== "*" && style[i + 1] !== "/") + continue; + isComment = false; + i++; + continue; + } + if (char === "\\") { + isEscaped = true; + continue; + } + if (isEscaped) { + value += char; + isEscaped = false; + continue; + } + if (!isComment && char === "/" && style[i + 1] === "*") { + isComment = true; + i++; + continue; + } + if (isQuoted) { + if (char === quoteChar) { + isQuoted = false; + value += char; + continue; + } + } + else { + if (char === '"' || char === "'") { + isQuoted = true; + quoteChar = char; + value += char; + continue; + } + } + if (char === "(" && !isQuoted) { + parenCount++; + value += char; + continue; + } + if (char === ")" && !isQuoted) { + parenCount--; + value += char; + continue; + } + if (char === ":" && !isQuoted && parenCount === 0) { + inValue = true; + continue; + } + if (char === ";" && !isQuoted && parenCount === 0) { + if (key && value) { + key = key.trim(); + if (!html.regexCSSProperty.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + key = ""; + value = ""; + } + inValue = false; + continue; + } + if (inValue) { + value += char; + } + else { + key += char; + } + } + if (key && value) { + key = key.trim(); + if (!html.regexCSSProperty.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + } + return styles; + }), + isAlpha(state, charCode = state.src.charCodeAt(state.i)) { + return (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122); // A-Z, a-z + }, + isNumeric(state, charCode = state.src.charCodeAt(state.i)) { + return charCode >= 48 && charCode <= 57; + }, + isHexadecimal(state, charCode = state.src.charCodeAt(state.i)) { + return (charCode >= 65 && charCode <= 70) || (charCode >= 97 && charCode <= 102) || html.isNumeric(state, charCode); + }, + isAlphaNumeric(state, charCode = state.src.charCodeAt(state.i)) { + return html.isAlpha(state, charCode) || html.isNumeric(state, charCode); + }, + isNonCharacter(state, charCode = state.src.charCodeAt(state.i)) { + return false + || (charCode >= 0xFDD0 && charCode <= 0xFDEF) + || charCode === 0xFFFE || charCode === 0xFFFF + || charCode === 0x1FFFE || charCode === 0x1FFFF + || charCode === 0x2FFFE || charCode === 0x2FFFF + || charCode === 0x3FFFE || charCode === 0x3FFFF + || charCode === 0x4FFFE || charCode === 0x4FFFF + || charCode === 0x5FFFE || charCode === 0x5FFFF + || charCode === 0x6FFFE || charCode === 0x6FFFF + || charCode === 0x7FFFE || charCode === 0x7FFFF + || charCode === 0x8FFFE || charCode === 0x8FFFF + || charCode === 0x9FFFE || charCode === 0x9FFFF + || charCode === 0xAFFFE || charCode === 0xAFFFF + || charCode === 0xBFFFE || charCode === 0xBFFFF + || charCode === 0xCFFFE || charCode === 0xCFFFF + || charCode === 0xDFFFE || charCode === 0xDFFFF + || charCode === 0xEFFFE || charCode === 0xEFFFF + || charCode === 0xFFFFE || charCode === 0xFFFFF + || charCode === 0x10FFFE || charCode === 0x10FFFF; + }, + isControl(state, charCode = state.src.charCodeAt(state.i)) { + return false + || (charCode >= 0x0000 && charCode <= 0x001F) + || (charCode >= 0x007F && charCode <= 0x009F); + }, + isWhitespace(state, charCode = state.src.charCodeAt(state.i)) { + return false + || charCode === 0x0009 // TAB + || charCode === 0x000A // LF + || charCode === 0x000C // FF + || charCode === 0x000D // CR + || charCode === 0x0020; // SPACE + }, + matchesAllowedValues(value, allowed) { + if (Array.isArray(allowed)) + return allowed.some(allowed => html.matchesAllowedValues(value, allowed)); + if (typeof allowed === "string") + return value === allowed; + if (typeof allowed === "function") + return allowed(value); + return allowed.test(value); + }, + }); + const MarkdownItHTML = html; + exports.default = MarkdownItHTML; +}); +define("utility/string/Strings", ["require", "exports", "markdown-it", "utility/string/MarkdownItHTML"], function (require, exports, markdown_it_1, MarkdownItHTML_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + markdown_it_1 = __importDefault(markdown_it_1); + MarkdownItHTML_1 = __importDefault(MarkdownItHTML_1); + var Strings; + (function (Strings) { + function includesAt(string, substring, index) { + if (index < 0) + index = string.length + index; + if (index + substring.length > string.length) + return false; + for (let i = 0; i < substring.length; i++) + if (string[i + index] !== substring[i]) + return false; + return true; + } + Strings.includesAt = includesAt; + function sliceTo(string, substring, startAt) { + const index = string.indexOf(substring, startAt); + if (index === -1) + return string; + return string.slice(0, index); + } + Strings.sliceTo = sliceTo; + function sliceAfter(string, substring, startAt) { + const index = string.indexOf(substring, startAt); + if (index === -1) + return string; + return string.slice(index + substring.length); + } + Strings.sliceAfter = sliceAfter; + function trimTextMatchingFromStart(string, substring, startAt) { + if (string.length < substring.length) + return string; + const index = string.indexOf(substring, startAt); + if (index !== 0) + return string; + return string.slice(index + substring.length); + } + Strings.trimTextMatchingFromStart = trimTextMatchingFromStart; + function trimTextMatchingFromEnd(string, substring, startAt) { + if (string.length < substring.length) + return string; + const index = string.lastIndexOf(substring, startAt); + if (index !== string.length - substring.length) + return string; + return string.slice(0, index); + } + Strings.trimTextMatchingFromEnd = trimTextMatchingFromEnd; + function extractFromQuotes(string) { + let substring = (string ?? "").trim(); + if (substring[0] === '"') + substring = substring.slice(1); + if (substring[substring.length - 1] === '"') + substring = substring.slice(0, -1); + return substring.trim(); + } + Strings.extractFromQuotes = extractFromQuotes; + function extractFromSquareBrackets(string) { + let substring = (string ?? ""); + if (substring[0] === "[") + substring = substring.slice(1).trimStart(); + if (substring[substring.length - 1] === "]") + substring = substring.slice(0, -1).trimEnd(); + return substring; + } + Strings.extractFromSquareBrackets = extractFromSquareBrackets; + function mergeRegularExpressions(flags, ...expressions) { + let exprString = ""; + for (const expr of expressions) + exprString += "|" + expr.source; + return new RegExp(exprString.slice(1), flags); + } + Strings.mergeRegularExpressions = mergeRegularExpressions; + function count(string, substring, stopAtCount = Infinity) { + let count = 0; + let lastIndex = -1; + while (count < stopAtCount) { + const index = string.indexOf(substring, lastIndex + 1); + if (index === -1) + return count; + count++; + lastIndex = index; + } + return count; + } + Strings.count = count; + function includesOnce(string, substring) { + return count(string, substring, 2) === 1; + } + Strings.includesOnce = includesOnce; + function getVariations(name) { + const variations = [name]; + variations.push(name + "d", name + "ed"); + if (name.endsWith("d")) + variations.push(...getVariations(name.slice(0, -1))); + if (name.endsWith("ed")) + variations.push(...getVariations(name.slice(0, -2))); + if (name.endsWith("ing")) { + variations.push(name.slice(0, -3)); + if (name[name.length - 4] === name[name.length - 5]) + variations.push(name.slice(0, -4)); + } + else { + variations.push(name + "ing", name + name[name.length - 1] + "ing"); + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ing"); + } + if (name.endsWith("ion")) { + variations.push(...getVariations(name.slice(0, -3))); + if (name[name.length - 4] === name[name.length - 5]) + variations.push(name.slice(0, -4)); + } + else + variations.push(name + "ion"); + if (name.endsWith("er")) + variations.push(name.slice(0, -1), name.slice(0, -2)); + else { + variations.push(name + "r", name + "er"); + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ier"); + } + if (name.endsWith("ier")) + variations.push(name.slice(0, -3) + "y"); + variations.push(name + "s", name + "es"); + if (name.endsWith("s")) + variations.push(name.slice(0, -1)); + else { + if (name.endsWith("y")) + variations.push(name.slice(0, -1) + "ies"); + } + return variations; + } + Strings.getVariations = getVariations; + function shiftLine(lines, count = 1) { + for (let i = 0; i < count; i++) { + const index = lines.indexOf("\n"); + if (index === -1) + return lines; + lines = lines.slice(index + 1); + } + return lines; + } + Strings.shiftLine = shiftLine; + const REGEX_APOSTROPHE = /'/g; + const REGEX_NON_WORD_MULTI = /\W+/g; + function getWords(text) { + return text.toLowerCase() + .replace(REGEX_APOSTROPHE, "") + .split(REGEX_NON_WORD_MULTI) + .filter(Boolean); + } + Strings.getWords = getWords; + function fuzzyMatches(a, b, options) { + options ??= {}; + options.missingWordsThreshold ??= 0.4; + options.maxMissingWordsForFuzzy = 4; + const wordsA = getWords(a).map(getVariations); + const wordsB = getWords(b).map(getVariations); + let matches = 0; + let misses = 0; + let ia = 0; + let ib = 0; + NextMain: while (true) { + const va = wordsA[ia]; + const vb = wordsB[ib]; + if (!va && !vb) + break; + if (!va || !vb) { + ia++; + ib++; + misses++; + continue; + } + let loopMisses = 0; + for (let ia2 = ia; ia2 < wordsA.length && loopMisses <= options.maxMissingWordsForFuzzy; ia2++) { + const va = wordsA[ia2]; + if (va.some(va => vb.includes(va))) { + ia = ia2 + 1; + ib++; + matches++; + misses += loopMisses; + continue NextMain; + } + loopMisses++; + } + loopMisses = 0; + for (let ib2 = ib; ib2 < wordsB.length && loopMisses <= options.maxMissingWordsForFuzzy; ib2++) { + const vb = wordsB[ib2]; + if (vb.some(vb => va.includes(vb))) { + ia++; + ib = ib2 + 1; + matches++; + misses += loopMisses; + continue NextMain; + } + loopMisses++; + } + misses++; + ia++; + ib++; + } + return matches / (matches + misses) >= options.missingWordsThreshold; + } + Strings.fuzzyMatches = fuzzyMatches; + const REGEX_NON_WORD_MULTI_PREV = /(?<=\W+)/g; + function toTitleCase(text) { + return text.split(REGEX_NON_WORD_MULTI_PREV) + .map(word => word[0].toUpperCase() + word.slice(1)) + .join(""); + } + Strings.toTitleCase = toTitleCase; + Strings.markdown = new markdown_it_1.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_1.default.use(Strings.markdown, MarkdownItHTML_1.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + })(Strings || (Strings = {})); + exports.default = Strings; +}); +define("utility/Time", ["require", "exports", "utility/string/Strings"], function (require, exports, Strings_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Strings_1 = __importDefault(Strings_1); + var Time; + (function (Time) { + function floor(interval) { + return Math.floor(Date.now() / interval) * interval; + } + Time.floor = floor; + Time.frame = seconds(1) / 144; + function ms(ms) { return ms; } + Time.ms = ms; + function seconds(seconds) { return seconds * 1000; } + Time.seconds = seconds; + function minutes(minutes) { return minutes * 1000 * 60; } + Time.minutes = minutes; + function hours(hours) { return hours * 1000 * 60 * 60; } + Time.hours = hours; + function days(days) { return days * 1000 * 60 * 60 * 24; } + Time.days = days; + function weeks(weeks) { return weeks * 1000 * 60 * 60 * 24 * 7; } + Time.weeks = weeks; + function months(months) { return Math.floor(months * 1000 * 60 * 60 * 24 * (365.2422 / 12)); } + Time.months = months; + function years(years) { return Math.floor(years * 1000 * 60 * 60 * 24 * 365.2422); } + Time.years = years; + function decades(decades) { return Math.floor(decades * 1000 * 60 * 60 * 24 * 365.2422 * 10); } + Time.decades = decades; + function centuries(centuries) { return Math.floor(centuries * 1000 * 60 * 60 * 24 * 365.2422 * 10 * 10); } + Time.centuries = centuries; + function millenia(millenia) { return Math.floor(millenia * 1000 * 60 * 60 * 24 * 365.2422 * 10 * 10 * 10); } + Time.millenia = millenia; + function relative(unixTimeMs, options = {}) { + let ms = unixTimeMs - Date.now(); + const locale = navigator.language || "en-NZ"; + if (!locale.startsWith("en")) + return relativeIntl(ms, locale, options); + if (Math.abs(ms) < seconds(1)) + return "now"; + const ago = ms < 0; + if (ago) + ms = Math.abs(ms); + let limit = options.components ?? Infinity; + let value = ms; + let result = !ago && options.label !== false ? "in " : ""; + value = Math.floor(ms / years(1)); + ms -= value * years(1); + if (value && limit-- > 0) + result += `${value} year${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / months(1)); + ms -= value * months(1); + if (value && limit-- > 0) + result += `${value} month${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / weeks(1)); + ms -= value * weeks(1); + if (value && limit-- > 0) + result += `${value} week${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / days(1)); + ms -= value * days(1); + if (value && limit-- > 0) + result += `${value} day${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / hours(1)); + ms -= value * hours(1); + if (value && limit-- > 0) + result += `${value} hour${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / minutes(1)); + ms -= value * minutes(1); + if (value && limit-- > 0) + result += `${value} minute${value === 1 ? "" : "s"}${limit > 0 ? ", " : ""}`; + value = Math.floor(ms / seconds(1)); + if (value && limit-- > 0 && (!options.secondsExclusive || !result.includes(","))) + result += `${value} second${value === 1 ? "" : "s"}`; + result = Strings_1.default.trimTextMatchingFromEnd(result, ", "); + return `${result}${ago && options.label !== false ? " ago" : ""}`; + } + Time.relative = relative; + function relativeIntl(ms, locale, options) { + const rtf = new Intl.RelativeTimeFormat(locale, options); + let value = ms; + value = Math.floor(ms / years(1)); + if (value) + return rtf.format(value, "year"); + value = Math.floor(ms / months(1)); + if (value) + return rtf.format(value, "month"); + value = Math.floor(ms / weeks(1)); + if (value) + return rtf.format(value, "week"); + value = Math.floor(ms / days(1)); + if (value) + return rtf.format(value, "day"); + value = Math.floor(ms / hours(1)); + if (value) + return rtf.format(value, "hour"); + value = Math.floor(ms / minutes(1)); + if (value) + return rtf.format(value, "minute"); + value = Math.floor(ms / seconds(1)); + return rtf.format(value, "second"); + } + function absolute(ms, options = { dateStyle: "full", timeStyle: "medium" }) { + const locale = navigator.language || "en-NZ"; + const rtf = new Intl.DateTimeFormat(locale, options); + return rtf.format(ms); + } + Time.absolute = absolute; + })(Time || (Time = {})); + Object.assign(window, { Time }); + exports.default = Time; +}); +define("endpoint/Endpoint", ["require", "exports", "utility/Env", "utility/Objects", "utility/Time"], function (require, exports, Env_1, Objects_1, Time_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Env_1 = __importDefault(Env_1); + Objects_1 = __importDefault(Objects_1); + Time_1 = __importDefault(Time_1); + function Endpoint(route, method, headers) { + let pageSize; + const endpoint = { + header(header, value) { + headers ??= {}; + headers[header] = value; + return endpoint; + }, + headers(h) { + headers = { ...headers, ...h }; + return endpoint; + }, + removeHeader(header) { + delete headers?.[header]; + return endpoint; + }, + getPageSize: () => pageSize, + setPageSize: (size) => { + pageSize = size; + return endpoint; + }, + noResponse: () => endpoint.removeHeader("Accept"), + query: query, + prep: (...parameters) => { + const endpoint = Endpoint(route, method, headers); + return Object.assign(endpoint, { + query: (...p2) => { + const newParameters = []; + const length = Math.max(parameters.length, p2.length); + for (let i = 0; i < length; i++) + newParameters.push(Objects_1.default.merge(parameters[i], p2[i])); + const ownPageSize = pageSize; + pageSize = endpoint.getPageSize(); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const result = query(...newParameters); + pageSize = ownPageSize; + return result; + }, + }); + }, + }; + return endpoint; + async function query(data) { + const body = !data?.body ? undefined : JSON.stringify(data.body); + const url = route.slice(1) + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + .replaceAll(/\{([^}]+)\}/g, (match, paramName) => data?.params?.[paramName]); + const params = new URLSearchParams(data?.query); + if (pageSize) + params.set("page_size", `${pageSize}`); + const qs = params.size ? "?" + params.toString() : ""; + let error; + const response = await fetch(`${Env_1.default.API_ORIGIN}${url}${qs}`, { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + method, + headers: { + "Content-Type": body ? "application/json" : undefined, + "Accept": "application/json", + ...headers, + }, + credentials: "include", + body, + signal: AbortSignal.timeout(Time_1.default.seconds(5)), + }).catch((e) => { + if (e.name === "AbortError") { + error = Object.assign(new Error("Request timed out"), { + code: 408, + data: null, + headers: new Headers(), + }); + return; + } + if (e.name === "TypeError" && /invalid URL|Failed to construct/.test(e.message)) + throw e; + if (e.name === "TypeError" || e.name === "NetworkError") { + error = Object.assign(new Error("Network connection failed"), { + code: 503, + data: null, + headers: new Headers(), + }); + return; + } + if (!error) + throw e; + }); + if (error || !response) // will always mean the same thing, but ts doesn't know that + return error; + const code = response.status; + if (code !== 200) { + error = Object.assign(new Error(response.statusText), { code, retry: () => query(data) }); + delete error.stack; + } + const responseHeaders = { headers: response.headers }; + if (!response.body) + return Object.assign(error ?? {}, responseHeaders); + const responseType = response.headers.get("Content-Type"); + if (responseType === "application/json") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const json = await response.json().catch(e => { + error ??= Object.assign(e instanceof Error ? e : new Error("Failed to parse JSON"), { code, retry: () => query(data) }); + delete error.stack; + }); + if (error) + return Object.assign(error, json, responseHeaders); + const paginated = json; + if (paginated.has_more) { + Object.assign(json, { + next: () => query({ + ...data, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + query: { ...data?.query, page: (data?.query?.page ?? 0) + 1 }, + }), + getPage: (page) => query({ + ...data, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + query: { ...data?.query, page }, + }), + }); + } + return Object.assign(json, responseHeaders); + } + throw new Error(`Response type ${responseType} is not supported`); + } + } + exports.default = Endpoint; +}); +define("endpoint/manifest/EndpointFormInputLengths", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_1 = __importDefault(Endpoint_1); + exports.default = (0, Endpoint_1.default)("/manifest/form/lengths", "get"); +}); +define("model/Manifest", ["require", "exports", "utility/Time"], function (require, exports, Time_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Time_2 = __importDefault(Time_2); + function Manifest(definition) { + let manifestTime; + let promise; + const result = { + manifest: undefined, + isFresh(manifest) { + return !!manifest && Date.now() - (manifestTime ?? 0) < Time_2.default.minutes(5); + }, + async getManifest(force) { + // don't re-request the tag manifest if it was requested less than 5 minutes ago + if (!force && result.isFresh(result.manifest)) + return result.manifest; + return promise ??= (async () => { + try { + const response = await definition.get(); + if (response instanceof Error) + throw response; + result.manifest = response.data; + } + catch (err) { + if (definition.orElse) + result.manifest = definition.orElse(); + else + throw err; + } + manifestTime = Date.now(); + promise = undefined; + return result.manifest; + })(); + }, + }; + return result; + } + exports.default = Manifest; +}); +define("model/FormInputLengths", ["require", "exports", "endpoint/manifest/EndpointFormInputLengths", "model/Manifest"], function (require, exports, EndpointFormInputLengths_1, Manifest_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointFormInputLengths_1 = __importDefault(EndpointFormInputLengths_1); + Manifest_1 = __importDefault(Manifest_1); + exports.default = (0, Manifest_1.default)({ + get() { + return EndpointFormInputLengths_1.default.query(); + }, + orElse() { + const empy = {}; + return new Proxy({}, { + get(target, p, receiver) { + return empy; + }, + }); + }, + }); +}); +define("endpoint/auth/EndpointAuthRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_2 = __importDefault(Endpoint_2); + exports.default = (0, Endpoint_2.default)("/auth/remove", "post") + .noResponse(); +}); +define("endpoint/session/EndpointSessionGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_3 = __importDefault(Endpoint_3); + exports.default = (0, Endpoint_3.default)("/session", "get"); +}); +define("endpoint/session/EndpointSessionReset", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_4 = __importDefault(Endpoint_4); + exports.default = (0, Endpoint_4.default)("/session/reset", "post") + .noResponse(); +}); +define("ui/component/core/ActionRow", ["require", "exports", "ui/Component"], function (require, exports, Component_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_1 = __importDefault(Component_1); + const ActionRow = Component_1.default.Builder((row) => { + row.style("action-row"); + return row + .extend(row => ({ + left: undefined, + middle: undefined, + right: undefined, + })) + .extendJIT("left", row => (0, Component_1.default)() + .style("action-row-left") + .appendTo(row)) + .extendJIT("middle", row => (0, Component_1.default)() + .style("action-row-middle") + .appendTo(row)) + .extendJIT("right", row => (0, Component_1.default)() + .style("action-row-right") + .appendTo(row)); + }); + exports.default = ActionRow; +}); +define("utility/Define", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function Define(proto, key, implementation) { + try { + Object.defineProperty(proto, key, { + configurable: true, + writable: true, + value: implementation, + }); + } + catch (err) { + } + } + (function (Define) { + function all(protos, key, implementation) { + for (const proto of protos) { + Define(proto, key, implementation); + } + } + Define.all = all; + function magic(obj, key, implementation) { + try { + Object.defineProperty(obj, key, { + configurable: true, + ...implementation, + }); + } + catch (err) { + } + } + Define.magic = magic; + function set(obj, key, value) { + try { + Object.defineProperty(obj, key, { + configurable: true, + writable: true, + value, + }); + } + catch (err) { + } + return value; + } + Define.set = set; + })(Define || (Define = {})); + exports.default = Define; +}); +define("utility/Arrays", ["require", "exports", "utility/Define"], function (require, exports, Define_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Define_1 = __importDefault(Define_1); + var Arrays; + (function (Arrays) { + Arrays.EMPTY = []; + function resolve(or) { + return Array.isArray(or) ? or : or === undefined ? [] : [or]; + } + Arrays.resolve = resolve; + function includes(array, value) { + return Array.isArray(array) ? array.includes(value) : array === value; + } + Arrays.includes = includes; + function slice(or) { + return Array.isArray(or) ? or.slice() : or === undefined ? [] : [or]; + } + Arrays.slice = slice; + /** + * Removes one instance of the given value from the given array. + * @returns `true` if removed, `false` otherwise + */ + function remove(array, ...values) { + if (!array) + return false; + let removed = false; + for (const value of values) { + const index = array.indexOf(value); + if (index === -1) + continue; + array.splice(index, 1); + removed = true; + } + return removed; + } + Arrays.remove = remove; + /** + * Adds the given value to the given array if not present. + * @returns `true` if added, `false` otherwise + */ + function add(array, value) { + if (!array) + return false; + const index = array.indexOf(value); + if (index !== -1) + return false; + array.push(value); + return true; + } + Arrays.add = add; + function tuple(...values) { + return values; + } + Arrays.tuple = tuple; + function range(start, end, step) { + if (step === 0) + throw new Error("Invalid step for range"); + const result = []; + if (end === undefined) + end = start, start = 0; + step = end < start ? -1 : 1; + for (let i = start; step > 0 ? i < end : i > end; i += step) + result.push(i); + return result; + } + Arrays.range = range; + function filterNullish(value) { + return value !== null && value !== undefined; + } + Arrays.filterNullish = filterNullish; + function filterFalsy(value) { + return !!value; + } + Arrays.filterFalsy = filterFalsy; + function mergeSorted(...arrays) { + return arrays.reduce((prev, curr) => mergeSorted2(prev, curr), []); + } + Arrays.mergeSorted = mergeSorted; + function mergeSorted2(array1, array2) { + const merged = []; + let index1 = 0; + let index2 = 0; + while (index1 < array1.length || index2 < array2.length) { + const v1 = index1 < array1.length ? array1[index1] : undefined; + const v2 = index2 < array2.length ? array2[index2] : undefined; + if (v1 === v2) { + merged.push(v1); + index1++; + index2++; + continue; + } + if (v1 === undefined && v2 !== undefined) { + merged.push(v2); + index2++; + continue; + } + if (v2 === undefined && v1 !== undefined) { + merged.push(v1); + index1++; + continue; + } + const indexOfPerson1InList2 = array2.indexOf(v1, index2); + if (indexOfPerson1InList2 === -1) { + merged.push(v1); + index1++; + } + else { + merged.push(v2); + index2++; + } + } + return merged; + } + function applyPrototypes() { + (0, Define_1.default)(Array.prototype, "findLast", function (predicate) { + if (this.length > 0) + for (let i = this.length - 1; i >= 0; i--) + if (predicate(this[i], i, this)) + return this[i]; + return undefined; + }); + (0, Define_1.default)(Array.prototype, "findLastIndex", function (predicate) { + if (this.length > 0) + for (let i = this.length - 1; i >= 0; i--) + if (predicate(this[i], i, this)) + return i; + return -1; + }); + const originalSort = Array.prototype.sort; + (0, Define_1.default)(Array.prototype, "sort", function (...sorters) { + if (this.length <= 1) + return this; + if (!sorters.length) + return originalSort.call(this); + return originalSort.call(this, (a, b) => { + for (const sorter of sorters) { + if (sorter.length === 1) { + const mapper = sorter; + const sortValue = mapper(b) - mapper(a); + if (sortValue) + return sortValue; + } + else { + const sortValue = sorter(a, b); + if (sortValue) + return sortValue; + } + } + return 0; + }); + }); + (0, Define_1.default)(Array.prototype, "collect", function (collector, ...args) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return collector?.(this, ...args); + }); + (0, Define_1.default)(Array.prototype, "splat", function (collector, ...args) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return collector?.(...this, ...args); + }); + (0, Define_1.default)(Array.prototype, "toObject", function (mapper) { + return Object.fromEntries(mapper ? this.map(mapper) : this); + }); + (0, Define_1.default)(Array.prototype, "toMap", function (mapper) { + return new Map(mapper ? this.map(mapper) : this); + }); + (0, Define_1.default)(Array.prototype, "distinct", function (mapper) { + const result = []; + const encountered = mapper ? [] : result; + for (const value of this) { + const encounterValue = mapper ? mapper(value) : value; + if (encountered.includes(encounterValue)) + continue; + if (mapper) + encountered.push(encounterValue); + result.push(value); + } + return result; + }); + (0, Define_1.default)(Array.prototype, "findMap", function (predicate, mapper) { + for (let i = 0; i < this.length; i++) + if (predicate(this[i], i, this)) + return mapper(this[i], i, this); + return undefined; + }); + (0, Define_1.default)(Array.prototype, "groupBy", function (grouper) { + const result = {}; + for (let i = 0; i < this.length; i++) + (result[String(grouper(this[i], i, this))] ??= []).push(this[i]); + return Object.entries(result); + }); + (0, Define_1.default)(Array.prototype, "filterInPlace", function (filter) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return this.splice(0, Infinity, ...this.filter(filter)); + }); + (0, Define_1.default)(Array.prototype, "mapInPlace", function (mapper) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return this.splice(0, Infinity, ...this.map(mapper)); + }); + } + Arrays.applyPrototypes = applyPrototypes; + })(Arrays || (Arrays = {})); + exports.default = Arrays; +}); +define("utility/State", ["require", "exports", "utility/Arrays", "utility/Define"], function (require, exports, Arrays_1, Define_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_1 = __importDefault(Arrays_1); + Define_2 = __importDefault(Define_2); + const SYMBOL_UNSUBSCRIBE = Symbol("UNSUBSCRIBE"); + const SYMBOL_VALUE = Symbol("VALUE"); + const SYMBOL_SUBSCRIBERS = Symbol("SUBSCRIBERS"); + function State(defaultValue, equals) { + const result = { + isState: true, + [SYMBOL_VALUE]: defaultValue, + [SYMBOL_SUBSCRIBERS]: [], + get value() { + return result[SYMBOL_VALUE]; + }, + set value(value) { + if (result[SYMBOL_VALUE] === value || equals?.(result[SYMBOL_VALUE], value)) + return; + result[SYMBOL_VALUE] = value; + result.emit(); + }, + equals: value => result[SYMBOL_VALUE] === value || equals?.(result[SYMBOL_VALUE], value) || false, + emit: () => { + for (const subscriber of result[SYMBOL_SUBSCRIBERS]) + subscriber(result[SYMBOL_VALUE]); + return result; + }, + use: (owner, subscriber) => { + result.subscribe(owner, subscriber); + subscriber(result[SYMBOL_VALUE], true); + return () => result.unsubscribe(subscriber); + }, + subscribe: (owner, subscriber) => { + function onRemoved() { + owner.removed.unsubscribe(onRemoved); + result.unsubscribe(subscriber); + fn[SYMBOL_UNSUBSCRIBE]?.delete(onRemoved); + } + const fn = subscriber; + fn[SYMBOL_UNSUBSCRIBE] ??= new Set(); + fn[SYMBOL_UNSUBSCRIBE].add(onRemoved); + owner.removed.subscribeManual(onRemoved); + result.subscribeManual(subscriber); + return () => { + result.unsubscribe(subscriber); + owner.removed.unsubscribe(onRemoved); + }; + }, + subscribeManual: subscriber => { + result[SYMBOL_SUBSCRIBERS].push(subscriber); + return () => result.unsubscribe(subscriber); + }, + unsubscribe: subscriber => { + result[SYMBOL_SUBSCRIBERS] = result[SYMBOL_SUBSCRIBERS].filter(s => s !== subscriber); + return result; + }, + await(owner, values, then) { + result.subscribe(owner, function awaitValue(newValue) { + if (newValue !== values && (!Array.isArray(values) || !values.includes(newValue))) + return; + result.unsubscribe(awaitValue); + then(newValue); + }); + return result; + }, + awaitManual(values, then) { + result.subscribeManual(function awaitValue(newValue) { + if (newValue !== values && (!Array.isArray(values) || !values.includes(newValue))) + return; + result.unsubscribe(awaitValue); + then(newValue); + }); + return result; + }, + map: (owner, mapper) => State.Map(owner, [result], mapper), + mapManual: mapper => State.MapManual([result], mapper), + get nonNullish() { + return Define_2.default.set(result, "nonNullish", State + .Generator(() => result.value !== undefined && result.value !== null) + .observeManual(result)); + }, + get truthy() { + return Define_2.default.set(result, "truthy", State + .Generator(() => !!result.value) + .observeManual(result)); + }, + get not() { + return getNot(); + }, + get falsy() { + return getNot(); + }, + }; + return result; + function getNot() { + const not = State + .Generator(() => !result.value) + .observeManual(result); + Define_2.default.set(result, "not", not); + Define_2.default.set(result, "falsy", not); + return not; + } + } + (function (State) { + function is(value) { + return typeof value === "object" && value?.isState === true; + } + State.is = is; + function get(value) { + return is(value) ? value : State(value); + } + State.get = get; + function Generator(generate) { + const result = State(generate()); + Define_2.default.magic(result, "value", { + get: () => result[SYMBOL_VALUE], + }); + result.refresh = () => { + const value = generate(); + if (result.equals(value)) + return result; + result[SYMBOL_VALUE] = value; + result.emit(); + return result; + }; + result.observe = (owner, ...states) => { + for (const state of states) + state?.subscribeManual(result.refresh); + owner.event.subscribe("remove", onRemove); + return result; + function onRemove() { + owner.event.unsubscribe("remove", onRemove); + for (const state of states) + state?.unsubscribe(result.refresh); + } + }; + result.observeManual = (...states) => { + for (const state of states) + state?.subscribeManual(result.refresh); + return result; + }; + result.unobserve = (...states) => { + for (const state of states) + state?.unsubscribe(result.refresh); + return result; + }; + return result; + } + State.Generator = Generator; + function JIT(generate) { + const result = State(undefined); + let isCached = false; + let cached; + Define_2.default.magic(result, "value", { + get: () => { + if (!isCached) { + isCached = true; + cached = generate(); + } + return cached; + }, + }); + result.emit = () => { + for (const subscriber of result[SYMBOL_SUBSCRIBERS]) + subscriber(undefined); + return result; + }; + result.markDirty = () => { + isCached = false; + cached = undefined; + result.emit(); + return result; + }; + result.observe = (...states) => { + for (const state of states) + state.subscribeManual(result.markDirty); + return result; + }; + result.unobserve = (...states) => { + for (const state of states) + state.unsubscribe(result.markDirty); + return result; + }; + return result; + } + State.JIT = JIT; + function Truthy(owner, state) { + return Generator(() => !!state.value) + .observe(owner, state); + } + State.Truthy = Truthy; + function NonNullish(owner, state) { + return Generator(() => state.value !== undefined && state.value !== null) + .observe(owner, state); + } + State.NonNullish = NonNullish; + function Falsy(owner, state) { + return Generator(() => !!state.value) + .observe(owner, state); + } + State.Falsy = Falsy; + function Some(owner, ...anyOfStates) { + return Generator(() => anyOfStates.some(state => state.value)) + .observe(owner, ...anyOfStates); + } + State.Some = Some; + function Every(owner, ...anyOfStates) { + return Generator(() => anyOfStates.every(state => state.value)) + .observe(owner, ...anyOfStates); + } + State.Every = Every; + function Map(owner, inputs, outputGenerator) { + return Generator(() => outputGenerator(...inputs.map(input => input?.value))) + .observe(owner, ...inputs.filter(Arrays_1.default.filterNullish)); + } + State.Map = Map; + function MapManual(inputs, outputGenerator) { + return Generator(() => outputGenerator(...inputs.map(input => input?.value))) + .observeManual(...inputs.filter(Arrays_1.default.filterNullish)); + } + State.MapManual = MapManual; + })(State || (State = {})); + exports.default = State; +}); +define("ui/utility/StyleManipulator", ["require", "exports", "style"], function (require, exports, style_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + style_1 = __importDefault(style_1); + function StyleManipulator(component) { + const styles = new Set(); + const stateUnsubscribers = new WeakMap(); + const unbindPropertyState = {}; + const result = Object.assign(((...names) => { + for (const name of names) + styles.add(name); + updateClasses(); + return component; + }), { + get: () => [...styles].sort(), + remove(...names) { + for (const name of names) + styles.delete(name); + updateClasses(names); + return component; + }, + toggle(enabled, ...names) { + if (enabled) + for (const name of names) + styles.add(name); + else + for (const name of names) + styles.delete(name); + updateClasses(!enabled ? names : undefined); + return component; + }, + bind(state, ...names) { + result.unbind(state); + const unsubscribe = state.use(component, active => { + if (active) + for (const name of names) + styles.add(name); + else + for (const name of names) + styles.delete(name); + updateClasses(!active ? names : undefined); + }); + stateUnsubscribers.set(state, [unsubscribe, names]); + return component; + }, + unbind(state) { + const bound = state && stateUnsubscribers.get(state); + if (!bound) + return component; + const [unsubscribe, names] = bound; + unsubscribe?.(); + stateUnsubscribers.delete(state); + result.remove(...names); + return component; + }, + refresh: () => updateClasses(), + hasProperty(property) { + return component.element.style.getPropertyValue(property) !== ""; + }, + setProperty(property, value) { + unbindPropertyState[property]?.(); + setProperty(property, value); + return component; + }, + toggleProperty(enabled, property, value) { + enabled ??= !result.hasProperty(property); + if (enabled === true) + return result.setProperty(property, enabled ? value : undefined); + else + return result.removeProperties(property); + }, + setVariable(variable, value) { + return result.setProperty(`--${variable}`, value); + }, + bindProperty(property, state) { + unbindPropertyState[property]?.(); + unbindPropertyState[property] = state.use(component, value => setProperty(property, value)); + return component; + }, + bindVariable(variable, state) { + return result.bindProperty(`--${variable}`, state); + }, + removeProperties(...properties) { + for (const property of properties) + component.element.style.removeProperty(property); + return component; + }, + removeVariables(...variables) { + for (const variable of variables) + component.element.style.removeProperty(`--${variable}`); + return component; + }, + }); + return result; + function updateClasses(deletedStyles) { + const toAdd = [...styles].flatMap(component => style_1.default[component]); + const toRemove = deletedStyles?.flatMap(component => style_1.default[component]).filter(cls => !toAdd.includes(cls)); + if (toRemove) + component.element.classList.remove(...toRemove); + component.element.classList.add(...toAdd); + return component; + } + function setProperty(property, value) { + if (value === undefined || value === null) + component.element.style.removeProperty(property); + else + component.element.style.setProperty(property, `${value}`); + } + } + exports.default = StyleManipulator; +}); +define("ui/component/core/Button", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_2, State_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_2 = __importDefault(Component_2); + State_1 = __importDefault(State_1); + const Button = Component_2.default.Builder("button", (button) => { + const disabledReasons = new Set(); + const disabled = State_1.default.Generator(() => !!disabledReasons.size); + let icon; + const unuseDisabledStateMap = new WeakMap(); + return button + .attributes.set("type", "button") + .style("button") + .style.bind(disabled, "button--disabled") + .attributes.bind(disabled, "disabled") + .extend(button => ({ + textWrapper: undefined, + disabled, + type: Object.assign((...types) => { + for (const type of types) + button.style(`button-type-${type}`); + return button; + }, { + remove(...types) { + for (const type of types) + button.style.remove(`button-type-${type}`); + return button; + }, + }), + setDisabled(newState, reason) { + const size = disabledReasons.size; + if (newState) + disabledReasons.add(reason); + else + disabledReasons.delete(reason); + if (disabledReasons.size !== size) + disabled.refresh(); + return button; + }, + bindDisabled(state, reason) { + unuseDisabledStateMap.get(state)?.(); + unuseDisabledStateMap.set(state, state.subscribe(button, newState => button.setDisabled(newState, reason))); + return button; + }, + unbindDisabled(state, reason) { + unuseDisabledStateMap.get(state)?.(); + unuseDisabledStateMap.delete(state); + return button; + }, + setIcon(newIcon) { + if (icon) + button.style.remove(`button-icon-${icon}`); + icon = newIcon; + if (icon) + button.style(`button-icon-${icon}`); + return button; + }, + })) + .extendJIT("textWrapper", button => (0, Component_2.default)() + .style("button-text") + .appendTo(button)); + }); + exports.default = Button; +}); +define("utility/EventManager", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.EventManager = void 0; + class EventManager { + static global = EventManager.make(); + static make() { + return new EventManager({}); + } + static emit(target, event, init) { + if (init instanceof Event) + event = init; + if (typeof event === "string") + event = new Event(event, { cancelable: true }); + if (typeof init === "function") + init?.(event); + else if (init && event !== init) + Object.assign(event, init); + target?.dispatchEvent(event); + return event; + } + host; + _target; + get target() { + return this._target instanceof WeakRef ? this._target.deref() : this._target; + } + constructor(host, target = new EventTarget()) { + this.host = new WeakRef(host); + this._target = target; + } + subscribe(type, listener) { + if (!Array.isArray(type)) + type = [type]; + for (const t of type) + this.target?.addEventListener(t, listener); + return this.host.deref(); + } + subscriptions = {}; + subscribeOnce(types, listener) { + if (!Array.isArray(types)) + types = [types]; + if (this.target) { + const target = this.target; + const subscriptions = this.subscriptions; + function realListener(event) { + listener.call(this, event); + for (const type of types) { + subscriptions[type]?.delete(listener); + target?.removeEventListener(type, realListener); + } + } + for (const type of types) { + subscriptions[type] ??= new WeakMap(); + subscriptions[type].set(listener, realListener); + this.target?.addEventListener(type, realListener); + } + } + return this.host.deref(); + } + unsubscribe(types, listener) { + if (!Array.isArray(types)) + types = [types]; + for (const type of types) { + this.target?.removeEventListener(type, listener); + const realListener = this.subscriptions[type]?.get(listener); + if (realListener) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + this.target?.removeEventListener(type, realListener); + this.subscriptions[type].delete(listener); + } + } + return this.host.deref(); + } + async waitFor(types) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return new Promise(resolve => this.subscribeOnce(types, resolve)); + } + until(promise, initialiser) { + if (typeof promise !== "object") + promise = this.waitFor(promise); + const manager = { + subscribe: (type, listener) => { + this.subscribe(type, listener); + void (promise).then(() => this.unsubscribe(type, listener)); + return manager; + }, + subscribeOnce: (type, listener) => { + this.subscribeOnce(type, listener); + void (promise).then(() => this.unsubscribe(type, listener)); + return manager; + }, + }; + initialiser?.(manager); + return this.host.deref(); + } + emit(event, init) { + event = EventManager.emit(this.target, event, init); + // const pipeTargets = this.pipeTargets.get(event.type) + // if (pipeTargets) { + // for (let i = 0; i < pipeTargets.length; i++) { + // const pipeTarget = pipeTargets[i].deref() + // if (pipeTarget) + // pipeTarget.dispatchEvent(event) + // else + // pipeTargets.splice(i--, 1) + // } + // if (!pipeTargets.length) + // this.pipeTargets.delete(event.type) + // } + return this.host.deref(); + } + } + exports.EventManager = EventManager; +}); +define("ui/InputBus", ["require", "exports", "ui/Component", "utility/EventManager"], function (require, exports, Component_3, EventManager_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_3 = __importDefault(Component_3); + var Classes; + (function (Classes) { + Classes["ReceiveFocusedClickEvents"] = "_receieve-focused-click-events"; + })(Classes || (Classes = {})); + Component_3.default.extend(component => { + component.extend(component => ({ + receiveFocusedClickEvents: () => component.classes.add(Classes.ReceiveFocusedClickEvents), + })); + }); + const MOUSE_KEYNAME_MAP = { + [0]: "MouseLeft", + [1]: "MouseMiddle", + [2]: "MouseRight", + [3]: "Mouse3", + [4]: "Mouse4", + [5]: "Mouse5", + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + [`${undefined}`]: "Mouse?", + }; + let lastUsed = 0; + const inputDownTime = {}; + const InputBus = Object.assign(EventManager_1.EventManager.make(), { + getPressStart: (name) => inputDownTime[name], + getPressDuration: (name) => inputDownTime[name] === undefined ? undefined : Date.now() - inputDownTime[name], + isDown: (name) => !!inputDownTime[name], + isUp: (name) => !inputDownTime[name], + }); + function emitKeyEvent(e) { + const target = e.target; + const input = target.closest("input[type=text], textarea, [contenteditable]"); + let usedByInput = !!input; + const isClick = true + && !usedByInput + && e.type === "keydown" + && (e.key === "Enter" || e.key === "Space") + && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey + && target.classList.contains(Classes.ReceiveFocusedClickEvents); + if (isClick) { + const result = target.component?.event.emit("click"); + if (result?.defaultPrevented) { + e.preventDefault(); + return; + } + } + const eventKey = e.key ?? MOUSE_KEYNAME_MAP[e.button]; + const eventType = e.type === "mousedown" ? "keydown" : e.type === "mouseup" ? "keyup" : e.type; + if (eventType === "keydown") + inputDownTime[eventKey] = Date.now(); + let cancelInput = false; + const event = { + key: eventKey, + ctrl: e.ctrlKey, + shift: e.shiftKey, + alt: e.altKey, + used: usedByInput, + input, + use: (key, ...modifiers) => { + if (event.used) + return false; + const matches = event.matches(key, ...modifiers); + if (matches) + event.used = true; + return matches; + }, + useOverInput: (key, ...modifiers) => { + if (event.used && !usedByInput) + return false; + const matches = event.matches(key, ...modifiers); + if (matches) { + event.used = true; + usedByInput = false; + } + return matches; + }, + matches: (key, ...modifiers) => { + if (eventKey !== key) + return false; + if (!modifiers.every(modifier => event[modifier])) + return false; + return true; + }, + cancelInput: () => cancelInput = true, + hovering: (selector) => { + const hovered = [...document.querySelectorAll(":hover")]; + return selector ? hovered[hovered.length - 1]?.closest(selector) ?? undefined : hovered[hovered.length - 1]; + }, + }; + if (eventType === "keyup") { + event.usedAnotherKeyDuring = lastUsed > (inputDownTime[eventKey] ?? 0); + delete inputDownTime[eventKey]; + } + InputBus.emit(eventType === "keydown" ? "down" : "up", event); + if ((event.used && !usedByInput) || (usedByInput && cancelInput)) { + e.preventDefault(); + lastUsed = Date.now(); + } + if (usedByInput) { + if (e.type === "keydown" && eventKey === "Enter" && !event.shift && !event.alt) { + const form = target.closest("form"); + if (form && (target.tagName.toLowerCase() === "input" || target.closest("[contenteditable]")) && !event.ctrl) { + e.preventDefault(); + } + else { + form?.requestSubmit(); + } + } + } + } + document.addEventListener("keydown", emitKeyEvent); + document.addEventListener("keyup", emitKeyEvent); + document.addEventListener("mousedown", emitKeyEvent); + document.addEventListener("mouseup", emitKeyEvent); + document.addEventListener("click", emitKeyEvent); + Object.defineProperty(MouseEvent.prototype, "used", { + get() { + return this._used ?? false; + }, + }); + Object.defineProperty(MouseEvent.prototype, "use", { + value: function (key, ...modifiers) { + if (this._used) + return false; + const matches = this.matches(key, ...modifiers); + if (matches) { + this._used = true; + // allow click & contextmenu handlers to be considered "used" for IKeyUpEvents + lastUsed = Date.now(); + } + return matches; + }, + }); + Object.defineProperty(MouseEvent.prototype, "matches", { + value: function (key, ...modifiers) { + if (MOUSE_KEYNAME_MAP[this.button] !== key) + return false; + if (!modifiers.every(modifier => this[`${modifier}Key`])) + return false; + return true; + }, + }); + exports.default = InputBus; +}); +define("ui/utility/FocusListener", ["require", "exports", "utility/State"], function (require, exports, State_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_2 = __importDefault(State_2); + var FocusListener; + (function (FocusListener) { + FocusListener.hasFocus = (0, State_2.default)(false); + FocusListener.focused = (0, State_2.default)(undefined); + function focusedComponent() { + return FocusListener.focused.value?.component; + } + FocusListener.focusedComponent = focusedComponent; + // interface QueuedFocusChange { + // type: "focus" | "blur" + // element: HTMLElement + // } + // let updatingFocusState = false + // let cursor = 0 + // const queue: QueuedFocusChange[] = [] + function focus(element) { + // if (updatingFocusState || exhaustingQueue) { + // queue.splice(cursor, 0, { type: "focus", element }) + // cursor++ + // return + // } + focusInternal(element); + } + FocusListener.focus = focus; + function focusInternal(element) { + if (document.querySelector(":focus-visible") === element) + return; + element.focus(); + } + function blur(element) { + // if (updatingFocusState || exhaustingQueue) { + // queue.splice(cursor, 0, { type: "blur", element }) + // cursor++ + // return + // } + blurInternal(element); + } + FocusListener.blur = blur; + function blurInternal(element) { + if (document.querySelector(":focus-visible") !== element) + return; + element.blur(); + } + function listen() { + document.addEventListener("focusin", onFocusIn); + document.addEventListener("focusout", onFocusOut); + } + FocusListener.listen = listen; + function onFocusIn() { + updateFocusState(); + } + function onFocusOut(event) { + if (event.relatedTarget === null) + updateFocusState(); + } + // let exhaustingQueue = false + function updateFocusState() { + if (document.activeElement && document.activeElement !== document.body && location.hash && document.activeElement.id !== location.hash.slice(1)) + history.pushState(undefined, "", " "); + const newFocused = document.querySelector(":focus-visible") ?? undefined; + if (newFocused === FocusListener.focused.value) + return; + // updatingFocusState = true + const lastFocusedComponent = FocusListener.focused.value?.component; + const focusedComponent = newFocused?.component; + const oldAncestors = !lastFocusedComponent ? undefined : [...lastFocusedComponent.getAncestorComponents()]; + const newAncestors = !focusedComponent ? undefined : [...focusedComponent.getAncestorComponents()]; + const lastFocusedContainsFocused = FocusListener.focused.value?.contains(newFocused ?? null); + FocusListener.focused.value = newFocused; + FocusListener.hasFocus.value = !!newFocused; + if (lastFocusedComponent) { + lastFocusedComponent.focused.value = false; + if (!lastFocusedContainsFocused) + lastFocusedComponent.hasFocused.value = false; + } + if (focusedComponent) { + focusedComponent.focused.value = true; + focusedComponent.hasFocused.value = true; + } + if (oldAncestors) + for (const ancestor of oldAncestors) + if (!newAncestors?.includes(ancestor)) + if (ancestor) + ancestor.hasFocused.value = false; + if (newAncestors) + for (const ancestor of newAncestors) + if (ancestor) + ancestor.hasFocused.value = true; + // updatingFocusState = false + // if (exhaustingQueue) + // return + // exhaustingQueue = true + // for (cursor = 0; cursor < queue.length; cursor++) { + // const change = queue[cursor] + // if (change.type === "blur") + // blurInternal(change.element) + // else if (change.type === "focus") + // focusInternal(change.element) + // } + // queue.splice(0, Infinity) + // cursor = 0 + // exhaustingQueue = false + } + })(FocusListener || (FocusListener = {})); + exports.default = FocusListener; + Object.assign(window, { FocusListener }); +}); +define("utility/maths/Vector2", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Vector2; + (function (Vector2) { + function ZERO() { + return { x: 0, y: 0 }; + } + Vector2.ZERO = ZERO; + function distance(v1, v2) { + return Math.sqrt((v2.x - v1.x) ** 2 + (v2.y - v1.y) ** 2); + } + Vector2.distance = distance; + function distanceWithin(v1, v2, within) { + return (v2.x - v1.x) ** 2 + (v2.y - v1.y) ** 2 < within ** 2; + } + Vector2.distanceWithin = distanceWithin; + })(Vector2 || (Vector2 = {})); + exports.default = Vector2; +}); +define("ui/utility/Mouse", ["require", "exports", "utility/State"], function (require, exports, State_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_3 = __importDefault(State_3); + var Mouse; + (function (Mouse) { + const pos = { x: 0, y: 0 }; + Mouse.state = (0, State_3.default)(pos); + const handlers = new Set(); + function onMove(handler) { + handlers.add(handler); + } + Mouse.onMove = onMove; + function offMove(handler) { + handlers.delete(handler); + } + Mouse.offMove = offMove; + function listen() { + document.addEventListener("mousemove", event => { + if (pos.x === event.clientX && pos.y === event.clientY) + return; + pos.x = event.clientX; + pos.y = event.clientY; + Mouse.state.emit(); + for (const handler of handlers) + handler(pos); + }); + } + Mouse.listen = listen; + })(Mouse || (Mouse = {})); + exports.default = Mouse; +}); +define("ui/utility/HoverListener", ["require", "exports", "ui/utility/Mouse"], function (require, exports, Mouse_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Mouse_1 = __importDefault(Mouse_1); + var HoverListener; + (function (HoverListener) { + let lastHovered = []; + function allHovered() { + return lastHovered; + } + HoverListener.allHovered = allHovered; + function hovered() { + return lastHovered.at(-1); + } + HoverListener.hovered = hovered; + function* allHoveredComponents() { + for (const element of lastHovered) { + const component = element.component; + if (component) + yield component; + } + } + HoverListener.allHoveredComponents = allHoveredComponents; + function hoveredComponent() { + return lastHovered.at(-1)?.component; + } + HoverListener.hoveredComponent = hoveredComponent; + function listen() { + Mouse_1.default.onMove(() => { + const allHovered = document.querySelectorAll(":hover"); + const hovered = allHovered[allHovered.length - 1]; + if (hovered === lastHovered[lastHovered.length - 1]) + return; + const newHovered = [...allHovered]; + for (const element of lastHovered) + if (element.component && !newHovered.includes(element)) + element.component.hovered.value = false; + for (const element of newHovered) + if (element.component && !lastHovered.includes(element)) + element.component.hovered.value = true; + lastHovered = newHovered; + }); + } + HoverListener.listen = listen; + })(HoverListener || (HoverListener = {})); + exports.default = HoverListener; + Object.assign(window, { HoverListener }); +}); +define("utility/Async", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Async; + (function (Async) { + async function sleep(ms, signal) { + // let stack = new Error().stack; + // stack = stack?.slice(stack.indexOf("\n") + 1); + // stack = stack?.slice(stack.indexOf("\n") + 1); + // stack = stack?.slice(0, stack.indexOf("\n")); + // console.log("sleep", stack); + if (!signal) { + return new Promise(resolve => { + window.setTimeout(() => resolve(undefined), ms); + }); + } + if (signal.aborted) { + return true; + } + return new Promise(resolve => { + // eslint-disable-next-line prefer-const + let timeoutId; + const onAbort = () => { + window.clearTimeout(timeoutId); + resolve(true); + }; + timeoutId = window.setTimeout(() => { + signal.removeEventListener("abort", onAbort); + resolve(false); + }, ms); + signal.addEventListener("abort", onAbort, { once: true }); + }); + } + Async.sleep = sleep; + function debounce(...args) { + let ms; + let callback; + if (typeof args[0] === "function") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [callback, ...args] = args; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return debounceByPromise(callback, ...args); + } + else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, callback, ...args] = args; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return debounceByTime(ms, callback, ...args); + } + } + Async.debounce = debounce; + const debouncedByTime = new WeakMap(); + function debounceByTime(ms, callback, ...args) { + let info = debouncedByTime.get(callback); + if (info && Date.now() - info.last < ms) { + const callbackRef = new WeakRef(callback); + callback = undefined; + const newAbortController = new AbortController(); + info.queued = sleep(Date.now() - info.last + ms, newAbortController.signal).then(aborted => { + if (aborted) { + return info?.queued; + } + delete info.queued; + delete info.abortController; + info.last = Date.now(); + return callbackRef.deref()?.(...args); + }); + info.abortController?.abort(); + info.abortController = newAbortController; + return info.queued; + } + if (!info) { + debouncedByTime.set(callback, info = { last: 0 }); + } + info.last = Date.now(); + return callback(...args); + } + const debouncedByPromise = new WeakMap(); + function debounceByPromise(callback, ...args) { + const debounceInfo = debouncedByPromise.get(callback); + if (debounceInfo?.nextQueued) { + return debounceInfo.promise; + } + const callbackRef = new WeakRef(callback); + callback = undefined; + const realCallback = () => { + try { + const callback = callbackRef.deref(); + if (!callback) { + return; + } + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const result = callback(...args); + const promise = Promise.resolve(result); + debouncedByPromise.set(callback, { + promise, + nextQueued: false, + }); + callback = undefined; + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + return promise; + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + return; + } + }; + if (debounceInfo) { + debounceInfo.nextQueued = true; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + return debounceInfo.promise.catch(realCallback).then(realCallback); + } + else { + return realCallback(); + } + } + function schedule(...args) { + let ms = 0; + let callback; + let debounceMs = false; + let signal; + if (typeof args[0] === "function") { + // (cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [callback, ...args] = args; + } + else if (typeof args[1] === "function") { + // (ms, cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, callback, ...args] = args; + } + else if (typeof args[2] === "function") { + // (ms, debounce | signal, cb, ...args) + if (typeof args[1] === "object") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, signal, callback, ...args] = args; + } + else { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, debounceMs, callback, ...args] = args; + } + } + else { + // (ms, debounce, signal, cb, ...args) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + [ms, debounceMs, signal, callback, ...args] = args; + } + if (debounceMs === true) { + debounceMs = ms; + } + const cancelCallbacks = []; + // eslint-disable-next-line prefer-const + let timeoutId; + const result = { + cancelled: false, + completed: false, + cancel: () => { + if (result.cancelled || result.completed) { + return; + } + signal?.removeEventListener("abort", result.cancel); + result.cancelled = true; + window.clearTimeout(timeoutId); + for (const callback of cancelCallbacks) { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + } + cancelCallbacks.length = 0; + args.length = 0; + }, + onCancel: callback => { + if (result.completed) { + return result; + } + if (result.cancelled) { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + } + else { + cancelCallbacks.push(callback); + } + return result; + }, + }; + signal?.addEventListener("abort", result.cancel, { once: true }); + timeoutId = window.setTimeout(() => { + if (result.cancelled) { + return; + } + signal?.removeEventListener("abort", result.cancel); + result.completed = true; + cancelCallbacks.length = 0; + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument + const result = debounceMs ? debounce(debounceMs, callback, ...args) : callback(...args); + const promise = Promise.resolve(result); + promise.catch(reason => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + window.dispatchEvent(new PromiseRejectionEvent("unhandledrejection", { promise, reason })); + }); + } + catch (error) { + window.dispatchEvent(new ErrorEvent("error", { error })); + } + }, ms); + return result; + } + Async.schedule = schedule; + /** + * Create an AbortSignal that will be emitted after `ms`. + * @param ms The time until the signal will be emitted. + * @param controller An optional existing `AbortController`. + * @param message An optional custom timeout message. + */ + function timeout(ms, controller = new AbortController(), message = `Timed out after ${ms} ms`) { + schedule(ms, () => controller.abort(message)); + return controller.signal; + } + Async.timeout = timeout; + })(Async || (Async = {})); + exports.default = Async; +}); +define("utility/Task", ["require", "exports", "utility/Async", "utility/Time"], function (require, exports, Async_1, Time_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Async_1 = __importDefault(Async_1); + Time_3 = __importDefault(Time_3); + const DEFAULT_INTERVAL = Time_3.default.seconds(1) / 144; + class Task { + interval; + static async yield(instantIfUnsupported = false) { + if (typeof scheduler !== "undefined" && typeof scheduler.yield === "function") + return scheduler.yield(); + if (!instantIfUnsupported) + await Async_1.default.sleep(1); + } + static post(callback, priority) { + if (typeof scheduler === "undefined" || typeof scheduler.postTask !== "function") + return callback(); + return scheduler.postTask(callback, { priority }); + } + lastYieldEnd = Date.now(); + constructor(interval = DEFAULT_INTERVAL) { + this.interval = interval; + } + reset() { + this.lastYieldEnd = Date.now(); + } + async yield(instantIfUnsupported = false) { + if (Date.now() - this.lastYieldEnd > this.interval) { + await Task.yield(instantIfUnsupported); + this.lastYieldEnd = Date.now(); + } + } + } + exports.default = Task; +}); +define("ui/component/core/Popover", ["require", "exports", "ui/Component", "ui/InputBus", "ui/utility/FocusListener", "ui/utility/HoverListener", "ui/utility/Mouse", "utility/State", "utility/Task"], function (require, exports, Component_4, InputBus_1, FocusListener_1, HoverListener_1, Mouse_2, State_4, Task_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_4 = __importDefault(Component_4); + InputBus_1 = __importDefault(InputBus_1); + FocusListener_1 = __importDefault(FocusListener_1); + HoverListener_1 = __importDefault(HoverListener_1); + Mouse_2 = __importDefault(Mouse_2); + State_4 = __importDefault(State_4); + Task_1 = __importDefault(Task_1); + const FOCUS_TRAP = (0, Component_4.default)() + .tabIndex("auto") + .ariaHidden() + .style.setProperty("display", "none") + .prependTo(document.body); + Component_4.default.extend(component => { + component.extend((component) => ({ + clearPopover: () => component + .attributes.set("data-clear-popover", "true"), + setPopover: (popoverEvent, initialiser) => { + if (component.popover) + component.popover.remove(); + let isShown = false; + const popover = Popover() + .anchor.from(component) + .setOwner(component) + .tweak(initialiser, component) + .event.subscribe("toggle", e => { + const event = e; + if (event.newState === "closed") { + isShown = false; + component.clickState = false; + Mouse_2.default.offMove(updatePopoverState); + } + }) + .appendTo(document.body); + if (popoverEvent === "hover" && !component.popover) + component.hoveredOrFocused.subscribe(component, updatePopoverState); + const ariaLabel = component.attributes.getUsing("aria-label") ?? popover.attributes.get("aria-label"); + const ariaRole = popover.attributes.getUsing("role") ?? popover.attributes.get("role"); + component.ariaLabel.use((quilt, { arg }) => quilt["component/popover/button"](arg(ariaLabel), arg(ariaRole))); + popover.ariaLabel.use((quilt, { arg }) => quilt["component/popover"](arg(ariaLabel))); + component.clickState = false; + if (!component.popover) { + component.event.subscribe("click", async (event) => { + // always subscribe click because we need to handle it for keyboard navigation + if (!component.focused.value && popoverEvent !== "click") + return; + event.stopPropagation(); + event.preventDefault(); + component.clickState = true; + component.popover?.show(); + component.popover?.focus(); + component.popover?.style.removeProperties("left", "top"); + await Task_1.default.yield(); + component.popover?.anchor.apply(); + }); + component.receiveAncestorInsertEvents(); + component.event.subscribe(["insert", "ancestorInsert"], updatePopoverParent); + } + popover.popoverHasFocus.subscribe(component, hasFocused => { + if (hasFocused) + return; + component.clickState = false; + component.popover?.hide(); + component.focus(); + }); + return component.extend(component => ({ + popover, + popoverDescendants: [], + tweakPopover: initialiser => { + initialiser(component.popover, component); + return component; + }, + })); + function updatePopoverParent() { + if (!component.popover) + return; + const oldParent = component.popover.popoverParent.value; + component.popover.popoverParent.value = component.closest(Popover); + if (oldParent && oldParent !== component.popover.popoverParent.value) + oldParent.popoverChildren.value = oldParent.popoverChildren.value.filter(c => c !== component.popover); + if (component.popover.popoverParent.value && component.popover.popoverParent.value !== oldParent) + component.popover.popoverParent.value.popoverChildren.value = [...component.popover.popoverParent.value.popoverChildren.value, component.popover]; + } + async function updatePopoverState() { + if (!component.popover) + return; + const shouldShow = false + || component.hoveredOrFocused.value + || (true + && isShown + && (false + || (component.popover.isMouseWithin(true) && !shouldClearPopover()) + || InputBus_1.default.isDown("F4"))) + || !!component.clickState; + if (isShown === shouldShow) + return; + if (component.hoveredOrFocused.value && !isShown) + Mouse_2.default.onMove(updatePopoverState); + if (!shouldShow) + Mouse_2.default.offMove(updatePopoverState); + if (!shouldShow) + FOCUS_TRAP.style.setProperty("display", "none"); + isShown = shouldShow; + component.popover.toggle(shouldShow); + if (!shouldShow) + return; + FOCUS_TRAP.style.setProperty("display", "inline"); + component.popover.style.removeProperties("left", "top"); + await Task_1.default.yield(); + component.popover.anchor.apply(); + } + function shouldClearPopover() { + if (!component.popover) + return false; + const hovered = HoverListener_1.default.hovered() ?? null; + if (component.element.contains(hovered) || component.popover.element.contains(hovered)) + return false; + const clearsPopover = hovered?.closest("[data-clear-popover]"); + if (!clearsPopover) + return false; + const clearsPopoverWithinPopover = clearsPopover.component?.closest(Popover); + if (component.popover.containsPopoverDescendant(clearsPopoverWithinPopover)) + return false; + return true; + } + }, + })); + }); + const Popover = Component_4.default.Builder((component) => { + let mousePadding; + let unbind; + const visible = (0, State_4.default)(false); + let shouldCloseOnInput = true; + let normalStacking = false; + const popover = component + .style("popover") + .tabIndex("programmatic") + .attributes.set("popover", "manual") + .extend(popover => ({ + visible, + popoverChildren: (0, State_4.default)([]), + popoverParent: (0, State_4.default)(undefined), + popoverHasFocus: FocusListener_1.default.focused.map(popover, focused => visible.value && containsPopoverDescendant(focused)), + setCloseOnInput(closeOnInput = true) { + shouldCloseOnInput = closeOnInput; + return popover; + }, + setMousePadding: padding => { + mousePadding = padding; + return popover; + }, + setNormalStacking() { + popover.style("popover--normal-stacking"); + popover.attributes.remove("popover"); + normalStacking = true; + togglePopover(visible.value); + return popover; + }, + isMouseWithin: (checkDescendants = false) => { + if (popover.rect.value.expand(mousePadding ?? 100).intersects(Mouse_2.default.state.value)) + return true; + if (checkDescendants) + for (const child of popover.popoverChildren.value) + if (child.isMouseWithin(true)) + return true; + return false; + }, + containsPopoverDescendant, + show: () => { + unbind?.(); + togglePopover(true); + popover.visible.value = true; + return popover; + }, + hide: () => { + unbind?.(); + togglePopover(false); + popover.visible.value = false; + return popover; + }, + toggle: shown => { + unbind?.(); + togglePopover(shown); + popover.visible.value = shown ?? !popover.visible.value; + return popover; + }, + bind: state => { + unbind?.(); + unbind = state.use(popover, shown => { + togglePopover(shown); + popover.visible.value = shown; + }); + return popover; + }, + unbind: () => { + unbind?.(); + return popover; + }, + })); + popover.event.subscribe("toggle", event => { + popover.visible.value = event.newState === "open"; + }); + popover.onRooted(() => { + InputBus_1.default.subscribe("down", onInputDown); + component.event.subscribe("remove", () => InputBus_1.default.unsubscribe("down", onInputDown)); + }); + return popover; + function togglePopover(shown) { + if (normalStacking) + popover.style.toggle(!shown, "popover--normal-stacking--hidden"); + else + popover.element.togglePopover(shown); + } + function onInputDown(event) { + if (!popover.visible.value || !shouldCloseOnInput) + return; + if (!event.key.startsWith("Mouse") || popover.containsPopoverDescendant(HoverListener_1.default.hovered())) + return; + popover.element.togglePopover(false); + popover.visible.value = false; + } + function containsPopoverDescendant(descendant) { + if (!descendant) + return false; + const node = Component_4.default.is(descendant) ? descendant.element : descendant; + if (popover.element.contains(node)) + return true; + for (const child of popover.popoverChildren.value) + if (child === descendant) + return true; + else if (child.containsPopoverDescendant(descendant)) + return true; + return false; + } + }); + exports.default = Popover; +}); +define("ui/component/core/ext/CanHasActionsMenuButton", ["require", "exports", "ui/Component", "ui/component/core/Button"], function (require, exports, Component_5, Button_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_5 = __importDefault(Component_5); + Button_1 = __importDefault(Button_1); + const CanHasActionsMenuButton = Component_5.default.Extension((component, inserter) => { + let actionsMenuPopoverInitialiser = () => { }; + return component + .extend(component => ({ + actionsMenuButton: undefined, + setActionsMenu(initialiser) { + actionsMenuPopoverInitialiser = initialiser; + component.actionsMenuButton.setPopover("click", (popover, button) => { + popover.anchor.add("off right", "aligned top"); + popover.anchor.add("off right", "aligned bottom"); + initialiser(popover, button); + }); + return component; + }, + })) + .extendJIT("actionsMenuButton", component => { + const button = (0, Button_1.default)() + .style("block-actions-menu-button") + .setIcon("ellipsis-vertical") + .setPopover("click", actionsMenuPopoverInitialiser); + if (inserter) + inserter(button); + else + button.appendTo(component); + return button; + }); + }); + exports.default = CanHasActionsMenuButton; +}); +define("ui/utility/MarkdownContent", ["require", "exports", "ui/Component", "utility/string/Strings"], function (require, exports, Component_6, Strings_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_6 = __importDefault(Component_6); + Strings_2 = __importDefault(Strings_2); + const handlers = []; + Component_6.default.extend(component => component.extend(component => ({ + setMarkdownContent(markdown) { + component.classes.add("markdown"); + component.element.innerHTML = Strings_2.default.markdown.render(markdown); + for (const node of [...component.element.querySelectorAll("*")]) + for (const handler of handlers) + handler(node); + return component; + }, + }))); + var MarkdownContent; + (function (MarkdownContent) { + function handle(handler) { + handlers.push(handler); + } + MarkdownContent.handle = handle; + })(MarkdownContent || (MarkdownContent = {})); + exports.default = MarkdownContent; +}); +define("ui/component/core/Heading", ["require", "exports", "ui/Component", "ui/utility/MarkdownContent"], function (require, exports, Component_7, MarkdownContent_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.HeadingClasses = void 0; + Component_7 = __importDefault(Component_7); + MarkdownContent_1 = __importDefault(MarkdownContent_1); + var HeadingClasses; + (function (HeadingClasses) { + HeadingClasses["_ContainsHeading"] = "_contains-heading"; + })(HeadingClasses || (exports.HeadingClasses = HeadingClasses = {})); + Component_7.default.extend(component => component.extend(component => ({ + containsHeading: () => component.classes.has(HeadingClasses._ContainsHeading), + setContainsHeading() { + component.classes.add(HeadingClasses._ContainsHeading); + return component; + }, + }))); + const Heading = Component_7.default.Builder("h1", (component) => { + component.style("heading"); + component.text.state.use(component, text => component.setId(text?.toString().toLowerCase().replace(/\W+/g, "-"))); + component.tabIndex("programmatic"); + component.receiveAncestorInsertEvents(); + component.event.subscribe(["insert", "ancestorInsert"], updateHeadingLevel); + component.rooted.subscribeManual(updateHeadingLevel); + let initial = true; + let aestheticLevel; + let aestheticStyle; + return component.extend(heading => ({ + setAestheticLevel(level) { + const style = aestheticStyle ?? "heading"; + const oldLevel = getHeadingLevel(component.element); + if (isStyledHeadingLevel(oldLevel)) + component.style.remove(`${style}-${oldLevel}`); + if (aestheticLevel) + component.style.remove(`${style}-${aestheticLevel}`); + aestheticLevel = level; + if (isStyledHeadingLevel(aestheticLevel)) + component.style(`${style}-${aestheticLevel}`); + return heading; + }, + setAestheticStyle(style) { + const level = aestheticLevel ?? getHeadingLevel(component.element); + if (isStyledHeadingLevel(level)) + component.style.remove(`${aestheticStyle ?? "heading"}`, `${aestheticStyle ?? "heading"}-${level}`); + aestheticStyle = style; + if (isStyledHeadingLevel(level)) + component.style(`${style ?? "heading"}`, `${style ?? "heading"}-${level}`); + return heading; + }, + updateLevel: () => { + updateHeadingLevel(); + return heading; + }, + })); + function updateHeadingLevel() { + const newLevel = computeHeadingLevel(component.element); + const oldLevel = getHeadingLevel(component.element); + const isSameLevel = newLevel === oldLevel; + if (isSameLevel && !initial) + return; + const style = aestheticStyle ?? "heading"; + initial = false; + if (isStyledHeadingLevel(oldLevel)) + component.style.remove(`${style}-${oldLevel}`); + const isStyledLevel = isStyledHeadingLevel(newLevel); + if (!aestheticLevel && isStyledLevel) + component.style(`${style}-${newLevel}`); + if (aestheticLevel) + component.style(`${style}-${aestheticLevel}`); + if (isSameLevel) + return; + component.event.unsubscribe(["insert", "ancestorInsert"], updateHeadingLevel); + component.replaceElement(isStyledLevel ? `h${newLevel}` : "span"); + component.attributes.toggle(!isStyledLevel, "role", "heading"); + component.attributes.toggle(!isStyledLevel && typeof newLevel === "number", "aria-level", `${newLevel}`); + component.event.subscribe(["insert", "ancestorInsert"], updateHeadingLevel); + } + }); + function computeHeadingLevel(node) { + let currentNode = node; + let incrementHeading = false; + while (currentNode) { + const heading = getPreviousSiblingHeading(currentNode); + if (heading) { + const level = getHeadingLevel(heading); + if (!incrementHeading && level !== 1) + return level; + if (level === undefined || level > 6) + return level; + return level + 1; + } + currentNode = currentNode.parentNode ?? undefined; + incrementHeading ||= true; + } + return 1; + } + function getPreviousSiblingHeading(node) { + let sibling = node; + while (sibling) { + sibling = sibling.previousSibling ?? undefined; + if (sibling?.nodeType !== Node.ELEMENT_NODE) + continue; + const siblingElement = sibling; + if (isHeadingElement(siblingElement)) + return siblingElement; + if (siblingElement.getAttribute("role") === "heading") + return siblingElement; + if (siblingElement.tagName === "HGROUP") { + const [heading] = siblingElement.querySelectorAll("h1, h2, h3, h4, h5, h6, [role='heading']"); + if (heading) + return heading; + } + if (siblingElement.component?.containsHeading()) { + const [heading] = siblingElement.querySelectorAll("h1, h2, h3, h4, h5, h6, [role='heading']"); + if (heading) + return heading; + } + } + } + function isHeadingElement(value) { + if (!value || typeof value !== "object" || !("tagName" in value)) + return false; + const element = value; + return element.tagName[0] === "H" && element.tagName.length === 2 && !isNaN(+element.tagName[1]); + } + function getHeadingLevel(element) { + return +element.tagName.slice(1) || +element.getAttribute("aria-level") || undefined; + } + function isStyledHeadingLevel(level) { + return typeof level === "number" && level >= 1 && level <= 6; + } + //#endregion + //////////////////////////////////// + MarkdownContent_1.default.handle(element => { + if (isHeadingElement(element)) { + const level = getHeadingLevel(element); + const heading = Heading().setAestheticStyle("markdown-heading"); + heading.element.replaceChildren(...element.childNodes); + element.replaceWith(heading.element); + heading.emitInsert(); + if (isStyledHeadingLevel(level)) + heading.setAestheticLevel(level); + } + }); + exports.default = Heading; +}); +define("ui/component/core/Paragraph", ["require", "exports", "ui/Component"], function (require, exports, Component_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_8 = __importDefault(Component_8); + const Paragraph = Component_8.default.Builder(component => component + .style("paragraph")); + exports.default = Paragraph; +}); +define("ui/component/core/Block", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/ext/CanHasActionsMenuButton", "ui/component/core/Heading", "ui/component/core/Paragraph", "utility/State"], function (require, exports, Component_9, ActionRow_1, CanHasActionsMenuButton_1, Heading_1, Paragraph_1, State_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BlockClasses = void 0; + Component_9 = __importDefault(Component_9); + ActionRow_1 = __importDefault(ActionRow_1); + CanHasActionsMenuButton_1 = __importDefault(CanHasActionsMenuButton_1); + Heading_1 = __importDefault(Heading_1); + Paragraph_1 = __importDefault(Paragraph_1); + State_5 = __importDefault(State_5); + var BlockClasses; + (function (BlockClasses) { + BlockClasses["Main"] = "$block"; + })(BlockClasses || (exports.BlockClasses = BlockClasses = {})); + const Block = Component_9.default.Builder((component) => { + const types = (0, State_5.default)(new Set()); + let header; + let footer; + const block = component + .classes.add(BlockClasses.Main) + .viewTransition("block") + .style("block") + .extend(block => ({ + title: undefined, + header: undefined, + description: undefined, + primaryActions: undefined, + content: (0, Component_9.default)().style("block-content").appendTo(component), + footer: undefined, + type: Object.assign((...newTypes) => { + const oldSize = types.value.size; + for (const type of newTypes) { + types.value.add(type); + block.style(`block-type-${type}`); + header?.style(`block-type-${type}-header`); + footer?.style(`block-type-${type}-footer`); + } + if (types.value.size !== oldSize) + types.emit(); + return block; + }, { + state: types, + remove(...removeTypes) { + let removed = false; + for (const type of removeTypes) { + removed ||= types.value.delete(type); + block.style.remove(`block-type-${type}`); + header?.style.remove(`block-type-${type}-header`); + footer?.style.remove(`block-type-${type}-footer`); + } + if (removed) + types.emit(); + return block; + }, + }), + })) + .extendJIT("header", block => header = (0, Component_9.default)("hgroup") + .style("block-header", ...[...types.value].map(t => `block-type-${t}-header`)) + .prependTo(block)) + .extendJIT("title", block => (0, Heading_1.default)().style("block-title").prependTo(block.header)) + .extendJIT("primaryActions", block => (0, Component_9.default)().style("block-actions-primary").appendTo(block.header)) + .extendJIT("description", block => (0, Paragraph_1.default)().style("block-description").appendTo(block.header)) + .extendJIT("footer", block => footer = (0, ActionRow_1.default)() + .style("block-footer", ...[...types.value].map(t => `block-type-${t}-footer`)) + .appendTo(block)); + return block + .and(CanHasActionsMenuButton_1.default, button => button.appendTo(block.primaryActions)); + }); + exports.default = Block; +}); +define("ui/component/core/Slot", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_10, State_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_10 = __importDefault(Component_10); + State_6 = __importDefault(State_6); + const Slot = Object.assign(Component_10.default.Builder((slot) => { + slot.style("slot"); + let unuse; + let cleanup; + return slot + .extend(slot => ({ + use: (state, initialiser) => { + unuse?.(); + unuse = state.use(slot, value => { + cleanup?.(); + slot.removeContents(); + let result = initialiser(slot, value) || undefined; + if (result === slot) + result = undefined; + if (Component_10.default.is(result)) { + result.appendTo(slot); + cleanup = undefined; + return; + } + cleanup = result; + }); + return slot; + }, + if: (state, initialiser) => { + unuse?.(); + state.use(slot, value => { + if (!value) { + cleanup?.(); + cleanup = undefined; + slot.removeContents(); + return; + } + let result = initialiser(slot) || undefined; + if (result === slot) + result = undefined; + if (Component_10.default.is(result)) { + result.appendTo(slot); + cleanup = undefined; + return; + } + cleanup = result; + }); + return slot; + }, + })) + .event.subscribe("remove", () => cleanup?.()); + }), { + using: (value, initialiser) => Slot().use(State_6.default.get(value), initialiser), + }); + exports.default = Slot; +}); +define("ui/utility/Viewport", ["require", "exports", "utility/State"], function (require, exports, State_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_7 = __importDefault(State_7); + var Viewport; + (function (Viewport) { + Viewport.size = State_7.default.JIT(() => ({ w: window.innerWidth, h: window.innerHeight })); + function listen() { + window.addEventListener("resize", Viewport.size.markDirty); + } + Viewport.listen = listen; + })(Viewport || (Viewport = {})); + exports.default = Viewport; +}); +define("ui/utility/AnchorManipulator", ["require", "exports", "ui/utility/Mouse", "ui/utility/Viewport", "utility/Time"], function (require, exports, Mouse_3, Viewport_1, Time_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AllowXOffscreen = exports.AllowYOffscreen = exports.ANCHOR_LOCATION_ALIGNMENTS = exports.ANCHOR_SIDE_VERTICAL = exports.ANCHOR_SIDE_HORIZONTAL = exports.ANCHOR_TYPES = void 0; + Mouse_3 = __importDefault(Mouse_3); + Viewport_1 = __importDefault(Viewport_1); + Time_4 = __importDefault(Time_4); + //////////////////////////////////// + //#region Anchor Strings + exports.ANCHOR_TYPES = ["off", "aligned"]; + exports.ANCHOR_SIDE_HORIZONTAL = ["left", "right"]; + exports.ANCHOR_SIDE_VERTICAL = ["top", "bottom"]; + const anchorStrings = new Set(exports.ANCHOR_TYPES + .flatMap(type => [exports.ANCHOR_SIDE_HORIZONTAL, exports.ANCHOR_SIDE_VERTICAL] + .flatMap(sides => sides + .map(side => `${type} ${side}`))) + .flatMap(type => [type, `sticky ${type}`])); + anchorStrings.add("centre"); + anchorStrings.add("sticky centre"); + function isAnchorString(value) { + if (anchorStrings.has(value)) { + return true; + } + if (typeof value !== "string") { + return false; + } + const lastSpace = value.lastIndexOf(" "); + if (lastSpace === -1) { + return false; + } + const simpleAnchorString = value.slice(0, lastSpace); + if (!anchorStrings.has(simpleAnchorString)) { + return false; + } + const offsetString = value.slice(lastSpace + 1); + return !isNaN(+offsetString); + } + function parseAnchor(anchor) { + const sticky = anchor.startsWith("sticky"); + if (sticky) { + anchor = anchor.slice(7); + } + const simpleAnchor = anchor; + if (simpleAnchor === "centre") { + return { sticky, type: "centre", side: "centre", offset: 0 }; + } + const [type, side, offset] = simpleAnchor.split(" "); + return { + sticky, + type, + side, + offset: offset ? +offset : 0, + }; + } + exports.ANCHOR_LOCATION_ALIGNMENTS = ["left", "centre", "right"]; + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region Implementation + exports.AllowYOffscreen = { allowYOffscreen: true }; + exports.AllowXOffscreen = { allowXOffscreen: true }; + function AnchorManipulator(host) { + let locationPreference; + let refCache; + let location; + let currentAlignment; + let from; + function onFromRemove() { + from = undefined; + } + let lastRender = 0; + let rerenderTimeout; + const subscribed = []; + const addSubscription = (use) => use && subscribed.push(use); + const result = { + isMouse: () => !locationPreference?.length, + from: component => { + from?.event.unsubscribe("remove", onFromRemove); + from = component; + component.event.subscribe("remove", onFromRemove); + return host; + }, + reset: () => { + locationPreference = undefined; + result.markDirty(); + return host; + }, + add: (...config) => { + const options = typeof config[config.length - 1] === "string" ? undefined + : config.pop(); + let [xAnchor, xRefSelector, yAnchor, yRefSelector] = config; + if (isAnchorString(xRefSelector)) { + yRefSelector = yAnchor; + yAnchor = xRefSelector; + xRefSelector = "*"; + } + yRefSelector ??= "*"; + locationPreference ??= []; + locationPreference.push({ + xAnchor: parseAnchor(xAnchor), + xRefSelector, + yAnchor: parseAnchor(yAnchor), + yRefSelector, + options, + }); + result.markDirty(); + return host; + }, + markDirty: () => { + location = undefined; + if (lastRender) { + const timeSinceLastRender = Date.now() - lastRender; + if (timeSinceLastRender > Time_4.default.frame) + result.apply(); + else if (rerenderTimeout === undefined) + rerenderTimeout = window.setTimeout(result.apply, Time_4.default.frame - timeSinceLastRender); + } + return host; + }, + get: () => { + if (location) + return location; + for (const unuse of subscribed) + unuse(); + const tooltipBox = host?.rect.value; + if (tooltipBox && locationPreference && from) { + for (const preference of locationPreference) { + let alignment = "left"; + const xConf = preference.xAnchor; + const xRef = resolveAnchorRef(preference.xRefSelector); + const xBox = xRef?.rect.value; + addSubscription(xRef?.rect.subscribe(host, result.markDirty)); + const xCenter = (xBox?.left ?? 0) + (xBox?.width ?? Viewport_1.default.size.value.w) / 2; + const xRefX = (xConf.side === "right" ? xBox?.right : xConf.side === "left" ? xBox?.left : xCenter) ?? xCenter; + let x; + switch (xConf.type) { + case "aligned": + x = xConf.side === "right" ? xRefX - tooltipBox.width - xConf.offset : xRefX + xConf.offset; + alignment = xConf.side; + break; + case "off": + x = xConf.side === "right" ? xRefX + xConf.offset : xRefX - tooltipBox.width - xConf.offset; + // alignment is inverted side for "off" + alignment = xConf.side === "left" ? "right" : "left"; + break; + case "centre": + x = xRefX - tooltipBox.width / 2; + alignment = "centre"; + break; + } + if (preference.options?.xValid?.(x, xBox, tooltipBox) === false) { + continue; + } + if (!xConf.sticky && tooltipBox.width < Viewport_1.default.size.value.w && !preference.options?.allowXOffscreen) { + const isXOffScreen = x < 0 || x + tooltipBox.width > Viewport_1.default.size.value.w; + if (isXOffScreen) { + continue; + } + } + const yConf = preference.yAnchor; + const yRef = resolveAnchorRef(preference.yRefSelector); + const yBox = yRef?.rect.value; + addSubscription(yRef?.rect.subscribe(host, result.markDirty)); + const yCenter = (yBox?.top ?? 0) + (yBox?.height ?? Viewport_1.default.size.value.h) / 2; + const yRefY = (yConf.side === "bottom" ? yBox?.bottom : yConf.side === "top" ? yBox?.top : yCenter) ?? yCenter; + let y; + switch (yConf.type) { + case "aligned": + y = yConf.side === "bottom" ? yRefY - tooltipBox.height - yConf.offset : yRefY + yConf.offset; + break; + case "off": + y = yConf.side === "bottom" ? yRefY + yConf.offset : yRefY - tooltipBox.height - yConf.offset; + break; + case "centre": + y = yRefY - tooltipBox.height / 2; + break; + } + if (preference.options?.yValid?.(y, yBox, tooltipBox) === false) { + continue; + } + if (!yConf.sticky && tooltipBox.height < Viewport_1.default.size.value.h && !preference.options?.allowYOffscreen) { + const isYOffScreen = y < 0 + || y + tooltipBox.height > Viewport_1.default.size.value.h; + if (isYOffScreen) { + continue; + } + } + return location ??= { mouse: false, padX: xConf.type === "off", alignment, x, y }; + } + } + return location ??= { mouse: true, padX: true, ...Mouse_3.default.state.value }; + }, + apply: () => { + const location = result.get(); + let alignment = location.alignment ?? currentAlignment; + if (location.mouse) { + const shouldFlip = currentAlignment === "centre" || (currentAlignment === "right" ? location.x < Viewport_1.default.size.value.w / 2 - 200 : location.x > Viewport_1.default.size.value.w / 2 + 200); + if (shouldFlip) { + alignment = currentAlignment === "left" ? "right" : "left"; + } + } + if (currentAlignment !== alignment) { + currentAlignment = alignment; + // this.surface.classes.removeStartingWith("aligned-") + // this.surface.classes.add(`aligned-${this.currentAlignment}`) + } + // this.surface.classes.toggle(location.padX, "pad-x") + host.element.style.left = `${location.x}px`; + host.element.style.top = `${location.y}px`; + host.rect.markDirty(); + rerenderTimeout = undefined; + lastRender = Date.now(); + return host; + }, + }; + return result; + function resolveAnchorRef(selector) { + const refRef = refCache?.[selector]; + let ref; + if (refRef) { + ref = refRef.deref(); + } + else { + ref = from?.element.closest(selector)?.component; + if (ref) { + if (getComputedStyle(ref.element).display === "contents") { + const children = ref.element.children; + if (!children.length) + console.warn("Anchor ref has display: contents and no children"); + else { + ref = children[0].component ?? ref; + if (children.length > 1) + console.warn("Anchor ref has display: contents and multiple children"); + } + } + refCache ??= {}; + refCache[selector] = new WeakRef(ref); + } + } + return ref; + } + } + exports.default = AnchorManipulator; +}); +//#endregion +//////////////////////////////////// +define("ui/utility/StringApplicator", ["require", "exports", "lang/en-nz", "utility/State"], function (require, exports, en_nz_1, State_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.QuiltHelper = void 0; + en_nz_1 = __importDefault(en_nz_1); + State_8 = __importDefault(State_8); + var QuiltHelper; + (function (QuiltHelper) { + function renderWeave(weave) { + return weave.content.map(renderWeft); + } + QuiltHelper.renderWeave = renderWeave; + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents + function arg(arg) { + if (typeof arg === "object" && arg && "map" in arg) + arg = arg.value; + if (typeof arg === "function") + arg = arg(en_nz_1.default, QuiltHelper); + if (typeof arg === "string" && arg in en_nz_1.default) + arg = en_nz_1.default[arg](); + return arg; + } + QuiltHelper.arg = arg; + function isPlaintextWeft(weft) { + return true + && typeof weft.content === "string"; + } + function renderWeft(weft) { + if (isPlaintextWeft(weft)) + return document.createTextNode(weft.content); + let element; + const tag = weft.tag?.toLowerCase(); + if (tag) { + if (tag.startsWith("link(")) { + const link = element = document.createElement("a"); + const href = tag.slice(5, -1); + link.href = href; + link.addEventListener("click", event => { + event.preventDefault(); + navigate.toRawURL(href); + }); + } + } + element ??= document.createElement("span"); + if (Array.isArray(weft.content)) + element.append(...weft.content.map(renderWeft)); + else if (typeof weft.content === "object" && weft.content) + element.append(...renderWeave(weft.content)); + else + element.textContent = `${weft.content ?? ""}`; + return element; + } + })(QuiltHelper || (exports.QuiltHelper = QuiltHelper = {})); + function StringApplicator(host, defaultValueOrApply, apply) { + const defaultValue = !apply ? undefined : defaultValueOrApply; + apply ??= defaultValueOrApply; + let translationHandler; + let unbind; + const result = makeApplicator(host); + return result; + function makeApplicator(host) { + return { + state: (0, State_8.default)(defaultValue), + set: value => { + unbind?.(); + translationHandler = undefined; + setInternal(value); + return host; + }, + use: translation => { + unbind?.(); + if (typeof translation === "string") { + translationHandler = undefined; + setInternal(en_nz_1.default[translation]().toString()); + return host; + } + translationHandler = translation; + result.refresh(); + return host; + }, + bind: state => { + translationHandler = undefined; + unbind?.(); + unbind = state?.use(host, setInternal); + if (!state) + setInternal(defaultValue); + return host; + }, + unbind: () => { + unbind?.(); + setInternal(defaultValue); + return host; + }, + refresh: () => { + if (!translationHandler) + return; + setInternal(translationHandler(en_nz_1.default, QuiltHelper).toString()); + }, + rehost: makeApplicator, + }; + } + function setInternal(value) { + if (typeof value === "object" && value !== null) + value = value.toString(); + if (result.state.value !== value) { + result.state.value = value; + apply(value); + } + } + } + exports.default = StringApplicator; +}); +define("ui/component/core/ext/Input", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Popover", "ui/component/core/Slot", "ui/utility/AnchorManipulator", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_11, Block_1, Popover_1, Slot_1, AnchorManipulator_1, StringApplicator_1, State_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_11 = __importDefault(Component_11); + Popover_1 = __importDefault(Popover_1); + Slot_1 = __importDefault(Slot_1); + StringApplicator_1 = __importDefault(StringApplicator_1); + State_9 = __importDefault(State_9); + const Input = Component_11.default.Extension((component) => { + const hintText = (0, State_9.default)(undefined); + const maxLength = (0, State_9.default)(undefined); + const length = (0, State_9.default)(undefined); + const unusedPercent = State_9.default.MapManual([length, maxLength], (length, maxLength) => length === undefined || !maxLength ? undefined : 1 - length / maxLength); + const unusedChars = State_9.default.MapManual([length, maxLength], (length, maxLength) => length === undefined || !maxLength ? undefined : maxLength - length); + const hasPopover = State_9.default.MapManual([hintText, maxLength], (hintText, maxLength) => !!hintText || !!maxLength); + let popover; + hasPopover.subscribeManual(hasPopover => { + if (!hasPopover) { + popover?.remove(); + popover = undefined; + return; + } + popover = (0, Popover_1.default)() + .anchor.from(component) + .anchor.add("off right", `.\\${Block_1.BlockClasses.Main}`, "aligned top", { + ...AnchorManipulator_1.AllowYOffscreen, + yValid(y, hostBox, popoverBox) { + // only align top if the popover box is taller than the host box + return popoverBox.height > (hostBox?.height ?? 0); + }, + }) + .anchor.add("off right", `.\\${Block_1.BlockClasses.Main}`, "centre", AnchorManipulator_1.AllowYOffscreen) + .setNormalStacking() + .setCloseOnInput(false) + .style("input-popover") + .setOwner(component) + .tweak(popover => { + Slot_1.default.using(hintText, (slot, hintText) => !hintText ? undefined + : (0, Component_11.default)() + .style("input-popover-hint-text") + .text.set(hintText)) + .appendTo(popover); + Slot_1.default.using(maxLength, (slot, maxLength) => !maxLength ? undefined + : (0, Component_11.default)() + .style("input-popover-max-length") + .append((0, Component_11.default)() + .style("input-popover-max-length-icon") + .style.bind(unusedPercent.mapManual(p => (p ?? 0) < 0), "input-popover-max-length-icon--overflowing")) + .append((0, Component_11.default)() + .style("input-popover-max-length-text") + .text.bind(unusedChars.mapManual(chars => chars === undefined ? "" : `${chars}`))) + .style.bindVariable("remaining", unusedPercent.mapManual(p => 1 - (p ?? 0)))) + .appendTo(popover); + }) + .tweak(popoverInitialiser, component) + .appendTo(document.body); + }); + component.hasFocused.subscribeManual(hasFocused => popover?.toggle(hasFocused).anchor.apply()); + let popoverInitialiser; + return component.extend(component => ({ + required: (0, State_9.default)(false), + hint: (0, StringApplicator_1.default)(component, value => hintText.value = value), + maxLength, + length, + setMaxLength(newLength) { + maxLength.value = newLength; + return component; + }, + setRequired: (required = true) => { + component.attributes.toggle(required, "required"); + component.required.value = required; + return component; + }, + setLabel: label => { + component.setName(label?.for); + component.setId(label?.for); + label?.setInput(component); + return component; + }, + tweakPopover(initialiser) { + popoverInitialiser = initialiser; + return component; + }, + })); + }); + exports.default = Input; +}); +define("ui/component/core/Form", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/Block", "ui/component/core/Button", "utility/State"], function (require, exports, Component_12, ActionRow_2, Block_2, Button_2, State_10) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_12 = __importDefault(Component_12); + ActionRow_2 = __importDefault(ActionRow_2); + Block_2 = __importDefault(Block_2); + Button_2 = __importDefault(Button_2); + State_10 = __importDefault(State_10); + const Form = Component_12.default.Builder((form, label) => { + form.replaceElement("form") + .style("form") + .ariaRole("form") + .ariaLabelledBy(label); + form.receiveDescendantInsertEvents(); + const valid = State_10.default.Generator(() => form.element.checkValidity()); + form.event.subscribe(["input", "change", "descendantInsert"], () => valid.refresh()); + const content = (form.is(Block_2.default) ? form.content : (0, Component_12.default)()) + .style("form-content"); + const footer = (form.is(Block_2.default) ? form.footer : (0, ActionRow_2.default)()) + .style("form-footer"); + return form + .append(content, footer) + .extend(() => ({ + content, footer, + submit: undefined, + })) + .extendJIT("submit", () => (0, Button_2.default)() + .type("primary") + .attributes.set("type", "submit") + .bindDisabled(valid.not, "invalid") + .appendTo(footer.right)); + }); + exports.default = Form; +}); +define("ui/view/shared/component/View", ["require", "exports", "ui/Component"], function (require, exports, Component_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_13 = __importDefault(Component_13); + const View = Component_13.default.Builder((_, id) => (0, Component_13.default)() + .style("view", `view-type-${id}`) + .attributes.set("data-view", id) + .extend(view => ({ + viewId: id, + hash: "", + })) + .extendJIT("hash", view => `${view.viewId}${view.params ? `_${JSON.stringify(view.params)}` : ""}` + .replaceAll(/\W+/g, "-"))); + exports.default = View; +}); +define("ui/component/core/Label", ["require", "exports", "ui/Component", "ui/component/core/Form", "ui/view/shared/component/View", "utility/State"], function (require, exports, Component_14, Form_1, View_1, State_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.AutoLabel = void 0; + Component_14 = __importDefault(Component_14); + Form_1 = __importDefault(Form_1); + View_1 = __importDefault(View_1); + State_11 = __importDefault(State_11); + const Label = Component_14.default.Builder("label", (label) => { + label.style("label"); + let requiredState; + return label + .extend(label => ({ + for: (0, State_11.default)(undefined), + setFor: inputName => { + label.attributes.set("for", inputName); + label.for.value = inputName; + return label; + }, + setRequired: (required = true) => { + label.style.unbind(requiredState); + requiredState = undefined; + if (typeof required === "boolean") + label.style.toggle("label-required"); + else + label.style.bind(requiredState = required, "label-required"); + return label; + }, + setInput: input => { + if (!label.is(exports.AutoLabel)) + label.setFor(input?.name.value); + label.setRequired(input?.required); + return label; + }, + })); + }); + exports.default = Label; + let globalI = 0; + exports.AutoLabel = Component_14.default.Builder("label", (component) => { + const i = globalI++; + const label = component.and(Label); + let formName; + let viewPath; + let unuseFormName; + label.receiveAncestorInsertEvents(); + label.event.subscribe(["insert", "ancestorInsert"], () => { + unuseFormName?.(); + const form = label.closest(Form_1.default); + unuseFormName = form?.name.use(label, name => formName = name); + const view = label.closest(View_1.default); + viewPath = view ? view.hash : "_"; + updateFor(); + }); + label.text.state.use(label, () => updateFor()); + return label.extend(label => ({})); + function updateFor() { + const text = label.text.state.value?.toString().toLowerCase().replace(/\W+/g, "-"); + if (!text) { + label.setFor(); + return; + } + if (!formName) + label.setFor(`${viewPath}--${text}--${i}`); + else + label.setFor(`${viewPath}--${formName}--${text}`); + } + }); +}); +define("ui/utility/AttributeManipulator", ["require", "exports", "lang/en-nz", "ui/utility/StringApplicator"], function (require, exports, en_nz_2, StringApplicator_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_2 = __importDefault(en_nz_2); + function AttributeManipulator(component) { + let translationHandlers; + const unuseAttributeMap = new Map(); + const result = { + get(attribute) { + return component.element.getAttribute(attribute) ?? undefined; + }, + append(...attributes) { + for (const attribute of attributes) { + delete translationHandlers?.[attribute]; + component.element.setAttribute(attribute, ""); + } + return component; + }, + prepend(...attributes) { + const oldAttributes = {}; + for (const attribute of [...component.element.attributes]) { + oldAttributes[attribute.name] = attribute.value; + component.element.removeAttribute(attribute.name); + } + for (const attribute of attributes) + component.element.setAttribute(attribute, oldAttributes[attribute] ?? ""); + for (const name of Object.keys(oldAttributes)) + component.element.setAttribute(name, oldAttributes[name]); + return component; + }, + set(attribute, value) { + delete translationHandlers?.[attribute]; + if (value === undefined) + component.element.removeAttribute(attribute); + else + component.element.setAttribute(attribute, value); + return component; + }, + bind(state, attribute, value) { + unuseAttributeMap.get(attribute)?.(); + unuseAttributeMap.set(attribute, state.use(component, active => { + if (active) + component.element.setAttribute(attribute, value ?? ""); + else + component.element.removeAttribute(attribute); + })); + return component; + }, + compute(attribute, supplier) { + if (component.element.hasAttribute(attribute)) + return component; + delete translationHandlers?.[attribute]; + const value = supplier(component); + if (value === undefined) + component.element.removeAttribute(attribute); + else + component.element.setAttribute(attribute, value); + return component; + }, + getUsing(attribute) { + return translationHandlers?.[attribute]; + }, + use(attribute, handler) { + translationHandlers ??= {}; + translationHandlers[attribute] = handler; + result.refresh(); + return component; + }, + refresh() { + if (!translationHandlers) + return; + for (const attribute in translationHandlers) { + const translationHandler = translationHandlers[attribute]; + const weave = typeof translationHandler === "string" ? en_nz_2.default[translationHandler]() : translationHandler(en_nz_2.default, StringApplicator_2.QuiltHelper); + component.element.setAttribute(attribute, weave.toString()); + } + }, + remove(...attributes) { + for (const attribute of attributes) { + delete translationHandlers?.[attribute]; + component.element.removeAttribute(attribute); + } + return component; + }, + toggle(present, attribute, value = "") { + return this[present ? "set" : "remove"](attribute, value); + }, + copy(element) { + if ("element" in element) + element = element.element; + for (const attribute of element.attributes) + component.element.setAttribute(attribute.name, attribute.value); + return component; + }, + }; + return result; + } + exports.default = AttributeManipulator; +}); +define("ui/utility/ClassManipulator", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function ClassManipulator(component) { + return { + has(...classes) { + return classes.every(className => component.element.classList.contains(className)); + }, + some(...classes) { + return classes.some(className => component.element.classList.contains(className)); + }, + add(...classes) { + component.element.classList.add(...classes); + return component; + }, + remove(...classes) { + component.element.classList.remove(...classes); + return component; + }, + toggle(present, ...classes) { + return this[present ? "add" : "remove"](...classes); + }, + copy(element) { + if ("element" in element) + element = element.element; + component.element.classList.add(...element.classList); + return component; + }, + }; + } + exports.default = ClassManipulator; +}); +define("ui/utility/EventManipulator", ["require", "exports", "utility/Arrays"], function (require, exports, Arrays_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_2 = __importDefault(Arrays_2); + const SYMBOL_REGISTERED_FUNCTION = Symbol("REGISTERED_FUNCTION"); + function EventManipulator(component) { + return { + emit(event, ...params) { + const detail = { result: [], params }; + const eventObject = new CustomEvent(event, { detail }); + component.element.dispatchEvent(eventObject); + return Object.assign(detail.result, { defaultPrevented: eventObject.defaultPrevented }); + }, + bubble(event, ...params) { + const detail = { result: [], params }; + const eventObject = new CustomEvent(event, { detail, bubbles: true }); + component.element.dispatchEvent(eventObject); + return Object.assign(detail.result, { defaultPrevented: eventObject.defaultPrevented }); + }, + subscribe(events, handler) { + if (handler[SYMBOL_REGISTERED_FUNCTION]) { + console.error(`Can't register handler for event(s) ${Arrays_2.default.resolve(events).join(", ")}, already used for other events`, handler); + return component; + } + const realHandler = (event) => { + const customEvent = event instanceof CustomEvent ? event : undefined; + const eventDetail = customEvent?.detail; + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + const result = handler(Object.assign(event, { component }), ...eventDetail?.params ?? []); + eventDetail?.result.push(result); + }; + Object.assign(handler, { [SYMBOL_REGISTERED_FUNCTION]: realHandler }); + for (const event of Arrays_2.default.resolve(events)) + component.element.addEventListener(event, realHandler); + return component; + }, + unsubscribe(events, handler) { + const realHandler = handler[SYMBOL_REGISTERED_FUNCTION]; + if (!realHandler) + return component; + delete handler[SYMBOL_REGISTERED_FUNCTION]; + for (const event of Arrays_2.default.resolve(events)) + component.element.removeEventListener(event, realHandler); + return component; + }, + }; + } + exports.default = EventManipulator; +}); +define("ui/utility/TextManipulator", ["require", "exports", "ui/utility/StringApplicator"], function (require, exports, StringApplicator_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + StringApplicator_3 = __importDefault(StringApplicator_3); + let Break; + const TextManipulator = Object.assign(function (component) { + return Object.assign((0, StringApplicator_3.default)(component, value => { + component.element.textContent = null; + if (!value) + return value; + const texts = value.split("\n"); + for (let i = 0; i < texts.length; i++) { + if (i > 0) + component.append(Break()); + component.element.append(document.createTextNode(texts[i])); + } + return value; + }), { + prepend(text) { + const texts = text.split("\n"); + for (let i = texts.length - 1; i >= 0; i--) { + if (i < texts.length - 1) + component.prepend(Break()); + component.element.prepend(document.createTextNode(texts[i])); + } + return component; + }, + append(text) { + const texts = text.split("\n"); + for (let i = 0; i < texts.length; i++) { + if (i > 0) + component.append(Break()); + component.element.append(document.createTextNode(texts[i])); + } + return component; + }, + }); + }, { + setComponent(Component) { + Break = Component + .Builder("br", component => component.style("break")) + .setName("Break"); + }, + }); + exports.default = TextManipulator; +}); +define("utility/Errors", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Errors; + (function (Errors) { + Errors.Impossible = () => new Error("Something impossible appears to have happened, what are you?"); + Errors.NotFound = () => Object.assign(new Error("Not found"), { code: 404 }); + Errors.BadData = (message) => Object.assign(new Error("Bad data was sent by the server", { cause: message }), { code: 500 }); + })(Errors || (Errors = {})); + exports.default = Errors; +}); +define("ui/Component", ["require", "exports", "ui/utility/AnchorManipulator", "ui/utility/AttributeManipulator", "ui/utility/ClassManipulator", "ui/utility/EventManipulator", "ui/utility/FocusListener", "ui/utility/StringApplicator", "ui/utility/StyleManipulator", "ui/utility/TextManipulator", "ui/utility/Viewport", "utility/Define", "utility/Env", "utility/Errors", "utility/State", "utility/string/Strings"], function (require, exports, AnchorManipulator_2, AttributeManipulator_1, ClassManipulator_1, EventManipulator_1, FocusListener_2, StringApplicator_4, StyleManipulator_1, TextManipulator_1, Viewport_2, Define_3, Env_2, Errors_1, State_12, Strings_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + AnchorManipulator_2 = __importDefault(AnchorManipulator_2); + AttributeManipulator_1 = __importDefault(AttributeManipulator_1); + ClassManipulator_1 = __importDefault(ClassManipulator_1); + EventManipulator_1 = __importDefault(EventManipulator_1); + FocusListener_2 = __importDefault(FocusListener_2); + StringApplicator_4 = __importDefault(StringApplicator_4); + StyleManipulator_1 = __importDefault(StyleManipulator_1); + TextManipulator_1 = __importDefault(TextManipulator_1); + Viewport_2 = __importDefault(Viewport_2); + Define_3 = __importDefault(Define_3); + Env_2 = __importDefault(Env_2); + Errors_1 = __importDefault(Errors_1); + State_12 = __importDefault(State_12); + Strings_3 = __importDefault(Strings_3); + const SYMBOL_COMPONENT_BRAND = Symbol("COMPONENT_BRAND"); + const ELEMENT_TO_COMPONENT_MAP = new WeakMap(); + Define_3.default.magic(Element.prototype, "component", { + get() { + return ELEMENT_TO_COMPONENT_MAP.get(this); + }, + set(component) { + if (component) { + ELEMENT_TO_COMPONENT_MAP.set(this, component); + } + else { + ELEMENT_TO_COMPONENT_MAP.delete(this); + } + }, + }); + var Classes; + (function (Classes) { + Classes["ReceiveAncestorInsertEvents"] = "_receieve-ancestor-insert-events"; + Classes["ReceiveDescendantInsertEvents"] = "_receieve-descendant-insert-events"; + Classes["ReceiveAncestorRectDirtyEvents"] = "_receieve-ancestor-rect-dirty-events"; + Classes["ReceiveScrollEvents"] = "_receieve-scroll-events"; + })(Classes || (Classes = {})); + const componentExtensionsRegistry = []; + function Component(type = "span") { + let unuseIdState; + let unuseNameState; + let unuseAriaLabelledByIdState; + let unuseAriaControlsIdState; + let descendantsListeningForScroll; + let owner; + let component = { + supers: [], + isComponent: true, + element: document.createElement(type), + removed: (0, State_12.default)(false), + rooted: (0, State_12.default)(false), + setOwner: newOwner => { + owner?.event.unsubscribe("remove", component.remove); + owner = newOwner; + owner.event.subscribe("remove", component.remove); + return component; + }, + replaceElement: newElement => { + if (typeof newElement === "string") + newElement = document.createElement(newElement); + const oldElement = component.element; + newElement.replaceChildren(...component.element.childNodes); + if (component.element.parentNode) + component.element.replaceWith(newElement); + component.element = newElement; + type = component.element.tagName; + ELEMENT_TO_COMPONENT_MAP.delete(oldElement); + ELEMENT_TO_COMPONENT_MAP.set(newElement, component); + component.attributes.copy(oldElement); + component.style.refresh(); + return component; + }, + is: (builder) => component.supers.includes(builder), + as: (builder) => component.supers.includes(builder) ? component : undefined, + cast: () => component, + and(builder, ...params) { + const result = builder.from(component, ...params); + if (result instanceof Promise) + return result.then(result => { + component = result; + component.supers.push(builder); + if (builder.name) + component.attributes.prepend(`:${builder.name.kebabcase}`); + return component; + }); + component = result; + component.supers.push(builder); + if (builder.name) + component.attributes.prepend(`:${builder.name.kebabcase}`); + return component; + }, + extend: extension => Object.assign(component, extension(component)), + extendMagic: (property, magic) => { + Define_3.default.magic(component, property, magic(component)); + return component; + }, + extendJIT: (property, supplier) => { + Define_3.default.magic(component, property, { + get: () => { + const value = supplier(component); + Define_3.default.set(component, property, value); + return value; + }, + set: value => { + Define_3.default.set(component, property, value); + }, + }); + return component; + }, + tweak: (tweaker, ...params) => { + tweaker?.(component, ...params); + return component; + }, + get style() { + return Define_3.default.set(component, "style", (0, StyleManipulator_1.default)(component)); + }, + get classes() { + return Define_3.default.set(component, "classes", (0, ClassManipulator_1.default)(component)); + }, + get attributes() { + return Define_3.default.set(component, "attributes", (0, AttributeManipulator_1.default)(component)); + }, + get event() { + return Define_3.default.set(component, "event", (0, EventManipulator_1.default)(component)); + }, + get text() { + return Define_3.default.set(component, "text", (0, TextManipulator_1.default)(component)); + }, + get anchor() { + return Define_3.default.set(component, "anchor", (0, AnchorManipulator_2.default)(component)); + }, + get hovered() { + return Define_3.default.set(component, "hovered", (0, State_12.default)(false)); + }, + get focused() { + return Define_3.default.set(component, "focused", (0, State_12.default)(false)); + }, + get hasFocused() { + return Define_3.default.set(component, "hasFocused", (0, State_12.default)(false)); + }, + get hoveredOrFocused() { + return Define_3.default.set(component, "hoveredOrFocused", State_12.default.Generator(() => component.hovered.value || component.focused.value) + .observe(component, component.hovered, component.focused)); + }, + get hoveredOrHasFocused() { + return Define_3.default.set(component, "hoveredOrHasFocused", State_12.default.Generator(() => component.hovered.value || component.hasFocused.value) + .observe(component, component.hovered, component.hasFocused)); + }, + get active() { + return Define_3.default.set(component, "active", (0, State_12.default)(false)); + }, + get id() { + return Define_3.default.set(component, "id", (0, State_12.default)(undefined)); + }, + get name() { + return Define_3.default.set(component, "name", (0, State_12.default)(undefined)); + }, + get rect() { + const rectState = State_12.default.JIT(() => component.element.getBoundingClientRect()); + const oldMarkDirty = rectState.markDirty; + rectState.markDirty = () => { + oldMarkDirty(); + for (const descendant of this.element.getElementsByClassName(Classes.ReceiveAncestorRectDirtyEvents)) + descendant.component?.event.emit("ancestorRectDirty"); + return rectState; + }; + this.receiveAncestorInsertEvents(); + this.receiveAncestorScrollEvents(); + this.classes.add(Classes.ReceiveAncestorRectDirtyEvents); + this.event.subscribe(["insert", "ancestorInsert", "ancestorScroll", "ancestorRectDirty"], rectState.markDirty); + Viewport_2.default.size.subscribe(component, rectState.markDirty); + return Define_3.default.set(component, "rect", rectState); + }, + setId: id => { + unuseIdState?.(); + unuseIdState = undefined; + if (id && typeof id !== "string") + unuseIdState = id.use(component, setId); + else + setId(id); + return component; + function setId(id) { + if (id) { + component.element.setAttribute("id", id); + component.id.value = id; + } + else { + component.element.removeAttribute("id"); + component.id.value = undefined; + } + } + }, + setName: name => { + unuseNameState?.(); + unuseNameState = undefined; + if (name && typeof name !== "string") + unuseNameState = name.use(component, setName); + else + setName(name); + return component; + function setName(name) { + if (name) { + name = name.replace(/[^\w-]+/g, "-").toLowerCase(); + component.element.setAttribute("name", name); + component.name.value = name; + } + else { + component.element.removeAttribute("name"); + component.name.value = undefined; + } + } + }, + remove(internal = false) { + component.removed.value = true; + component.rooted.value = false; + if (internal !== true) + for (const descendant of component.element.querySelectorAll("*")) + descendant.component?.remove(true); + component.element.component = undefined; + component.element.remove(); + component.event.emit("unroot"); + component.event.emit("remove"); + owner?.event.unsubscribe("remove", component.remove); + }, + appendTo(destination) { + Component.element(destination).append(component.element); + component.emitInsert(); + return component; + }, + prependTo(destination) { + Component.element(destination).prepend(component.element); + component.emitInsert(); + return component; + }, + insertTo(destination, direction, sibling) { + const element = Component.element(destination); + const siblingElement = sibling ? Component.element(sibling) : null; + if (direction === "before") + element.insertBefore(component.element, siblingElement); + else + element.insertBefore(component.element, siblingElement?.nextSibling ?? null); + component.emitInsert(); + return component; + }, + append(...contents) { + const elements = contents.map(Component.element); + component.element.append(...elements); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + prepend(...contents) { + const elements = contents.map(Component.element); + component.element.prepend(...elements); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + insert(direction, sibling, ...contents) { + const siblingElement = sibling ? Component.element(sibling) : null; + const elements = contents.map(Component.element); + if (direction === "before") + for (let i = elements.length - 1; i >= 0; i--) + component.element.insertBefore(elements[i], siblingElement); + else + for (const element of elements) + component.element.insertBefore(element, siblingElement?.nextSibling ?? null); + for (const element of elements) + element.component?.emitInsert(); + return component; + }, + removeContents() { + component.element.replaceChildren(); + return component; + }, + closest(builder) { + let cursor = component.element; + while (cursor) { + cursor = cursor.parentElement; + const component = cursor?.component; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + if (component?.is(builder)) + return component; + } + }, + get parent() { + return component.element.parentElement?.component; + }, + get previousSibling() { + return component.element.previousElementSibling?.component; + }, + get nextSibling() { + return component.element.nextElementSibling?.component; + }, + *getAncestorComponents() { + let cursor = component.element; + while (cursor) { + cursor = cursor.parentElement; + const component = cursor?.component; + if (component) + yield component; + } + }, + receiveAncestorInsertEvents: () => { + component.element.classList.add(Classes.ReceiveAncestorInsertEvents); + return component; + }, + receiveDescendantInsertEvents: () => { + component.element.classList.add(Classes.ReceiveAncestorInsertEvents); + return component; + }, + receiveAncestorScrollEvents() { + component.element.classList.add(Classes.ReceiveScrollEvents); + return component; + }, + emitInsert: () => { + updateRooted(component); + emitInsert(component); + return component; + }, + monitorScrollEvents() { + descendantsListeningForScroll ??= component.element.getElementsByClassName(Classes.ReceiveScrollEvents); + component.event.subscribe("scroll", () => { + for (const descendant of [...descendantsListeningForScroll]) + descendant.component?.event.emit("ancestorScroll"); + }); + return component; + }, + onRooted(callback) { + component.rooted.awaitManual(true, () => callback(component)); + return component; + }, + ariaRole: (role) => { + if (!role) + return component.attributes.remove("role"); + return component.attributes.set("role", role); + }, + get ariaLabel() { + return Define_3.default.set(component, "ariaLabel", (0, StringApplicator_4.default)(component, value => component.attributes.set("aria-label", value))); + }, + ariaLabelledBy: labelledBy => { + unuseAriaLabelledByIdState?.(); + if (labelledBy) { + const state = State_12.default.Generator(() => labelledBy.id.value ?? labelledBy.attributes.get("for")) + .observe(component, labelledBy.id, labelledBy.cast()?.for); + unuseAriaLabelledByIdState = state.use(component, id => component.attributes.set("aria-labelledby", id)); + } + return component; + }, + ariaHidden: () => component.attributes.set("aria-hidden", "true"), + ariaChecked: state => { + state.use(component, state => component.attributes.set("aria-checked", `${state}`)); + return component; + }, + ariaControls: target => { + unuseAriaControlsIdState?.(); + unuseAriaControlsIdState = target?.id.use(component, id => component.attributes.set("aria-controls", id)); + return component; + }, + tabIndex: index => { + if (index === undefined) + component.element.removeAttribute("tabindex"); + else if (index === "programmatic") + component.element.setAttribute("tabindex", "-1"); + else if (index === "auto") + component.element.setAttribute("tabindex", "0"); + else + component.element.setAttribute("tabindex", `${index}`); + return component; + }, + focus: () => { + FocusListener_2.default.focus(component.element); + return component; + }, + blur: () => { + FocusListener_2.default.blur(component.element); + return component; + }, + }; + for (const extension of componentExtensionsRegistry) + extension(component); + if (!Component.is(component)) + throw Errors_1.default.Impossible(); + component.element.component = component; + return component; + } + function emitInsert(component) { + if (!component) + return; + component.event.emit("insert"); + const descendantsListeningForEvent = component.element.getElementsByClassName(Classes.ReceiveAncestorInsertEvents); + for (const descendant of descendantsListeningForEvent) + descendant.component?.event.emit("ancestorInsert"); + let cursor = component.element.parentElement; + while (cursor) { + cursor.component?.event.emit("descendantInsert"); + cursor = cursor.parentElement; + } + } + function updateRooted(component) { + if (component) { + const rooted = document.documentElement.contains(component.element); + if (component.rooted.value === rooted) + return; + component.rooted.value = rooted; + component.event.emit(rooted ? "root" : "unroot"); + for (const descendant of component.element.querySelectorAll("*")) { + const component = descendant.component; + if (component) { + component.rooted.value = rooted; + component.event.emit(rooted ? "root" : "unroot"); + } + } + } + } + (function (Component) { + function is(value) { + return typeof value === "object" && !!value?.isComponent; + } + Component.is = is; + function element(from) { + return is(from) ? from.element : from; + } + Component.element = element; + const defaultBuilder = (type) => Component(type); + function Builder(initialOrBuilder, builder) { + let name = getBuilderName(); + const type = typeof initialOrBuilder === "string" ? initialOrBuilder : undefined; + const initialBuilder = !builder || typeof initialOrBuilder === "string" ? defaultBuilder : initialOrBuilder; + builder ??= initialOrBuilder; + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const realBuilder = (component = initialBuilder(type), ...params) => builder(component, ...params); + const simpleBuilder = (...params) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + const component = realBuilder(undefined, ...params); + if (component instanceof Promise) + return component.then(completeComponent); + return completeComponent(component); + }; + Object.defineProperty(simpleBuilder, "name", { value: name, configurable: true }); + const resultBuilder = Object.assign(simpleBuilder, { + from: realBuilder, + setName(newName) { + name = addKebabCase(newName); + Object.defineProperty(simpleBuilder, "name", { value: name }); + return resultBuilder; + }, + }); + return resultBuilder; + function completeComponent(component) { + if (name && Env_2.default.isDev) { + component[Symbol.toStringTag] ??= name.toString(); + const tagName = `:${name.kebabcase}`; + if (component.element.tagName === "SPAN") { + component.replaceElement(tagName); + } + else { + component.attributes.prepend(tagName); + } + } + component.supers.push(simpleBuilder); + return component; + } + } + Component.Builder = Builder; + function Extension(builder) { + return { + name: getBuilderName(), + from: builder, + }; + } + Component.Extension = Extension; + function extend(extension) { + componentExtensionsRegistry.push(extension); + } + Component.extend = extend; + /** + * Returns the component for the given element, if it exists + */ + function get(element) { + if (!element || (typeof element !== "object" && typeof element !== "function")) + return undefined; + return ELEMENT_TO_COMPONENT_MAP.get(element); + } + Component.get = get; + const STACK_FILE_NAME_REGEX = /\(http.*?(\w+)\.ts:\d+:\d+\)/; + const PASCAL_CASE_WORD_START = /(?<=[a-z0-9_-])(?=[A-Z])/g; + function addKebabCase(name) { + return Object.assign(String(name), { + kebabcase: name.replaceAll(PASCAL_CASE_WORD_START, "-").toLowerCase(), + }); + } + function getBuilderName() { + const stack = Strings_3.default.shiftLine((new Error().stack ?? ""), 3); + const name = stack.match(STACK_FILE_NAME_REGEX)?.[1]; + if (!name) + return undefined; + return addKebabCase(name); + } + })(Component || (Component = {})); + TextManipulator_1.default.setComponent(Component); + exports.default = Component; +}); +define("utility/Store", ["require", "exports", "utility/State"], function (require, exports, State_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + State_13 = __importDefault(State_13); + // export type IStoreEvents = + // & { [KEY in keyof ILocalStorage as `set${Capitalize}`]: { value: ILocalStorage[KEY]; oldValue: ILocalStorage[KEY] } } + // & { [KEY in keyof ILocalStorage as `delete${Capitalize}`]: { oldValue: ILocalStorage[KEY] } } + let storage; + let statesProxy; + let states; + class Store { + // public static readonly event = EventManager.make() + static get items() { + return storage ??= new Proxy({}, { + has(_, key) { + return Store.has(key); + }, + get(_, key) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return Store.get(key); + }, + set(_, key, value) { + return Store.set(key, value); + }, + deleteProperty(_, key) { + return Store.delete(key); + }, + }); + } + static get state() { + const s = states ??= {}; + return statesProxy ??= new Proxy({}, { + has(_, key) { + return Store.has(key); + }, + get(_, key) { + return s[key] ??= (0, State_13.default)(Store.get(key)); + }, + }); + } + static get full() { + const result = {}; + for (const [key, value] of Object.entries(localStorage)) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + result[key] = JSON.parse(value); + return result; + } + static has(key) { + return localStorage.getItem(key) !== null; + } + static get(key) { + const value = localStorage.getItem(key); + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return value === null ? null : JSON.parse(value); + } + catch { + localStorage.removeItem(key); + return null; + } + } + static set(key, value) { + // const oldValue = Store.get(key) + if (value === undefined) + localStorage.removeItem(key); + else + localStorage.setItem(key, JSON.stringify(value)); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + // Store.event.emit(`set${key[0].toUpperCase()}${key.slice(1)}` as keyof IStoreEvents, { value, oldValue } as never) + const state = states?.[key]; + if (state) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + state.value = value; + return true; + } + static delete(key) { + // const oldValue = Store.get(key) + localStorage.removeItem(key); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + // Store.event.emit(`delete${key[0].toUpperCase()}${key.slice(1)}` as keyof IStoreEvents, { oldValue } as never) + const state = states?.[key]; + if (state) + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + state.value = undefined; + return true; + } + } + exports.default = Store; + Object.assign(window, { Store }); +}); +define("utility/Popup", ["require", "exports", "utility/Store"], function (require, exports, Store_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = popup; + Store_1 = __importDefault(Store_1); + function popup(name, url, width = 600, height = 800) { + const left = (window.innerWidth - width) / 2 + window.screenLeft; + const top = (window.innerHeight - height) / 2 + window.screenTop; + return new Promise((resolve, reject) => { + delete Store_1.default.items.popupError; + const options = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left; + const oauthPopup = window.open(url, name, options); + const interval = setInterval(() => { + if (oauthPopup?.closed) { + clearInterval(interval); + const popupError = Store_1.default.items.popupError; + if (popupError) + return reject(Object.assign(new Error(popupError.message ?? "Internal Server Error"), { code: popupError.code })); + resolve(); + } + }, 100); + }); + } +}); +define("model/Session", ["require", "exports", "endpoint/auth/EndpointAuthRemove", "endpoint/session/EndpointSessionGet", "endpoint/session/EndpointSessionReset", "utility/Env", "utility/Popup", "utility/State", "utility/Store"], function (require, exports, EndpointAuthRemove_1, EndpointSessionGet_1, EndpointSessionReset_1, Env_3, Popup_1, State_14, Store_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthRemove_1 = __importDefault(EndpointAuthRemove_1); + EndpointSessionGet_1 = __importDefault(EndpointSessionGet_1); + EndpointSessionReset_1 = __importDefault(EndpointSessionReset_1); + Env_3 = __importDefault(Env_3); + Popup_1 = __importDefault(Popup_1); + State_14 = __importDefault(State_14); + Store_2 = __importDefault(Store_2); + var Session; + (function (Session) { + const clearedWithSessionChange = []; + function setClearedWithSessionChange(...keys) { + clearedWithSessionChange.push(...keys); + } + Session.setClearedWithSessionChange = setClearedWithSessionChange; + async function refresh() { + const session = await EndpointSessionGet_1.default.query(); + const stateToken = session.headers.get("State-Token"); + if (stateToken) + Store_2.default.items.stateToken = stateToken; + if (Store_2.default.items.session?.created !== session.data?.created) + for (const key of clearedWithSessionChange) + Store_2.default.delete(key); + Store_2.default.items.session = session?.data ?? undefined; + updateState(); + } + Session.refresh = refresh; + async function reset() { + await EndpointSessionReset_1.default.query(); + delete Store_2.default.items.session; + updateState(); + } + Session.reset = reset; + function setAuthor(author) { + const session = Store_2.default.items.session; + if (!session) + return void refresh(); + Store_2.default.items.session = { + ...session, + author: { + ...author, + authorisations: undefined, + }, + authorisations: author.authorisations ?? session.authorisations, + }; + updateState(); + } + Session.setAuthor = setAuthor; + function updateState() { + Auth.state.value = Store_2.default.items.session?.author ? "logged-in" : Store_2.default.items.session?.authorisations?.length ? "has-authorisations" : "none"; + Auth.authorisations.value = Store_2.default.items.session?.authorisations ?? []; + Auth.author.value = Store_2.default.items.session?.author ?? undefined; + } + function getStateToken() { + return Store_2.default.items.stateToken; + } + Session.getStateToken = getStateToken; + let Auth; + (function (Auth) { + Auth.state = (0, State_14.default)("none"); + Auth.loggedIn = State_14.default.Generator(() => Auth.state.value === "logged-in").observeManual(Auth.state); + Auth.authorisations = (0, State_14.default)([]); + Auth.author = (0, State_14.default)(undefined, (a, b) => a?.vanity === b?.vanity); + function getAll() { + return Store_2.default.items.session?.authorisations ?? []; + } + Auth.getAll = getAll; + function get(service) { + return Store_2.default.items.session?.authorisations?.find(auth => auth.service === service); + } + Auth.get = get; + function isAuthed(service) { + return Session.Auth.authorisations.value.some(auth => auth.service === service.name); + } + Auth.isAuthed = isAuthed; + async function unauth(authOrId) { + const id = typeof authOrId === "string" ? authOrId : authOrId.id; + await EndpointAuthRemove_1.default.query({ body: { id } }); + const session = Store_2.default.items.session; + if (session?.authorisations) { + let authorisations = session.authorisations.filter(auth => auth.id !== id); + if (!authorisations.length) + authorisations = null; + Store_2.default.items.session = { + ...session, + authorisations, + }; + } + updateState(); + } + Auth.unauth = unauth; + async function auth(service) { + await (0, Popup_1.default)(`Login Using ${service.name}`, service.url_begin, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session.refresh(); + } + Auth.auth = auth; + let isRequestingDangerToken = false; + function canRequestDangerToken() { + return !isRequestingDangerToken; + } + Auth.canRequestDangerToken = canRequestDangerToken; + async function requestDangerToken(type, service) { + if (isRequestingDangerToken) + return false; + isRequestingDangerToken = true; + const result = await (0, Popup_1.default)(`Re-authenticate Using ${service.name}`, `${Env_3.default.API_ORIGIN}danger-token/request/${type}/${service.id}/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + isRequestingDangerToken = false; + return result; + } + Auth.requestDangerToken = requestDangerToken; + async function await(owner) { + if (Auth.state.value === "logged-in") + return true; + return new Promise(resolve => { + Auth.state.subscribe(owner, handleStateChange); + function handleStateChange(value) { + if (value !== "logged-in") + return; + resolve(); + Auth.state.unsubscribe(handleStateChange); + } + }); + } + Auth.await = await; + })(Auth = Session.Auth || (Session.Auth = {})); + })(Session || (Session = {})); + Object.assign(window, { Session }); + exports.default = Session; +}); +define("navigation/Route", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function Route(path, route) { + const segments = (path.startsWith("/") ? path.slice(1) : path).split("/"); + const varGroups = []; + let regexString = "^"; + for (const segment of segments) { + regexString += "/+"; + if (segment[0] !== "$") { + regexString += segment; + continue; + } + if (segment[1] === "$") { + varGroups.push(segment.slice(2)); + regexString += "(.*)"; + continue; + } + varGroups.push(segment.slice(1)); + regexString += "([^/]+)"; + } + regexString += "$"; + const regex = new RegExp(regexString); + const rawRoutePath = path; + return { + path, + ...typeof route === "function" ? { handler: route } : route, + match: path => { + const match = path.match(regex); + if (!match) + return undefined; + const params = {}; + for (let i = 0; i < varGroups.length; i++) { + const groupName = varGroups[i]; + const group = match[i + 1]; + if (group === undefined) { + console.warn(`${rawRoutePath} matched, but $${groupName} was unset`); + return undefined; + } + params[groupName] = group; + } + return params; + }, + }; + } + exports.default = Route; +}); +define("endpoint/author/EndpointAuthorDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_5 = __importDefault(Endpoint_5); + exports.default = (0, Endpoint_5.default)("/author/delete", "post") + .noResponse(); +}); +define("ui/component/core/Dialog", ["require", "exports", "ui/Component", "utility/State"], function (require, exports, Component_15, State_15) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_15 = __importDefault(Component_15); + State_15 = __importDefault(State_15); + const Dialog = Component_15.default.Builder(() => { + const opened = (0, State_15.default)(false); + const willOpen = (0, State_15.default)(false); + const willClose = (0, State_15.default)(false); + let modal = true; + let unbind; + const dialog = (0, Component_15.default)("dialog") + .style("dialog") + .style.bind(opened, "dialog--open") + .extend(dialog => ({ + opened, + willClose, + willOpen, + setNotModal: (notModal = true) => { + modal = !notModal; + dialog.style.toggle(notModal, "dialog--not-modal"); + return dialog; + }, + setFullscreen: (fullscreen = true) => dialog.style.toggle(fullscreen, "dialog--fullscreen"), + open: () => { + dialog.willOpen.value = true; + if (!dialog.willOpen.value) + return dialog; + unbind?.(); + dialog.element[modal ? "showModal" : "show"](); + dialog.opened.value = true; + dialog.willOpen.value = false; + return dialog; + }, + close: () => { + dialog.willClose.value = true; + if (!dialog.willClose.value) + return dialog; + unbind?.(); + dialog.element.close(); + dialog.opened.value = false; + dialog.willClose.value = false; + return dialog; + }, + toggle: (open = !dialog.opened.value) => { + const willChangeStateName = open ? "willOpen" : "willClose"; + dialog[willChangeStateName].value = true; + if (!dialog[willChangeStateName].value) + return dialog; + unbind?.(); + if (open) + dialog.element[modal ? "showModal" : "show"](); + else + dialog.element.close(); + dialog.opened.value = open ?? !dialog.opened.value; + dialog[willChangeStateName].value = false; + return dialog; + }, + bind: state => { + unbind?.(); + unbind = state.use(dialog, open => { + const willChangeStateName = open ? "willOpen" : "willClose"; + dialog[willChangeStateName].value = true; + if (open) + dialog.element[modal ? "showModal" : "show"](); + else + dialog.element.close(); + dialog.opened.value = open; + dialog[willChangeStateName].value = false; + }); + return dialog; + }, + unbind: () => { + unbind?.(); + return dialog; + }, + })); + return dialog; + }); + exports.default = Dialog; +}); +define("ui/component/core/BlockDialog", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Dialog", "utility/Task"], function (require, exports, Component_16, Block_3, Dialog_1, Task_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_16 = __importDefault(Component_16); + Block_3 = __importDefault(Block_3); + Dialog_1 = __importDefault(Dialog_1); + Task_2 = __importDefault(Task_2); + const BlockDialog = Component_16.default.Builder((component) => { + const dialog = component.and(Dialog_1.default).and(Block_3.default) + .viewTransition() + .style.remove("block"); + dialog + .style("dialog-block-wrapper") + .style.bind(dialog.opened.not, "dialog-block-wrapper--closed"); + const block = (0, Block_3.default)() + .style("dialog-block") + .style.bind(dialog.opened.not, "dialog-block--closed") + .appendTo(dialog); + dialog + .extend(dialog => ({ + type: block.type, + content: block.content, + setActionsMenu: block.setActionsMenu, + })) + .extendJIT("header", () => block.header) + .extendJIT("title", () => block.title) + .extendJIT("primaryActions", () => block.primaryActions) + .extendJIT("description", () => block.description) + .extendJIT("footer", () => block.footer) + .extendJIT("actionsMenuButton", () => block.actionsMenuButton); + const superOpen = dialog.open; + return dialog.extend(dialog => ({ + open() { + superOpen(); + block.style("dialog-block--opening"); + void Task_2.default.yield().then(() => block.style.remove("dialog-block--opening")); + return dialog; + }, + })); + }); + exports.default = BlockDialog; +}); +define("endpoint/auth/EndpointAuthServices", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_6 = __importDefault(Endpoint_6); + exports.default = (0, Endpoint_6.default)("/auth/services", "get"); +}); +define("ui/component/core/Checkbutton", ["require", "exports", "ui/Component", "ui/component/core/Button", "utility/State"], function (require, exports, Component_17, Button_3, State_16) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_17 = __importDefault(Component_17); + Button_3 = __importDefault(Button_3); + State_16 = __importDefault(State_16); + const Checkbutton = Component_17.default.Builder("label", (component) => { + const input = (0, Component_17.default)("input") + .style("checkbutton-input") + .attributes.set("type", "checkbox"); + const inputElement = input.element; + const state = (0, State_16.default)(false); + let unuse; + const checkbutton = component + .and(Button_3.default) + .style("checkbutton") + .tabIndex("auto") + .ariaChecked(state) + .ariaRole("checkbox") + .append(input) + .extend(() => ({ + input, + checked: state, + isChecked: () => inputElement.checked, + setChecked: (checked) => { + if (checked === inputElement.checked) + return checkbutton; + if (unuse) { + checkbutton.event.emit("trySetChecked", checked); + return checkbutton; + } + inputElement.checked = checked; + onChange(); + return checkbutton; + }, + use: sourceState => { + unuse = sourceState.use(checkbutton, checked => { + if (inputElement.checked === checked) + return; + inputElement.checked = checked; + onChange(); + }); + return checkbutton; + }, + unuse: () => { + unuse?.(); + unuse = undefined; + return checkbutton; + }, + })); + input.event.subscribe("change", () => { + if (unuse) { + const checked = inputElement.checked; + inputElement.checked = !checked; // undo because it's managed by a State + checkbutton.event.emit("trySetChecked", checked); + return; + } + onChange(); + }); + function onChange() { + state.value = inputElement.checked; + checkbutton.style.toggle(inputElement.checked, "checkbutton--checked"); + checkbutton.event.emit("setChecked", inputElement.checked); + } + return checkbutton; + }); + exports.default = Checkbutton; +}); +define("ui/component/OAuthService", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Checkbutton", "utility/State"], function (require, exports, Session_1, Component_18, Checkbutton_1, State_17) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_1 = __importDefault(Session_1); + Component_18 = __importDefault(Component_18); + Checkbutton_1 = __importDefault(Checkbutton_1); + State_17 = __importDefault(State_17); + const OAuthService = Component_18.default.Builder((component, service, reauthDangerToken) => { + const authedAtStart = !!Session_1.default.Auth.get(service.name); + const authorisationState = Session_1.default.Auth.authorisations.map(component, authorisations => authorisations.find(authorisation => authorisation.service === service.name)); + const isAuthed = State_17.default.Truthy(component, authorisationState); + const button = component + .and(Checkbutton_1.default) + .setChecked(authedAtStart) + .style("oauth-service") + .ariaRole("button") + .attributes.remove("aria-checked") + .style.bind(isAuthed, "oauth-service--authenticated") + .style.setVariable("colour", `#${service.colour.toString(16)}`) + .append((0, Component_18.default)("img") + .style("oauth-service-icon") + .attributes.set("src", service.icon)) + .append((0, Component_18.default)() + .style("oauth-service-name") + .text.set(service.name)) + .extend(button => ({})); + if (!reauthDangerToken) + (0, Component_18.default)() + .style("oauth-service-state") + .style.bind(isAuthed, "oauth-service-state--authenticated") + .style.bind(button.hoveredOrFocused, "oauth-service-state--focus") + .appendTo((0, Component_18.default)() + .style("oauth-service-state-wrapper") + .style.bind(button.hoveredOrFocused, "oauth-service-state-wrapper--focus") + .appendTo(button)); + const username = (0, Component_18.default)() + .style("oauth-service-username") + .style.bind(isAuthed, "oauth-service-username--has-username") + .ariaHidden() + .appendTo(button); + authorisationState.use(button, authorisation => { + button.ariaLabel.use(quilt => quilt[`view/account/auth/service/accessibility/${authorisation ? "disconnect" : "connect"}`](service.name, authorisation?.display_name)); + username.text.set(authorisation?.display_name ?? ""); + }); + button.onRooted(() => { + button.event.subscribe("click", async (event) => { + event.preventDefault(); + if (reauthDangerToken) { + if (!Session_1.default.Auth.canRequestDangerToken()) + return; + const granted = await Session_1.default.Auth.requestDangerToken(reauthDangerToken, service); + if (granted) + button.event.bubble("dangerTokenGranted", reauthDangerToken); + else + ; + // TODO show notification + return; + } + let auth = Session_1.default.Auth.get(service.name); + if (auth) + await Session_1.default.Auth.unauth(auth.id); + else + await Session_1.default.Auth.auth(service); + auth = Session_1.default.Auth.get(service.name); + event.component.setChecked(!!auth); + }); + }); + return button; + }); + exports.default = OAuthService; +}); +define("ui/component/OAuthServices", ["require", "exports", "endpoint/auth/EndpointAuthServices", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/OAuthService", "utility/Objects"], function (require, exports, EndpointAuthServices_1, Session_2, Component_19, Block_4, OAuthService_1, Objects_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthServices_1 = __importDefault(EndpointAuthServices_1); + Session_2 = __importDefault(Session_2); + Component_19 = __importDefault(Component_19); + Block_4 = __importDefault(Block_4); + OAuthService_1 = __importDefault(OAuthService_1); + Objects_2 = __importDefault(Objects_2); + const OAuthServices = Component_19.default.Builder(async (component, state, reauthDangerToken) => { + const block = component + .and(Block_4.default) + .viewTransition("oauth-services") + .style("oauth-service-container") + .style.toggle(!!reauthDangerToken, "oauth-service-container--reauth-list") + .extend(block => ({})); + if (reauthDangerToken) { + block.type("flush"); + } + else { + state.use(component, state => { + block.title.text.use(`view/account/auth/${state}/title`); + block.description.text.use(`view/account/auth/${state}/description`); + }); + } + const list = (0, Component_19.default)() + .style("oauth-service-list") + .appendTo(block); + const services = await EndpointAuthServices_1.default.query(); + if (services instanceof Error) { + console.error(services); + return block; + } + for (const service of Objects_2.default.values(services.data)) + if (!reauthDangerToken || Session_2.default.Auth.isAuthed(service)) + (0, OAuthService_1.default)(service, reauthDangerToken) + // .event.subscribe("dangerTokenGranted", event => block.event.emit("dangerTokenGranted")) + .appendTo(list); + return block; + }); + exports.default = OAuthServices; +}); +define("ui/component/core/ConfirmDialog", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/BlockDialog", "ui/component/core/Button", "ui/component/core/Paragraph", "ui/component/OAuthServices", "utility/State"], function (require, exports, Session_3, Component_20, BlockDialog_1, Button_4, Paragraph_2, OAuthServices_1, State_18) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_3 = __importDefault(Session_3); + Component_20 = __importDefault(Component_20); + BlockDialog_1 = __importDefault(BlockDialog_1); + Button_4 = __importDefault(Button_4); + Paragraph_2 = __importDefault(Paragraph_2); + OAuthServices_1 = __importDefault(OAuthServices_1); + State_18 = __importDefault(State_18); + const ConfirmDialog = Object.assign(Component_20.default.Builder(async (component, definition) => { + const dialog = component.and(BlockDialog_1.default); + const state = (0, State_18.default)(undefined); + dialog.title.text.use(definition?.titleTranslation ?? "shared/prompt/confirm"); + const cancelButton = (0, Button_4.default)() + .text.use(definition?.confirmButtonTranslation ?? "shared/action/cancel") + .appendTo(dialog.footer.right); + const confirmButton = (0, Button_4.default)() + .type("primary") + .text.use(definition?.confirmButtonTranslation ?? "shared/action/confirm") + .appendTo(dialog.footer.right); + if (definition?.dangerToken) { + confirmButton.setDisabled(true, "danger-token"); + (0, Paragraph_2.default)() + .text.use("shared/prompt/reauth") + .appendTo(dialog.content); + const authServices = await (0, OAuthServices_1.default)(Session_3.default.Auth.state, definition.dangerToken); + authServices + .event.subscribe("dangerTokenGranted", () => confirmButton.setDisabled(false, "danger-token")) + .appendTo(dialog.content); + } + return dialog + .extend(dialog => ({ + state, + cancelButton, + confirmButton, + await(owner) { + state.value = undefined; + dialog.open(); + return new Promise(resolve => dialog.state.await(owner, [true, false], resolve)); + }, + cancel() { + state.value = false; + dialog.close(); + }, + confirm() { + state.value = true; + dialog.close(); + }, + })) + .onRooted(dialog => { + dialog.cancelButton.event.subscribe("click", dialog.cancel); + dialog.confirmButton.event.subscribe("click", dialog.confirm); + }); + }), { + prompt: async (owner, definition) => (await ConfirmDialog(definition)) + .appendTo(document.body) + .event.subscribe("close", event => event.component.event.subscribe("transitionend", event => event.component.remove())) + .await(owner), + }); + exports.default = ConfirmDialog; +}); +define("endpoint/author/EndpointAuthorCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_7 = __importDefault(Endpoint_7); + exports.default = (0, Endpoint_7.default)("/author/create", "post"); +}); +define("endpoint/author/EndpointAuthorUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_8 = __importDefault(Endpoint_8); + exports.default = (0, Endpoint_8.default)("/author/update", "post"); +}); +define("ui/component/core/LabelledRow", ["require", "exports", "ui/Component", "ui/component/core/Label"], function (require, exports, Component_21, Label_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_21 = __importDefault(Component_21); + const LabelledRow = Component_21.default.Builder((row) => { + row.style("labelled-row"); + let label = (0, Label_1.AutoLabel)().style("labelled-row-label").appendTo(row); + let content = (0, Component_21.default)().style("labelled-row-content").appendTo(row); + return row + .extend(row => ({ + label, content, + })) + .extendMagic("label", row => ({ + get: () => label, + set: newLabel => { + if (label === newLabel) + return; + label.element.replaceWith(newLabel.element); + label = newLabel; + }, + })) + .extendMagic("content", row => ({ + get: () => content, + set: newContent => { + if (content === newContent) + return; + content.element.replaceWith(newContent.element); + content = newContent; + }, + })); + }); + exports.default = LabelledRow; +}); +define("ui/component/core/LabelledTable", ["require", "exports", "ui/Component", "ui/component/core/LabelledRow"], function (require, exports, Component_22, LabelledRow_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_22 = __importDefault(Component_22); + LabelledRow_1 = __importDefault(LabelledRow_1); + const LabelledTable = Component_22.default.Builder((table) => { + table.style("labelled-table"); + let labelInitialiser; + let factory; + return table.extend(table => ({ + label: initialiser => { + labelInitialiser = initialiser; + return factory ??= { + content: contentInitialiser => { + const row = (0, LabelledRow_1.default)() + .style("labelled-row--in-labelled-table") + .appendTo(table); + row.label = labelInitialiser(row.label, row); + row.content = contentInitialiser(row.content, row.label, row) ?? row.content; + labelInitialiser = undefined; + return table; + }, + }; + }, + })); + }); + exports.default = LabelledTable; +}); +define("ui/component/core/TextInput", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_23, Input_1, StringApplicator_5, State_19) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_23 = __importDefault(Component_23); + Input_1 = __importDefault(Input_1); + StringApplicator_5 = __importDefault(StringApplicator_5); + State_19 = __importDefault(State_19); + const TextInput = Component_23.default.Builder("input", (component) => { + let shouldIgnoreInputEvent = false; + let filterFunction; + const input = component + .and(Input_1.default) + .style("text-input") + .attributes.set("type", "text") + .extend(input => ({ + value: "", + state: (0, State_19.default)(""), + default: (0, StringApplicator_5.default)(input, value => { + if (input.value === "") { + input.value = value ?? ""; + input.state.value = value ?? ""; + input.length.value = value?.length ?? 0; + } + }), + placeholder: (0, StringApplicator_5.default)(input, value => { + input.attributes.set("placeholder", value); + }), + ignoreInputEvent: (ignore = true) => { + shouldIgnoreInputEvent = ignore; + return input; + }, + filter: filter => { + filterFunction = filter; + return input; + }, + })) + .extendMagic("value", input => ({ + get: () => input.element.value || "", + set: (value) => { + input.element.value = value; + input.state.value = value; + input.length.value = value.length; + }, + })); + input.length.value = 0; + input.event.subscribe(["input", "change"], event => { + const element = input.element.asType("input"); + if (filterFunction && element) { + if (event.type === "change") { + input.value = filterFunction(input.value, "", true); + } + else { + let { selectionStart, selectionEnd, value } = element; + const hasSelection = selectionStart !== null || selectionEnd !== null; + selectionStart ??= value.length; + selectionEnd ??= value.length; + const beforeSelection = filterFunction(value.slice(0, selectionStart), "", false); + const selection = filterFunction(value.slice(selectionStart, selectionEnd), beforeSelection, false); + const afterSelection = filterFunction(value.slice(selectionEnd), selection || beforeSelection, false); + input.value = beforeSelection + selection + afterSelection; + if (hasSelection) + element.setSelectionRange(beforeSelection.length, beforeSelection.length + selection.length); + } + } + if (shouldIgnoreInputEvent) + return; + input.state.value = input.value; + input.length.value = input.value.length; + }); + return input; + }); + exports.default = TextInput; +}); +define("ui/component/core/TextInputBlock", ["require", "exports", "ui/Component", "ui/component/core/TextInput"], function (require, exports, Component_24, TextInput_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_24 = __importDefault(Component_24); + TextInput_1 = __importDefault(TextInput_1); + const TextInputBlock = Component_24.default.Builder((component) => { + const inputs = []; + const block = component + .style("text-input-block") + .extend(block => ({ + inputs, + addInput: (initialiser) => { + const input = (0, TextInput_1.default)() + .style("text-input-block-input") + .tweak(initialiser) + .event.subscribe("remove", () => { + inputs.filterInPlace(i => i !== input); + const firstInput = inputs.at(0); + firstInput?.style("text-input-block-input--first"); + firstInput?.previousSibling?.remove(); // remove previous divider if it exists + inputs.at(-1)?.style("text-input-block-input--last"); + inputs.at(-1)?.parent?.style("text-input-block-input-wrapper--last"); + }) + .appendTo((0, Component_24.default)() + .style("text-input-block-input-wrapper") + .appendTo(block)); + if (!inputs.length) + input.style("text-input-block-input--first"); + inputs.at(-1)?.style.remove("text-input-block-input--last"); + inputs.at(-1)?.parent?.style.remove("text-input-block-input-wrapper--last"); + inputs.push(input); + input.style("text-input-block-input--last"); + input.parent?.style("text-input-block-input-wrapper--last"); + return block; + }, + })); + return block; + }); + exports.default = TextInputBlock; +}); +define("ui/component/core/LabelledTextInputBlock", ["require", "exports", "ui/Component", "ui/component/core/Label", "ui/component/core/TextInputBlock"], function (require, exports, Component_25, Label_2, TextInputBlock_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_25 = __importDefault(Component_25); + TextInputBlock_1 = __importDefault(TextInputBlock_1); + const LabelledTextInputBlock = Component_25.default.Builder((block) => { + block.style("labelled-text-input-block", "labelled-row") + .ariaRole("group"); + const labels = (0, Component_25.default)() + .style("labelled-text-input-block-labels") + .appendTo(block); + const inputs = (0, TextInputBlock_1.default)() + .style("labelled-text-input-block-inputs") + .appendTo(block); + let labelInitialiser; + let factory; + return block.extend(block => ({ + labels, + inputs, + label: initialiser => { + labelInitialiser = initialiser; + return factory ??= { + input: inputInitialiser => { + const rowNumber = inputs.inputs.length + 1; + const label = (0, Label_2.AutoLabel)() + .style("labelled-text-input-block-label") + .style.setProperty("grid-row", `${rowNumber}`) + .appendTo(labels); + labelInitialiser(label); + inputs.addInput(input => input + .style("labelled-text-input-block-input") + .style.setProperty("grid-row", `${rowNumber}`) + .tweak(input => inputInitialiser(input.setLabel(label), label))); + labelInitialiser = undefined; + return block; + }, + }; + }, + })); + }); + exports.default = LabelledTextInputBlock; +}); +define("ui/Announcer", ["require", "exports", "ui/Component"], function (require, exports, Component_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_26 = __importDefault(Component_26); + var Announcer; + (function (Announcer) { + const assertive = (0, Component_26.default)() + .attributes.set("aria-live", "assertive") + .style.setProperty("opacity", "0") + .style.setProperty("user-select", "none") + .style.setProperty("pointer-events", "none") + .style.setProperty("position", "fixed") + .appendTo(document.body); + const polite = (0, Component_26.default)() + .attributes.set("aria-live", "polite") + .style.setProperty("opacity", "0") + .style.setProperty("user-select", "none") + .style.setProperty("pointer-events", "none") + .style.setProperty("position", "fixed") + .appendTo(document.body); + function interrupt(id, announcer) { + announceInternal(assertive, id, announcer); + } + Announcer.interrupt = interrupt; + function announce(id, announcer) { + announceInternal(polite, id, announcer); + } + Announcer.announce = announce; + function announceInternal(within, id, announcer) { + const components = []; + announcer(keyOrHandler => { + components.push((0, Component_26.default)("p") + .attributes.set("data-id", id) + .text.use(keyOrHandler)); + }); + const current = getAnnouncementElements(within, id); + if (current.length) { + const currentText = current.map(el => el.textContent).join("\n"); + const newText = components.map(component => component.element.textContent).join("\n"); + if (newText === currentText) + return; + for (const element of current) + element.remove(); + } + for (const component of components) + component.appendTo(within); + } + function getAnnouncementElements(within, id) { + return [ + ...within.element.querySelectorAll(`[data-id="${id}"]`), + ]; + } + })(Announcer || (Announcer = {})); + exports.default = Announcer; +}); +define("ui/component/core/RadioButton", ["require", "exports", "ui/Component", "ui/component/core/Checkbutton"], function (require, exports, Component_27, Checkbutton_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_27 = __importDefault(Component_27); + Checkbutton_2 = __importDefault(Checkbutton_2); + exports.default = Component_27.default.Builder(() => { + const cb = (0, Checkbutton_2.default)(); + cb.ariaRole("radio"); + cb.input.attributes.set("type", "radio"); + return cb; + }); +}); +define("ui/view/shared/ext/ViewTransition", ["require", "exports", "ui/Component", "utility/Arrays"], function (require, exports, Component_28, Arrays_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_28 = __importDefault(Component_28); + Arrays_3 = __importDefault(Arrays_3); + var ViewTransition; + (function (ViewTransition) { + const DATA_VIEW_TRANSITION_NAME = "data-view-transition-name"; + const DATA_SUBVIEW_TRANSITION_NAME = "data-subview-transition-name"; + const DATA_ID = "data-view-transition-id"; + const VIEW_TRANSITION_CLASS_VIEW = "view-transition"; + const VIEW_TRANSITION_CLASS_SUBVIEW = "subview-transition"; + const VIEW_TRANSITION_CLASS_DELAY = "view-transition-delay"; + const PADDING = 100; + Component_28.default.extend(component => component.extend(component => ({ + viewTransition(name) { + if (name) { + name = name.replace(/[^a-z0-9-]+/g, "-").toLowerCase(); + component.attributes.set(DATA_VIEW_TRANSITION_NAME, name); + component.attributes.compute(DATA_ID, () => `${id++}`); + } + else { + component.attributes.remove(DATA_VIEW_TRANSITION_NAME); + component.attributes.remove(DATA_ID); + } + return component; + }, + subviewTransition(name) { + if (name) { + name = name.replace(/[^a-z0-9-]+/g, "-").toLowerCase(); + component.attributes.set(DATA_SUBVIEW_TRANSITION_NAME, name); + component.attributes.compute(DATA_ID, () => `${id++}`); + } + else { + component.attributes.remove(DATA_SUBVIEW_TRANSITION_NAME); + component.attributes.remove(DATA_ID); + } + return component; + }, + }))); + let id = 0; + let i = 0; + let queuedUnapply; + function perform(type, name, swap) { + queuedUnapply = undefined; + if (typeof name === "function") { + swap = name; + name = undefined; + } + reapply(type, name); + const transition = document.startViewTransition(async () => { + await swap(); + reapply(type, name); + }); + const id = queuedUnapply = i++; + void transition.finished.then(() => { + if (queuedUnapply !== id) + // another view transition started, no unapply + return; + unapply(type); + }); + return transition; + } + ViewTransition.perform = perform; + function reapply(type, name) { + const components = getComponents(type, name).filter(isInView); + let i = 0; + if (type === "view") + for (const component of components) { + component.classes.add(VIEW_TRANSITION_CLASS_VIEW); + const name = component.attributes.get(DATA_VIEW_TRANSITION_NAME); + component.style.setVariable("view-transition-delay", `${VIEW_TRANSITION_CLASS_DELAY}-${i}`); + component.style.setProperty("view-transition-name", `${VIEW_TRANSITION_CLASS_VIEW}-${name}-${i++}`); + } + else + for (const component of components) { + component.classes.add(VIEW_TRANSITION_CLASS_SUBVIEW); + const name = component.attributes.get(DATA_SUBVIEW_TRANSITION_NAME); + const id = +component.attributes.get(DATA_ID) || 0; + component.style.setProperty("view-transition-name", `${VIEW_TRANSITION_CLASS_SUBVIEW}-${name}-${id}`); + component.style.setVariable("view-transition-delay", `${VIEW_TRANSITION_CLASS_DELAY}-${i++}`); + } + } + ViewTransition.reapply = reapply; + function unapply(type) { + for (const component of getComponents(type)) { + component.classes.remove(VIEW_TRANSITION_CLASS_VIEW); + component.classes.remove(VIEW_TRANSITION_CLASS_SUBVIEW); + component.style.removeProperties("view-transition-name"); + component.style.removeVariables("view-transition-delay"); + } + } + ViewTransition.unapply = unapply; + function isInView(component) { + const rect = component.element.getBoundingClientRect(); + return true + && rect.bottom > -PADDING && rect.top < window.innerHeight + PADDING + && rect.right > -PADDING && rect.left < window.innerWidth + PADDING; + } + function getComponents(type, name) { + return [...document.querySelectorAll(`[${type === "view" ? DATA_VIEW_TRANSITION_NAME : DATA_SUBVIEW_TRANSITION_NAME}${name ? `="${name}"` : ""}]`)] + .map(e => e.component) + .filter(Arrays_3.default.filterNullish); + } + })(ViewTransition || (ViewTransition = {})); + exports.default = ViewTransition; +}); +define("ui/component/core/TextEditor", ["require", "exports", "lang/en-nz", "markdown-it", "model/Session", "prosemirror-commands", "prosemirror-dropcursor", "prosemirror-example-setup", "prosemirror-gapcursor", "prosemirror-history", "prosemirror-inputrules", "prosemirror-keymap", "prosemirror-markdown", "prosemirror-model", "prosemirror-schema-list", "prosemirror-state", "prosemirror-transform", "prosemirror-view", "ui/Announcer", "ui/Component", "ui/component/core/Button", "ui/component/core/Checkbutton", "ui/component/core/Dialog", "ui/component/core/ext/Input", "ui/component/core/Popover", "ui/component/core/RadioButton", "ui/component/core/Slot", "ui/utility/StringApplicator", "ui/utility/Viewport", "ui/view/shared/ext/ViewTransition", "utility/Arrays", "utility/Define", "utility/Objects", "utility/State", "utility/Store", "utility/string/MarkdownItHTML", "utility/Time", "w3c-keyname"], function (require, exports, en_nz_3, markdown_it_2, Session_4, prosemirror_commands_1, prosemirror_dropcursor_1, prosemirror_example_setup_1, prosemirror_gapcursor_1, prosemirror_history_1, prosemirror_inputrules_1, prosemirror_keymap_1, prosemirror_markdown_1, prosemirror_model_1, prosemirror_schema_list_1, prosemirror_state_1, prosemirror_transform_1, prosemirror_view_1, Announcer_1, Component_29, Button_5, Checkbutton_3, Dialog_2, Input_2, Popover_2, RadioButton_1, Slot_2, StringApplicator_6, Viewport_3, ViewTransition_1, Arrays_4, Define_4, Objects_3, State_20, Store_3, MarkdownItHTML_2, Time_5, w3c_keyname_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_3 = __importDefault(en_nz_3); + markdown_it_2 = __importDefault(markdown_it_2); + Session_4 = __importDefault(Session_4); + Announcer_1 = __importDefault(Announcer_1); + Component_29 = __importDefault(Component_29); + Button_5 = __importDefault(Button_5); + Checkbutton_3 = __importDefault(Checkbutton_3); + Dialog_2 = __importDefault(Dialog_2); + Input_2 = __importDefault(Input_2); + Popover_2 = __importDefault(Popover_2); + RadioButton_1 = __importDefault(RadioButton_1); + Slot_2 = __importDefault(Slot_2); + StringApplicator_6 = __importDefault(StringApplicator_6); + Viewport_3 = __importDefault(Viewport_3); + ViewTransition_1 = __importDefault(ViewTransition_1); + Arrays_4 = __importDefault(Arrays_4); + Define_4 = __importDefault(Define_4); + Objects_3 = __importDefault(Objects_3); + State_20 = __importDefault(State_20); + Store_3 = __importDefault(Store_3); + MarkdownItHTML_2 = __importDefault(MarkdownItHTML_2); + Time_5 = __importDefault(Time_5); + w3c_keyname_1 = __importDefault(w3c_keyname_1); + function vars(...params) { } + function types() { } + //////////////////////////////////// + //#region Module Augmentation + const baseKeyName = w3c_keyname_1.default.keyName; + w3c_keyname_1.default.keyName = (event) => { + const keyboardEvent = event; + if (keyboardEvent.code.startsWith("Numpad") && !keyboardEvent.shiftKey && (keyboardEvent.ctrlKey || keyboardEvent.altKey)) { + Object.defineProperty(event, "shiftKey", { value: true }); + const str = keyboardEvent.code.slice(6); + if (str === "Decimal") + return "."; + if (!isNaN(+str)) + return str; + } + return baseKeyName(event); + }; + (0, Define_4.default)(prosemirror_model_1.ResolvedPos.prototype, "closest", function (node, attrsOrStartingAtDepth, startingAtDepth) { + if (typeof attrsOrStartingAtDepth === "number") { + startingAtDepth = attrsOrStartingAtDepth; + attrsOrStartingAtDepth = undefined; + } + const attrs = attrsOrStartingAtDepth; + startingAtDepth ??= this.depth; + for (let depth = startingAtDepth; depth >= 0; depth--) { + const current = this.node(depth); + if (current.type === node && (!attrs || current.hasAttrs(attrs))) + return current; + } + return undefined; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "matches", function (type, attrs) { + if (type !== undefined && this.type !== type) + return false; + return attrs === undefined || this.hasAttrs(attrs); + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "hasAttrs", function (attrs) { + for (const [attr, val] of Object.entries(attrs)) + if (this.attrs[attr] !== val) + return false; + return true; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "pos", function (document) { + if (document === this) + return 0; + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node === this) { + result = pos; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "parent", function (document) { + if (document === this) + return undefined; + // eslint-disable-next-line @typescript-eslint/no-this-alias + const searchNode = this; + return searchChildren(document); + function searchChildren(parent) { + let result; + parent.forEach(child => { + result ??= (child === searchNode ? parent : undefined) + ?? searchChildren(child); + }); + return result; + } + }); + (0, Define_4.default)(prosemirror_model_1.Node.prototype, "depth", function (document) { + if (document === this) + return 0; + // eslint-disable-next-line @typescript-eslint/no-this-alias + const searchNode = this; + return searchChildren(document, 1); + function searchChildren(parent, depth) { + let result; + parent.forEach(child => { + result ??= (child === searchNode ? depth : undefined) + ?? searchChildren(child, depth + 1); + }); + return result; + } + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "pos", function (document) { + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node.content === this) { + result = pos + 1; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "range", function (document) { + const pos = this.pos(document); + if (!pos) + return undefined; + const $from = document.resolve(pos); + const $to = document.resolve(pos + this.size); + return new prosemirror_model_1.NodeRange($from, $to, Math.min($from.depth, $to.depth)); + }); + (0, Define_4.default)(prosemirror_model_1.Fragment.prototype, "parent", function (document) { + if (document.content === this) + return document; + let result; + document.descendants((node, pos) => { + if (result !== undefined) + return false; + if (node.content === this) { + result = node; + return false; + } + }); + return result; + }); + (0, Define_4.default)(prosemirror_transform_1.Transform.prototype, "stripNodeType", function (from, type) { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const tr = this; + let range = from instanceof prosemirror_model_1.Fragment ? from.range(tr.doc) : from; + if (!range) + return this; + while (stripRange()) + ; + return this; + function stripRange() { + let stripped = false; + range.parent.forEach((node, pos, index) => { + if (stripped) + return; + if (index >= range.startIndex && index < range.endIndex) { + if (node.type === type) { + stripNode(node); + stripped = true; + return; + } + if (stripDescendants(node)) { + stripped = true; + return; + } + } + }); + return stripped; + } + function stripDescendants(node) { + let stripped = false; + node.descendants((node, pos) => { + if (stripped) + return; + if (node.type === type) { + stripNode(node); + stripped = true; + return; + } + }); + return stripped; + } + function stripNode(node) { + const nodePos = node.pos(tr.doc); + if (nodePos === undefined) + throw new Error("Unable to continue stripping, no pos"); + const liftRange = node.content.range(tr.doc); + if (!liftRange) + throw new Error("Unable to continue stripping, unable to resolve node range"); + const depth = (0, prosemirror_transform_1.liftTarget)(liftRange); + if (depth !== null) + tr.lift(liftRange, depth); + if (range) { + let start = range.$from.pos; + start = start <= nodePos ? start : start - 1; + let end = range.$to.pos; + end = end < nodePos + node.nodeSize ? end - 1 : end - 2; + const newRange = tr.doc.resolve(start).blockRange(tr.doc.resolve(end)); + if (!newRange) + throw new Error("Unable to continue stripping, unable to resolve new range"); + range = newRange; + } + } + }); + //#endregion + types(); + Session_4.default.setClearedWithSessionChange("textEditorDrafts"); + //#endregion + vars(w3c_keyname_1.default.keyName); + types(); + types(); + const schema = new prosemirror_model_1.Schema({ + nodes: Objects_3.default.filterNullish({ + ...prosemirror_markdown_1.schema.spec.nodes.toObject(), + image: undefined, + heading: { + ...prosemirror_markdown_1.schema.spec.nodes.get("heading"), + content: "text*", + toDOM(node) { + const heading = (0, Component_29.default)(`h${node.attrs.level}`); + heading.style("markdown-heading", `markdown-heading-${node.attrs.level}`); + return { + dom: heading.element, + contentDOM: heading.element, + }; + }, + }, + text_align: { + attrs: { align: { default: "left", validate: (value) => value === "left" || value === "center" || value === "right" } }, + content: "block+", + group: "block", + defining: true, + parseDOM: [ + { tag: "center", getAttrs: () => ({ align: "center" }) }, + { + tag: "*", getAttrs: (element) => { + const textAlign = element.style.getPropertyValue("text-align"); + if (!textAlign) + return false; + return { + align: textAlign === "justify" || textAlign === "start" ? "left" + : textAlign === "end" ? "right" + : textAlign, + }; + }, + priority: 51, + }, + ], + toDOM: (node) => ["div", Objects_3.default.filterNullish({ + "class": node.attrs.align === "left" ? "align-left" : undefined, + "style": `text-align:${node.attrs.align}`, + }), 0], + }, + }), + marks: { + ...prosemirror_markdown_1.schema.spec.marks.toObject(), + underline: { + parseDOM: [ + { tag: "u" }, + { style: "text-decoration=underline", clearMark: m => m.type.name === "underline" }, + ], + toDOM() { return ["u"]; }, + }, + strikethrough: { + parseDOM: [ + { tag: "s" }, + { style: "text-decoration=line-through", clearMark: m => m.type.name === "strikethrough" }, + ], + // toDOM () { return ["s"] }, + toDOM() { + const span = document.createElement("span"); + span.style.setProperty("text-decoration", "line-through"); + return span; + }, + }, + subscript: { + parseDOM: [ + { tag: "sub" }, + ], + toDOM() { return ["sub"]; }, + }, + superscript: { + parseDOM: [ + { tag: "sup" }, + ], + toDOM() { return ["sup"]; }, + }, + }, + }); + //#endregion + vars(schema); + types(); + //////////////////////////////////// + //////////////////////////////////// + //#region Markdown + const REGEX_ATTRIBUTE = (() => { + const attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*"; + const unquoted = "[^\"'=<>`\\x00-\\x20]+"; + const single_quoted = "'[^']*'"; + const double_quoted = '"[^"]*"'; + const attr_value = `(?:${unquoted}|${single_quoted}|${double_quoted})`; + const attribute = `(${attr_name})(?:\\s*=\\s*(${attr_value}))(?= |$)`; + return new RegExp(attribute, "g"); + })(); + const REGEX_CSS_PROPERTY = /^[-a-zA-Z_][a-zA-Z0-9_-]*$/; + const markdown = new markdown_it_2.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_2.default.use(markdown, MarkdownItHTML_2.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + markdown.inline.ruler.enable("strikethrough"); + markdown.inline.ruler2.enable("strikethrough"); + //////////////////////////////////// + //#region Underline Parse + // Based on https://github.com/markdown-it/markdown-it/blob/0fe7ccb4b7f30236fb05f623be6924961d296d3d/lib/rules_inline/strikethrough.mjs + markdown.inline.ruler.before("emphasis", "underline", function underline_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent || marker !== 0x5F /* _ */) + return false; + const scanned = state.scanDelims(state.pos, true); + let len = scanned.length; + if (len < 2) + return false; + const ch = String.fromCharCode(marker); + let token; + if (len % 2) { + token = state.push("text", "", 0); + token.content = ch; + len--; + } + for (let i = 0; i < len; i += 2) { + token = state.push("text", "", 0); + token.content = ch + ch; + state.delimiters.push({ + marker, + length: 0, // disable "rule of 3" length checks meant for emphasis + token: state.tokens.length - 1, + end: -1, + open: scanned.can_open, + close: scanned.can_close, + }); + } + state.pos += scanned.length; + return true; + }); + markdown.inline.ruler2.before("emphasis", "underline", function underline_postProcess(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + const delimiters = tokens_meta[curr]?.delimiters; + if (delimiters) + postProcess(state, delimiters); + } + state.delimiters = state.delimiters.filter(delim => delim.marker !== 0x5F /* _ */); + return true; + function postProcess(state, delimiters) { + let token; + const loneMarkers = []; + const max = delimiters.length; + for (let i = 0; i < max; i++) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x5F /* _ */) + continue; + if (startDelim.end === -1) + continue; + const endDelim = delimiters[startDelim.end]; + token = state.tokens[startDelim.token]; + token.type = "u_open"; + token.tag = "u"; + token.nesting = 1; + token.markup = "__"; + token.content = ""; + token = state.tokens[endDelim.token]; + token.type = "u_close"; + token.tag = "u"; + token.nesting = -1; + token.markup = "__"; + token.content = ""; + if (state.tokens[endDelim.token - 1].type === "text" && + state.tokens[endDelim.token - 1].content === "_") { + loneMarkers.push(endDelim.token - 1); + } + } + // If a marker sequence has an odd number of characters, it's splitted + // like this: `_____` -> `_` + `__` + `__`, leaving one marker at the + // start of the sequence. + // + // So, we have to move all those markers after subsequent u_close tags. + // + while (loneMarkers.length) { + const i = loneMarkers.pop() ?? 0; + let j = i + 1; + while (j < state.tokens.length && state.tokens[j].type === "u_close") { + j++; + } + j--; + if (i !== j) { + token = state.tokens[j]; + state.tokens[j] = state.tokens[i]; + state.tokens[i] = token; + } + } + } + }); + const markdownHTMLNodeRegistry = { + text_align: { + getAttrs: token => { + const align = token.style?.get("text-align"); + if (!["left", "center", "right"].includes(align)) + return undefined; + return { align }; + }, + }, + }; + const originalParse = markdown.parse; + markdown.parse = (src, env) => { + const rawTokens = originalParse.call(markdown, src, env); + const tokens = []; + // the `level` of the parent `_open` token + let level = 0; + for (const token of rawTokens) { + if (token.type !== "html_block_open" && token.type !== "html_block_close") { + tokens.push(token); + continue; + } + if (token.nesting < 0) { + const opening = tokens.findLast(token => token.level === level); + if (!opening) { + console.warn("Invalid HTML in markdown:", token.raw); + continue; + } + token.type = `${opening.type.slice(0, -5)}_close`; + tokens.push(token); + level = token.level; + continue; + } + for (const [nodeType, spec] of Object.entries(markdownHTMLNodeRegistry)) { + const attrs = spec.getAttrs(token); + if (attrs) { + token.type = nodeType; + if (attrs !== true) + token.nodeAttrs = attrs; + break; + } + } + token.type = `${token.type}_open`; + level = token.level; + tokens.push(token); + } + return tokens; + }; + const markdownParser = new prosemirror_markdown_1.MarkdownParser(schema, markdown, Objects_3.default.filterNullish({ + ...prosemirror_markdown_1.defaultMarkdownParser.tokens, + image: undefined, + u: { + mark: "underline", + }, + s: { + mark: "strikethrough", + }, + ...Object.entries(markdownHTMLNodeRegistry) + .toObject(([tokenType, spec]) => [tokenType, { + block: tokenType, + getAttrs: token => token.nodeAttrs ?? {}, + }]), + })); + const markdownSerializer = new prosemirror_markdown_1.MarkdownSerializer({ + ...prosemirror_markdown_1.defaultMarkdownSerializer.nodes, + text_align: (state, node, parent, index) => { + state.write(`
\n`); + state.renderContent(node); + state.write("
"); + state.closeBlock(node); + }, + }, { + ...prosemirror_markdown_1.defaultMarkdownSerializer.marks, + strikethrough: { + open: "~~", + close: "~~", + expelEnclosingWhitespace: true, + }, + underline: { + open: "__", + close: "__", + expelEnclosingWhitespace: true, + }, + }); + function parseStyleAttributeValue(style) { + if (style === undefined || style === null) + return undefined; + const styles = new Map(); + let key = ""; + let value = ""; + let inValue = false; + let isEscaped = false; + let isQuoted = false; + let quoteChar = ""; + let parenCount = 0; + for (let i = 0; i < style.length; i++) { + const char = style[i]; + if (char === "\\") { + isEscaped = true; + continue; + } + if (isEscaped) { + value += char; + isEscaped = false; + continue; + } + if ((char === '"' || char === "'") && !isQuoted) { + isQuoted = true; + quoteChar = char; + continue; + } + if (char === quoteChar && isQuoted) { + isQuoted = false; + continue; + } + if (char === "(" && !isQuoted) { + parenCount++; + value += char; + continue; + } + if (char === ")" && !isQuoted) { + parenCount--; + value += char; + continue; + } + if (char === ":" && !isQuoted && parenCount === 0) { + inValue = true; + continue; + } + if (char === ";" && !isQuoted && parenCount === 0) { + if (key && value) { + key = key.trim(); + if (!REGEX_CSS_PROPERTY.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + key = ""; + value = ""; + } + inValue = false; + continue; + } + if (inValue) { + value += char; + } + else { + key += char; + } + } + if (key && value) { + key = key.trim(); + if (!REGEX_CSS_PROPERTY.test(key)) + console.warn(`Invalid CSS property "${key}"`); + else + styles.set(key, value.trim()); + } + return styles; + } + //#endregion + vars(REGEX_ATTRIBUTE, REGEX_CSS_PROPERTY, markdownParser, markdownSerializer, parseStyleAttributeValue); + //////////////////////////////////// + const BLOCK_TYPES = [ + "paragraph", + "code_block", + ]; + let globalid = 0; + const TextEditor = Component_29.default.Builder((component) => { + const id = globalid++; + const isMarkdown = (0, State_20.default)(false); + const content = (0, State_20.default)(""); + const isFullscreen = (0, State_20.default)(false); + // eslint-disable-next-line prefer-const + let editor; + const state = (0, State_20.default)(undefined); + //////////////////////////////////// + //#region Announcements + state.subscribe(component, () => { + if (!editor.mirror?.hasFocus() || !editor.mirror.state.selection.empty) + return; + const pos = editor.mirror.state.selection.from + 1; + const $pos = editor.mirror.state.doc.resolve(pos > editor.mirror.state.doc.content.size ? pos - 1 : pos); + Announcer_1.default.interrupt("text-editor/format/inline", announce => { + const markTypes = Object.keys(schema.marks); + let hadActive = false; + for (const type of markTypes) { + if (!isMarkActive(schema.marks[type], $pos)) + continue; + hadActive = true; + announce(`component/text-editor/formatting/${type}`); + } + if (!hadActive) + announce("component/text-editor/formatting/none"); + }); + }); + //////////////////////////////////// + //#region Types + const ToolbarButtonTypeMark = Component_29.default.Extension((component, type) => { + const mark = schema.marks[type]; + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`) + .extend(() => ({ mark })); + }); + const ToolbarButtonTypeNode = Component_29.default.Extension((component, type) => { + const node = schema.nodes[type.replaceAll("-", "_")]; + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`) + .extend(() => ({ node })); + }); + const ToolbarButtonTypeOther = Component_29.default.Extension((component, type) => { + return component + .style(`text-editor-toolbar-${type}`) + .ariaLabel.use(`component/text-editor/toolbar/button/${type}`); + }); + //#endregion + vars(ToolbarButtonTypeMark, ToolbarButtonTypeNode, ToolbarButtonTypeOther); + //////////////////////////////////// + //////////////////////////////////// + //#region Components + const ToolbarButtonGroup = Component_29.default.Builder(component => component + .ariaRole("group") + .style("text-editor-toolbar-button-group")); + const ToolbarButton = Component_29.default.Builder((_, handler) => { + return (0, Button_5.default)() + .style("text-editor-toolbar-button") + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + handler(event.component); + }); + }); + const ToolbarCheckbutton = Component_29.default.Builder((_, state, toggler) => { + return (0, Checkbutton_3.default)() + .style("text-editor-toolbar-button") + .style.bind(state, "text-editor-toolbar-button--enabled") + .use(state) + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + toggler(event.component); + }); + }); + const ToolbarRadioButton = Component_29.default.Builder((_, name, state, toggler) => { + return (0, RadioButton_1.default)() + .style("text-editor-toolbar-button") + .setName(name) + .style.bind(state, "text-editor-toolbar-button--enabled") + .use(state) + .clearPopover() + .receiveFocusedClickEvents() + .event.subscribe("click", event => { + event.preventDefault(); + toggler(event.component); + }); + }); + const ToolbarButtonPopover = Component_29.default.Builder((_, align) => { + return (0, Button_5.default)() + .style("text-editor-toolbar-button", "text-editor-toolbar-button--has-popover") + .clearPopover() + .setPopover("hover", (popover, button) => { + popover + .style("text-editor-toolbar-popover") + .style.bind(popover.popoverParent.nonNullish, "text-editor-toolbar-popover-sub", `text-editor-toolbar-popover-sub--${align}`) + .anchor.add(align === "centre" ? align : `aligned ${align}`, "off bottom") + .style.toggle(align === "left", "text-editor-toolbar-popover--left") + .style.toggle(align === "right", "text-editor-toolbar-popover--right") + .setMousePadding(20); + button.style.bind(popover.visible, "text-editor-toolbar-button--has-popover-visible"); + }) + .receiveAncestorInsertEvents() + .event.subscribe(["insert", "ancestorInsert"], event => event.component.style.toggle(!!event.component.closest(Popover_2.default), "text-editor-toolbar-button--has-popover--within-popover")); + }); + //#endregion + vars(ToolbarButtonGroup, ToolbarButton, ToolbarCheckbutton, ToolbarRadioButton, ToolbarButtonPopover); + //////////////////////////////////// + //////////////////////////////////// + //#region Specifics + const ToolbarButtonMark = Component_29.default.Builder((_, type) => { + const mark = schema.marks[type]; + const toggler = markToggler(mark); + const markActive = state.map(component, state => isMarkActive(mark)); + return ToolbarCheckbutton(markActive, toggler) + .and(ToolbarButtonTypeMark, type); + }); + const ToolbarButtonAlign = Component_29.default.Builder((_, align) => { + const toggler = wrapper(schema.nodes.text_align, { align: align === "centre" ? "center" : align }); + const alignActive = state.map(component, state => isAlignActive(align)); + return ToolbarRadioButton(`text-editor-${id}-text-align`, alignActive, toggler) + .and(ToolbarButtonTypeOther, `align-${align}`); + }); + const ToolbarButtonBlockType = Component_29.default.Builder((_, type) => { + const node = schema.nodes[type.replaceAll("-", "_")]; + const toggle = blockTypeToggler(node); + const typeActive = state.map(component, state => isTypeActive(node)); + return ToolbarRadioButton(`text-editor-${id}-block-type`, typeActive, toggle) + .and(ToolbarButtonTypeNode, type); + }); + const ToolbarButtonHeading = Component_29.default.Builder((_, level) => { + const node = schema.nodes.heading; + const toggle = blockTypeToggler(node, { level }); + const typeActive = state.map(component, state => isTypeActive(node, { level })); + return ToolbarRadioButton(`text-editor-${id}-block-type`, typeActive, toggle) + .style(`text-editor-toolbar-h${level}`); + }); + const ToolbarButtonWrap = Component_29.default.Builder((_, type) => ToolbarButton(wrapper(schema.nodes[type.replaceAll("-", "_")])) + .and(ToolbarButtonTypeNode, type)); + const ToolbarButtonList = Component_29.default.Builder((_, type) => ToolbarButton(listWrapper(schema.nodes[type.replaceAll("-", "_")])) + .and(ToolbarButtonTypeNode, type)); + //#endregion + vars(ToolbarButtonMark, ToolbarButtonAlign, ToolbarButtonBlockType, ToolbarButtonHeading, ToolbarButtonWrap, ToolbarButtonList); + types(); + //////////////////////////////////// + //////////////////////////////////// + //#region Commands + let inTransaction = false; + function wrapCmd(cmd) { + return (component) => { + if (!state.value) + return; + inTransaction = true; + cmd(state.value, editor.mirror?.dispatch, editor.mirror); + inTransaction = false; + if (!component.hasFocused.value) + editor.document?.focus(); + }; + } + function markToggler(type) { + return wrapCmd((0, prosemirror_commands_1.toggleMark)(type)); + } + function wrapper(node, attrs) { + if (node === schema.nodes.text_align) + return wrapCmd((state, dispatch) => { + const { $from, $to } = state.selection; + let range = $from.blockRange($to); + if (range) { + const textAlignBlock = $from.closest(schema.nodes.text_align, range.depth); + if (textAlignBlock && !range.startIndex && range.endIndex === textAlignBlock.childCount) { + const pos = textAlignBlock.pos(state.doc); + if (pos === undefined) + return false; + if (dispatch) + dispatch(state.tr + .setNodeMarkup(pos, undefined, attrs) + .stripNodeType(textAlignBlock.content, schema.nodes.text_align) + .scrollIntoView()); + return true; + } + } + const wrapping = range && (0, prosemirror_transform_1.findWrapping)(range, node, attrs); + if (!wrapping) + return false; + if (dispatch) { + const tr = state.tr; + tr.wrap(range, wrapping); + range = tr.doc.resolve($from.pos + 1).blockRange(tr.doc.resolve($to.pos + 1)); + if (!range) + throw new Error("Unable to strip nodes, unable to resolve new range"); + tr.stripNodeType(range, schema.nodes.text_align); + tr.scrollIntoView(); + dispatch(tr); + } + return true; + }); + return wrapCmd((0, prosemirror_commands_1.wrapIn)(node, attrs)); + } + function blockTypeToggler(node, attrs) { + return wrapCmd((0, prosemirror_commands_1.setBlockType)(node, attrs)); + } + function listWrapper(node, attrs) { + return wrapCmd((0, prosemirror_schema_list_1.wrapInList)(node, attrs)); + } + //#endregion + vars(wrapCmd, markToggler, wrapper, blockTypeToggler, listWrapper); + //////////////////////////////////// + //#endregion + vars(ToolbarButtonTypeMark, ToolbarButtonTypeNode, ToolbarButtonTypeOther); + vars(ToolbarButtonGroup, ToolbarButton, ToolbarCheckbutton, ToolbarRadioButton, ToolbarButtonPopover); + vars(ToolbarButtonMark, ToolbarButtonAlign, ToolbarButtonBlockType, ToolbarButtonHeading, ToolbarButtonWrap, ToolbarButtonList); + types(); + //////////////////////////////////// + const toolbar = (0, Component_29.default)() + .style("text-editor-toolbar") + .style.bind(isFullscreen, "text-editor-toolbar--fullscreen") + .ariaRole("toolbar") + .append((0, Component_29.default)() + .style("text-editor-toolbar-left") + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/inline") + .append(ToolbarButtonMark("strong")) + .append(ToolbarButtonMark("em")) + .append(ToolbarButtonPopover("left") + .and(ToolbarButtonTypeOther, "other-formatting") + .tweakPopover(popover => popover + .append(ToolbarButtonMark("underline")) + .append(ToolbarButtonMark("strikethrough")) + .append(ToolbarButtonMark("subscript")) + .append(ToolbarButtonMark("superscript")) + .append(ToolbarButtonMark("code"))))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/block") + .append(ToolbarButtonPopover("centre") + .tweakPopover(popover => popover + .ariaRole("radiogroup") + .append(ToolbarButtonAlign("left")) + .append(ToolbarButtonAlign("centre")) + .append(ToolbarButtonAlign("right"))) + .tweak(button => { + state.use(button, () => { + const align = !editor?.mirror?.hasFocus() && !inTransaction ? "left" : getAlign() ?? "mixed"; + button.ariaLabel.set(en_nz_3.default["component/text-editor/toolbar/button/align"](en_nz_3.default[`component/text-editor/toolbar/button/align/currently/${align}`]()).toString()); + button.style.remove("text-editor-toolbar-align-left", "text-editor-toolbar-align-centre", "text-editor-toolbar-align-right", "text-editor-toolbar-align-mixed"); + button.style(`text-editor-toolbar-align-${align}`); + }); + }))) + .append(ToolbarButtonGroup() + .ariaRole() + .append(ToolbarButtonPopover("centre") + .tweakPopover(popover => popover + .ariaRole("radiogroup") + .append(ToolbarButtonBlockType("paragraph")) + .append(ToolbarButtonPopover("centre") + .style("text-editor-toolbar-heading") + .tweakPopover(popover => popover + .append(ToolbarButtonHeading(1)) + .append(ToolbarButtonHeading(2)) + .append(ToolbarButtonHeading(3)) + .append(ToolbarButtonHeading(4)) + .append(ToolbarButtonHeading(5)) + .append(ToolbarButtonHeading(6)))) + .append(ToolbarButtonBlockType("code-block"))) + .tweak(button => { + state.use(button, () => { + const blockType = !editor?.mirror?.hasFocus() && !inTransaction ? "paragraph" : getBlockType() ?? "mixed"; + button.ariaLabel.set(en_nz_3.default["component/text-editor/toolbar/button/block-type"](en_nz_3.default[`component/text-editor/toolbar/button/block-type/currently/${blockType}`]()).toString()); + button.style.remove("text-editor-toolbar-mixed", ...BLOCK_TYPES + .map(type => type.replaceAll("_", "-")) + .map(type => `text-editor-toolbar-${type}`)); + button.style(`text-editor-toolbar-${blockType}`); + }); + }))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/wrapper") + .append(ToolbarButton(wrapCmd(prosemirror_commands_1.lift)).and(ToolbarButtonTypeOther, "lift") + .style.bind(state.map(component, value => !value || !(0, prosemirror_commands_1.lift)(value)), "text-editor-toolbar-button--hidden")) + .append(ToolbarButtonWrap("blockquote")) + .append(ToolbarButtonList("bullet-list")) + .append(ToolbarButtonList("ordered-list"))) + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/insert") + .append(ToolbarButton(wrapCmd((state, dispatch) => { + dispatch?.(state.tr.replaceSelectionWith(schema.nodes.horizontal_rule.create())); + return true; + })) + .and(ToolbarButtonTypeOther, "hr")))) + .append((0, Component_29.default)() + .style("text-editor-toolbar-right") + .append(ToolbarButtonGroup() + .ariaLabel.use("component/text-editor/toolbar/group/actions") + .append(ToolbarButton(wrapCmd(prosemirror_history_1.undo)).and(ToolbarButtonTypeOther, "undo")) + .append(ToolbarButton(wrapCmd(prosemirror_history_1.redo)).and(ToolbarButtonTypeOther, "redo")) + .append(ToolbarButton(toggleFullscreen) + .style.bind(isFullscreen.not, "text-editor-toolbar-fullscreen") + .style.bind(isFullscreen, "text-editor-toolbar-unfullscreen") + .ariaLabel.bind(isFullscreen.map(component, fullscreen => en_nz_3.default[`component/text-editor/toolbar/button/${fullscreen ? "unfullscreen" : "fullscreen"}`]().toString()))))) + .appendTo(component); + //#endregion + vars(toolbar); + //////////////////////////////////// + //////////////////////////////////// + //#region Main UI + let label; + let unsubscribeLabelFor; + const stopUsingLabel = () => { + label?.event.unsubscribe("remove", stopUsingLabel); + label = undefined; + unsubscribeLabelFor?.(); + unsubscribeLabelFor = undefined; + }; + const viewTransitionName = "text-editor"; + const actualEditor = (0, Component_29.default)() + .subviewTransition(viewTransitionName) + .style("text-editor") + .style.bind(isFullscreen, "text-editor--fullscreen") + .event.subscribe("click", event => { + const target = Component_29.default.get(event.target); + if (target !== toolbar && !target?.is(TextEditor)) + return; + editor.document?.focus(); + }) + .append(toolbar); + editor = (0, Slot_2.default)() + .and(Input_2.default) + .append(actualEditor) + .extend(editor => ({ + default: (0, StringApplicator_6.default)(editor, value => loadFromMarkdown(value)), + toolbar, + setRequired(required = true) { + editor.style.toggle(required, "text-editor--required"); + editor.required.value = required; + refresh(); + return editor; + }, + setLabel(newLabel) { + label = newLabel; + label?.event.subscribe("remove", stopUsingLabel); + refresh(); + // the moment a name is assigned to the editor, attempt to replace the doc with a local draft (if it exists) + unsubscribeLabelFor = label?.for.use(editor, loadLocal); + return editor; + }, + useMarkdown: () => { + clearLocal(); + return !state.value ? "" : markdownSerializer.serialize(state.value?.doc); + }, + })); + const documentSlot = (0, Slot_2.default)() + .style.bind(isFullscreen, "text-editor-document-slot--fullscreen") + .use(isMarkdown, (slot, isMarkdown) => { + if (isMarkdown) { + state.value = undefined; + return; + } + return createDefaultView(slot); + }) + .appendTo(actualEditor); + const contentWidth = State_20.default.Generator(() => `${editor.document?.element.scrollWidth ?? 0}px`) + .observe(component, state, Viewport_3.default.size); + const scrollbarProxy = (0, Component_29.default)() + .style("text-editor-document-scrollbar-proxy") + .style.bind(isFullscreen, "text-editor-document-scrollbar-proxy--fullscreen") + .style.bind(contentWidth.map(component, () => (editor.document?.element.scrollWidth ?? 0) > (editor.document?.rect.value.width ?? 0)), "text-editor-document-scrollbar-proxy--visible") + .style.bindVariable("content-width", contentWidth) + .event.subscribe("scroll", () => editor.document?.element.scrollTo({ left: scrollbarProxy.element.scrollLeft, behavior: "instant" })) + .appendTo(actualEditor); + const fullscreenContentWidth = State_20.default.Generator(() => `${documentSlot.element.scrollWidth ?? 0}px`) + .observe(component, state, Viewport_3.default.size); + documentSlot.style.bindVariable("content-width", fullscreenContentWidth); + state.use(editor, state => { + saveLocal(undefined, state?.doc); + toolbar.rect.markDirty(); + }); + const fullscreenDialog = (0, Dialog_2.default)() + .and(Slot_2.default) + .style.remove("slot") + .setFullscreen() + .setOwner(editor) + .bind(isFullscreen) + .appendTo(document.body); + //#endregion + vars(editor, actualEditor, documentSlot, scrollbarProxy, fullscreenDialog); + //////////////////////////////////// + return editor; + //////////////////////////////////// + //#region ProseMirror Init + function markInputRule(regexp, markType, getAttrs = null, getContent) { + return new prosemirror_inputrules_1.InputRule(regexp, (state, match, start, end) => { + const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + const content = getContent instanceof Function ? getContent(match) : getContent; + const tr = state.tr; + tr.replaceWith(start, end, typeof content === "string" ? schema.text(content) : content); + const mark = markType.create(attrs); + tr.addMark(tr.mapping.map(start), tr.mapping.map(end), mark); + tr.removeStoredMark(mark); + return tr; + }); + } + function createDefaultView(slot) { + const view = new prosemirror_view_1.EditorView(slot.element, { + state: prosemirror_state_1.EditorState.create({ + doc: markdownParser.parse(content.value), + plugins: [ + (0, prosemirror_example_setup_1.buildInputRules)(schema), + (0, prosemirror_inputrules_1.inputRules)({ + rules: [ + markInputRule(/\*\*([^*]+?)\*\*/, schema.marks.strong, undefined, match => match[1]), + markInputRule(/__([^_]+?)__/, schema.marks.underline, undefined, match => match[1]), + markInputRule(/\/\/([^/]+?)\/\//, schema.marks.em, undefined, match => match[1]), + markInputRule(/`([^`]+?)`/, schema.marks.code, undefined, match => match[1]), + markInputRule(/\[(.+?)\]\(([^ ]+?)(?:[  ](?:\((.+?)\)|["'“”‘’](.+?)["'“”‘’]))?\)/, schema.marks.link, ([match, text, href, title1, title2]) => ({ href, title: title1 || title2 || undefined }), match => match[1]), + ], + }), + (0, prosemirror_keymap_1.keymap)((0, prosemirror_example_setup_1.buildKeymap)(schema, {})), + (0, prosemirror_keymap_1.keymap)(prosemirror_commands_1.baseKeymap), + (0, prosemirror_keymap_1.keymap)({ + "Mod-s": (0, prosemirror_commands_1.toggleMark)(schema.marks.strikethrough), + "Mod-S": (0, prosemirror_commands_1.toggleMark)(schema.marks.strikethrough), + "Mod-.": (0, prosemirror_commands_1.toggleMark)(schema.marks.superscript), + "Mod-,": (0, prosemirror_commands_1.toggleMark)(schema.marks.subscript), + "Alt-Ctrl-0": (0, prosemirror_commands_1.setBlockType)(schema.nodes.paragraph), + ...Arrays_4.default.range(1, 7) + .toObject(i => [`Alt-Ctrl-${i}`, (0, prosemirror_commands_1.setBlockType)(schema.nodes.heading, { level: i })]), + }), + (0, prosemirror_dropcursor_1.dropCursor)(), + (0, prosemirror_gapcursor_1.gapCursor)(), + (0, prosemirror_history_1.history)(), + new prosemirror_state_1.Plugin({ + view() { + return { + update(view, prevState) { + state.value = view.state; + if (state.value === prevState) + state.emit(); + }, + }; + }, + }), + ], + }), + }); + editor.mirror = view; + editor.document = (0, Component_29.default)() + .and(Input_2.default) + .replaceElement(editor.mirror.dom) + .ariaRole("textbox") + .classes.add("markdown") + .style("text-editor-document") + .style.bind(isFullscreen, "text-editor-document--fullscreen") + .setId(`text-editor-${id}`) + .attributes.set("aria-multiline", "true") + .event.subscribe("scroll", () => scrollbarProxy.element.scrollTo({ left: editor.document?.element.scrollLeft ?? 0, behavior: "instant" })); + toolbar.ariaControls(editor.document); + refresh(); + return () => { + content.value = markdownSerializer.serialize(view.state.doc); + editor.mirror = undefined; + editor.document = undefined; + refresh(); + view.destroy(); + }; + } + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region Events/Actions + function refresh() { + label?.setInput(editor.document); + editor.document?.setName(label?.for); + editor.document?.setId(label?.for); + label?.setId(label.for.map(component, v => `${v}-label`)); + toolbar.ariaLabelledBy(label); + editor.document?.ariaLabelledBy(label); + editor.document?.attributes.toggle(editor.required.value, "aria-required", "true"); + } + function toggleFullscreen() { + ViewTransition_1.default.perform("subview", viewTransitionName, () => { + isFullscreen.value = !isFullscreen.value; + actualEditor.appendTo(isFullscreen.value ? fullscreenDialog : editor); + actualEditor.rect.markDirty(); + }); + } + function clearLocal(name = editor.document?.name.value) { + if (!name) + return; + Store_3.default.items.textEditorDrafts = Store_3.default.items.textEditorDrafts?.filter(draft => draft.name !== name); + } + function loadFromMarkdown(markdown = "") { + // hack to fix it not redrawing when calling updateState now? + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + (editor.mirror?.docView).dirty = 2; // CONTENT_DIRTY + editor.mirror?.updateState(prosemirror_state_1.EditorState.create({ + plugins: editor.mirror.state.plugins.slice(), + doc: markdownParser.parse(markdown), + })); + } + function loadLocal(name = editor.document?.name.value) { + if (!name) + return; + const draft = Store_3.default.items.textEditorDrafts?.find(draft => draft.name === name); + if (!draft) + return; + loadFromMarkdown(draft.body); + } + function saveLocal(name = editor.document?.name.value, doc) { + if (!name) + return; + const body = !doc ? "" : markdownSerializer.serialize(doc); + editor.length.value = body.length; + if (body === editor.default.state.value) + return clearLocal(); + Store_3.default.items.textEditorDrafts = [ + ...!body ? [] : [{ name, body, created: Date.now() }], + ...(Store_3.default.items.textEditorDrafts ?? []) + .filter(draft => true + && draft.name !== name // keep old drafts that don't share names with the new draft + && Date.now() - draft.created < Time_5.default.days(1) // keep old drafts only if they were made in the last day + && true), + ] + // disallow more than 4 drafts due to localstorage limitations with using localStorage + // this won't be necessary when drafts are stored in indexeddb + .slice(0, 4); + } + //#endregion + //////////////////////////////////// + //////////////////////////////////// + //#region State + function isMarkActive(type, pos) { + if (!state.value) + return false; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return !!type.isInSet(state.value.storedMarks || pos.marks()); + return state.value.doc.rangeHasMark(selection.from, selection.to, type); + } + function isTypeActive(type, attrs, pos) { + if (!state.value) + return false; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return !!pos.closest(type, attrs); + let found = false; + state.value.doc.nodesBetween(selection.from, selection.to, node => { + found ||= node.matches(type, attrs); + }); + return found; + } + function getBlockType(pos) { + if (!state.value) + return undefined; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) { + for (const blockType of BLOCK_TYPES) + if (isTypeActive(schema.nodes[blockType], pos)) + return blockType.replaceAll("_", "-"); + return "paragraph"; + } + const types = new Set(); + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + if (node.type !== schema.nodes.text) + return; + const $pos = state.value?.doc.resolve(pos); + if (!$pos) + return; + for (const blockType of BLOCK_TYPES) + if (isTypeActive(schema.nodes[blockType], $pos)) { + types.add(blockType.replaceAll("_", "-")); + return; + } + }); + if (!types.size) + return getBlockType(selection.$from); + if (types.size > 1) + return undefined; + const [type] = types; + return type; + } + function isAlignActive(align, pos) { + if (!state.value) + return false; + align = align === "centre" ? "center" : align; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) + return (pos.closest(schema.nodes.text_align)?.attrs.align ?? "left") === align; + let found = false; + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + const resolved = state.value?.doc.resolve(pos); + found ||= !resolved ? align === "left" : isAlignActive(align, resolved); + }); + return found; + } + function getAlign(pos) { + if (!state.value) + return undefined; + const selection = state.value.selection; + pos ??= !selection.empty ? undefined : selection.$from; + if (pos) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const align = pos.closest(schema.nodes.text_align)?.attrs.align ?? "left"; + return align === "center" ? "centre" : align; + } + const aligns = new Set(); + state.value.doc.nodesBetween(selection.from, selection.to, (node, pos) => { + if (node.type === schema.nodes.text) { + const $pos = state.value?.doc.resolve(pos); + if ($pos) + aligns.add(getAlign($pos)); + } + }); + if (!aligns.size) + return getAlign(selection.$from); + if (aligns.size > 1) + return undefined; + const [align] = aligns; + return align; + } + //#endregion + //////////////////////////////////// + }); + exports.default = TextEditor; +}); +define("ui/component/core/toast/ToastList", ["require", "exports", "ui/Component", "utility/Async", "utility/Task", "utility/Time"], function (require, exports, Component_30, Async_2, Task_3, Time_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_30 = __importDefault(Component_30); + Async_2 = __importDefault(Async_2); + Task_3 = __importDefault(Task_3); + Time_6 = __importDefault(Time_6); + const ToastComponent = Component_30.default.Builder((component) => { + const title = (0, Component_30.default)() + .style("toast-title") + .appendTo(component); + return component + .style("toast") + .extend(toast => ({ + title, + content: undefined, + type: Object.assign((...types) => { + for (const type of types) + toast.style(`toast-type-${type}`); + return toast; + }, { + remove(...types) { + for (const type of types) + toast.style.remove(`toast-type-${type}`); + return toast; + }, + }), + })) + .extendJIT("content", toast => (0, Component_30.default)() + .style("toast-content") + .appendTo(toast)); + }).setName("Toast"); + const ToastList = Component_30.default.Builder((component) => { + const toasts = component + .style("toast-list") + .extend(toasts => ({ + info: add.bind(null, "info"), + success: add.bind(null, "success"), + warning: add.bind(null, "warning"), + })); + Object.assign(window, { toast: toasts }); + return toasts; + function add(type, toast, ...params) { + const component = ToastComponent() + .type(type) + .style("toast--measuring") + .tweak(toast.initialise, ...params); + void lifecycle(toast, component); + return component; + } + async function lifecycle(toast, component) { + const wrapper = (0, Component_30.default)().style("toast-wrapper").appendTo(toasts); + component.style("toast--measuring").appendTo(wrapper); + await Task_3.default.yield(); + const rect = component.rect.value; + component.style.remove("toast--measuring"); + wrapper.style.setProperty("height", `${rect.height}px`); + await Async_2.default.sleep(toast.duration); + component.style("toast--hide"); + wrapper.style.removeProperties("height"); + await Promise.race([ + new Promise(resolve => component.event.subscribe("animationend", resolve)), + Async_2.default.sleep(Time_6.default.seconds(1)), + ]); + return; + wrapper.remove(); + } + }); + //#endregion + //////////////////////////////////// + exports.default = ToastList; +}); +define("ui/component/core/toast/Toast", ["require", "exports", "ui/Component"], function (require, exports, Component_31) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.TOAST_ERROR = exports.TOAST_SUCCESS = void 0; + Component_31 = __importDefault(Component_31); + function Toast(toast) { + return toast; + } + exports.default = Toast; + exports.TOAST_SUCCESS = Toast({ + duration: 2000, + initialise(toast, translation) { + toast.title.text.use(translation); + }, + }); + function isErrorResponse(error) { + return error.headers !== undefined; + } + exports.TOAST_ERROR = Toast({ + duration: 5000, + initialise(toast, translation, error) { + toast.title.text.use(translation); + if (!isErrorResponse(error) || !error.detail) + toast.content.text.set(error.message); + else + toast.content + .append((0, Component_31.default)() + .style("toast-error-type") + .text.set(error.message)) + .text.append(": ") + .text.append(error.detail); + }, + }); +}); +define("ui/component/VanityInput", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/component/core/TextInput"], function (require, exports, Component_32, Input_3, TextInput_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_32 = __importDefault(Component_32); + Input_3 = __importDefault(Input_3); + TextInput_2 = __importDefault(TextInput_2); + const VanityInput = Object.assign(Component_32.default.Builder((component) => { + const input = (0, TextInput_2.default)() + .style("vanity-input-input") + .filter(filterVanity) + .appendTo(component); + return component.and(Input_3.default) + .style("vanity-input") + .append((0, Component_32.default)() + .style("vanity-input-prefix") + .text.set("@")) + .extend(component => ({ + // vanity input + input, + // input + required: input.required, + hint: input.hint.rehost(component), + maxLength: input.maxLength, + length: input.length, + setMaxLength(maxLength) { + input.setMaxLength(maxLength); + return component; + }, + setRequired(required) { + input.setRequired(required); + return component; + }, + setLabel(label) { + input.setLabel(label); + return component; + }, + tweakPopover(initialiser) { + input.tweakPopover(initialiser); + return component; + }, + // text input + state: input.state, + value: undefined, + default: input.default.rehost(component), + placeholder: input.placeholder.rehost(component), + ignoreInputEvent(ignore = true) { + input.ignoreInputEvent(ignore); + return component; + }, + filter(filter) { + input.filter(filter); + return component; + }, + })) + .extendMagic("value", component => ({ + get() { return input.value; }, + set(value) { input.value = value; }, + })); + }), { + filter: filterVanity, + }); + exports.default = VanityInput; + function filterVanity(vanity, textBefore = "", isFullText = true) { + vanity = vanity.replace(/[\W_]+/g, "-"); + if (isFullText) + vanity = vanity.replace(/^-|-$/g, ""); + if (textBefore.endsWith("-") && vanity.startsWith("-")) + return vanity.slice(1); + return vanity; + } +}); +define("ui/view/account/AccountViewForm", ["require", "exports", "endpoint/author/EndpointAuthorCreate", "endpoint/author/EndpointAuthorUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/LabelledTextInputBlock", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast", "ui/component/VanityInput"], function (require, exports, EndpointAuthorCreate_1, EndpointAuthorUpdate_1, en_nz_4, FormInputLengths_1, Session_5, Component_33, Block_5, Form_2, LabelledTable_1, LabelledTextInputBlock_1, TextEditor_1, TextInput_3, Toast_1, VanityInput_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorCreate_1 = __importDefault(EndpointAuthorCreate_1); + EndpointAuthorUpdate_1 = __importDefault(EndpointAuthorUpdate_1); + en_nz_4 = __importDefault(en_nz_4); + FormInputLengths_1 = __importDefault(FormInputLengths_1); + Session_5 = __importDefault(Session_5); + Component_33 = __importDefault(Component_33); + Block_5 = __importDefault(Block_5); + Form_2 = __importDefault(Form_2); + LabelledTable_1 = __importDefault(LabelledTable_1); + LabelledTextInputBlock_1 = __importDefault(LabelledTextInputBlock_1); + TextEditor_1 = __importDefault(TextEditor_1); + TextInput_3 = __importDefault(TextInput_3); + VanityInput_1 = __importDefault(VanityInput_1); + exports.default = Component_33.default.Builder((component, type) => { + const block = component.and(Block_5.default); + const form = block.and(Form_2.default, block.title); + form.viewTransition("account-form"); + form.title.text.use(`view/account/${type}/title`); + form.setName(en_nz_4.default[`view/account/${type}/title`]().toString()); + if (type === "create") + form.description.text.use("view/account/create/description"); + form.submit.textWrapper.text.use(`view/account/${type}/submit`); + const table = (0, LabelledTable_1.default)().appendTo(form.content); + const nameInput = (0, TextInput_3.default)() + .setRequired() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.name)) + .hint.use("view/account/name/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.name); + table.label(label => label.text.use("view/account/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const vanityInput = (0, VanityInput_1.default)() + .placeholder.bind(nameInput.state + .map(component, name => VanityInput_1.default.filter(name))) + .default.bind(Session_5.default.Auth.author.map(component, author => author?.vanity)) + .hint.use("view/account/vanity/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.vanity); + table.label(label => label.text.use("view/account/vanity/label")) + .content((content, label) => content.append(vanityInput.setLabel(label))); + const pronounsInput = (0, TextInput_3.default)() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.pronouns)) + .hint.use("view/account/pronouns/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.pronouns); + table.label(label => label.text.use("view/account/pronouns/label")) + .content((content, label) => content.append(pronounsInput.setLabel(label))); + const descriptionInput = (0, TextEditor_1.default)() + .default.bind(Session_5.default.Auth.author.map(component, author => author?.description.body)) + .hint.use("view/account/description/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.description); + table.label(label => label.text.use("view/account/description/label")) + .content((content, label) => content.append(descriptionInput.setLabel(label))); + let supportLinkInput; + let supportMessageInput; + (0, LabelledTextInputBlock_1.default)() + .style("labelled-row--in-labelled-table") + .ariaLabel.use("view/account/support-link/label") + .label(label => label.text.use("view/account/support-link/label")) + .input(input => supportLinkInput = input + .default.bind(Session_5.default.Auth.author.map(component, author => author?.support_link)) + .hint.use("view/account/support-link/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.support_link)) + .label(label => label.text.use("view/account/support-message/label")) + .input(input => supportMessageInput = input + .default.bind(Session_5.default.Auth.author.map(component, author => author?.support_message)) + .hint.use("view/account/support-message/hint") + .setMaxLength(FormInputLengths_1.default.manifest?.author.support_message)) + .appendTo(table); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const response = await (type === "create" ? EndpointAuthorCreate_1.default : EndpointAuthorUpdate_1.default).query({ + body: { + name: nameInput.value, + vanity: vanityInput.value, + description: descriptionInput.useMarkdown(), + pronouns: pronounsInput.value, + support_link: supportLinkInput.value, + support_message: supportMessageInput.value, + }, + }); + if (response instanceof Error) { + toast.warning(Toast_1.TOAST_ERROR, "view/account/toast/failed-to-save", response); + console.error(response); + return; + } + toast.success(Toast_1.TOAST_SUCCESS, "view/account/toast/saved"); + Session_5.default.setAuthor(response.data); + }); + return form; + }); +}); +define("ui/view/shared/component/ViewDefinition", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function ViewDefinition(definition) { + const result = { + ...definition, + navigate: (app, params) => app.view.show(result, params), + }; + return result; + } + exports.default = ViewDefinition; +}); +define("ui/view/AccountView", ["require", "exports", "endpoint/author/EndpointAuthorDelete", "model/Session", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/ConfirmDialog", "ui/component/core/Slot", "ui/component/OAuthServices", "ui/view/account/AccountViewForm", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "utility/State"], function (require, exports, EndpointAuthorDelete_1, Session_6, ActionRow_3, Button_6, ConfirmDialog_1, Slot_3, OAuthServices_2, AccountViewForm_1, View_2, ViewDefinition_1, ViewTransition_2, State_21) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorDelete_1 = __importDefault(EndpointAuthorDelete_1); + Session_6 = __importDefault(Session_6); + ActionRow_3 = __importDefault(ActionRow_3); + Button_6 = __importDefault(Button_6); + ConfirmDialog_1 = __importDefault(ConfirmDialog_1); + Slot_3 = __importDefault(Slot_3); + OAuthServices_2 = __importDefault(OAuthServices_2); + AccountViewForm_1 = __importDefault(AccountViewForm_1); + View_2 = __importDefault(View_2); + ViewDefinition_1 = __importDefault(ViewDefinition_1); + ViewTransition_2 = __importDefault(ViewTransition_2); + State_21 = __importDefault(State_21); + exports.default = (0, ViewDefinition_1.default)({ + create: async () => { + const id = "account"; + const view = (0, View_2.default)(id); + const state = (0, State_21.default)(Session_6.default.Auth.state.value); + (0, Slot_3.default)() + .use(state, () => createForm()?.subviewTransition(id)) + .appendTo(view); + const services = await (0, OAuthServices_2.default)(state); + services.header.subviewTransition(id); + services.appendTo(view); + (0, Slot_3.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + Session_6.default.Auth.state.subscribe(view, () => ViewTransition_2.default.perform("subview", id, updateAuthState)); + updateAuthState(); + return view; + function updateAuthState(newState = Session_6.default.Auth.state.value) { + state.value = newState; + } + function createForm() { + switch (state.value) { + case "has-authorisations": + return (0, AccountViewForm_1.default)("create"); + case "logged-in": + return (0, AccountViewForm_1.default)("update"); + } + } + function createActionRow() { + switch (state.value) { + case "logged-in": + return (0, ActionRow_3.default)() + .viewTransition("account-action-row") + .tweak(row => row.right + .append((0, Button_6.default)() + .text.use("view/account/action/logout") + .event.subscribe("click", () => Session_6.default.reset())) + .append((0, Button_6.default)() + .text.use("view/account/action/delete") + .event.subscribe("click", async () => { + const result = await ConfirmDialog_1.default.prompt(view, { dangerToken: "delete-account" }); + if (!result) + return; + const response = await EndpointAuthorDelete_1.default.query(); + if (response instanceof Error) { + console.error(response); + return; + } + return Session_6.default.reset(); + }))); + } + } + }, + }); +}); +define("endpoint/author/EndpointAuthorGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_9 = __importDefault(Endpoint_9); + exports.default = (0, Endpoint_9.default)("/author/{vanity}/get", "get"); +}); +define("endpoint/work/EndpointWorkGetAllAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_10) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_10 = __importDefault(Endpoint_10); + exports.default = (0, Endpoint_10.default)("/works/{author}", "get"); +}); +define("ui/component/core/ExternalLink", ["require", "exports", "ui/Component"], function (require, exports, Component_34) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_34 = __importDefault(Component_34); + const ExternalLink = Component_34.default.Builder("a", (component, href) => { + component.style("link", "link-external"); + if (href !== undefined) + component.attributes.set("href", href); + return component; + }); + exports.default = ExternalLink; +}); +define("ui/component/Author", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/ExternalLink", "ui/component/core/Slot"], function (require, exports, Component_35, Block_6, ExternalLink_1, Slot_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_35 = __importDefault(Component_35); + Block_6 = __importDefault(Block_6); + ExternalLink_1 = __importDefault(ExternalLink_1); + Slot_4 = __importDefault(Slot_4); + exports.default = Component_35.default.Builder((component, author) => { + component + .viewTransition("author") + .style("author"); + const block = component.and(Block_6.default); + block.title + .style("author-name") + .text.set(author.name); + block.description + .append((0, Component_35.default)() + .style("author-vanity") + .text.set(`@${author.vanity}`)) + .append(Slot_4.default.using(author.pronouns, (slot, pronouns) => pronouns && slot + .text.append(" · ") + .append((0, Component_35.default)() + .style("author-pronouns") + .text.set(pronouns)))); + (0, Component_35.default)() + .style("author-description") + .append(Slot_4.default.using(author.description.body, (slot, body) => { + if (body) + slot.setMarkdownContent(body); + else + slot.style("placeholder").text.use("author/description/empty"); + })) + .appendTo(block.content); + if (author.support_link && author.support_message) + (0, ExternalLink_1.default)(author.support_link) + .style("author-support-link") + .text.set(author.support_message) + .appendTo(block.content); + return block; + }); +}); +define("ui/component/core/Link", ["require", "exports", "ui/Component", "utility/Env"], function (require, exports, Component_36, Env_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_36 = __importDefault(Component_36); + Env_4 = __importDefault(Env_4); + const Link = Component_36.default.Builder("a", (component, route) => { + component.style("link"); + if (route !== undefined) { + component.attributes.set("href", `${Env_4.default.URL_ORIGIN}${route.slice(1)}`); + component.event.subscribe("click", event => { + event.preventDefault(); + event.stopImmediatePropagation(); + void navigate.toURL(route); + }); + } + return component; + }); + exports.default = Link; +}); +define("ui/component/core/Paginator", ["require", "exports", "ui/Component", "ui/component/core/Block", "ui/component/core/Button", "ui/component/core/Slot", "utility/Async", "utility/State"], function (require, exports, Component_37, Block_7, Button_7, Slot_5, Async_3, State_22) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_37 = __importDefault(Component_37); + Block_7 = __importDefault(Block_7); + Button_7 = __importDefault(Button_7); + Slot_5 = __importDefault(Slot_5); + Async_3 = __importDefault(Async_3); + State_22 = __importDefault(State_22); + const Paginator = Component_37.default.Builder((component) => { + const block = component.and(Block_7.default); + const isFlush = block.type.state.mapManual(type => type.has("flush")); + block.style.bind(isFlush, "paginator--flush"); + block.header + .style("paginator-header") + .style.bind(isFlush, "paginator-header--flush"); + const content = block.content + .style("paginator-content"); + block.footer + .style("paginator-footer", "paginator-footer--hidden") + .style.bind(isFlush, "paginator-footer--flush"); + block.footer.left.style("paginator-footer-left"); + block.footer.right.style("paginator-footer-right"); + const buttonFirst = (0, Button_7.default)() + .style("paginator-button", "paginator-button-first") + .event.subscribe("click", () => showPage(0)) + .appendTo(block.footer.left); + const buttonPrev = (0, Button_7.default)() + .style("paginator-button", "paginator-button-prev") + .event.subscribe("click", () => showPage(Math.max(cursor.value - 1, 0))) + .appendTo(block.footer.left); + const buttonNext = (0, Button_7.default)() + .style("paginator-button", "paginator-button-next") + .event.subscribe("click", () => showPage(Math.min(cursor.value + 1, using?.pageCount === true ? Infinity : pages.length - 1))) + .appendTo(block.footer.right); + const buttonLast = (0, Button_7.default)() + .style("paginator-button", "paginator-button-last") + .event.subscribe("click", () => showPage(pages.length - 1)) + .appendTo(block.footer.right); + let pageContent = []; + let pages = []; + const cursor = (0, State_22.default)(0); + const data = cursor.mapManual(page => pageContent[page]); + let showingPage = -1; + let orElseContentInitialiser; + let isEmpty = true; + let using; + const paginator = block + .viewTransition("paginator") + .style("paginator") + .extend(component => ({ + page: cursor, + data, + useInitial(initialData, page, pageCount) { + resetPages(); + pageContent[page] = initialData; + cursor.value = page; + data.refresh(); + using = { endpoint: undefined, initialiser: undefined, pageCount }; + return component; + }, + thenUse(endpoint) { + using.endpoint = endpoint; + return component; + }, + async withContent(contentInitialiser) { + clearContent(); + using.initialiser = contentInitialiser; + await setup(pageContent[cursor.value], cursor.value, using.pageCount); + return component; + }, + async useEndpoint(endpoint, initialiser) { + clearContent(); + resetPages(); + const mainPage = MainPage(); + let response; + while (true) { + const result = await endpoint.query(); + if (result instanceof Error) { + mainPage.removeContents(); + await new Promise(resolve => mainPage.append(RetryDialog(resolve))); + continue; + } + response = result; + break; + } + using = { endpoint: endpoint, initialiser: initialiser, pageCount: response.page_count }; + await setup(response.data, 0, response.page_count); + return component; + }, + orElse(contentInitialiser) { + orElseContentInitialiser = contentInitialiser; + if (isEmpty) { + clearContent(); + resetPages(); + const mainPage = MainPage() + .style.remove("paginator-page--hidden"); + content.style("paginator-content--or-else"); + contentInitialiser(mainPage); + } + return component; + }, + })); + return paginator; + function clearContent() { + content.removeContents(); + block.footer.style("paginator-footer--hidden"); + } + function resetPages() { + pageContent = []; + pages = []; + cursor.value = 0; + } + async function setup(initialData, page, pageCount) { + if (pageCount === true || pageCount > 1) + block.footer.style.remove("paginator-footer--hidden"); + if (pageCount !== true) + while (pages.length < pageCount) + pages.push(Page()); + const pageComponent = pages[page] + .style("paginator-page--initial-load") + .style.remove("paginator-page--hidden"); + pageContent[page] = initialData; + cursor.value = page; + data.refresh(); + if (initialData && (!Array.isArray(initialData) || initialData.length)) { + await using.initialiser(pageComponent, initialData, paginator); + isEmpty = false; + } + else { + content.style("paginator-content--or-else"); + orElseContentInitialiser?.(pageComponent); + } + updateButtons(page); + } + function MainPage() { + const mainPage = Page() + .style("paginator-page--initial-load"); + pages.push(mainPage); + return mainPage; + } + function Page() { + return (0, Slot_5.default)() + .style("paginator-page", "paginator-page--hidden") + .style.bind(isFlush, "paginator-page--flush") + .appendTo(content); + } + function RetryDialog(retry) { + return (0, Component_37.default)() + .style("paginator-error") + .append((0, Component_37.default)() + .style("paginator-error-text") + .text.use("component/paginator/error")) + .append((0, Button_7.default)() + .type("primary") + .text.use("component/paginator/error/retry") + .event.subscribe("click", () => retry())); + } + function updateButtons(page = cursor.value, pageCount = using?.pageCount ?? 0) { + buttonFirst.style.toggle(page <= 0, "paginator-button--disabled"); + buttonPrev.style.toggle(page <= 0, "paginator-button--disabled"); + buttonNext.style.toggle(pageCount !== true && page >= pageCount - 1, "paginator-button--disabled"); + buttonLast.style.toggle(pageCount !== true && page >= pageCount - 1, "paginator-button--disabled"); + buttonLast.style.toggle(pageCount === true, "paginator-button--hidden"); + } + async function showPage(number) { + if (cursor.value === number || !using) + return; + const oldNumber = cursor.value; + const direction = Math.sign(number - oldNumber); + pages[oldNumber] + .style.remove("paginator-page--initial-load", "paginator-page--bounce") + .style("paginator-page--hidden") + .style.setVariable("page-direction", direction); + let page = pages[number]; + if (!page) + pages.push(page ??= Page()); + page.style.setVariable("page-direction", direction); + updateButtons(number); + if (pageContent[number]) { + cursor.value = number; + page.style.remove("paginator-page--hidden"); + scrollIntoView(direction); + return; + } + let response; + while (true) { + page.removeContents(); + showingPage = number; + const result = await using?.endpoint.query({ query: { page: number } }); + if (showingPage !== number) + return; + const isError = result instanceof Error; + if (!isError && !hasResults(result.data)) { + cursor.value = number; + pages[oldNumber].style("paginator-page--bounce"); + await Async_3.default.sleep(200); + return showPage(oldNumber); + } + page.style.remove("paginator-page--hidden"); + if (isError) { + await new Promise(resolve => { + RetryDialog(resolve).appendTo(page); + block.header.element.scrollIntoView(); + }); + if (showingPage !== number) + return; + continue; + } + response = result; + break; + } + pageContent[number] = response.data; + cursor.value = number; + await using?.initialiser(page, response.data, paginator); + scrollIntoView(direction); + } + function scrollIntoView(direction) { + const scrollTarget = direction > 0 ? block.element : pages[cursor.value].element.lastElementChild; + scrollTarget?.scrollIntoView(); + } + }); + function hasResults(result) { + if (result === null || result === undefined) + return false; + if (typeof result !== "object") + return true; + if (Array.isArray(result)) + return result.length > 0; + for (const sub of Object.values(result)) + if (hasResults(sub)) + return true; + return false; + } + exports.default = Paginator; +}); +define("endpoint/tag/EndpointTagManifest", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_11 = __importDefault(Endpoint_11); + exports.default = (0, Endpoint_11.default)("/manifest/tags", "get"); +}); +define("model/Tags", ["require", "exports", "endpoint/tag/EndpointTagManifest", "model/Manifest"], function (require, exports, EndpointTagManifest_1, Manifest_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.resolve = resolve; + EndpointTagManifest_1 = __importDefault(EndpointTagManifest_1); + Manifest_2 = __importDefault(Manifest_2); + const Tags = Object.assign((0, Manifest_2.default)({ + get() { + return EndpointTagManifest_1.default.query(); + }, + }), { resolve }); + exports.default = Tags; + async function resolve(tags, name) { + if (!tags?.length) + return []; + if (Array.isArray(tags)) + return resolveInternal(tags); + const tag = name ? `${tags}: ${name}` : tags; + const [result] = await resolveInternal([tag]); + return result; + } + async function resolveInternal(tags) { + const result = []; + let manifest = await Tags.getManifest(); + resolveTags(); + if (result.length !== tags.length && !Tags.isFresh()) { + manifest = await Tags.getManifest(true); + resolveTags(); + } + return result; + function resolveTags() { + result.splice(0, Infinity); + for (const tagString of tags) { + const tag = manifest.tags[tagString]; + if (!tag) + continue; + result.push(tag); + } + } + } +}); +define("ui/component/core/TextLabel", ["require", "exports", "ui/Component"], function (require, exports, Component_38) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_38 = __importDefault(Component_38); + const TextLabel = Component_38.default.Builder((component) => { + component.style("text-label"); + const label = (0, Component_38.default)() + .style("text-label-label"); + const punctuation = (0, Component_38.default)() + .style("text-label-punctuation") + .text.set(": "); + const content = (0, Component_38.default)() + .style("text-label-content"); + return component + .append(label, punctuation, content) + .extend(() => ({ + label, content, + })); + }); + exports.default = TextLabel; +}); +define("ui/component/core/Timestamp", ["require", "exports", "ui/Component", "utility/State", "utility/Time"], function (require, exports, Component_39, State_23, Time_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_39 = __importDefault(Component_39); + State_23 = __importDefault(State_23); + Time_7 = __importDefault(Time_7); + const Timestamp = Component_39.default.Builder((component, time) => { + const state = (0, State_23.default)(new Date(time ?? Date.now())); + state.use(component, update); + return component + .style("timestamp") + .extend(component => ({ time: state })) + .onRooted(component => { + update(); + const interval = setInterval(update, Time_7.default.seconds(1)); + component.event.subscribe("remove", () => clearInterval(interval)); + }); + function update() { + component.text.set(Time_7.default.relative(state.value.getTime(), { components: 2, secondsExclusive: true })); + } + }); + exports.default = Timestamp; +}); +define("ui/component/Tag", ["require", "exports", "ui/Component", "ui/component/core/Button", "ui/component/core/Link"], function (require, exports, Component_40, Button_8, Link_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_40 = __importDefault(Component_40); + Button_8 = __importDefault(Button_8); + Link_1 = __importDefault(Link_1); + const toURLRegex = /\W+/g; + const toURL = (name) => name.replaceAll(toURLRegex, "-").toLowerCase(); + const Tag = Component_40.default.Builder("a", (component, tag) => { + component + .and(Link_1.default, `/tag/${toURL(tag.category)}/${toURL(tag.name)}`) + .and(Button_8.default) + .style("tag"); + (0, Component_40.default)() + .style("tag-category") + .text.set(tag.category) + .appendTo(component); + (0, Component_40.default)() + .style("tag-name") + .text.set(tag.name) + .appendTo(component); + // component.href.use(`/tag/${tag.id}`) + return component.extend(component => ({ tag })); + }); + exports.default = Tag; +}); +define("ui/component/Work", ["require", "exports", "model/Session", "model/Tags", "ui/Component", "ui/component/core/Block", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Slot", "ui/component/core/TextLabel", "ui/component/core/Timestamp", "ui/component/Tag"], function (require, exports, Session_7, Tags_1, Component_41, Block_8, Button_9, Link_2, Slot_6, TextLabel_1, Timestamp_1, Tag_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_7 = __importDefault(Session_7); + Tags_1 = __importDefault(Tags_1); + Component_41 = __importDefault(Component_41); + Block_8 = __importDefault(Block_8); + Button_9 = __importDefault(Button_9); + Link_2 = __importDefault(Link_2); + Slot_6 = __importDefault(Slot_6); + TextLabel_1 = __importDefault(TextLabel_1); + Timestamp_1 = __importDefault(Timestamp_1); + Tag_1 = __importDefault(Tag_1); + const Work = Component_41.default.Builder(async (component, work, author, notFullOverride) => { + author = author ?? work.synopsis?.mentions[0]; + component + .viewTransition("work") + .style("work") + .style.toggle(component.is(Link_2.default), "work--link"); + const block = component.and(Block_8.default); + const isFlush = block.type.state.mapManual(types => types.has("flush")); + block.header.style("work-header"); + block.title + .style("work-name") + .text.set(work.name); + if (author) + block.description + .style("work-author-list") + .style.bind(isFlush, "work-author-list--flush") + .append((0, Link_2.default)(`/author/${author.vanity}`) + .style("work-author") + .text.set(author.name)); + block.content.style("work-content"); + (0, Slot_6.default)() + .use(isFlush, (slot, isFlush) => { + isFlush ||= notFullOverride ?? false; + const shouldShowDescription = isFlush || (work.synopsis?.body && work.description); + if (shouldShowDescription) + (0, Component_41.default)() + .style("work-description") + .style.toggle(!work.description, "placeholder") + .tweak(component => { + if (work.description) + component.text.set(work.description); + else + component.text.use("work/description/empty"); + }) + .appendTo(slot); + if (!isFlush) + (0, Component_41.default)() + .style("work-synopsis") + .style.toggle(!work.synopsis?.body && !work.description, "placeholder") + .append(Slot_6.default.using(work.synopsis ?? work.description, (slot, synopsis) => { + if (typeof synopsis === "string") + slot.text.set(synopsis); + else if (!synopsis.body) + slot.text.use("work/description/empty"); + else + slot.setMarkdownContent(synopsis.body); + })) + .appendTo(slot); + }) + .appendTo(block.content); + let tagsWrapper; + const tags = await Tags_1.default.resolve(work.global_tags); + for (const tag of tags) { + (0, Tag_1.default)(tag) + .appendTo(tagsWrapper ??= (0, Component_41.default)() + .style("work-tags") + .style.bind(isFlush, "work-tags--flush") + .appendTo(block.content)); + } + (0, TextLabel_1.default)() + .tweak(textLabel => textLabel.label.text.use("work/chapters/label")) + .tweak(textLabel => textLabel.content.text.set(`${work.chapter_count_public}`)) + .appendTo(block.footer.left); + if (work.time_last_update) + block.footer.right.append((0, Timestamp_1.default)(work.time_last_update).style("work-timestamp")); + block.setActionsMenu((popover, button) => { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/view") + .event.subscribe("click", () => navigate.toURL(`/work/${author?.vanity}/${work.vanity}`)) + .appendTo(popover); + if (author && author.vanity === Session_7.default.Auth.author.value?.vanity) { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/edit") + .event.subscribe("click", () => navigate.toURL(`/work/${author.vanity}/${work.vanity}/edit`)) + .appendTo(popover); + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/delete") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + else if (Session_7.default.Auth.loggedIn.value) { + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/follow") + .event.subscribe("click", () => { }) + .appendTo(popover); + (0, Button_9.default)() + .type("flush") + .text.use("view/author/works/action/label/ignore") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + }); + return block.extend(component => ({ work })); + }); + exports.default = Work; +}); +define("ui/view/AuthorView", ["require", "exports", "endpoint/author/EndpointAuthorGet", "endpoint/work/EndpointWorkGetAllAuthor", "model/Session", "ui/Component", "ui/component/Author", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Paginator", "ui/component/core/Slot", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, EndpointAuthorGet_1, EndpointWorkGetAllAuthor_1, Session_8, Component_42, Author_1, Button_10, Link_3, Paginator_1, Slot_7, Work_1, View_3, ViewDefinition_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthorGet_1 = __importDefault(EndpointAuthorGet_1); + EndpointWorkGetAllAuthor_1 = __importDefault(EndpointWorkGetAllAuthor_1); + Session_8 = __importDefault(Session_8); + Component_42 = __importDefault(Component_42); + Author_1 = __importDefault(Author_1); + Button_10 = __importDefault(Button_10); + Link_3 = __importDefault(Link_3); + Paginator_1 = __importDefault(Paginator_1); + Slot_7 = __importDefault(Slot_7); + Work_1 = __importDefault(Work_1); + View_3 = __importDefault(View_3); + ViewDefinition_2 = __importDefault(ViewDefinition_2); + exports.default = (0, ViewDefinition_2.default)({ + create: async (params) => { + const view = (0, View_3.default)("author"); + const author = await EndpointAuthorGet_1.default.query({ params }); + if (author instanceof Error) + throw author; + (0, Author_1.default)(author.data) + .viewTransition("author-view-author") + .setContainsHeading() + .appendTo(view); + const paginator = (0, Paginator_1.default)() + .viewTransition("author-view-works") + .tweak(p => p.title.text.use("view/author/works/title")) + .tweak(p => p.primaryActions.append((0, Slot_7.default)() + .if(Session_8.default.Auth.loggedIn, () => (0, Button_10.default)() + .setIcon("plus") + .ariaLabel.use("view/author/works/action/label/new") + .event.subscribe("click", () => navigate.toURL("/work/new"))))) + .appendTo(view); + const worksQuery = EndpointWorkGetAllAuthor_1.default.prep({ + params: { + author: params.vanity, + }, + }); + await paginator.useEndpoint(worksQuery, async (slot, works) => { + for (const workData of works) { + const work = await (0, Link_3.default)(`/work/${author.data.vanity}/${workData.vanity}`) + .and(Work_1.default, workData, author.data); + work + .viewTransition() + .type("flush") + .appendTo(slot); + } + }); + paginator.orElse(slot => (0, Component_42.default)() + .style("placeholder") + .text.use("view/author/works/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("endpoint/work/EndpointWorkGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_12 = __importDefault(Endpoint_12); + exports.default = (0, Endpoint_12.default)("/work/{author}/{vanity}/get", "get"); +}); +define("endpoint/chapter/EndpointChapterGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_13) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_13 = __importDefault(Endpoint_13); + exports.default = (0, Endpoint_13.default)("/work/{author}/{vanity}/chapter/{url}/get", "get"); +}); +define("endpoint/chapter/EndpointChapterCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_14) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_14 = __importDefault(Endpoint_14); + exports.default = (0, Endpoint_14.default)("/work/{author}/{vanity}/chapter/create", "post"); +}); +define("endpoint/chapter/EndpointChapterUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_15) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_15 = __importDefault(Endpoint_15); + exports.default = (0, Endpoint_15.default)("/work/{author}/{vanity}/chapter/{url}/update", "post"); +}); +define("ui/view/chapter/ChapterEditForm", ["require", "exports", "endpoint/chapter/EndpointChapterCreate", "endpoint/chapter/EndpointChapterUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast"], function (require, exports, EndpointChapterCreate_1, EndpointChapterUpdate_1, en_nz_5, FormInputLengths_2, Session_9, Component_43, Block_9, Form_3, LabelledTable_2, TextEditor_2, TextInput_4, Toast_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterCreate_1 = __importDefault(EndpointChapterCreate_1); + EndpointChapterUpdate_1 = __importDefault(EndpointChapterUpdate_1); + en_nz_5 = __importDefault(en_nz_5); + FormInputLengths_2 = __importDefault(FormInputLengths_2); + Session_9 = __importDefault(Session_9); + Component_43 = __importDefault(Component_43); + Block_9 = __importDefault(Block_9); + Form_3 = __importDefault(Form_3); + LabelledTable_2 = __importDefault(LabelledTable_2); + TextEditor_2 = __importDefault(TextEditor_2); + TextInput_4 = __importDefault(TextInput_4); + exports.default = Component_43.default.Builder((component, state, workParams) => { + const block = component.and(Block_9.default); + const form = block.and(Form_3.default, block.title); + form.viewTransition("chapter-edit-form"); + const type = state.value ? "update" : "create"; + form.title.text.use(`view/chapter-edit/${type}/title`); + form.setName(en_nz_5.default[`view/chapter-edit/${type}/title`]().toString()); + // if (params.type === "create") + // form.description.text.use("view/work-edit/create/description") + form.submit.textWrapper.text.use(`view/chapter-edit/${type}/submit`); + const table = (0, LabelledTable_2.default)().appendTo(form.content); + const nameInput = (0, TextInput_4.default)() + .setRequired() + .default.bind(state.map(component, work => work?.name)) + .hint.use("view/chapter-edit/shared/form/name/hint") + .setMaxLength(FormInputLengths_2.default.manifest?.chapter.name); + table.label(label => label.text.use("view/chapter-edit/shared/form/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const bodyInput = (0, TextEditor_2.default)() + .default.bind(state.map(component, chapter => chapter?.body ?? undefined)) + .hint.use("view/chapter-edit/shared/form/body/hint"); + table.label(label => label.text.use("view/chapter-edit/shared/form/body/label")) + .content((content, label) => content.append(bodyInput.setLabel(label))); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const response = await (() => { + switch (type) { + case "create": + return EndpointChapterCreate_1.default.query({ + params: workParams, + body: { + name: nameInput.value, + body: bodyInput.useMarkdown(), + visibility: "Private", + }, + }); + case "update": { + if (!state.value) + return; + const authorVanity = Session_9.default.Auth.author.value?.vanity; + if (!authorVanity) + return new Error("Cannot update a work when not signed in"); + return EndpointChapterUpdate_1.default.query({ + params: { + ...workParams, + url: state.value.url, + }, + body: { + name: nameInput.value, + body: bodyInput.useMarkdown(), + visibility: "Private", + }, + }); + } + } + })(); + if (response instanceof Error) { + toast.warning(Toast_2.TOAST_ERROR, "view/chapter-edit/shared/toast/failed-to-save", response); + console.error(response); + return; + } + toast.success(Toast_2.TOAST_SUCCESS, "view/chapter-edit/shared/toast/saved"); + state.value = response?.data; + }); + return form; + }); +}); +define("ui/view/ChapterEditView", ["require", "exports", "endpoint/chapter/EndpointChapterGet", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/Slot", "ui/view/chapter/ChapterEditForm", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "utility/State"], function (require, exports, EndpointChapterGet_1, ActionRow_4, Button_11, Slot_8, ChapterEditForm_1, View_4, ViewDefinition_3, ViewTransition_3, State_24) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGet_1 = __importDefault(EndpointChapterGet_1); + ActionRow_4 = __importDefault(ActionRow_4); + Button_11 = __importDefault(Button_11); + Slot_8 = __importDefault(Slot_8); + ChapterEditForm_1 = __importDefault(ChapterEditForm_1); + View_4 = __importDefault(View_4); + ViewDefinition_3 = __importDefault(ViewDefinition_3); + ViewTransition_3 = __importDefault(ViewTransition_3); + State_24 = __importDefault(State_24); + exports.default = (0, ViewDefinition_3.default)({ + requiresLogin: true, + create: async (params) => { + const id = "chapter-edit"; + const view = (0, View_4.default)(id); + const chapter = !params.url ? undefined : await EndpointChapterGet_1.default.query({ params: params }); + if (chapter instanceof Error) + throw chapter; + const state = (0, State_24.default)(chapter?.data); + const stateInternal = (0, State_24.default)(chapter?.data); + (0, Slot_8.default)() + .use(state, () => (0, ChapterEditForm_1.default)(stateInternal, params).subviewTransition(id)) + .appendTo(view); + (0, Slot_8.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + stateInternal.subscribe(view, chapter => ViewTransition_3.default.perform("subview", id, () => state.value = chapter)); + return view; + function createActionRow() { + if (!stateInternal.value) + return; + return (0, ActionRow_4.default)() + .viewTransition("chapter-edit-action-row") + .tweak(row => row.right + .append((0, Button_11.default)() + .text.use("view/chapter-edit/update/action/delete") + .event.subscribe("click", async () => { + // const response = await EndpointAuthorDelete.query() + // if (response instanceof Error) { + // console.error(response) + // return + // } + // return Session.reset() + }))); + } + }, + }); +}); +define("endpoint/chapter/EndpointChapterGetPaged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_16) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_16 = __importDefault(Endpoint_16); + exports.default = (0, Endpoint_16.default)("/work/{author}/{vanity}/chapters/paged", "get"); +}); +define("ui/view/shared/component/PaginatedView", ["require", "exports", "ui/Component", "ui/component/core/Paginator", "ui/view/shared/component/View"], function (require, exports, Component_44, Paginator_2, View_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_44 = __importDefault(Component_44); + Paginator_2 = __importDefault(Paginator_2); + View_5 = __importDefault(View_5); + const PaginatedView = Component_44.default.Builder((_, id) => { + let paginator; + const urls = []; + return (0, View_5.default)(id) + .extend(view => ({ + setURL, + paginator: () => { + paginator ??= (0, Paginator_2.default)().extend(paginator => ({ setURL })); + paginator.page.subscribeManual(page => { + const route = urls[page]; + if (route) + navigate.setURL(route); + }); + return paginator; + }, + })); + function setURL(route) { + navigate.setURL(route); + const page = paginator?.page.value; + if (page !== undefined) + urls[page] = route; + } + }); + exports.default = PaginatedView; +}); +define("utility/maths/Maths", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Maths; + (function (Maths) { + function sum(...nums) { + let result = 0; + for (const num of nums) + result += num; + return result; + } + Maths.sum = sum; + function average(...nums) { + let result = 0; + for (const num of nums) + result += num; + return result / nums.length; + } + Maths.average = average; + function bits(number) { + const result = new BitsSet(); + for (let i = 52; i >= 0; i--) { + const v = 1 << i; + if (number & v) + result.add(v); + } + return result; + } + Maths.bits = bits; + class BitsSet extends Set { + everyIn(type) { + const t = type ?? 0; + for (const bit of this) + if (!(t & bit)) + return false; + return true; + } + someIn(type) { + const t = type ?? 0; + for (const bit of this) + if (t & bit) + return true; + return false; + } + every(predicate) { + for (const bit of this) + if (!predicate(bit)) + return false; + return true; + } + some(predicate) { + for (const bit of this) + if (predicate(bit)) + return true; + return false; + } + } + Maths.BitsSet = BitsSet; + function bitsn(flag) { + const result = new BitsSetN(); + for (let i = 52n; i >= 0n; i--) { + const v = 1n << i; + if (flag & v) + result.add(v); + } + return result; + } + Maths.bitsn = bitsn; + class BitsSetN extends Set { + everyIn(type) { + const t = type ?? 0n; + for (const bit of this) + if (!(t & bit)) + return false; + return true; + } + someIn(type) { + const t = type ?? 0n; + for (const bit of this) + if (t & bit) + return true; + return false; + } + every(predicate) { + for (const bit of this) + if (!predicate(bit)) + return false; + return true; + } + some(predicate) { + for (const bit of this) + if (predicate(bit)) + return true; + return false; + } + } + Maths.BitsSetN = BitsSetN; + function lerp(from, to, t) { + return (1 - t) * from + t * to; + } + Maths.lerp = lerp; + function parseIntOrUndefined(value) { + const result = parseFloat(value); + return isNaN(result) || !Number.isInteger(result) ? undefined : result; + } + Maths.parseIntOrUndefined = parseIntOrUndefined; + })(Maths || (Maths = {})); + exports.default = Maths; +}); +define("ui/view/ChapterView", ["require", "exports", "endpoint/chapter/EndpointChapterGet", "endpoint/chapter/EndpointChapterGetPaged", "endpoint/work/EndpointWorkGet", "lang/en-nz", "ui/component/Work", "ui/view/shared/component/PaginatedView", "ui/view/shared/component/ViewDefinition", "utility/maths/Maths", "utility/State"], function (require, exports, EndpointChapterGet_2, EndpointChapterGetPaged_1, EndpointWorkGet_1, en_nz_6, Work_2, PaginatedView_1, ViewDefinition_4, Maths_1, State_25) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGet_2 = __importDefault(EndpointChapterGet_2); + EndpointChapterGetPaged_1 = __importDefault(EndpointChapterGetPaged_1); + EndpointWorkGet_1 = __importDefault(EndpointWorkGet_1); + en_nz_6 = __importDefault(en_nz_6); + Work_2 = __importDefault(Work_2); + PaginatedView_1 = __importDefault(PaginatedView_1); + ViewDefinition_4 = __importDefault(ViewDefinition_4); + Maths_1 = __importDefault(Maths_1); + State_25 = __importDefault(State_25); + exports.default = (0, ViewDefinition_4.default)({ + create: async (params) => { + const view = (0, PaginatedView_1.default)("chapter"); + const response = await EndpointWorkGet_1.default.query({ params }); + if (response instanceof Error) + throw response; + const author = response.data.synopsis.mentions.find(author => author.vanity === params.author); + const workData = response.data; + delete workData.synopsis; + delete workData.custom_tags; + const work = await (0, Work_2.default)(workData, author); + work + .viewTransition("work-view-work") + .style("view-type-chapter-work") + .setContainsHeading() + .appendTo(view); + const initialChapterResponse = await EndpointChapterGet_2.default.query({ params }); + if (initialChapterResponse instanceof Error) + throw initialChapterResponse; + const chapterState = (0, State_25.default)(initialChapterResponse.data); + const chaptersQuery = EndpointChapterGetPaged_1.default.prep({ params }); + const paginator = await view.paginator() + .viewTransition("chapter-view-chapter") + .style("view-type-chapter-block") + .tweak(p => p.title.text.bind(chapterState.mapManual(chapter => en_nz_6.default["view/chapter/title"](Maths_1.default.parseIntOrUndefined(chapter.url), chapter.name)))) + .appendTo(view) + .useInitial(initialChapterResponse.data, initialChapterResponse.page, initialChapterResponse.page_count) + .thenUse(chaptersQuery) + .withContent((slot, chapter, paginator) => { + paginator.setURL(`/work/${params.author}/${params.vanity}/chapter/${chapter.url}`); + slot + .style("view-type-chapter-block-body") + .setMarkdownContent(chapter.body ?? ""); + }); + paginator.data.use(paginator, chapter => chapterState.value = chapter); + return view; + }, + }); +}); +define("ui/view/debug/ButtonRegistry", ["require", "exports", "model/Session", "utility/Env"], function (require, exports, Session_10, Env_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.BUTTON_REGISTRY = void 0; + Session_10 = __importDefault(Session_10); + Env_5 = __importDefault(Env_5); + exports.BUTTON_REGISTRY = { + createAuthor: { + name: "Create Author", + async execute(name, vanity, description, pronouns) { + const response = await fetch(`${Env_5.default.API_ORIGIN}author/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + "Accept": "application/json", + }, + body: JSON.stringify({ + name: name, + vanity: vanity, + description: description, + pronouns: pronouns, + }), + }).then(response => response.json()); + console.log(response); + await Session_10.default.refresh(); + }, + }, + updateAuthor: { + name: "Update Author", + async execute(name, description, vanity, support_link, support_message) { + await fetch(`${Env_5.default.API_ORIGIN}author/update`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + vanity: vanity, + support_link: support_link, + support_message: support_message, + }), + }); + }, + }, + deleteAuthor: { + name: "Delete Author", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}author/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewAuthor: { + name: "View Author", + async execute(label, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}author/${vanity}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + clearSession: { + name: "Clear Session", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}session/reset`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + }); + await Session_10.default.refresh(); + }, + }, + createWork: { + name: "Create Work", + async execute(name, synopsis, description, vanity, status, visibility, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + synopsis: synopsis, + description: description, + vanity: vanity, + status: status, + visibility: visibility, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateWork: { + name: "Update Work", + async execute(author, url, name, description, vanity, status, visibility) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/update`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + vanity: vanity, + status: status, + visibility: visibility, + }), + }); + }, + }, + deleteWork: { + name: "Delete Work", + async execute(author, url) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewWork: { + name: "View Work", + async execute(label, author, url) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${url}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllWorksByAuthor: { + name: "View All Works By Author", + async execute(label, author) { + const response = await fetch(`${Env_5.default.API_ORIGIN}works/${author}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + createChapter: { + name: "Create Chapter", + async execute(author, work_url, name, body, visibility, is_numbered, notesBefore, notesAfter, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + body: body, + visibility: visibility, + is_numbered: is_numbered, + notes_before: notesBefore, + notes_after: notesAfter, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateChapter: { + name: "Update Chapter", + async execute(author, work_url, index, name, body, visibility, is_numbered, notesBefore, notesAfter, globalTags, customTags) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/update`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name, + body, + visibility, + is_numbered, + notes_before: notesBefore, + notes_after: notesAfter, + global_tags: globalTags, + custom_tags: customTags, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + deleteChapter: { + name: "Delete Chapter", + async execute(author, work_url, index) { + await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/delete`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + viewChapter: { + name: "View Chapter", + async execute(label, author, work_url, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapter/${index}/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + viewChapterPaginated: { + name: "View Chapter Paginated", + async execute(label, author, work_url, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${work_url}/chapters/individual?page=${index}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllChapters: { + name: "Get All Chapters", + async execute(author, vanity, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapters/list?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + follow: { + name: "Follow", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}follow/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + followWork: { + name: "Follow", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}follow/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unfollow: { + name: "Unfollow", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unfollow/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unfollowWork: { + name: "Unfollow", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unfollow/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + getFollow: { + name: "Get Follow", + async execute(type, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}follows/${type}/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getFollowWork: { + name: "Get Follow", + async execute(author_vanity, work_vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}follows/work/${author_vanity}/${work_vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllFollows: { + name: "Get All Follows", + async execute(type, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}following/${type}?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllFollowsMerged: { + name: "Get All Follows Merged", + async execute(page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}following?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + ignore: { + name: "Ignore", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}ignore/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + ignoreWork: { + name: "Ignore", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}ignore/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unignore: { + name: "Unignore", + async execute(type, vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unignore/${type}/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + unignoreWork: { + name: "Unignore", + async execute(author_vanity, work_vanity) { + await fetch(`${Env_5.default.API_ORIGIN}unignore/work/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + getIgnore: { + name: "Get Ignore", + async execute(type, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignores/${type}/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getIgnoreWork: { + name: "Get Ignore", + async execute(author_vanity, work_vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignores/work/${author_vanity}/${work_vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllIgnores: { + name: "Get All Ignores", + async execute(type, page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignoring/${type}?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + getAllIgnoresMerged: { + name: "Get All Ignores Merged", + async execute(page = 0) { + const response = await fetch(`${Env_5.default.API_ORIGIN}ignoring?page=${page}`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + privilegeGetAllAuthor: { + name: "Get All Author Privileges", + async execute(label, vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/get/${vanity}`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + privilegeGrantAuthor: { + name: "Grant Privileges to Author", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/grant/author/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("granted privileges", response); + }, + }, + privilegeRevokeAuthor: { + name: "Revoke Privileges from Author", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/revoke/author/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("revoked privileges", response); + }, + }, + createRole: { + name: "Create Role", + async execute(roleName, visibilty, roleBelow) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/create`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: roleName, + below: roleBelow, + description: "idk some test stuff", + visibilty: visibilty, + }), + }).then(response => response.json()); + console.log("created role", response); + }, + }, + deleteRole: { + name: "Delete Role", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/delete/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("deleted role", response); + }, + }, + editRole: { + name: "Edit Role", + async execute(vanity, name, description) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/update/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: name, + description: description, + }), + }).then(response => response.json()); + console.log("edited role", response); + }, + }, + grantRoleToAuthor: { + name: "Grant Role to Author", + async execute(roleVanity, authorVanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/grant/${roleVanity}/${authorVanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("granted role", response); + }, + }, + revokeRoleFromAuthor: { + name: "Revoke Role from Author", + async execute(roleVanity, authorVanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/revoke/${roleVanity}/${authorVanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log("granted role", response); + }, + }, + privilegeGrantRole: { + name: "Grant Privileges to Role", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/grant/role/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("granted privileges to role", response); + }, + }, + privilegeRevokeRole: { + name: "Revoke Privileges from Role", + async execute(vanity, ...privileges) { + const response = await fetch(`${Env_5.default.API_ORIGIN}privilege/revoke/role/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + privileges, + }), + }).then(response => response.json()); + console.log("revoked privileges from role", response); + }, + }, + roleListAll: { + name: "List all roles", + async execute(label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + roleReorder: { + name: "Reorder roles", + async execute(...roles) { + const response = await fetch(`${Env_5.default.API_ORIGIN}role/reorder`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + roles, + }), + }).then(response => response.json()); + console.log("reordered roles", response); + }, + }, + createCommentChapter: { + name: "Create Comment Chapter", + async execute(author, vanity, index, body, parent_id) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapter/${index}/comment/add`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + body, + parent_id, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + updateCommentChapter: { + name: "Update Comment Chapter", + async execute(id, comment_body) { + const response = await fetch(`${Env_5.default.API_ORIGIN}comment/update/chapter`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + body: comment_body, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + deleteCommentChapter: { + name: "Delete Comment Chapter", + async execute(id) { + await fetch(`${Env_5.default.API_ORIGIN}comment/remove/chapter`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + }), + }); + }, + }, + getComment: { + name: "Get Comment", + async execute(id, label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}comment/get`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + comment_id: id, + }), + }).then(response => response.json()); + console.log(label, response); + }, + }, + getAllComments: { + name: "Get All Comments", + async execute(author, vanity, index) { + const response = await fetch(`${Env_5.default.API_ORIGIN}work/${author}/${vanity}/chapter/${index}/comments`, { + credentials: "include", + }).then(response => response.json()); + console.log(response); + }, + }, + patreonGetTiers: { + name: "Get Tiers", + async execute(label) { + const response = await fetch(`${Env_5.default.API_ORIGIN}patreon/campaign/tiers/get`, { + credentials: "include", + }).then(response => response.json()); + console.log(label, response); + }, + }, + patreonSetThresholds: { + name: "Set Chapter Thresholds", + async execute(author_vanity, work_vanity, visibility, chapters, tier_id) { + const response = await fetch(`${Env_5.default.API_ORIGIN}patreon/campaign/tiers/set/${author_vanity}/${work_vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + visibility: visibility, + chapters: chapters, + tier_id: tier_id, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagCreateCategory: { + name: "Tag Create Category", + async execute(categoryName, categoryDescription) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/create/category`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: categoryName, + description: categoryDescription, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagCreateGlobal: { + name: "Tag Create Global", + async execute(tagName, tagDescription, tagCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/create/global`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: tagName, + description: tagDescription, + category: tagCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagPromoteCustom: { + name: "Tag Promote Custom", + async execute(tagName, newDescription, newCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/promote/${tagName}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + description: newDescription, + category: newCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagDemoteGlobal: { + name: "Tag Demote Global", + async execute(tagName) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/demote/${tagName}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagUpdateCategory: { + name: "Tag Update Category", + async execute(vanity, categoryName, categoryDescription) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/update/category/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: categoryName, + description: categoryDescription, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagUpdateGlobal: { + name: "Tag Update Global", + async execute(vanity, tagName, tagDescription, tagCategory) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/update/global/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: tagName, + description: tagDescription, + category: tagCategory, + }), + }).then(response => response.json()); + console.log(response); + }, + }, + tagRemoveCategory: { + name: "Tag Remove Category", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/remove/category/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagRemoveGlobal: { + name: "Tag Remove Global", + async execute(vanity) { + const response = await fetch(`${Env_5.default.API_ORIGIN}tag/remove/global/${vanity}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + tagGetManifest: { + name: "Tag Get Manifest", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}manifest/tags`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + manifestFormLengthGet: { + name: "Form Length Manifest", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}manifest/form/lengths`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsGet: { + name: "Get Notifications", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}notifications/get/all`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsGetUnread: { + name: "Get Unread Notifications", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}notifications/get/unread`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + notificationsMark: { + name: "Mark Notifications Read/Unread", + async execute(state, notifications) { + await fetch(`${Env_5.default.API_ORIGIN}notifications/mark/${state}`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + notification_ids: notifications, + }), + }); + }, + }, + seedBulk: { + name: "Seed Bulk", + async execute() { + await fetch(`${Env_5.default.API_ORIGIN}seed/bulk`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }); + }, + }, + feedGet: { + name: "Get Feed", + async execute() { + const response = await fetch(`${Env_5.default.API_ORIGIN}feed/get`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }).then(response => response.json()); + console.log(response); + }, + }, + }; +}); +define("ui/view/DebugView", ["require", "exports", "endpoint/auth/EndpointAuthServices", "model/Session", "ui/Component", "ui/component/core/Button", "ui/view/debug/ButtonRegistry", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Env", "utility/Objects", "utility/Popup"], function (require, exports, EndpointAuthServices_2, Session_11, Component_45, Button_12, ButtonRegistry_1, View_6, ViewDefinition_5, Env_6, Objects_4, Popup_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointAuthServices_2 = __importDefault(EndpointAuthServices_2); + Session_11 = __importDefault(Session_11); + Component_45 = __importDefault(Component_45); + Button_12 = __importDefault(Button_12); + View_6 = __importDefault(View_6); + ViewDefinition_5 = __importDefault(ViewDefinition_5); + Env_6 = __importDefault(Env_6); + Objects_4 = __importDefault(Objects_4); + Popup_2 = __importDefault(Popup_2); + const Block = Component_45.default.Builder(component => component + .style("debug-block")); + exports.default = (0, ViewDefinition_5.default)({ + async create() { + const view = (0, View_6.default)("debug"); + const createButton = (implementation, ...args) => { + return (0, Button_12.default)() + .text.set(implementation.name) + .event.subscribe("click", async () => { + try { + await implementation.execute(...args); + } + catch (err) { + const error = err; + console.warn(`Button ${implementation.name} failed to execute:`, error); + } + }); + }; + const oauthDiv = Block().appendTo(view); + const OAuthServices = await EndpointAuthServices_2.default.query(); + for (const service of Objects_4.default.values(OAuthServices.data ?? {})) { + if (!service) + continue; + (0, Button_12.default)() + .text.set(`OAuth ${service.name}`) + .event.subscribe("click", async () => { + await (0, Popup_2.default)(`OAuth ${service.name}`, service.url_begin, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(oauthDiv); + (0, Button_12.default)() + .text.set(`UnOAuth ${service.name}`) + .event.subscribe("click", async () => { + const id = Session_11.default.Auth.get(service.id)?.id; + if (id === undefined) + return; + await fetch(`${Env_6.default.API_ORIGIN}auth/remove`, { + method: "POST", + credentials: "include", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ id }), + }); + }) + .appendTo(oauthDiv); + } + // document.body.append(createButton(BUTTON_REGISTRY.createAuthor, "test author 1", "hi-im-an-author")); + oauthDiv.append(createButton(ButtonRegistry_1.BUTTON_REGISTRY.clearSession)); + const profileButtons = Block().appendTo(view); + profileButtons.append(createButton({ + name: "Seed Bulk Data", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.seedBulk.execute(); + }, + })); + profileButtons.append(createButton({ + name: "Create Profile 1", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("prolific author", "somanystories", "wow a description that mentions ", "she/her pronies m8"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("a debut work", "pretty decent by ", "short description", "debut", "Complete", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "debut", "chapter 1", "woo look it's prolific author's first story!", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("sequel to debut", "wow they wrote a sequel", "sequel short description", "sequel", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "sequel", "the chapters", "pretend there's a story here", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("work in progress", "test", "short description test", "wip", "Ongoing", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("somanystories", "wip", "draft", "it's a rough draft", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "debut"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "sequel"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work", "somanystories", "wip"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "somanystories"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 1", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("author with many stories", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "somanystories"); + }, + })); + profileButtons.append(createButton({ + name: "Create Profile 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("single story author", "justonestory", " writes so much"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("one big work", "made by ", "wow description", "bigstory", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 1", "start of a long story", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story interlude", "middle of a long story", "Public", false, "only notes before"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 2", "aaaa", "Public", true, undefined, "only notes after"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3", "aaaaaaa", "Public", true, "both notes before", "and notes after"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.1", "aaaaaaaaaaaaaaaaaaa", "Public", false); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.2", "aaaaaaaaaaaaaaaaaaa", "Private", false); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 3.3", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 4", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 5", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "bigstory", "big story 6", "aaaaaaaaaaaaaaaaaaa", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateChapter.execute("justonestory", "bigstory", 4, undefined, undefined, undefined, false); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("", "justonestory", "bigstory", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("big story five chapters", "justonestory", "bigstory"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllChapters.execute("justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("0", "justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("4 (3.1)", "justonestory", "bigstory", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("6 (private)", "justonestory", "bigstory", 6); + // await BUTTON_REGISTRY.follow.execute("work", "debut"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("justonestory author", "justonestory"); + }, + })); + profileButtons.append(createButton({ + name: "View Profile 2's stories", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("", "justonestory", "bigstory", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("big story five chapters", "justonestory", "bigstory"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllChapters.execute("justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("0", "justonestory", "bigstory", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("4 (3.1)", "justonestory", "bigstory", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapterPaginated.execute("6 (private)", "justonestory", "bigstory", 6); + }, + })); + // profileButtons.append(createButton({ + // name: "Set Chiri Patreon chapters", + // async execute () { + // await BUTTON_REGISTRY.patreonSetThresholds.execute("justonestory", "bigstory", "Patreon", ["8", "9"], "4392761") + // }, + // })) + const followButtons = Block().appendTo(view); + followButtons.append(createButton({ + name: "Test New Following", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("new follows", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("wow a work", "test pls ignore", "pls ignore", "wowawork", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.follow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.followWork.execute("thefollower", "wowawork"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollow.execute("author", "thefollower"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.unignoreWork.execute("thefollower", "wowawork"); + // await BUTTON_REGISTRY.unfollow.execute("work", "wowawork"); + await ButtonRegistry_1.BUTTON_REGISTRY.getFollowWork.execute("thefollower", "wowawork"); + }, + })); + followButtons.append(createButton({ + name: "Create a work with loads of chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("even longer story", "aaaaaaaaa", "short description aaaaa", "wowbig", "Ongoing", "Public"); + for (let i = 0; i < 2000; i++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("justonestory", "wowbig", `chapter ${i}`, `wow chapter body ${i}`, "Public"); + } + }, + })); + followButtons.append(createButton({ + name: "Follows testing", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work", 0); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollows.execute("work", 1); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(0); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllFollowsMerged.execute(1); + }, + })); + followButtons.append(createButton({ + name: "Spam Create Follow Work Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("spam create works", "manyworks"); + for (let i = 0; i < 100; i++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute(`rapid story ${i}`, "aaaaaaaaa", "rapid story aaaaa", `rapidstory${i}`, "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.follow.execute("work", `rapidstory${i}`); + } + }, + })); + followButtons.append(createButton({ + name: "Test Ignore Endpoints", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("ignoring myself", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("to ignore", "testing ignoring", "test ignoring", "worktoignore", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.ignore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.ignore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("author", "ignorepls"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getIgnore.execute("work", "worktoignore"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("author"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("author"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnores.execute("work"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnoresMerged.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllIgnoresMerged.execute(); + }, + })); + const privRoleButtons = Block().appendTo(view); + privRoleButtons.append(createButton({ + name: "privileges initial test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "WorkViewPrivate", "PrivilegeViewAuthor"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGetAllAuthor.execute("privileges of somanystories", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeAuthor.execute("somanystories", "WorkViewPrivate"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RevokePrivilege"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeAuthor.execute("somanystories", "WorkViewPrivate"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "ThisPrivilegeDoesntExist"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGetAllAuthor.execute("privileges of somanystories", "somanystories"); + }, + })); + privRoleButtons.append(createButton({ + name: "grant privs for testing", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "PrivilegeRevoke", "RoleCreate", "RoleEdit", "RoleDelete", "RoleGrant", "RoleRevoke", "PrivilegeViewAuthor", "RoleViewAll"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("TestingRevoke", "Visible"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("TestingRevoke", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.revokeRoleFromAuthor.execute("TestingRevoke", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantRole.execute("TestingRevoke", "ViewAllRoles"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeRevokeRole.execute("TestingRevoke", "ViewAllRoles"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteRole.execute("TestingRevoke"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("SecondAuthorRole", "Visible"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("SecondAuthorRole", "justonestory"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantRole.execute("SecondAuthorRole", "RoleEdit", "RoleDelete", "RoleCreate"); + // await BUTTON_REGISTRY.privilegeGrantAuthor.execute("justonestory", "ViewPrivateStories"); + }, + })); + privRoleButtons.append(createButton({ + name: "second author test stuff", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("DontWork", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("DoWork", "SecondAuthorRole"); + await ButtonRegistry_1.BUTTON_REGISTRY.editRole.execute("Admin", "CantDoThis"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteRole.execute("SecondAuthorRole"); + }, + })); + privRoleButtons.append(createButton({ + name: "see highest level", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleViewAll", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("NotTopRole", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("NotTopRole", "somanystories"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("listing all roles"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("listing all roles"); + }, + })); + privRoleButtons.append(createButton({ + name: "role reorder test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleViewAll", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role1", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role2", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role3", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role4", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleReorder.execute("Role1", "Role2", "Role3", "Role4"); + }, + })); + const moreRoleButtons = Block().appendTo(view); + moreRoleButtons.append(createButton({ + name: "Make ten billion works", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("lots of works test", "manyworks", "test description"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("manyworks", "TagGlobalCreate", "TagGlobalDelete", "TagGlobalUpdate", "TagCategoryCreate", "TagCategoryUpdate", "TagCategoryDelete", "TagPromote", "TagDemote"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category One", "the first test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Two", "the second test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Three", "the third test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag One", "test tag 1", "Category One"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Two", "test tag 1", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Three", "test tag 1", "Category Three"); + for (let a = 0; a < 333; a++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute(`work${a}`, `description no ${a} mentions \n"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."`, "Lorem ipsum dolor sit amet, consectetur adipiscing elit,", `testwork${a}`, "Ongoing", "Public", ["Category One: Tag One", "Category Two: Tag Two", "Category Three: Tag Three"], ["custom tag one", `custom tag two ${a}`]); + } + for (let a = 0; a < 333; a++) { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("manyworks", `testwork${a}`, `chapter ${a}`, `it's a test chapter ${a}`, "Public"); + } + }, + })); + moreRoleButtons.append(createButton({ + name: "view ten billion works", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("many works", "manyworks"); + }, + })); + moreRoleButtons.append(createButton({ + name: "admin list roles test (profile 1)", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("somanystories", "RoleGrant", "RoleCreate"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role4", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role3", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role2", "Hidden", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.createRole.execute("Role1", "Visible", "Admin"); + await ButtonRegistry_1.BUTTON_REGISTRY.grantRoleToAuthor.execute("Role2", "justonestory"); + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("all roles admin"); + }, + })); + moreRoleButtons.append(createButton({ + name: "user list roles test (profile 2)", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.roleListAll.execute("all roles user"); + }, + })); + moreRoleButtons.append(createButton({ + name: "Delete Author Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.deleteAuthor.execute(); + }, + })); + const commentsButton = Block().appendTo(view); + commentsButton.append(createButton({ + name: "Author 2 lots of comments", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comments 1"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "2", "base comments 2"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "3", "base comments 3"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "4", "base comments 4"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "5", "base comments 5"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment ", "6"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 2", "6"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 3", "11"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 4", "12"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comment index 1"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 6", "13"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "child comment 7", "11"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("justonestory", "bigstory", "1", "base comment index 1 again"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllComments.execute("justonestory", "bigstory", "1"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("1", "get comment"); + }, + })); + commentsButton.append(createButton({ + name: "Author 2 just get comments", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.getAllComments.execute("justonestory", "bigstory", "1"); + }, + })); + commentsButton.append(createButton({ + name: "Author 1 single comment ping", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("somanystories", "debut", "1", "wow you write so many stories @somanystories how do you do it"); + await ButtonRegistry_1.BUTTON_REGISTRY.createCommentChapter.execute("somanystories", "debut", "1", "@somanystories you're so @somanystories amazing"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("5"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateCommentChapter.execute("4", "okay done fawning over @somanystories now"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.deleteCommentChapter.execute("5"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("5"); + }, + })); + commentsButton.append(createButton({ + name: "try to delete author 1's comment", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.deleteCommentChapter.execute("4"); + await ButtonRegistry_1.BUTTON_REGISTRY.getComment.execute("4"); + }, + })); + const patreonButtons = Block().appendTo(view); + (0, Button_12.default)() + .text.set("Campaign Test") + .event.subscribe("click", async () => { + await (0, Popup_2.default)("Campaign OAuth", `${Env_6.default.API_ORIGIN}auth/patreon/campaign/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(patreonButtons); + patreonButtons.append(createButton({ + name: "create patreon author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("has a campaign", "patreonuser"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("patreon only story", "test", "short description test", "exclusive", "Ongoing", "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 1", "hewwo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 2", "hewwoo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 3", "hewwooo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 4", "hewwooo", "Private"); + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("patreonuser", "exclusive", "chapter 5", "hewwooo", "Private"); + }, + })); + patreonButtons.append(createButton({ + name: "get patreon tiers", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.patreonGetTiers.execute("patreon tiers"); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonGetTiers.execute("patreon tiers"); + }, + })); + patreonButtons.append(createButton({ + name: "set patreon chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.updateChapter.execute("patreonuser", "exclusive", 1, undefined, undefined, "Public"); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Public", ["2", "3"]); + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Patreon", ["4", "5"], "4392761"); + }, + })); + (0, Button_12.default)() + .text.set("Patron Test") + .event.subscribe("click", async () => { + await (0, Popup_2.default)("Patron OAuth", `${Env_6.default.API_ORIGIN}auth/patreon/patron/begin`, 600, 900) + .then(() => true).catch(err => { console.warn(err); return false; }); + await Session_11.default.refresh(); + }) + .appendTo(patreonButtons); + patreonButtons.append(createButton({ + name: "get patreon-only chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("public:", "patreonuser", "exclusive", 3); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("public:", "patreonuser", "exclusive", 3); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("patreon:", "patreonuser", "exclusive", 4); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("patreon:", "patreonuser", "exclusive", 4); + }, + })); + patreonButtons.append(createButton({ + name: "update patreon-only chapters", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.patreonSetThresholds.execute("patreonuser", "exclusive", "Public", ["4"]); + }, + })); + const tagButtons = Block().appendTo(view); + tagButtons.append(createButton({ + name: "Create Tag Author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createAuthor.execute("tagging test", "thetagger", "test description"); + await ButtonRegistry_1.BUTTON_REGISTRY.privilegeGrantAuthor.execute("thetagger", "TagGlobalCreate", "TagGlobalDelete", "TagGlobalUpdate", "TagCategoryCreate", "TagCategoryUpdate", "TagCategoryDelete", "TagPromote", "TagDemote"); + }, + })); + tagButtons.append(createButton({ + name: "Update Tag Author", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateAuthor.execute("the tagger 2", "wow i'm "); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewAuthor.execute("view post-update", "thetagger"); + }, + })); + tagButtons.append(createButton({ + name: "Tag Create Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category One", "the first test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Two", "the second test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateCategory.execute("Category Three", "the third test category"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag One", "test tag 1 ", "Category One"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateGlobal.execute("Category One: Tag One", "Tag One Updated", "test tag 1 updated", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateCategory.execute("Category One", "Category One Updated", "first test category updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagRemoveCategory.execute("Category One Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagRemoveGlobal.execute("Category Two: Tag One Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagUpdateGlobal.execute("Category Three: tag conflict", undefined, undefined, "Category Two"); + }, + })); + tagButtons.append(createButton({ + name: "Work Tag Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Two", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Three", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Four", "test tag 2", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("Tag Test Work", "test", "desc test", "testwork", "Ongoing", "Public", ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 1", "custom tag 2"]); + await ButtonRegistry_1.BUTTON_REGISTRY.createWork.execute("Tag Test Work Two", "test2", "desc test", "testworktwo", "Ongoing", "Public", ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 2", "custom tag 3"]); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 1", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 2", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.updateWork.execute("thetagger", "testworktwo", "Test Work Two Updated"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 3", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 4", "thetagger", "testworktwo"); + await ButtonRegistry_1.BUTTON_REGISTRY.getAllWorksByAuthor.execute("all works", "thetagger"); + }, + })); + tagButtons.append(createButton({ + name: "Chapter Tag Test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.createChapter.execute("thetagger", "testworktwo", "test chapter", "test chapter body", "Public", true, undefined, undefined, ["Category Two: Tag Two", "Category Two: Tag Three"], ["custom tag 2", "custom tag 3", "custom tag 4"]); + await ButtonRegistry_1.BUTTON_REGISTRY.viewChapter.execute("chapter", "thetagger", "testworktwo", 1); + }, + })); + tagButtons.append(createButton({ + name: "Tag Promote/Demote", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagPromoteCustom.execute("custom tag 1", "test description", "Category Two"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagDemoteGlobal.execute("Category Two: Tag Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 3", "thetagger", "testwork"); + await ButtonRegistry_1.BUTTON_REGISTRY.viewWork.execute("work view 4", "thetagger", "testworktwo"); + }, + })); + tagButtons.append(createButton({ + name: "manifest test", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagGetManifest.execute(); + }, + })); + tagButtons.append(createButton({ + name: "manifest test 2", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.tagCreateGlobal.execute("extra tag", "wow", "Category Three"); + await ButtonRegistry_1.BUTTON_REGISTRY.tagGetManifest.execute(); + }, + })); + tagButtons.append(createButton({ + name: "form length manifest", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.manifestFormLengthGet.execute(); + }, + })); + const notifButtons = Block().appendTo(view); + notifButtons.append(createButton({ + name: "Get Notifications", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsGet.execute(); + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsGetUnread.execute(); + }, + })); + notifButtons.append(createButton({ + name: "Mark Notifications Read", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsMark.execute("read", ["ba397c1b-02e5-462c-b367-04b007d1f09a", "d8830a0c-3e2c-4caa-ae4b-679a8c5cefa5"]); + await ButtonRegistry_1.BUTTON_REGISTRY.notificationsMark.execute("unread", ["ba397c1b-02e5-462c-b367-04b007d1f09a", "3b9781ea-d15d-4915-bbeb-4788ed734453"]); + }, + })); + notifButtons.append(createButton({ + name: "Get Front Page Feed", + async execute() { + await ButtonRegistry_1.BUTTON_REGISTRY.feedGet.execute(); + }, + })); + return view; + }, + }); +}); +define("endpoint/feed/EndpointFeedGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_17) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_17 = __importDefault(Endpoint_17); + exports.default = (0, Endpoint_17.default)("/feed/get", "get"); +}); +define("ui/view/FeedView", ["require", "exports", "endpoint/feed/EndpointFeedGet", "ui/Component", "ui/component/core/Link", "ui/component/core/Paginator", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, EndpointFeedGet_1, Component_46, Link_4, Paginator_3, Work_3, View_7, ViewDefinition_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointFeedGet_1 = __importDefault(EndpointFeedGet_1); + Component_46 = __importDefault(Component_46); + Link_4 = __importDefault(Link_4); + Paginator_3 = __importDefault(Paginator_3); + Work_3 = __importDefault(Work_3); + View_7 = __importDefault(View_7); + ViewDefinition_6 = __importDefault(ViewDefinition_6); + exports.default = (0, ViewDefinition_6.default)({ + create: async () => { + const view = (0, View_7.default)("feed"); + const paginator = (0, Paginator_3.default)() + .viewTransition("author-view-feed") + .type("flush") + .tweak(p => p.title.text.use("view/feed/main/title")) + .appendTo(view); + const endpoint = EndpointFeedGet_1.default.prep().setPageSize(3); + await paginator.useEndpoint(endpoint, async (slot, { works, authors }) => { + for (const workData of works) { + const author = authors.find(author => author.vanity === workData.author); + const work = await (0, Link_4.default)(author && `/work/${author.vanity}/${workData.vanity}`) + .and(Work_3.default, workData, author, true); + work + .viewTransition() + .appendTo(slot); + } + }); + paginator.orElse(slot => (0, Component_46.default)() + .style("placeholder") + .text.use("view/feed/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("ui/view/HomeView", ["require", "exports", "markdown-it", "ui/Component", "ui/component/core/Block", "ui/component/core/TextEditor", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Env", "utility/string/MarkdownItHTML"], function (require, exports, markdown_it_3, Component_47, Block_10, TextEditor_3, View_8, ViewDefinition_7, Env_7, MarkdownItHTML_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + markdown_it_3 = __importDefault(markdown_it_3); + Component_47 = __importDefault(Component_47); + Block_10 = __importDefault(Block_10); + TextEditor_3 = __importDefault(TextEditor_3); + View_8 = __importDefault(View_8); + ViewDefinition_7 = __importDefault(ViewDefinition_7); + Env_7 = __importDefault(Env_7); + MarkdownItHTML_3 = __importDefault(MarkdownItHTML_3); + exports.default = (0, ViewDefinition_7.default)({ + create: () => { + const view = (0, View_8.default)("home"); + const block = (0, Block_10.default)().appendTo(view); + block.title.text.set("Test the text editor"); + block.description.text.set("fluff4.me is still a work-in-progress. In the meantime, feel free to play with this!"); + // const form = block.and(Form, block.title) + (0, TextEditor_3.default)() + .appendTo(block.content); + if (Env_7.default.isDev) { + (0, Component_47.default)("br").appendTo(block.content); + const output = (0, Component_47.default)("div"); + (0, Component_47.default)("div") + .attributes.set("contenteditable", "plaintext-only") + .style.setProperty("white-space", "pre-wrap") + .style.setProperty("font", "inherit") + .style.setProperty("background", "#222") + .style.setProperty("width", "100%") + .style.setProperty("height", "400px") + .style.setProperty("padding", "0.5em") + .style.setProperty("box-sizing", "border-box") + .event.subscribe("input", event => { + const text = event.component.element.textContent ?? ""; + const md = new markdown_it_3.default("commonmark", { html: true, breaks: true }); + MarkdownItHTML_3.default.use(md, MarkdownItHTML_3.default.Options() + .disallowTags("img", "figure", "figcaption", "map", "area")); + console.log(md.parse(text, {})); + output.element.innerHTML = md.render(text); + }) + .appendTo(block.content); + output + .style.setProperty("font", "inherit") + .style.setProperty("background", "#222") + .style.setProperty("width", "100%") + .style.setProperty("padding", "0.5em") + .style.setProperty("margin-top", "1em") + .style.setProperty("box-sizing", "border-box") + .appendTo(block.content); + } + return view; + }, + }); +}); +define("ui/view/TagView", ["require", "exports", "model/Tags", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Errors"], function (require, exports, Tags_2, View_9, ViewDefinition_8, Errors_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Tags_2 = __importDefault(Tags_2); + View_9 = __importDefault(View_9); + ViewDefinition_8 = __importDefault(ViewDefinition_8); + Errors_2 = __importDefault(Errors_2); + const fromURLRegex = /(-|^)(.)/g; + const fromURL = (name) => name.replaceAll(fromURLRegex, (_, dash, char) => `${dash ? " " : ""}${char.toUpperCase()}`); + exports.default = (0, ViewDefinition_8.default)({ + create: async (params) => { + const view = (0, View_9.default)("tag"); + const tag = await Tags_2.default.resolve(fromURL(params.category), fromURL(params.name)); + if (!tag) + throw Errors_2.default.NotFound(); + return view; + }, + }); +}); +define("endpoint/work/EndpointWorkCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_18) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_18 = __importDefault(Endpoint_18); + exports.default = (0, Endpoint_18.default)("/work/create", "post"); +}); +define("endpoint/work/EndpointWorkUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_19) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_19 = __importDefault(Endpoint_19); + exports.default = (0, Endpoint_19.default)("/work/{author}/{vanity}/update", "post"); +}); +define("ui/component/core/Textarea", ["require", "exports", "ui/Component", "ui/component/core/ext/Input", "ui/utility/StringApplicator", "utility/State"], function (require, exports, Component_48, Input_4, StringApplicator_7, State_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_48 = __importDefault(Component_48); + Input_4 = __importDefault(Input_4); + StringApplicator_7 = __importDefault(StringApplicator_7); + State_26 = __importDefault(State_26); + const Textarea = Component_48.default.Builder((component) => { + let shouldIgnoreInputEvent = false; + const input = component + .and(Input_4.default) + .style("text-input", "text-area") + .attributes.set("contenteditable", "plaintext-only") + .ariaRole("textbox") + .attributes.set("aria-multiline", "true") + .extend(input => ({ + value: "", + state: (0, State_26.default)(""), + default: (0, StringApplicator_7.default)(input, value => { + if (input.value === "") { + input.value = value ?? ""; + input.state.value = value ?? ""; + input.length.value = value?.length ?? 0; + } + }), + placeholder: (0, StringApplicator_7.default)(input, value => { + input.attributes.set("placeholder", value); + }), + ignoreInputEvent: (ignore = true) => { + shouldIgnoreInputEvent = ignore; + return input; + }, + setLabel(label) { + component.setName(label?.for); + component.setId(label?.for); + label?.setInput(input); + component.ariaLabelledBy(label); + return input; + }, + })) + .extendMagic("value", input => ({ + get: () => input.element.textContent || "", + set: (value) => { + input.element.textContent = value; + input.state.value = value; + input.length.value = value.length; + }, + })); + input.length.value = 0; + input.onRooted(input => { + input.event.subscribe(["input", "change"], event => { + if (shouldIgnoreInputEvent) + return; + input.state.value = input.value; + input.length.value = input.value.length; + }); + }); + return input; + }); + exports.default = Textarea; +}); +define("ui/view/work/WorkEditForm", ["require", "exports", "endpoint/work/EndpointWorkCreate", "endpoint/work/EndpointWorkUpdate", "lang/en-nz", "model/FormInputLengths", "model/Session", "ui/Component", "ui/component/core/Block", "ui/component/core/Form", "ui/component/core/LabelledTable", "ui/component/core/Textarea", "ui/component/core/TextEditor", "ui/component/core/TextInput", "ui/component/core/toast/Toast"], function (require, exports, EndpointWorkCreate_1, EndpointWorkUpdate_1, en_nz_7, FormInputLengths_3, Session_12, Component_49, Block_11, Form_4, LabelledTable_3, Textarea_1, TextEditor_4, TextInput_5, Toast_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointWorkCreate_1 = __importDefault(EndpointWorkCreate_1); + EndpointWorkUpdate_1 = __importDefault(EndpointWorkUpdate_1); + en_nz_7 = __importDefault(en_nz_7); + FormInputLengths_3 = __importDefault(FormInputLengths_3); + Session_12 = __importDefault(Session_12); + Component_49 = __importDefault(Component_49); + Block_11 = __importDefault(Block_11); + Form_4 = __importDefault(Form_4); + LabelledTable_3 = __importDefault(LabelledTable_3); + Textarea_1 = __importDefault(Textarea_1); + TextEditor_4 = __importDefault(TextEditor_4); + TextInput_5 = __importDefault(TextInput_5); + exports.default = Component_49.default.Builder((component, state) => { + const block = component.and(Block_11.default); + const form = block.and(Form_4.default, block.title); + form.viewTransition("work-edit-form"); + const type = state.value ? "update" : "create"; + form.title.text.use(`view/work-edit/${type}/title`); + form.setName(en_nz_7.default[`view/work-edit/${type}/title`]().toString()); + // if (params.type === "create") + // form.description.text.use("view/work-edit/create/description") + form.submit.textWrapper.text.use(`view/work-edit/${type}/submit`); + const table = (0, LabelledTable_3.default)().appendTo(form.content); + const nameInput = (0, TextInput_5.default)() + .setRequired() + .default.bind(state.map(component, work => work?.name)) + .hint.use("view/work-edit/shared/form/name/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.name); + table.label(label => label.text.use("view/work-edit/shared/form/name/label")) + .content((content, label) => content.append(nameInput.setLabel(label))); + const vanityInput = (0, TextInput_5.default)() + .placeholder.bind(nameInput.state + .map(component, name => filterVanity(name))) + .default.bind(state.map(component, work => work?.vanity)) + .filter(filterVanity) + .hint.use("view/work-edit/shared/form/vanity/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.vanity); + table.label(label => label.text.use("view/work-edit/shared/form/vanity/label")) + .content((content, label) => content.append(vanityInput.setLabel(label))); + const descriptionInput = (0, Textarea_1.default)() + .default.bind(state.map(component, work => work?.description)) + .hint.use("view/work-edit/shared/form/description/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.description); + table.label(label => label.text.use("view/work-edit/shared/form/description/label")) + .content((content, label) => content.append(descriptionInput.setLabel(label))); + const synopsisInput = (0, TextEditor_4.default)() + .default.bind(state.map(component, work => work?.synopsis.body)) + .hint.use("view/work-edit/shared/form/synopsis/hint") + .setMaxLength(FormInputLengths_3.default.manifest?.work.synopsis); + table.label(label => label.text.use("view/work-edit/shared/form/synopsis/label")) + .content((content, label) => content.append(synopsisInput.setLabel(label))); + form.event.subscribe("submit", async (event) => { + event.preventDefault(); + const name = nameInput.value; + const response = await (() => { + switch (type) { + case "create": + return EndpointWorkCreate_1.default.query({ + body: { + name, + vanity: vanityInput.value, + description: descriptionInput.value, + synopsis: synopsisInput.useMarkdown(), + }, + }); + case "update": { + if (!state.value) + return; + const authorVanity = Session_12.default.Auth.author.value?.vanity; + if (!authorVanity) + return new Error("Cannot update a work when not signed in"); + return EndpointWorkUpdate_1.default.query({ + params: { + author: authorVanity, + vanity: state.value.vanity, + }, + body: { + name, + vanity: vanityInput.value, + description: descriptionInput.value, + synopsis: synopsisInput.useMarkdown(), + }, + }); + } + } + })(); + if (response instanceof Error) { + toast.warning(Toast_3.TOAST_ERROR, quilt => quilt["view/work-edit/shared/toast/failed-to-save"](name), response); + console.error(response); + return; + } + toast.success(Toast_3.TOAST_SUCCESS, quilt => quilt["view/work-edit/shared/toast/saved"](name)); + state.value = response?.data; + }); + return form; + function filterVanity(vanity, textBefore = "", isFullText = true) { + vanity = vanity.replace(/[\W_]+/g, "-"); + if (isFullText) + vanity = vanity.replace(/^-|-$/g, ""); + if (textBefore.endsWith("-") && vanity.startsWith("-")) + return vanity.slice(1); + return vanity; + } + }); +}); +define("ui/view/WorkEditView", ["require", "exports", "endpoint/work/EndpointWorkGet", "ui/component/core/ActionRow", "ui/component/core/Button", "ui/component/core/Slot", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "ui/view/shared/ext/ViewTransition", "ui/view/work/WorkEditForm", "utility/State"], function (require, exports, EndpointWorkGet_2, ActionRow_5, Button_13, Slot_9, View_10, ViewDefinition_9, ViewTransition_4, WorkEditForm_1, State_27) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointWorkGet_2 = __importDefault(EndpointWorkGet_2); + ActionRow_5 = __importDefault(ActionRow_5); + Button_13 = __importDefault(Button_13); + Slot_9 = __importDefault(Slot_9); + View_10 = __importDefault(View_10); + ViewDefinition_9 = __importDefault(ViewDefinition_9); + ViewTransition_4 = __importDefault(ViewTransition_4); + WorkEditForm_1 = __importDefault(WorkEditForm_1); + State_27 = __importDefault(State_27); + exports.default = (0, ViewDefinition_9.default)({ + requiresLogin: true, + create: async (params) => { + const id = "work-edit"; + const view = (0, View_10.default)(id); + const work = params && await EndpointWorkGet_2.default.query({ params }); + if (work instanceof Error) + throw work; + const state = (0, State_27.default)(work?.data); + const stateInternal = (0, State_27.default)(work?.data); + (0, Slot_9.default)() + .use(state, () => (0, WorkEditForm_1.default)(stateInternal).subviewTransition(id)) + .appendTo(view); + (0, Slot_9.default)() + .use(state, () => createActionRow()?.subviewTransition(id)) + .appendTo(view); + stateInternal.subscribe(view, work => ViewTransition_4.default.perform("subview", id, () => state.value = work)); + return view; + function createActionRow() { + if (!stateInternal.value) + return; + return (0, ActionRow_5.default)() + .viewTransition("work-edit-action-row") + .tweak(row => row.right + .append((0, Button_13.default)() + .text.use("view/work-edit/update/action/delete") + .event.subscribe("click", async () => { + // const response = await EndpointAuthorDelete.query() + // if (response instanceof Error) { + // console.error(response) + // return + // } + // return Session.reset() + }))); + } + }, + }); +}); +define("endpoint/chapter/EndpointChapterGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_20) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_20 = __importDefault(Endpoint_20); + exports.default = (0, Endpoint_20.default)("/work/{author}/{vanity}/chapters/list", "get"); +}); +define("ui/component/Chapter", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/ext/CanHasActionsMenuButton", "ui/component/core/Link", "ui/component/core/Timestamp", "utility/maths/Maths"], function (require, exports, Session_13, Component_50, Button_14, CanHasActionsMenuButton_2, Link_5, Timestamp_2, Maths_2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_13 = __importDefault(Session_13); + Component_50 = __importDefault(Component_50); + Button_14 = __importDefault(Button_14); + CanHasActionsMenuButton_2 = __importDefault(CanHasActionsMenuButton_2); + Link_5 = __importDefault(Link_5); + Timestamp_2 = __importDefault(Timestamp_2); + Maths_2 = __importDefault(Maths_2); + const Chapter = Component_50.default.Builder((component, chapter, work, author) => { + component = (0, Link_5.default)(`/work/${author.vanity}/${work.vanity}/chapter/${chapter.url}`) + .style("chapter"); + const chapterNumber = Maths_2.default.parseIntOrUndefined(chapter.url); + const number = (0, Component_50.default)() + .style("chapter-number") + .text.set(chapterNumber ? `${chapterNumber.toLocaleString()}` : "") + .appendTo(component); + const chapterName = (0, Component_50.default)() + .style("chapter-name") + .text.set(chapter.name) + .appendTo(component); + const right = (0, Component_50.default)() + .style("chapter-right") + .appendTo(component); + const timestamp = !chapter.time_last_update ? undefined + : (0, Timestamp_2.default)(chapter.time_last_update) + .style("chapter-timestamp") + .appendTo(right); + return component + .and(CanHasActionsMenuButton_2.default, button => button + .type("inherit-size") + .style("chapter-actions-menu-button") + .style.bind(component.hoveredOrHasFocused.not, "chapter-actions-menu-button--not-focused") + .appendTo(right)) + .setActionsMenu((popover, button) => { + if (author && author.vanity === Session_13.default.Auth.author.value?.vanity) { + (0, Button_14.default)() + .type("flush") + .text.use("view/work/chapters/action/label/edit") + .event.subscribe("click", () => navigate.toURL(`/work/${author.vanity}/${work.vanity}/chapter/${chapter.url}/edit`)) + .appendTo(popover); + (0, Button_14.default)() + .type("flush") + .text.use("view/author/works/action/label/delete") + .event.subscribe("click", () => { }) + .appendTo(popover); + } + }) + .tweak(component => component.actionsMenuButton) + .extend(component => ({ + chapter, + number, + chapterName, + timestamp, + })); + }); + exports.default = Chapter; +}); +define("ui/view/WorkView", ["require", "exports", "endpoint/chapter/EndpointChapterGetAll", "endpoint/work/EndpointWorkGet", "model/Session", "ui/Component", "ui/component/Chapter", "ui/component/core/Button", "ui/component/core/Paginator", "ui/component/core/Slot", "ui/component/Work", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition", "utility/Errors"], function (require, exports, EndpointChapterGetAll_1, EndpointWorkGet_3, Session_14, Component_51, Chapter_1, Button_15, Paginator_4, Slot_10, Work_4, View_11, ViewDefinition_10, Errors_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + EndpointChapterGetAll_1 = __importDefault(EndpointChapterGetAll_1); + EndpointWorkGet_3 = __importDefault(EndpointWorkGet_3); + Session_14 = __importDefault(Session_14); + Component_51 = __importDefault(Component_51); + Chapter_1 = __importDefault(Chapter_1); + Button_15 = __importDefault(Button_15); + Paginator_4 = __importDefault(Paginator_4); + Slot_10 = __importDefault(Slot_10); + Work_4 = __importDefault(Work_4); + View_11 = __importDefault(View_11); + ViewDefinition_10 = __importDefault(ViewDefinition_10); + Errors_3 = __importDefault(Errors_3); + exports.default = (0, ViewDefinition_10.default)({ + create: async (params) => { + const view = (0, View_11.default)("work"); + const response = await EndpointWorkGet_3.default.query({ params }); + if (response instanceof Error) + throw response; + const workData = response.data; + const authorData = workData.synopsis.mentions.find(author => author.vanity === params.author); + if (!authorData) + throw Errors_3.default.BadData("Work author not in synopsis authors"); + const work = await (0, Work_4.default)(workData, authorData); + work + .viewTransition("work-view-work") + .setContainsHeading() + .appendTo(view); + const paginator = (0, Paginator_4.default)() + .viewTransition("work-view-chapters") + .tweak(p => p.title.text.use("view/work/chapters/title")) + .tweak(p => p.primaryActions.append((0, Slot_10.default)() + .if(Session_14.default.Auth.loggedIn, () => (0, Button_15.default)() + .setIcon("plus") + .ariaLabel.use("view/work/chapters/action/label/new") + .event.subscribe("click", () => navigate.toURL(`/work/${params.author}/${params.vanity}/chapter/new`))))) + .appendTo(view); + const chaptersQuery = EndpointChapterGetAll_1.default.prep({ + params: { + author: params.author, + vanity: params.vanity, + }, + }); + await paginator.useEndpoint(chaptersQuery, (slot, chapters) => { + slot.style("chapter-list"); + for (const chapterData of chapters) + (0, Chapter_1.default)(chapterData, workData, authorData) + .appendTo(slot); + }); + paginator.orElse(slot => (0, Component_51.default)() + .style("placeholder") + .text.use("view/work/chapters/content/empty") + .appendTo(slot)); + return view; + }, + }); +}); +define("navigation/Routes", ["require", "exports", "navigation/Route", "ui/view/AccountView", "ui/view/AuthorView", "ui/view/ChapterEditView", "ui/view/ChapterView", "ui/view/DebugView", "ui/view/FeedView", "ui/view/HomeView", "ui/view/TagView", "ui/view/WorkEditView", "ui/view/WorkView", "utility/Env"], function (require, exports, Route_1, AccountView_1, AuthorView_1, ChapterEditView_1, ChapterView_1, DebugView_1, FeedView_1, HomeView_1, TagView_1, WorkEditView_1, WorkView_1, Env_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Route_1 = __importDefault(Route_1); + AccountView_1 = __importDefault(AccountView_1); + AuthorView_1 = __importDefault(AuthorView_1); + ChapterEditView_1 = __importDefault(ChapterEditView_1); + ChapterView_1 = __importDefault(ChapterView_1); + DebugView_1 = __importDefault(DebugView_1); + FeedView_1 = __importDefault(FeedView_1); + HomeView_1 = __importDefault(HomeView_1); + TagView_1 = __importDefault(TagView_1); + WorkEditView_1 = __importDefault(WorkEditView_1); + WorkView_1 = __importDefault(WorkView_1); + Env_8 = __importDefault(Env_8); + const Routes = [ + (0, Route_1.default)("/debug", DebugView_1.default.navigate), + (0, Route_1.default)("/", Env_8.default.isDev ? FeedView_1.default.navigate : HomeView_1.default.navigate), + (0, Route_1.default)("/account", AccountView_1.default.navigate), + (0, Route_1.default)("/author/$vanity", AuthorView_1.default.navigate), + (0, Route_1.default)("/work/new", WorkEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity", WorkView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/edit", WorkEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/new", ChapterEditView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/$url", ChapterView_1.default.navigate), + (0, Route_1.default)("/work/$author/$vanity/chapter/$url/edit", ChapterEditView_1.default.navigate), + (0, Route_1.default)("/tag/$category/$name", TagView_1.default.navigate), + ]; + exports.default = Routes; +}); +define("ui/view/ErrorView", ["require", "exports", "lang/en-nz", "ui/component/core/Heading", "ui/component/core/Paragraph", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, en_nz_8, Heading_2, Paragraph_3, View_12, ViewDefinition_11) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_8 = __importDefault(en_nz_8); + Heading_2 = __importDefault(Heading_2); + Paragraph_3 = __importDefault(Paragraph_3); + View_12 = __importDefault(View_12); + ViewDefinition_11 = __importDefault(ViewDefinition_11); + exports.default = (0, ViewDefinition_11.default)({ + create: (params) => { + const view = (0, View_12.default)("error"); + if (params.code === 500 && params.error) + console.error(params.error); + (0, Heading_2.default)() + .text.use(quilt => quilt["view/error/title"]({ CODE: params.code })) + .appendTo(view); + const key = `view/error/description-${params.code}`; + if (key in en_nz_8.default) + (0, Paragraph_3.default)() + .text.use(key) + .appendTo(view); + return view; + }, + }); +}); +define("ui/view/RequireLoginView", ["require", "exports", "ui/component/core/ActionRow", "ui/component/core/Block", "ui/component/core/Button", "ui/view/AccountView", "ui/view/shared/component/View", "ui/view/shared/component/ViewDefinition"], function (require, exports, ActionRow_6, Block_12, Button_16, AccountView_2, View_13, ViewDefinition_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + ActionRow_6 = __importDefault(ActionRow_6); + Block_12 = __importDefault(Block_12); + Button_16 = __importDefault(Button_16); + AccountView_2 = __importDefault(AccountView_2); + View_13 = __importDefault(View_13); + ViewDefinition_12 = __importDefault(ViewDefinition_12); + exports.default = (0, ViewDefinition_12.default)({ + create: () => { + const view = (0, View_13.default)("require-login"); + const block = (0, Block_12.default)().appendTo(view); + block.title.text.use("view/shared/login-required/title"); + block.description.text.use("view/shared/login-required/description"); + const actionRow = (0, ActionRow_6.default)() + .appendTo(block); + (0, Button_16.default)() + .type("primary") + .text.use("view/shared/login-required/action") + .event.subscribe("click", () => navigate.ephemeral(AccountView_2.default, undefined)) + .appendTo(actionRow.right); + return view; + }, + }); +}); +define("ui/view/shared/component/ViewContainer", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/Dialog", "ui/view/AccountView", "ui/view/ErrorView", "ui/view/RequireLoginView", "ui/view/shared/ext/ViewTransition"], function (require, exports, Session_15, Component_52, Button_17, Dialog_3, AccountView_3, ErrorView_1, RequireLoginView_1, ViewTransition_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_15 = __importDefault(Session_15); + Component_52 = __importDefault(Component_52); + Button_17 = __importDefault(Button_17); + Dialog_3 = __importDefault(Dialog_3); + AccountView_3 = __importDefault(AccountView_3); + ErrorView_1 = __importDefault(ErrorView_1); + RequireLoginView_1 = __importDefault(RequireLoginView_1); + ViewTransition_5 = __importDefault(ViewTransition_5); + let globalId = 0; + const ViewContainer = () => { + let cancelLogin; + const container = (0, Component_52.default)() + .style("view-container") + .tabIndex("programmatic") + .ariaRole("main") + .ariaLabel.use("view/container/alt") + .extend(container => ({ + show: async (definition, params) => { + const showingId = ++globalId; + let view; + let loadParams = undefined; + const needsLogin = definition.requiresLogin && !Session_15.default.Auth.loggedIn.value; + if (needsLogin || definition.load) { + let loginPromise; + const transition = ViewTransition_5.default.perform("view", async () => { + swapRemove(); + if (!needsLogin) + return; + const login = logIn(); + loginPromise = login?.authed; + await login?.accountViewShown; + }); + await transition.updateCallbackDone; + await loginPromise; + if (needsLogin && !Session_15.default.Auth.loggedIn.value) { + let setLoggedIn; + const loggedIn = new Promise(resolve => setLoggedIn = resolve); + ViewTransition_5.default.perform("view", async () => { + hideEphemeral(); + const view = await swapAdd(RequireLoginView_1.default); + if (!view) + return; + Session_15.default.Auth.loggedIn.subscribe(view, loggedIn => loggedIn && setLoggedIn()); + }); + await loggedIn; + } + } + loadParams = !definition.load ? undefined : await definition.load(params); + if (globalId !== showingId) + return; + if (container.view || showingId > 1) { + const transition = ViewTransition_5.default.perform("view", swap); + await transition.updateCallbackDone; + } + else { + await swap(); + } + return view; + async function swap() { + swapRemove(); + await swapAdd(); + } + function swapRemove() { + container.view?.remove(); + hideEphemeral(); + } + async function swapAdd(replacementDefinition = definition) { + const shownView = await Promise.resolve(replacementDefinition.create(params, loadParams)) + .then(v => { + view = replacementDefinition === definition ? v : undefined; + return v; + }) + .catch((error) => ErrorView_1.default.create({ code: error.code ?? 500, error })); + if (shownView) { + shownView.appendTo(container); + container.view = shownView; + if (replacementDefinition === definition) + shownView.params = params; + } + return shownView; + } + }, + ephemeralDialog: (0, Dialog_3.default)() + .style("view-container-ephemeral") + .tweak(dialog => dialog.style.bind(dialog.opened, "view-container-ephemeral--open")) + .setOwner(container) + .setNotModal() + .append((0, Button_17.default)() + .style("view-container-ephemeral-close") + .event.subscribe("click", () => { + if (cancelLogin) + cancelLogin(); + else + return container.hideEphemeral(); + })) + .appendTo(document.body), + showEphemeral: async (definition, params) => { + let view; + const transition = document.startViewTransition(async () => view = await showEphemeral(definition, params)); + await transition.updateCallbackDone; + return view; + }, + hideEphemeral: async () => { + const transition = document.startViewTransition(hideEphemeral); + await transition.updateCallbackDone; + }, + })); + return container; + async function showEphemeral(definition, params) { + container.ephemeral?.remove(); + let view; + const shownView = await Promise.resolve(definition.create(params)) + .then(v => view = v) + .catch((error) => ErrorView_1.default.create({ code: error.code ?? 500, error })); + if (shownView) { + shownView.appendTo(container.ephemeralDialog); + container.ephemeral = shownView; + container.ephemeralDialog.open(); + container.attributes.append("inert"); + container.ephemeralDialog.opened.subscribe(shownView, opened => { + if (!opened) { + hideEphemeral(); + } + }); + } + return view; + } + function hideEphemeral() { + container.ephemeralDialog.close(); + container.ephemeral?.remove(); + delete container.ephemeral; + container.attributes.remove("inert"); + } + function logIn() { + if (Session_15.default.Auth.author.value) + return; + const accountViewShown = showEphemeral(AccountView_3.default, undefined); + const authPromise = accountViewShown.then(async (view) => { + if (!view) + return false; + const loginCancelledPromise = new Promise(resolve => cancelLogin = resolve); + await Promise.race([ + Session_15.default.Auth.await(view), + loginCancelledPromise, + ]); + cancelLogin = undefined; + return Session_15.default.Auth.loggedIn.value; + }); + return { + accountViewShown, + authed: authPromise, + }; + } + }; + exports.default = ViewContainer; +}); +define("navigation/Navigate", ["require", "exports", "navigation/Routes", "ui/view/ErrorView", "utility/Env"], function (require, exports, Routes_1, ErrorView_2, Env_9) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Routes_1 = __importDefault(Routes_1); + ErrorView_2 = __importDefault(ErrorView_2); + Env_9 = __importDefault(Env_9); + function Navigator(app) { + let lastURL; + const navigate = { + fromURL: async () => { + if (location.href === lastURL?.href) + return; + const oldURL = lastURL; + lastURL = new URL(location.href); + let errored = false; + if (location.pathname !== oldURL?.pathname) { + const url = location.pathname; + let handled = false; + for (const route of Routes_1.default) { + const params = route.match(url); + if (!params) + continue; + await route.handler(app, (!Object.keys(params).length ? undefined : params)); + handled = true; + break; + } + if (!handled) { + errored = true; + await app.view.show(ErrorView_2.default, { code: 404 }); + } + } + if (location.hash && !errored) { + const id = location.hash.slice(1); + const element = document.getElementById(id); + if (!element) { + console.error(`No element by ID: "${id}"`); + location.hash = ""; + return; + } + element.scrollIntoView(); + element.focus(); + } + }, + toURL: async (url) => { + navigate.setURL(url); + return navigate.fromURL(); + }, + setURL: (url) => { + if (url !== location.pathname) + history.pushState({}, "", `${Env_9.default.URL_ORIGIN}${url.slice(1)}`); + }, + toRawURL: (url) => { + if (url.startsWith("http")) { + location.href = url; + return true; + } + if (url.startsWith("/")) { + void navigate.toURL(url); + return true; + } + if (url.startsWith("#")) { + const id = url.slice(1); + const element = document.getElementById(id); + if (!element) { + console.error(`No element by ID: "${id}"`); + return false; + } + location.hash = url; + return true; + } + console.error(`Unsupported raw URL to navigate to: "${url}"`); + return false; + }, + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + ephemeral: (...args) => app.view.showEphemeral(...args), + }; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + window.addEventListener("popstate", navigate.fromURL); + Object.assign(window, { navigate }); + return navigate; + } + exports.default = Navigator; +}); +define("ui/component/masthead/Flag", ["require", "exports", "ui/Component", "utility/Arrays"], function (require, exports, Component_53, Arrays_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_53 = __importDefault(Component_53); + Arrays_5 = __importDefault(Arrays_5); + const Flag = Component_53.default.Builder((component) => { + const stripes = Arrays_5.default.range(5) + .map(i => (0, Component_53.default)() + .style("flag-stripe", `flag-stripe-${FLAG_STRIPE_COLOURS[i]}`, `flag-stripe-${i + 1}`)); + let endWhen = Infinity; + const activeReasons = new Set(); + function add(reason) { + if (!activeReasons.size) { + endWhen = Infinity; + for (const stripe of stripes) { + stripe.style.remove("flag-stripe--animate-end-0", "flag-stripe--animate-end-1"); + stripe.style("flag-stripe--animate"); + } + } + activeReasons.add(reason); + } + function remove(reason) { + activeReasons.delete(reason); + } + function toggle(reason, enabled) { + if (enabled) + add(reason); + else + remove(reason); + } + component.hoveredOrFocused.subscribe(component, enabled => toggle("focus", enabled)); + for (const stripe of stripes) { + const first = stripe === stripes[0]; + let iteration = 0; + stripe.event.subscribe("animationstart", () => iteration = 0); + stripe.event.subscribe("animationiteration", () => { + iteration++; + if (first && !activeReasons.size) + endWhen = iteration; + if (iteration >= endWhen) { + stripe.style.remove("flag-stripe--animate"); + stripe.style(`flag-stripe--animate-end-${(iteration % 2)}`); + } + }); + } + return component + .style("flag") + .append(...stripes) + .extend(flag => ({ + wave: toggle, + })); + }); + exports.default = Flag; + const FLAG_STRIPE_COLOURS = [ + "blue", + "pink", + "white", + "pink", + "blue", + ]; +}); +define("ui/component/PrimaryNav", ["require", "exports", "ui/Component"], function (require, exports, Component_54) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_54 = __importDefault(Component_54); + exports.default = Component_54.default.Builder(nav => { + // Heading() + // .text.set("hi") + // .appendTo(nav) + return nav; + }); +}); +define("ui/component/Sidebar", ["require", "exports", "ui/Component", "ui/component/core/Button", "utility/Env", "utility/Store"], function (require, exports, Component_55, Button_18, Env_10, Store_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_55 = __importDefault(Component_55); + Button_18 = __importDefault(Button_18); + Env_10 = __importDefault(Env_10); + Store_4 = __importDefault(Store_4); + const Sidebar = Component_55.default.Builder("nav", (sidebar) => { + sidebar.style("sidebar") + .ariaLabel.use("masthead/primary-nav/alt"); + if (Env_10.default.ENVIRONMENT === "dev") + (0, Button_18.default)() + .text.set("Debug") + .event.subscribe("click", () => navigate.toURL("/debug")) + .appendTo(sidebar); + updateSidebarVisibility(); + return sidebar.extend(sidebar => ({ + toggle: () => { + Store_4.default.items.sidebar = !Store_4.default.items.sidebar; + updateSidebarVisibility(); + return sidebar; + }, + })); + function updateSidebarVisibility() { + sidebar.style.toggle(!!Store_4.default.items.sidebar, "sidebar--visible"); + } + }); + exports.default = Sidebar; +}); +define("ui/component/Masthead", ["require", "exports", "model/Session", "ui/Component", "ui/component/core/Button", "ui/component/core/Link", "ui/component/core/Slot", "ui/component/masthead/Flag", "ui/component/PrimaryNav", "ui/component/Sidebar", "ui/utility/Viewport", "utility/Env", "utility/Task"], function (require, exports, Session_16, Component_56, Button_19, Link_6, Slot_11, Flag_1, PrimaryNav_1, Sidebar_1, Viewport_4, Env_11, Task_4) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Session_16 = __importDefault(Session_16); + Component_56 = __importDefault(Component_56); + Button_19 = __importDefault(Button_19); + Link_6 = __importDefault(Link_6); + Slot_11 = __importDefault(Slot_11); + Flag_1 = __importDefault(Flag_1); + PrimaryNav_1 = __importDefault(PrimaryNav_1); + Sidebar_1 = __importDefault(Sidebar_1); + Viewport_4 = __importDefault(Viewport_4); + Env_11 = __importDefault(Env_11); + Task_4 = __importDefault(Task_4); + const Masthead = Component_56.default.Builder("header", (masthead, view) => { + masthead.style("masthead"); + const sidebar = (0, Sidebar_1.default)(); + const nav = (0, PrimaryNav_1.default)(); + (0, Button_19.default)() + .style("masthead-skip-nav") + .text.use("masthead/skip-navigation") + .event.subscribe("click", view.focus) + .appendTo(masthead); + let popover; + const left = (0, Component_56.default)() + .append((0, Component_56.default)() + .and(Button_19.default) + .style("masthead-left-hamburger", "masthead-left-hamburger-sidebar") + .ariaHidden() + .event.subscribe("click", sidebar.toggle)) + .append((0, Button_19.default)() + .style("masthead-left-hamburger", "masthead-left-hamburger-popover") + .ariaLabel.use("masthead/primary-nav/alt") + .clearPopover() + .setPopover("hover", p => popover = p + .anchor.add("aligned left", "off bottom") + .ariaRole("navigation"))) + .style("masthead-left") + .appendTo(masthead); + sidebar.style.bind(masthead.hasFocused, "sidebar--visible-due-to-keyboard-navigation"); + Viewport_4.default.size.use(masthead, async () => { + await Task_4.default.yield(); + nav.appendTo(sidebar.element.clientWidth ? sidebar : popover); + }); + const flag = (0, Flag_1.default)() + .style("masthead-home-logo"); + const homeLink = (0, Link_6.default)("/") + .ariaLabel.use("home/label") + .clearPopover() + .append((0, Component_56.default)() + .and(Button_19.default) + .style("masthead-home", "heading") + .append(flag) + .append((0, Component_56.default)("img") + .style("masthead-home-logo-wordmark") + .ariaHidden() + .attributes.set("src", `${Env_11.default.URL_ORIGIN}image/logo-wordmark.svg`))) + .appendTo(left); + flag.style.bind(homeLink.hoveredOrFocused, "flag--focused"); + flag.style.bind(homeLink.active, "flag--active"); + homeLink.hoveredOrFocused.subscribe(masthead, focus => flag.wave("home link focus", focus)); + (0, Component_56.default)() + .style("masthead-search") + .appendTo(masthead); + (0, Component_56.default)() + .style("masthead-user") + .append((0, Button_19.default)() + .style("masthead-user-notifications") + .clearPopover() + .ariaLabel.use("masthead/user/notifications/alt")) + .append((0, Button_19.default)() + .style("masthead-user-profile") + .clearPopover() + .ariaLabel.use("masthead/user/profile/alt") + .setPopover("hover", popover => popover + .anchor.add("aligned right", "off bottom") + .ariaRole("navigation") + .append((0, Slot_11.default)() + .use(Session_16.default.Auth.author, (slot, author) => { + if (!author) { + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/login") + .event.subscribe("click", () => navigate.toURL("/account")) + .appendTo(slot); + return; + } + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/profile") + .event.subscribe("click", () => navigate.toURL(`/author/${author.vanity}`)) + .appendTo(slot); + (0, Button_19.default)() + .type("flush") + .text.use("masthead/user/profile/popover/account") + .event.subscribe("click", () => navigate.toURL("/account")) + .appendTo(slot); + })))) + .appendTo(masthead); + return masthead.extend(masthead => ({ + sidebar, + })); + }); + exports.default = Masthead; +}); +define("App", ["require", "exports", "lang/en-nz", "model/FormInputLengths", "model/Session", "navigation/Navigate", "style", "ui/Component", "ui/component/core/toast/ToastList", "ui/component/Masthead", "ui/InputBus", "ui/utility/FocusListener", "ui/utility/HoverListener", "ui/utility/Mouse", "ui/utility/Viewport", "ui/view/shared/component/ViewContainer", "utility/Async", "utility/Store", "utility/Time"], function (require, exports, en_nz_9, FormInputLengths_4, Session_17, Navigate_1, style_2, Component_57, ToastList_1, Masthead_1, InputBus_2, FocusListener_3, HoverListener_2, Mouse_4, Viewport_5, ViewContainer_1, Async_4, Store_5, Time_8) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + en_nz_9 = __importDefault(en_nz_9); + FormInputLengths_4 = __importDefault(FormInputLengths_4); + Session_17 = __importDefault(Session_17); + Navigate_1 = __importDefault(Navigate_1); + style_2 = __importDefault(style_2); + Component_57 = __importDefault(Component_57); + ToastList_1 = __importDefault(ToastList_1); + Masthead_1 = __importDefault(Masthead_1); + InputBus_2 = __importDefault(InputBus_2); + FocusListener_3 = __importDefault(FocusListener_3); + HoverListener_2 = __importDefault(HoverListener_2); + Mouse_4 = __importDefault(Mouse_4); + Viewport_5 = __importDefault(Viewport_5); + ViewContainer_1 = __importDefault(ViewContainer_1); + Async_4 = __importDefault(Async_4); + Store_5 = __importDefault(Store_5); + Time_8 = __importDefault(Time_8); + async function App() { + if (location.pathname.startsWith("/auth/")) { + if (location.pathname.endsWith("/error")) { + const params = new URLSearchParams(location.search); + // eslint-disable-next-line no-debugger + debugger; + Store_5.default.items.popupError = { + code: +(params.get("code") ?? "500"), + message: params.get("message") ?? "Internal Server Error", + }; + } + window.close(); + } + await screen?.orientation?.lock?.("portrait-primary").catch(() => { }); + InputBus_2.default.subscribe("down", event => { + if (event.use("F6")) + for (const stylesheet of document.querySelectorAll("link[rel=stylesheet]")) { + const href = stylesheet.getAttribute("href"); + const newHref = `${href.slice(0, Math.max(0, href.indexOf("?")) || Infinity)}?${Math.random().toString().slice(2)}`; + stylesheet.setAttribute("href", newHref); + } + if (event.use("F4")) + document.documentElement.classList.add("persist-tooltips"); + }); + InputBus_2.default.subscribe("up", event => { + if (event.use("F4")) + document.documentElement.classList.remove("persist-tooltips"); + }); + await FormInputLengths_4.default.getManifest(); + // const path = URL.path ?? URL.hash; + // if (path === AuthView.id) { + // URL.hash = null; + // URL.path = null; + // } + // ViewManager.showByHash(URL.path ?? URL.hash); + await Promise.race([ + Session_17.default.refresh(), + Async_4.default.sleep(Time_8.default.seconds(2)), + ]); + HoverListener_2.default.listen(); + FocusListener_3.default.listen(); + Mouse_4.default.listen(); + Viewport_5.default.listen(); + document.title = en_nz_9.default["fluff4me/title"]().toString(); + document.body.classList.add(...style_2.default.body); + const view = (0, ViewContainer_1.default)(); + const masthead = (0, Masthead_1.default)(view); + const related = (0, Component_57.default)() + .style("app-content-related"); + const content = (0, Component_57.default)() + .style("app-content") + .monitorScrollEvents() + .append(view, related); + const app = (0, Component_57.default)() + .style("app") + .append(masthead, masthead.sidebar, content) + .append((0, ToastList_1.default)()) + .extend(app => ({ + navigate: (0, Navigate_1.default)(app), + view, + })) + .appendTo(document.body); + await app.navigate.fromURL(); + Object.assign(window, { app }); + return app; + } + exports.default = App; +}); +define("Constants", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.APP_NAME = void 0; + exports.APP_NAME = "fluff4.me / Queer Webnovels"; +}); +define("utility/DOMRect", ["require", "exports", "utility/Define"], function (require, exports, Define_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = default_1; + Define_5 = __importDefault(Define_5); + function default_1() { + Define_5.default.magic(DOMRect.prototype, "centreX", { + get() { + return this.left + this.width / 2; + }, + }); + Define_5.default.magic(DOMRect.prototype, "centreY", { + get() { + return this.top + this.height / 2; + }, + }); + (0, Define_5.default)(DOMRect.prototype, "expand", function (amount) { + return new DOMRect(this.x - amount, this.y - amount, this.width + amount * 2, this.height + amount * 2); + }); + (0, Define_5.default)(DOMRect.prototype, "contract", function (amount) { + return new DOMRect(Math.min(this.x + amount, this.centreX), Math.min(this.y - amount, this.centreY), Math.max(0, this.width - amount * 2), Math.max(0, this.height - amount * 2)); + }); + (0, Define_5.default)(DOMRect.prototype, "intersects", function (target) { + if ("width" in target) + return true + && this.left >= target.right + && this.right <= target.left + && this.top >= target.bottom + && this.bottom <= target.top; + return true + && this.left <= target.x && this.right >= target.x + && this.top <= target.y && this.bottom >= target.y; + }); + } +}); +define("utility/Elements", ["require", "exports", "utility/Define"], function (require, exports, Define_6) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Define_6 = __importDefault(Define_6); + var Elements; + (function (Elements) { + function applyPrototypes() { + Define_6.default.set(Element.prototype, "asType", function (tagName) { + return this.tagName.toLowerCase() === tagName ? this : undefined; + }); + } + Elements.applyPrototypes = applyPrototypes; + })(Elements || (Elements = {})); + exports.default = Elements; +}); +define("index", ["require", "exports", "utility/Arrays", "utility/DOMRect", "utility/Elements", "browser-source-map-support", "utility/Env"], function (require, exports, Arrays_6, DOMRect_1, Elements_1, browser_source_map_support_1, Env_12) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_6 = __importDefault(Arrays_6); + DOMRect_1 = __importDefault(DOMRect_1); + Elements_1 = __importDefault(Elements_1); + browser_source_map_support_1 = __importDefault(browser_source_map_support_1); + Env_12 = __importDefault(Env_12); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + browser_source_map_support_1.default.install({ + environment: "browser", + }); + // view transition api fallback + const noopViewTransition = { + finished: Promise.resolve(undefined), + ready: Promise.resolve(undefined), + updateCallbackDone: Promise.resolve(undefined), + skipTransition: () => { }, + }; + document.startViewTransition ??= cb => { + cb?.(); + return noopViewTransition; + }; + (0, DOMRect_1.default)(); + Arrays_6.default.applyPrototypes(); + Elements_1.default.applyPrototypes(); + void (async () => { + await Env_12.default.load(); + const app = await new Promise((resolve_1, reject_1) => { require(["App"], resolve_1, reject_1); }).then(__importStar); + await app.default(); + })(); +}); +define("endpoint/chapter/EndpointChapterDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_21) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_21 = __importDefault(Endpoint_21); + exports.default = (0, Endpoint_21.default)("/work/{author}/{vanity}/chapter/{url}/delete", "post"); +}); +define("endpoint/comment/EndpointCommentAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_22) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_22 = __importDefault(Endpoint_22); + exports.default = (0, Endpoint_22.default)("/work/{author}/{vanity}/chapter/{url}/comment/add", "post"); +}); +define("endpoint/comment/EndpointCommentGetAllChapter", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_23) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_23 = __importDefault(Endpoint_23); + exports.default = (0, Endpoint_23.default)("/work/{author}/{vanity}/chapter/{url}/comments", "get"); +}); +define("endpoint/comment/EndpointCommentRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_24) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_24 = __importDefault(Endpoint_24); + exports.default = (0, Endpoint_24.default)("/comment/remove/chapter", "post"); +}); +define("endpoint/comment/EndpointCommentUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_25) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_25 = __importDefault(Endpoint_25); + exports.default = (0, Endpoint_25.default)("/comment/update/chapter", "post"); +}); +define("endpoint/follow/EndpointFollowAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_26) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_26 = __importDefault(Endpoint_26); + exports.default = (0, Endpoint_26.default)("/follow/{type}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowAddWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_27) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_27 = __importDefault(Endpoint_27); + exports.default = (0, Endpoint_27.default)("/follow/work/{author}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_28) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_28 = __importDefault(Endpoint_28); + exports.default = (0, Endpoint_28.default)("/follows/{type}/{vanity}", "get"); +}); +define("endpoint/follow/EndpointFollowGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_29) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_29 = __importDefault(Endpoint_29); + exports.default = (0, Endpoint_29.default)("/following/{type}", "get"); +}); +define("endpoint/follow/EndpointFollowGetAllMerged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_30) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_30 = __importDefault(Endpoint_30); + exports.default = (0, Endpoint_30.default)("/following", "get"); +}); +define("endpoint/follow/EndpointFollowGetWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_31) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_31 = __importDefault(Endpoint_31); + exports.default = (0, Endpoint_31.default)("/follows/work/{author}/{vanity}", "get"); +}); +define("endpoint/follow/EndpointFollowRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_32) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_32 = __importDefault(Endpoint_32); + exports.default = (0, Endpoint_32.default)("/unfollow/{type}/{vanity}", "post"); +}); +define("endpoint/follow/EndpointFollowRemoveWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_33) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_33 = __importDefault(Endpoint_33); + exports.default = (0, Endpoint_33.default)("/unfollow/work/{author}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreAdd", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_34) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_34 = __importDefault(Endpoint_34); + exports.default = (0, Endpoint_34.default)("/ignore/{type}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreAddWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_35) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_35 = __importDefault(Endpoint_35); + exports.default = (0, Endpoint_35.default)("/ignore/work/{author}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_36) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_36 = __importDefault(Endpoint_36); + exports.default = (0, Endpoint_36.default)("/ignores/{type}/{vanity}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_37) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_37 = __importDefault(Endpoint_37); + exports.default = (0, Endpoint_37.default)("/ignoring/{type}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetAllMerged", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_38) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_38 = __importDefault(Endpoint_38); + exports.default = (0, Endpoint_38.default)("/ignoring", "get"); +}); +define("endpoint/ignore/EndpointIgnoreGetWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_39) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_39 = __importDefault(Endpoint_39); + exports.default = (0, Endpoint_39.default)("/ignores/work/{author}/{vanity}", "get"); +}); +define("endpoint/ignore/EndpointIgnoreRemove", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_40) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_40 = __importDefault(Endpoint_40); + exports.default = (0, Endpoint_40.default)("/unignore/{type}/{vanity}", "post"); +}); +define("endpoint/ignore/EndpointIgnoreRemoveWork", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_41) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_41 = __importDefault(Endpoint_41); + exports.default = (0, Endpoint_41.default)("/unignore/work/{author}/{vanity}", "post"); +}); +define("endpoint/notification/EndpointNotificationGet", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_42) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_42 = __importDefault(Endpoint_42); + exports.default = (0, Endpoint_42.default)("/notifications/get/all", "get"); +}); +define("endpoint/notification/EndpointNotificationGetCount", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_43) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_43 = __importDefault(Endpoint_43); + exports.default = (0, Endpoint_43.default)("/notifications/get/count", "get"); +}); +define("endpoint/notification/EndpointNotificationGetUnread", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_44) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_44 = __importDefault(Endpoint_44); + exports.default = (0, Endpoint_44.default)("/notifications/get/unread", "get"); +}); +define("endpoint/notification/EndpointNotificationMarkRead", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_45) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_45 = __importDefault(Endpoint_45); + exports.default = (0, Endpoint_45.default)("/notifications/mark/read", "post"); +}); +define("endpoint/notification/EndpointNotificationMarkUnread", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_46) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_46 = __importDefault(Endpoint_46); + exports.default = (0, Endpoint_46.default)("/notifications/mark/unread", "post"); +}); +define("endpoint/patreon/EndpointPatreonGetTiers", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_47) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_47 = __importDefault(Endpoint_47); + exports.default = (0, Endpoint_47.default)("/patreon/campaign/tiers/get", "get"); +}); +define("endpoint/patreon/EndpointPatreonSetThresholds", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_48) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_48 = __importDefault(Endpoint_48); + exports.default = (0, Endpoint_48.default)("/patreon/campaign/tiers/set/{author}/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeGetAllAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_49) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_49 = __importDefault(Endpoint_49); + exports.default = (0, Endpoint_49.default)("/privilege/get/{vanity}", "get"); +}); +define("endpoint/privilege/EndpointPrivilegeGrantAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_50) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_50 = __importDefault(Endpoint_50); + exports.default = (0, Endpoint_50.default)("/privilege/grant/author/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeGrantRole", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_51) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_51 = __importDefault(Endpoint_51); + exports.default = (0, Endpoint_51.default)("/privilege/grant/role/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeRevokeAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_52) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_52 = __importDefault(Endpoint_52); + exports.default = (0, Endpoint_52.default)("/privilege/revoke/author/{vanity}", "post"); +}); +define("endpoint/privilege/EndpointPrivilegeRevokeRole", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_53) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_53 = __importDefault(Endpoint_53); + exports.default = (0, Endpoint_53.default)("/privilege/revoke/role/{vanity}", "post"); +}); +define("endpoint/role/EndpointRoleCreate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_54) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_54 = __importDefault(Endpoint_54); + exports.default = (0, Endpoint_54.default)("/role/create", "post"); +}); +define("endpoint/role/EndpointRoleDelete", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_55) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_55 = __importDefault(Endpoint_55); + exports.default = (0, Endpoint_55.default)("/role/delete/{role}", "post"); +}); +define("endpoint/role/EndpointRoleGrantAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_56) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_56 = __importDefault(Endpoint_56); + exports.default = (0, Endpoint_56.default)("/role/grant/{role}/{author}", "post"); +}); +define("endpoint/role/EndpointRoleListAll", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_57) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_57 = __importDefault(Endpoint_57); + exports.default = (0, Endpoint_57.default)("/role/get", "get"); +}); +define("endpoint/role/EndpointRoleReorder", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_58) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_58 = __importDefault(Endpoint_58); + exports.default = (0, Endpoint_58.default)("/role/reorder", "post"); +}); +define("endpoint/role/EndpointRoleRevokeAuthor", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_59) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_59 = __importDefault(Endpoint_59); + exports.default = (0, Endpoint_59.default)("/role/revoke/{role}/{author}", "post"); +}); +define("endpoint/role/EndpointRoleUpdate", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_60) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_60 = __importDefault(Endpoint_60); + exports.default = (0, Endpoint_60.default)("/role/update/{role}", "post"); +}); +define("endpoint/tag/EndpointTagCreateCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_61) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_61 = __importDefault(Endpoint_61); + exports.default = (0, Endpoint_61.default)("/tag/create/category", "post"); +}); +define("endpoint/tag/EndpointTagCreateGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_62) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_62 = __importDefault(Endpoint_62); + exports.default = (0, Endpoint_62.default)("/tag/create/global", "post"); +}); +define("endpoint/tag/EndpointTagCustomPromote", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_63) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_63 = __importDefault(Endpoint_63); + exports.default = (0, Endpoint_63.default)("/tag/promote/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagGlobalDemote", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_64) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_64 = __importDefault(Endpoint_64); + exports.default = (0, Endpoint_64.default)("/tag/demote/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagRemoveCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_65) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_65 = __importDefault(Endpoint_65); + exports.default = (0, Endpoint_65.default)("/tag/remove/category/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagRemoveGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_66) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_66 = __importDefault(Endpoint_66); + exports.default = (0, Endpoint_66.default)("/tag/remove/global/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagUpdateCategory", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_67) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_67 = __importDefault(Endpoint_67); + exports.default = (0, Endpoint_67.default)("/tag/update/category/{vanity}", "post"); +}); +define("endpoint/tag/EndpointTagUpdateGlobal", ["require", "exports", "endpoint/Endpoint"], function (require, exports, Endpoint_68) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Endpoint_68 = __importDefault(Endpoint_68); + exports.default = (0, Endpoint_68.default)("/tag/update/global/{vanity}", "post"); +}); +define("ui/component/core/ActionHeading", ["require", "exports", "ui/Component", "ui/component/core/ActionRow", "ui/component/core/Heading"], function (require, exports, Component_58, ActionRow_7, Heading_3) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Component_58 = __importDefault(Component_58); + ActionRow_7 = __importDefault(ActionRow_7); + Heading_3 = __importDefault(Heading_3); + const ActionHeading = Component_58.default.Builder((component) => { + const row = component.and(ActionRow_7.default) + .viewTransition("action-heading") + .style("action-heading"); + const heading = row.left.and(Heading_3.default).style("action-heading-heading"); + return row.extend(row => ({ + heading, + })); + }); + exports.default = ActionHeading; +}); +//#region Not currently used +// interface AnchorNameManipulator { +// (name: string): HOST +// remove (name: string): HOST +// } +// interface AnchorComponentExtensions { +// anchorName: AnchorNameManipulator +// } +// declare module "ui/Component" { +// interface ComponentExtensions extends AnchorComponentExtensions { } +// } +// Component.extend(component => { +// let anchorNames: string[] | undefined +// return { +// anchorName: Object.assign( +// (name: string) => { +// anchorNames ??= [] +// if (!name.startsWith("--")) +// name = `--${name}` +// anchorNames.push(name) +// component.style.setProperty("anchor-name", anchorNames.join(",")) +// return component +// }, +// { +// remove: (name: string) => { +// const index = anchorNames?.indexOf(name) ?? -1 +// if (index === -1) +// return component +// anchorNames!.splice(index, 1) +// if (!anchorNames!.length) +// component.style.removeProperties("anchor-name") +// else +// component.style.setProperty("anchor-name", anchorNames!.join(",")) +// return component +// }, +// }, +// ), +// } +// }) +// namespace Anchor { +// const INDICES: Record = {} +// export function name (type: string) { +// const id = INDICES[type] ?? 0 +// INDICES[type] = id + 1 +// return `--${type}-${id}` +// } +// } +// export default Anchor +define("ui/utility/ActiveListener", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var ActiveListener; + (function (ActiveListener) { + let lastActive = []; + function allActive() { + return lastActive; + } + ActiveListener.allActive = allActive; + function active() { + return lastActive.at(-1); + } + ActiveListener.active = active; + function* allActiveComponents() { + for (const element of lastActive) { + const component = element.component; + if (component) + yield component; + } + } + ActiveListener.allActiveComponents = allActiveComponents; + function activeComponent() { + return lastActive.at(-1)?.component; + } + ActiveListener.activeComponent = activeComponent; + function listen() { + document.addEventListener("mousedown", updateActive); + document.addEventListener("mouseup", updateActive); + function updateActive() { + const allActive = document.querySelectorAll(":active"); + const active = allActive[allActive.length - 1]; + if (active === lastActive[lastActive.length - 1]) + return; + const newActive = [...allActive]; + for (const element of lastActive) + if (element.component && !newActive.includes(element)) + element.component.active.value = false; + for (const element of newActive) + if (element.component && !lastActive.includes(element)) + element.component.active.value = true; + lastActive = newActive; + } + } + ActiveListener.listen = listen; + })(ActiveListener || (ActiveListener = {})); + exports.default = ActiveListener; + Object.assign(window, { ActiveListener }); +}); +define("utility/Debug", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Debug = void 0; + var Debug; + (function (Debug) { + Debug.placeholder = false; + })(Debug || (exports.Debug = Debug = {})); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + window.Debug = Debug; +}); +define("utility/Functions", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var Functions; + (function (Functions) { + function resolve(fn, ...args) { + return typeof fn === "function" ? fn(...args) : fn; + } + Functions.resolve = resolve; + })(Functions || (Functions = {})); + exports.default = Functions; +}); +define("utility/Tuples", ["require", "exports", "utility/Arrays"], function (require, exports, Arrays_7) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + Arrays_7 = __importDefault(Arrays_7); + var Tuples; + (function (Tuples) { + function make(...values) { + return values; + } + Tuples.make = make; + const nullishFilters = Object.fromEntries(Arrays_7.default.range(6) + .map(index => make(index, (value) => value[index] !== undefined && value[index] !== null))); + function filterNullish(index) { + return nullishFilters[index]; + } + Tuples.filterNullish = filterNullish; + const falsyFilters = Object.fromEntries(Arrays_7.default.range(6) + .map(index => make(index, (value) => value[index]))); + function filterFalsy(index) { + return falsyFilters[index]; + } + Tuples.filterFalsy = filterFalsy; + function getter(index) { + return tuple => tuple[index]; + } + Tuples.getter = getter; + function filter(index, predicate) { + return (tuple, i) => predicate(tuple[index], i); + } + Tuples.filter = filter; + })(Tuples || (Tuples = {})); + exports.default = Tuples; +}); +define("utility/decorator/Bound", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Bound = Bound; + exports.Final = Final; + function Bound(target, key, descriptor) { + return Bounder(target, key, descriptor); + } + function Final(target, key, descriptor) { + return Bounder(target, key, descriptor); + } + function Bounder(target, key, descriptor) { + return { + configurable: false, + enumerable: descriptor.enumerable, + get() { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins + if (!this || this === target.prototype || this.hasOwnProperty(key) || typeof descriptor.value !== "function") { + return descriptor.value; + } + const value = descriptor.value.bind(this); + Object.defineProperty(this, key, { + configurable: false, + enumerable: descriptor.enumerable, + value, + }); + return value; + }, + }; + } + exports.default = Bound; +}); diff --git a/js/init.js b/js/init.js new file mode 100644 index 0000000..c06c2b2 --- /dev/null +++ b/js/init.js @@ -0,0 +1,348 @@ +/* eslint-disable */ + +(() => { + const baseURL = document.currentScript.dataset.baseUrl + + /** + * @enum {number} + */ + const ModuleState = { + Unprocessed: 0, + Waiting: 1, + Processed: 2, + Error: 3, + } + + /** + * @typedef {(module: string) => any} ModuleGetter + */ + + /** + * @typedef {(modules: string[], resolve: (module: any) => void, reject: (err?: any) => any) => void} ModuleGetterAsync + */ + + /** + * @typedef {(getModule: ModuleGetter | ModuleGetterAsync, module: Module, ...args: any[]) => any} ModuleInitializer + */ + + /** + * @typedef {{ _name: string; _state: ModuleState; _requirements: string[]; _initializer: ModuleInitializer; _error?: Error }} Module + */ + + /** + * @type {Map} + */ + const moduleMap = new Map() + /** + * @type {Set} + */ + const requirements = new Set() + + /** + * @param {string | string[]} name + * @param {string[] | ModuleInitializer} reqs + * @param {ModuleInitializer?} fn + */ + function define (name, reqs, fn) { + if (Array.isArray(name)) { + fn = reqs + reqs = name + + const src = document.currentScript.getAttribute("src") + if (!src) + throw new Error("Cannot define module without a name") + + name = src.startsWith("./") ? src.slice(2) : src.startsWith("/") ? src.slice(1) : src + name = baseURL && name.startsWith(baseURL) ? name.slice(baseURL.length) : name + name = name.endsWith(".js") ? name.slice(0, -3) : name + name = name.endsWith("/index") ? name.slice(0, -6) : name + } + + reqs ??= [] + + if (moduleMap.has(name)) + throw new Error(`Module "${name}" cannot be redefined`) + + if (typeof reqs === "function") { + if (fn) + throw new Error("Unsupport define call") + + fn = reqs + reqs = [] + } + + const _requirements = reqs.slice(2).map(req => findModuleName(name, req)) + /** + * @type {Module} + */ + const module = { + _name: name, + _state: ModuleState.Unprocessed, + _requirements, + _initializer: fn, + _init: document.currentScript?.dataset.init === name, + _replace (newModule) { + if (typeof newModule !== "object" && typeof newModule !== "function") + throw new Error("Cannot assign module.exports to a non-object") + + newModule._name = name + newModule._state = ModuleState.Unprocessed + newModule._requirements = _requirements + newModule._initializer = fn + newModule._replace = module._replace + moduleMap.set(name, newModule) + }, + } + moduleMap.set(name, module) + for (const req of module._requirements) + requirements.add(req) + + const preload = name.endsWith("$preload") + if (preload) { + if (module._requirements.length) + throw new Error(`Module "${name}" cannot import other modules`) + + initializeModule(module) + } + + if (initialProcessCompleted) + processModules() + } + + define.amd = true + + /** + * @param {string} name + * @param {string[]} [requiredBy] + */ + function getModule (name, requiredBy) { + let module = moduleMap.get(name) + if (!module) { + if (name.endsWith(".js")) + name = name.slice(0, -3) + + if (name.startsWith(".")) { + let from = requiredBy[requiredBy.length - 1] + if (!from.includes("/")) + from += "/" + + name = findModuleName(from, name) + } + + module = moduleMap.get(name) + if (!module) + throw new Error(`Module "${name}" has not been declared and cannot be required`) + } + + if (module._state === ModuleState.Unprocessed) + module = processModule(name, module, requiredBy) + + return module + } + + /** + * @param {string} name + */ + function initializeModuleByName (name) { + initializeModule(getModule(name)) + } + + /** + * @param {Module} module + * @param {string[]} [requiredBy] + * @param {...any} args + */ + function initializeModule (module, requiredBy, ...args) { + if (module._state) + throw new Error(`Module "${module._name}" has already been processed`) + + try { + requiredBy = [...requiredBy, module._name] + + /** + * @param {string | string[]} nameOrNames + * @param {(module: any) => void} [resolve] + * @param {(err?: any) => void} [reject] + */ + function require (nameOrNames, resolve, reject) { + if (Array.isArray(nameOrNames)) { + const results = nameOrNames.map(name => getModule(name, requiredBy)) + return resolve(results.length === 1 ? results[0] : results) + } + + return getModule(nameOrNames, requiredBy) + } + + module.require = require + + const result = module._initializer(require, module, ...args) + if (module.default === undefined) { + module.default = result ?? module + module.__esModule = true + } + + module = moduleMap.get(module._name) + module._state = ModuleState.Processed + + injectModule(module) + + } catch (err) { + module._state = ModuleState.Error + module._error = err + err.message = `[Module initialization ${module._name}] ${err.message}` + console.error(err) + } + } + + const isInjectableModuleDefaultNameRegex = /^[A-Z_$][a-zA-Z_$0-9]+$/ + function injectModule (module) { + const name = module._name + const inject = module.default ?? module + const moduleDefaultName = basename(name) + if (isInjectableModuleDefaultNameRegex.test(moduleDefaultName) && !(moduleDefaultName in window)) + Object.assign(window, { [moduleDefaultName]: inject }) + + for (const key of Object.keys(module)) { + if (key !== "default" && !key.startsWith("_") && isInjectableModuleDefaultNameRegex.test(key) && !(key in window)) { + Object.assign(window, { [key]: module[key] }) + } + } + } + + + //////////////////////////////////// + // Add the above functions to Window + // + + /** + * @type {Window & typeof globalThis & { define: typeof define; getModule: typeof getModule; initializeModule: typeof initializeModuleByName }} + */ + const moddableWindow = (window) + moddableWindow.define = define + moddableWindow.getModule = getModule + moddableWindow.initializeModule = initializeModuleByName + + + //////////////////////////////////// + // Actually process the modules + // + + document.addEventListener("DOMContentLoaded", processModules) + + let initialProcessCompleted = false + async function processModules () { + const scriptsStillToImport = Array.from(document.querySelectorAll("template[data-script]")) + .map(definition => { + const script = /** @type {HTMLTemplateElement} */ (definition).dataset.script + definition.remove() + return script + }) + + await Promise.all(Array.from(new Set(scriptsStillToImport)).map(tryImportAdditionalModule)) + + while (requirements.size) { + const remainingRequirements = Array.from(requirements) + await Promise.all(remainingRequirements.map(tryImportAdditionalModule)) + for (const req of remainingRequirements) + requirements.delete(req) + } + + for (const [name, module] of moduleMap.entries()) + if (module._init) + processModule(name, module) + + initialProcessCompleted = true + } + + /** + * @param {string} req + */ + async function tryImportAdditionalModule (req) { + if (moduleMap.has(req)) + return + + await importAdditionalModule(req) + + if (!moduleMap.has(req)) + throw new Error(`The required module '${req}' could not be asynchronously loaded.`) + } + + /** + * @param {string} req + */ + async function importAdditionalModule (req) { + const script = document.createElement("script") + document.head.appendChild(script) + /** @type {Promise} */ + const promise = new Promise(resolve => script.addEventListener("load", () => resolve())) + script.src = `/script/${req}.js` + return promise + } + + /** + * @param {string} name + * @param {Module | undefined} module + * @param {string[]} requiredBy + */ + function processModule (name, module = moduleMap.get(name), requiredBy = []) { + if (!module) + throw new Error(`No "${name}" module defined`) + + if (module._state === ModuleState.Waiting) + throw new Error(`Circular dependency! Dependency chain: ${[...requiredBy, name].map(m => `"${m}"`).join(" > ")}`) + + if (!module._state) { + module._state = ModuleState.Waiting + const args = module._requirements + .map(req => processModule(req, undefined, [...requiredBy, name])) + + module._state = ModuleState.Unprocessed + initializeModule(module, requiredBy, ...args) + } + + return moduleMap.get(name) + } + + + //////////////////////////////////// + // Utils + // + + /** + * @param {string} name + * @param {string} requirement + */ + function findModuleName (name, requirement) { + let root = dirname(name) + if (requirement.startsWith("./")) + return join(root, requirement.slice(2)) + + while (requirement.startsWith("../")) + root = dirname(root), requirement = requirement.slice(3) + + return requirement // join(root, requirement); + } + + /** + * @param {string} name + */ + function dirname (name) { + const lastIndex = name.lastIndexOf("/") + return lastIndex === -1 ? "" : name.slice(0, lastIndex) + } + + /** + * @param {string} name + */ + function basename (name) { + const lastIndex = name.lastIndexOf("/") + return name.slice(lastIndex + 1) + } + + /** + * @param {...string} path + */ + function join (...path) { + return path.filter(p => p).join("/") + } +})() diff --git a/js/vendor.js b/js/vendor.js new file mode 100644 index 0000000..204b894 --- /dev/null +++ b/js/vendor.js @@ -0,0 +1,23464 @@ +define("prosemirror-commands",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorState = require('prosemirror-state'); +var deleteSelection = function deleteSelection(state, dispatch) { + if (state.selection.empty) return false; + if (dispatch) dispatch(state.tr.deleteSelection().scrollIntoView()); + return true; +}; +function atBlockStart(state, view) { + var $cursor = state.selection.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) return null; + return $cursor; +} +var joinBackward = function joinBackward(state, dispatch, view) { + var $cursor = atBlockStart(state, view); + if (!$cursor) return false; + var $cut = findCutBefore($cursor); + if (!$cut) { + var range = $cursor.blockRange(), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; + } + var before = $cut.nodeBefore; + if (deleteBarrier(state, $cut, dispatch, -1)) return true; + if ($cursor.parent.content.size == 0 && (textblockAt(before, "end") || prosemirrorState.NodeSelection.isSelectable(before))) { + for (var depth = $cursor.depth;; depth--) { + var delStep = prosemirrorTransform.replaceStep(state.doc, $cursor.before(depth), $cursor.after(depth), prosemirrorModel.Slice.empty); + if (delStep && delStep.slice.size < delStep.to - delStep.from) { + if (dispatch) { + var tr = state.tr.step(delStep); + tr.setSelection(textblockAt(before, "end") ? prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos, -1)), -1) : prosemirrorState.NodeSelection.create(tr.doc, $cut.pos - before.nodeSize)); + dispatch(tr.scrollIntoView()); + } + return true; + } + if (depth == 1 || $cursor.node(depth - 1).childCount > 1) break; + } + } + if (before.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr["delete"]($cut.pos - before.nodeSize, $cut.pos).scrollIntoView()); + return true; + } + return false; +}; +var joinTextblockBackward = function joinTextblockBackward(state, dispatch, view) { + var $cursor = atBlockStart(state, view); + if (!$cursor) return false; + var $cut = findCutBefore($cursor); + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; +}; +var joinTextblockForward = function joinTextblockForward(state, dispatch, view) { + var $cursor = atBlockEnd(state, view); + if (!$cursor) return false; + var $cut = findCutAfter($cursor); + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; +}; +function joinTextblocksAround(state, $cut, dispatch) { + var before = $cut.nodeBefore, + beforeText = before, + beforePos = $cut.pos - 1; + for (; !beforeText.isTextblock; beforePos--) { + if (beforeText.type.spec.isolating) return false; + var child = beforeText.lastChild; + if (!child) return false; + beforeText = child; + } + var after = $cut.nodeAfter, + afterText = after, + afterPos = $cut.pos + 1; + for (; !afterText.isTextblock; afterPos++) { + if (afterText.type.spec.isolating) return false; + var _child = afterText.firstChild; + if (!_child) return false; + afterText = _child; + } + var step = prosemirrorTransform.replaceStep(state.doc, beforePos, afterPos, prosemirrorModel.Slice.empty); + if (!step || step.from != beforePos || step instanceof prosemirrorTransform.ReplaceStep && step.slice.size >= afterPos - beforePos) return false; + if (dispatch) { + var tr = state.tr.step(step); + tr.setSelection(prosemirrorState.TextSelection.create(tr.doc, beforePos)); + dispatch(tr.scrollIntoView()); + } + return true; +} +function textblockAt(node, side) { + var only = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + for (var scan = node; scan; scan = side == "start" ? scan.firstChild : scan.lastChild) { + if (scan.isTextblock) return true; + if (only && scan.childCount != 1) return false; + } + return false; +} +var selectNodeBackward = function selectNodeBackward(state, dispatch, view) { + var _state$selection = state.selection, + $head = _state$selection.$head, + empty = _state$selection.empty, + $cut = $head; + if (!empty) return false; + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("backward", state) : $head.parentOffset > 0) return false; + $cut = findCutBefore($head); + } + var node = $cut && $cut.nodeBefore; + if (!node || !prosemirrorState.NodeSelection.isSelectable(node)) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, $cut.pos - node.nodeSize)).scrollIntoView()); + return true; +}; +function findCutBefore($pos) { + if (!$pos.parent.type.spec.isolating) for (var i = $pos.depth - 1; i >= 0; i--) { + if ($pos.index(i) > 0) return $pos.doc.resolve($pos.before(i + 1)); + if ($pos.node(i).type.spec.isolating) break; + } + return null; +} +function atBlockEnd(state, view) { + var $cursor = state.selection.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("forward", state) : $cursor.parentOffset < $cursor.parent.content.size)) return null; + return $cursor; +} +var joinForward = function joinForward(state, dispatch, view) { + var $cursor = atBlockEnd(state, view); + if (!$cursor) return false; + var $cut = findCutAfter($cursor); + if (!$cut) return false; + var after = $cut.nodeAfter; + if (deleteBarrier(state, $cut, dispatch, 1)) return true; + if ($cursor.parent.content.size == 0 && (textblockAt(after, "start") || prosemirrorState.NodeSelection.isSelectable(after))) { + var delStep = prosemirrorTransform.replaceStep(state.doc, $cursor.before(), $cursor.after(), prosemirrorModel.Slice.empty); + if (delStep && delStep.slice.size < delStep.to - delStep.from) { + if (dispatch) { + var tr = state.tr.step(delStep); + tr.setSelection(textblockAt(after, "start") ? prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1) : prosemirrorState.NodeSelection.create(tr.doc, tr.mapping.map($cut.pos))); + dispatch(tr.scrollIntoView()); + } + return true; + } + } + if (after.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr["delete"]($cut.pos, $cut.pos + after.nodeSize).scrollIntoView()); + return true; + } + return false; +}; +var selectNodeForward = function selectNodeForward(state, dispatch, view) { + var _state$selection2 = state.selection, + $head = _state$selection2.$head, + empty = _state$selection2.empty, + $cut = $head; + if (!empty) return false; + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("forward", state) : $head.parentOffset < $head.parent.content.size) return false; + $cut = findCutAfter($head); + } + var node = $cut && $cut.nodeAfter; + if (!node || !prosemirrorState.NodeSelection.isSelectable(node)) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, $cut.pos)).scrollIntoView()); + return true; +}; +function findCutAfter($pos) { + if (!$pos.parent.type.spec.isolating) for (var i = $pos.depth - 1; i >= 0; i--) { + var parent = $pos.node(i); + if ($pos.index(i) + 1 < parent.childCount) return $pos.doc.resolve($pos.after(i + 1)); + if (parent.type.spec.isolating) break; + } + return null; +} +var joinUp = function joinUp(state, dispatch) { + var sel = state.selection, + nodeSel = sel instanceof prosemirrorState.NodeSelection, + point; + if (nodeSel) { + if (sel.node.isTextblock || !prosemirrorTransform.canJoin(state.doc, sel.from)) return false; + point = sel.from; + } else { + point = prosemirrorTransform.joinPoint(state.doc, sel.from, -1); + if (point == null) return false; + } + if (dispatch) { + var tr = state.tr.join(point); + if (nodeSel) tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, point - state.doc.resolve(point).nodeBefore.nodeSize)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var joinDown = function joinDown(state, dispatch) { + var sel = state.selection, + point; + if (sel instanceof prosemirrorState.NodeSelection) { + if (sel.node.isTextblock || !prosemirrorTransform.canJoin(state.doc, sel.to)) return false; + point = sel.to; + } else { + point = prosemirrorTransform.joinPoint(state.doc, sel.to, 1); + if (point == null) return false; + } + if (dispatch) dispatch(state.tr.join(point).scrollIntoView()); + return true; +}; +var lift = function lift(state, dispatch) { + var _state$selection3 = state.selection, + $from = _state$selection3.$from, + $to = _state$selection3.$to; + var range = $from.blockRange($to), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; +}; +var newlineInCode = function newlineInCode(state, dispatch) { + var _state$selection4 = state.selection, + $head = _state$selection4.$head, + $anchor = _state$selection4.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; + if (dispatch) dispatch(state.tr.insertText("\n").scrollIntoView()); + return true; +}; +function defaultBlockAt(match) { + for (var i = 0; i < match.edgeCount; i++) { + var _match$edge = match.edge(i), + type = _match$edge.type; + if (type.isTextblock && !type.hasRequiredAttrs()) return type; + } + return null; +} +var exitCode = function exitCode(state, dispatch) { + var _state$selection5 = state.selection, + $head = _state$selection5.$head, + $anchor = _state$selection5.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; + var above = $head.node(-1), + after = $head.indexAfter(-1), + type = defaultBlockAt(above.contentMatchAt(after)); + if (!type || !above.canReplaceWith(after, after, type)) return false; + if (dispatch) { + var pos = $head.after(), + tr = state.tr.replaceWith(pos, pos, type.createAndFill()); + tr.setSelection(prosemirrorState.Selection.near(tr.doc.resolve(pos), 1)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var createParagraphNear = function createParagraphNear(state, dispatch) { + var sel = state.selection, + $from = sel.$from, + $to = sel.$to; + if (sel instanceof prosemirrorState.AllSelection || $from.parent.inlineContent || $to.parent.inlineContent) return false; + var type = defaultBlockAt($to.parent.contentMatchAt($to.indexAfter())); + if (!type || !type.isTextblock) return false; + if (dispatch) { + var side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos; + var tr = state.tr.insert(side, type.createAndFill()); + tr.setSelection(prosemirrorState.TextSelection.create(tr.doc, side + 1)); + dispatch(tr.scrollIntoView()); + } + return true; +}; +var liftEmptyBlock = function liftEmptyBlock(state, dispatch) { + var $cursor = state.selection.$cursor; + if (!$cursor || $cursor.parent.content.size) return false; + if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) { + var before = $cursor.before(); + if (prosemirrorTransform.canSplit(state.doc, before)) { + if (dispatch) dispatch(state.tr.split(before).scrollIntoView()); + return true; + } + } + var range = $cursor.blockRange(), + target = range && prosemirrorTransform.liftTarget(range); + if (target == null) return false; + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; +}; +function splitBlockAs(splitNode) { + return function (state, dispatch) { + var _state$selection6 = state.selection, + $from = _state$selection6.$from, + $to = _state$selection6.$to; + if (state.selection instanceof prosemirrorState.NodeSelection && state.selection.node.isBlock) { + if (!$from.parentOffset || !prosemirrorTransform.canSplit(state.doc, $from.pos)) return false; + if (dispatch) dispatch(state.tr.split($from.pos).scrollIntoView()); + return true; + } + if (!$from.parent.isBlock) return false; + var atEnd = $to.parentOffset == $to.parent.content.size; + var tr = state.tr; + if (state.selection instanceof prosemirrorState.TextSelection || state.selection instanceof prosemirrorState.AllSelection) tr.deleteSelection(); + var deflt = $from.depth == 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1))); + var splitType = splitNode && splitNode($to.parent, atEnd, $from); + var types = splitType ? [splitType] : atEnd && deflt ? [{ + type: deflt + }] : undefined; + var can = prosemirrorTransform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, types); + if (!types && !can && prosemirrorTransform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ + type: deflt + }] : undefined)) { + if (deflt) types = [{ + type: deflt + }]; + can = true; + } + if (!can) return false; + tr.split(tr.mapping.map($from.pos), 1, types); + if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) { + var first = tr.mapping.map($from.before()), + $first = tr.doc.resolve(first); + if (deflt && $from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(tr.mapping.map($from.before()), deflt); + } + if (dispatch) dispatch(tr.scrollIntoView()); + return true; + }; +} +var splitBlock = splitBlockAs(); +var splitBlockKeepMarks = function splitBlockKeepMarks(state, dispatch) { + return splitBlock(state, dispatch && function (tr) { + var marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks(); + if (marks) tr.ensureMarks(marks); + dispatch(tr); + }); +}; +var selectParentNode = function selectParentNode(state, dispatch) { + var _state$selection7 = state.selection, + $from = _state$selection7.$from, + to = _state$selection7.to, + pos; + var same = $from.sharedDepth(to); + if (same == 0) return false; + pos = $from.before(same); + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.NodeSelection.create(state.doc, pos))); + return true; +}; +var selectAll = function selectAll(state, dispatch) { + if (dispatch) dispatch(state.tr.setSelection(new prosemirrorState.AllSelection(state.doc))); + return true; +}; +function joinMaybeClear(state, $pos, dispatch) { + var before = $pos.nodeBefore, + after = $pos.nodeAfter, + index = $pos.index(); + if (!before || !after || !before.type.compatibleContent(after.type)) return false; + if (!before.content.size && $pos.parent.canReplace(index - 1, index)) { + if (dispatch) dispatch(state.tr["delete"]($pos.pos - before.nodeSize, $pos.pos).scrollIntoView()); + return true; + } + if (!$pos.parent.canReplace(index, index + 1) || !(after.isTextblock || prosemirrorTransform.canJoin(state.doc, $pos.pos))) return false; + if (dispatch) dispatch(state.tr.join($pos.pos).scrollIntoView()); + return true; +} +function deleteBarrier(state, $cut, dispatch, dir) { + var before = $cut.nodeBefore, + after = $cut.nodeAfter, + conn, + match; + var isolated = before.type.spec.isolating || after.type.spec.isolating; + if (!isolated && joinMaybeClear(state, $cut, dispatch)) return true; + var canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1); + if (canDelAfter && (conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && match.matchType(conn[0] || after.type).validEnd) { + if (dispatch) { + var end = $cut.pos + after.nodeSize, + wrap = prosemirrorModel.Fragment.empty; + for (var i = conn.length - 1; i >= 0; i--) wrap = prosemirrorModel.Fragment.from(conn[i].create(null, wrap)); + wrap = prosemirrorModel.Fragment.from(before.copy(wrap)); + var tr = state.tr.step(new prosemirrorTransform.ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new prosemirrorModel.Slice(wrap, 1, 0), conn.length, true)); + var $joinAt = tr.doc.resolve(end + 2 * conn.length); + if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && prosemirrorTransform.canJoin(tr.doc, $joinAt.pos)) tr.join($joinAt.pos); + dispatch(tr.scrollIntoView()); + } + return true; + } + var selAfter = after.type.spec.isolating || dir > 0 && isolated ? null : prosemirrorState.Selection.findFrom($cut, 1); + var range = selAfter && selAfter.$from.blockRange(selAfter.$to), + target = range && prosemirrorTransform.liftTarget(range); + if (target != null && target >= $cut.depth) { + if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); + return true; + } + if (canDelAfter && textblockAt(after, "start", true) && textblockAt(before, "end")) { + var at = before, + _wrap = []; + for (;;) { + _wrap.push(at); + if (at.isTextblock) break; + at = at.lastChild; + } + var afterText = after, + afterDepth = 1; + for (; !afterText.isTextblock; afterText = afterText.firstChild) afterDepth++; + if (at.canReplace(at.childCount, at.childCount, afterText.content)) { + if (dispatch) { + var _end = prosemirrorModel.Fragment.empty; + for (var _i = _wrap.length - 1; _i >= 0; _i--) _end = prosemirrorModel.Fragment.from(_wrap[_i].copy(_end)); + var _tr = state.tr.step(new prosemirrorTransform.ReplaceAroundStep($cut.pos - _wrap.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new prosemirrorModel.Slice(_end, _wrap.length, 0), 0, true)); + dispatch(_tr.scrollIntoView()); + } + return true; + } + } + return false; +} +function selectTextblockSide(side) { + return function (state, dispatch) { + var sel = state.selection, + $pos = side < 0 ? sel.$from : sel.$to; + var depth = $pos.depth; + while ($pos.node(depth).isInline) { + if (!depth) return false; + depth--; + } + if (!$pos.node(depth).isTextblock) return false; + if (dispatch) dispatch(state.tr.setSelection(prosemirrorState.TextSelection.create(state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))); + return true; + }; +} +var selectTextblockStart = selectTextblockSide(-1); +var selectTextblockEnd = selectTextblockSide(1); +function wrapIn(nodeType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var _state$selection8 = state.selection, + $from = _state$selection8.$from, + $to = _state$selection8.$to; + var range = $from.blockRange($to), + wrapping = range && prosemirrorTransform.findWrapping(range, nodeType, attrs); + if (!wrapping) return false; + if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView()); + return true; + }; +} +function setBlockType(nodeType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var applicable = false; + for (var i = 0; i < state.selection.ranges.length && !applicable; i++) { + var _state$selection$rang = state.selection.ranges[i], + from = _state$selection$rang.$from.pos, + to = _state$selection$rang.$to.pos; + state.doc.nodesBetween(from, to, function (node, pos) { + if (applicable) return false; + if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return; + if (node.type == nodeType) { + applicable = true; + } else { + var $pos = state.doc.resolve(pos), + index = $pos.index(); + applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType); + } + }); + } + if (!applicable) return false; + if (dispatch) { + var tr = state.tr; + for (var _i2 = 0; _i2 < state.selection.ranges.length; _i2++) { + var _state$selection$rang2 = state.selection.ranges[_i2], + _from = _state$selection$rang2.$from.pos, + _to = _state$selection$rang2.$to.pos; + tr.setBlockType(_from, _to, nodeType, attrs); + } + dispatch(tr.scrollIntoView()); + } + return true; + }; +} +function markApplies(doc, ranges, type, enterAtoms) { + var _loop = function _loop() { + var _ranges$i = ranges[i], + $from = _ranges$i.$from, + $to = _ranges$i.$to; + var can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false; + doc.nodesBetween($from.pos, $to.pos, function (node, pos) { + if (can || !enterAtoms && node.isAtom && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) return false; + can = node.inlineContent && node.type.allowsMarkType(type); + }); + if (can) return { + v: true + }; + }, + _ret; + for (var i = 0; i < ranges.length; i++) { + _ret = _loop(); + if (_ret) return _ret.v; + } + return false; +} +function removeInlineAtoms(ranges) { + var result = []; + var _loop2 = function _loop2() { + var _ranges$i2 = ranges[i], + $from = _ranges$i2.$from, + $to = _ranges$i2.$to; + $from.doc.nodesBetween($from.pos, $to.pos, function (node, pos) { + if (node.isAtom && node.content.size && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) { + if (pos + 1 > $from.pos) result.push(new prosemirrorState.SelectionRange($from, $from.doc.resolve(pos + 1))); + $from = $from.doc.resolve(pos + 1 + node.content.size); + return false; + } + }); + if ($from.pos < $to.pos) result.push(new prosemirrorState.SelectionRange($from, $to)); + }; + for (var i = 0; i < ranges.length; i++) { + _loop2(); + } + return result; +} +function toggleMark(markType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var options = arguments.length > 2 ? arguments[2] : undefined; + var removeWhenPresent = (options && options.removeWhenPresent) !== false; + var enterAtoms = (options && options.enterInlineAtoms) !== false; + return function (state, dispatch) { + var _state$selection9 = state.selection, + empty = _state$selection9.empty, + $cursor = _state$selection9.$cursor, + ranges = _state$selection9.ranges; + if (empty && !$cursor || !markApplies(state.doc, ranges, markType, enterAtoms)) return false; + if (dispatch) { + if ($cursor) { + if (markType.isInSet(state.storedMarks || $cursor.marks())) dispatch(state.tr.removeStoredMark(markType));else dispatch(state.tr.addStoredMark(markType.create(attrs))); + } else { + var add, + tr = state.tr; + if (!enterAtoms) ranges = removeInlineAtoms(ranges); + if (removeWhenPresent) { + add = !ranges.some(function (r) { + return state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType); + }); + } else { + add = !ranges.every(function (r) { + var missing = false; + tr.doc.nodesBetween(r.$from.pos, r.$to.pos, function (node, pos, parent) { + if (missing) return false; + missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(node.textBetween(Math.max(0, r.$from.pos - pos), Math.min(node.nodeSize, r.$to.pos - pos)))); + }); + return !missing; + }); + } + for (var i = 0; i < ranges.length; i++) { + var _ranges$i3 = ranges[i], + $from = _ranges$i3.$from, + $to = _ranges$i3.$to; + if (!add) { + tr.removeMark($from.pos, $to.pos, markType); + } else { + var from = $from.pos, + to = $to.pos, + start = $from.nodeAfter, + end = $to.nodeBefore; + var spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0; + var spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0; + if (from + spaceStart < to) { + from += spaceStart; + to -= spaceEnd; + } + tr.addMark(from, to, markType.create(attrs)); + } + } + dispatch(tr.scrollIntoView()); + } + } + return true; + }; +} +function wrapDispatchForJoin(dispatch, isJoinable) { + return function (tr) { + if (!tr.isGeneric) return dispatch(tr); + var ranges = []; + for (var i = 0; i < tr.mapping.maps.length; i++) { + var map = tr.mapping.maps[i]; + for (var j = 0; j < ranges.length; j++) ranges[j] = map.map(ranges[j]); + map.forEach(function (_s, _e, from, to) { + return ranges.push(from, to); + }); + } + var joinable = []; + for (var _i3 = 0; _i3 < ranges.length; _i3 += 2) { + var from = ranges[_i3], + to = ranges[_i3 + 1]; + var $from = tr.doc.resolve(from), + depth = $from.sharedDepth(to), + parent = $from.node(depth); + for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { + var after = parent.maybeChild(index); + if (!after) break; + if (index && joinable.indexOf(pos) == -1) { + var before = parent.child(index - 1); + if (before.type == after.type && isJoinable(before, after)) joinable.push(pos); + } + pos += after.nodeSize; + } + } + joinable.sort(function (a, b) { + return a - b; + }); + for (var _i4 = joinable.length - 1; _i4 >= 0; _i4--) { + if (prosemirrorTransform.canJoin(tr.doc, joinable[_i4])) tr.join(joinable[_i4]); + } + dispatch(tr); + }; +} +function autoJoin(command, isJoinable) { + var canJoin = Array.isArray(isJoinable) ? function (node) { + return isJoinable.indexOf(node.type.name) > -1; + } : isJoinable; + return function (state, dispatch, view) { + return command(state, dispatch && wrapDispatchForJoin(dispatch, canJoin), view); + }; +} +function chainCommands() { + for (var _len = arguments.length, commands = new Array(_len), _key = 0; _key < _len; _key++) { + commands[_key] = arguments[_key]; + } + return function (state, dispatch, view) { + for (var i = 0; i < commands.length; i++) if (commands[i](state, dispatch, view)) return true; + return false; + }; +} +var backspace = chainCommands(deleteSelection, joinBackward, selectNodeBackward); +var del = chainCommands(deleteSelection, joinForward, selectNodeForward); +var pcBaseKeymap = { + "Enter": chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock), + "Mod-Enter": exitCode, + "Backspace": backspace, + "Mod-Backspace": backspace, + "Shift-Backspace": backspace, + "Delete": del, + "Mod-Delete": del, + "Mod-a": selectAll +}; +var macBaseKeymap = { + "Ctrl-h": pcBaseKeymap["Backspace"], + "Alt-Backspace": pcBaseKeymap["Mod-Backspace"], + "Ctrl-d": pcBaseKeymap["Delete"], + "Ctrl-Alt-Backspace": pcBaseKeymap["Mod-Delete"], + "Alt-Delete": pcBaseKeymap["Mod-Delete"], + "Alt-d": pcBaseKeymap["Mod-Delete"], + "Ctrl-a": selectTextblockStart, + "Ctrl-e": selectTextblockEnd +}; +for (var key in pcBaseKeymap) macBaseKeymap[key] = pcBaseKeymap[key]; +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : typeof os != "undefined" && os.platform ? os.platform() == "darwin" : false; +var baseKeymap = mac ? macBaseKeymap : pcBaseKeymap; +exports.autoJoin = autoJoin; +exports.baseKeymap = baseKeymap; +exports.chainCommands = chainCommands; +exports.createParagraphNear = createParagraphNear; +exports.deleteSelection = deleteSelection; +exports.exitCode = exitCode; +exports.joinBackward = joinBackward; +exports.joinDown = joinDown; +exports.joinForward = joinForward; +exports.joinTextblockBackward = joinTextblockBackward; +exports.joinTextblockForward = joinTextblockForward; +exports.joinUp = joinUp; +exports.lift = lift; +exports.liftEmptyBlock = liftEmptyBlock; +exports.macBaseKeymap = macBaseKeymap; +exports.newlineInCode = newlineInCode; +exports.pcBaseKeymap = pcBaseKeymap; +exports.selectAll = selectAll; +exports.selectNodeBackward = selectNodeBackward; +exports.selectNodeForward = selectNodeForward; +exports.selectParentNode = selectParentNode; +exports.selectTextblockEnd = selectTextblockEnd; +exports.selectTextblockStart = selectTextblockStart; +exports.setBlockType = setBlockType; +exports.splitBlock = splitBlock; +exports.splitBlockAs = splitBlockAs; +exports.splitBlockKeepMarks = splitBlockKeepMarks; +exports.toggleMark = toggleMark; +exports.wrapIn = wrapIn; + +}); +define("prosemirror-dropcursor",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorState = require('prosemirror-state'); + +var prosemirrorTransform = require('prosemirror-transform'); + +function dropCursor() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new prosemirrorState.Plugin({ + view: function view(editorView) { + return new DropCursorView(editorView, options); + } + }); +} + +var DropCursorView = function () { + function DropCursorView(editorView, options) { + var _this = this; + + _classCallCheck(this, DropCursorView); + + var _a; + + this.editorView = editorView; + this.cursorPos = null; + this.element = null; + this.timeout = -1; + this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1; + this.color = options.color === false ? undefined : options.color || "black"; + this["class"] = options["class"]; + this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(function (name) { + var handler = function handler(e) { + _this[name](e); + }; + + editorView.dom.addEventListener(name, handler); + return { + name: name, + handler: handler + }; + }); + } + + _createClass(DropCursorView, [{ + key: "destroy", + value: function destroy() { + var _this2 = this; + + this.handlers.forEach(function (_ref) { + var name = _ref.name, + handler = _ref.handler; + return _this2.editorView.dom.removeEventListener(name, handler); + }); + } + }, { + key: "update", + value: function update(editorView, prevState) { + if (this.cursorPos != null && prevState.doc != editorView.state.doc) { + if (this.cursorPos > editorView.state.doc.content.size) this.setCursor(null);else this.updateOverlay(); + } + } + }, { + key: "setCursor", + value: function setCursor(pos) { + if (pos == this.cursorPos) return; + this.cursorPos = pos; + + if (pos == null) { + this.element.parentNode.removeChild(this.element); + this.element = null; + } else { + this.updateOverlay(); + } + } + }, { + key: "updateOverlay", + value: function updateOverlay() { + var $pos = this.editorView.state.doc.resolve(this.cursorPos); + var isBlock = !$pos.parent.inlineContent, + rect; + + if (isBlock) { + var before = $pos.nodeBefore, + after = $pos.nodeAfter; + + if (before || after) { + var node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0)); + + if (node) { + var nodeRect = node.getBoundingClientRect(); + var top = before ? nodeRect.bottom : nodeRect.top; + if (before && after) top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2; + rect = { + left: nodeRect.left, + right: nodeRect.right, + top: top - this.width / 2, + bottom: top + this.width / 2 + }; + } + } + } + + if (!rect) { + var coords = this.editorView.coordsAtPos(this.cursorPos); + rect = { + left: coords.left - this.width / 2, + right: coords.left + this.width / 2, + top: coords.top, + bottom: coords.bottom + }; + } + + var parent = this.editorView.dom.offsetParent; + + if (!this.element) { + this.element = parent.appendChild(document.createElement("div")); + if (this["class"]) this.element.className = this["class"]; + this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;"; + + if (this.color) { + this.element.style.backgroundColor = this.color; + } + } + + this.element.classList.toggle("prosemirror-dropcursor-block", isBlock); + this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock); + var parentLeft, parentTop; + + if (!parent || parent == document.body && getComputedStyle(parent).position == "static") { + parentLeft = -pageXOffset; + parentTop = -pageYOffset; + } else { + var _rect = parent.getBoundingClientRect(); + + parentLeft = _rect.left - parent.scrollLeft; + parentTop = _rect.top - parent.scrollTop; + } + + this.element.style.left = rect.left - parentLeft + "px"; + this.element.style.top = rect.top - parentTop + "px"; + this.element.style.width = rect.right - rect.left + "px"; + this.element.style.height = rect.bottom - rect.top + "px"; + } + }, { + key: "scheduleRemoval", + value: function scheduleRemoval(timeout) { + var _this3 = this; + + clearTimeout(this.timeout); + this.timeout = setTimeout(function () { + return _this3.setCursor(null); + }, timeout); + } + }, { + key: "dragover", + value: function dragover(event) { + if (!this.editorView.editable) return; + var pos = this.editorView.posAtCoords({ + left: event.clientX, + top: event.clientY + }); + var node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside); + var disableDropCursor = node && node.type.spec.disableDropCursor; + var disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor; + + if (pos && !disabled) { + var target = pos.pos; + + if (this.editorView.dragging && this.editorView.dragging.slice) { + var point = prosemirrorTransform.dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice); + if (point != null) target = point; + } + + this.setCursor(target); + this.scheduleRemoval(5000); + } + } + }, { + key: "dragend", + value: function dragend() { + this.scheduleRemoval(20); + } + }, { + key: "drop", + value: function drop() { + this.scheduleRemoval(20); + } + }, { + key: "dragleave", + value: function dragleave(event) { + if (event.target == this.editorView.dom || !this.editorView.dom.contains(event.relatedTarget)) this.setCursor(null); + } + }]); + + return DropCursorView; +}(); + +exports.dropCursor = dropCursor; + +}); +define("prosemirror-example-setup",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorKeymap = require('prosemirror-keymap'); +var prosemirrorHistory = require('prosemirror-history'); +var prosemirrorCommands = require('prosemirror-commands'); +var prosemirrorState = require('prosemirror-state'); +var prosemirrorDropcursor = require('prosemirror-dropcursor'); +var prosemirrorGapcursor = require('prosemirror-gapcursor'); +var prosemirrorMenu = require('prosemirror-menu'); +var prosemirrorSchemaList = require('prosemirror-schema-list'); +var prosemirrorInputrules = require('prosemirror-inputrules'); +var prefix = "ProseMirror-prompt"; +function openPrompt(options) { + var wrapper = document.body.appendChild(document.createElement("div")); + wrapper.className = prefix; + var mouseOutside = function mouseOutside(e) { + if (!wrapper.contains(e.target)) close(); + }; + setTimeout(function () { + return window.addEventListener("mousedown", mouseOutside); + }, 50); + var close = function close() { + window.removeEventListener("mousedown", mouseOutside); + if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper); + }; + var domFields = []; + for (var name in options.fields) domFields.push(options.fields[name].render()); + var submitButton = document.createElement("button"); + submitButton.type = "submit"; + submitButton.className = prefix + "-submit"; + submitButton.textContent = "OK"; + var cancelButton = document.createElement("button"); + cancelButton.type = "button"; + cancelButton.className = prefix + "-cancel"; + cancelButton.textContent = "Cancel"; + cancelButton.addEventListener("click", close); + var form = wrapper.appendChild(document.createElement("form")); + if (options.title) form.appendChild(document.createElement("h5")).textContent = options.title; + domFields.forEach(function (field) { + form.appendChild(document.createElement("div")).appendChild(field); + }); + var buttons = form.appendChild(document.createElement("div")); + buttons.className = prefix + "-buttons"; + buttons.appendChild(submitButton); + buttons.appendChild(document.createTextNode(" ")); + buttons.appendChild(cancelButton); + var box = wrapper.getBoundingClientRect(); + wrapper.style.top = (window.innerHeight - box.height) / 2 + "px"; + wrapper.style.left = (window.innerWidth - box.width) / 2 + "px"; + var submit = function submit() { + var params = getValues(options.fields, domFields); + if (params) { + close(); + options.callback(params); + } + }; + form.addEventListener("submit", function (e) { + e.preventDefault(); + submit(); + }); + form.addEventListener("keydown", function (e) { + if (e.keyCode == 27) { + e.preventDefault(); + close(); + } else if (e.keyCode == 13 && !(e.ctrlKey || e.metaKey || e.shiftKey)) { + e.preventDefault(); + submit(); + } else if (e.keyCode == 9) { + window.setTimeout(function () { + if (!wrapper.contains(document.activeElement)) close(); + }, 500); + } + }); + var input = form.elements[0]; + if (input) input.focus(); +} +function getValues(fields, domFields) { + var result = Object.create(null), + i = 0; + for (var name in fields) { + var field = fields[name], + dom = domFields[i++]; + var value = field.read(dom), + bad = field.validate(value); + if (bad) { + reportInvalid(dom, bad); + return null; + } + result[name] = field.clean(value); + } + return result; +} +function reportInvalid(dom, message) { + var parent = dom.parentNode; + var msg = parent.appendChild(document.createElement("div")); + msg.style.left = dom.offsetLeft + dom.offsetWidth + 2 + "px"; + msg.style.top = dom.offsetTop - 5 + "px"; + msg.className = "ProseMirror-invalid"; + msg.textContent = message; + setTimeout(function () { + return parent.removeChild(msg); + }, 1500); +} +var Field = function () { + function Field(options) { + _classCallCheck(this, Field); + this.options = options; + } + _createClass(Field, [{ + key: "read", + value: function read(dom) { + return dom.value; + } + }, { + key: "validateType", + value: function validateType(value) { + return null; + } + }, { + key: "validate", + value: function validate(value) { + if (!value && this.options.required) return "Required field"; + return this.validateType(value) || (this.options.validate ? this.options.validate(value) : null); + } + }, { + key: "clean", + value: function clean(value) { + return this.options.clean ? this.options.clean(value) : value; + } + }]); + return Field; +}(); +var TextField = function (_Field) { + _inherits(TextField, _Field); + var _super = _createSuper(TextField); + function TextField() { + _classCallCheck(this, TextField); + return _super.apply(this, arguments); + } + _createClass(TextField, [{ + key: "render", + value: function render() { + var input = document.createElement("input"); + input.type = "text"; + input.placeholder = this.options.label; + input.value = this.options.value || ""; + input.autocomplete = "off"; + return input; + } + }]); + return TextField; +}(Field); +function canInsert(state, nodeType) { + var $from = state.selection.$from; + for (var d = $from.depth; d >= 0; d--) { + var index = $from.index(d); + if ($from.node(d).canReplaceWith(index, index, nodeType)) return true; + } + return false; +} +function insertImageItem(nodeType) { + return new prosemirrorMenu.MenuItem({ + title: "Insert image", + label: "Image", + enable: function enable(state) { + return canInsert(state, nodeType); + }, + run: function run(state, _, view) { + var _state$selection = state.selection, + from = _state$selection.from, + to = _state$selection.to, + attrs = null; + if (state.selection instanceof prosemirrorState.NodeSelection && state.selection.node.type == nodeType) attrs = state.selection.node.attrs; + openPrompt({ + title: "Insert image", + fields: { + src: new TextField({ + label: "Location", + required: true, + value: attrs && attrs.src + }), + title: new TextField({ + label: "Title", + value: attrs && attrs.title + }), + alt: new TextField({ + label: "Description", + value: attrs ? attrs.alt : state.doc.textBetween(from, to, " ") + }) + }, + callback: function callback(attrs) { + view.dispatch(view.state.tr.replaceSelectionWith(nodeType.createAndFill(attrs))); + view.focus(); + } + }); + } + }); +} +function cmdItem(cmd, options) { + var passedOptions = { + label: options.title, + run: cmd + }; + for (var prop in options) passedOptions[prop] = options[prop]; + if (!options.enable && !options.select) passedOptions[options.enable ? "enable" : "select"] = function (state) { + return cmd(state); + }; + return new prosemirrorMenu.MenuItem(passedOptions); +} +function markActive(state, type) { + var _state$selection2 = state.selection, + from = _state$selection2.from, + $from = _state$selection2.$from, + to = _state$selection2.to, + empty = _state$selection2.empty; + if (empty) return !!type.isInSet(state.storedMarks || $from.marks());else return state.doc.rangeHasMark(from, to, type); +} +function markItem(markType, options) { + var passedOptions = { + active: function active(state) { + return markActive(state, markType); + } + }; + for (var prop in options) passedOptions[prop] = options[prop]; + return cmdItem(prosemirrorCommands.toggleMark(markType), passedOptions); +} +function linkItem(markType) { + return new prosemirrorMenu.MenuItem({ + title: "Add or remove link", + icon: prosemirrorMenu.icons.link, + active: function active(state) { + return markActive(state, markType); + }, + enable: function enable(state) { + return !state.selection.empty; + }, + run: function run(state, dispatch, view) { + if (markActive(state, markType)) { + prosemirrorCommands.toggleMark(markType)(state, dispatch); + return true; + } + openPrompt({ + title: "Create a link", + fields: { + href: new TextField({ + label: "Link target", + required: true + }), + title: new TextField({ + label: "Title" + }) + }, + callback: function callback(attrs) { + prosemirrorCommands.toggleMark(markType, attrs)(view.state, view.dispatch); + view.focus(); + } + }); + } + }); +} +function wrapListItem(nodeType, options) { + return cmdItem(prosemirrorSchemaList.wrapInList(nodeType, options.attrs), options); +} +function buildMenuItems(schema) { + var r = {}; + var mark; + if (mark = schema.marks.strong) r.toggleStrong = markItem(mark, { + title: "Toggle strong style", + icon: prosemirrorMenu.icons.strong + }); + if (mark = schema.marks.em) r.toggleEm = markItem(mark, { + title: "Toggle emphasis", + icon: prosemirrorMenu.icons.em + }); + if (mark = schema.marks.code) r.toggleCode = markItem(mark, { + title: "Toggle code font", + icon: prosemirrorMenu.icons.code + }); + if (mark = schema.marks.link) r.toggleLink = linkItem(mark); + var node; + if (node = schema.nodes.image) r.insertImage = insertImageItem(node); + if (node = schema.nodes.bullet_list) r.wrapBulletList = wrapListItem(node, { + title: "Wrap in bullet list", + icon: prosemirrorMenu.icons.bulletList + }); + if (node = schema.nodes.ordered_list) r.wrapOrderedList = wrapListItem(node, { + title: "Wrap in ordered list", + icon: prosemirrorMenu.icons.orderedList + }); + if (node = schema.nodes.blockquote) r.wrapBlockQuote = prosemirrorMenu.wrapItem(node, { + title: "Wrap in block quote", + icon: prosemirrorMenu.icons.blockquote + }); + if (node = schema.nodes.paragraph) r.makeParagraph = prosemirrorMenu.blockTypeItem(node, { + title: "Change to paragraph", + label: "Plain" + }); + if (node = schema.nodes.code_block) r.makeCodeBlock = prosemirrorMenu.blockTypeItem(node, { + title: "Change to code block", + label: "Code" + }); + if (node = schema.nodes.heading) for (var i = 1; i <= 10; i++) r["makeHead" + i] = prosemirrorMenu.blockTypeItem(node, { + title: "Change to heading " + i, + label: "Level " + i, + attrs: { + level: i + } + }); + if (node = schema.nodes.horizontal_rule) { + var hr = node; + r.insertHorizontalRule = new prosemirrorMenu.MenuItem({ + title: "Insert horizontal rule", + label: "Horizontal rule", + enable: function enable(state) { + return canInsert(state, hr); + }, + run: function run(state, dispatch) { + dispatch(state.tr.replaceSelectionWith(hr.create())); + } + }); + } + var cut = function cut(arr) { + return arr.filter(function (x) { + return x; + }); + }; + r.insertMenu = new prosemirrorMenu.Dropdown(cut([r.insertImage, r.insertHorizontalRule]), { + label: "Insert" + }); + r.typeMenu = new prosemirrorMenu.Dropdown(cut([r.makeParagraph, r.makeCodeBlock, r.makeHead1 && new prosemirrorMenu.DropdownSubmenu(cut([r.makeHead1, r.makeHead2, r.makeHead3, r.makeHead4, r.makeHead5, r.makeHead6]), { + label: "Heading" + })]), { + label: "Type..." + }); + r.inlineMenu = [cut([r.toggleStrong, r.toggleEm, r.toggleCode, r.toggleLink])]; + r.blockMenu = [cut([r.wrapBulletList, r.wrapOrderedList, r.wrapBlockQuote, prosemirrorMenu.joinUpItem, prosemirrorMenu.liftItem, prosemirrorMenu.selectParentNodeItem])]; + r.fullMenu = r.inlineMenu.concat([[r.insertMenu, r.typeMenu]], [[prosemirrorMenu.undoItem, prosemirrorMenu.redoItem]], r.blockMenu); + return r; +} +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false; +function buildKeymap(schema, mapKeys) { + var keys = {}, + type; + function bind(key, cmd) { + if (mapKeys) { + var mapped = mapKeys[key]; + if (mapped === false) return; + if (mapped) key = mapped; + } + keys[key] = cmd; + } + bind("Mod-z", prosemirrorHistory.undo); + bind("Shift-Mod-z", prosemirrorHistory.redo); + bind("Backspace", prosemirrorInputrules.undoInputRule); + if (!mac) bind("Mod-y", prosemirrorHistory.redo); + bind("Alt-ArrowUp", prosemirrorCommands.joinUp); + bind("Alt-ArrowDown", prosemirrorCommands.joinDown); + bind("Mod-BracketLeft", prosemirrorCommands.lift); + bind("Escape", prosemirrorCommands.selectParentNode); + if (type = schema.marks.strong) { + bind("Mod-b", prosemirrorCommands.toggleMark(type)); + bind("Mod-B", prosemirrorCommands.toggleMark(type)); + } + if (type = schema.marks.em) { + bind("Mod-i", prosemirrorCommands.toggleMark(type)); + bind("Mod-I", prosemirrorCommands.toggleMark(type)); + } + if (type = schema.marks.code) bind("Mod-`", prosemirrorCommands.toggleMark(type)); + if (type = schema.nodes.bullet_list) bind("Shift-Ctrl-8", prosemirrorSchemaList.wrapInList(type)); + if (type = schema.nodes.ordered_list) bind("Shift-Ctrl-9", prosemirrorSchemaList.wrapInList(type)); + if (type = schema.nodes.blockquote) bind("Ctrl->", prosemirrorCommands.wrapIn(type)); + if (type = schema.nodes.hard_break) { + var br = type, + cmd = prosemirrorCommands.chainCommands(prosemirrorCommands.exitCode, function (state, dispatch) { + if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView()); + return true; + }); + bind("Mod-Enter", cmd); + bind("Shift-Enter", cmd); + if (mac) bind("Ctrl-Enter", cmd); + } + if (type = schema.nodes.list_item) { + bind("Enter", prosemirrorSchemaList.splitListItem(type)); + bind("Mod-[", prosemirrorSchemaList.liftListItem(type)); + bind("Mod-]", prosemirrorSchemaList.sinkListItem(type)); + } + if (type = schema.nodes.paragraph) bind("Shift-Ctrl-0", prosemirrorCommands.setBlockType(type)); + if (type = schema.nodes.code_block) bind("Shift-Ctrl-\\", prosemirrorCommands.setBlockType(type)); + if (type = schema.nodes.heading) for (var i = 1; i <= 6; i++) bind("Shift-Ctrl-" + i, prosemirrorCommands.setBlockType(type, { + level: i + })); + if (type = schema.nodes.horizontal_rule) { + var hr = type; + bind("Mod-_", function (state, dispatch) { + if (dispatch) dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView()); + return true; + }); + } + return keys; +} +function blockQuoteRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^\s*>\s$/, nodeType); +} +function orderedListRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^(\d+)\.\s$/, nodeType, function (match) { + return { + order: +match[1] + }; + }, function (match, node) { + return node.childCount + node.attrs.order == +match[1]; + }); +} +function bulletListRule(nodeType) { + return prosemirrorInputrules.wrappingInputRule(/^\s*([-+*])\s$/, nodeType); +} +function codeBlockRule(nodeType) { + return prosemirrorInputrules.textblockTypeInputRule(/^```$/, nodeType); +} +function headingRule(nodeType, maxLevel) { + return prosemirrorInputrules.textblockTypeInputRule(new RegExp("^(#{1," + maxLevel + "})\\s$"), nodeType, function (match) { + return { + level: match[1].length + }; + }); +} +function buildInputRules(schema) { + var rules = prosemirrorInputrules.smartQuotes.concat(prosemirrorInputrules.ellipsis, prosemirrorInputrules.emDash), + type; + if (type = schema.nodes.blockquote) rules.push(blockQuoteRule(type)); + if (type = schema.nodes.ordered_list) rules.push(orderedListRule(type)); + if (type = schema.nodes.bullet_list) rules.push(bulletListRule(type)); + if (type = schema.nodes.code_block) rules.push(codeBlockRule(type)); + if (type = schema.nodes.heading) rules.push(headingRule(type, 6)); + return prosemirrorInputrules.inputRules({ + rules: rules + }); +} +function exampleSetup(options) { + var plugins = [buildInputRules(options.schema), prosemirrorKeymap.keymap(buildKeymap(options.schema, options.mapKeys)), prosemirrorKeymap.keymap(prosemirrorCommands.baseKeymap), prosemirrorDropcursor.dropCursor(), prosemirrorGapcursor.gapCursor()]; + if (options.menuBar !== false) plugins.push(prosemirrorMenu.menuBar({ + floating: options.floatingMenu !== false, + content: options.menuContent || buildMenuItems(options.schema).fullMenu + })); + if (options.history !== false) plugins.push(prosemirrorHistory.history()); + return plugins.concat(new prosemirrorState.Plugin({ + props: { + attributes: { + "class": "ProseMirror-example-setup-style" + } + } + })); +} +exports.buildInputRules = buildInputRules; +exports.buildKeymap = buildKeymap; +exports.buildMenuItems = buildMenuItems; +exports.exampleSetup = exampleSetup; + +}); +define("prosemirror-gapcursor",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorKeymap = require('prosemirror-keymap'); + +var prosemirrorState = require('prosemirror-state'); + +var prosemirrorModel = require('prosemirror-model'); + +var prosemirrorView = require('prosemirror-view'); + +var GapCursor = function (_prosemirrorState$Sel) { + _inherits(GapCursor, _prosemirrorState$Sel); + + var _super = _createSuper(GapCursor); + + function GapCursor($pos) { + _classCallCheck(this, GapCursor); + + return _super.call(this, $pos, $pos); + } + + _createClass(GapCursor, [{ + key: "map", + value: function map(doc, mapping) { + var $pos = doc.resolve(mapping.map(this.head)); + return GapCursor.valid($pos) ? new GapCursor($pos) : prosemirrorState.Selection.near($pos); + } + }, { + key: "content", + value: function content() { + return prosemirrorModel.Slice.empty; + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof GapCursor && other.head == this.head; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "gapcursor", + pos: this.head + }; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new GapBookmark(this.anchor); + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for GapCursor.fromJSON"); + return new GapCursor(doc.resolve(json.pos)); + } + }, { + key: "valid", + value: function valid($pos) { + var parent = $pos.parent; + if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos)) return false; + var override = parent.type.spec.allowGapCursor; + if (override != null) return override; + var deflt = parent.contentMatchAt($pos.index()).defaultType; + return deflt && deflt.isTextblock; + } + }, { + key: "findGapCursorFrom", + value: function findGapCursorFrom($pos, dir) { + var mustMove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + search: for (;;) { + if (!mustMove && GapCursor.valid($pos)) return $pos; + var pos = $pos.pos, + next = null; + + for (var d = $pos.depth;; d--) { + var parent = $pos.node(d); + + if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) { + next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1); + break; + } else if (d == 0) { + return null; + } + + pos += dir; + var $cur = $pos.doc.resolve(pos); + if (GapCursor.valid($cur)) return $cur; + } + + for (;;) { + var inside = dir > 0 ? next.firstChild : next.lastChild; + + if (!inside) { + if (next.isAtom && !next.isText && !prosemirrorState.NodeSelection.isSelectable(next)) { + $pos = $pos.doc.resolve(pos + next.nodeSize * dir); + mustMove = false; + continue search; + } + + break; + } + + next = inside; + pos += dir; + + var _$cur = $pos.doc.resolve(pos); + + if (GapCursor.valid(_$cur)) return _$cur; + } + + return null; + } + } + }]); + + return GapCursor; +}(prosemirrorState.Selection); + +GapCursor.prototype.visible = false; +GapCursor.findFrom = GapCursor.findGapCursorFrom; +prosemirrorState.Selection.jsonID("gapcursor", GapCursor); + +var GapBookmark = function () { + function GapBookmark(pos) { + _classCallCheck(this, GapBookmark); + + this.pos = pos; + } + + _createClass(GapBookmark, [{ + key: "map", + value: function map(mapping) { + return new GapBookmark(mapping.map(this.pos)); + } + }, { + key: "resolve", + value: function resolve(doc) { + var $pos = doc.resolve(this.pos); + return GapCursor.valid($pos) ? new GapCursor($pos) : prosemirrorState.Selection.near($pos); + } + }]); + + return GapBookmark; +}(); + +function closedBefore($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.index(d), + parent = $pos.node(d); + + if (index == 0) { + if (parent.type.spec.isolating) return true; + continue; + } + + for (var before = parent.child(index - 1);; before = before.lastChild) { + if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating) return true; + if (before.inlineContent) return false; + } + } + + return true; +} + +function closedAfter($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.indexAfter(d), + parent = $pos.node(d); + + if (index == parent.childCount) { + if (parent.type.spec.isolating) return true; + continue; + } + + for (var after = parent.child(index);; after = after.firstChild) { + if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating) return true; + if (after.inlineContent) return false; + } + } + + return true; +} + +function gapCursor() { + return new prosemirrorState.Plugin({ + props: { + decorations: drawGapCursor, + createSelectionBetween: function createSelectionBetween(_view, $anchor, $head) { + return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null; + }, + handleClick: handleClick, + handleKeyDown: handleKeyDown, + handleDOMEvents: { + beforeinput: beforeinput + } + } + }); +} + +var handleKeyDown = prosemirrorKeymap.keydownHandler({ + "ArrowLeft": arrow("horiz", -1), + "ArrowRight": arrow("horiz", 1), + "ArrowUp": arrow("vert", -1), + "ArrowDown": arrow("vert", 1) +}); + +function arrow(axis, dir) { + var dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left"; + return function (state, dispatch, view) { + var sel = state.selection; + var $start = dir > 0 ? sel.$to : sel.$from, + mustMove = sel.empty; + + if (sel instanceof prosemirrorState.TextSelection) { + if (!view.endOfTextblock(dirStr) || $start.depth == 0) return false; + mustMove = false; + $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before()); + } + + var $found = GapCursor.findGapCursorFrom($start, dir, mustMove); + if (!$found) return false; + if (dispatch) dispatch(state.tr.setSelection(new GapCursor($found))); + return true; + }; +} + +function handleClick(view, pos, event) { + if (!view || !view.editable) return false; + var $pos = view.state.doc.resolve(pos); + if (!GapCursor.valid($pos)) return false; + var clickPos = view.posAtCoords({ + left: event.clientX, + top: event.clientY + }); + if (clickPos && clickPos.inside > -1 && prosemirrorState.NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside))) return false; + view.dispatch(view.state.tr.setSelection(new GapCursor($pos))); + return true; +} + +function beforeinput(view, event) { + if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor)) return false; + var $from = view.state.selection.$from; + var insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text); + if (!insert) return false; + var frag = prosemirrorModel.Fragment.empty; + + for (var i = insert.length - 1; i >= 0; i--) { + frag = prosemirrorModel.Fragment.from(insert[i].createAndFill(null, frag)); + } + + var tr = view.state.tr.replace($from.pos, $from.pos, new prosemirrorModel.Slice(frag, 0, 0)); + tr.setSelection(prosemirrorState.TextSelection.near(tr.doc.resolve($from.pos + 1))); + view.dispatch(tr); + return false; +} + +function drawGapCursor(state) { + if (!(state.selection instanceof GapCursor)) return null; + var node = document.createElement("div"); + node.className = "ProseMirror-gapcursor"; + return prosemirrorView.DecorationSet.create(state.doc, [prosemirrorView.Decoration.widget(state.selection.head, node, { + key: "gapcursor" + })]); +} + +exports.GapCursor = GapCursor; +exports.gapCursor = gapCursor; + +}); +define("prosemirror-history",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var RopeSequence = require('rope-sequence'); +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorState = require('prosemirror-state'); +var max_empty_items = 500; +var Branch = function () { + function Branch(items, eventCount) { + _classCallCheck(this, Branch); + this.items = items; + this.eventCount = eventCount; + } + _createClass(Branch, [{ + key: "popEvent", + value: function popEvent(state, preserveItems) { + var _this = this; + if (this.eventCount == 0) return null; + var end = this.items.length; + for (;; end--) { + var next = this.items.get(end - 1); + if (next.selection) { + --end; + break; + } + } + var remap, mapFrom; + if (preserveItems) { + remap = this.remapping(end, this.items.length); + mapFrom = remap.maps.length; + } + var transform = state.tr; + var selection, remaining; + var addAfter = [], + addBefore = []; + this.items.forEach(function (item, i) { + if (!item.step) { + if (!remap) { + remap = _this.remapping(end, i + 1); + mapFrom = remap.maps.length; + } + mapFrom--; + addBefore.push(item); + return; + } + if (remap) { + addBefore.push(new Item(item.map)); + var step = item.step.map(remap.slice(mapFrom)), + map; + if (step && transform.maybeStep(step).doc) { + map = transform.mapping.maps[transform.mapping.maps.length - 1]; + addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length)); + } + mapFrom--; + if (map) remap.appendMap(map, mapFrom); + } else { + transform.maybeStep(item.step); + } + if (item.selection) { + selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection; + remaining = new Branch(_this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), _this.eventCount - 1); + return false; + } + }, this.items.length, 0); + return { + remaining: remaining, + transform: transform, + selection: selection + }; + } + }, { + key: "addTransform", + value: function addTransform(transform, selection, histOptions, preserveItems) { + var newItems = [], + eventCount = this.eventCount; + var oldItems = this.items, + lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null; + for (var i = 0; i < transform.steps.length; i++) { + var step = transform.steps[i].invert(transform.docs[i]); + var item = new Item(transform.mapping.maps[i], step, selection), + merged = void 0; + if (merged = lastItem && lastItem.merge(item)) { + item = merged; + if (i) newItems.pop();else oldItems = oldItems.slice(0, oldItems.length - 1); + } + newItems.push(item); + if (selection) { + eventCount++; + selection = undefined; + } + if (!preserveItems) lastItem = item; + } + var overflow = eventCount - histOptions.depth; + if (overflow > DEPTH_OVERFLOW) { + oldItems = cutOffEvents(oldItems, overflow); + eventCount -= overflow; + } + return new Branch(oldItems.append(newItems), eventCount); + } + }, { + key: "remapping", + value: function remapping(from, to) { + var maps = new prosemirrorTransform.Mapping(); + this.items.forEach(function (item, i) { + var mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from ? maps.maps.length - item.mirrorOffset : undefined; + maps.appendMap(item.map, mirrorPos); + }, from, to); + return maps; + } + }, { + key: "addMaps", + value: function addMaps(array) { + if (this.eventCount == 0) return this; + return new Branch(this.items.append(array.map(function (map) { + return new Item(map); + })), this.eventCount); + } + }, { + key: "rebased", + value: function rebased(rebasedTransform, rebasedCount) { + if (!this.eventCount) return this; + var rebasedItems = [], + start = Math.max(0, this.items.length - rebasedCount); + var mapping = rebasedTransform.mapping; + var newUntil = rebasedTransform.steps.length; + var eventCount = this.eventCount; + this.items.forEach(function (item) { + if (item.selection) eventCount--; + }, start); + var iRebased = rebasedCount; + this.items.forEach(function (item) { + var pos = mapping.getMirror(--iRebased); + if (pos == null) return; + newUntil = Math.min(newUntil, pos); + var map = mapping.maps[pos]; + if (item.step) { + var step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]); + var selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos)); + if (selection) eventCount++; + rebasedItems.push(new Item(map, step, selection)); + } else { + rebasedItems.push(new Item(map)); + } + }, start); + var newMaps = []; + for (var i = rebasedCount; i < newUntil; i++) newMaps.push(new Item(mapping.maps[i])); + var items = this.items.slice(0, start).append(newMaps).append(rebasedItems); + var branch = new Branch(items, eventCount); + if (branch.emptyItemCount() > max_empty_items) branch = branch.compress(this.items.length - rebasedItems.length); + return branch; + } + }, { + key: "emptyItemCount", + value: function emptyItemCount() { + var count = 0; + this.items.forEach(function (item) { + if (!item.step) count++; + }); + return count; + } + }, { + key: "compress", + value: function compress() { + var upto = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items.length; + var remap = this.remapping(0, upto), + mapFrom = remap.maps.length; + var items = [], + events = 0; + this.items.forEach(function (item, i) { + if (i >= upto) { + items.push(item); + if (item.selection) events++; + } else if (item.step) { + var step = item.step.map(remap.slice(mapFrom)), + map = step && step.getMap(); + mapFrom--; + if (map) remap.appendMap(map, mapFrom); + if (step) { + var selection = item.selection && item.selection.map(remap.slice(mapFrom)); + if (selection) events++; + var newItem = new Item(map.invert(), step, selection), + merged, + last = items.length - 1; + if (merged = items.length && items[last].merge(newItem)) items[last] = merged;else items.push(newItem); + } + } else if (item.map) { + mapFrom--; + } + }, this.items.length, 0); + return new Branch(RopeSequence.from(items.reverse()), events); + } + }]); + return Branch; +}(); +Branch.empty = new Branch(RopeSequence.empty, 0); +function cutOffEvents(items, n) { + var cutPoint; + items.forEach(function (item, i) { + if (item.selection && n-- == 0) { + cutPoint = i; + return false; + } + }); + return items.slice(cutPoint); +} +var Item = function () { + function Item(map, step, selection, mirrorOffset) { + _classCallCheck(this, Item); + this.map = map; + this.step = step; + this.selection = selection; + this.mirrorOffset = mirrorOffset; + } + _createClass(Item, [{ + key: "merge", + value: function merge(other) { + if (this.step && other.step && !other.selection) { + var step = other.step.merge(this.step); + if (step) return new Item(step.getMap().invert(), step, this.selection); + } + } + }]); + return Item; +}(); +var HistoryState = _createClass(function HistoryState(done, undone, prevRanges, prevTime, prevComposition) { + _classCallCheck(this, HistoryState); + this.done = done; + this.undone = undone; + this.prevRanges = prevRanges; + this.prevTime = prevTime; + this.prevComposition = prevComposition; +}); +var DEPTH_OVERFLOW = 20; +function applyTransaction(history, state, tr, options) { + var historyTr = tr.getMeta(historyKey), + rebased; + if (historyTr) return historyTr.historyState; + if (tr.getMeta(closeHistoryKey)) history = new HistoryState(history.done, history.undone, null, 0, -1); + var appended = tr.getMeta("appendedTransaction"); + if (tr.steps.length == 0) { + return history; + } else if (appended && appended.getMeta(historyKey)) { + if (appended.getMeta(historyKey).redo) return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);else return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition); + } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) { + var composition = tr.getMeta("composition"); + var newGroup = history.prevTime == 0 || !appended && history.prevComposition != composition && (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges)); + var prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps); + return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition); + } else if (rebased = tr.getMeta("rebased")) { + return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition); + } else { + return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition); + } +} +function isAdjacentTo(transform, prevRanges) { + if (!prevRanges) return false; + if (!transform.docChanged) return true; + var adjacent = false; + transform.mapping.maps[0].forEach(function (start, end) { + for (var i = 0; i < prevRanges.length; i += 2) if (start <= prevRanges[i + 1] && end >= prevRanges[i]) adjacent = true; + }); + return adjacent; +} +function rangesFor(maps) { + var result = []; + for (var i = maps.length - 1; i >= 0 && result.length == 0; i--) maps[i].forEach(function (_from, _to, from, to) { + return result.push(from, to); + }); + return result; +} +function mapRanges(ranges, mapping) { + if (!ranges) return null; + var result = []; + for (var i = 0; i < ranges.length; i += 2) { + var from = mapping.map(ranges[i], 1), + to = mapping.map(ranges[i + 1], -1); + if (from <= to) result.push(from, to); + } + return result; +} +function histTransaction(history, state, redo) { + var preserveItems = mustPreserveItems(state); + var histOptions = historyKey.get(state).spec.config; + var pop = (redo ? history.undone : history.done).popEvent(state, preserveItems); + if (!pop) return null; + var selection = pop.selection.resolve(pop.transform.doc); + var added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems); + var newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1); + return pop.transform.setSelection(selection).setMeta(historyKey, { + redo: redo, + historyState: newHist + }); +} +var cachedPreserveItems = false, + cachedPreserveItemsPlugins = null; +function mustPreserveItems(state) { + var plugins = state.plugins; + if (cachedPreserveItemsPlugins != plugins) { + cachedPreserveItems = false; + cachedPreserveItemsPlugins = plugins; + for (var i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) { + cachedPreserveItems = true; + break; + } + } + return cachedPreserveItems; +} +function closeHistory(tr) { + return tr.setMeta(closeHistoryKey, true); +} +var historyKey = new prosemirrorState.PluginKey("history"); +var closeHistoryKey = new prosemirrorState.PluginKey("closeHistory"); +function history() { + var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + config = { + depth: config.depth || 100, + newGroupDelay: config.newGroupDelay || 500 + }; + return new prosemirrorState.Plugin({ + key: historyKey, + state: { + init: function init() { + return new HistoryState(Branch.empty, Branch.empty, null, 0, -1); + }, + apply: function apply(tr, hist, state) { + return applyTransaction(hist, state, tr, config); + } + }, + config: config, + props: { + handleDOMEvents: { + beforeinput: function beforeinput(view, e) { + var inputType = e.inputType; + var command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null; + if (!command) return false; + e.preventDefault(); + return command(view.state, view.dispatch); + } + } + } + }); +} +function buildCommand(redo, scroll) { + return function (state, dispatch) { + var hist = historyKey.getState(state); + if (!hist || (redo ? hist.undone : hist.done).eventCount == 0) return false; + if (dispatch) { + var tr = histTransaction(hist, state, redo); + if (tr) dispatch(scroll ? tr.scrollIntoView() : tr); + } + return true; + }; +} +var undo = buildCommand(false, true); +var redo = buildCommand(true, true); +var undoNoScroll = buildCommand(false, false); +var redoNoScroll = buildCommand(true, false); +function undoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.done.eventCount : 0; +} +function redoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.undone.eventCount : 0; +} +exports.closeHistory = closeHistory; +exports.history = history; +exports.redo = redo; +exports.redoDepth = redoDepth; +exports.redoNoScroll = redoNoScroll; +exports.undo = undo; +exports.undoDepth = undoDepth; +exports.undoNoScroll = undoNoScroll; + +}); +define("prosemirror-inputrules",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var prosemirrorState = require('prosemirror-state'); +var prosemirrorTransform = require('prosemirror-transform'); +var InputRule = _createClass(function InputRule(match, handler) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + _classCallCheck(this, InputRule); + this.match = match; + this.match = match; + this.handler = typeof handler == "string" ? stringHandler(handler) : handler; + this.undoable = options.undoable !== false; + this.inCode = options.inCode || false; +}); +function stringHandler(string) { + return function (state, match, start, end) { + var insert = string; + if (match[1]) { + var offset = match[0].lastIndexOf(match[1]); + insert += match[0].slice(offset + match[1].length); + start += offset; + var cutOff = start - end; + if (cutOff > 0) { + insert = match[0].slice(offset - cutOff, offset) + insert; + start = end; + } + } + return state.tr.insertText(insert, start, end); + }; +} +var MAX_MATCH = 500; +function inputRules(_ref) { + var rules = _ref.rules; + var plugin = new prosemirrorState.Plugin({ + state: { + init: function init() { + return null; + }, + apply: function apply(tr, prev) { + var stored = tr.getMeta(this); + if (stored) return stored; + return tr.selectionSet || tr.docChanged ? null : prev; + } + }, + props: { + handleTextInput: function handleTextInput(view, from, to, text) { + return run(view, from, to, text, rules, plugin); + }, + handleDOMEvents: { + compositionend: function compositionend(view) { + setTimeout(function () { + var $cursor = view.state.selection.$cursor; + if ($cursor) run(view, $cursor.pos, $cursor.pos, "", rules, plugin); + }); + } + } + }, + isInputRules: true + }); + return plugin; +} +function run(view, from, to, text, rules, plugin) { + if (view.composing) return false; + var state = view.state, + $from = state.doc.resolve(from); + var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, "\uFFFC") + text; + for (var i = 0; i < rules.length; i++) { + var rule = rules[i]; + if ($from.parent.type.spec.code) { + if (!rule.inCode) continue; + } else if (rule.inCode === "only") { + continue; + } + var match = rule.match.exec(textBefore); + var tr = match && rule.handler(state, match, from - (match[0].length - text.length), to); + if (!tr) continue; + if (rule.undoable) tr.setMeta(plugin, { + transform: tr, + from: from, + to: to, + text: text + }); + view.dispatch(tr); + return true; + } + return false; +} +var undoInputRule = function undoInputRule(state, dispatch) { + var plugins = state.plugins; + for (var i = 0; i < plugins.length; i++) { + var plugin = plugins[i], + undoable = void 0; + if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) { + if (dispatch) { + var tr = state.tr, + toUndo = undoable.transform; + for (var j = toUndo.steps.length - 1; j >= 0; j--) tr.step(toUndo.steps[j].invert(toUndo.docs[j])); + if (undoable.text) { + var marks = tr.doc.resolve(undoable.from).marks(); + tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks)); + } else { + tr["delete"](undoable.from, undoable.to); + } + dispatch(tr); + } + return true; + } + } + return false; +}; +var emDash = new InputRule(/--$/, "—"); +var ellipsis = new InputRule(/\.\.\.$/, "…"); +var openDoubleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/, "“"); +var closeDoubleQuote = new InputRule(/"$/, "”"); +var openSingleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/, "‘"); +var closeSingleQuote = new InputRule(/'$/, "’"); +var smartQuotes = [openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote]; +function wrappingInputRule(regexp, nodeType) { + var getAttrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var joinPredicate = arguments.length > 3 ? arguments[3] : undefined; + return new InputRule(regexp, function (state, match, start, end) { + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + var tr = state.tr["delete"](start, end); + var $start = tr.doc.resolve(start), + range = $start.blockRange(), + wrapping = range && prosemirrorTransform.findWrapping(range, nodeType, attrs); + if (!wrapping) return null; + tr.wrap(range, wrapping); + var before = tr.doc.resolve(start - 1).nodeBefore; + if (before && before.type == nodeType && prosemirrorTransform.canJoin(tr.doc, start - 1) && (!joinPredicate || joinPredicate(match, before))) tr.join(start - 1); + return tr; + }); +} +function textblockTypeInputRule(regexp, nodeType) { + var getAttrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + return new InputRule(regexp, function (state, match, start, end) { + var $start = state.doc.resolve(start); + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) return null; + return state.tr["delete"](start, end).setBlockType(start, start, nodeType, attrs); + }); +} +exports.InputRule = InputRule; +exports.closeDoubleQuote = closeDoubleQuote; +exports.closeSingleQuote = closeSingleQuote; +exports.ellipsis = ellipsis; +exports.emDash = emDash; +exports.inputRules = inputRules; +exports.openDoubleQuote = openDoubleQuote; +exports.openSingleQuote = openSingleQuote; +exports.smartQuotes = smartQuotes; +exports.textblockTypeInputRule = textblockTypeInputRule; +exports.undoInputRule = undoInputRule; +exports.wrappingInputRule = wrappingInputRule; + +}); +define("prosemirror-keymap",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var w3cKeyname = require('w3c-keyname'); + +var prosemirrorState = require('prosemirror-state'); + +var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false; + +function normalizeKeyName(name) { + var parts = name.split(/-(?!$)/), + result = parts[parts.length - 1]; + if (result == "Space") result = " "; + var alt, ctrl, shift, meta; + + for (var i = 0; i < parts.length - 1; i++) { + var mod = parts[i]; + if (/^(cmd|meta|m)$/i.test(mod)) meta = true;else if (/^a(lt)?$/i.test(mod)) alt = true;else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;else if (/^s(hift)?$/i.test(mod)) shift = true;else if (/^mod$/i.test(mod)) { + if (mac) meta = true;else ctrl = true; + } else throw new Error("Unrecognized modifier name: " + mod); + } + + if (alt) result = "Alt-" + result; + if (ctrl) result = "Ctrl-" + result; + if (meta) result = "Meta-" + result; + if (shift) result = "Shift-" + result; + return result; +} + +function normalize(map) { + var copy = Object.create(null); + + for (var prop in map) { + copy[normalizeKeyName(prop)] = map[prop]; + } + + return copy; +} + +function modifiers(name, event) { + var shift = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + if (event.altKey) name = "Alt-" + name; + if (event.ctrlKey) name = "Ctrl-" + name; + if (event.metaKey) name = "Meta-" + name; + if (shift && event.shiftKey) name = "Shift-" + name; + return name; +} + +function keymap(bindings) { + return new prosemirrorState.Plugin({ + props: { + handleKeyDown: keydownHandler(bindings) + } + }); +} + +function keydownHandler(bindings) { + var map = normalize(bindings); + return function (view, event) { + var name = w3cKeyname.keyName(event), + baseName, + direct = map[modifiers(name, event)]; + if (direct && direct(view.state, view.dispatch, view)) return true; + + if (name.length == 1 && name != " ") { + if (event.shiftKey) { + var noShift = map[modifiers(name, event, false)]; + if (noShift && noShift(view.state, view.dispatch, view)) return true; + } + + if ((event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && (baseName = w3cKeyname.base[event.keyCode]) && baseName != name) { + var fromCode = map[modifiers(baseName, event)]; + if (fromCode && fromCode(view.state, view.dispatch, view)) return true; + } + } + + return false; + }; +} + +exports.keydownHandler = keydownHandler; +exports.keymap = keymap; + +}); +define("prosemirror-markdown",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorModel = require('prosemirror-model'); +var MarkdownIt = require('markdown-it'); +var schema = new prosemirrorModel.Schema({ + nodes: { + doc: { + content: "block+" + }, + paragraph: { + content: "inline*", + group: "block", + parseDOM: [{ + tag: "p" + }], + toDOM: function toDOM() { + return ["p", 0]; + } + }, + blockquote: { + content: "block+", + group: "block", + parseDOM: [{ + tag: "blockquote" + }], + toDOM: function toDOM() { + return ["blockquote", 0]; + } + }, + horizontal_rule: { + group: "block", + parseDOM: [{ + tag: "hr" + }], + toDOM: function toDOM() { + return ["div", ["hr"]]; + } + }, + heading: { + attrs: { + level: { + "default": 1 + } + }, + content: "(text | image)*", + group: "block", + defining: true, + parseDOM: [{ + tag: "h1", + attrs: { + level: 1 + } + }, { + tag: "h2", + attrs: { + level: 2 + } + }, { + tag: "h3", + attrs: { + level: 3 + } + }, { + tag: "h4", + attrs: { + level: 4 + } + }, { + tag: "h5", + attrs: { + level: 5 + } + }, { + tag: "h6", + attrs: { + level: 6 + } + }], + toDOM: function toDOM(node) { + return ["h" + node.attrs.level, 0]; + } + }, + code_block: { + content: "text*", + group: "block", + code: true, + defining: true, + marks: "", + attrs: { + params: { + "default": "" + } + }, + parseDOM: [{ + tag: "pre", + preserveWhitespace: "full", + getAttrs: function getAttrs(node) { + return { + params: node.getAttribute("data-params") || "" + }; + } + }], + toDOM: function toDOM(node) { + return ["pre", node.attrs.params ? { + "data-params": node.attrs.params + } : {}, ["code", 0]]; + } + }, + ordered_list: { + content: "list_item+", + group: "block", + attrs: { + order: { + "default": 1 + }, + tight: { + "default": false + } + }, + parseDOM: [{ + tag: "ol", + getAttrs: function getAttrs(dom) { + return { + order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1, + tight: dom.hasAttribute("data-tight") + }; + } + }], + toDOM: function toDOM(node) { + return ["ol", { + start: node.attrs.order == 1 ? null : node.attrs.order, + "data-tight": node.attrs.tight ? "true" : null + }, 0]; + } + }, + bullet_list: { + content: "list_item+", + group: "block", + attrs: { + tight: { + "default": false + } + }, + parseDOM: [{ + tag: "ul", + getAttrs: function getAttrs(dom) { + return { + tight: dom.hasAttribute("data-tight") + }; + } + }], + toDOM: function toDOM(node) { + return ["ul", { + "data-tight": node.attrs.tight ? "true" : null + }, 0]; + } + }, + list_item: { + content: "block+", + defining: true, + parseDOM: [{ + tag: "li" + }], + toDOM: function toDOM() { + return ["li", 0]; + } + }, + text: { + group: "inline" + }, + image: { + inline: true, + attrs: { + src: {}, + alt: { + "default": null + }, + title: { + "default": null + } + }, + group: "inline", + draggable: true, + parseDOM: [{ + tag: "img[src]", + getAttrs: function getAttrs(dom) { + return { + src: dom.getAttribute("src"), + title: dom.getAttribute("title"), + alt: dom.getAttribute("alt") + }; + } + }], + toDOM: function toDOM(node) { + return ["img", node.attrs]; + } + }, + hard_break: { + inline: true, + group: "inline", + selectable: false, + parseDOM: [{ + tag: "br" + }], + toDOM: function toDOM() { + return ["br"]; + } + } + }, + marks: { + em: { + parseDOM: [{ + tag: "i" + }, { + tag: "em" + }, { + style: "font-style=italic" + }, { + style: "font-style=normal", + clearMark: function clearMark(m) { + return m.type.name == "em"; + } + }], + toDOM: function toDOM() { + return ["em"]; + } + }, + strong: { + parseDOM: [{ + tag: "strong" + }, { + tag: "b", + getAttrs: function getAttrs(node) { + return node.style.fontWeight != "normal" && null; + } + }, { + style: "font-weight=400", + clearMark: function clearMark(m) { + return m.type.name == "strong"; + } + }, { + style: "font-weight", + getAttrs: function getAttrs(value) { + return /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null; + } + }], + toDOM: function toDOM() { + return ["strong"]; + } + }, + link: { + attrs: { + href: {}, + title: { + "default": null + } + }, + inclusive: false, + parseDOM: [{ + tag: "a[href]", + getAttrs: function getAttrs(dom) { + return { + href: dom.getAttribute("href"), + title: dom.getAttribute("title") + }; + } + }], + toDOM: function toDOM(node) { + return ["a", node.attrs]; + } + }, + code: { + parseDOM: [{ + tag: "code" + }], + toDOM: function toDOM() { + return ["code"]; + } + } + } +}); +function maybeMerge(a, b) { + if (a.isText && b.isText && prosemirrorModel.Mark.sameSet(a.marks, b.marks)) return a.withText(a.text + b.text); +} +var MarkdownParseState = function () { + function MarkdownParseState(schema, tokenHandlers) { + _classCallCheck(this, MarkdownParseState); + this.schema = schema; + this.tokenHandlers = tokenHandlers; + this.stack = [{ + type: schema.topNodeType, + attrs: null, + content: [], + marks: prosemirrorModel.Mark.none + }]; + } + _createClass(MarkdownParseState, [{ + key: "top", + value: function top() { + return this.stack[this.stack.length - 1]; + } + }, { + key: "push", + value: function push(elt) { + if (this.stack.length) this.top().content.push(elt); + } + }, { + key: "addText", + value: function addText(text) { + if (!text) return; + var top = this.top(), + nodes = top.content, + last = nodes[nodes.length - 1]; + var node = this.schema.text(text, top.marks), + merged; + if (last && (merged = maybeMerge(last, node))) nodes[nodes.length - 1] = merged;else nodes.push(node); + } + }, { + key: "openMark", + value: function openMark(mark) { + var top = this.top(); + top.marks = mark.addToSet(top.marks); + } + }, { + key: "closeMark", + value: function closeMark(mark) { + var top = this.top(); + top.marks = mark.removeFromSet(top.marks); + } + }, { + key: "parseTokens", + value: function parseTokens(toks) { + for (var i = 0; i < toks.length; i++) { + var tok = toks[i]; + var handler = this.tokenHandlers[tok.type]; + if (!handler) throw new Error("Token type `" + tok.type + "` not supported by Markdown parser"); + handler(this, tok, toks, i); + } + } + }, { + key: "addNode", + value: function addNode(type, attrs, content) { + var top = this.top(); + var node = type.createAndFill(attrs, content, top ? top.marks : []); + if (!node) return null; + this.push(node); + return node; + } + }, { + key: "openNode", + value: function openNode(type, attrs) { + this.stack.push({ + type: type, + attrs: attrs, + content: [], + marks: prosemirrorModel.Mark.none + }); + } + }, { + key: "closeNode", + value: function closeNode() { + var info = this.stack.pop(); + return this.addNode(info.type, info.attrs, info.content); + } + }]); + return MarkdownParseState; +}(); +function attrs(spec, token, tokens, i) { + if (spec.getAttrs) return spec.getAttrs(token, tokens, i);else if (spec.attrs instanceof Function) return spec.attrs(token);else return spec.attrs; +} +function noCloseToken(spec, type) { + return spec.noCloseToken || type == "code_inline" || type == "code_block" || type == "fence"; +} +function withoutTrailingNewline(str) { + return str[str.length - 1] == "\n" ? str.slice(0, str.length - 1) : str; +} +function noOp() {} +function tokenHandlers(schema, tokens) { + var handlers = Object.create(null); + var _loop = function _loop() { + var spec = tokens[type]; + if (spec.block) { + var nodeType = schema.nodeType(spec.block); + if (noCloseToken(spec, type)) { + handlers[type] = function (state, tok, tokens, i) { + state.openNode(nodeType, attrs(spec, tok, tokens, i)); + state.addText(withoutTrailingNewline(tok.content)); + state.closeNode(); + }; + } else { + handlers[type + "_open"] = function (state, tok, tokens, i) { + return state.openNode(nodeType, attrs(spec, tok, tokens, i)); + }; + handlers[type + "_close"] = function (state) { + return state.closeNode(); + }; + } + } else if (spec.node) { + var _nodeType = schema.nodeType(spec.node); + handlers[type] = function (state, tok, tokens, i) { + return state.addNode(_nodeType, attrs(spec, tok, tokens, i)); + }; + } else if (spec.mark) { + var markType = schema.marks[spec.mark]; + if (noCloseToken(spec, type)) { + handlers[type] = function (state, tok, tokens, i) { + state.openMark(markType.create(attrs(spec, tok, tokens, i))); + state.addText(withoutTrailingNewline(tok.content)); + state.closeMark(markType); + }; + } else { + handlers[type + "_open"] = function (state, tok, tokens, i) { + return state.openMark(markType.create(attrs(spec, tok, tokens, i))); + }; + handlers[type + "_close"] = function (state) { + return state.closeMark(markType); + }; + } + } else if (spec.ignore) { + if (noCloseToken(spec, type)) { + handlers[type] = noOp; + } else { + handlers[type + "_open"] = noOp; + handlers[type + "_close"] = noOp; + } + } else { + throw new RangeError("Unrecognized parsing spec " + JSON.stringify(spec)); + } + }; + for (var type in tokens) { + _loop(); + } + handlers.text = function (state, tok) { + return state.addText(tok.content); + }; + handlers.inline = function (state, tok) { + return state.parseTokens(tok.children); + }; + handlers.softbreak = handlers.softbreak || function (state) { + return state.addText(" "); + }; + return handlers; +} +var MarkdownParser = function () { + function MarkdownParser(schema, tokenizer, tokens) { + _classCallCheck(this, MarkdownParser); + this.schema = schema; + this.tokenizer = tokenizer; + this.tokens = tokens; + this.tokenHandlers = tokenHandlers(schema, tokens); + } + _createClass(MarkdownParser, [{ + key: "parse", + value: function parse(text) { + var markdownEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var state = new MarkdownParseState(this.schema, this.tokenHandlers), + doc; + state.parseTokens(this.tokenizer.parse(text, markdownEnv)); + do { + doc = state.closeNode(); + } while (state.stack.length); + return doc || this.schema.topNodeType.createAndFill(); + } + }]); + return MarkdownParser; +}(); +function listIsTight(tokens, i) { + while (++i < tokens.length) if (tokens[i].type != "list_item_open") return tokens[i].hidden; + return false; +} +var defaultMarkdownParser = new MarkdownParser(schema, MarkdownIt("commonmark", { + html: false +}), { + blockquote: { + block: "blockquote" + }, + paragraph: { + block: "paragraph" + }, + list_item: { + block: "list_item" + }, + bullet_list: { + block: "bullet_list", + getAttrs: function getAttrs(_, tokens, i) { + return { + tight: listIsTight(tokens, i) + }; + } + }, + ordered_list: { + block: "ordered_list", + getAttrs: function getAttrs(tok, tokens, i) { + return { + order: +tok.attrGet("start") || 1, + tight: listIsTight(tokens, i) + }; + } + }, + heading: { + block: "heading", + getAttrs: function getAttrs(tok) { + return { + level: +tok.tag.slice(1) + }; + } + }, + code_block: { + block: "code_block", + noCloseToken: true + }, + fence: { + block: "code_block", + getAttrs: function getAttrs(tok) { + return { + params: tok.info || "" + }; + }, + noCloseToken: true + }, + hr: { + node: "horizontal_rule" + }, + image: { + node: "image", + getAttrs: function getAttrs(tok) { + return { + src: tok.attrGet("src"), + title: tok.attrGet("title") || null, + alt: tok.children[0] && tok.children[0].content || null + }; + } + }, + hardbreak: { + node: "hard_break" + }, + em: { + mark: "em" + }, + strong: { + mark: "strong" + }, + link: { + mark: "link", + getAttrs: function getAttrs(tok) { + return { + href: tok.attrGet("href"), + title: tok.attrGet("title") || null + }; + } + }, + code_inline: { + mark: "code", + noCloseToken: true + } +}); +var blankMark = { + open: "", + close: "", + mixable: true +}; +var MarkdownSerializer = function () { + function MarkdownSerializer(nodes, marks) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + _classCallCheck(this, MarkdownSerializer); + this.nodes = nodes; + this.marks = marks; + this.options = options; + } + _createClass(MarkdownSerializer, [{ + key: "serialize", + value: function serialize(content) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + options = Object.assign({}, this.options, options); + var state = new MarkdownSerializerState(this.nodes, this.marks, options); + state.renderContent(content); + return state.out; + } + }]); + return MarkdownSerializer; +}(); +var defaultMarkdownSerializer = new MarkdownSerializer({ + blockquote: function blockquote(state, node) { + state.wrapBlock("> ", null, node, function () { + return state.renderContent(node); + }); + }, + code_block: function code_block(state, node) { + var backticks = node.textContent.match(/`{3,}/gm); + var fence = backticks ? backticks.sort().slice(-1)[0] + "`" : "```"; + state.write(fence + (node.attrs.params || "") + "\n"); + state.text(node.textContent, false); + state.write("\n"); + state.write(fence); + state.closeBlock(node); + }, + heading: function heading(state, node) { + state.write(state.repeat("#", node.attrs.level) + " "); + state.renderInline(node, false); + state.closeBlock(node); + }, + horizontal_rule: function horizontal_rule(state, node) { + state.write(node.attrs.markup || "---"); + state.closeBlock(node); + }, + bullet_list: function bullet_list(state, node) { + state.renderList(node, " ", function () { + return (node.attrs.bullet || "*") + " "; + }); + }, + ordered_list: function ordered_list(state, node) { + var start = node.attrs.order || 1; + var maxW = String(start + node.childCount - 1).length; + var space = state.repeat(" ", maxW + 2); + state.renderList(node, space, function (i) { + var nStr = String(start + i); + return state.repeat(" ", maxW - nStr.length) + nStr + ". "; + }); + }, + list_item: function list_item(state, node) { + state.renderContent(node); + }, + paragraph: function paragraph(state, node) { + state.renderInline(node); + state.closeBlock(node); + }, + image: function image(state, node) { + state.write("![" + state.esc(node.attrs.alt || "") + "](" + node.attrs.src.replace(/[\(\)]/g, "\\$&") + (node.attrs.title ? ' "' + node.attrs.title.replace(/"/g, '\\"') + '"' : "") + ")"); + }, + hard_break: function hard_break(state, node, parent, index) { + for (var i = index + 1; i < parent.childCount; i++) if (parent.child(i).type != node.type) { + state.write("\\\n"); + return; + } + }, + text: function text(state, node) { + state.text(node.text, !state.inAutolink); + } +}, { + em: { + open: "*", + close: "*", + mixable: true, + expelEnclosingWhitespace: true + }, + strong: { + open: "**", + close: "**", + mixable: true, + expelEnclosingWhitespace: true + }, + link: { + open: function open(state, mark, parent, index) { + state.inAutolink = isPlainURL(mark, parent, index); + return state.inAutolink ? "<" : "["; + }, + close: function close(state, mark, parent, index) { + var inAutolink = state.inAutolink; + state.inAutolink = undefined; + return inAutolink ? ">" : "](" + mark.attrs.href.replace(/[\(\)"]/g, "\\$&") + (mark.attrs.title ? " \"".concat(mark.attrs.title.replace(/"/g, '\\"'), "\"") : "") + ")"; + }, + mixable: true + }, + code: { + open: function open(_state, _mark, parent, index) { + return backticksFor(parent.child(index), -1); + }, + close: function close(_state, _mark, parent, index) { + return backticksFor(parent.child(index - 1), 1); + }, + escape: false + } +}); +function backticksFor(node, side) { + var ticks = /`+/g, + m, + len = 0; + if (node.isText) while (m = ticks.exec(node.text)) len = Math.max(len, m[0].length); + var result = len > 0 && side > 0 ? " `" : "`"; + for (var i = 0; i < len; i++) result += "`"; + if (len > 0 && side < 0) result += " "; + return result; +} +function isPlainURL(link, parent, index) { + if (link.attrs.title || !/^\w+:/.test(link.attrs.href)) return false; + var content = parent.child(index); + if (!content.isText || content.text != link.attrs.href || content.marks[content.marks.length - 1] != link) return false; + return index == parent.childCount - 1 || !link.isInSet(parent.child(index + 1).marks); +} +var MarkdownSerializerState = function () { + function MarkdownSerializerState(nodes, marks, options) { + _classCallCheck(this, MarkdownSerializerState); + this.nodes = nodes; + this.marks = marks; + this.options = options; + this.delim = ""; + this.out = ""; + this.closed = null; + this.inAutolink = undefined; + this.atBlockStart = false; + this.inTightList = false; + if (typeof this.options.tightLists == "undefined") this.options.tightLists = false; + if (typeof this.options.hardBreakNodeName == "undefined") this.options.hardBreakNodeName = "hard_break"; + } + _createClass(MarkdownSerializerState, [{ + key: "flushClose", + value: function flushClose() { + var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; + if (this.closed) { + if (!this.atBlank()) this.out += "\n"; + if (size > 1) { + var delimMin = this.delim; + var trim = /\s+$/.exec(delimMin); + if (trim) delimMin = delimMin.slice(0, delimMin.length - trim[0].length); + for (var i = 1; i < size; i++) this.out += delimMin + "\n"; + } + this.closed = null; + } + } + }, { + key: "getMark", + value: function getMark(name) { + var info = this.marks[name]; + if (!info) { + if (this.options.strict !== false) throw new Error("Mark type `".concat(name, "` not supported by Markdown renderer")); + info = blankMark; + } + return info; + } + }, { + key: "wrapBlock", + value: function wrapBlock(delim, firstDelim, node, f) { + var old = this.delim; + this.write(firstDelim != null ? firstDelim : delim); + this.delim += delim; + f(); + this.delim = old; + this.closeBlock(node); + } + }, { + key: "atBlank", + value: function atBlank() { + return /(^|\n)$/.test(this.out); + } + }, { + key: "ensureNewLine", + value: function ensureNewLine() { + if (!this.atBlank()) this.out += "\n"; + } + }, { + key: "write", + value: function write(content) { + this.flushClose(); + if (this.delim && this.atBlank()) this.out += this.delim; + if (content) this.out += content; + } + }, { + key: "closeBlock", + value: function closeBlock(node) { + this.closed = node; + } + }, { + key: "text", + value: function text(_text) { + var escape = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var lines = _text.split("\n"); + for (var i = 0; i < lines.length; i++) { + this.write(); + if (!escape && lines[i][0] == "[" && /(^|[^\\])\!$/.test(this.out)) this.out = this.out.slice(0, this.out.length - 1) + "\\!"; + this.out += escape ? this.esc(lines[i], this.atBlockStart) : lines[i]; + if (i != lines.length - 1) this.out += "\n"; + } + } + }, { + key: "render", + value: function render(node, parent, index) { + if (this.nodes[node.type.name]) { + this.nodes[node.type.name](this, node, parent, index); + } else { + if (this.options.strict !== false) { + throw new Error("Token type `" + node.type.name + "` not supported by Markdown renderer"); + } else if (!node.type.isLeaf) { + if (node.type.inlineContent) this.renderInline(node);else this.renderContent(node); + if (node.isBlock) this.closeBlock(node); + } + } + } + }, { + key: "renderContent", + value: function renderContent(parent) { + var _this = this; + parent.forEach(function (node, _, i) { + return _this.render(node, parent, i); + }); + } + }, { + key: "renderInline", + value: function renderInline(parent) { + var _this2 = this; + var fromBlockStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + this.atBlockStart = fromBlockStart; + var active = [], + trailing = ""; + var progress = function progress(node, offset, index) { + var marks = node ? node.marks : []; + if (node && node.type.name === _this2.options.hardBreakNodeName) marks = marks.filter(function (m) { + if (index + 1 == parent.childCount) return false; + var next = parent.child(index + 1); + return m.isInSet(next.marks) && (!next.isText || /\S/.test(next.text)); + }); + var leading = trailing; + trailing = ""; + if (node && node.isText && marks.some(function (mark) { + var info = _this2.getMark(mark.type.name); + return info && info.expelEnclosingWhitespace && !mark.isInSet(active); + })) { + var _exec = /^(\s*)(.*)$/m.exec(node.text), + _exec2 = _slicedToArray(_exec, 3), + _ = _exec2[0], + lead = _exec2[1], + rest = _exec2[2]; + if (lead) { + leading += lead; + node = rest ? node.withText(rest) : null; + if (!node) marks = active; + } + } + if (node && node.isText && marks.some(function (mark) { + var info = _this2.getMark(mark.type.name); + return info && info.expelEnclosingWhitespace && (index == parent.childCount - 1 || !mark.isInSet(parent.child(index + 1).marks)); + })) { + var _exec3 = /^(.*?)(\s*)$/m.exec(node.text), + _exec4 = _slicedToArray(_exec3, 3), + _2 = _exec4[0], + _rest = _exec4[1], + trail = _exec4[2]; + if (trail) { + trailing = trail; + node = _rest ? node.withText(_rest) : null; + if (!node) marks = active; + } + } + var inner = marks.length ? marks[marks.length - 1] : null; + var noEsc = inner && _this2.getMark(inner.type.name).escape === false; + var len = marks.length - (noEsc ? 1 : 0); + outer: for (var i = 0; i < len; i++) { + var mark = marks[i]; + if (!_this2.getMark(mark.type.name).mixable) break; + for (var j = 0; j < active.length; j++) { + var other = active[j]; + if (!_this2.getMark(other.type.name).mixable) break; + if (mark.eq(other)) { + if (i > j) marks = marks.slice(0, j).concat(mark).concat(marks.slice(j, i)).concat(marks.slice(i + 1, len));else if (j > i) marks = marks.slice(0, i).concat(marks.slice(i + 1, j)).concat(mark).concat(marks.slice(j, len)); + continue outer; + } + } + } + var keep = 0; + while (keep < Math.min(active.length, len) && marks[keep].eq(active[keep])) ++keep; + while (keep < active.length) _this2.text(_this2.markString(active.pop(), false, parent, index), false); + if (leading) _this2.text(leading); + if (node) { + while (active.length < len) { + var add = marks[active.length]; + active.push(add); + _this2.text(_this2.markString(add, true, parent, index), false); + _this2.atBlockStart = false; + } + if (noEsc && node.isText) _this2.text(_this2.markString(inner, true, parent, index) + node.text + _this2.markString(inner, false, parent, index + 1), false);else _this2.render(node, parent, index); + _this2.atBlockStart = false; + } + if ((node === null || node === void 0 ? void 0 : node.isText) && node.nodeSize > 0) { + _this2.atBlockStart = false; + } + }; + parent.forEach(progress); + progress(null, 0, parent.childCount); + this.atBlockStart = false; + } + }, { + key: "renderList", + value: function renderList(node, delim, firstDelim) { + var _this3 = this; + if (this.closed && this.closed.type == node.type) this.flushClose(3);else if (this.inTightList) this.flushClose(1); + var isTight = typeof node.attrs.tight != "undefined" ? node.attrs.tight : this.options.tightLists; + var prevTight = this.inTightList; + this.inTightList = isTight; + node.forEach(function (child, _, i) { + if (i && isTight) _this3.flushClose(1); + _this3.wrapBlock(delim, firstDelim(i), node, function () { + return _this3.render(child, node, i); + }); + }); + this.inTightList = prevTight; + } + }, { + key: "esc", + value: function esc(str) { + var startOfLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + str = str.replace(/[`*\\~\[\]_]/g, function (m, i) { + return m == "_" && i > 0 && i + 1 < str.length && str[i - 1].match(/\w/) && str[i + 1].match(/\w/) ? m : "\\" + m; + }); + if (startOfLine) str = str.replace(/^(\+[ ]|[\-*>])/, "\\$&").replace(/^(\s*)(#{1,6})(\s|$)/, '$1\\$2$3').replace(/^(\s*\d+)\.\s/, "$1\\. "); + if (this.options.escapeExtraCharacters) str = str.replace(this.options.escapeExtraCharacters, "\\$&"); + return str; + } + }, { + key: "quote", + value: function quote(str) { + var wrap = str.indexOf('"') == -1 ? '""' : str.indexOf("'") == -1 ? "''" : "()"; + return wrap[0] + str + wrap[1]; + } + }, { + key: "repeat", + value: function repeat(str, n) { + var out = ""; + for (var i = 0; i < n; i++) out += str; + return out; + } + }, { + key: "markString", + value: function markString(mark, open, parent, index) { + var info = this.getMark(mark.type.name); + var value = open ? info.open : info.close; + return typeof value == "string" ? value : value(this, mark, parent, index); + } + }, { + key: "getEnclosingWhitespace", + value: function getEnclosingWhitespace(text) { + return { + leading: (text.match(/^(\s+)/) || [undefined])[0], + trailing: (text.match(/(\s+)$/) || [undefined])[0] + }; + } + }]); + return MarkdownSerializerState; +}(); +exports.MarkdownParser = MarkdownParser; +exports.MarkdownSerializer = MarkdownSerializer; +exports.MarkdownSerializerState = MarkdownSerializerState; +exports.defaultMarkdownParser = defaultMarkdownParser; +exports.defaultMarkdownSerializer = defaultMarkdownSerializer; +exports.schema = schema; + +}); +define("prosemirror-model",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var OrderedMap = require('orderedmap'); +function _findDiffStart(a, b, pos) { + for (var i = 0;; i++) { + if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos; + var childA = a.child(i), + childB = b.child(i); + if (childA == childB) { + pos += childA.nodeSize; + continue; + } + if (!childA.sameMarkup(childB)) return pos; + if (childA.isText && childA.text != childB.text) { + for (var j = 0; childA.text[j] == childB.text[j]; j++) pos++; + return pos; + } + if (childA.content.size || childB.content.size) { + var inner = _findDiffStart(childA.content, childB.content, pos + 1); + if (inner != null) return inner; + } + pos += childA.nodeSize; + } +} +function _findDiffEnd(a, b, posA, posB) { + for (var iA = a.childCount, iB = b.childCount;;) { + if (iA == 0 || iB == 0) return iA == iB ? null : { + a: posA, + b: posB + }; + var childA = a.child(--iA), + childB = b.child(--iB), + size = childA.nodeSize; + if (childA == childB) { + posA -= size; + posB -= size; + continue; + } + if (!childA.sameMarkup(childB)) return { + a: posA, + b: posB + }; + if (childA.isText && childA.text != childB.text) { + var same = 0, + minSize = Math.min(childA.text.length, childB.text.length); + while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) { + same++; + posA--; + posB--; + } + return { + a: posA, + b: posB + }; + } + if (childA.content.size || childB.content.size) { + var inner = _findDiffEnd(childA.content, childB.content, posA - 1, posB - 1); + if (inner) return inner; + } + posA -= size; + posB -= size; + } +} +var Fragment = function () { + function Fragment(content, size) { + _classCallCheck(this, Fragment); + this.content = content; + this.size = size || 0; + if (size == null) for (var i = 0; i < content.length; i++) this.size += content[i].nodeSize; + } + _createClass(Fragment, [{ + key: "nodesBetween", + value: function nodesBetween(from, to, f) { + var nodeStart = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + var parent = arguments.length > 4 ? arguments[4] : undefined; + for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], + end = pos + child.nodeSize; + if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) { + var start = pos + 1; + child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start); + } + pos = end; + } + } + }, { + key: "descendants", + value: function descendants(f) { + this.nodesBetween(0, this.size, f); + } + }, { + key: "textBetween", + value: function textBetween(from, to, blockSeparator, leafText) { + var text = "", + first = true; + this.nodesBetween(from, to, function (node, pos) { + var nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : ""; + if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) { + if (first) first = false;else text += blockSeparator; + } + text += nodeText; + }, 0); + return text; + } + }, { + key: "append", + value: function append(other) { + if (!other.size) return this; + if (!this.size) return other; + var last = this.lastChild, + first = other.firstChild, + content = this.content.slice(), + i = 0; + if (last.isText && last.sameMarkup(first)) { + content[content.length - 1] = last.withText(last.text + first.text); + i = 1; + } + for (; i < other.content.length; i++) content.push(other.content[i]); + return new Fragment(content, this.size + other.size); + } + }, { + key: "cut", + value: function cut(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size; + if (from == 0 && to == this.size) return this; + var result = [], + size = 0; + if (to > from) for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], + end = pos + child.nodeSize; + if (end > from) { + if (pos < from || end > to) { + if (child.isText) child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));else child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1)); + } + result.push(child); + size += child.nodeSize; + } + pos = end; + } + return new Fragment(result, size); + } + }, { + key: "cutByIndex", + value: function cutByIndex(from, to) { + if (from == to) return Fragment.empty; + if (from == 0 && to == this.content.length) return this; + return new Fragment(this.content.slice(from, to)); + } + }, { + key: "replaceChild", + value: function replaceChild(index, node) { + var current = this.content[index]; + if (current == node) return this; + var copy = this.content.slice(); + var size = this.size + node.nodeSize - current.nodeSize; + copy[index] = node; + return new Fragment(copy, size); + } + }, { + key: "addToStart", + value: function addToStart(node) { + return new Fragment([node].concat(this.content), this.size + node.nodeSize); + } + }, { + key: "addToEnd", + value: function addToEnd(node) { + return new Fragment(this.content.concat(node), this.size + node.nodeSize); + } + }, { + key: "eq", + value: function eq(other) { + if (this.content.length != other.content.length) return false; + for (var i = 0; i < this.content.length; i++) if (!this.content[i].eq(other.content[i])) return false; + return true; + } + }, { + key: "firstChild", + get: function get() { + return this.content.length ? this.content[0] : null; + } + }, { + key: "lastChild", + get: function get() { + return this.content.length ? this.content[this.content.length - 1] : null; + } + }, { + key: "childCount", + get: function get() { + return this.content.length; + } + }, { + key: "child", + value: function child(index) { + var found = this.content[index]; + if (!found) throw new RangeError("Index " + index + " out of range for " + this); + return found; + } + }, { + key: "maybeChild", + value: function maybeChild(index) { + return this.content[index] || null; + } + }, { + key: "forEach", + value: function forEach(f) { + for (var i = 0, p = 0; i < this.content.length; i++) { + var child = this.content[i]; + f(child, p, i); + p += child.nodeSize; + } + } + }, { + key: "findDiffStart", + value: function findDiffStart(other) { + var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return _findDiffStart(this, other, pos); + } + }, { + key: "findDiffEnd", + value: function findDiffEnd(other) { + var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.size; + var otherPos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : other.size; + return _findDiffEnd(this, other, pos, otherPos); + } + }, { + key: "findIndex", + value: function findIndex(pos) { + var round = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; + if (pos == 0) return retIndex(0, pos); + if (pos == this.size) return retIndex(this.content.length, pos); + if (pos > this.size || pos < 0) throw new RangeError("Position ".concat(pos, " outside of fragment (").concat(this, ")")); + for (var i = 0, curPos = 0;; i++) { + var cur = this.child(i), + end = curPos + cur.nodeSize; + if (end >= pos) { + if (end == pos || round > 0) return retIndex(i + 1, end); + return retIndex(i, curPos); + } + curPos = end; + } + } + }, { + key: "toString", + value: function toString() { + return "<" + this.toStringInner() + ">"; + } + }, { + key: "toStringInner", + value: function toStringInner() { + return this.content.join(", "); + } + }, { + key: "toJSON", + value: function toJSON() { + return this.content.length ? this.content.map(function (n) { + return n.toJSON(); + }) : null; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, value) { + if (!value) return Fragment.empty; + if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON"); + return new Fragment(value.map(schema.nodeFromJSON)); + } + }, { + key: "fromArray", + value: function fromArray(array) { + if (!array.length) return Fragment.empty; + var joined, + size = 0; + for (var i = 0; i < array.length; i++) { + var node = array[i]; + size += node.nodeSize; + if (i && node.isText && array[i - 1].sameMarkup(node)) { + if (!joined) joined = array.slice(0, i); + joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text); + } else if (joined) { + joined.push(node); + } + } + return new Fragment(joined || array, size); + } + }, { + key: "from", + value: function from(nodes) { + if (!nodes) return Fragment.empty; + if (nodes instanceof Fragment) return nodes; + if (Array.isArray(nodes)) return this.fromArray(nodes); + if (nodes.attrs) return new Fragment([nodes], nodes.nodeSize); + throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")); + } + }]); + return Fragment; +}(); +Fragment.empty = new Fragment([], 0); +var found = { + index: 0, + offset: 0 +}; +function retIndex(index, offset) { + found.index = index; + found.offset = offset; + return found; +} +function compareDeep(a, b) { + if (a === b) return true; + if (!(a && _typeof(a) == "object") || !(b && _typeof(b) == "object")) return false; + var array = Array.isArray(a); + if (Array.isArray(b) != array) return false; + if (array) { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false; + } else { + for (var p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false; + for (var _p in b) if (!(_p in a)) return false; + } + return true; +} +var Mark = function () { + function Mark(type, attrs) { + _classCallCheck(this, Mark); + this.type = type; + this.attrs = attrs; + } + _createClass(Mark, [{ + key: "addToSet", + value: function addToSet(set) { + var copy, + placed = false; + for (var i = 0; i < set.length; i++) { + var other = set[i]; + if (this.eq(other)) return set; + if (this.type.excludes(other.type)) { + if (!copy) copy = set.slice(0, i); + } else if (other.type.excludes(this.type)) { + return set; + } else { + if (!placed && other.type.rank > this.type.rank) { + if (!copy) copy = set.slice(0, i); + copy.push(this); + placed = true; + } + if (copy) copy.push(other); + } + } + if (!copy) copy = set.slice(); + if (!placed) copy.push(this); + return copy; + } + }, { + key: "removeFromSet", + value: function removeFromSet(set) { + for (var i = 0; i < set.length; i++) if (this.eq(set[i])) return set.slice(0, i).concat(set.slice(i + 1)); + return set; + } + }, { + key: "isInSet", + value: function isInSet(set) { + for (var i = 0; i < set.length; i++) if (this.eq(set[i])) return true; + return false; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs); + } + }, { + key: "toJSON", + value: function toJSON() { + var obj = { + type: this.type.name + }; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break; + } + return obj; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) throw new RangeError("Invalid input for Mark.fromJSON"); + var type = schema.marks[json.type]; + if (!type) throw new RangeError("There is no mark type ".concat(json.type, " in this schema")); + var mark = type.create(json.attrs); + type.checkAttrs(mark.attrs); + return mark; + } + }, { + key: "sameSet", + value: function sameSet(a, b) { + if (a == b) return true; + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!a[i].eq(b[i])) return false; + return true; + } + }, { + key: "setFrom", + value: function setFrom(marks) { + if (!marks || Array.isArray(marks) && marks.length == 0) return Mark.none; + if (marks instanceof Mark) return [marks]; + var copy = marks.slice(); + copy.sort(function (a, b) { + return a.type.rank - b.type.rank; + }); + return copy; + } + }]); + return Mark; +}(); +Mark.none = []; +var ReplaceError = function (_Error) { + _inherits(ReplaceError, _Error); + var _super = _createSuper(ReplaceError); + function ReplaceError() { + _classCallCheck(this, ReplaceError); + return _super.apply(this, arguments); + } + return _createClass(ReplaceError); +}(_wrapNativeSuper(Error)); +var Slice = function () { + function Slice(content, openStart, openEnd) { + _classCallCheck(this, Slice); + this.content = content; + this.openStart = openStart; + this.openEnd = openEnd; + } + _createClass(Slice, [{ + key: "size", + get: function get() { + return this.content.size - this.openStart - this.openEnd; + } + }, { + key: "insertAt", + value: function insertAt(pos, fragment) { + var content = insertInto(this.content, pos + this.openStart, fragment); + return content && new Slice(content, this.openStart, this.openEnd); + } + }, { + key: "removeBetween", + value: function removeBetween(from, to) { + return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd); + } + }, { + key: "eq", + value: function eq(other) { + return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd; + } + }, { + key: "toString", + value: function toString() { + return this.content + "(" + this.openStart + "," + this.openEnd + ")"; + } + }, { + key: "toJSON", + value: function toJSON() { + if (!this.content.size) return null; + var json = { + content: this.content.toJSON() + }; + if (this.openStart > 0) json.openStart = this.openStart; + if (this.openEnd > 0) json.openEnd = this.openEnd; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) return Slice.empty; + var openStart = json.openStart || 0, + openEnd = json.openEnd || 0; + if (typeof openStart != "number" || typeof openEnd != "number") throw new RangeError("Invalid input for Slice.fromJSON"); + return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd); + } + }, { + key: "maxOpen", + value: function maxOpen(fragment) { + var openIsolating = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var openStart = 0, + openEnd = 0; + for (var n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) openStart++; + for (var _n = fragment.lastChild; _n && !_n.isLeaf && (openIsolating || !_n.type.spec.isolating); _n = _n.lastChild) openEnd++; + return new Slice(fragment, openStart, openEnd); + } + }]); + return Slice; +}(); +Slice.empty = new Slice(Fragment.empty, 0, 0); +function removeRange(content, from, to) { + var _content$findIndex = content.findIndex(from), + index = _content$findIndex.index, + offset = _content$findIndex.offset, + child = content.maybeChild(index); + var _content$findIndex2 = content.findIndex(to), + indexTo = _content$findIndex2.index, + offsetTo = _content$findIndex2.offset; + if (offset == from || child.isText) { + if (offsetTo != to && !content.child(indexTo).isText) throw new RangeError("Removing non-flat range"); + return content.cut(0, from).append(content.cut(to)); + } + if (index != indexTo) throw new RangeError("Removing non-flat range"); + return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1))); +} +function insertInto(content, dist, insert, parent) { + var _content$findIndex3 = content.findIndex(dist), + index = _content$findIndex3.index, + offset = _content$findIndex3.offset, + child = content.maybeChild(index); + if (offset == dist || child.isText) { + if (parent && !parent.canReplace(index, index, insert)) return null; + return content.cut(0, dist).append(insert).append(content.cut(dist)); + } + var inner = insertInto(child.content, dist - offset - 1, insert); + return inner && content.replaceChild(index, child.copy(inner)); +} +function _replace($from, $to, slice) { + if (slice.openStart > $from.depth) throw new ReplaceError("Inserted content deeper than insertion position"); + if ($from.depth - slice.openStart != $to.depth - slice.openEnd) throw new ReplaceError("Inconsistent open depths"); + return replaceOuter($from, $to, slice, 0); +} +function replaceOuter($from, $to, slice, depth) { + var index = $from.index(depth), + node = $from.node(depth); + if (index == $to.index(depth) && depth < $from.depth - slice.openStart) { + var inner = replaceOuter($from, $to, slice, depth + 1); + return node.copy(node.content.replaceChild(index, inner)); + } else if (!slice.content.size) { + return close(node, replaceTwoWay($from, $to, depth)); + } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { + var parent = $from.parent, + content = parent.content; + return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))); + } else { + var _prepareSliceForRepla = prepareSliceForReplace(slice, $from), + start = _prepareSliceForRepla.start, + end = _prepareSliceForRepla.end; + return close(node, replaceThreeWay($from, start, end, $to, depth)); + } +} +function checkJoin(main, sub) { + if (!sub.type.compatibleContent(main.type)) throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name); +} +function joinable($before, $after, depth) { + var node = $before.node(depth); + checkJoin(node, $after.node(depth)); + return node; +} +function addNode(child, target) { + var last = target.length - 1; + if (last >= 0 && child.isText && child.sameMarkup(target[last])) target[last] = child.withText(target[last].text + child.text);else target.push(child); +} +function addRange($start, $end, depth, target) { + var node = ($end || $start).node(depth); + var startIndex = 0, + endIndex = $end ? $end.index(depth) : node.childCount; + if ($start) { + startIndex = $start.index(depth); + if ($start.depth > depth) { + startIndex++; + } else if ($start.textOffset) { + addNode($start.nodeAfter, target); + startIndex++; + } + } + for (var i = startIndex; i < endIndex; i++) addNode(node.child(i), target); + if ($end && $end.depth == depth && $end.textOffset) addNode($end.nodeBefore, target); +} +function close(node, content) { + node.type.checkContent(content); + return node.copy(content); +} +function replaceThreeWay($from, $start, $end, $to, depth) { + var openStart = $from.depth > depth && joinable($from, $start, depth + 1); + var openEnd = $to.depth > depth && joinable($end, $to, depth + 1); + var content = []; + addRange(null, $from, depth, content); + if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { + checkJoin(openStart, openEnd); + addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content); + } else { + if (openStart) addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content); + addRange($start, $end, depth, content); + if (openEnd) addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content); + } + addRange($to, null, depth, content); + return new Fragment(content); +} +function replaceTwoWay($from, $to, depth) { + var content = []; + addRange(null, $from, depth, content); + if ($from.depth > depth) { + var type = joinable($from, $to, depth + 1); + addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content); + } + addRange($to, null, depth, content); + return new Fragment(content); +} +function prepareSliceForReplace(slice, $along) { + var extra = $along.depth - slice.openStart, + parent = $along.node(extra); + var node = parent.copy(slice.content); + for (var i = extra - 1; i >= 0; i--) node = $along.node(i).copy(Fragment.from(node)); + return { + start: node.resolveNoCache(slice.openStart + extra), + end: node.resolveNoCache(node.content.size - slice.openEnd - extra) + }; +} +var ResolvedPos = function () { + function ResolvedPos(pos, path, parentOffset) { + _classCallCheck(this, ResolvedPos); + this.pos = pos; + this.path = path; + this.parentOffset = parentOffset; + this.depth = path.length / 3 - 1; + } + _createClass(ResolvedPos, [{ + key: "resolveDepth", + value: function resolveDepth(val) { + if (val == null) return this.depth; + if (val < 0) return this.depth + val; + return val; + } + }, { + key: "parent", + get: function get() { + return this.node(this.depth); + } + }, { + key: "doc", + get: function get() { + return this.node(0); + } + }, { + key: "node", + value: function node(depth) { + return this.path[this.resolveDepth(depth) * 3]; + } + }, { + key: "index", + value: function index(depth) { + return this.path[this.resolveDepth(depth) * 3 + 1]; + } + }, { + key: "indexAfter", + value: function indexAfter(depth) { + depth = this.resolveDepth(depth); + return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1); + } + }, { + key: "start", + value: function start(depth) { + depth = this.resolveDepth(depth); + return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; + } + }, { + key: "end", + value: function end(depth) { + depth = this.resolveDepth(depth); + return this.start(depth) + this.node(depth).content.size; + } + }, { + key: "before", + value: function before(depth) { + depth = this.resolveDepth(depth); + if (!depth) throw new RangeError("There is no position before the top-level node"); + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1]; + } + }, { + key: "after", + value: function after(depth) { + depth = this.resolveDepth(depth); + if (!depth) throw new RangeError("There is no position after the top-level node"); + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize; + } + }, { + key: "textOffset", + get: function get() { + return this.pos - this.path[this.path.length - 1]; + } + }, { + key: "nodeAfter", + get: function get() { + var parent = this.parent, + index = this.index(this.depth); + if (index == parent.childCount) return null; + var dOff = this.pos - this.path[this.path.length - 1], + child = parent.child(index); + return dOff ? parent.child(index).cut(dOff) : child; + } + }, { + key: "nodeBefore", + get: function get() { + var index = this.index(this.depth); + var dOff = this.pos - this.path[this.path.length - 1]; + if (dOff) return this.parent.child(index).cut(0, dOff); + return index == 0 ? null : this.parent.child(index - 1); + } + }, { + key: "posAtIndex", + value: function posAtIndex(index, depth) { + depth = this.resolveDepth(depth); + var node = this.path[depth * 3], + pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; + for (var i = 0; i < index; i++) pos += node.child(i).nodeSize; + return pos; + } + }, { + key: "marks", + value: function marks() { + var parent = this.parent, + index = this.index(); + if (parent.content.size == 0) return Mark.none; + if (this.textOffset) return parent.child(index).marks; + var main = parent.maybeChild(index - 1), + other = parent.maybeChild(index); + if (!main) { + var tmp = main; + main = other; + other = tmp; + } + var marks = main.marks; + for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) marks = marks[i--].removeFromSet(marks); + return marks; + } + }, { + key: "marksAcross", + value: function marksAcross($end) { + var after = this.parent.maybeChild(this.index()); + if (!after || !after.isInline) return null; + var marks = after.marks, + next = $end.parent.maybeChild($end.index()); + for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) marks = marks[i--].removeFromSet(marks); + return marks; + } + }, { + key: "sharedDepth", + value: function sharedDepth(pos) { + for (var depth = this.depth; depth > 0; depth--) if (this.start(depth) <= pos && this.end(depth) >= pos) return depth; + return 0; + } + }, { + key: "blockRange", + value: function blockRange() { + var other = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this; + var pred = arguments.length > 1 ? arguments[1] : undefined; + if (other.pos < this.pos) return other.blockRange(this); + for (var d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) return new NodeRange(this, other, d); + return null; + } + }, { + key: "sameParent", + value: function sameParent(other) { + return this.pos - this.parentOffset == other.pos - other.parentOffset; + } + }, { + key: "max", + value: function max(other) { + return other.pos > this.pos ? other : this; + } + }, { + key: "min", + value: function min(other) { + return other.pos < this.pos ? other : this; + } + }, { + key: "toString", + value: function toString() { + var str = ""; + for (var i = 1; i <= this.depth; i++) str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1); + return str + ":" + this.parentOffset; + } + }], [{ + key: "resolve", + value: function resolve(doc, pos) { + if (!(pos >= 0 && pos <= doc.content.size)) throw new RangeError("Position " + pos + " out of range"); + var path = []; + var start = 0, + parentOffset = pos; + for (var node = doc;;) { + var _node$content$findInd = node.content.findIndex(parentOffset), + index = _node$content$findInd.index, + offset = _node$content$findInd.offset; + var rem = parentOffset - offset; + path.push(node, index, start + offset); + if (!rem) break; + node = node.child(index); + if (node.isText) break; + parentOffset = rem - 1; + start += offset + 1; + } + return new ResolvedPos(pos, path, parentOffset); + } + }, { + key: "resolveCached", + value: function resolveCached(doc, pos) { + var cache = resolveCache.get(doc); + if (cache) { + for (var i = 0; i < cache.elts.length; i++) { + var elt = cache.elts[i]; + if (elt.pos == pos) return elt; + } + } else { + resolveCache.set(doc, cache = new ResolveCache()); + } + var result = cache.elts[cache.i] = ResolvedPos.resolve(doc, pos); + cache.i = (cache.i + 1) % resolveCacheSize; + return result; + } + }]); + return ResolvedPos; +}(); +var ResolveCache = _createClass(function ResolveCache() { + _classCallCheck(this, ResolveCache); + this.elts = []; + this.i = 0; +}); +var resolveCacheSize = 12, + resolveCache = new WeakMap(); +var NodeRange = function () { + function NodeRange($from, $to, depth) { + _classCallCheck(this, NodeRange); + this.$from = $from; + this.$to = $to; + this.depth = depth; + } + _createClass(NodeRange, [{ + key: "start", + get: function get() { + return this.$from.before(this.depth + 1); + } + }, { + key: "end", + get: function get() { + return this.$to.after(this.depth + 1); + } + }, { + key: "parent", + get: function get() { + return this.$from.node(this.depth); + } + }, { + key: "startIndex", + get: function get() { + return this.$from.index(this.depth); + } + }, { + key: "endIndex", + get: function get() { + return this.$to.indexAfter(this.depth); + } + }]); + return NodeRange; +}(); +var emptyAttrs = Object.create(null); +var Node = function () { + function Node(type, attrs, content) { + var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Mark.none; + _classCallCheck(this, Node); + this.type = type; + this.attrs = attrs; + this.marks = marks; + this.content = content || Fragment.empty; + } + _createClass(Node, [{ + key: "nodeSize", + get: function get() { + return this.isLeaf ? 1 : 2 + this.content.size; + } + }, { + key: "childCount", + get: function get() { + return this.content.childCount; + } + }, { + key: "child", + value: function child(index) { + return this.content.child(index); + } + }, { + key: "maybeChild", + value: function maybeChild(index) { + return this.content.maybeChild(index); + } + }, { + key: "forEach", + value: function forEach(f) { + this.content.forEach(f); + } + }, { + key: "nodesBetween", + value: function nodesBetween(from, to, f) { + var startPos = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + this.content.nodesBetween(from, to, f, startPos, this); + } + }, { + key: "descendants", + value: function descendants(f) { + this.nodesBetween(0, this.content.size, f); + } + }, { + key: "textContent", + get: function get() { + return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, ""); + } + }, { + key: "textBetween", + value: function textBetween(from, to, blockSeparator, leafText) { + return this.content.textBetween(from, to, blockSeparator, leafText); + } + }, { + key: "firstChild", + get: function get() { + return this.content.firstChild; + } + }, { + key: "lastChild", + get: function get() { + return this.content.lastChild; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || this.sameMarkup(other) && this.content.eq(other.content); + } + }, { + key: "sameMarkup", + value: function sameMarkup(other) { + return this.hasMarkup(other.type, other.attrs, other.marks); + } + }, { + key: "hasMarkup", + value: function hasMarkup(type, attrs, marks) { + return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none); + } + }, { + key: "copy", + value: function copy() { + var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + if (content == this.content) return this; + return new Node(this.type, this.attrs, content, this.marks); + } + }, { + key: "mark", + value: function mark(marks) { + return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks); + } + }, { + key: "cut", + value: function cut(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.content.size; + if (from == 0 && to == this.content.size) return this; + return this.copy(this.content.cut(from, to)); + } + }, { + key: "slice", + value: function slice(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.content.size; + var includeParents = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + if (from == to) return Slice.empty; + var $from = this.resolve(from), + $to = this.resolve(to); + var depth = includeParents ? 0 : $from.sharedDepth(to); + var start = $from.start(depth), + node = $from.node(depth); + var content = node.content.cut($from.pos - start, $to.pos - start); + return new Slice(content, $from.depth - depth, $to.depth - depth); + } + }, { + key: "replace", + value: function replace(from, to, slice) { + return _replace(this.resolve(from), this.resolve(to), slice); + } + }, { + key: "nodeAt", + value: function nodeAt(pos) { + for (var node = this;;) { + var _node$content$findInd2 = node.content.findIndex(pos), + index = _node$content$findInd2.index, + offset = _node$content$findInd2.offset; + node = node.maybeChild(index); + if (!node) return null; + if (offset == pos || node.isText) return node; + pos -= offset + 1; + } + } + }, { + key: "childAfter", + value: function childAfter(pos) { + var _this$content$findInd = this.content.findIndex(pos), + index = _this$content$findInd.index, + offset = _this$content$findInd.offset; + return { + node: this.content.maybeChild(index), + index: index, + offset: offset + }; + } + }, { + key: "childBefore", + value: function childBefore(pos) { + if (pos == 0) return { + node: null, + index: 0, + offset: 0 + }; + var _this$content$findInd2 = this.content.findIndex(pos), + index = _this$content$findInd2.index, + offset = _this$content$findInd2.offset; + if (offset < pos) return { + node: this.content.child(index), + index: index, + offset: offset + }; + var node = this.content.child(index - 1); + return { + node: node, + index: index - 1, + offset: offset - node.nodeSize + }; + } + }, { + key: "resolve", + value: function resolve(pos) { + return ResolvedPos.resolveCached(this, pos); + } + }, { + key: "resolveNoCache", + value: function resolveNoCache(pos) { + return ResolvedPos.resolve(this, pos); + } + }, { + key: "rangeHasMark", + value: function rangeHasMark(from, to, type) { + var found = false; + if (to > from) this.nodesBetween(from, to, function (node) { + if (type.isInSet(node.marks)) found = true; + return !found; + }); + return found; + } + }, { + key: "isBlock", + get: function get() { + return this.type.isBlock; + } + }, { + key: "isTextblock", + get: function get() { + return this.type.isTextblock; + } + }, { + key: "inlineContent", + get: function get() { + return this.type.inlineContent; + } + }, { + key: "isInline", + get: function get() { + return this.type.isInline; + } + }, { + key: "isText", + get: function get() { + return this.type.isText; + } + }, { + key: "isLeaf", + get: function get() { + return this.type.isLeaf; + } + }, { + key: "isAtom", + get: function get() { + return this.type.isAtom; + } + }, { + key: "toString", + value: function toString() { + if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); + var name = this.type.name; + if (this.content.size) name += "(" + this.content.toStringInner() + ")"; + return wrapMarks(this.marks, name); + } + }, { + key: "contentMatchAt", + value: function contentMatchAt(index) { + var match = this.type.contentMatch.matchFragment(this.content, 0, index); + if (!match) throw new Error("Called contentMatchAt on a node with invalid content"); + return match; + } + }, { + key: "canReplace", + value: function canReplace(from, to) { + var replacement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Fragment.empty; + var start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + var end = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : replacement.childCount; + var one = this.contentMatchAt(from).matchFragment(replacement, start, end); + var two = one && one.matchFragment(this.content, to); + if (!two || !two.validEnd) return false; + for (var i = start; i < end; i++) if (!this.type.allowsMarks(replacement.child(i).marks)) return false; + return true; + } + }, { + key: "canReplaceWith", + value: function canReplaceWith(from, to, type, marks) { + if (marks && !this.type.allowsMarks(marks)) return false; + var start = this.contentMatchAt(from).matchType(type); + var end = start && start.matchFragment(this.content, to); + return end ? end.validEnd : false; + } + }, { + key: "canAppend", + value: function canAppend(other) { + if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content);else return this.type.compatibleContent(other.type); + } + }, { + key: "check", + value: function check() { + this.type.checkContent(this.content); + this.type.checkAttrs(this.attrs); + var copy = Mark.none; + for (var i = 0; i < this.marks.length; i++) { + var mark = this.marks[i]; + mark.type.checkAttrs(mark.attrs); + copy = mark.addToSet(copy); + } + if (!Mark.sameSet(copy, this.marks)) throw new RangeError("Invalid collection of marks for node ".concat(this.type.name, ": ").concat(this.marks.map(function (m) { + return m.type.name; + }))); + this.content.forEach(function (node) { + return node.check(); + }); + } + }, { + key: "toJSON", + value: function toJSON() { + var obj = { + type: this.type.name + }; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break; + } + if (this.content.size) obj.content = this.content.toJSON(); + if (this.marks.length) obj.marks = this.marks.map(function (n) { + return n.toJSON(); + }); + return obj; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json) throw new RangeError("Invalid input for Node.fromJSON"); + var marks = undefined; + if (json.marks) { + if (!Array.isArray(json.marks)) throw new RangeError("Invalid mark data for Node.fromJSON"); + marks = json.marks.map(schema.markFromJSON); + } + if (json.type == "text") { + if (typeof json.text != "string") throw new RangeError("Invalid text node in JSON"); + return schema.text(json.text, marks); + } + var content = Fragment.fromJSON(schema, json.content); + var node = schema.nodeType(json.type).create(json.attrs, content, marks); + node.type.checkAttrs(node.attrs); + return node; + } + }]); + return Node; +}(); +Node.prototype.text = undefined; +var TextNode = function (_Node) { + _inherits(TextNode, _Node); + var _super2 = _createSuper(TextNode); + function TextNode(type, attrs, content, marks) { + var _this; + _classCallCheck(this, TextNode); + _this = _super2.call(this, type, attrs, null, marks); + if (!content) throw new RangeError("Empty text nodes are not allowed"); + _this.text = content; + return _this; + } + _createClass(TextNode, [{ + key: "toString", + value: function toString() { + if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); + return wrapMarks(this.marks, JSON.stringify(this.text)); + } + }, { + key: "textContent", + get: function get() { + return this.text; + } + }, { + key: "textBetween", + value: function textBetween(from, to) { + return this.text.slice(from, to); + } + }, { + key: "nodeSize", + get: function get() { + return this.text.length; + } + }, { + key: "mark", + value: function mark(marks) { + return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks); + } + }, { + key: "withText", + value: function withText(text) { + if (text == this.text) return this; + return new TextNode(this.type, this.attrs, text, this.marks); + } + }, { + key: "cut", + value: function cut() { + var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.text.length; + if (from == 0 && to == this.text.length) return this; + return this.withText(this.text.slice(from, to)); + } + }, { + key: "eq", + value: function eq(other) { + return this.sameMarkup(other) && this.text == other.text; + } + }, { + key: "toJSON", + value: function toJSON() { + var base = _get(_getPrototypeOf(TextNode.prototype), "toJSON", this).call(this); + base.text = this.text; + return base; + } + }]); + return TextNode; +}(Node); +function wrapMarks(marks, str) { + for (var i = marks.length - 1; i >= 0; i--) str = marks[i].type.name + "(" + str + ")"; + return str; +} +var ContentMatch = function () { + function ContentMatch(validEnd) { + _classCallCheck(this, ContentMatch); + this.validEnd = validEnd; + this.next = []; + this.wrapCache = []; + } + _createClass(ContentMatch, [{ + key: "matchType", + value: function matchType(type) { + for (var i = 0; i < this.next.length; i++) if (this.next[i].type == type) return this.next[i].next; + return null; + } + }, { + key: "matchFragment", + value: function matchFragment(frag) { + var start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : frag.childCount; + var cur = this; + for (var i = start; cur && i < end; i++) cur = cur.matchType(frag.child(i).type); + return cur; + } + }, { + key: "inlineContent", + get: function get() { + return this.next.length != 0 && this.next[0].type.isInline; + } + }, { + key: "defaultType", + get: function get() { + for (var i = 0; i < this.next.length; i++) { + var type = this.next[i].type; + if (!(type.isText || type.hasRequiredAttrs())) return type; + } + return null; + } + }, { + key: "compatible", + value: function compatible(other) { + for (var i = 0; i < this.next.length; i++) for (var j = 0; j < other.next.length; j++) if (this.next[i].type == other.next[j].type) return true; + return false; + } + }, { + key: "fillBefore", + value: function fillBefore(after) { + var toEnd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var seen = [this]; + function search(match, types) { + var finished = match.matchFragment(after, startIndex); + if (finished && (!toEnd || finished.validEnd)) return Fragment.from(types.map(function (tp) { + return tp.createAndFill(); + })); + for (var i = 0; i < match.next.length; i++) { + var _match$next$i = match.next[i], + type = _match$next$i.type, + next = _match$next$i.next; + if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) { + seen.push(next); + var _found = search(next, types.concat(type)); + if (_found) return _found; + } + } + return null; + } + return search(this, []); + } + }, { + key: "findWrapping", + value: function findWrapping(target) { + for (var i = 0; i < this.wrapCache.length; i += 2) if (this.wrapCache[i] == target) return this.wrapCache[i + 1]; + var computed = this.computeWrapping(target); + this.wrapCache.push(target, computed); + return computed; + } + }, { + key: "computeWrapping", + value: function computeWrapping(target) { + var seen = Object.create(null), + active = [{ + match: this, + type: null, + via: null + }]; + while (active.length) { + var current = active.shift(), + match = current.match; + if (match.matchType(target)) { + var result = []; + for (var obj = current; obj.type; obj = obj.via) result.push(obj.type); + return result.reverse(); + } + for (var i = 0; i < match.next.length; i++) { + var _match$next$i2 = match.next[i], + type = _match$next$i2.type, + next = _match$next$i2.next; + if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) { + active.push({ + match: type.contentMatch, + type: type, + via: current + }); + seen[type.name] = true; + } + } + } + return null; + } + }, { + key: "edgeCount", + get: function get() { + return this.next.length; + } + }, { + key: "edge", + value: function edge(n) { + if (n >= this.next.length) throw new RangeError("There's no ".concat(n, "th edge in this content match")); + return this.next[n]; + } + }, { + key: "toString", + value: function toString() { + var seen = []; + function scan(m) { + seen.push(m); + for (var i = 0; i < m.next.length; i++) if (seen.indexOf(m.next[i].next) == -1) scan(m.next[i].next); + } + scan(this); + return seen.map(function (m, i) { + var out = i + (m.validEnd ? "*" : " ") + " "; + for (var _i = 0; _i < m.next.length; _i++) out += (_i ? ", " : "") + m.next[_i].type.name + "->" + seen.indexOf(m.next[_i].next); + return out; + }).join("\n"); + } + }], [{ + key: "parse", + value: function parse(string, nodeTypes) { + var stream = new TokenStream(string, nodeTypes); + if (stream.next == null) return ContentMatch.empty; + var expr = parseExpr(stream); + if (stream.next) stream.err("Unexpected trailing text"); + var match = dfa(nfa(expr)); + checkForDeadEnds(match, stream); + return match; + } + }]); + return ContentMatch; +}(); +ContentMatch.empty = new ContentMatch(true); +var TokenStream = function () { + function TokenStream(string, nodeTypes) { + _classCallCheck(this, TokenStream); + this.string = string; + this.nodeTypes = nodeTypes; + this.inline = null; + this.pos = 0; + this.tokens = string.split(/\s*(?=\b|\W|$)/); + if (this.tokens[this.tokens.length - 1] == "") this.tokens.pop(); + if (this.tokens[0] == "") this.tokens.shift(); + } + _createClass(TokenStream, [{ + key: "next", + get: function get() { + return this.tokens[this.pos]; + } + }, { + key: "eat", + value: function eat(tok) { + return this.next == tok && (this.pos++ || true); + } + }, { + key: "err", + value: function err(str) { + throw new SyntaxError(str + " (in content expression '" + this.string + "')"); + } + }]); + return TokenStream; +}(); +function parseExpr(stream) { + var exprs = []; + do { + exprs.push(parseExprSeq(stream)); + } while (stream.eat("|")); + return exprs.length == 1 ? exprs[0] : { + type: "choice", + exprs: exprs + }; +} +function parseExprSeq(stream) { + var exprs = []; + do { + exprs.push(parseExprSubscript(stream)); + } while (stream.next && stream.next != ")" && stream.next != "|"); + return exprs.length == 1 ? exprs[0] : { + type: "seq", + exprs: exprs + }; +} +function parseExprSubscript(stream) { + var expr = parseExprAtom(stream); + for (;;) { + if (stream.eat("+")) expr = { + type: "plus", + expr: expr + };else if (stream.eat("*")) expr = { + type: "star", + expr: expr + };else if (stream.eat("?")) expr = { + type: "opt", + expr: expr + };else if (stream.eat("{")) expr = parseExprRange(stream, expr);else break; + } + return expr; +} +function parseNum(stream) { + if (/\D/.test(stream.next)) stream.err("Expected number, got '" + stream.next + "'"); + var result = Number(stream.next); + stream.pos++; + return result; +} +function parseExprRange(stream, expr) { + var min = parseNum(stream), + max = min; + if (stream.eat(",")) { + if (stream.next != "}") max = parseNum(stream);else max = -1; + } + if (!stream.eat("}")) stream.err("Unclosed braced range"); + return { + type: "range", + min: min, + max: max, + expr: expr + }; +} +function resolveName(stream, name) { + var types = stream.nodeTypes, + type = types[name]; + if (type) return [type]; + var result = []; + for (var typeName in types) { + var _type = types[typeName]; + if (_type.isInGroup(name)) result.push(_type); + } + if (result.length == 0) stream.err("No node type or group '" + name + "' found"); + return result; +} +function parseExprAtom(stream) { + if (stream.eat("(")) { + var expr = parseExpr(stream); + if (!stream.eat(")")) stream.err("Missing closing paren"); + return expr; + } else if (!/\W/.test(stream.next)) { + var exprs = resolveName(stream, stream.next).map(function (type) { + if (stream.inline == null) stream.inline = type.isInline;else if (stream.inline != type.isInline) stream.err("Mixing inline and block content"); + return { + type: "name", + value: type + }; + }); + stream.pos++; + return exprs.length == 1 ? exprs[0] : { + type: "choice", + exprs: exprs + }; + } else { + stream.err("Unexpected token '" + stream.next + "'"); + } +} +function nfa(expr) { + var nfa = [[]]; + connect(compile(expr, 0), node()); + return nfa; + function node() { + return nfa.push([]) - 1; + } + function edge(from, to, term) { + var edge = { + term: term, + to: to + }; + nfa[from].push(edge); + return edge; + } + function connect(edges, to) { + edges.forEach(function (edge) { + return edge.to = to; + }); + } + function compile(expr, from) { + if (expr.type == "choice") { + return expr.exprs.reduce(function (out, expr) { + return out.concat(compile(expr, from)); + }, []); + } else if (expr.type == "seq") { + for (var i = 0;; i++) { + var next = compile(expr.exprs[i], from); + if (i == expr.exprs.length - 1) return next; + connect(next, from = node()); + } + } else if (expr.type == "star") { + var loop = node(); + edge(from, loop); + connect(compile(expr.expr, loop), loop); + return [edge(loop)]; + } else if (expr.type == "plus") { + var _loop = node(); + connect(compile(expr.expr, from), _loop); + connect(compile(expr.expr, _loop), _loop); + return [edge(_loop)]; + } else if (expr.type == "opt") { + return [edge(from)].concat(compile(expr.expr, from)); + } else if (expr.type == "range") { + var cur = from; + for (var _i2 = 0; _i2 < expr.min; _i2++) { + var _next = node(); + connect(compile(expr.expr, cur), _next); + cur = _next; + } + if (expr.max == -1) { + connect(compile(expr.expr, cur), cur); + } else { + for (var _i3 = expr.min; _i3 < expr.max; _i3++) { + var _next2 = node(); + edge(cur, _next2); + connect(compile(expr.expr, cur), _next2); + cur = _next2; + } + } + return [edge(cur)]; + } else if (expr.type == "name") { + return [edge(from, undefined, expr.value)]; + } else { + throw new Error("Unknown expr type"); + } + } +} +function cmp(a, b) { + return b - a; +} +function nullFrom(nfa, node) { + var result = []; + scan(node); + return result.sort(cmp); + function scan(node) { + var edges = nfa[node]; + if (edges.length == 1 && !edges[0].term) return scan(edges[0].to); + result.push(node); + for (var i = 0; i < edges.length; i++) { + var _edges$i = edges[i], + term = _edges$i.term, + to = _edges$i.to; + if (!term && result.indexOf(to) == -1) scan(to); + } + } +} +function dfa(nfa) { + var labeled = Object.create(null); + return explore(nullFrom(nfa, 0)); + function explore(states) { + var out = []; + states.forEach(function (node) { + nfa[node].forEach(function (_ref) { + var term = _ref.term, + to = _ref.to; + if (!term) return; + var set; + for (var i = 0; i < out.length; i++) if (out[i][0] == term) set = out[i][1]; + nullFrom(nfa, to).forEach(function (node) { + if (!set) out.push([term, set = []]); + if (set.indexOf(node) == -1) set.push(node); + }); + }); + }); + var state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1); + for (var i = 0; i < out.length; i++) { + var _states = out[i][1].sort(cmp); + state.next.push({ + type: out[i][0], + next: labeled[_states.join(",")] || explore(_states) + }); + } + return state; + } +} +function checkForDeadEnds(match, stream) { + for (var i = 0, work = [match]; i < work.length; i++) { + var state = work[i], + dead = !state.validEnd, + nodes = []; + for (var j = 0; j < state.next.length; j++) { + var _state$next$j = state.next[j], + type = _state$next$j.type, + next = _state$next$j.next; + nodes.push(type.name); + if (dead && !(type.isText || type.hasRequiredAttrs())) dead = false; + if (work.indexOf(next) == -1) work.push(next); + } + if (dead) stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)"); + } +} +function defaultAttrs(attrs) { + var defaults = Object.create(null); + for (var attrName in attrs) { + var attr = attrs[attrName]; + if (!attr.hasDefault) return null; + defaults[attrName] = attr["default"]; + } + return defaults; +} +function _computeAttrs(attrs, value) { + var built = Object.create(null); + for (var name in attrs) { + var given = value && value[name]; + if (given === undefined) { + var attr = attrs[name]; + if (attr.hasDefault) given = attr["default"];else throw new RangeError("No value supplied for attribute " + name); + } + built[name] = given; + } + return built; +} +function _checkAttrs(attrs, values, type, name) { + for (var _name in values) if (!(_name in attrs)) throw new RangeError("Unsupported attribute ".concat(_name, " for ").concat(type, " of type ").concat(_name)); + for (var _name2 in attrs) { + var attr = attrs[_name2]; + if (attr.validate) attr.validate(values[_name2]); + } +} +function initAttrs(typeName, attrs) { + var result = Object.create(null); + if (attrs) for (var name in attrs) result[name] = new Attribute(typeName, name, attrs[name]); + return result; +} +var NodeType = function () { + function NodeType(name, schema, spec) { + _classCallCheck(this, NodeType); + this.name = name; + this.schema = schema; + this.spec = spec; + this.markSet = null; + this.groups = spec.group ? spec.group.split(" ") : []; + this.attrs = initAttrs(name, spec.attrs); + this.defaultAttrs = defaultAttrs(this.attrs); + this.contentMatch = null; + this.inlineContent = null; + this.isBlock = !(spec.inline || name == "text"); + this.isText = name == "text"; + } + _createClass(NodeType, [{ + key: "isInline", + get: function get() { + return !this.isBlock; + } + }, { + key: "isTextblock", + get: function get() { + return this.isBlock && this.inlineContent; + } + }, { + key: "isLeaf", + get: function get() { + return this.contentMatch == ContentMatch.empty; + } + }, { + key: "isAtom", + get: function get() { + return this.isLeaf || !!this.spec.atom; + } + }, { + key: "isInGroup", + value: function isInGroup(group) { + return this.groups.indexOf(group) > -1; + } + }, { + key: "whitespace", + get: function get() { + return this.spec.whitespace || (this.spec.code ? "pre" : "normal"); + } + }, { + key: "hasRequiredAttrs", + value: function hasRequiredAttrs() { + for (var n in this.attrs) if (this.attrs[n].isRequired) return true; + return false; + } + }, { + key: "compatibleContent", + value: function compatibleContent(other) { + return this == other || this.contentMatch.compatible(other.contentMatch); + } + }, { + key: "computeAttrs", + value: function computeAttrs(attrs) { + if (!attrs && this.defaultAttrs) return this.defaultAttrs;else return _computeAttrs(this.attrs, attrs); + } + }, { + key: "create", + value: function create() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + if (this.isText) throw new Error("NodeType.create can't construct text nodes"); + return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks)); + } + }, { + key: "createChecked", + value: function createChecked() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + content = Fragment.from(content); + this.checkContent(content); + return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks)); + } + }, { + key: "createAndFill", + value: function createAndFill() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var content = arguments.length > 1 ? arguments[1] : undefined; + var marks = arguments.length > 2 ? arguments[2] : undefined; + attrs = this.computeAttrs(attrs); + content = Fragment.from(content); + if (content.size) { + var before = this.contentMatch.fillBefore(content); + if (!before) return null; + content = before.append(content); + } + var matched = this.contentMatch.matchFragment(content); + var after = matched && matched.fillBefore(Fragment.empty, true); + if (!after) return null; + return new Node(this, attrs, content.append(after), Mark.setFrom(marks)); + } + }, { + key: "validContent", + value: function validContent(content) { + var result = this.contentMatch.matchFragment(content); + if (!result || !result.validEnd) return false; + for (var i = 0; i < content.childCount; i++) if (!this.allowsMarks(content.child(i).marks)) return false; + return true; + } + }, { + key: "checkContent", + value: function checkContent(content) { + if (!this.validContent(content)) throw new RangeError("Invalid content for node ".concat(this.name, ": ").concat(content.toString().slice(0, 50))); + } + }, { + key: "checkAttrs", + value: function checkAttrs(attrs) { + _checkAttrs(this.attrs, attrs, "node", this.name); + } + }, { + key: "allowsMarkType", + value: function allowsMarkType(markType) { + return this.markSet == null || this.markSet.indexOf(markType) > -1; + } + }, { + key: "allowsMarks", + value: function allowsMarks(marks) { + if (this.markSet == null) return true; + for (var i = 0; i < marks.length; i++) if (!this.allowsMarkType(marks[i].type)) return false; + return true; + } + }, { + key: "allowedMarks", + value: function allowedMarks(marks) { + if (this.markSet == null) return marks; + var copy; + for (var i = 0; i < marks.length; i++) { + if (!this.allowsMarkType(marks[i].type)) { + if (!copy) copy = marks.slice(0, i); + } else if (copy) { + copy.push(marks[i]); + } + } + return !copy ? marks : copy.length ? copy : Mark.none; + } + }], [{ + key: "compile", + value: function compile(nodes, schema) { + var result = Object.create(null); + nodes.forEach(function (name, spec) { + return result[name] = new NodeType(name, schema, spec); + }); + var topType = schema.spec.topNode || "doc"; + if (!result[topType]) throw new RangeError("Schema is missing its top node type ('" + topType + "')"); + if (!result.text) throw new RangeError("Every schema needs a 'text' type"); + for (var _ in result.text.attrs) throw new RangeError("The text node type should not have attributes"); + return result; + } + }]); + return NodeType; +}(); +function validateType(typeName, attrName, type) { + var types = type.split("|"); + return function (value) { + var name = value === null ? "null" : _typeof(value); + if (types.indexOf(name) < 0) throw new RangeError("Expected value of type ".concat(types, " for attribute ").concat(attrName, " on type ").concat(typeName, ", got ").concat(name)); + }; +} +var Attribute = function () { + function Attribute(typeName, attrName, options) { + _classCallCheck(this, Attribute); + this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default"); + this["default"] = options["default"]; + this.validate = typeof options.validate == "string" ? validateType(typeName, attrName, options.validate) : options.validate; + } + _createClass(Attribute, [{ + key: "isRequired", + get: function get() { + return !this.hasDefault; + } + }]); + return Attribute; +}(); +var MarkType = function () { + function MarkType(name, rank, schema, spec) { + _classCallCheck(this, MarkType); + this.name = name; + this.rank = rank; + this.schema = schema; + this.spec = spec; + this.attrs = initAttrs(name, spec.attrs); + this.excluded = null; + var defaults = defaultAttrs(this.attrs); + this.instance = defaults ? new Mark(this, defaults) : null; + } + _createClass(MarkType, [{ + key: "create", + value: function create() { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + if (!attrs && this.instance) return this.instance; + return new Mark(this, _computeAttrs(this.attrs, attrs)); + } + }, { + key: "removeFromSet", + value: function removeFromSet(set) { + for (var i = 0; i < set.length; i++) if (set[i].type == this) { + set = set.slice(0, i).concat(set.slice(i + 1)); + i--; + } + return set; + } + }, { + key: "isInSet", + value: function isInSet(set) { + for (var i = 0; i < set.length; i++) if (set[i].type == this) return set[i]; + } + }, { + key: "checkAttrs", + value: function checkAttrs(attrs) { + _checkAttrs(this.attrs, attrs, "mark", this.name); + } + }, { + key: "excludes", + value: function excludes(other) { + return this.excluded.indexOf(other) > -1; + } + }], [{ + key: "compile", + value: function compile(marks, schema) { + var result = Object.create(null), + rank = 0; + marks.forEach(function (name, spec) { + return result[name] = new MarkType(name, rank++, schema, spec); + }); + return result; + } + }]); + return MarkType; +}(); +var Schema = function () { + function Schema(spec) { + _classCallCheck(this, Schema); + this.linebreakReplacement = null; + this.cached = Object.create(null); + var instanceSpec = this.spec = {}; + for (var prop in spec) instanceSpec[prop] = spec[prop]; + instanceSpec.nodes = OrderedMap.from(spec.nodes), instanceSpec.marks = OrderedMap.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this); + this.marks = MarkType.compile(this.spec.marks, this); + var contentExprCache = Object.create(null); + for (var _prop in this.nodes) { + if (_prop in this.marks) throw new RangeError(_prop + " can not be both a node and a mark"); + var type = this.nodes[_prop], + contentExpr = type.spec.content || "", + markExpr = type.spec.marks; + type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes)); + type.inlineContent = type.contentMatch.inlineContent; + if (type.spec.linebreakReplacement) { + if (this.linebreakReplacement) throw new RangeError("Multiple linebreak nodes defined"); + if (!type.isInline || !type.isLeaf) throw new RangeError("Linebreak replacement nodes must be inline leaf nodes"); + this.linebreakReplacement = type; + } + type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null; + } + for (var _prop2 in this.marks) { + var _type2 = this.marks[_prop2], + excl = _type2.spec.excludes; + _type2.excluded = excl == null ? [_type2] : excl == "" ? [] : gatherMarks(this, excl.split(" ")); + } + this.nodeFromJSON = this.nodeFromJSON.bind(this); + this.markFromJSON = this.markFromJSON.bind(this); + this.topNodeType = this.nodes[this.spec.topNode || "doc"]; + this.cached.wrappings = Object.create(null); + } + _createClass(Schema, [{ + key: "node", + value: function node(type) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var content = arguments.length > 2 ? arguments[2] : undefined; + var marks = arguments.length > 3 ? arguments[3] : undefined; + if (typeof type == "string") type = this.nodeType(type);else if (!(type instanceof NodeType)) throw new RangeError("Invalid node type: " + type);else if (type.schema != this) throw new RangeError("Node type from different schema used (" + type.name + ")"); + return type.createChecked(attrs, content, marks); + } + }, { + key: "text", + value: function text(_text, marks) { + var type = this.nodes.text; + return new TextNode(type, type.defaultAttrs, _text, Mark.setFrom(marks)); + } + }, { + key: "mark", + value: function mark(type, attrs) { + if (typeof type == "string") type = this.marks[type]; + return type.create(attrs); + } + }, { + key: "nodeFromJSON", + value: function nodeFromJSON(json) { + return Node.fromJSON(this, json); + } + }, { + key: "markFromJSON", + value: function markFromJSON(json) { + return Mark.fromJSON(this, json); + } + }, { + key: "nodeType", + value: function nodeType(name) { + var found = this.nodes[name]; + if (!found) throw new RangeError("Unknown node type: " + name); + return found; + } + }]); + return Schema; +}(); +function gatherMarks(schema, marks) { + var found = []; + for (var i = 0; i < marks.length; i++) { + var name = marks[i], + mark = schema.marks[name], + ok = mark; + if (mark) { + found.push(mark); + } else { + for (var prop in schema.marks) { + var _mark = schema.marks[prop]; + if (name == "_" || _mark.spec.group && _mark.spec.group.split(" ").indexOf(name) > -1) found.push(ok = _mark); + } + } + if (!ok) throw new SyntaxError("Unknown mark type: '" + marks[i] + "'"); + } + return found; +} +function isTagRule(rule) { + return rule.tag != null; +} +function isStyleRule(rule) { + return rule.style != null; +} +var DOMParser = function () { + function DOMParser(schema, rules) { + var _this2 = this; + _classCallCheck(this, DOMParser); + this.schema = schema; + this.rules = rules; + this.tags = []; + this.styles = []; + var matchedStyles = this.matchedStyles = []; + rules.forEach(function (rule) { + if (isTagRule(rule)) { + _this2.tags.push(rule); + } else if (isStyleRule(rule)) { + var prop = /[^=]*/.exec(rule.style)[0]; + if (matchedStyles.indexOf(prop) < 0) matchedStyles.push(prop); + _this2.styles.push(rule); + } + }); + this.normalizeLists = !this.tags.some(function (r) { + if (!/^(ul|ol)\b/.test(r.tag) || !r.node) return false; + var node = schema.nodes[r.node]; + return node.contentMatch.matchType(node); + }); + } + _createClass(DOMParser, [{ + key: "parse", + value: function parse(dom) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var context = new ParseContext(this, options, false); + context.addAll(dom, Mark.none, options.from, options.to); + return context.finish(); + } + }, { + key: "parseSlice", + value: function parseSlice(dom) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var context = new ParseContext(this, options, true); + context.addAll(dom, Mark.none, options.from, options.to); + return Slice.maxOpen(context.finish()); + } + }, { + key: "matchTag", + value: function matchTag(dom, context, after) { + for (var i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) { + var rule = this.tags[i]; + if (matches(dom, rule.tag) && (rule.namespace === undefined || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) { + if (rule.getAttrs) { + var result = rule.getAttrs(dom); + if (result === false) continue; + rule.attrs = result || undefined; + } + return rule; + } + } + } + }, { + key: "matchStyle", + value: function matchStyle(prop, value, context, after) { + for (var i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) { + var rule = this.styles[i], + style = rule.style; + if (style.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || style.length > prop.length && (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value)) continue; + if (rule.getAttrs) { + var result = rule.getAttrs(value); + if (result === false) continue; + rule.attrs = result || undefined; + } + return rule; + } + } + }], [{ + key: "schemaRules", + value: function schemaRules(schema) { + var result = []; + function insert(rule) { + var priority = rule.priority == null ? 50 : rule.priority, + i = 0; + for (; i < result.length; i++) { + var next = result[i], + nextPriority = next.priority == null ? 50 : next.priority; + if (nextPriority < priority) break; + } + result.splice(i, 0, rule); + } + var _loop2 = function _loop2(name) { + var rules = schema.marks[name].spec.parseDOM; + if (rules) rules.forEach(function (rule) { + insert(rule = copy(rule)); + if (!(rule.mark || rule.ignore || rule.clearMark)) rule.mark = name; + }); + }; + for (var name in schema.marks) { + _loop2(name); + } + var _loop3 = function _loop3(_name3) { + var rules = schema.nodes[_name3].spec.parseDOM; + if (rules) rules.forEach(function (rule) { + insert(rule = copy(rule)); + if (!(rule.node || rule.ignore || rule.mark)) rule.node = _name3; + }); + }; + for (var _name3 in schema.nodes) { + _loop3(_name3); + } + return result; + } + }, { + key: "fromSchema", + value: function fromSchema(schema) { + return schema.cached.domParser || (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema))); + } + }]); + return DOMParser; +}(); +var blockTags = { + address: true, + article: true, + aside: true, + blockquote: true, + canvas: true, + dd: true, + div: true, + dl: true, + fieldset: true, + figcaption: true, + figure: true, + footer: true, + form: true, + h1: true, + h2: true, + h3: true, + h4: true, + h5: true, + h6: true, + header: true, + hgroup: true, + hr: true, + li: true, + noscript: true, + ol: true, + output: true, + p: true, + pre: true, + section: true, + table: true, + tfoot: true, + ul: true +}; +var ignoreTags = { + head: true, + noscript: true, + object: true, + script: true, + style: true, + title: true +}; +var listTags = { + ol: true, + ul: true +}; +var OPT_PRESERVE_WS = 1, + OPT_PRESERVE_WS_FULL = 2, + OPT_OPEN_LEFT = 4; +function wsOptionsFor(type, preserveWhitespace, base) { + if (preserveWhitespace != null) return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0); + return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT; +} +var NodeContext = function () { + function NodeContext(type, attrs, marks, solid, match, options) { + _classCallCheck(this, NodeContext); + this.type = type; + this.attrs = attrs; + this.marks = marks; + this.solid = solid; + this.options = options; + this.content = []; + this.activeMarks = Mark.none; + this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch); + } + _createClass(NodeContext, [{ + key: "findWrapping", + value: function findWrapping(node) { + if (!this.match) { + if (!this.type) return []; + var fill = this.type.contentMatch.fillBefore(Fragment.from(node)); + if (fill) { + this.match = this.type.contentMatch.matchFragment(fill); + } else { + var start = this.type.contentMatch, + wrap; + if (wrap = start.findWrapping(node.type)) { + this.match = start; + return wrap; + } else { + return null; + } + } + } + return this.match.findWrapping(node.type); + } + }, { + key: "finish", + value: function finish(openEnd) { + if (!(this.options & OPT_PRESERVE_WS)) { + var last = this.content[this.content.length - 1], + m; + if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) { + var text = last; + if (last.text.length == m[0].length) this.content.pop();else this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length)); + } + } + var content = Fragment.from(this.content); + if (!openEnd && this.match) content = content.append(this.match.fillBefore(Fragment.empty, true)); + return this.type ? this.type.create(this.attrs, content, this.marks) : content; + } + }, { + key: "inlineContext", + value: function inlineContext(node) { + if (this.type) return this.type.inlineContent; + if (this.content.length) return this.content[0].isInline; + return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase()); + } + }]); + return NodeContext; +}(); +var ParseContext = function () { + function ParseContext(parser, options, isOpen) { + _classCallCheck(this, ParseContext); + this.parser = parser; + this.options = options; + this.isOpen = isOpen; + this.open = 0; + var topNode = options.topNode, + topContext; + var topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0); + if (topNode) topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);else if (isOpen) topContext = new NodeContext(null, null, Mark.none, true, null, topOptions);else topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions); + this.nodes = [topContext]; + this.find = options.findPositions; + this.needsBlock = false; + } + _createClass(ParseContext, [{ + key: "top", + get: function get() { + return this.nodes[this.open]; + } + }, { + key: "addDOM", + value: function addDOM(dom, marks) { + if (dom.nodeType == 3) this.addTextNode(dom, marks);else if (dom.nodeType == 1) this.addElement(dom, marks); + } + }, { + key: "addTextNode", + value: function addTextNode(dom, marks) { + var value = dom.nodeValue; + var top = this.top; + if (top.options & OPT_PRESERVE_WS_FULL || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) { + if (!(top.options & OPT_PRESERVE_WS)) { + value = value.replace(/[ \t\r\n\u000c]+/g, " "); + if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) { + var nodeBefore = top.content[top.content.length - 1]; + var domNodeBefore = dom.previousSibling; + if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == 'BR' || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text)) value = value.slice(1); + } + } else if (!(top.options & OPT_PRESERVE_WS_FULL)) { + value = value.replace(/\r?\n|\r/g, " "); + } else { + value = value.replace(/\r\n?/g, "\n"); + } + if (value) this.insertNode(this.parser.schema.text(value), marks); + this.findInText(dom); + } else { + this.findInside(dom); + } + } + }, { + key: "addElement", + value: function addElement(dom, marks, matchAfter) { + var name = dom.nodeName.toLowerCase(), + ruleID; + if (listTags.hasOwnProperty(name) && this.parser.normalizeLists) normalizeList(dom); + var rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter)); + if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) { + this.findInside(dom); + this.ignoreFallback(dom, marks); + } else if (!rule || rule.skip || rule.closeParent) { + if (rule && rule.closeParent) this.open = Math.max(0, this.open - 1);else if (rule && rule.skip.nodeType) dom = rule.skip; + var sync, + top = this.top, + oldNeedsBlock = this.needsBlock; + if (blockTags.hasOwnProperty(name)) { + if (top.content.length && top.content[0].isInline && this.open) { + this.open--; + top = this.top; + } + sync = true; + if (!top.type) this.needsBlock = true; + } else if (!dom.firstChild) { + this.leafFallback(dom, marks); + return; + } + var innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks); + if (innerMarks) this.addAll(dom, innerMarks); + if (sync) this.sync(top); + this.needsBlock = oldNeedsBlock; + } else { + var _innerMarks = this.readStyles(dom, marks); + if (_innerMarks) this.addElementByRule(dom, rule, _innerMarks, rule.consuming === false ? ruleID : undefined); + } + } + }, { + key: "leafFallback", + value: function leafFallback(dom, marks) { + if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent) this.addTextNode(dom.ownerDocument.createTextNode("\n"), marks); + } + }, { + key: "ignoreFallback", + value: function ignoreFallback(dom, marks) { + if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent)) this.findPlace(this.parser.schema.text("-"), marks); + } + }, { + key: "readStyles", + value: function readStyles(dom, marks) { + var _this3 = this; + var styles = dom.style; + if (styles && styles.length) for (var i = 0; i < this.parser.matchedStyles.length; i++) { + var name = this.parser.matchedStyles[i], + value = styles.getPropertyValue(name); + if (value) { + var _loop4 = function _loop4(_after) { + var rule = _this3.parser.matchStyle(name, value, _this3, _after); + if (!rule) { + after = _after; + return 0; + } + if (rule.ignore) return { + v: null + }; + if (rule.clearMark) marks = marks.filter(function (m) { + return !rule.clearMark(m); + });else marks = marks.concat(_this3.parser.schema.marks[rule.mark].create(rule.attrs)); + if (rule.consuming === false) _after = rule;else { + after = _after; + return 0; + } + after = _after; + }, + _ret; + for (var after = undefined;;) { + _ret = _loop4(after); + if (_ret === 0) break; + if (_ret) return _ret.v; + } + } + } + return marks; + } + }, { + key: "addElementByRule", + value: function addElementByRule(dom, rule, marks, continueAfter) { + var _this4 = this; + var sync, nodeType; + if (rule.node) { + nodeType = this.parser.schema.nodes[rule.node]; + if (!nodeType.isLeaf) { + var inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace); + if (inner) { + sync = true; + marks = inner; + } + } else if (!this.insertNode(nodeType.create(rule.attrs), marks)) { + this.leafFallback(dom, marks); + } + } else { + var markType = this.parser.schema.marks[rule.mark]; + marks = marks.concat(markType.create(rule.attrs)); + } + var startIn = this.top; + if (nodeType && nodeType.isLeaf) { + this.findInside(dom); + } else if (continueAfter) { + this.addElement(dom, marks, continueAfter); + } else if (rule.getContent) { + this.findInside(dom); + rule.getContent(dom, this.parser.schema).forEach(function (node) { + return _this4.insertNode(node, marks); + }); + } else { + var contentDOM = dom; + if (typeof rule.contentElement == "string") contentDOM = dom.querySelector(rule.contentElement);else if (typeof rule.contentElement == "function") contentDOM = rule.contentElement(dom);else if (rule.contentElement) contentDOM = rule.contentElement; + this.findAround(dom, contentDOM, true); + this.addAll(contentDOM, marks); + this.findAround(dom, contentDOM, false); + } + if (sync && this.sync(startIn)) this.open--; + } + }, { + key: "addAll", + value: function addAll(parent, marks, startIndex, endIndex) { + var index = startIndex || 0; + for (var dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) { + this.findAtPoint(parent, index); + this.addDOM(dom, marks); + } + this.findAtPoint(parent, index); + } + }, { + key: "findPlace", + value: function findPlace(node, marks) { + var route, sync; + for (var depth = this.open; depth >= 0; depth--) { + var cx = this.nodes[depth]; + var _found2 = cx.findWrapping(node); + if (_found2 && (!route || route.length > _found2.length)) { + route = _found2; + sync = cx; + if (!_found2.length) break; + } + if (cx.solid) break; + } + if (!route) return null; + this.sync(sync); + for (var i = 0; i < route.length; i++) marks = this.enterInner(route[i], null, marks, false); + return marks; + } + }, { + key: "insertNode", + value: function insertNode(node, marks) { + if (node.isInline && this.needsBlock && !this.top.type) { + var block = this.textblockFromContext(); + if (block) marks = this.enterInner(block, null, marks); + } + var innerMarks = this.findPlace(node, marks); + if (innerMarks) { + this.closeExtra(); + var top = this.top; + if (top.match) top.match = top.match.matchType(node.type); + var nodeMarks = Mark.none; + var _iterator = _createForOfIteratorHelper(innerMarks.concat(node.marks)), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var m = _step.value; + if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type)) nodeMarks = m.addToSet(nodeMarks); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + top.content.push(node.mark(nodeMarks)); + return true; + } + return false; + } + }, { + key: "enter", + value: function enter(type, attrs, marks, preserveWS) { + var innerMarks = this.findPlace(type.create(attrs), marks); + if (innerMarks) innerMarks = this.enterInner(type, attrs, marks, true, preserveWS); + return innerMarks; + } + }, { + key: "enterInner", + value: function enterInner(type, attrs, marks) { + var solid = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + var preserveWS = arguments.length > 4 ? arguments[4] : undefined; + this.closeExtra(); + var top = this.top; + top.match = top.match && top.match.matchType(type); + var options = wsOptionsFor(type, preserveWS, top.options); + if (top.options & OPT_OPEN_LEFT && top.content.length == 0) options |= OPT_OPEN_LEFT; + var applyMarks = Mark.none; + marks = marks.filter(function (m) { + if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) { + applyMarks = m.addToSet(applyMarks); + return false; + } + return true; + }); + this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options)); + this.open++; + return marks; + } + }, { + key: "closeExtra", + value: function closeExtra() { + var openEnd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var i = this.nodes.length - 1; + if (i > this.open) { + for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)); + this.nodes.length = this.open + 1; + } + } + }, { + key: "finish", + value: function finish() { + this.open = 0; + this.closeExtra(this.isOpen); + return this.nodes[0].finish(this.isOpen || this.options.topOpen); + } + }, { + key: "sync", + value: function sync(to) { + for (var i = this.open; i >= 0; i--) if (this.nodes[i] == to) { + this.open = i; + return true; + } + return false; + } + }, { + key: "currentPos", + get: function get() { + this.closeExtra(); + var pos = 0; + for (var i = this.open; i >= 0; i--) { + var content = this.nodes[i].content; + for (var j = content.length - 1; j >= 0; j--) pos += content[j].nodeSize; + if (i) pos++; + } + return pos; + } + }, { + key: "findAtPoint", + value: function findAtPoint(parent, offset) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == parent && this.find[i].offset == offset) this.find[i].pos = this.currentPos; + } + } + }, { + key: "findInside", + value: function findInside(parent) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) this.find[i].pos = this.currentPos; + } + } + }, { + key: "findAround", + value: function findAround(parent, content, before) { + if (parent != content && this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) { + var pos = content.compareDocumentPosition(this.find[i].node); + if (pos & (before ? 2 : 4)) this.find[i].pos = this.currentPos; + } + } + } + }, { + key: "findInText", + value: function findInText(textNode) { + if (this.find) for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == textNode) this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset); + } + } + }, { + key: "matchesContext", + value: function matchesContext(context) { + var _this5 = this; + if (context.indexOf("|") > -1) return context.split(/\s*\|\s*/).some(this.matchesContext, this); + var parts = context.split("/"); + var option = this.options.context; + var useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type); + var minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1); + var match = function match(i, depth) { + for (; i >= 0; i--) { + var part = parts[i]; + if (part == "") { + if (i == parts.length - 1 || i == 0) continue; + for (; depth >= minDepth; depth--) if (match(i - 1, depth)) return true; + return false; + } else { + var next = depth > 0 || depth == 0 && useRoot ? _this5.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null; + if (!next || next.name != part && !next.isInGroup(part)) return false; + depth--; + } + } + return true; + }; + return match(parts.length - 1, this.open); + } + }, { + key: "textblockFromContext", + value: function textblockFromContext() { + var $context = this.options.context; + if ($context) for (var d = $context.depth; d >= 0; d--) { + var deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType; + if (deflt && deflt.isTextblock && deflt.defaultAttrs) return deflt; + } + for (var name in this.parser.schema.nodes) { + var type = this.parser.schema.nodes[name]; + if (type.isTextblock && type.defaultAttrs) return type; + } + } + }]); + return ParseContext; +}(); +function normalizeList(dom) { + for (var child = dom.firstChild, prevItem = null; child; child = child.nextSibling) { + var name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null; + if (name && listTags.hasOwnProperty(name) && prevItem) { + prevItem.appendChild(child); + child = prevItem; + } else if (name == "li") { + prevItem = child; + } else if (name) { + prevItem = null; + } + } +} +function matches(dom, selector) { + return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector); +} +function copy(obj) { + var copy = {}; + for (var prop in obj) copy[prop] = obj[prop]; + return copy; +} +function markMayApply(markType, nodeType) { + var nodes = nodeType.schema.nodes; + var _loop5 = function _loop5() { + var parent = nodes[name]; + if (!parent.allowsMarkType(markType)) return 0; + var seen = [], + scan = function scan(match) { + seen.push(match); + for (var i = 0; i < match.edgeCount; i++) { + var _match$edge = match.edge(i), + type = _match$edge.type, + next = _match$edge.next; + if (type == nodeType) return true; + if (seen.indexOf(next) < 0 && scan(next)) return true; + } + }; + if (scan(parent.contentMatch)) return { + v: true + }; + }, + _ret2; + for (var name in nodes) { + _ret2 = _loop5(); + if (_ret2 === 0) continue; + if (_ret2) return _ret2.v; + } +} +var DOMSerializer = function () { + function DOMSerializer(nodes, marks) { + _classCallCheck(this, DOMSerializer); + this.nodes = nodes; + this.marks = marks; + } + _createClass(DOMSerializer, [{ + key: "serializeFragment", + value: function serializeFragment(fragment) { + var _this6 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var target = arguments.length > 2 ? arguments[2] : undefined; + if (!target) target = doc(options).createDocumentFragment(); + var top = target, + active = []; + fragment.forEach(function (node) { + if (active.length || node.marks.length) { + var keep = 0, + rendered = 0; + while (keep < active.length && rendered < node.marks.length) { + var next = node.marks[rendered]; + if (!_this6.marks[next.type.name]) { + rendered++; + continue; + } + if (!next.eq(active[keep][0]) || next.type.spec.spanning === false) break; + keep++; + rendered++; + } + while (keep < active.length) top = active.pop()[1]; + while (rendered < node.marks.length) { + var add = node.marks[rendered++]; + var markDOM = _this6.serializeMark(add, node.isInline, options); + if (markDOM) { + active.push([add, top]); + top.appendChild(markDOM.dom); + top = markDOM.contentDOM || markDOM.dom; + } + } + } + top.appendChild(_this6.serializeNodeInner(node, options)); + }); + return target; + } + }, { + key: "serializeNodeInner", + value: function serializeNodeInner(node, options) { + var _renderSpec2 = _renderSpec(doc(options), this.nodes[node.type.name](node), null, node.attrs), + dom = _renderSpec2.dom, + contentDOM = _renderSpec2.contentDOM; + if (contentDOM) { + if (node.isLeaf) throw new RangeError("Content hole not allowed in a leaf node spec"); + this.serializeFragment(node.content, options, contentDOM); + } + return dom; + } + }, { + key: "serializeNode", + value: function serializeNode(node) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var dom = this.serializeNodeInner(node, options); + for (var i = node.marks.length - 1; i >= 0; i--) { + var wrap = this.serializeMark(node.marks[i], node.isInline, options); + if (wrap) { + (wrap.contentDOM || wrap.dom).appendChild(dom); + dom = wrap.dom; + } + } + return dom; + } + }, { + key: "serializeMark", + value: function serializeMark(mark, inline) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var toDOM = this.marks[mark.type.name]; + return toDOM && _renderSpec(doc(options), toDOM(mark, inline), null, mark.attrs); + } + }], [{ + key: "renderSpec", + value: function renderSpec(doc, structure) { + var xmlNS = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var blockArraysIn = arguments.length > 3 ? arguments[3] : undefined; + return _renderSpec(doc, structure, xmlNS, blockArraysIn); + } + }, { + key: "fromSchema", + value: function fromSchema(schema) { + return schema.cached.domSerializer || (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema))); + } + }, { + key: "nodesFromSchema", + value: function nodesFromSchema(schema) { + var result = gatherToDOM(schema.nodes); + if (!result.text) result.text = function (node) { + return node.text; + }; + return result; + } + }, { + key: "marksFromSchema", + value: function marksFromSchema(schema) { + return gatherToDOM(schema.marks); + } + }]); + return DOMSerializer; +}(); +function gatherToDOM(obj) { + var result = {}; + for (var name in obj) { + var toDOM = obj[name].spec.toDOM; + if (toDOM) result[name] = toDOM; + } + return result; +} +function doc(options) { + return options.document || window.document; +} +var suspiciousAttributeCache = new WeakMap(); +function suspiciousAttributes(attrs) { + var value = suspiciousAttributeCache.get(attrs); + if (value === undefined) suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs)); + return value; +} +function suspiciousAttributesInner(attrs) { + var result = null; + function scan(value) { + if (value && _typeof(value) == "object") { + if (Array.isArray(value)) { + if (typeof value[0] == "string") { + if (!result) result = []; + result.push(value); + } else { + for (var i = 0; i < value.length; i++) scan(value[i]); + } + } else { + for (var prop in value) scan(value[prop]); + } + } + } + scan(attrs); + return result; +} +function _renderSpec(doc, structure, xmlNS, blockArraysIn) { + if (typeof structure == "string") return { + dom: doc.createTextNode(structure) + }; + if (structure.nodeType != null) return { + dom: structure + }; + if (structure.dom && structure.dom.nodeType != null) return structure; + var tagName = structure[0], + suspicious; + if (typeof tagName != "string") throw new RangeError("Invalid array passed to renderSpec"); + if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1) throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack."); + var space = tagName.indexOf(" "); + if (space > 0) { + xmlNS = tagName.slice(0, space); + tagName = tagName.slice(space + 1); + } + var contentDOM; + var dom = xmlNS ? doc.createElementNS(xmlNS, tagName) : doc.createElement(tagName); + var attrs = structure[1], + start = 1; + if (attrs && _typeof(attrs) == "object" && attrs.nodeType == null && !Array.isArray(attrs)) { + start = 2; + for (var name in attrs) if (attrs[name] != null) { + var _space = name.indexOf(" "); + if (_space > 0) dom.setAttributeNS(name.slice(0, _space), name.slice(_space + 1), attrs[name]);else dom.setAttribute(name, attrs[name]); + } + } + for (var i = start; i < structure.length; i++) { + var child = structure[i]; + if (child === 0) { + if (i < structure.length - 1 || i > start) throw new RangeError("Content hole must be the only child of its parent node"); + return { + dom: dom, + contentDOM: dom + }; + } else { + var _renderSpec3 = _renderSpec(doc, child, xmlNS, blockArraysIn), + inner = _renderSpec3.dom, + innerContent = _renderSpec3.contentDOM; + dom.appendChild(inner); + if (innerContent) { + if (contentDOM) throw new RangeError("Multiple content holes"); + contentDOM = innerContent; + } + } + } + return { + dom: dom, + contentDOM: contentDOM + }; +} +exports.ContentMatch = ContentMatch; +exports.DOMParser = DOMParser; +exports.DOMSerializer = DOMSerializer; +exports.Fragment = Fragment; +exports.Mark = Mark; +exports.MarkType = MarkType; +exports.Node = Node; +exports.NodeRange = NodeRange; +exports.NodeType = NodeType; +exports.ReplaceError = ReplaceError; +exports.ResolvedPos = ResolvedPos; +exports.Schema = Schema; +exports.Slice = Slice; + +}); +define("prosemirror-schema-list",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var prosemirrorTransform = require('prosemirror-transform'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorState = require('prosemirror-state'); +var olDOM = ["ol", 0], + ulDOM = ["ul", 0], + liDOM = ["li", 0]; +var orderedList = { + attrs: { + order: { + "default": 1, + validate: "number" + } + }, + parseDOM: [{ + tag: "ol", + getAttrs: function getAttrs(dom) { + return { + order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1 + }; + } + }], + toDOM: function toDOM(node) { + return node.attrs.order == 1 ? olDOM : ["ol", { + start: node.attrs.order + }, 0]; + } +}; +var bulletList = { + parseDOM: [{ + tag: "ul" + }], + toDOM: function toDOM() { + return ulDOM; + } +}; +var listItem = { + parseDOM: [{ + tag: "li" + }], + toDOM: function toDOM() { + return liDOM; + }, + defining: true +}; +function add(obj, props) { + var copy = {}; + for (var prop in obj) copy[prop] = obj[prop]; + for (var _prop in props) copy[_prop] = props[_prop]; + return copy; +} +function addListNodes(nodes, itemContent, listGroup) { + return nodes.append({ + ordered_list: add(orderedList, { + content: "list_item+", + group: listGroup + }), + bullet_list: add(bulletList, { + content: "list_item+", + group: listGroup + }), + list_item: add(listItem, { + content: itemContent + }) + }); +} +function wrapInList(listType) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + return function (state, dispatch) { + var _state$selection = state.selection, + $from = _state$selection.$from, + $to = _state$selection.$to; + var range = $from.blockRange($to), + doJoin = false, + outerRange = range; + if (!range) return false; + if (range.depth >= 2 && $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex == 0) { + if ($from.index(range.depth - 1) == 0) return false; + var $insert = state.doc.resolve(range.start - 2); + outerRange = new prosemirrorModel.NodeRange($insert, $insert, range.depth); + if (range.endIndex < range.parent.childCount) range = new prosemirrorModel.NodeRange($from, state.doc.resolve($to.end(range.depth)), range.depth); + doJoin = true; + } + var wrap = prosemirrorTransform.findWrapping(outerRange, listType, attrs, range); + if (!wrap) return false; + if (dispatch) dispatch(doWrapInList(state.tr, range, wrap, doJoin, listType).scrollIntoView()); + return true; + }; +} +function doWrapInList(tr, range, wrappers, joinBefore, listType) { + var content = prosemirrorModel.Fragment.empty; + for (var i = wrappers.length - 1; i >= 0; i--) content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); + tr.step(new prosemirrorTransform.ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true)); + var found = 0; + for (var _i = 0; _i < wrappers.length; _i++) if (wrappers[_i].type == listType) found = _i + 1; + var splitDepth = wrappers.length - found; + var splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), + parent = range.parent; + for (var _i2 = range.startIndex, e = range.endIndex, first = true; _i2 < e; _i2++, first = false) { + if (!first && prosemirrorTransform.canSplit(tr.doc, splitPos, splitDepth)) { + tr.split(splitPos, splitDepth); + splitPos += 2 * splitDepth; + } + splitPos += parent.child(_i2).nodeSize; + } + return tr; +} +function splitListItem(itemType, itemAttrs) { + return function (state, dispatch) { + var _state$selection2 = state.selection, + $from = _state$selection2.$from, + $to = _state$selection2.$to, + node = _state$selection2.node; + if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; + var grandParent = $from.node(-1); + if (grandParent.type != itemType) return false; + if ($from.parent.content.size == 0 && $from.node(-1).childCount == $from.indexAfter(-1)) { + if ($from.depth == 3 || $from.node(-3).type != itemType || $from.index(-2) != $from.node(-2).childCount - 1) return false; + if (dispatch) { + var wrap = prosemirrorModel.Fragment.empty; + var depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3; + for (var d = $from.depth - depthBefore; d >= $from.depth - 3; d--) wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); + var depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3; + wrap = wrap.append(prosemirrorModel.Fragment.from(itemType.createAndFill())); + var start = $from.before($from.depth - (depthBefore - 1)); + var _tr = state.tr.replace(start, $from.after(-depthAfter), new prosemirrorModel.Slice(wrap, 4 - depthBefore, 0)); + var sel = -1; + _tr.doc.nodesBetween(start, _tr.doc.content.size, function (node, pos) { + if (sel > -1) return false; + if (node.isTextblock && node.content.size == 0) sel = pos + 1; + }); + if (sel > -1) _tr.setSelection(prosemirrorState.Selection.near(_tr.doc.resolve(sel))); + dispatch(_tr.scrollIntoView()); + } + return true; + } + var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt(0).defaultType : null; + var tr = state.tr["delete"]($from.pos, $to.pos); + var types = nextType ? [itemAttrs ? { + type: itemType, + attrs: itemAttrs + } : null, { + type: nextType + }] : undefined; + if (!prosemirrorTransform.canSplit(tr.doc, $from.pos, 2, types)) return false; + if (dispatch) dispatch(tr.split($from.pos, 2, types).scrollIntoView()); + return true; + }; +} +function splitListItemKeepMarks(itemType, itemAttrs) { + var split = splitListItem(itemType, itemAttrs); + return function (state, dispatch) { + return split(state, dispatch && function (tr) { + var marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks(); + if (marks) tr.ensureMarks(marks); + dispatch(tr); + }); + }; +} +function liftListItem(itemType) { + return function (state, dispatch) { + var _state$selection3 = state.selection, + $from = _state$selection3.$from, + $to = _state$selection3.$to; + var range = $from.blockRange($to, function (node) { + return node.childCount > 0 && node.firstChild.type == itemType; + }); + if (!range) return false; + if (!dispatch) return true; + if ($from.node(range.depth - 1).type == itemType) return liftToOuterList(state, dispatch, itemType, range);else return liftOutOfList(state, dispatch, range); + }; +} +function liftToOuterList(state, dispatch, itemType, range) { + var tr = state.tr, + end = range.end, + endOfList = range.$to.end(range.depth); + if (end < endOfList) { + tr.step(new prosemirrorTransform.ReplaceAroundStep(end - 1, endOfList, end, endOfList, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true)); + range = new prosemirrorModel.NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth); + } + var target = prosemirrorTransform.liftTarget(range); + if (target == null) return false; + tr.lift(range, target); + var after = tr.mapping.map(end, -1) - 1; + if (prosemirrorTransform.canJoin(tr.doc, after)) tr.join(after); + dispatch(tr.scrollIntoView()); + return true; +} +function liftOutOfList(state, dispatch, range) { + var tr = state.tr, + list = range.parent; + for (var pos = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) { + pos -= list.child(i).nodeSize; + tr["delete"](pos - 1, pos + 1); + } + var $start = tr.doc.resolve(range.start), + item = $start.nodeAfter; + if (tr.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) return false; + var atStart = range.startIndex == 0, + atEnd = range.endIndex == list.childCount; + var parent = $start.node(-1), + indexBefore = $start.index(-1); + if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list)))) return false; + var start = $start.pos, + end = start + item.nodeSize; + tr.step(new prosemirrorTransform.ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new prosemirrorModel.Slice((atStart ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list.copy(prosemirrorModel.Fragment.empty))).append(atEnd ? prosemirrorModel.Fragment.empty : prosemirrorModel.Fragment.from(list.copy(prosemirrorModel.Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1)); + dispatch(tr.scrollIntoView()); + return true; +} +function sinkListItem(itemType) { + return function (state, dispatch) { + var _state$selection4 = state.selection, + $from = _state$selection4.$from, + $to = _state$selection4.$to; + var range = $from.blockRange($to, function (node) { + return node.childCount > 0 && node.firstChild.type == itemType; + }); + if (!range) return false; + var startIndex = range.startIndex; + if (startIndex == 0) return false; + var parent = range.parent, + nodeBefore = parent.child(startIndex - 1); + if (nodeBefore.type != itemType) return false; + if (dispatch) { + var nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type; + var inner = prosemirrorModel.Fragment.from(nestedBefore ? itemType.create() : null); + var slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(itemType.create(null, prosemirrorModel.Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0); + var before = range.start, + after = range.end; + dispatch(state.tr.step(new prosemirrorTransform.ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice, 1, true)).scrollIntoView()); + } + return true; + }; +} +exports.addListNodes = addListNodes; +exports.bulletList = bulletList; +exports.liftListItem = liftListItem; +exports.listItem = listItem; +exports.orderedList = orderedList; +exports.sinkListItem = sinkListItem; +exports.splitListItem = splitListItem; +exports.splitListItemKeepMarks = splitListItemKeepMarks; +exports.wrapInList = wrapInList; + +}); +define("prosemirror-state",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } + +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } + +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var prosemirrorModel = require('prosemirror-model'); + +var prosemirrorTransform = require('prosemirror-transform'); + +var classesById = Object.create(null); + +var Selection = function () { + function Selection($anchor, $head, ranges) { + _classCallCheck(this, Selection); + + this.$anchor = $anchor; + this.$head = $head; + this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))]; + } + + _createClass(Selection, [{ + key: "anchor", + get: function get() { + return this.$anchor.pos; + } + }, { + key: "head", + get: function get() { + return this.$head.pos; + } + }, { + key: "from", + get: function get() { + return this.$from.pos; + } + }, { + key: "to", + get: function get() { + return this.$to.pos; + } + }, { + key: "$from", + get: function get() { + return this.ranges[0].$from; + } + }, { + key: "$to", + get: function get() { + return this.ranges[0].$to; + } + }, { + key: "empty", + get: function get() { + var ranges = this.ranges; + + for (var i = 0; i < ranges.length; i++) { + if (ranges[i].$from.pos != ranges[i].$to.pos) return false; + } + + return true; + } + }, { + key: "content", + value: function content() { + return this.$from.doc.slice(this.from, this.to, true); + } + }, { + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + var lastNode = content.content.lastChild, + lastParent = null; + + for (var i = 0; i < content.openEnd; i++) { + lastParent = lastNode; + lastNode = lastNode.lastChild; + } + + var mapFrom = tr.steps.length, + ranges = this.ranges; + + for (var _i = 0; _i < ranges.length; _i++) { + var _ranges$_i = ranges[_i], + $from = _ranges$_i.$from, + $to = _ranges$_i.$to, + mapping = tr.mapping.slice(mapFrom); + tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), _i ? prosemirrorModel.Slice.empty : content); + if (_i == 0) selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1); + } + } + }, { + key: "replaceWith", + value: function replaceWith(tr, node) { + var mapFrom = tr.steps.length, + ranges = this.ranges; + + for (var i = 0; i < ranges.length; i++) { + var _ranges$i = ranges[i], + $from = _ranges$i.$from, + $to = _ranges$i.$to, + mapping = tr.mapping.slice(mapFrom); + var from = mapping.map($from.pos), + to = mapping.map($to.pos); + + if (i) { + tr.deleteRange(from, to); + } else { + tr.replaceRangeWith(from, to, node); + selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1); + } + } + } + }, { + key: "getBookmark", + value: function getBookmark() { + return TextSelection.between(this.$anchor, this.$head).getBookmark(); + } + }], [{ + key: "findFrom", + value: function findFrom($pos, dir) { + var textOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly); + if (inner) return inner; + + for (var depth = $pos.depth - 1; depth >= 0; depth--) { + var found = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly); + if (found) return found; + } + + return null; + } + }, { + key: "near", + value: function near($pos) { + var bias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0)); + } + }, { + key: "atStart", + value: function atStart(doc) { + return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc); + } + }, { + key: "atEnd", + value: function atEnd(doc) { + return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc); + } + }, { + key: "fromJSON", + value: function fromJSON(doc, json) { + if (!json || !json.type) throw new RangeError("Invalid input for Selection.fromJSON"); + var cls = classesById[json.type]; + if (!cls) throw new RangeError("No selection type ".concat(json.type, " defined")); + return cls.fromJSON(doc, json); + } + }, { + key: "jsonID", + value: function jsonID(id, selectionClass) { + if (id in classesById) throw new RangeError("Duplicate use of selection JSON ID " + id); + classesById[id] = selectionClass; + selectionClass.prototype.jsonID = id; + return selectionClass; + } + }]); + + return Selection; +}(); + +Selection.prototype.visible = true; + +var SelectionRange = _createClass(function SelectionRange($from, $to) { + _classCallCheck(this, SelectionRange); + + this.$from = $from; + this.$to = $to; +}); + +var warnedAboutTextSelection = false; + +function checkTextSelection($pos) { + if (!warnedAboutTextSelection && !$pos.parent.inlineContent) { + warnedAboutTextSelection = true; + console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")"); + } +} + +var TextSelection = function (_Selection) { + _inherits(TextSelection, _Selection); + + var _super = _createSuper(TextSelection); + + function TextSelection($anchor) { + var $head = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchor; + + _classCallCheck(this, TextSelection); + + checkTextSelection($anchor); + checkTextSelection($head); + return _super.call(this, $anchor, $head); + } + + _createClass(TextSelection, [{ + key: "$cursor", + get: function get() { + return this.$anchor.pos == this.$head.pos ? this.$head : null; + } + }, { + key: "map", + value: function map(doc, mapping) { + var $head = doc.resolve(mapping.map(this.head)); + if (!$head.parent.inlineContent) return Selection.near($head); + var $anchor = doc.resolve(mapping.map(this.anchor)); + return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head); + } + }, { + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + + _get(_getPrototypeOf(TextSelection.prototype), "replace", this).call(this, tr, content); + + if (content == prosemirrorModel.Slice.empty) { + var marks = this.$from.marksAcross(this.$to); + if (marks) tr.ensureMarks(marks); + } + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new TextBookmark(this.anchor, this.head); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "text", + anchor: this.anchor, + head: this.head + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.anchor != "number" || typeof json.head != "number") throw new RangeError("Invalid input for TextSelection.fromJSON"); + return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head)); + } + }, { + key: "create", + value: function create(doc, anchor) { + var head = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : anchor; + var $anchor = doc.resolve(anchor); + return new this($anchor, head == anchor ? $anchor : doc.resolve(head)); + } + }, { + key: "between", + value: function between($anchor, $head, bias) { + var dPos = $anchor.pos - $head.pos; + if (!bias || dPos) bias = dPos >= 0 ? 1 : -1; + + if (!$head.parent.inlineContent) { + var found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true); + if (found) $head = found.$head;else return Selection.near($head, bias); + } + + if (!$anchor.parent.inlineContent) { + if (dPos == 0) { + $anchor = $head; + } else { + $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor; + if ($anchor.pos < $head.pos != dPos < 0) $anchor = $head; + } + } + + return new TextSelection($anchor, $head); + } + }]); + + return TextSelection; +}(Selection); + +Selection.jsonID("text", TextSelection); + +var TextBookmark = function () { + function TextBookmark(anchor, head) { + _classCallCheck(this, TextBookmark); + + this.anchor = anchor; + this.head = head; + } + + _createClass(TextBookmark, [{ + key: "map", + value: function map(mapping) { + return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head)); + } + }, { + key: "resolve", + value: function resolve(doc) { + return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head)); + } + }]); + + return TextBookmark; +}(); + +var NodeSelection = function (_Selection2) { + _inherits(NodeSelection, _Selection2); + + var _super2 = _createSuper(NodeSelection); + + function NodeSelection($pos) { + var _this; + + _classCallCheck(this, NodeSelection); + + var node = $pos.nodeAfter; + var $end = $pos.node(0).resolve($pos.pos + node.nodeSize); + _this = _super2.call(this, $pos, $end); + _this.node = node; + return _this; + } + + _createClass(NodeSelection, [{ + key: "map", + value: function map(doc, mapping) { + var _mapping$mapResult = mapping.mapResult(this.anchor), + deleted = _mapping$mapResult.deleted, + pos = _mapping$mapResult.pos; + + var $pos = doc.resolve(pos); + if (deleted) return Selection.near($pos); + return new NodeSelection($pos); + } + }, { + key: "content", + value: function content() { + return new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(this.node), 0, 0); + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof NodeSelection && other.anchor == this.anchor; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "node", + anchor: this.anchor + }; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return new NodeBookmark(this.anchor); + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc, json) { + if (typeof json.anchor != "number") throw new RangeError("Invalid input for NodeSelection.fromJSON"); + return new NodeSelection(doc.resolve(json.anchor)); + } + }, { + key: "create", + value: function create(doc, from) { + return new NodeSelection(doc.resolve(from)); + } + }, { + key: "isSelectable", + value: function isSelectable(node) { + return !node.isText && node.type.spec.selectable !== false; + } + }]); + + return NodeSelection; +}(Selection); + +NodeSelection.prototype.visible = false; +Selection.jsonID("node", NodeSelection); + +var NodeBookmark = function () { + function NodeBookmark(anchor) { + _classCallCheck(this, NodeBookmark); + + this.anchor = anchor; + } + + _createClass(NodeBookmark, [{ + key: "map", + value: function map(mapping) { + var _mapping$mapResult2 = mapping.mapResult(this.anchor), + deleted = _mapping$mapResult2.deleted, + pos = _mapping$mapResult2.pos; + + return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos); + } + }, { + key: "resolve", + value: function resolve(doc) { + var $pos = doc.resolve(this.anchor), + node = $pos.nodeAfter; + if (node && NodeSelection.isSelectable(node)) return new NodeSelection($pos); + return Selection.near($pos); + } + }]); + + return NodeBookmark; +}(); + +var AllSelection = function (_Selection3) { + _inherits(AllSelection, _Selection3); + + var _super3 = _createSuper(AllSelection); + + function AllSelection(doc) { + _classCallCheck(this, AllSelection); + + return _super3.call(this, doc.resolve(0), doc.resolve(doc.content.size)); + } + + _createClass(AllSelection, [{ + key: "replace", + value: function replace(tr) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prosemirrorModel.Slice.empty; + + if (content == prosemirrorModel.Slice.empty) { + tr["delete"](0, tr.doc.content.size); + var sel = Selection.atStart(tr.doc); + if (!sel.eq(tr.selection)) tr.setSelection(sel); + } else { + _get(_getPrototypeOf(AllSelection.prototype), "replace", this).call(this, tr, content); + } + } + }, { + key: "toJSON", + value: function toJSON() { + return { + type: "all" + }; + } + }, { + key: "map", + value: function map(doc) { + return new AllSelection(doc); + } + }, { + key: "eq", + value: function eq(other) { + return other instanceof AllSelection; + } + }, { + key: "getBookmark", + value: function getBookmark() { + return AllBookmark; + } + }], [{ + key: "fromJSON", + value: function fromJSON(doc) { + return new AllSelection(doc); + } + }]); + + return AllSelection; +}(Selection); + +Selection.jsonID("all", AllSelection); +var AllBookmark = { + map: function map() { + return this; + }, + resolve: function resolve(doc) { + return new AllSelection(doc); + } +}; + +function findSelectionIn(doc, node, pos, index, dir) { + var text = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; + if (node.inlineContent) return TextSelection.create(doc, pos); + + for (var i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) { + var child = node.child(i); + + if (!child.isAtom) { + var inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text); + if (inner) return inner; + } else if (!text && NodeSelection.isSelectable(child)) { + return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0)); + } + + pos += child.nodeSize * dir; + } + + return null; +} + +function selectionToInsertionEnd(tr, startLen, bias) { + var last = tr.steps.length - 1; + if (last < startLen) return; + var step = tr.steps[last]; + if (!(step instanceof prosemirrorTransform.ReplaceStep || step instanceof prosemirrorTransform.ReplaceAroundStep)) return; + var map = tr.mapping.maps[last], + end; + map.forEach(function (_from, _to, _newFrom, newTo) { + if (end == null) end = newTo; + }); + tr.setSelection(Selection.near(tr.doc.resolve(end), bias)); +} + +var UPDATED_SEL = 1, + UPDATED_MARKS = 2, + UPDATED_SCROLL = 4; + +var Transaction = function (_prosemirrorTransform) { + _inherits(Transaction, _prosemirrorTransform); + + var _super4 = _createSuper(Transaction); + + function Transaction(state) { + var _this2; + + _classCallCheck(this, Transaction); + + _this2 = _super4.call(this, state.doc); + _this2.curSelectionFor = 0; + _this2.updated = 0; + _this2.meta = Object.create(null); + _this2.time = Date.now(); + _this2.curSelection = state.selection; + _this2.storedMarks = state.storedMarks; + return _this2; + } + + _createClass(Transaction, [{ + key: "selection", + get: function get() { + if (this.curSelectionFor < this.steps.length) { + this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)); + this.curSelectionFor = this.steps.length; + } + + return this.curSelection; + } + }, { + key: "setSelection", + value: function setSelection(selection) { + if (selection.$from.doc != this.doc) throw new RangeError("Selection passed to setSelection must point at the current document"); + this.curSelection = selection; + this.curSelectionFor = this.steps.length; + this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS; + this.storedMarks = null; + return this; + } + }, { + key: "selectionSet", + get: function get() { + return (this.updated & UPDATED_SEL) > 0; + } + }, { + key: "setStoredMarks", + value: function setStoredMarks(marks) { + this.storedMarks = marks; + this.updated |= UPDATED_MARKS; + return this; + } + }, { + key: "ensureMarks", + value: function ensureMarks(marks) { + if (!prosemirrorModel.Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks)) this.setStoredMarks(marks); + return this; + } + }, { + key: "addStoredMark", + value: function addStoredMark(mark) { + return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks())); + } + }, { + key: "removeStoredMark", + value: function removeStoredMark(mark) { + return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks())); + } + }, { + key: "storedMarksSet", + get: function get() { + return (this.updated & UPDATED_MARKS) > 0; + } + }, { + key: "addStep", + value: function addStep(step, doc) { + _get(_getPrototypeOf(Transaction.prototype), "addStep", this).call(this, step, doc); + + this.updated = this.updated & ~UPDATED_MARKS; + this.storedMarks = null; + } + }, { + key: "setTime", + value: function setTime(time) { + this.time = time; + return this; + } + }, { + key: "replaceSelection", + value: function replaceSelection(slice) { + this.selection.replace(this, slice); + return this; + } + }, { + key: "replaceSelectionWith", + value: function replaceSelectionWith(node) { + var inheritMarks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var selection = this.selection; + if (inheritMarks) node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : selection.$from.marksAcross(selection.$to) || prosemirrorModel.Mark.none)); + selection.replaceWith(this, node); + return this; + } + }, { + key: "deleteSelection", + value: function deleteSelection() { + this.selection.replace(this); + return this; + } + }, { + key: "insertText", + value: function insertText(text, from, to) { + var schema = this.doc.type.schema; + + if (from == null) { + if (!text) return this.deleteSelection(); + return this.replaceSelectionWith(schema.text(text), true); + } else { + if (to == null) to = from; + to = to == null ? from : to; + if (!text) return this.deleteRange(from, to); + var marks = this.storedMarks; + + if (!marks) { + var $from = this.doc.resolve(from); + marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to)); + } + + this.replaceRangeWith(from, to, schema.text(text, marks)); + if (!this.selection.empty) this.setSelection(Selection.near(this.selection.$to)); + return this; + } + } + }, { + key: "setMeta", + value: function setMeta(key, value) { + this.meta[typeof key == "string" ? key : key.key] = value; + return this; + } + }, { + key: "getMeta", + value: function getMeta(key) { + return this.meta[typeof key == "string" ? key : key.key]; + } + }, { + key: "isGeneric", + get: function get() { + for (var _ in this.meta) { + return false; + } + + return true; + } + }, { + key: "scrollIntoView", + value: function scrollIntoView() { + this.updated |= UPDATED_SCROLL; + return this; + } + }, { + key: "scrolledIntoView", + get: function get() { + return (this.updated & UPDATED_SCROLL) > 0; + } + }]); + + return Transaction; +}(prosemirrorTransform.Transform); + +function bind(f, self) { + return !self || !f ? f : f.bind(self); +} + +var FieldDesc = _createClass(function FieldDesc(name, desc, self) { + _classCallCheck(this, FieldDesc); + + this.name = name; + this.init = bind(desc.init, self); + this.apply = bind(desc.apply, self); +}); + +var baseFields = [new FieldDesc("doc", { + init: function init(config) { + return config.doc || config.schema.topNodeType.createAndFill(); + }, + apply: function apply(tr) { + return tr.doc; + } +}), new FieldDesc("selection", { + init: function init(config, instance) { + return config.selection || Selection.atStart(instance.doc); + }, + apply: function apply(tr) { + return tr.selection; + } +}), new FieldDesc("storedMarks", { + init: function init(config) { + return config.storedMarks || null; + }, + apply: function apply(tr, _marks, _old, state) { + return state.selection.$cursor ? tr.storedMarks : null; + } +}), new FieldDesc("scrollToSelection", { + init: function init() { + return 0; + }, + apply: function apply(tr, prev) { + return tr.scrolledIntoView ? prev + 1 : prev; + } +})]; + +var Configuration = _createClass(function Configuration(schema, plugins) { + var _this3 = this; + + _classCallCheck(this, Configuration); + + this.schema = schema; + this.plugins = []; + this.pluginsByKey = Object.create(null); + this.fields = baseFields.slice(); + if (plugins) plugins.forEach(function (plugin) { + if (_this3.pluginsByKey[plugin.key]) throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")"); + + _this3.plugins.push(plugin); + + _this3.pluginsByKey[plugin.key] = plugin; + if (plugin.spec.state) _this3.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin)); + }); +}); + +var EditorState = function () { + function EditorState(config) { + _classCallCheck(this, EditorState); + + this.config = config; + } + + _createClass(EditorState, [{ + key: "schema", + get: function get() { + return this.config.schema; + } + }, { + key: "plugins", + get: function get() { + return this.config.plugins; + } + }, { + key: "apply", + value: function apply(tr) { + return this.applyTransaction(tr).state; + } + }, { + key: "filterTransaction", + value: function filterTransaction(tr) { + var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; + + for (var i = 0; i < this.config.plugins.length; i++) { + if (i != ignore) { + var plugin = this.config.plugins[i]; + if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this)) return false; + } + } + + return true; + } + }, { + key: "applyTransaction", + value: function applyTransaction(rootTr) { + if (!this.filterTransaction(rootTr)) return { + state: this, + transactions: [] + }; + var trs = [rootTr], + newState = this.applyInner(rootTr), + seen = null; + + for (;;) { + var haveNew = false; + + for (var i = 0; i < this.config.plugins.length; i++) { + var plugin = this.config.plugins[i]; + + if (plugin.spec.appendTransaction) { + var n = seen ? seen[i].n : 0, + oldState = seen ? seen[i].state : this; + var tr = n < trs.length && plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState); + + if (tr && newState.filterTransaction(tr, i)) { + tr.setMeta("appendedTransaction", rootTr); + + if (!seen) { + seen = []; + + for (var j = 0; j < this.config.plugins.length; j++) { + seen.push(j < i ? { + state: newState, + n: trs.length + } : { + state: this, + n: 0 + }); + } + } + + trs.push(tr); + newState = newState.applyInner(tr); + haveNew = true; + } + + if (seen) seen[i] = { + state: newState, + n: trs.length + }; + } + } + + if (!haveNew) return { + state: newState, + transactions: trs + }; + } + } + }, { + key: "applyInner", + value: function applyInner(tr) { + if (!tr.before.eq(this.doc)) throw new RangeError("Applying a mismatched transaction"); + var newInstance = new EditorState(this.config), + fields = this.config.fields; + + for (var i = 0; i < fields.length; i++) { + var field = fields[i]; + newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance); + } + + return newInstance; + } + }, { + key: "tr", + get: function get() { + return new Transaction(this); + } + }, { + key: "reconfigure", + value: function reconfigure(config) { + var $config = new Configuration(this.schema, config.plugins); + var fields = $config.fields, + instance = new EditorState($config); + + for (var i = 0; i < fields.length; i++) { + var name = fields[i].name; + instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance); + } + + return instance; + } + }, { + key: "toJSON", + value: function toJSON(pluginFields) { + var result = { + doc: this.doc.toJSON(), + selection: this.selection.toJSON() + }; + if (this.storedMarks) result.storedMarks = this.storedMarks.map(function (m) { + return m.toJSON(); + }); + if (pluginFields && _typeof(pluginFields) == 'object') for (var prop in pluginFields) { + if (prop == "doc" || prop == "selection") throw new RangeError("The JSON fields `doc` and `selection` are reserved"); + var plugin = pluginFields[prop], + state = plugin.spec.state; + if (state && state.toJSON) result[prop] = state.toJSON.call(plugin, this[plugin.key]); + } + return result; + } + }], [{ + key: "create", + value: function create(config) { + var $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins); + var instance = new EditorState($config); + + for (var i = 0; i < $config.fields.length; i++) { + instance[$config.fields[i].name] = $config.fields[i].init(config, instance); + } + + return instance; + } + }, { + key: "fromJSON", + value: function fromJSON(config, json, pluginFields) { + if (!json) throw new RangeError("Invalid input for EditorState.fromJSON"); + if (!config.schema) throw new RangeError("Required config field 'schema' missing"); + var $config = new Configuration(config.schema, config.plugins); + var instance = new EditorState($config); + $config.fields.forEach(function (field) { + if (field.name == "doc") { + instance.doc = prosemirrorModel.Node.fromJSON(config.schema, json.doc); + } else if (field.name == "selection") { + instance.selection = Selection.fromJSON(instance.doc, json.selection); + } else if (field.name == "storedMarks") { + if (json.storedMarks) instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON); + } else { + if (pluginFields) for (var prop in pluginFields) { + var plugin = pluginFields[prop], + state = plugin.spec.state; + + if (plugin.key == field.name && state && state.fromJSON && Object.prototype.hasOwnProperty.call(json, prop)) { + instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance); + return; + } + } + instance[field.name] = field.init(config, instance); + } + }); + return instance; + } + }]); + + return EditorState; +}(); + +function bindProps(obj, self, target) { + for (var prop in obj) { + var val = obj[prop]; + if (val instanceof Function) val = val.bind(self);else if (prop == "handleDOMEvents") val = bindProps(val, self, {}); + target[prop] = val; + } + + return target; +} + +var Plugin = function () { + function Plugin(spec) { + _classCallCheck(this, Plugin); + + this.spec = spec; + this.props = {}; + if (spec.props) bindProps(spec.props, this, this.props); + this.key = spec.key ? spec.key.key : createKey("plugin"); + } + + _createClass(Plugin, [{ + key: "getState", + value: function getState(state) { + return state[this.key]; + } + }]); + + return Plugin; +}(); + +var keys = Object.create(null); + +function createKey(name) { + if (name in keys) return name + "$" + ++keys[name]; + keys[name] = 0; + return name + "$"; +} + +var PluginKey = function () { + function PluginKey() { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "key"; + + _classCallCheck(this, PluginKey); + + this.key = createKey(name); + } + + _createClass(PluginKey, [{ + key: "get", + value: function get(state) { + return state.config.pluginsByKey[this.key]; + } + }, { + key: "getState", + value: function getState(state) { + return state[this.key]; + } + }]); + + return PluginKey; +}(); + +exports.AllSelection = AllSelection; +exports.EditorState = EditorState; +exports.NodeSelection = NodeSelection; +exports.Plugin = Plugin; +exports.PluginKey = PluginKey; +exports.Selection = Selection; +exports.SelectionRange = SelectionRange; +exports.TextSelection = TextSelection; +exports.Transaction = Transaction; + +}); +define("prosemirror-transform",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } +function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorModel = require('prosemirror-model'); +var lower16 = 0xffff; +var factor16 = Math.pow(2, 16); +function makeRecover(index, offset) { + return index + offset * factor16; +} +function recoverIndex(value) { + return value & lower16; +} +function recoverOffset(value) { + return (value - (value & lower16)) / factor16; +} +var DEL_BEFORE = 1, + DEL_AFTER = 2, + DEL_ACROSS = 4, + DEL_SIDE = 8; +var MapResult = function () { + function MapResult(pos, delInfo, recover) { + _classCallCheck(this, MapResult); + this.pos = pos; + this.delInfo = delInfo; + this.recover = recover; + } + _createClass(MapResult, [{ + key: "deleted", + get: function get() { + return (this.delInfo & DEL_SIDE) > 0; + } + }, { + key: "deletedBefore", + get: function get() { + return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; + } + }, { + key: "deletedAfter", + get: function get() { + return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; + } + }, { + key: "deletedAcross", + get: function get() { + return (this.delInfo & DEL_ACROSS) > 0; + } + }]); + return MapResult; +}(); +var StepMap = function () { + function StepMap(ranges) { + var inverted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + _classCallCheck(this, StepMap); + this.ranges = ranges; + this.inverted = inverted; + if (!ranges.length && StepMap.empty) return StepMap.empty; + } + _createClass(StepMap, [{ + key: "recover", + value: function recover(value) { + var diff = 0, + index = recoverIndex(value); + if (!this.inverted) for (var i = 0; i < index; i++) diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1]; + return this.ranges[index * 3] + diff + recoverOffset(value); + } + }, { + key: "mapResult", + value: function mapResult(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, false); + } + }, { + key: "map", + value: function map(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, true); + } + }, { + key: "_map", + value: function _map(pos, assoc, simple) { + var diff = 0, + oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) break; + var oldSize = this.ranges[i + oldIndex], + newSize = this.ranges[i + newIndex], + end = start + oldSize; + if (pos <= end) { + var side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc; + var result = start + diff + (side < 0 ? 0 : newSize); + if (simple) return result; + var recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start); + var del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS; + if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE; + return new MapResult(result, del, recover); + } + diff += newSize - oldSize; + } + return simple ? pos + diff : new MapResult(pos + diff, 0, null); + } + }, { + key: "touches", + value: function touches(pos, recover) { + var diff = 0, + index = recoverIndex(recover); + var oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) break; + var oldSize = this.ranges[i + oldIndex], + end = start + oldSize; + if (pos <= end && i == index * 3) return true; + diff += this.ranges[i + newIndex] - oldSize; + } + return false; + } + }, { + key: "forEach", + value: function forEach(f) { + var oldIndex = this.inverted ? 2 : 1, + newIndex = this.inverted ? 1 : 2; + for (var i = 0, diff = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i], + oldStart = start - (this.inverted ? diff : 0), + newStart = start + (this.inverted ? 0 : diff); + var oldSize = this.ranges[i + oldIndex], + newSize = this.ranges[i + newIndex]; + f(oldStart, oldStart + oldSize, newStart, newStart + newSize); + diff += newSize - oldSize; + } + } + }, { + key: "invert", + value: function invert() { + return new StepMap(this.ranges, !this.inverted); + } + }, { + key: "toString", + value: function toString() { + return (this.inverted ? "-" : "") + JSON.stringify(this.ranges); + } + }], [{ + key: "offset", + value: function offset(n) { + return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]); + } + }]); + return StepMap; +}(); +StepMap.empty = new StepMap([]); +var Mapping = function () { + function Mapping() { + var maps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var mirror = arguments.length > 1 ? arguments[1] : undefined; + var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : maps.length; + _classCallCheck(this, Mapping); + this.maps = maps; + this.mirror = mirror; + this.from = from; + this.to = to; + } + _createClass(Mapping, [{ + key: "slice", + value: function slice() { + var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.maps.length; + return new Mapping(this.maps, this.mirror, from, to); + } + }, { + key: "copy", + value: function copy() { + return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to); + } + }, { + key: "appendMap", + value: function appendMap(map, mirrors) { + this.to = this.maps.push(map); + if (mirrors != null) this.setMirror(this.maps.length - 1, mirrors); + } + }, { + key: "appendMapping", + value: function appendMapping(mapping) { + for (var i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : undefined); + } + } + }, { + key: "getMirror", + value: function getMirror(n) { + if (this.mirror) for (var i = 0; i < this.mirror.length; i++) if (this.mirror[i] == n) return this.mirror[i + (i % 2 ? -1 : 1)]; + } + }, { + key: "setMirror", + value: function setMirror(n, m) { + if (!this.mirror) this.mirror = []; + this.mirror.push(n, m); + } + }, { + key: "appendMappingInverted", + value: function appendMappingInverted(mapping) { + for (var i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined); + } + } + }, { + key: "invert", + value: function invert() { + var inverse = new Mapping(); + inverse.appendMappingInverted(this); + return inverse; + } + }, { + key: "map", + value: function map(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + if (this.mirror) return this._map(pos, assoc, true); + for (var i = this.from; i < this.to; i++) pos = this.maps[i].map(pos, assoc); + return pos; + } + }, { + key: "mapResult", + value: function mapResult(pos) { + var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return this._map(pos, assoc, false); + } + }, { + key: "_map", + value: function _map(pos, assoc, simple) { + var delInfo = 0; + for (var i = this.from; i < this.to; i++) { + var map = this.maps[i], + result = map.mapResult(pos, assoc); + if (result.recover != null) { + var corr = this.getMirror(i); + if (corr != null && corr > i && corr < this.to) { + i = corr; + pos = this.maps[corr].recover(result.recover); + continue; + } + } + delInfo |= result.delInfo; + pos = result.pos; + } + return simple ? pos : new MapResult(pos, delInfo, null); + } + }]); + return Mapping; +}(); +var stepsByID = Object.create(null); +var Step = function () { + function Step() { + _classCallCheck(this, Step); + } + _createClass(Step, [{ + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "merge", + value: function merge(other) { + return null; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (!json || !json.stepType) throw new RangeError("Invalid input for Step.fromJSON"); + var type = stepsByID[json.stepType]; + if (!type) throw new RangeError("No step type ".concat(json.stepType, " defined")); + return type.fromJSON(schema, json); + } + }, { + key: "jsonID", + value: function jsonID(id, stepClass) { + if (id in stepsByID) throw new RangeError("Duplicate use of step JSON ID " + id); + stepsByID[id] = stepClass; + stepClass.prototype.jsonID = id; + return stepClass; + } + }]); + return Step; +}(); +var StepResult = function () { + function StepResult(doc, failed) { + _classCallCheck(this, StepResult); + this.doc = doc; + this.failed = failed; + } + _createClass(StepResult, null, [{ + key: "ok", + value: function ok(doc) { + return new StepResult(doc, null); + } + }, { + key: "fail", + value: function fail(message) { + return new StepResult(null, message); + } + }, { + key: "fromReplace", + value: function fromReplace(doc, from, to, slice) { + try { + return StepResult.ok(doc.replace(from, to, slice)); + } catch (e) { + if (e instanceof prosemirrorModel.ReplaceError) return StepResult.fail(e.message); + throw e; + } + } + }]); + return StepResult; +}(); +function mapFragment(fragment, f, parent) { + var mapped = []; + for (var i = 0; i < fragment.childCount; i++) { + var child = fragment.child(i); + if (child.content.size) child = child.copy(mapFragment(child.content, f, child)); + if (child.isInline) child = f(child, parent, i); + mapped.push(child); + } + return prosemirrorModel.Fragment.fromArray(mapped); +} +var AddMarkStep = function (_Step) { + _inherits(AddMarkStep, _Step); + var _super = _createSuper(AddMarkStep); + function AddMarkStep(from, to, mark) { + var _this; + _classCallCheck(this, AddMarkStep); + _this = _super.call(this); + _this.from = from; + _this.to = to; + _this.mark = mark; + return _this; + } + _createClass(AddMarkStep, [{ + key: "apply", + value: function apply(doc) { + var _this2 = this; + var oldSlice = doc.slice(this.from, this.to), + $from = doc.resolve(this.from); + var parent = $from.node($from.sharedDepth(this.to)); + var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node, parent) { + if (!node.isAtom || !parent.type.allowsMarkType(_this2.mark.type)) return node; + return node.mark(_this2.mark.addToSet(node.marks)); + }, parent), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice); + } + }, { + key: "invert", + value: function invert() { + return new RemoveMarkStep(this.from, this.to, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) return null; + return new AddMarkStep(from.pos, to.pos, this.mark); + } + }, { + key: "merge", + value: function merge(other) { + if (other instanceof AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); + return null; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "addMark", + mark: this.mark.toJSON(), + from: this.from, + to: this.to + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for AddMarkStep.fromJSON"); + return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); + } + }]); + return AddMarkStep; +}(Step); +Step.jsonID("addMark", AddMarkStep); +var RemoveMarkStep = function (_Step2) { + _inherits(RemoveMarkStep, _Step2); + var _super2 = _createSuper(RemoveMarkStep); + function RemoveMarkStep(from, to, mark) { + var _this3; + _classCallCheck(this, RemoveMarkStep); + _this3 = _super2.call(this); + _this3.from = from; + _this3.to = to; + _this3.mark = mark; + return _this3; + } + _createClass(RemoveMarkStep, [{ + key: "apply", + value: function apply(doc) { + var _this4 = this; + var oldSlice = doc.slice(this.from, this.to); + var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node) { + return node.mark(_this4.mark.removeFromSet(node.marks)); + }, doc), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice); + } + }, { + key: "invert", + value: function invert() { + return new AddMarkStep(this.from, this.to, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) return null; + return new RemoveMarkStep(from.pos, to.pos, this.mark); + } + }, { + key: "merge", + value: function merge(other) { + if (other instanceof RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); + return null; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "removeMark", + mark: this.mark.toJSON(), + from: this.from, + to: this.to + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for RemoveMarkStep.fromJSON"); + return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); + } + }]); + return RemoveMarkStep; +}(Step); +Step.jsonID("removeMark", RemoveMarkStep); +var AddNodeMarkStep = function (_Step3) { + _inherits(AddNodeMarkStep, _Step3); + var _super3 = _createSuper(AddNodeMarkStep); + function AddNodeMarkStep(pos, mark) { + var _this5; + _classCallCheck(this, AddNodeMarkStep); + _this5 = _super3.call(this); + _this5.pos = pos; + _this5.mark = mark; + return _this5; + } + _createClass(AddNodeMarkStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at mark step's position"); + var updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks)); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "invert", + value: function invert(doc) { + var node = doc.nodeAt(this.pos); + if (node) { + var newSet = this.mark.addToSet(node.marks); + if (newSet.length == node.marks.length) { + for (var i = 0; i < node.marks.length; i++) if (!node.marks[i].isInSet(newSet)) return new AddNodeMarkStep(this.pos, node.marks[i]); + return new AddNodeMarkStep(this.pos, this.mark); + } + } + return new RemoveNodeMarkStep(this.pos, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "addNodeMark", + pos: this.pos, + mark: this.mark.toJSON() + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON"); + return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); + } + }]); + return AddNodeMarkStep; +}(Step); +Step.jsonID("addNodeMark", AddNodeMarkStep); +var RemoveNodeMarkStep = function (_Step4) { + _inherits(RemoveNodeMarkStep, _Step4); + var _super4 = _createSuper(RemoveNodeMarkStep); + function RemoveNodeMarkStep(pos, mark) { + var _this6; + _classCallCheck(this, RemoveNodeMarkStep); + _this6 = _super4.call(this); + _this6.pos = pos; + _this6.mark = mark; + return _this6; + } + _createClass(RemoveNodeMarkStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at mark step's position"); + var updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks)); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "invert", + value: function invert(doc) { + var node = doc.nodeAt(this.pos); + if (!node || !this.mark.isInSet(node.marks)) return this; + return new AddNodeMarkStep(this.pos, this.mark); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "removeNodeMark", + pos: this.pos, + mark: this.mark.toJSON() + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number") throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON"); + return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); + } + }]); + return RemoveNodeMarkStep; +}(Step); +Step.jsonID("removeNodeMark", RemoveNodeMarkStep); +var ReplaceStep = function (_Step5) { + _inherits(ReplaceStep, _Step5); + var _super5 = _createSuper(ReplaceStep); + function ReplaceStep(from, to, slice) { + var _this7; + var structure = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + _classCallCheck(this, ReplaceStep); + _this7 = _super5.call(this); + _this7.from = from; + _this7.to = to; + _this7.slice = slice; + _this7.structure = structure; + return _this7; + } + _createClass(ReplaceStep, [{ + key: "apply", + value: function apply(doc) { + if (this.structure && contentBetween(doc, this.from, this.to)) return StepResult.fail("Structure replace would overwrite content"); + return StepResult.fromReplace(doc, this.from, this.to, this.slice); + } + }, { + key: "getMap", + value: function getMap() { + return new StepMap([this.from, this.to - this.from, this.slice.size]); + } + }, { + key: "invert", + value: function invert(doc) { + return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to)); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + if (from.deletedAcross && to.deletedAcross) return null; + return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice); + } + }, { + key: "merge", + value: function merge(other) { + if (!(other instanceof ReplaceStep) || other.structure || this.structure) return null; + if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) { + var slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd); + return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure); + } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) { + var _slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd); + return new ReplaceStep(other.from, this.to, _slice, this.structure); + } else { + return null; + } + } + }, { + key: "toJSON", + value: function toJSON() { + var json = { + stepType: "replace", + from: this.from, + to: this.to + }; + if (this.slice.size) json.slice = this.slice.toJSON(); + if (this.structure) json.structure = true; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for ReplaceStep.fromJSON"); + return new ReplaceStep(json.from, json.to, prosemirrorModel.Slice.fromJSON(schema, json.slice), !!json.structure); + } + }]); + return ReplaceStep; +}(Step); +Step.jsonID("replace", ReplaceStep); +var ReplaceAroundStep = function (_Step6) { + _inherits(ReplaceAroundStep, _Step6); + var _super6 = _createSuper(ReplaceAroundStep); + function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert) { + var _this8; + var structure = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false; + _classCallCheck(this, ReplaceAroundStep); + _this8 = _super6.call(this); + _this8.from = from; + _this8.to = to; + _this8.gapFrom = gapFrom; + _this8.gapTo = gapTo; + _this8.slice = slice; + _this8.insert = insert; + _this8.structure = structure; + return _this8; + } + _createClass(ReplaceAroundStep, [{ + key: "apply", + value: function apply(doc) { + if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to))) return StepResult.fail("Structure gap-replace would overwrite content"); + var gap = doc.slice(this.gapFrom, this.gapTo); + if (gap.openStart || gap.openEnd) return StepResult.fail("Gap is not a flat range"); + var inserted = this.slice.insertAt(this.insert, gap.content); + if (!inserted) return StepResult.fail("Content does not fit in gap"); + return StepResult.fromReplace(doc, this.from, this.to, inserted); + } + }, { + key: "getMap", + value: function getMap() { + return new StepMap([this.from, this.gapFrom - this.from, this.insert, this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]); + } + }, { + key: "invert", + value: function invert(doc) { + var gap = this.gapTo - this.gapFrom; + return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure); + } + }, { + key: "map", + value: function map(mapping) { + var from = mapping.mapResult(this.from, 1), + to = mapping.mapResult(this.to, -1); + var gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1); + var gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1); + if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos) return null; + return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure); + } + }, { + key: "toJSON", + value: function toJSON() { + var json = { + stepType: "replaceAround", + from: this.from, + to: this.to, + gapFrom: this.gapFrom, + gapTo: this.gapTo, + insert: this.insert + }; + if (this.slice.size) json.slice = this.slice.toJSON(); + if (this.structure) json.structure = true; + return json; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON"); + return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, prosemirrorModel.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure); + } + }]); + return ReplaceAroundStep; +}(Step); +Step.jsonID("replaceAround", ReplaceAroundStep); +function contentBetween(doc, from, to) { + var $from = doc.resolve(from), + dist = to - from, + depth = $from.depth; + while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) { + depth--; + dist--; + } + if (dist > 0) { + var next = $from.node(depth).maybeChild($from.indexAfter(depth)); + while (dist > 0) { + if (!next || next.isLeaf) return true; + next = next.firstChild; + dist--; + } + } + return false; +} +function _addMark(tr, from, to, mark) { + var removed = [], + added = []; + var removing, adding; + tr.doc.nodesBetween(from, to, function (node, pos, parent) { + if (!node.isInline) return; + var marks = node.marks; + if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) { + var start = Math.max(pos, from), + end = Math.min(pos + node.nodeSize, to); + var newSet = mark.addToSet(marks); + for (var i = 0; i < marks.length; i++) { + if (!marks[i].isInSet(newSet)) { + if (removing && removing.to == start && removing.mark.eq(marks[i])) removing.to = end;else removed.push(removing = new RemoveMarkStep(start, end, marks[i])); + } + } + if (adding && adding.to == start) adding.to = end;else added.push(adding = new AddMarkStep(start, end, mark)); + } + }); + removed.forEach(function (s) { + return tr.step(s); + }); + added.forEach(function (s) { + return tr.step(s); + }); +} +function _removeMark(tr, from, to, mark) { + var matched = [], + step = 0; + tr.doc.nodesBetween(from, to, function (node, pos) { + if (!node.isInline) return; + step++; + var toRemove = null; + if (mark instanceof prosemirrorModel.MarkType) { + var set = node.marks, + found; + while (found = mark.isInSet(set)) { + (toRemove || (toRemove = [])).push(found); + set = found.removeFromSet(set); + } + } else if (mark) { + if (mark.isInSet(node.marks)) toRemove = [mark]; + } else { + toRemove = node.marks; + } + if (toRemove && toRemove.length) { + var end = Math.min(pos + node.nodeSize, to); + for (var i = 0; i < toRemove.length; i++) { + var style = toRemove[i], + _found = void 0; + for (var j = 0; j < matched.length; j++) { + var m = matched[j]; + if (m.step == step - 1 && style.eq(matched[j].style)) _found = m; + } + if (_found) { + _found.to = end; + _found.step = step; + } else { + matched.push({ + style: style, + from: Math.max(pos, from), + to: end, + step: step + }); + } + } + } + }); + matched.forEach(function (m) { + return tr.step(new RemoveMarkStep(m.from, m.to, m.style)); + }); +} +function _clearIncompatible(tr, pos, parentType) { + var match = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : parentType.contentMatch; + var clearNewlines = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; + var node = tr.doc.nodeAt(pos); + var replSteps = [], + cur = pos + 1; + for (var i = 0; i < node.childCount; i++) { + var child = node.child(i), + end = cur + child.nodeSize; + var allowed = match.matchType(child.type); + if (!allowed) { + replSteps.push(new ReplaceStep(cur, end, prosemirrorModel.Slice.empty)); + } else { + match = allowed; + for (var j = 0; j < child.marks.length; j++) if (!parentType.allowsMarkType(child.marks[j].type)) tr.step(new RemoveMarkStep(cur, end, child.marks[j])); + if (clearNewlines && child.isText && parentType.whitespace != "pre") { + var m = void 0, + newline = /\r?\n|\r/g, + slice = void 0; + while (m = newline.exec(child.text)) { + if (!slice) slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0); + replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice)); + } + } + } + cur = end; + } + if (!match.validEnd) { + var fill = match.fillBefore(prosemirrorModel.Fragment.empty, true); + tr.replace(cur, cur, new prosemirrorModel.Slice(fill, 0, 0)); + } + for (var _i = replSteps.length - 1; _i >= 0; _i--) tr.step(replSteps[_i]); +} +function canCut(node, start, end) { + return (start == 0 || node.canReplace(start, node.childCount)) && (end == node.childCount || node.canReplace(0, end)); +} +function liftTarget(range) { + var parent = range.parent; + var content = parent.content.cutByIndex(range.startIndex, range.endIndex); + for (var depth = range.depth;; --depth) { + var node = range.$from.node(depth); + var index = range.$from.index(depth), + endIndex = range.$to.indexAfter(depth); + if (depth < range.depth && node.canReplace(index, endIndex, content)) return depth; + if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break; + } + return null; +} +function _lift(tr, range, target) { + var $from = range.$from, + $to = range.$to, + depth = range.depth; + var gapStart = $from.before(depth + 1), + gapEnd = $to.after(depth + 1); + var start = gapStart, + end = gapEnd; + var before = prosemirrorModel.Fragment.empty, + openStart = 0; + for (var d = depth, splitting = false; d > target; d--) if (splitting || $from.index(d) > 0) { + splitting = true; + before = prosemirrorModel.Fragment.from($from.node(d).copy(before)); + openStart++; + } else { + start--; + } + var after = prosemirrorModel.Fragment.empty, + openEnd = 0; + for (var _d = depth, _splitting = false; _d > target; _d--) if (_splitting || $to.after(_d + 1) < $to.end(_d)) { + _splitting = true; + after = prosemirrorModel.Fragment.from($to.node(_d).copy(after)); + openEnd++; + } else { + end++; + } + tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new prosemirrorModel.Slice(before.append(after), openStart, openEnd), before.size - openStart, true)); +} +function findWrapping(range, nodeType) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var innerRange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : range; + var around = findWrappingOutside(range, nodeType); + var inner = around && findWrappingInside(innerRange, nodeType); + if (!inner) return null; + return around.map(withAttrs).concat({ + type: nodeType, + attrs: attrs + }).concat(inner.map(withAttrs)); +} +function withAttrs(type) { + return { + type: type, + attrs: null + }; +} +function findWrappingOutside(range, type) { + var parent = range.parent, + startIndex = range.startIndex, + endIndex = range.endIndex; + var around = parent.contentMatchAt(startIndex).findWrapping(type); + if (!around) return null; + var outer = around.length ? around[0] : type; + return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null; +} +function findWrappingInside(range, type) { + var parent = range.parent, + startIndex = range.startIndex, + endIndex = range.endIndex; + var inner = parent.child(startIndex); + var inside = type.contentMatch.findWrapping(inner.type); + if (!inside) return null; + var lastType = inside.length ? inside[inside.length - 1] : type; + var innerMatch = lastType.contentMatch; + for (var i = startIndex; innerMatch && i < endIndex; i++) innerMatch = innerMatch.matchType(parent.child(i).type); + if (!innerMatch || !innerMatch.validEnd) return null; + return inside; +} +function _wrap2(tr, range, wrappers) { + var content = prosemirrorModel.Fragment.empty; + for (var i = wrappers.length - 1; i >= 0; i--) { + if (content.size) { + var match = wrappers[i].type.contentMatch.matchFragment(content); + if (!match || !match.validEnd) throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper"); + } + content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); + } + var start = range.start, + end = range.end; + tr.step(new ReplaceAroundStep(start, end, start, end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true)); +} +function _setBlockType(tr, from, to, type, attrs) { + if (!type.isTextblock) throw new RangeError("Type given to setBlockType should be a textblock"); + var mapFrom = tr.steps.length; + tr.doc.nodesBetween(from, to, function (node, pos) { + var attrsHere = typeof attrs == "function" ? attrs(node) : attrs; + if (node.isTextblock && !node.hasMarkup(type, attrsHere) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) { + var convertNewlines = null; + if (type.schema.linebreakReplacement) { + var pre = type.whitespace == "pre", + supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement); + if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true; + } + if (convertNewlines === false) replaceLinebreaks(tr, node, pos, mapFrom); + _clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null); + var mapping = tr.mapping.slice(mapFrom); + var startM = mapping.map(pos, 1), + endM = mapping.map(pos + node.nodeSize, 1); + tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true)); + if (convertNewlines === true) replaceNewlines(tr, node, pos, mapFrom); + return false; + } + }); +} +function replaceNewlines(tr, node, pos, mapFrom) { + node.forEach(function (child, offset) { + if (child.isText) { + var m, + newline = /\r?\n|\r/g; + while (m = newline.exec(child.text)) { + var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index); + tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create()); + } + } + }); +} +function replaceLinebreaks(tr, node, pos, mapFrom) { + node.forEach(function (child, offset) { + if (child.type == child.type.schema.linebreakReplacement) { + var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset); + tr.replaceWith(start, start + 1, node.type.schema.text("\n")); + } + }); +} +function canChangeType(doc, pos, type) { + var $pos = doc.resolve(pos), + index = $pos.index(); + return $pos.parent.canReplaceWith(index, index + 1, type); +} +function _setNodeMarkup(tr, pos, type, attrs, marks) { + var node = tr.doc.nodeAt(pos); + if (!node) throw new RangeError("No node at given position"); + if (!type) type = node.type; + var newNode = type.create(attrs, null, marks || node.marks); + if (node.isLeaf) return tr.replaceWith(pos, pos + node.nodeSize, newNode); + if (!type.validContent(node.content)) throw new RangeError("Invalid content for node type " + type.name); + tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(newNode), 0, 0), 1, true)); +} +function canSplit(doc, pos) { + var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; + var typesAfter = arguments.length > 3 ? arguments[3] : undefined; + var $pos = doc.resolve(pos), + base = $pos.depth - depth; + var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; + if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; + for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { + var node = $pos.node(d), + _index = $pos.index(d); + if (node.type.spec.isolating) return false; + var rest = node.content.cutByIndex(_index, node.childCount); + var overrideChild = typesAfter && typesAfter[i + 1]; + if (overrideChild) rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs)); + var after = typesAfter && typesAfter[i] || node; + if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false; + } + var index = $pos.indexAfter(base); + var baseType = typesAfter && typesAfter[0]; + return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); +} +function _split(tr, pos) { + var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; + var typesAfter = arguments.length > 3 ? arguments[3] : undefined; + var $pos = tr.doc.resolve(pos), + before = prosemirrorModel.Fragment.empty, + after = prosemirrorModel.Fragment.empty; + for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) { + before = prosemirrorModel.Fragment.from($pos.node(d).copy(before)); + var typeAfter = typesAfter && typesAfter[i]; + after = prosemirrorModel.Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after)); + } + tr.step(new ReplaceStep(pos, pos, new prosemirrorModel.Slice(before.append(after), depth, depth), true)); +} +function canJoin(doc, pos) { + var $pos = doc.resolve(pos), + index = $pos.index(); + return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1); +} +function canAppendWithSubstitutedLinebreaks(a, b) { + if (!b.content.size) a.type.compatibleContent(b.type); + var match = a.contentMatchAt(a.childCount); + var linebreakReplacement = a.type.schema.linebreakReplacement; + for (var i = 0; i < b.childCount; i++) { + var child = b.child(i); + var type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type; + match = match.matchType(type); + if (!match) return false; + if (!a.type.allowsMarks(child.marks)) return false; + } + return match.validEnd; +} +function joinable(a, b) { + return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b)); +} +function joinPoint(doc, pos) { + var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; + var $pos = doc.resolve(pos); + for (var d = $pos.depth;; d--) { + var before = void 0, + after = void 0, + index = $pos.index(d); + if (d == $pos.depth) { + before = $pos.nodeBefore; + after = $pos.nodeAfter; + } else if (dir > 0) { + before = $pos.node(d + 1); + index++; + after = $pos.node(d).maybeChild(index); + } else { + before = $pos.node(d).maybeChild(index - 1); + after = $pos.node(d + 1); + } + if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1)) return pos; + if (d == 0) break; + pos = dir < 0 ? $pos.before(d) : $pos.after(d); + } +} +function _join(tr, pos, depth) { + var convertNewlines = null; + var linebreakReplacement = tr.doc.type.schema.linebreakReplacement; + var $before = tr.doc.resolve(pos - depth), + beforeType = $before.node().type; + if (linebreakReplacement && beforeType.inlineContent) { + var pre = beforeType.whitespace == "pre"; + var supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement); + if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true; + } + var mapFrom = tr.steps.length; + if (convertNewlines === false) { + var $after = tr.doc.resolve(pos + depth); + replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom); + } + if (beforeType.inlineContent) _clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null); + var mapping = tr.mapping.slice(mapFrom), + start = mapping.map(pos - depth); + tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), prosemirrorModel.Slice.empty, true)); + if (convertNewlines === true) { + var $full = tr.doc.resolve(start); + replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length); + } + return tr; +} +function insertPoint(doc, pos, nodeType) { + var $pos = doc.resolve(pos); + if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) return pos; + if ($pos.parentOffset == 0) for (var d = $pos.depth - 1; d >= 0; d--) { + var index = $pos.index(d); + if ($pos.node(d).canReplaceWith(index, index, nodeType)) return $pos.before(d + 1); + if (index > 0) return null; + } + if ($pos.parentOffset == $pos.parent.content.size) for (var _d2 = $pos.depth - 1; _d2 >= 0; _d2--) { + var _index2 = $pos.indexAfter(_d2); + if ($pos.node(_d2).canReplaceWith(_index2, _index2, nodeType)) return $pos.after(_d2 + 1); + if (_index2 < $pos.node(_d2).childCount) return null; + } + return null; +} +function dropPoint(doc, pos, slice) { + var $pos = doc.resolve(pos); + if (!slice.content.size) return pos; + var content = slice.content; + for (var i = 0; i < slice.openStart; i++) content = content.firstChild.content; + for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) { + for (var d = $pos.depth; d >= 0; d--) { + var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1; + var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0); + var parent = $pos.node(d), + fits = false; + if (pass == 1) { + fits = parent.canReplace(insertPos, insertPos, content); + } else { + var wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type); + fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]); + } + if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1); + } + } + return null; +} +function replaceStep(doc, from) { + var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : from; + var slice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prosemirrorModel.Slice.empty; + if (from == to && !slice.size) return null; + var $from = doc.resolve(from), + $to = doc.resolve(to); + if (fitsTrivially($from, $to, slice)) return new ReplaceStep(from, to, slice); + return new Fitter($from, $to, slice).fit(); +} +function fitsTrivially($from, $to, slice) { + return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content); +} +var Fitter = function () { + function Fitter($from, $to, unplaced) { + _classCallCheck(this, Fitter); + this.$from = $from; + this.$to = $to; + this.unplaced = unplaced; + this.frontier = []; + this.placed = prosemirrorModel.Fragment.empty; + for (var i = 0; i <= $from.depth; i++) { + var node = $from.node(i); + this.frontier.push({ + type: node.type, + match: node.contentMatchAt($from.indexAfter(i)) + }); + } + for (var _i2 = $from.depth; _i2 > 0; _i2--) this.placed = prosemirrorModel.Fragment.from($from.node(_i2).copy(this.placed)); + } + _createClass(Fitter, [{ + key: "depth", + get: function get() { + return this.frontier.length - 1; + } + }, { + key: "fit", + value: function fit() { + while (this.unplaced.size) { + var fit = this.findFittable(); + if (fit) this.placeNodes(fit);else this.openMore() || this.dropNode(); + } + var moveInline = this.mustMoveInline(), + placedSize = this.placed.size - this.depth - this.$from.depth; + var $from = this.$from, + $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline)); + if (!$to) return null; + var content = this.placed, + openStart = $from.depth, + openEnd = $to.depth; + while (openStart && openEnd && content.childCount == 1) { + content = content.firstChild.content; + openStart--; + openEnd--; + } + var slice = new prosemirrorModel.Slice(content, openStart, openEnd); + if (moveInline > -1) return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize); + if (slice.size || $from.pos != this.$to.pos) return new ReplaceStep($from.pos, $to.pos, slice); + return null; + } + }, { + key: "findFittable", + value: function findFittable() { + var startDepth = this.unplaced.openStart; + for (var cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) { + var node = cur.firstChild; + if (cur.childCount > 1) openEnd = 0; + if (node.type.spec.isolating && openEnd <= d) { + startDepth = d; + break; + } + cur = node.content; + } + for (var pass = 1; pass <= 2; pass++) { + for (var sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) { + var fragment = void 0, + parent = null; + if (sliceDepth) { + parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild; + fragment = parent.content; + } else { + fragment = this.unplaced.content; + } + var first = fragment.firstChild; + for (var frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) { + var _this$frontier$fronti = this.frontier[frontierDepth], + type = _this$frontier$fronti.type, + match = _this$frontier$fronti.match, + _wrap = void 0, + inject = null; + if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(prosemirrorModel.Fragment.from(first), false)) : parent && type.compatibleContent(parent.type))) return { + sliceDepth: sliceDepth, + frontierDepth: frontierDepth, + parent: parent, + inject: inject + };else if (pass == 2 && first && (_wrap = match.findWrapping(first.type))) return { + sliceDepth: sliceDepth, + frontierDepth: frontierDepth, + parent: parent, + wrap: _wrap + }; + if (parent && match.matchType(parent.type)) break; + } + } + } + } + }, { + key: "openMore", + value: function openMore() { + var _this$unplaced = this.unplaced, + content = _this$unplaced.content, + openStart = _this$unplaced.openStart, + openEnd = _this$unplaced.openEnd; + var inner = contentAt(content, openStart); + if (!inner.childCount || inner.firstChild.isLeaf) return false; + this.unplaced = new prosemirrorModel.Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0)); + return true; + } + }, { + key: "dropNode", + value: function dropNode() { + var _this$unplaced2 = this.unplaced, + content = _this$unplaced2.content, + openStart = _this$unplaced2.openStart, + openEnd = _this$unplaced2.openEnd; + var inner = contentAt(content, openStart); + if (inner.childCount <= 1 && openStart > 0) { + var openAtEnd = content.size - openStart <= openStart + inner.size; + this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd); + } else { + this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart, 1), openStart, openEnd); + } + } + }, { + key: "placeNodes", + value: function placeNodes(_ref) { + var sliceDepth = _ref.sliceDepth, + frontierDepth = _ref.frontierDepth, + parent = _ref.parent, + inject = _ref.inject, + wrap = _ref.wrap; + while (this.depth > frontierDepth) this.closeFrontierNode(); + if (wrap) for (var i = 0; i < wrap.length; i++) this.openFrontierNode(wrap[i]); + var slice = this.unplaced, + fragment = parent ? parent.content : slice.content; + var openStart = slice.openStart - sliceDepth; + var taken = 0, + add = []; + var _this$frontier$fronti2 = this.frontier[frontierDepth], + match = _this$frontier$fronti2.match, + type = _this$frontier$fronti2.type; + if (inject) { + for (var _i3 = 0; _i3 < inject.childCount; _i3++) add.push(inject.child(_i3)); + match = match.matchFragment(inject); + } + var openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd); + while (taken < fragment.childCount) { + var next = fragment.child(taken), + matches = match.matchType(next.type); + if (!matches) break; + taken++; + if (taken > 1 || openStart == 0 || next.content.size) { + match = matches; + add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1)); + } + } + var toEnd = taken == fragment.childCount; + if (!toEnd) openEndCount = -1; + this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add)); + this.frontier[frontierDepth].match = match; + if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode(); + for (var _i4 = 0, cur = fragment; _i4 < openEndCount; _i4++) { + var node = cur.lastChild; + this.frontier.push({ + type: node.type, + match: node.contentMatchAt(node.childCount) + }); + cur = node.content; + } + this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1); + } + }, { + key: "mustMoveInline", + value: function mustMoveInline() { + if (!this.$to.parent.isTextblock) return -1; + var top = this.frontier[this.depth], + level; + if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth) return -1; + var depth = this.$to.depth, + after = this.$to.after(depth); + while (depth > 1 && after == this.$to.end(--depth)) ++after; + return after; + } + }, { + key: "findCloseLevel", + value: function findCloseLevel($to) { + scan: for (var i = Math.min(this.depth, $to.depth); i >= 0; i--) { + var _this$frontier$i = this.frontier[i], + match = _this$frontier$i.match, + type = _this$frontier$i.type; + var dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1)); + var fit = contentAfterFits($to, i, type, match, dropInner); + if (!fit) continue; + for (var d = i - 1; d >= 0; d--) { + var _this$frontier$d = this.frontier[d], + _match = _this$frontier$d.match, + _type = _this$frontier$d.type; + var matches = contentAfterFits($to, d, _type, _match, true); + if (!matches || matches.childCount) continue scan; + } + return { + depth: i, + fit: fit, + move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to + }; + } + } + }, { + key: "close", + value: function close($to) { + var close = this.findCloseLevel($to); + if (!close) return null; + while (this.depth > close.depth) this.closeFrontierNode(); + if (close.fit.childCount) this.placed = addToFragment(this.placed, close.depth, close.fit); + $to = close.move; + for (var d = close.depth + 1; d <= $to.depth; d++) { + var node = $to.node(d), + add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d)); + this.openFrontierNode(node.type, node.attrs, add); + } + return $to; + } + }, { + key: "openFrontierNode", + value: function openFrontierNode(type) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var content = arguments.length > 2 ? arguments[2] : undefined; + var top = this.frontier[this.depth]; + top.match = top.match.matchType(type); + this.placed = addToFragment(this.placed, this.depth, prosemirrorModel.Fragment.from(type.create(attrs, content))); + this.frontier.push({ + type: type, + match: type.contentMatch + }); + } + }, { + key: "closeFrontierNode", + value: function closeFrontierNode() { + var open = this.frontier.pop(); + var add = open.match.fillBefore(prosemirrorModel.Fragment.empty, true); + if (add.childCount) this.placed = addToFragment(this.placed, this.frontier.length, add); + } + }]); + return Fitter; +}(); +function dropFromFragment(fragment, depth, count) { + if (depth == 0) return fragment.cutByIndex(count, fragment.childCount); + return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count))); +} +function addToFragment(fragment, depth, content) { + if (depth == 0) return fragment.append(content); + return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content))); +} +function contentAt(fragment, depth) { + for (var i = 0; i < depth; i++) fragment = fragment.firstChild.content; + return fragment; +} +function closeNodeStart(node, openStart, openEnd) { + if (openStart <= 0) return node; + var frag = node.content; + if (openStart > 1) frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0)); + if (openStart > 0) { + frag = node.type.contentMatch.fillBefore(frag).append(frag); + if (openEnd <= 0) frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(prosemirrorModel.Fragment.empty, true)); + } + return node.copy(frag); +} +function contentAfterFits($to, depth, type, match, open) { + var node = $to.node(depth), + index = open ? $to.indexAfter(depth) : $to.index(depth); + if (index == node.childCount && !type.compatibleContent(node.type)) return null; + var fit = match.fillBefore(node.content, true, index); + return fit && !invalidMarks(type, node.content, index) ? fit : null; +} +function invalidMarks(type, fragment, start) { + for (var i = start; i < fragment.childCount; i++) if (!type.allowsMarks(fragment.child(i).marks)) return true; + return false; +} +function definesContent(type) { + return type.spec.defining || type.spec.definingForContent; +} +function _replaceRange(tr, from, to, slice) { + if (!slice.size) return tr.deleteRange(from, to); + var $from = tr.doc.resolve(from), + $to = tr.doc.resolve(to); + if (fitsTrivially($from, $to, slice)) return tr.step(new ReplaceStep(from, to, slice)); + var targetDepths = coveredDepths($from, tr.doc.resolve(to)); + if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop(); + var preferredTarget = -($from.depth + 1); + targetDepths.unshift(preferredTarget); + for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) { + var spec = $from.node(d).type.spec; + if (spec.defining || spec.definingAsContext || spec.isolating) break; + if (targetDepths.indexOf(d) > -1) preferredTarget = d;else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d); + } + var preferredTargetIndex = targetDepths.indexOf(preferredTarget); + var leftNodes = [], + preferredDepth = slice.openStart; + for (var content = slice.content, i = 0;; i++) { + var node = content.firstChild; + leftNodes.push(node); + if (i == slice.openStart) break; + content = node.content; + } + for (var _d3 = preferredDepth - 1; _d3 >= 0; _d3--) { + var leftNode = leftNodes[_d3], + def = definesContent(leftNode.type); + if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = _d3;else if (def || !leftNode.type.isTextblock) break; + } + for (var j = slice.openStart; j >= 0; j--) { + var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1); + var insert = leftNodes[openDepth]; + if (!insert) continue; + for (var _i5 = 0; _i5 < targetDepths.length; _i5++) { + var targetDepth = targetDepths[(_i5 + preferredTargetIndex) % targetDepths.length], + expand = true; + if (targetDepth < 0) { + expand = false; + targetDepth = -targetDepth; + } + var parent = $from.node(targetDepth - 1), + index = $from.index(targetDepth - 1); + if (parent.canReplaceWith(index, index, insert.type, insert.marks)) return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new prosemirrorModel.Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd)); + } + } + var startSteps = tr.steps.length; + for (var _i6 = targetDepths.length - 1; _i6 >= 0; _i6--) { + tr.replace(from, to, slice); + if (tr.steps.length > startSteps) break; + var depth = targetDepths[_i6]; + if (depth < 0) continue; + from = $from.before(depth); + to = $to.after(depth); + } +} +function closeFragment(fragment, depth, oldOpen, newOpen, parent) { + if (depth < oldOpen) { + var first = fragment.firstChild; + fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first))); + } + if (depth > newOpen) { + var match = parent.contentMatchAt(0); + var start = match.fillBefore(fragment).append(fragment); + fragment = start.append(match.matchFragment(start).fillBefore(prosemirrorModel.Fragment.empty, true)); + } + return fragment; +} +function _replaceRangeWith(tr, from, to, node) { + if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) { + var point = insertPoint(tr.doc, from, node.type); + if (point != null) from = to = point; + } + tr.replaceRange(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(node), 0, 0)); +} +function _deleteRange(tr, from, to) { + var $from = tr.doc.resolve(from), + $to = tr.doc.resolve(to); + var covered = coveredDepths($from, $to); + for (var i = 0; i < covered.length; i++) { + var depth = covered[i], + last = i == covered.length - 1; + if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) return tr["delete"]($from.start(depth), $to.end(depth)); + if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) return tr["delete"]($from.before(depth), $to.after(depth)); + } + for (var d = 1; d <= $from.depth && d <= $to.depth; d++) { + if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d && $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1))) return tr["delete"]($from.before(d), to); + } + tr["delete"](from, to); +} +function coveredDepths($from, $to) { + var result = [], + minDepth = Math.min($from.depth, $to.depth); + for (var d = minDepth; d >= 0; d--) { + var start = $from.start(d); + if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating) break; + if (start == $to.start(d) || d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent && d && $to.start(d - 1) == start - 1) result.push(d); + } + return result; +} +var AttrStep = function (_Step7) { + _inherits(AttrStep, _Step7); + var _super7 = _createSuper(AttrStep); + function AttrStep(pos, attr, value) { + var _this9; + _classCallCheck(this, AttrStep); + _this9 = _super7.call(this); + _this9.pos = pos; + _this9.attr = attr; + _this9.value = value; + return _this9; + } + _createClass(AttrStep, [{ + key: "apply", + value: function apply(doc) { + var node = doc.nodeAt(this.pos); + if (!node) return StepResult.fail("No node at attribute step's position"); + var attrs = Object.create(null); + for (var name in node.attrs) attrs[name] = node.attrs[name]; + attrs[this.attr] = this.value; + var updated = node.type.create(attrs, null, node.marks); + return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); + } + }, { + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "invert", + value: function invert(doc) { + return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]); + } + }, { + key: "map", + value: function map(mapping) { + var pos = mapping.mapResult(this.pos, 1); + return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value); + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "attr", + pos: this.pos, + attr: this.attr, + value: this.value + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.pos != "number" || typeof json.attr != "string") throw new RangeError("Invalid input for AttrStep.fromJSON"); + return new AttrStep(json.pos, json.attr, json.value); + } + }]); + return AttrStep; +}(Step); +Step.jsonID("attr", AttrStep); +var DocAttrStep = function (_Step8) { + _inherits(DocAttrStep, _Step8); + var _super8 = _createSuper(DocAttrStep); + function DocAttrStep(attr, value) { + var _this10; + _classCallCheck(this, DocAttrStep); + _this10 = _super8.call(this); + _this10.attr = attr; + _this10.value = value; + return _this10; + } + _createClass(DocAttrStep, [{ + key: "apply", + value: function apply(doc) { + var attrs = Object.create(null); + for (var name in doc.attrs) attrs[name] = doc.attrs[name]; + attrs[this.attr] = this.value; + var updated = doc.type.create(attrs, doc.content, doc.marks); + return StepResult.ok(updated); + } + }, { + key: "getMap", + value: function getMap() { + return StepMap.empty; + } + }, { + key: "invert", + value: function invert(doc) { + return new DocAttrStep(this.attr, doc.attrs[this.attr]); + } + }, { + key: "map", + value: function map(mapping) { + return this; + } + }, { + key: "toJSON", + value: function toJSON() { + return { + stepType: "docAttr", + attr: this.attr, + value: this.value + }; + } + }], [{ + key: "fromJSON", + value: function fromJSON(schema, json) { + if (typeof json.attr != "string") throw new RangeError("Invalid input for DocAttrStep.fromJSON"); + return new DocAttrStep(json.attr, json.value); + } + }]); + return DocAttrStep; +}(Step); +Step.jsonID("docAttr", DocAttrStep); +exports.TransformError = function (_Error) { + _inherits(TransformError, _Error); + var _super9 = _createSuper(TransformError); + function TransformError() { + _classCallCheck(this, TransformError); + return _super9.apply(this, arguments); + } + return _createClass(TransformError); +}(_wrapNativeSuper(Error)); +exports.TransformError = function TransformError(message) { + var err = Error.call(this, message); + err.__proto__ = TransformError.prototype; + return err; +}; +exports.TransformError.prototype = Object.create(Error.prototype); +exports.TransformError.prototype.constructor = exports.TransformError; +exports.TransformError.prototype.name = "TransformError"; +var Transform = function () { + function Transform(doc) { + _classCallCheck(this, Transform); + this.doc = doc; + this.steps = []; + this.docs = []; + this.mapping = new Mapping(); + } + _createClass(Transform, [{ + key: "before", + get: function get() { + return this.docs.length ? this.docs[0] : this.doc; + } + }, { + key: "step", + value: function step(_step) { + var result = this.maybeStep(_step); + if (result.failed) throw new exports.TransformError(result.failed); + return this; + } + }, { + key: "maybeStep", + value: function maybeStep(step) { + var result = step.apply(this.doc); + if (!result.failed) this.addStep(step, result.doc); + return result; + } + }, { + key: "docChanged", + get: function get() { + return this.steps.length > 0; + } + }, { + key: "addStep", + value: function addStep(step, doc) { + this.docs.push(this.doc); + this.steps.push(step); + this.mapping.appendMap(step.getMap()); + this.doc = doc; + } + }, { + key: "replace", + value: function replace(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from; + var slice = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : prosemirrorModel.Slice.empty; + var step = replaceStep(this.doc, from, to, slice); + if (step) this.step(step); + return this; + } + }, { + key: "replaceWith", + value: function replaceWith(from, to, content) { + return this.replace(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(content), 0, 0)); + } + }, { + key: "delete", + value: function _delete(from, to) { + return this.replace(from, to, prosemirrorModel.Slice.empty); + } + }, { + key: "insert", + value: function insert(pos, content) { + return this.replaceWith(pos, pos, content); + } + }, { + key: "replaceRange", + value: function replaceRange(from, to, slice) { + _replaceRange(this, from, to, slice); + return this; + } + }, { + key: "replaceRangeWith", + value: function replaceRangeWith(from, to, node) { + _replaceRangeWith(this, from, to, node); + return this; + } + }, { + key: "deleteRange", + value: function deleteRange(from, to) { + _deleteRange(this, from, to); + return this; + } + }, { + key: "lift", + value: function lift(range, target) { + _lift(this, range, target); + return this; + } + }, { + key: "join", + value: function join(pos) { + var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + _join(this, pos, depth); + return this; + } + }, { + key: "wrap", + value: function wrap(range, wrappers) { + _wrap2(this, range, wrappers); + return this; + } + }, { + key: "setBlockType", + value: function setBlockType(from) { + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from; + var type = arguments.length > 2 ? arguments[2] : undefined; + var attrs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _setBlockType(this, from, to, type, attrs); + return this; + } + }, { + key: "setNodeMarkup", + value: function setNodeMarkup(pos, type) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var marks = arguments.length > 3 ? arguments[3] : undefined; + _setNodeMarkup(this, pos, type, attrs, marks); + return this; + } + }, { + key: "setNodeAttribute", + value: function setNodeAttribute(pos, attr, value) { + this.step(new AttrStep(pos, attr, value)); + return this; + } + }, { + key: "setDocAttribute", + value: function setDocAttribute(attr, value) { + this.step(new DocAttrStep(attr, value)); + return this; + } + }, { + key: "addNodeMark", + value: function addNodeMark(pos, mark) { + this.step(new AddNodeMarkStep(pos, mark)); + return this; + } + }, { + key: "removeNodeMark", + value: function removeNodeMark(pos, mark) { + if (!(mark instanceof prosemirrorModel.Mark)) { + var node = this.doc.nodeAt(pos); + if (!node) throw new RangeError("No node at position " + pos); + mark = mark.isInSet(node.marks); + if (!mark) return this; + } + this.step(new RemoveNodeMarkStep(pos, mark)); + return this; + } + }, { + key: "split", + value: function split(pos) { + var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var typesAfter = arguments.length > 2 ? arguments[2] : undefined; + _split(this, pos, depth, typesAfter); + return this; + } + }, { + key: "addMark", + value: function addMark(from, to, mark) { + _addMark(this, from, to, mark); + return this; + } + }, { + key: "removeMark", + value: function removeMark(from, to, mark) { + _removeMark(this, from, to, mark); + return this; + } + }, { + key: "clearIncompatible", + value: function clearIncompatible(pos, parentType, match) { + _clearIncompatible(this, pos, parentType, match); + return this; + } + }]); + return Transform; +}(); +exports.AddMarkStep = AddMarkStep; +exports.AddNodeMarkStep = AddNodeMarkStep; +exports.AttrStep = AttrStep; +exports.DocAttrStep = DocAttrStep; +exports.MapResult = MapResult; +exports.Mapping = Mapping; +exports.RemoveMarkStep = RemoveMarkStep; +exports.RemoveNodeMarkStep = RemoveNodeMarkStep; +exports.ReplaceAroundStep = ReplaceAroundStep; +exports.ReplaceStep = ReplaceStep; +exports.Step = Step; +exports.StepMap = StepMap; +exports.StepResult = StepResult; +exports.Transform = Transform; +exports.canJoin = canJoin; +exports.canSplit = canSplit; +exports.dropPoint = dropPoint; +exports.findWrapping = findWrapping; +exports.insertPoint = insertPoint; +exports.joinPoint = joinPoint; +exports.liftTarget = liftTarget; +exports.replaceStep = replaceStep; + +}); +define("prosemirror-view",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } +function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var prosemirrorState = require('prosemirror-state'); +var prosemirrorModel = require('prosemirror-model'); +var prosemirrorTransform = require('prosemirror-transform'); +var domIndex = function domIndex(node) { + for (var index = 0;; index++) { + node = node.previousSibling; + if (!node) return index; + } +}; +var parentNode = function parentNode(node) { + var parent = node.assignedSlot || node.parentNode; + return parent && parent.nodeType == 11 ? parent.host : parent; +}; +var reusedRange = null; +var textRange = function textRange(node, from, to) { + var range = reusedRange || (reusedRange = document.createRange()); + range.setEnd(node, to == null ? node.nodeValue.length : to); + range.setStart(node, from || 0); + return range; +}; +var clearReusedRange = function clearReusedRange() { + reusedRange = null; +}; +var isEquivalentPosition = function isEquivalentPosition(node, off, targetNode, targetOff) { + return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1)); +}; +var atomElements = /^(img|br|input|textarea|hr)$/i; +function scanFor(node, off, targetNode, targetOff, dir) { + for (;;) { + if (node == targetNode && off == targetOff) return true; + if (off == (dir < 0 ? 0 : nodeSize(node))) { + var parent = node.parentNode; + if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false; + off = domIndex(node) + (dir < 0 ? 0 : 1); + node = parent; + } else if (node.nodeType == 1) { + node = node.childNodes[off + (dir < 0 ? -1 : 0)]; + if (node.contentEditable == "false") return false; + off = dir < 0 ? nodeSize(node) : 0; + } else { + return false; + } + } +} +function nodeSize(node) { + return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; +} +function textNodeBefore$1(node, offset) { + for (;;) { + if (node.nodeType == 3 && offset) return node; + if (node.nodeType == 1 && offset > 0) { + if (node.contentEditable == "false") return null; + node = node.childNodes[offset - 1]; + offset = nodeSize(node); + } else if (node.parentNode && !hasBlockDesc(node)) { + offset = domIndex(node); + node = node.parentNode; + } else { + return null; + } + } +} +function textNodeAfter$1(node, offset) { + for (;;) { + if (node.nodeType == 3 && offset < node.nodeValue.length) return node; + if (node.nodeType == 1 && offset < node.childNodes.length) { + if (node.contentEditable == "false") return null; + node = node.childNodes[offset]; + offset = 0; + } else if (node.parentNode && !hasBlockDesc(node)) { + offset = domIndex(node) + 1; + node = node.parentNode; + } else { + return null; + } + } +} +function isOnEdge(node, offset, parent) { + for (var atStart = offset == 0, atEnd = offset == nodeSize(node); atStart || atEnd;) { + if (node == parent) return true; + var index = domIndex(node); + node = node.parentNode; + if (!node) return false; + atStart = atStart && index == 0; + atEnd = atEnd && index == nodeSize(node); + } +} +function hasBlockDesc(dom) { + var desc; + for (var cur = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break; + return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom); +} +var selectionCollapsed = function selectionCollapsed(domSel) { + return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset); +}; +function keyEvent(keyCode, key) { + var event = document.createEvent("Event"); + event.initEvent("keydown", true, true); + event.keyCode = keyCode; + event.key = event.code = key; + return event; +} +function deepActiveElement(doc) { + var elt = doc.activeElement; + while (elt && elt.shadowRoot) elt = elt.shadowRoot.activeElement; + return elt; +} +function caretFromPoint(doc, x, y) { + if (doc.caretPositionFromPoint) { + try { + var pos = doc.caretPositionFromPoint(x, y); + if (pos) return { + node: pos.offsetNode, + offset: Math.min(nodeSize(pos.offsetNode), pos.offset) + }; + } catch (_) {} + } + if (doc.caretRangeFromPoint) { + var range = doc.caretRangeFromPoint(x, y); + if (range) return { + node: range.startContainer, + offset: Math.min(nodeSize(range.startContainer), range.startOffset) + }; + } +} +var nav = typeof navigator != "undefined" ? navigator : null; +var doc = typeof document != "undefined" ? document : null; +var agent = nav && nav.userAgent || ""; +var ie_edge = /Edge\/(\d+)/.exec(agent); +var ie_upto10 = /MSIE \d/.exec(agent); +var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent); +var ie = !!(ie_upto10 || ie_11up || ie_edge); +var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0; +var gecko = !ie && /gecko\/(\d+)/i.test(agent); +gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1]; +var _chrome = !ie && /Chrome\/(\d+)/.exec(agent); +var chrome = !!_chrome; +var chrome_version = _chrome ? +_chrome[1] : 0; +var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor); +var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2); +var mac = ios || (nav ? /Mac/.test(nav.platform) : false); +var windows = nav ? /Win/.test(nav.platform) : false; +var android = /Android \d/.test(agent); +var webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style; +var webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0; +function windowRect(doc) { + var vp = doc.defaultView && doc.defaultView.visualViewport; + if (vp) return { + left: 0, + right: vp.width, + top: 0, + bottom: vp.height + }; + return { + left: 0, + right: doc.documentElement.clientWidth, + top: 0, + bottom: doc.documentElement.clientHeight + }; +} +function getSide(value, side) { + return typeof value == "number" ? value : value[side]; +} +function clientRect(node) { + var rect = node.getBoundingClientRect(); + var scaleX = rect.width / node.offsetWidth || 1; + var scaleY = rect.height / node.offsetHeight || 1; + return { + left: rect.left, + right: rect.left + node.clientWidth * scaleX, + top: rect.top, + bottom: rect.top + node.clientHeight * scaleY + }; +} +function scrollRectIntoView(view, rect, startDOM) { + var scrollThreshold = view.someProp("scrollThreshold") || 0, + scrollMargin = view.someProp("scrollMargin") || 5; + var doc = view.dom.ownerDocument; + for (var parent = startDOM || view.dom;; parent = parentNode(parent)) { + if (!parent) break; + if (parent.nodeType != 1) continue; + var elt = parent; + var atTop = elt == doc.body; + var bounding = atTop ? windowRect(doc) : clientRect(elt); + var moveX = 0, + moveY = 0; + if (rect.top < bounding.top + getSide(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top"));else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom"); + if (rect.left < bounding.left + getSide(scrollThreshold, "left")) moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left"));else if (rect.right > bounding.right - getSide(scrollThreshold, "right")) moveX = rect.right - bounding.right + getSide(scrollMargin, "right"); + if (moveX || moveY) { + if (atTop) { + doc.defaultView.scrollBy(moveX, moveY); + } else { + var startX = elt.scrollLeft, + startY = elt.scrollTop; + if (moveY) elt.scrollTop += moveY; + if (moveX) elt.scrollLeft += moveX; + var dX = elt.scrollLeft - startX, + dY = elt.scrollTop - startY; + rect = { + left: rect.left - dX, + top: rect.top - dY, + right: rect.right - dX, + bottom: rect.bottom - dY + }; + } + } + if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position)) break; + } +} +function storeScrollPos(view) { + var rect = view.dom.getBoundingClientRect(), + startY = Math.max(0, rect.top); + var refDOM, refTop; + for (var x = (rect.left + rect.right) / 2, y = startY + 1; y < Math.min(innerHeight, rect.bottom); y += 5) { + var dom = view.root.elementFromPoint(x, y); + if (!dom || dom == view.dom || !view.dom.contains(dom)) continue; + var localRect = dom.getBoundingClientRect(); + if (localRect.top >= startY - 20) { + refDOM = dom; + refTop = localRect.top; + break; + } + } + return { + refDOM: refDOM, + refTop: refTop, + stack: scrollStack(view.dom) + }; +} +function scrollStack(dom) { + var stack = [], + doc = dom.ownerDocument; + for (var cur = dom; cur; cur = parentNode(cur)) { + stack.push({ + dom: cur, + top: cur.scrollTop, + left: cur.scrollLeft + }); + if (dom == doc) break; + } + return stack; +} +function resetScrollPos(_ref) { + var refDOM = _ref.refDOM, + refTop = _ref.refTop, + stack = _ref.stack; + var newRefTop = refDOM ? refDOM.getBoundingClientRect().top : 0; + restoreScrollStack(stack, newRefTop == 0 ? 0 : newRefTop - refTop); +} +function restoreScrollStack(stack, dTop) { + for (var i = 0; i < stack.length; i++) { + var _stack$i = stack[i], + dom = _stack$i.dom, + top = _stack$i.top, + left = _stack$i.left; + if (dom.scrollTop != top + dTop) dom.scrollTop = top + dTop; + if (dom.scrollLeft != left) dom.scrollLeft = left; + } +} +var preventScrollSupported = null; +function focusPreventScroll(dom) { + if (dom.setActive) return dom.setActive(); + if (preventScrollSupported) return dom.focus(preventScrollSupported); + var stored = scrollStack(dom); + dom.focus(preventScrollSupported == null ? { + get preventScroll() { + preventScrollSupported = { + preventScroll: true + }; + return true; + } + } : undefined); + if (!preventScrollSupported) { + preventScrollSupported = false; + restoreScrollStack(stored, 0); + } +} +function findOffsetInNode(node, coords) { + var closest, + dxClosest = 2e8, + coordsClosest, + offset = 0; + var rowBot = coords.top, + rowTop = coords.top; + var firstBelow, coordsBelow; + for (var child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) { + var rects = void 0; + if (child.nodeType == 1) rects = child.getClientRects();else if (child.nodeType == 3) rects = textRange(child).getClientRects();else continue; + for (var i = 0; i < rects.length; i++) { + var rect = rects[i]; + if (rect.top <= rowBot && rect.bottom >= rowTop) { + rowBot = Math.max(rect.bottom, rowBot); + rowTop = Math.min(rect.top, rowTop); + var dx = rect.left > coords.left ? rect.left - coords.left : rect.right < coords.left ? coords.left - rect.right : 0; + if (dx < dxClosest) { + closest = child; + dxClosest = dx; + coordsClosest = dx && closest.nodeType == 3 ? { + left: rect.right < coords.left ? rect.right : rect.left, + top: coords.top + } : coords; + if (child.nodeType == 1 && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0); + continue; + } + } else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) { + firstBelow = child; + coordsBelow = { + left: Math.max(rect.left, Math.min(rect.right, coords.left)), + top: rect.top + }; + } + if (!closest && (coords.left >= rect.right && coords.top >= rect.top || coords.left >= rect.left && coords.top >= rect.bottom)) offset = childIndex + 1; + } + } + if (!closest && firstBelow) { + closest = firstBelow; + coordsClosest = coordsBelow; + dxClosest = 0; + } + if (closest && closest.nodeType == 3) return findOffsetInText(closest, coordsClosest); + if (!closest || dxClosest && closest.nodeType == 1) return { + node: node, + offset: offset + }; + return findOffsetInNode(closest, coordsClosest); +} +function findOffsetInText(node, coords) { + var len = node.nodeValue.length; + var range = document.createRange(); + for (var i = 0; i < len; i++) { + range.setEnd(node, i + 1); + range.setStart(node, i); + var rect = singleRect(range, 1); + if (rect.top == rect.bottom) continue; + if (inRect(coords, rect)) return { + node: node, + offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) + }; + } + return { + node: node, + offset: 0 + }; +} +function inRect(coords, rect) { + return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1; +} +function targetKludge(dom, coords) { + var parent = dom.parentNode; + if (parent && /^li$/i.test(parent.nodeName) && coords.left < dom.getBoundingClientRect().left) return parent; + return dom; +} +function posFromElement(view, elt, coords) { + var _findOffsetInNode = findOffsetInNode(elt, coords), + node = _findOffsetInNode.node, + offset = _findOffsetInNode.offset, + bias = -1; + if (node.nodeType == 1 && !node.firstChild) { + var rect = node.getBoundingClientRect(); + bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1; + } + return view.docView.posFromDOM(node, offset, bias); +} +function posFromCaret(view, node, offset, coords) { + var outsideBlock = -1; + for (var cur = node, sawBlock = false;;) { + if (cur == view.dom) break; + var desc = view.docView.nearestDesc(cur, true); + if (!desc) return null; + if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) { + var rect = desc.dom.getBoundingClientRect(); + if (desc.node.isBlock && desc.parent) { + if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter; + sawBlock = true; + } + if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) { + var before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2; + return before ? desc.posBefore : desc.posAfter; + } + } + cur = desc.dom.parentNode; + } + return outsideBlock > -1 ? outsideBlock : view.docView.posFromDOM(node, offset, -1); +} +function elementFromPoint(element, coords, box) { + var len = element.childNodes.length; + if (len && box.top < box.bottom) { + for (var startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) { + var child = element.childNodes[i]; + if (child.nodeType == 1) { + var rects = child.getClientRects(); + for (var j = 0; j < rects.length; j++) { + var rect = rects[j]; + if (inRect(coords, rect)) return elementFromPoint(child, coords, rect); + } + } + if ((i = (i + 1) % len) == startI) break; + } + } + return element; +} +function _posAtCoords(view, coords) { + var doc = view.dom.ownerDocument, + node, + offset = 0; + var caret = caretFromPoint(doc, coords.left, coords.top); + if (caret) { + node = caret.node; + offset = caret.offset; + } + var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top); + var pos; + if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) { + var box = view.dom.getBoundingClientRect(); + if (!inRect(coords, box)) return null; + elt = elementFromPoint(view.dom, coords, box); + if (!elt) return null; + } + if (safari) { + for (var p = elt; node && p; p = parentNode(p)) if (p.draggable) node = undefined; + } + elt = targetKludge(elt, coords); + if (node) { + if (gecko && node.nodeType == 1) { + offset = Math.min(offset, node.childNodes.length); + if (offset < node.childNodes.length) { + var next = node.childNodes[offset], + _box; + if (next.nodeName == "IMG" && (_box = next.getBoundingClientRect()).right <= coords.left && _box.bottom > coords.top) offset++; + } + } + var prev; + if (webkit && offset && node.nodeType == 1 && (prev = node.childNodes[offset - 1]).nodeType == 1 && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--; + if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords); + } + if (pos == null) pos = posFromElement(view, elt, coords); + var desc = view.docView.nearestDesc(elt, true); + return { + pos: pos, + inside: desc ? desc.posAtStart - desc.border : -1 + }; +} +function nonZero(rect) { + return rect.top < rect.bottom || rect.left < rect.right; +} +function singleRect(target, bias) { + var rects = target.getClientRects(); + if (rects.length) { + var first = rects[bias < 0 ? 0 : rects.length - 1]; + if (nonZero(first)) return first; + } + return Array.prototype.find.call(rects, nonZero) || target.getBoundingClientRect(); +} +var BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/; +function _coordsAtPos(view, pos, side) { + var _view$docView$domFrom = view.docView.domFromPos(pos, side < 0 ? -1 : 1), + node = _view$docView$domFrom.node, + offset = _view$docView$domFrom.offset, + atom = _view$docView$domFrom.atom; + var supportEmptyRange = webkit || gecko; + if (node.nodeType == 3) { + if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) { + var rect = singleRect(textRange(node, offset, offset), side); + if (gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) { + var rectBefore = singleRect(textRange(node, offset - 1, offset - 1), -1); + if (rectBefore.top == rect.top) { + var rectAfter = singleRect(textRange(node, offset, offset + 1), -1); + if (rectAfter.top != rect.top) return flattenV(rectAfter, rectAfter.left < rectBefore.left); + } + } + return rect; + } else { + var from = offset, + to = offset, + takeSide = side < 0 ? 1 : -1; + if (side < 0 && !offset) { + to++; + takeSide = -1; + } else if (side >= 0 && offset == node.nodeValue.length) { + from--; + takeSide = 1; + } else if (side < 0) { + from--; + } else { + to++; + } + return flattenV(singleRect(textRange(node, from, to), takeSide), takeSide < 0); + } + } + var $dom = view.state.doc.resolve(pos - (atom || 0)); + if (!$dom.parent.inlineContent) { + if (atom == null && offset && (side < 0 || offset == nodeSize(node))) { + var before = node.childNodes[offset - 1]; + if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false); + } + if (atom == null && offset < nodeSize(node)) { + var after = node.childNodes[offset]; + if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true); + } + return flattenH(node.getBoundingClientRect(), side >= 0); + } + if (atom == null && offset && (side < 0 || offset == nodeSize(node))) { + var _before = node.childNodes[offset - 1]; + var target = _before.nodeType == 3 ? textRange(_before, nodeSize(_before) - (supportEmptyRange ? 0 : 1)) : _before.nodeType == 1 && (_before.nodeName != "BR" || !_before.nextSibling) ? _before : null; + if (target) return flattenV(singleRect(target, 1), false); + } + if (atom == null && offset < nodeSize(node)) { + var _after = node.childNodes[offset]; + while (_after.pmViewDesc && _after.pmViewDesc.ignoreForCoords) _after = _after.nextSibling; + var _target = !_after ? null : _after.nodeType == 3 ? textRange(_after, 0, supportEmptyRange ? 0 : 1) : _after.nodeType == 1 ? _after : null; + if (_target) return flattenV(singleRect(_target, -1), true); + } + return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0); +} +function flattenV(rect, left) { + if (rect.width == 0) return rect; + var x = left ? rect.left : rect.right; + return { + top: rect.top, + bottom: rect.bottom, + left: x, + right: x + }; +} +function flattenH(rect, top) { + if (rect.height == 0) return rect; + var y = top ? rect.top : rect.bottom; + return { + top: y, + bottom: y, + left: rect.left, + right: rect.right + }; +} +function withFlushedState(view, state, f) { + var viewState = view.state, + active = view.root.activeElement; + if (viewState != state) view.updateState(state); + if (active != view.dom) view.focus(); + try { + return f(); + } finally { + if (viewState != state) view.updateState(viewState); + if (active != view.dom && active) active.focus(); + } +} +function endOfTextblockVertical(view, state, dir) { + var sel = state.selection; + var $pos = dir == "up" ? sel.$from : sel.$to; + return withFlushedState(view, state, function () { + var _view$docView$domFrom2 = view.docView.domFromPos($pos.pos, dir == "up" ? -1 : 1), + dom = _view$docView$domFrom2.node; + for (;;) { + var nearest = view.docView.nearestDesc(dom, true); + if (!nearest) break; + if (nearest.node.isBlock) { + dom = nearest.contentDOM || nearest.dom; + break; + } + dom = nearest.dom.parentNode; + } + var coords = _coordsAtPos(view, $pos.pos, 1); + for (var child = dom.firstChild; child; child = child.nextSibling) { + var boxes = void 0; + if (child.nodeType == 1) boxes = child.getClientRects();else if (child.nodeType == 3) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();else continue; + for (var i = 0; i < boxes.length; i++) { + var box = boxes[i]; + if (box.bottom > box.top + 1 && (dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2 : box.bottom - coords.bottom > (coords.bottom - box.top) * 2)) return false; + } + } + return true; + }); +} +var maybeRTL = /[\u0590-\u08ac]/; +function endOfTextblockHorizontal(view, state, dir) { + var $head = state.selection.$head; + if (!$head.parent.isTextblock) return false; + var offset = $head.parentOffset, + atStart = !offset, + atEnd = offset == $head.parent.content.size; + var sel = view.domSelection(); + if (!sel) return $head.pos == $head.start() || $head.pos == $head.end(); + if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd; + return withFlushedState(view, state, function () { + var _view$domSelectionRan = view.domSelectionRange(), + oldNode = _view$domSelectionRan.focusNode, + oldOff = _view$domSelectionRan.focusOffset, + anchorNode = _view$domSelectionRan.anchorNode, + anchorOffset = _view$domSelectionRan.anchorOffset; + var oldBidiLevel = sel.caretBidiLevel; + sel.modify("move", dir, "character"); + var parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom; + var _view$domSelectionRan2 = view.domSelectionRange(), + newNode = _view$domSelectionRan2.focusNode, + newOff = _view$domSelectionRan2.focusOffset; + var result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff; + try { + sel.collapse(anchorNode, anchorOffset); + if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff); + } catch (_) {} + if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel; + return result; + }); +} +var cachedState = null; +var cachedDir = null; +var cachedResult = false; +function _endOfTextblock(view, state, dir) { + if (cachedState == state && cachedDir == dir) return cachedResult; + cachedState = state; + cachedDir = dir; + return cachedResult = dir == "up" || dir == "down" ? endOfTextblockVertical(view, state, dir) : endOfTextblockHorizontal(view, state, dir); +} +var NOT_DIRTY = 0, + CHILD_DIRTY = 1, + CONTENT_DIRTY = 2, + NODE_DIRTY = 3; +var ViewDesc = function () { + function ViewDesc(parent, children, dom, contentDOM) { + _classCallCheck(this, ViewDesc); + this.parent = parent; + this.children = children; + this.dom = dom; + this.contentDOM = contentDOM; + this.dirty = NOT_DIRTY; + dom.pmViewDesc = this; + } + _createClass(ViewDesc, [{ + key: "matchesWidget", + value: function matchesWidget(widget) { + return false; + } + }, { + key: "matchesMark", + value: function matchesMark(mark) { + return false; + } + }, { + key: "matchesNode", + value: function matchesNode(node, outerDeco, innerDeco) { + return false; + } + }, { + key: "matchesHack", + value: function matchesHack(nodeName) { + return false; + } + }, { + key: "parseRule", + value: function parseRule() { + return null; + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + return false; + } + }, { + key: "size", + get: function get() { + var size = 0; + for (var i = 0; i < this.children.length; i++) size += this.children[i].size; + return size; + } + }, { + key: "border", + get: function get() { + return 0; + } + }, { + key: "destroy", + value: function destroy() { + this.parent = undefined; + if (this.dom.pmViewDesc == this) this.dom.pmViewDesc = undefined; + for (var i = 0; i < this.children.length; i++) this.children[i].destroy(); + } + }, { + key: "posBeforeChild", + value: function posBeforeChild(child) { + for (var i = 0, pos = this.posAtStart;; i++) { + var cur = this.children[i]; + if (cur == child) return pos; + pos += cur.size; + } + } + }, { + key: "posBefore", + get: function get() { + return this.parent.posBeforeChild(this); + } + }, { + key: "posAtStart", + get: function get() { + return this.parent ? this.parent.posBeforeChild(this) + this.border : 0; + } + }, { + key: "posAfter", + get: function get() { + return this.posBefore + this.size; + } + }, { + key: "posAtEnd", + get: function get() { + return this.posAtStart + this.size - 2 * this.border; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset, bias) { + if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) { + if (bias < 0) { + var domBefore, desc; + if (dom == this.contentDOM) { + domBefore = dom.childNodes[offset - 1]; + } else { + while (dom.parentNode != this.contentDOM) dom = dom.parentNode; + domBefore = dom.previousSibling; + } + while (domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this)) domBefore = domBefore.previousSibling; + return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart; + } else { + var domAfter, _desc; + if (dom == this.contentDOM) { + domAfter = dom.childNodes[offset]; + } else { + while (dom.parentNode != this.contentDOM) dom = dom.parentNode; + domAfter = dom.nextSibling; + } + while (domAfter && !((_desc = domAfter.pmViewDesc) && _desc.parent == this)) domAfter = domAfter.nextSibling; + return domAfter ? this.posBeforeChild(_desc) : this.posAtEnd; + } + } + var atEnd; + if (dom == this.dom && this.contentDOM) { + atEnd = offset > domIndex(this.contentDOM); + } else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) { + atEnd = dom.compareDocumentPosition(this.contentDOM) & 2; + } else if (this.dom.firstChild) { + if (offset == 0) for (var search = dom;; search = search.parentNode) { + if (search == this.dom) { + atEnd = false; + break; + } + if (search.previousSibling) break; + } + if (atEnd == null && offset == dom.childNodes.length) for (var _search = dom;; _search = _search.parentNode) { + if (_search == this.dom) { + atEnd = true; + break; + } + if (_search.nextSibling) break; + } + } + return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart; + } + }, { + key: "nearestDesc", + value: function nearestDesc(dom) { + var onlyNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + for (var first = true, cur = dom; cur; cur = cur.parentNode) { + var desc = this.getDesc(cur), + nodeDOM = void 0; + if (desc && (!onlyNodes || desc.node)) { + if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first = false;else return desc; + } + } + } + }, { + key: "getDesc", + value: function getDesc(dom) { + var desc = dom.pmViewDesc; + for (var cur = desc; cur; cur = cur.parent) if (cur == this) return desc; + } + }, { + key: "posFromDOM", + value: function posFromDOM(dom, offset, bias) { + for (var scan = dom; scan; scan = scan.parentNode) { + var desc = this.getDesc(scan); + if (desc) return desc.localPosFromDOM(dom, offset, bias); + } + return -1; + } + }, { + key: "descAt", + value: function descAt(pos) { + for (var i = 0, offset = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (offset == pos && end != offset) { + while (!child.border && child.children.length) child = child.children[0]; + return child; + } + if (pos < end) return child.descAt(pos - offset - child.border); + offset = end; + } + } + }, { + key: "domFromPos", + value: function domFromPos(pos, side) { + if (!this.contentDOM) return { + node: this.dom, + offset: 0, + atom: pos + 1 + }; + var i = 0, + offset = 0; + for (var curPos = 0; i < this.children.length; i++) { + var child = this.children[i], + end = curPos + child.size; + if (end > pos || child instanceof TrailingHackViewDesc) { + offset = pos - curPos; + break; + } + curPos = end; + } + if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side); + for (var prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--) {} + if (side <= 0) { + var _prev, + enter = true; + for (;; i--, enter = false) { + _prev = i ? this.children[i - 1] : null; + if (!_prev || _prev.dom.parentNode == this.contentDOM) break; + } + if (_prev && side && enter && !_prev.border && !_prev.domAtom) return _prev.domFromPos(_prev.size, side); + return { + node: this.contentDOM, + offset: _prev ? domIndex(_prev.dom) + 1 : 0 + }; + } else { + var next, + _enter = true; + for (;; i++, _enter = false) { + next = i < this.children.length ? this.children[i] : null; + if (!next || next.dom.parentNode == this.contentDOM) break; + } + if (next && _enter && !next.border && !next.domAtom) return next.domFromPos(0, side); + return { + node: this.contentDOM, + offset: next ? domIndex(next.dom) : this.contentDOM.childNodes.length + }; + } + } + }, { + key: "parseRange", + value: function parseRange(from, to) { + var base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + if (this.children.length == 0) return { + node: this.contentDOM, + from: from, + to: to, + fromOffset: 0, + toOffset: this.contentDOM.childNodes.length + }; + var fromOffset = -1, + toOffset = -1; + for (var offset = base, i = 0;; i++) { + var child = this.children[i], + end = offset + child.size; + if (fromOffset == -1 && from <= end) { + var childBase = offset + child.border; + if (from >= childBase && to <= end - child.border && child.node && child.contentDOM && this.contentDOM.contains(child.contentDOM)) return child.parseRange(from, to, childBase); + from = offset; + for (var j = i; j > 0; j--) { + var prev = this.children[j - 1]; + if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) { + fromOffset = domIndex(prev.dom) + 1; + break; + } + from -= prev.size; + } + if (fromOffset == -1) fromOffset = 0; + } + if (fromOffset > -1 && (end > to || i == this.children.length - 1)) { + to = end; + for (var _j = i + 1; _j < this.children.length; _j++) { + var next = this.children[_j]; + if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) { + toOffset = domIndex(next.dom); + break; + } + to += next.size; + } + if (toOffset == -1) toOffset = this.contentDOM.childNodes.length; + break; + } + offset = end; + } + return { + node: this.contentDOM, + from: from, + to: to, + fromOffset: fromOffset, + toOffset: toOffset + }; + } + }, { + key: "emptyChildAt", + value: function emptyChildAt(side) { + if (this.border || !this.contentDOM || !this.children.length) return false; + var child = this.children[side < 0 ? 0 : this.children.length - 1]; + return child.size == 0 || child.emptyChildAt(side); + } + }, { + key: "domAfterPos", + value: function domAfterPos(pos) { + var _this$domFromPos = this.domFromPos(pos, 0), + node = _this$domFromPos.node, + offset = _this$domFromPos.offset; + if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos); + return node.childNodes[offset]; + } + }, { + key: "setSelection", + value: function setSelection(anchor, head, root) { + var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + var from = Math.min(anchor, head), + to = Math.max(anchor, head); + for (var i = 0, offset = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (from > offset && to < end) return child.setSelection(anchor - offset - child.border, head - offset - child.border, root, force); + offset = end; + } + var anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1); + var headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1); + var domSel = root.getSelection(); + var brKludge = false; + if ((gecko || safari) && anchor == head) { + var _anchorDOM = anchorDOM, + node = _anchorDOM.node, + _offset = _anchorDOM.offset; + if (node.nodeType == 3) { + brKludge = !!(_offset && node.nodeValue[_offset - 1] == "\n"); + if (brKludge && _offset == node.nodeValue.length) { + for (var scan = node, after; scan; scan = scan.parentNode) { + if (after = scan.nextSibling) { + if (after.nodeName == "BR") anchorDOM = headDOM = { + node: after.parentNode, + offset: domIndex(after) + 1 + }; + break; + } + var desc = scan.pmViewDesc; + if (desc && desc.node && desc.node.isBlock) break; + } + } + } else { + var prev = node.childNodes[_offset - 1]; + brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false"); + } + } + if (gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) { + var _after2 = domSel.focusNode.childNodes[domSel.focusOffset]; + if (_after2 && _after2.contentEditable == "false") force = true; + } + if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, domSel.focusNode, domSel.focusOffset)) return; + var domSelExtended = false; + if ((domSel.extend || anchor == head) && !brKludge) { + domSel.collapse(anchorDOM.node, anchorDOM.offset); + try { + if (anchor != head) domSel.extend(headDOM.node, headDOM.offset); + domSelExtended = true; + } catch (_) {} + } + if (!domSelExtended) { + if (anchor > head) { + var tmp = anchorDOM; + anchorDOM = headDOM; + headDOM = tmp; + } + var range = document.createRange(); + range.setEnd(headDOM.node, headDOM.offset); + range.setStart(anchorDOM.node, anchorDOM.offset); + domSel.removeAllRanges(); + domSel.addRange(range); + } + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return !this.contentDOM && mutation.type != "selection"; + } + }, { + key: "contentLost", + get: function get() { + return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + for (var offset = 0, i = 0; i < this.children.length; i++) { + var child = this.children[i], + end = offset + child.size; + if (offset == end ? from <= end && to >= offset : from < end && to > offset) { + var startInside = offset + child.border, + endInside = end - child.border; + if (from >= startInside && to <= endInside) { + this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY; + if (from == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY;else child.markDirty(from - startInside, to - startInside); + return; + } else { + child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY; + } + } + offset = end; + } + this.dirty = CONTENT_DIRTY; + } + }, { + key: "markParentsDirty", + value: function markParentsDirty() { + var level = 1; + for (var node = this.parent; node; node = node.parent, level++) { + var dirty = level == 1 ? CONTENT_DIRTY : CHILD_DIRTY; + if (node.dirty < dirty) node.dirty = dirty; + } + } + }, { + key: "domAtom", + get: function get() { + return false; + } + }, { + key: "ignoreForCoords", + get: function get() { + return false; + } + }, { + key: "isText", + value: function isText(text) { + return false; + } + }]); + return ViewDesc; +}(); +var WidgetViewDesc = function (_ViewDesc) { + _inherits(WidgetViewDesc, _ViewDesc); + var _super = _createSuper(WidgetViewDesc); + function WidgetViewDesc(parent, widget, view, pos) { + var _this; + _classCallCheck(this, WidgetViewDesc); + var self, + dom = widget.type.toDOM; + if (typeof dom == "function") dom = dom(view, function () { + if (!self) return pos; + if (self.parent) return self.parent.posBeforeChild(self); + }); + if (!widget.type.spec.raw) { + if (dom.nodeType != 1) { + var wrap = document.createElement("span"); + wrap.appendChild(dom); + dom = wrap; + } + dom.contentEditable = "false"; + dom.classList.add("ProseMirror-widget"); + } + _this = _super.call(this, parent, [], dom, null); + _this.widget = widget; + _this.widget = widget; + self = _assertThisInitialized(_this); + return _this; + } + _createClass(WidgetViewDesc, [{ + key: "matchesWidget", + value: function matchesWidget(widget) { + return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type); + } + }, { + key: "parseRule", + value: function parseRule() { + return { + ignore: true + }; + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + var stop = this.widget.spec.stopEvent; + return stop ? stop(event) : false; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return mutation.type != "selection" || this.widget.spec.ignoreSelection; + } + }, { + key: "destroy", + value: function destroy() { + this.widget.type.destroy(this.dom); + _get(_getPrototypeOf(WidgetViewDesc.prototype), "destroy", this).call(this); + } + }, { + key: "domAtom", + get: function get() { + return true; + } + }, { + key: "side", + get: function get() { + return this.widget.type.side; + } + }]); + return WidgetViewDesc; +}(ViewDesc); +var CompositionViewDesc = function (_ViewDesc2) { + _inherits(CompositionViewDesc, _ViewDesc2); + var _super2 = _createSuper(CompositionViewDesc); + function CompositionViewDesc(parent, dom, textDOM, text) { + var _this2; + _classCallCheck(this, CompositionViewDesc); + _this2 = _super2.call(this, parent, [], dom, null); + _this2.textDOM = textDOM; + _this2.text = text; + return _this2; + } + _createClass(CompositionViewDesc, [{ + key: "size", + get: function get() { + return this.text.length; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset) { + if (dom != this.textDOM) return this.posAtStart + (offset ? this.size : 0); + return this.posAtStart + offset; + } + }, { + key: "domFromPos", + value: function domFromPos(pos) { + return { + node: this.textDOM, + offset: pos + }; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mut) { + return mut.type === 'characterData' && mut.target.nodeValue == mut.oldValue; + } + }]); + return CompositionViewDesc; +}(ViewDesc); +var MarkViewDesc = function (_ViewDesc3) { + _inherits(MarkViewDesc, _ViewDesc3); + var _super3 = _createSuper(MarkViewDesc); + function MarkViewDesc(parent, mark, dom, contentDOM) { + var _this3; + _classCallCheck(this, MarkViewDesc); + _this3 = _super3.call(this, parent, [], dom, contentDOM); + _this3.mark = mark; + return _this3; + } + _createClass(MarkViewDesc, [{ + key: "parseRule", + value: function parseRule() { + if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null; + return { + mark: this.mark.type.name, + attrs: this.mark.attrs, + contentElement: this.contentDOM + }; + } + }, { + key: "matchesMark", + value: function matchesMark(mark) { + return this.dirty != NODE_DIRTY && this.mark.eq(mark); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + _get(_getPrototypeOf(MarkViewDesc.prototype), "markDirty", this).call(this, from, to); + if (this.dirty != NOT_DIRTY) { + var parent = this.parent; + while (!parent.node) parent = parent.parent; + if (parent.dirty < this.dirty) parent.dirty = this.dirty; + this.dirty = NOT_DIRTY; + } + } + }, { + key: "slice", + value: function slice(from, to, view) { + var copy = MarkViewDesc.create(this.parent, this.mark, true, view); + var nodes = this.children, + size = this.size; + if (to < size) nodes = replaceNodes(nodes, to, size, view); + if (from > 0) nodes = replaceNodes(nodes, 0, from, view); + for (var i = 0; i < nodes.length; i++) nodes[i].parent = copy; + copy.children = nodes; + return copy; + } + }], [{ + key: "create", + value: function create(parent, mark, inline, view) { + var custom = view.nodeViews[mark.type.name]; + var spec = custom && custom(mark, view, inline); + if (!spec || !spec.dom) spec = prosemirrorModel.DOMSerializer.renderSpec(document, mark.type.spec.toDOM(mark, inline), null, mark.attrs); + return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom); + } + }]); + return MarkViewDesc; +}(ViewDesc); +var NodeViewDesc = function (_ViewDesc4) { + _inherits(NodeViewDesc, _ViewDesc4); + var _super4 = _createSuper(NodeViewDesc); + function NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos) { + var _this4; + _classCallCheck(this, NodeViewDesc); + _this4 = _super4.call(this, parent, [], dom, contentDOM); + _this4.node = node; + _this4.outerDeco = outerDeco; + _this4.innerDeco = innerDeco; + _this4.nodeDOM = nodeDOM; + return _this4; + } + _createClass(NodeViewDesc, [{ + key: "parseRule", + value: function parseRule() { + var _this5 = this; + if (this.node.type.spec.reparseInView) return null; + var rule = { + node: this.node.type.name, + attrs: this.node.attrs + }; + if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full"; + if (!this.contentDOM) { + rule.getContent = function () { + return _this5.node.content; + }; + } else if (!this.contentLost) { + rule.contentElement = this.contentDOM; + } else { + for (var i = this.children.length - 1; i >= 0; i--) { + var child = this.children[i]; + if (this.dom.contains(child.dom.parentNode)) { + rule.contentElement = child.dom.parentNode; + break; + } + } + if (!rule.contentElement) rule.getContent = function () { + return prosemirrorModel.Fragment.empty; + }; + } + return rule; + } + }, { + key: "matchesNode", + value: function matchesNode(node, outerDeco, innerDeco) { + return this.dirty == NOT_DIRTY && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco); + } + }, { + key: "size", + get: function get() { + return this.node.nodeSize; + } + }, { + key: "border", + get: function get() { + return this.node.isLeaf ? 0 : 1; + } + }, { + key: "updateChildren", + value: function updateChildren(view, pos) { + var _this6 = this; + var inline = this.node.inlineContent, + off = pos; + var composition = view.composing ? this.localCompositionInfo(view, pos) : null; + var localComposition = composition && composition.pos > -1 ? composition : null; + var compositionInChild = composition && composition.pos < 0; + var updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view); + iterDeco(this.node, this.innerDeco, function (widget, i, insideNode) { + if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == _this6.node.childCount ? prosemirrorModel.Mark.none : _this6.node.child(i).marks, inline, view); + updater.placeWidget(widget, view, off); + }, function (child, outerDeco, innerDeco, i) { + updater.syncToMarks(child.marks, inline, view); + var compIndex; + if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ;else if (compositionInChild && view.state.selection.from > off && view.state.selection.to < off + child.nodeSize && (compIndex = updater.findIndexWithChild(composition.node)) > -1 && updater.updateNodeAt(child, outerDeco, innerDeco, compIndex, view)) ;else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off)) ;else { + updater.addNode(child, outerDeco, innerDeco, view, off); + } + off += child.nodeSize; + }); + updater.syncToMarks([], inline, view); + if (this.node.isTextblock) updater.addTextblockHacks(); + updater.destroyRest(); + if (updater.changed || this.dirty == CONTENT_DIRTY) { + if (localComposition) this.protectLocalComposition(view, localComposition); + renderDescs(this.contentDOM, this.children, view); + if (ios) iosHacks(this.dom); + } + } + }, { + key: "localCompositionInfo", + value: function localCompositionInfo(view, pos) { + var _view$state$selection = view.state.selection, + from = _view$state$selection.from, + to = _view$state$selection.to; + if (!(view.state.selection instanceof prosemirrorState.TextSelection) || from < pos || to > pos + this.node.content.size) return null; + var textNode = view.input.compositionNode; + if (!textNode || !this.dom.contains(textNode.parentNode)) return null; + if (this.node.inlineContent) { + var text = textNode.nodeValue; + var textPos = findTextInFragment(this.node.content, text, from - pos, to - pos); + return textPos < 0 ? null : { + node: textNode, + pos: textPos, + text: text + }; + } else { + return { + node: textNode, + pos: -1, + text: "" + }; + } + } + }, { + key: "protectLocalComposition", + value: function protectLocalComposition(view, _ref2) { + var node = _ref2.node, + pos = _ref2.pos, + text = _ref2.text; + if (this.getDesc(node)) return; + var topNode = node; + for (;; topNode = topNode.parentNode) { + if (topNode.parentNode == this.contentDOM) break; + while (topNode.previousSibling) topNode.parentNode.removeChild(topNode.previousSibling); + while (topNode.nextSibling) topNode.parentNode.removeChild(topNode.nextSibling); + if (topNode.pmViewDesc) topNode.pmViewDesc = undefined; + } + var desc = new CompositionViewDesc(this, topNode, node, text); + view.input.compositionNodes.push(desc); + this.children = replaceNodes(this.children, pos, pos + text.length, view, desc); + } + }, { + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY || !node.sameMarkup(this.node)) return false; + this.updateInner(node, outerDeco, innerDeco, view); + return true; + } + }, { + key: "updateInner", + value: function updateInner(node, outerDeco, innerDeco, view) { + this.updateOuterDeco(outerDeco); + this.node = node; + this.innerDeco = innerDeco; + if (this.contentDOM) this.updateChildren(view, this.posAtStart); + this.dirty = NOT_DIRTY; + } + }, { + key: "updateOuterDeco", + value: function updateOuterDeco(outerDeco) { + if (sameOuterDeco(outerDeco, this.outerDeco)) return; + var needsWrap = this.nodeDOM.nodeType != 1; + var oldDOM = this.dom; + this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap)); + if (this.dom != oldDOM) { + oldDOM.pmViewDesc = undefined; + this.dom.pmViewDesc = this; + } + this.outerDeco = outerDeco; + } + }, { + key: "selectNode", + value: function selectNode() { + if (this.nodeDOM.nodeType == 1) this.nodeDOM.classList.add("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) this.dom.draggable = true; + } + }, { + key: "deselectNode", + value: function deselectNode() { + if (this.nodeDOM.nodeType == 1) { + this.nodeDOM.classList.remove("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) this.dom.removeAttribute("draggable"); + } + } + }, { + key: "domAtom", + get: function get() { + return this.node.isAtom; + } + }], [{ + key: "create", + value: function create(parent, node, outerDeco, innerDeco, view, pos) { + var custom = view.nodeViews[node.type.name], + descObj; + var spec = custom && custom(node, view, function () { + if (!descObj) return pos; + if (descObj.parent) return descObj.parent.posBeforeChild(descObj); + }, outerDeco, innerDeco); + var dom = spec && spec.dom, + contentDOM = spec && spec.contentDOM; + if (node.isText) { + if (!dom) dom = document.createTextNode(node.text);else if (dom.nodeType != 3) throw new RangeError("Text must be rendered as a DOM text node"); + } else if (!dom) { + var _spec = prosemirrorModel.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs); + dom = _spec.dom; + contentDOM = _spec.contentDOM; + } + if (!contentDOM && !node.isText && dom.nodeName != "BR") { + if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false"; + if (node.type.spec.draggable) dom.draggable = true; + } + var nodeDOM = dom; + dom = applyOuterDeco(dom, outerDeco, node); + if (spec) return descObj = new CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, spec, view, pos + 1);else if (node.isText) return new TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view);else return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, view, pos + 1); + } + }]); + return NodeViewDesc; +}(ViewDesc); +function docViewDesc(doc, outerDeco, innerDeco, dom, view) { + applyOuterDeco(dom, outerDeco, doc); + var docView = new NodeViewDesc(undefined, doc, outerDeco, innerDeco, dom, dom, dom, view, 0); + if (docView.contentDOM) docView.updateChildren(view, 0); + return docView; +} +var TextViewDesc = function (_NodeViewDesc) { + _inherits(TextViewDesc, _NodeViewDesc); + var _super5 = _createSuper(TextViewDesc); + function TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) { + _classCallCheck(this, TextViewDesc); + return _super5.call(this, parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view, 0); + } + _createClass(TextViewDesc, [{ + key: "parseRule", + value: function parseRule() { + var skip = this.nodeDOM.parentNode; + while (skip && skip != this.dom && !skip.pmIsDeco) skip = skip.parentNode; + return { + skip: skip || true + }; + } + }, { + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY || this.dirty != NOT_DIRTY && !this.inParent() || !node.sameMarkup(this.node)) return false; + this.updateOuterDeco(outerDeco); + if ((this.dirty != NOT_DIRTY || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) { + this.nodeDOM.nodeValue = node.text; + if (view.trackWrites == this.nodeDOM) view.trackWrites = null; + } + this.node = node; + this.dirty = NOT_DIRTY; + return true; + } + }, { + key: "inParent", + value: function inParent() { + var parentDOM = this.parent.contentDOM; + for (var n = this.nodeDOM; n; n = n.parentNode) if (n == parentDOM) return true; + return false; + } + }, { + key: "domFromPos", + value: function domFromPos(pos) { + return { + node: this.nodeDOM, + offset: pos + }; + } + }, { + key: "localPosFromDOM", + value: function localPosFromDOM(dom, offset, bias) { + if (dom == this.nodeDOM) return this.posAtStart + Math.min(offset, this.node.text.length); + return _get(_getPrototypeOf(TextViewDesc.prototype), "localPosFromDOM", this).call(this, dom, offset, bias); + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return mutation.type != "characterData" && mutation.type != "selection"; + } + }, { + key: "slice", + value: function slice(from, to, view) { + var node = this.node.cut(from, to), + dom = document.createTextNode(node.text); + return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view); + } + }, { + key: "markDirty", + value: function markDirty(from, to) { + _get(_getPrototypeOf(TextViewDesc.prototype), "markDirty", this).call(this, from, to); + if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY; + } + }, { + key: "domAtom", + get: function get() { + return false; + } + }, { + key: "isText", + value: function isText(text) { + return this.node.text == text; + } + }]); + return TextViewDesc; +}(NodeViewDesc); +var TrailingHackViewDesc = function (_ViewDesc5) { + _inherits(TrailingHackViewDesc, _ViewDesc5); + var _super6 = _createSuper(TrailingHackViewDesc); + function TrailingHackViewDesc() { + _classCallCheck(this, TrailingHackViewDesc); + return _super6.apply(this, arguments); + } + _createClass(TrailingHackViewDesc, [{ + key: "parseRule", + value: function parseRule() { + return { + ignore: true + }; + } + }, { + key: "matchesHack", + value: function matchesHack(nodeName) { + return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName; + } + }, { + key: "domAtom", + get: function get() { + return true; + } + }, { + key: "ignoreForCoords", + get: function get() { + return this.dom.nodeName == "IMG"; + } + }]); + return TrailingHackViewDesc; +}(ViewDesc); +var CustomNodeViewDesc = function (_NodeViewDesc2) { + _inherits(CustomNodeViewDesc, _NodeViewDesc2); + var _super7 = _createSuper(CustomNodeViewDesc); + function CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec, view, pos) { + var _this7; + _classCallCheck(this, CustomNodeViewDesc); + _this7 = _super7.call(this, parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos); + _this7.spec = spec; + return _this7; + } + _createClass(CustomNodeViewDesc, [{ + key: "update", + value: function update(node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY) return false; + if (this.spec.update) { + var result = this.spec.update(node, outerDeco, innerDeco); + if (result) this.updateInner(node, outerDeco, innerDeco, view); + return result; + } else if (!this.contentDOM && !node.isLeaf) { + return false; + } else { + return _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "update", this).call(this, node, outerDeco, innerDeco, view); + } + } + }, { + key: "selectNode", + value: function selectNode() { + this.spec.selectNode ? this.spec.selectNode() : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "selectNode", this).call(this); + } + }, { + key: "deselectNode", + value: function deselectNode() { + this.spec.deselectNode ? this.spec.deselectNode() : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "deselectNode", this).call(this); + } + }, { + key: "setSelection", + value: function setSelection(anchor, head, root, force) { + this.spec.setSelection ? this.spec.setSelection(anchor, head, root) : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "setSelection", this).call(this, anchor, head, root, force); + } + }, { + key: "destroy", + value: function destroy() { + if (this.spec.destroy) this.spec.destroy(); + _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "destroy", this).call(this); + } + }, { + key: "stopEvent", + value: function stopEvent(event) { + return this.spec.stopEvent ? this.spec.stopEvent(event) : false; + } + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : _get(_getPrototypeOf(CustomNodeViewDesc.prototype), "ignoreMutation", this).call(this, mutation); + } + }]); + return CustomNodeViewDesc; +}(NodeViewDesc); +function renderDescs(parentDOM, descs, view) { + var dom = parentDOM.firstChild, + written = false; + for (var i = 0; i < descs.length; i++) { + var desc = descs[i], + childDOM = desc.dom; + if (childDOM.parentNode == parentDOM) { + while (childDOM != dom) { + dom = rm(dom); + written = true; + } + dom = dom.nextSibling; + } else { + written = true; + parentDOM.insertBefore(childDOM, dom); + } + if (desc instanceof MarkViewDesc) { + var pos = dom ? dom.previousSibling : parentDOM.lastChild; + renderDescs(desc.contentDOM, desc.children, view); + dom = pos ? pos.nextSibling : parentDOM.firstChild; + } + } + while (dom) { + dom = rm(dom); + written = true; + } + if (written && view.trackWrites == parentDOM) view.trackWrites = null; +} +var OuterDecoLevel = function OuterDecoLevel(nodeName) { + if (nodeName) this.nodeName = nodeName; +}; +OuterDecoLevel.prototype = Object.create(null); +var noDeco = [new OuterDecoLevel()]; +function computeOuterDeco(outerDeco, node, needsWrap) { + if (outerDeco.length == 0) return noDeco; + var top = needsWrap ? noDeco[0] : new OuterDecoLevel(), + result = [top]; + for (var i = 0; i < outerDeco.length; i++) { + var attrs = outerDeco[i].type.attrs; + if (!attrs) continue; + if (attrs.nodeName) result.push(top = new OuterDecoLevel(attrs.nodeName)); + for (var name in attrs) { + var val = attrs[name]; + if (val == null) continue; + if (needsWrap && result.length == 1) result.push(top = new OuterDecoLevel(node.isInline ? "span" : "div")); + if (name == "class") top["class"] = (top["class"] ? top["class"] + " " : "") + val;else if (name == "style") top.style = (top.style ? top.style + ";" : "") + val;else if (name != "nodeName") top[name] = val; + } + } + return result; +} +function patchOuterDeco(outerDOM, nodeDOM, prevComputed, curComputed) { + if (prevComputed == noDeco && curComputed == noDeco) return nodeDOM; + var curDOM = nodeDOM; + for (var i = 0; i < curComputed.length; i++) { + var deco = curComputed[i], + prev = prevComputed[i]; + if (i) { + var parent = void 0; + if (prev && prev.nodeName == deco.nodeName && curDOM != outerDOM && (parent = curDOM.parentNode) && parent.nodeName.toLowerCase() == deco.nodeName) { + curDOM = parent; + } else { + parent = document.createElement(deco.nodeName); + parent.pmIsDeco = true; + parent.appendChild(curDOM); + prev = noDeco[0]; + curDOM = parent; + } + } + patchAttributes(curDOM, prev || noDeco[0], deco); + } + return curDOM; +} +function patchAttributes(dom, prev, cur) { + for (var name in prev) if (name != "class" && name != "style" && name != "nodeName" && !(name in cur)) dom.removeAttribute(name); + for (var _name in cur) if (_name != "class" && _name != "style" && _name != "nodeName" && cur[_name] != prev[_name]) dom.setAttribute(_name, cur[_name]); + if (prev["class"] != cur["class"]) { + var prevList = prev["class"] ? prev["class"].split(" ").filter(Boolean) : []; + var curList = cur["class"] ? cur["class"].split(" ").filter(Boolean) : []; + for (var i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) dom.classList.remove(prevList[i]); + for (var _i = 0; _i < curList.length; _i++) if (prevList.indexOf(curList[_i]) == -1) dom.classList.add(curList[_i]); + if (dom.classList.length == 0) dom.removeAttribute("class"); + } + if (prev.style != cur.style) { + if (prev.style) { + var prop = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, + m; + while (m = prop.exec(prev.style)) dom.style.removeProperty(m[1]); + } + if (cur.style) dom.style.cssText += cur.style; + } +} +function applyOuterDeco(dom, deco, node) { + return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1)); +} +function sameOuterDeco(a, b) { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) if (!a[i].type.eq(b[i].type)) return false; + return true; +} +function rm(dom) { + var next = dom.nextSibling; + dom.parentNode.removeChild(dom); + return next; +} +var ViewTreeUpdater = function () { + function ViewTreeUpdater(top, lock, view) { + _classCallCheck(this, ViewTreeUpdater); + this.lock = lock; + this.view = view; + this.index = 0; + this.stack = []; + this.changed = false; + this.top = top; + this.preMatch = preMatch(top.node.content, top); + } + _createClass(ViewTreeUpdater, [{ + key: "destroyBetween", + value: function destroyBetween(start, end) { + if (start == end) return; + for (var i = start; i < end; i++) this.top.children[i].destroy(); + this.top.children.splice(start, end - start); + this.changed = true; + } + }, { + key: "destroyRest", + value: function destroyRest() { + this.destroyBetween(this.index, this.top.children.length); + } + }, { + key: "syncToMarks", + value: function syncToMarks(marks, inline, view) { + var keep = 0, + depth = this.stack.length >> 1; + var maxKeep = Math.min(depth, marks.length); + while (keep < maxKeep && (keep == depth - 1 ? this.top : this.stack[keep + 1 << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) keep++; + while (keep < depth) { + this.destroyRest(); + this.top.dirty = NOT_DIRTY; + this.index = this.stack.pop(); + this.top = this.stack.pop(); + depth--; + } + while (depth < marks.length) { + this.stack.push(this.top, this.index + 1); + var found = -1; + for (var i = this.index; i < Math.min(this.index + 3, this.top.children.length); i++) { + var next = this.top.children[i]; + if (next.matchesMark(marks[depth]) && !this.isLocked(next.dom)) { + found = i; + break; + } + } + if (found > -1) { + if (found > this.index) { + this.changed = true; + this.destroyBetween(this.index, found); + } + this.top = this.top.children[this.index]; + } else { + var markDesc = MarkViewDesc.create(this.top, marks[depth], inline, view); + this.top.children.splice(this.index, 0, markDesc); + this.top = markDesc; + this.changed = true; + } + this.index = 0; + depth++; + } + } + }, { + key: "findNodeMatch", + value: function findNodeMatch(node, outerDeco, innerDeco, index) { + var found = -1, + targetDesc; + if (index >= this.preMatch.index && (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top && targetDesc.matchesNode(node, outerDeco, innerDeco)) { + found = this.top.children.indexOf(targetDesc, this.index); + } else { + for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) { + var child = this.top.children[i]; + if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) { + found = i; + break; + } + } + } + if (found < 0) return false; + this.destroyBetween(this.index, found); + this.index++; + return true; + } + }, { + key: "updateNodeAt", + value: function updateNodeAt(node, outerDeco, innerDeco, index, view) { + var child = this.top.children[index]; + if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY; + if (!child.update(node, outerDeco, innerDeco, view)) return false; + this.destroyBetween(this.index, index); + this.index++; + return true; + } + }, { + key: "findIndexWithChild", + value: function findIndexWithChild(domNode) { + for (;;) { + var parent = domNode.parentNode; + if (!parent) return -1; + if (parent == this.top.contentDOM) { + var desc = domNode.pmViewDesc; + if (desc) for (var i = this.index; i < this.top.children.length; i++) { + if (this.top.children[i] == desc) return i; + } + return -1; + } + domNode = parent; + } + } + }, { + key: "updateNextNode", + value: function updateNextNode(node, outerDeco, innerDeco, view, index, pos) { + for (var i = this.index; i < this.top.children.length; i++) { + var next = this.top.children[i]; + if (next instanceof NodeViewDesc) { + var _preMatch = this.preMatch.matched.get(next); + if (_preMatch != null && _preMatch != index) return false; + var nextDOM = next.dom, + updated = void 0; + var locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && next.dirty != NODE_DIRTY && sameOuterDeco(outerDeco, next.outerDeco)); + if (!locked && next.update(node, outerDeco, innerDeco, view)) { + this.destroyBetween(this.index, i); + if (next.dom != nextDOM) this.changed = true; + this.index++; + return true; + } else if (!locked && (updated = this.recreateWrapper(next, node, outerDeco, innerDeco, view, pos))) { + this.destroyBetween(this.index, i); + this.top.children[this.index] = updated; + if (updated.contentDOM) { + updated.dirty = CONTENT_DIRTY; + updated.updateChildren(view, pos + 1); + updated.dirty = NOT_DIRTY; + } + this.changed = true; + this.index++; + return true; + } + break; + } + } + return false; + } + }, { + key: "recreateWrapper", + value: function recreateWrapper(next, node, outerDeco, innerDeco, view, pos) { + if (next.dirty || node.isAtom || !next.children.length || !next.node.content.eq(node.content) || !sameOuterDeco(outerDeco, next.outerDeco) || !innerDeco.eq(next.innerDeco)) return null; + var wrapper = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); + if (wrapper.contentDOM) { + wrapper.children = next.children; + next.children = []; + var _iterator = _createForOfIteratorHelper(wrapper.children), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var ch = _step.value; + ch.parent = wrapper; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + next.destroy(); + return wrapper; + } + }, { + key: "addNode", + value: function addNode(node, outerDeco, innerDeco, view, pos) { + var desc = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); + if (desc.contentDOM) desc.updateChildren(view, pos + 1); + this.top.children.splice(this.index++, 0, desc); + this.changed = true; + } + }, { + key: "placeWidget", + value: function placeWidget(widget, view, pos) { + var next = this.index < this.top.children.length ? this.top.children[this.index] : null; + if (next && next.matchesWidget(widget) && (widget == next.widget || !next.widget.type.toDOM.parentNode)) { + this.index++; + } else { + var desc = new WidgetViewDesc(this.top, widget, view, pos); + this.top.children.splice(this.index++, 0, desc); + this.changed = true; + } + } + }, { + key: "addTextblockHacks", + value: function addTextblockHacks() { + var lastChild = this.top.children[this.index - 1], + parent = this.top; + while (lastChild instanceof MarkViewDesc) { + parent = lastChild; + lastChild = parent.children[parent.children.length - 1]; + } + if (!lastChild || !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(lastChild.node.text)) { + if ((safari || chrome) && lastChild && lastChild.dom.contentEditable == "false") this.addHackNode("IMG", parent); + this.addHackNode("BR", this.top); + } + } + }, { + key: "addHackNode", + value: function addHackNode(nodeName, parent) { + if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) { + this.index++; + } else { + var dom = document.createElement(nodeName); + if (nodeName == "IMG") { + dom.className = "ProseMirror-separator"; + dom.alt = ""; + } + if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak"; + var hack = new TrailingHackViewDesc(this.top, [], dom, null); + if (parent != this.top) parent.children.push(hack);else parent.children.splice(this.index++, 0, hack); + this.changed = true; + } + } + }, { + key: "isLocked", + value: function isLocked(node) { + return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode)); + } + }]); + return ViewTreeUpdater; +}(); +function preMatch(frag, parentDesc) { + var curDesc = parentDesc, + descI = curDesc.children.length; + var fI = frag.childCount, + matched = new Map(), + matches = []; + outer: while (fI > 0) { + var desc = void 0; + for (;;) { + if (descI) { + var next = curDesc.children[descI - 1]; + if (next instanceof MarkViewDesc) { + curDesc = next; + descI = next.children.length; + } else { + desc = next; + descI--; + break; + } + } else if (curDesc == parentDesc) { + break outer; + } else { + descI = curDesc.parent.children.indexOf(curDesc); + curDesc = curDesc.parent; + } + } + var node = desc.node; + if (!node) continue; + if (node != frag.child(fI - 1)) break; + --fI; + matched.set(desc, fI); + matches.push(desc); + } + return { + index: fI, + matched: matched, + matches: matches.reverse() + }; +} +function compareSide(a, b) { + return a.type.side - b.type.side; +} +function iterDeco(parent, deco, onWidget, onNode) { + var locals = deco.locals(parent), + offset = 0; + if (locals.length == 0) { + for (var i = 0; i < parent.childCount; i++) { + var child = parent.child(i); + onNode(child, locals, deco.forChild(offset, child), i); + offset += child.nodeSize; + } + return; + } + var decoIndex = 0, + active = [], + restNode = null; + for (var parentIndex = 0;;) { + var widget = void 0, + widgets = void 0; + while (decoIndex < locals.length && locals[decoIndex].to == offset) { + var next = locals[decoIndex++]; + if (next.widget) { + if (!widget) widget = next;else (widgets || (widgets = [widget])).push(next); + } + } + if (widget) { + if (widgets) { + widgets.sort(compareSide); + for (var _i2 = 0; _i2 < widgets.length; _i2++) onWidget(widgets[_i2], parentIndex, !!restNode); + } else { + onWidget(widget, parentIndex, !!restNode); + } + } + var _child = void 0, + index = void 0; + if (restNode) { + index = -1; + _child = restNode; + restNode = null; + } else if (parentIndex < parent.childCount) { + index = parentIndex; + _child = parent.child(parentIndex++); + } else { + break; + } + for (var _i3 = 0; _i3 < active.length; _i3++) if (active[_i3].to <= offset) active.splice(_i3--, 1); + while (decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset) active.push(locals[decoIndex++]); + var end = offset + _child.nodeSize; + if (_child.isText) { + var cutAt = end; + if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from; + for (var _i4 = 0; _i4 < active.length; _i4++) if (active[_i4].to < cutAt) cutAt = active[_i4].to; + if (cutAt < end) { + restNode = _child.cut(cutAt - offset); + _child = _child.cut(0, cutAt - offset); + end = cutAt; + index = -1; + } + } else { + while (decoIndex < locals.length && locals[decoIndex].to < end) decoIndex++; + } + var outerDeco = _child.isInline && !_child.isLeaf ? active.filter(function (d) { + return !d.inline; + }) : active.slice(); + onNode(_child, outerDeco, deco.forChild(offset, _child), index); + offset = end; + } +} +function iosHacks(dom) { + if (dom.nodeName == "UL" || dom.nodeName == "OL") { + var oldCSS = dom.style.cssText; + dom.style.cssText = oldCSS + "; list-style: square !important"; + window.getComputedStyle(dom).listStyle; + dom.style.cssText = oldCSS; + } +} +function findTextInFragment(frag, text, from, to) { + for (var i = 0, pos = 0; i < frag.childCount && pos <= to;) { + var child = frag.child(i++), + childStart = pos; + pos += child.nodeSize; + if (!child.isText) continue; + var str = child.text; + while (i < frag.childCount) { + var next = frag.child(i++); + pos += next.nodeSize; + if (!next.isText) break; + str += next.text; + } + if (pos >= from) { + if (pos >= to && str.slice(to - text.length - childStart, to - childStart) == text) return to - text.length; + var found = childStart < to ? str.lastIndexOf(text, to - childStart - 1) : -1; + if (found >= 0 && found + text.length + childStart >= from) return childStart + found; + if (from == to && str.length >= to + text.length - childStart && str.slice(to - childStart, to - childStart + text.length) == text) return to; + } + } + return -1; +} +function replaceNodes(nodes, from, to, view, replacement) { + var result = []; + for (var i = 0, off = 0; i < nodes.length; i++) { + var child = nodes[i], + start = off, + end = off += child.size; + if (start >= to || end <= from) { + result.push(child); + } else { + if (start < from) result.push(child.slice(0, from - start, view)); + if (replacement) { + result.push(replacement); + replacement = undefined; + } + if (end > to) result.push(child.slice(to - start, child.size, view)); + } + } + return result; +} +function selectionFromDOM(view) { + var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var domSel = view.domSelectionRange(), + doc = view.state.doc; + if (!domSel.focusNode) return null; + var nearestDesc = view.docView.nearestDesc(domSel.focusNode), + inWidget = nearestDesc && nearestDesc.size == 0; + var head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1); + if (head < 0) return null; + var $head = doc.resolve(head), + anchor, + selection; + if (selectionCollapsed(domSel)) { + anchor = head; + while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent; + var nearestDescNode = nearestDesc.node; + if (nearestDesc && nearestDescNode.isAtom && prosemirrorState.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) { + var pos = nearestDesc.posBefore; + selection = new prosemirrorState.NodeSelection(head == pos ? $head : doc.resolve(pos)); + } + } else { + if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) { + var min = head, + max = head; + for (var i = 0; i < domSel.rangeCount; i++) { + var range = domSel.getRangeAt(i); + min = Math.min(min, view.docView.posFromDOM(range.startContainer, range.startOffset, 1)); + max = Math.max(max, view.docView.posFromDOM(range.endContainer, range.endOffset, -1)); + } + if (min < 0) return null; + var _ref3 = max == view.state.selection.anchor ? [max, min] : [min, max]; + var _ref4 = _slicedToArray(_ref3, 2); + anchor = _ref4[0]; + head = _ref4[1]; + $head = doc.resolve(head); + } else { + anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1); + } + if (anchor < 0) return null; + } + var $anchor = doc.resolve(anchor); + if (!selection) { + var bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1; + selection = selectionBetween(view, $anchor, $head, bias); + } + return selection; +} +function editorOwnsSelection(view) { + return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom); +} +function selectionToDOM(view) { + var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var sel = view.state.selection; + syncNodeSelection(view, sel); + if (!editorOwnsSelection(view)) return; + if (!force && view.input.mouseDown && view.input.mouseDown.allowDefault && chrome) { + var domSel = view.domSelectionRange(), + curSel = view.domObserver.currentSelection; + if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset)) { + view.input.mouseDown.delayedSelectionSync = true; + view.domObserver.setCurSelection(); + return; + } + } + view.domObserver.disconnectSelection(); + if (view.cursorWrapper) { + selectCursorWrapper(view); + } else { + var anchor = sel.anchor, + head = sel.head, + resetEditableFrom, + resetEditableTo; + if (brokenSelectBetweenUneditable && !(sel instanceof prosemirrorState.TextSelection)) { + if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from); + if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to); + } + view.docView.setSelection(anchor, head, view.root, force); + if (brokenSelectBetweenUneditable) { + if (resetEditableFrom) resetEditable(resetEditableFrom); + if (resetEditableTo) resetEditable(resetEditableTo); + } + if (sel.visible) { + view.dom.classList.remove("ProseMirror-hideselection"); + } else { + view.dom.classList.add("ProseMirror-hideselection"); + if ("onselectionchange" in document) removeClassOnSelectionChange(view); + } + } + view.domObserver.setCurSelection(); + view.domObserver.connectSelection(); +} +var brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63; +function temporarilyEditableNear(view, pos) { + var _view$docView$domFrom3 = view.docView.domFromPos(pos, 0), + node = _view$docView$domFrom3.node, + offset = _view$docView$domFrom3.offset; + var after = offset < node.childNodes.length ? node.childNodes[offset] : null; + var before = offset ? node.childNodes[offset - 1] : null; + if (safari && after && after.contentEditable == "false") return setEditable(after); + if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) { + if (after) return setEditable(after);else if (before) return setEditable(before); + } +} +function setEditable(element) { + element.contentEditable = "true"; + if (safari && element.draggable) { + element.draggable = false; + element.wasDraggable = true; + } + return element; +} +function resetEditable(element) { + element.contentEditable = "false"; + if (element.wasDraggable) { + element.draggable = true; + element.wasDraggable = null; + } +} +function removeClassOnSelectionChange(view) { + var doc = view.dom.ownerDocument; + doc.removeEventListener("selectionchange", view.input.hideSelectionGuard); + var domSel = view.domSelectionRange(); + var node = domSel.anchorNode, + offset = domSel.anchorOffset; + doc.addEventListener("selectionchange", view.input.hideSelectionGuard = function () { + if (domSel.anchorNode != node || domSel.anchorOffset != offset) { + doc.removeEventListener("selectionchange", view.input.hideSelectionGuard); + setTimeout(function () { + if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection"); + }, 20); + } + }); +} +function selectCursorWrapper(view) { + var domSel = view.domSelection(), + range = document.createRange(); + if (!domSel) return; + var node = view.cursorWrapper.dom, + img = node.nodeName == "IMG"; + if (img) range.setStart(node.parentNode, domIndex(node) + 1);else range.setStart(node, 0); + range.collapse(true); + domSel.removeAllRanges(); + domSel.addRange(range); + if (!img && !view.state.selection.visible && ie && ie_version <= 11) { + node.disabled = true; + node.disabled = false; + } +} +function syncNodeSelection(view, sel) { + if (sel instanceof prosemirrorState.NodeSelection) { + var desc = view.docView.descAt(sel.from); + if (desc != view.lastSelectedViewDesc) { + clearNodeSelection(view); + if (desc) desc.selectNode(); + view.lastSelectedViewDesc = desc; + } + } else { + clearNodeSelection(view); + } +} +function clearNodeSelection(view) { + if (view.lastSelectedViewDesc) { + if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode(); + view.lastSelectedViewDesc = undefined; + } +} +function selectionBetween(view, $anchor, $head, bias) { + return view.someProp("createSelectionBetween", function (f) { + return f(view, $anchor, $head); + }) || prosemirrorState.TextSelection.between($anchor, $head, bias); +} +function hasFocusAndSelection(view) { + if (view.editable && !view.hasFocus()) return false; + return hasSelection(view); +} +function hasSelection(view) { + var sel = view.domSelectionRange(); + if (!sel.anchorNode) return false; + try { + return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode)); + } catch (_) { + return false; + } +} +function anchorInRightPlace(view) { + var anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0); + var domSel = view.domSelectionRange(); + return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset); +} +function moveSelectionBlock(state, dir) { + var _state$selection = state.selection, + $anchor = _state$selection.$anchor, + $head = _state$selection.$head; + var $side = dir > 0 ? $anchor.max($head) : $anchor.min($head); + var $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null; + return $start && prosemirrorState.Selection.findFrom($start, dir); +} +function apply(view, sel) { + view.dispatch(view.state.tr.setSelection(sel).scrollIntoView()); + return true; +} +function selectHorizontally(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirrorState.TextSelection) { + if (mods.indexOf("s") > -1) { + var $head = sel.$head, + node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter; + if (!node || node.isText || !node.isLeaf) return false; + var $newHead = view.state.doc.resolve($head.pos + node.nodeSize * (dir < 0 ? -1 : 1)); + return apply(view, new prosemirrorState.TextSelection(sel.$anchor, $newHead)); + } else if (!sel.empty) { + return false; + } else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) { + var next = moveSelectionBlock(view.state, dir); + if (next && next instanceof prosemirrorState.NodeSelection) return apply(view, next); + return false; + } else if (!(mac && mods.indexOf("m") > -1)) { + var _$head = sel.$head, + _node = _$head.textOffset ? null : dir < 0 ? _$head.nodeBefore : _$head.nodeAfter, + desc; + if (!_node || _node.isText) return false; + var nodePos = dir < 0 ? _$head.pos - _node.nodeSize : _$head.pos; + if (!(_node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false; + if (prosemirrorState.NodeSelection.isSelectable(_node)) { + return apply(view, new prosemirrorState.NodeSelection(dir < 0 ? view.state.doc.resolve(_$head.pos - _node.nodeSize) : _$head)); + } else if (webkit) { + return apply(view, new prosemirrorState.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + _node.nodeSize))); + } else { + return false; + } + } + } else if (sel instanceof prosemirrorState.NodeSelection && sel.node.isInline) { + return apply(view, new prosemirrorState.TextSelection(dir > 0 ? sel.$to : sel.$from)); + } else { + var _next = moveSelectionBlock(view.state, dir); + if (_next) return apply(view, _next); + return false; + } +} +function nodeLen(node) { + return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; +} +function isIgnorable(dom, dir) { + var desc = dom.pmViewDesc; + return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR"); +} +function skipIgnoredNodes(view, dir) { + return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view); +} +function skipIgnoredNodesBefore(view) { + var sel = view.domSelectionRange(); + var node = sel.focusNode, + offset = sel.focusOffset; + if (!node) return; + var moveNode, + moveOffset, + force = false; + if (gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset], -1)) force = true; + for (;;) { + if (offset > 0) { + if (node.nodeType != 1) { + break; + } else { + var before = node.childNodes[offset - 1]; + if (isIgnorable(before, -1)) { + moveNode = node; + moveOffset = --offset; + } else if (before.nodeType == 3) { + node = before; + offset = node.nodeValue.length; + } else break; + } + } else if (isBlockNode(node)) { + break; + } else { + var prev = node.previousSibling; + while (prev && isIgnorable(prev, -1)) { + moveNode = node.parentNode; + moveOffset = domIndex(prev); + prev = prev.previousSibling; + } + if (!prev) { + node = node.parentNode; + if (node == view.dom) break; + offset = 0; + } else { + node = prev; + offset = nodeLen(node); + } + } + } + if (force) setSelFocus(view, node, offset);else if (moveNode) setSelFocus(view, moveNode, moveOffset); +} +function skipIgnoredNodesAfter(view) { + var sel = view.domSelectionRange(); + var node = sel.focusNode, + offset = sel.focusOffset; + if (!node) return; + var len = nodeLen(node); + var moveNode, moveOffset; + for (;;) { + if (offset < len) { + if (node.nodeType != 1) break; + var after = node.childNodes[offset]; + if (isIgnorable(after, 1)) { + moveNode = node; + moveOffset = ++offset; + } else break; + } else if (isBlockNode(node)) { + break; + } else { + var next = node.nextSibling; + while (next && isIgnorable(next, 1)) { + moveNode = next.parentNode; + moveOffset = domIndex(next) + 1; + next = next.nextSibling; + } + if (!next) { + node = node.parentNode; + if (node == view.dom) break; + offset = len = 0; + } else { + node = next; + offset = 0; + len = nodeLen(node); + } + } + } + if (moveNode) setSelFocus(view, moveNode, moveOffset); +} +function isBlockNode(dom) { + var desc = dom.pmViewDesc; + return desc && desc.node && desc.node.isBlock; +} +function textNodeAfter(node, offset) { + while (node && offset == node.childNodes.length && !hasBlockDesc(node)) { + offset = domIndex(node) + 1; + node = node.parentNode; + } + while (node && offset < node.childNodes.length) { + var next = node.childNodes[offset]; + if (next.nodeType == 3) return next; + if (next.nodeType == 1 && next.contentEditable == "false") break; + node = next; + offset = 0; + } +} +function textNodeBefore(node, offset) { + while (node && !offset && !hasBlockDesc(node)) { + offset = domIndex(node); + node = node.parentNode; + } + while (node && offset) { + var next = node.childNodes[offset - 1]; + if (next.nodeType == 3) return next; + if (next.nodeType == 1 && next.contentEditable == "false") break; + node = next; + offset = node.childNodes.length; + } +} +function setSelFocus(view, node, offset) { + if (node.nodeType != 3) { + var before, after; + if (after = textNodeAfter(node, offset)) { + node = after; + offset = 0; + } else if (before = textNodeBefore(node, offset)) { + node = before; + offset = before.nodeValue.length; + } + } + var sel = view.domSelection(); + if (!sel) return; + if (selectionCollapsed(sel)) { + var range = document.createRange(); + range.setEnd(node, offset); + range.setStart(node, offset); + sel.removeAllRanges(); + sel.addRange(range); + } else if (sel.extend) { + sel.extend(node, offset); + } + view.domObserver.setCurSelection(); + var state = view.state; + setTimeout(function () { + if (view.state == state) selectionToDOM(view); + }, 50); +} +function findDirection(view, pos) { + var $pos = view.state.doc.resolve(pos); + if (!(chrome || windows) && $pos.parent.inlineContent) { + var coords = view.coordsAtPos(pos); + if (pos > $pos.start()) { + var before = view.coordsAtPos(pos - 1); + var mid = (before.top + before.bottom) / 2; + if (mid > coords.top && mid < coords.bottom && Math.abs(before.left - coords.left) > 1) return before.left < coords.left ? "ltr" : "rtl"; + } + if (pos < $pos.end()) { + var after = view.coordsAtPos(pos + 1); + var _mid = (after.top + after.bottom) / 2; + if (_mid > coords.top && _mid < coords.bottom && Math.abs(after.left - coords.left) > 1) return after.left > coords.left ? "ltr" : "rtl"; + } + } + var computed = getComputedStyle(view.dom).direction; + return computed == "rtl" ? "rtl" : "ltr"; +} +function selectVertically(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirrorState.TextSelection && !sel.empty || mods.indexOf("s") > -1) return false; + if (mac && mods.indexOf("m") > -1) return false; + var $from = sel.$from, + $to = sel.$to; + if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) { + var next = moveSelectionBlock(view.state, dir); + if (next && next instanceof prosemirrorState.NodeSelection) return apply(view, next); + } + if (!$from.parent.inlineContent) { + var side = dir < 0 ? $from : $to; + var beyond = sel instanceof prosemirrorState.AllSelection ? prosemirrorState.Selection.near(side, dir) : prosemirrorState.Selection.findFrom(side, dir); + return beyond ? apply(view, beyond) : false; + } + return false; +} +function stopNativeHorizontalDelete(view, dir) { + if (!(view.state.selection instanceof prosemirrorState.TextSelection)) return true; + var _view$state$selection2 = view.state.selection, + $head = _view$state$selection2.$head, + $anchor = _view$state$selection2.$anchor, + empty = _view$state$selection2.empty; + if (!$head.sameParent($anchor)) return true; + if (!empty) return false; + if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) return true; + var nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter); + if (nextNode && !nextNode.isText) { + var tr = view.state.tr; + if (dir < 0) tr["delete"]($head.pos - nextNode.nodeSize, $head.pos);else tr["delete"]($head.pos, $head.pos + nextNode.nodeSize); + view.dispatch(tr); + return true; + } + return false; +} +function switchEditable(view, node, state) { + view.domObserver.stop(); + node.contentEditable = state; + view.domObserver.start(); +} +function safariDownArrowBug(view) { + if (!safari || view.state.selection.$head.parentOffset > 0) return false; + var _view$domSelectionRan3 = view.domSelectionRange(), + focusNode = _view$domSelectionRan3.focusNode, + focusOffset = _view$domSelectionRan3.focusOffset; + if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") { + var child = focusNode.firstChild; + switchEditable(view, child, "true"); + setTimeout(function () { + return switchEditable(view, child, "false"); + }, 20); + } + return false; +} +function getMods(event) { + var result = ""; + if (event.ctrlKey) result += "c"; + if (event.metaKey) result += "m"; + if (event.altKey) result += "a"; + if (event.shiftKey) result += "s"; + return result; +} +function captureKeyDown(view, event) { + var code = event.keyCode, + mods = getMods(event); + if (code == 8 || mac && code == 72 && mods == "c") { + return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodes(view, -1); + } else if (code == 46 && !event.shiftKey || mac && code == 68 && mods == "c") { + return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodes(view, 1); + } else if (code == 13 || code == 27) { + return true; + } else if (code == 37 || mac && code == 66 && mods == "c") { + var dir = code == 37 ? findDirection(view, view.state.selection.from) == "ltr" ? -1 : 1 : -1; + return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir); + } else if (code == 39 || mac && code == 70 && mods == "c") { + var _dir = code == 39 ? findDirection(view, view.state.selection.from) == "ltr" ? 1 : -1 : 1; + return selectHorizontally(view, _dir, mods) || skipIgnoredNodes(view, _dir); + } else if (code == 38 || mac && code == 80 && mods == "c") { + return selectVertically(view, -1, mods) || skipIgnoredNodes(view, -1); + } else if (code == 40 || mac && code == 78 && mods == "c") { + return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodes(view, 1); + } else if (mods == (mac ? "m" : "c") && (code == 66 || code == 73 || code == 89 || code == 90)) { + return true; + } + return false; +} +function serializeForClipboard(view, slice) { + view.someProp("transformCopied", function (f) { + slice = f(slice, view); + }); + var context = [], + _slice = slice, + content = _slice.content, + openStart = _slice.openStart, + openEnd = _slice.openEnd; + while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) { + openStart--; + openEnd--; + var node = content.firstChild; + context.push(node.type.name, node.attrs != node.type.defaultAttrs ? node.attrs : null); + content = node.content; + } + var serializer = view.someProp("clipboardSerializer") || prosemirrorModel.DOMSerializer.fromSchema(view.state.schema); + var doc = detachedDoc(), + wrap = doc.createElement("div"); + wrap.appendChild(serializer.serializeFragment(content, { + document: doc + })); + var firstChild = wrap.firstChild, + needsWrap, + wrappers = 0; + while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) { + for (var i = needsWrap.length - 1; i >= 0; i--) { + var wrapper = doc.createElement(needsWrap[i]); + while (wrap.firstChild) wrapper.appendChild(wrap.firstChild); + wrap.appendChild(wrapper); + wrappers++; + } + firstChild = wrap.firstChild; + } + if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", "".concat(openStart, " ").concat(openEnd).concat(wrappers ? " -".concat(wrappers) : "", " ").concat(JSON.stringify(context))); + var text = view.someProp("clipboardTextSerializer", function (f) { + return f(slice, view); + }) || slice.content.textBetween(0, slice.content.size, "\n\n"); + return { + dom: wrap, + text: text, + slice: slice + }; +} +function parseFromClipboard(view, text, html, plainText, $context) { + var inCode = $context.parent.type.spec.code; + var dom, slice; + if (!html && !text) return null; + var asText = text && (plainText || inCode || !html); + if (asText) { + view.someProp("transformPastedText", function (f) { + text = f(text, inCode || plainText, view); + }); + if (inCode) return text ? new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : prosemirrorModel.Slice.empty; + var parsed = view.someProp("clipboardTextParser", function (f) { + return f(text, $context, plainText, view); + }); + if (parsed) { + slice = parsed; + } else { + var marks = $context.marks(); + var schema = view.state.schema, + serializer = prosemirrorModel.DOMSerializer.fromSchema(schema); + dom = document.createElement("div"); + text.split(/(?:\r\n?|\n)+/).forEach(function (block) { + var p = dom.appendChild(document.createElement("p")); + if (block) p.appendChild(serializer.serializeNode(schema.text(block, marks))); + }); + } + } else { + view.someProp("transformPastedHTML", function (f) { + html = f(html, view); + }); + dom = readHTML(html); + if (webkit) restoreReplacedSpaces(dom); + } + var contextNode = dom && dom.querySelector("[data-pm-slice]"); + var sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || ""); + if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0; i--) { + var child = dom.firstChild; + while (child && child.nodeType != 1) child = child.nextSibling; + if (!child) break; + dom = child; + } + if (!slice) { + var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema); + slice = parser.parseSlice(dom, { + preserveWhitespace: !!(asText || sliceData), + context: $context, + ruleFromNode: function ruleFromNode(dom) { + if (dom.nodeName == "BR" && !dom.nextSibling && dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) return { + ignore: true + }; + return null; + } + }); + } + if (sliceData) { + slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[4]); + } else { + slice = prosemirrorModel.Slice.maxOpen(normalizeSiblings(slice.content, $context), true); + if (slice.openStart || slice.openEnd) { + var openStart = 0, + openEnd = 0; + for (var node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating; openStart++, node = node.firstChild) {} + for (var _node2 = slice.content.lastChild; openEnd < slice.openEnd && !_node2.type.spec.isolating; openEnd++, _node2 = _node2.lastChild) {} + slice = closeSlice(slice, openStart, openEnd); + } + } + view.someProp("transformPasted", function (f) { + slice = f(slice, view); + }); + return slice; +} +var inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i; +function normalizeSiblings(fragment, $context) { + if (fragment.childCount < 2) return fragment; + var _loop = function _loop() { + var parent = $context.node(d); + var match = parent.contentMatchAt($context.index(d)); + var lastWrap, + result = []; + fragment.forEach(function (node) { + if (!result) return; + var wrap = match.findWrapping(node.type), + inLast; + if (!wrap) return result = null; + if (inLast = result.length && lastWrap.length && addToSibling(wrap, lastWrap, node, result[result.length - 1], 0)) { + result[result.length - 1] = inLast; + } else { + if (result.length) result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length); + var wrapped = withWrappers(node, wrap); + result.push(wrapped); + match = match.matchType(wrapped.type); + lastWrap = wrap; + } + }); + if (result) return { + v: prosemirrorModel.Fragment.from(result) + }; + }, + _ret; + for (var d = $context.depth; d >= 0; d--) { + _ret = _loop(); + if (_ret) return _ret.v; + } + return fragment; +} +function withWrappers(node, wrap) { + var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + for (var i = wrap.length - 1; i >= from; i--) node = wrap[i].create(null, prosemirrorModel.Fragment.from(node)); + return node; +} +function addToSibling(wrap, lastWrap, node, sibling, depth) { + if (depth < wrap.length && depth < lastWrap.length && wrap[depth] == lastWrap[depth]) { + var inner = addToSibling(wrap, lastWrap, node, sibling.lastChild, depth + 1); + if (inner) return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner)); + var match = sibling.contentMatchAt(sibling.childCount); + if (match.matchType(depth == wrap.length - 1 ? node.type : wrap[depth + 1])) return sibling.copy(sibling.content.append(prosemirrorModel.Fragment.from(withWrappers(node, wrap, depth + 1)))); + } +} +function closeRight(node, depth) { + if (depth == 0) return node; + var fragment = node.content.replaceChild(node.childCount - 1, closeRight(node.lastChild, depth - 1)); + var fill = node.contentMatchAt(node.childCount).fillBefore(prosemirrorModel.Fragment.empty, true); + return node.copy(fragment.append(fill)); +} +function closeRange(fragment, side, from, to, depth, openEnd) { + var node = side < 0 ? fragment.firstChild : fragment.lastChild, + inner = node.content; + if (fragment.childCount > 1) openEnd = 0; + if (depth < to - 1) inner = closeRange(inner, side, from, to, depth + 1, openEnd); + if (depth >= from) inner = side < 0 ? node.contentMatchAt(0).fillBefore(inner, openEnd <= depth).append(inner) : inner.append(node.contentMatchAt(node.childCount).fillBefore(prosemirrorModel.Fragment.empty, true)); + return fragment.replaceChild(side < 0 ? 0 : fragment.childCount - 1, node.copy(inner)); +} +function closeSlice(slice, openStart, openEnd) { + if (openStart < slice.openStart) slice = new prosemirrorModel.Slice(closeRange(slice.content, -1, openStart, slice.openStart, 0, slice.openEnd), openStart, slice.openEnd); + if (openEnd < slice.openEnd) slice = new prosemirrorModel.Slice(closeRange(slice.content, 1, openEnd, slice.openEnd, 0, 0), slice.openStart, openEnd); + return slice; +} +var wrapMap = { + thead: ["table"], + tbody: ["table"], + tfoot: ["table"], + caption: ["table"], + colgroup: ["table"], + col: ["table", "colgroup"], + tr: ["table", "tbody"], + td: ["table", "tbody", "tr"], + th: ["table", "tbody", "tr"] +}; +var _detachedDoc = null; +function detachedDoc() { + return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title")); +} +function maybeWrapTrusted(html) { + var trustedTypes = window.trustedTypes; + if (!trustedTypes) return html; + return trustedTypes.createPolicy("detachedDocument", { + createHTML: function createHTML(s) { + return s; + } + }).createHTML(html); +} +function readHTML(html) { + var metas = /^(\s*]*>)*/.exec(html); + if (metas) html = html.slice(metas[0].length); + var elt = detachedDoc().createElement("div"); + var firstTag = /<([a-z][^>\s]+)/i.exec(html), + wrap; + if (wrap = firstTag && wrapMap[firstTag[1].toLowerCase()]) html = wrap.map(function (n) { + return "<" + n + ">"; + }).join("") + html + wrap.map(function (n) { + return ""; + }).reverse().join(""); + elt.innerHTML = maybeWrapTrusted(html); + if (wrap) for (var i = 0; i < wrap.length; i++) elt = elt.querySelector(wrap[i]) || elt; + return elt; +} +function restoreReplacedSpaces(dom) { + var nodes = dom.querySelectorAll(chrome ? "span:not([class]):not([style])" : "span.Apple-converted-space"); + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + if (node.childNodes.length == 1 && node.textContent == "\xA0" && node.parentNode) node.parentNode.replaceChild(dom.ownerDocument.createTextNode(" "), node); + } +} +function addContext(slice, context) { + if (!slice.size) return slice; + var schema = slice.content.firstChild.type.schema, + array; + try { + array = JSON.parse(context); + } catch (e) { + return slice; + } + var content = slice.content, + openStart = slice.openStart, + openEnd = slice.openEnd; + for (var i = array.length - 2; i >= 0; i -= 2) { + var type = schema.nodes[array[i]]; + if (!type || type.hasRequiredAttrs()) break; + content = prosemirrorModel.Fragment.from(type.create(array[i + 1], content)); + openStart++; + openEnd++; + } + return new prosemirrorModel.Slice(content, openStart, openEnd); +} +var handlers = {}; +var editHandlers = {}; +var passiveHandlers = { + touchstart: true, + touchmove: true +}; +var InputState = _createClass(function InputState() { + _classCallCheck(this, InputState); + this.shiftKey = false; + this.mouseDown = null; + this.lastKeyCode = null; + this.lastKeyCodeTime = 0; + this.lastClick = { + time: 0, + x: 0, + y: 0, + type: "" + }; + this.lastSelectionOrigin = null; + this.lastSelectionTime = 0; + this.lastIOSEnter = 0; + this.lastIOSEnterFallbackTimeout = -1; + this.lastFocus = 0; + this.lastTouch = 0; + this.lastAndroidDelete = 0; + this.composing = false; + this.compositionNode = null; + this.composingTimeout = -1; + this.compositionNodes = []; + this.compositionEndedAt = -2e8; + this.compositionID = 1; + this.compositionPendingChanges = 0; + this.domChangeCount = 0; + this.eventHandlers = Object.create(null); + this.hideSelectionGuard = null; +}); +function initInput(view) { + var _loop2 = function _loop2() { + var handler = handlers[event]; + view.dom.addEventListener(event, view.input.eventHandlers[event] = function (event) { + if (eventBelongsToView(view, event) && !runCustomHandler(view, event) && (view.editable || !(event.type in editHandlers))) handler(view, event); + }, passiveHandlers[event] ? { + passive: true + } : undefined); + }; + for (var event in handlers) { + _loop2(); + } + if (safari) view.dom.addEventListener("input", function () { + return null; + }); + ensureListeners(view); +} +function setSelectionOrigin(view, origin) { + view.input.lastSelectionOrigin = origin; + view.input.lastSelectionTime = Date.now(); +} +function destroyInput(view) { + view.domObserver.stop(); + for (var type in view.input.eventHandlers) view.dom.removeEventListener(type, view.input.eventHandlers[type]); + clearTimeout(view.input.composingTimeout); + clearTimeout(view.input.lastIOSEnterFallbackTimeout); +} +function ensureListeners(view) { + view.someProp("handleDOMEvents", function (currentHandlers) { + for (var type in currentHandlers) if (!view.input.eventHandlers[type]) view.dom.addEventListener(type, view.input.eventHandlers[type] = function (event) { + return runCustomHandler(view, event); + }); + }); +} +function runCustomHandler(view, event) { + return view.someProp("handleDOMEvents", function (handlers) { + var handler = handlers[event.type]; + return handler ? handler(view, event) || event.defaultPrevented : false; + }); +} +function eventBelongsToView(view, event) { + if (!event.bubbles) return true; + if (event.defaultPrevented) return false; + for (var node = event.target; node != view.dom; node = node.parentNode) if (!node || node.nodeType == 11 || node.pmViewDesc && node.pmViewDesc.stopEvent(event)) return false; + return true; +} +function _dispatchEvent(view, event) { + if (!runCustomHandler(view, event) && handlers[event.type] && (view.editable || !(event.type in editHandlers))) handlers[event.type](view, event); +} +editHandlers.keydown = function (view, _event) { + var event = _event; + view.input.shiftKey = event.keyCode == 16 || event.shiftKey; + if (inOrNearComposition(view, event)) return; + view.input.lastKeyCode = event.keyCode; + view.input.lastKeyCodeTime = Date.now(); + if (android && chrome && event.keyCode == 13) return; + if (view.domObserver.selectionChanged(view.domSelectionRange())) view.domObserver.flush();else if (event.keyCode != 229) view.domObserver.forceFlush(); + if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) { + var now = Date.now(); + view.input.lastIOSEnter = now; + view.input.lastIOSEnterFallbackTimeout = setTimeout(function () { + if (view.input.lastIOSEnter == now) { + view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + }); + view.input.lastIOSEnter = 0; + } + }, 200); + } else if (view.someProp("handleKeyDown", function (f) { + return f(view, event); + }) || captureKeyDown(view, event)) { + event.preventDefault(); + } else { + setSelectionOrigin(view, "key"); + } +}; +editHandlers.keyup = function (view, event) { + if (event.keyCode == 16) view.input.shiftKey = false; +}; +editHandlers.keypress = function (view, _event) { + var event = _event; + if (inOrNearComposition(view, event) || !event.charCode || event.ctrlKey && !event.altKey || mac && event.metaKey) return; + if (view.someProp("handleKeyPress", function (f) { + return f(view, event); + })) { + event.preventDefault(); + return; + } + var sel = view.state.selection; + if (!(sel instanceof prosemirrorState.TextSelection) || !sel.$from.sameParent(sel.$to)) { + var text = String.fromCharCode(event.charCode); + if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", function (f) { + return f(view, sel.$from.pos, sel.$to.pos, text); + })) view.dispatch(view.state.tr.insertText(text).scrollIntoView()); + event.preventDefault(); + } +}; +function eventCoords(event) { + return { + left: event.clientX, + top: event.clientY + }; +} +function isNear(event, click) { + var dx = click.x - event.clientX, + dy = click.y - event.clientY; + return dx * dx + dy * dy < 100; +} +function runHandlerOnContext(view, propName, pos, inside, event) { + if (inside == -1) return false; + var $pos = view.state.doc.resolve(inside); + var _loop3 = function _loop3(i) { + if (view.someProp(propName, function (f) { + return i > $pos.depth ? f(view, pos, $pos.nodeAfter, $pos.before(i), event, true) : f(view, pos, $pos.node(i), $pos.before(i), event, false); + })) return { + v: true + }; + }, + _ret2; + for (var i = $pos.depth + 1; i > 0; i--) { + _ret2 = _loop3(i); + if (_ret2) return _ret2.v; + } + return false; +} +function updateSelection(view, selection, origin) { + if (!view.focused) view.focus(); + if (view.state.selection.eq(selection)) return; + var tr = view.state.tr.setSelection(selection); + if (origin == "pointer") tr.setMeta("pointer", true); + view.dispatch(tr); +} +function selectClickedLeaf(view, inside) { + if (inside == -1) return false; + var $pos = view.state.doc.resolve(inside), + node = $pos.nodeAfter; + if (node && node.isAtom && prosemirrorState.NodeSelection.isSelectable(node)) { + updateSelection(view, new prosemirrorState.NodeSelection($pos), "pointer"); + return true; + } + return false; +} +function selectClickedNode(view, inside) { + if (inside == -1) return false; + var sel = view.state.selection, + selectedNode, + selectAt; + if (sel instanceof prosemirrorState.NodeSelection) selectedNode = sel.node; + var $pos = view.state.doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + if (prosemirrorState.NodeSelection.isSelectable(node)) { + if (selectedNode && sel.$from.depth > 0 && i >= sel.$from.depth && $pos.before(sel.$from.depth + 1) == sel.$from.pos) selectAt = $pos.before(sel.$from.depth);else selectAt = $pos.before(i); + break; + } + } + if (selectAt != null) { + updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt), "pointer"); + return true; + } else { + return false; + } +} +function handleSingleClick(view, pos, inside, event, selectNode) { + return runHandlerOnContext(view, "handleClickOn", pos, inside, event) || view.someProp("handleClick", function (f) { + return f(view, pos, event); + }) || (selectNode ? selectClickedNode(view, inside) : selectClickedLeaf(view, inside)); +} +function handleDoubleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", function (f) { + return f(view, pos, event); + }); +} +function handleTripleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", function (f) { + return f(view, pos, event); + }) || defaultTripleClick(view, inside, event); +} +function defaultTripleClick(view, inside, event) { + if (event.button != 0) return false; + var doc = view.state.doc; + if (inside == -1) { + if (doc.inlineContent) { + updateSelection(view, prosemirrorState.TextSelection.create(doc, 0, doc.content.size), "pointer"); + return true; + } + return false; + } + var $pos = doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + var nodePos = $pos.before(i); + if (node.inlineContent) updateSelection(view, prosemirrorState.TextSelection.create(doc, nodePos + 1, nodePos + 1 + node.content.size), "pointer");else if (prosemirrorState.NodeSelection.isSelectable(node)) updateSelection(view, prosemirrorState.NodeSelection.create(doc, nodePos), "pointer");else continue; + return true; + } +} +function forceDOMFlush(view) { + return endComposition(view); +} +var selectNodeModifier = mac ? "metaKey" : "ctrlKey"; +handlers.mousedown = function (view, _event) { + var event = _event; + view.input.shiftKey = event.shiftKey; + var flushed = forceDOMFlush(view); + var now = Date.now(), + type = "singleClick"; + if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier]) { + if (view.input.lastClick.type == "singleClick") type = "doubleClick";else if (view.input.lastClick.type == "doubleClick") type = "tripleClick"; + } + view.input.lastClick = { + time: now, + x: event.clientX, + y: event.clientY, + type: type + }; + var pos = view.posAtCoords(eventCoords(event)); + if (!pos) return; + if (type == "singleClick") { + if (view.input.mouseDown) view.input.mouseDown.done(); + view.input.mouseDown = new MouseDown(view, pos, event, !!flushed); + } else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) { + event.preventDefault(); + } else { + setSelectionOrigin(view, "pointer"); + } +}; +var MouseDown = function () { + function MouseDown(view, pos, event, flushed) { + var _this8 = this; + _classCallCheck(this, MouseDown); + this.view = view; + this.pos = pos; + this.event = event; + this.flushed = flushed; + this.delayedSelectionSync = false; + this.mightDrag = null; + this.startDoc = view.state.doc; + this.selectNode = !!event[selectNodeModifier]; + this.allowDefault = event.shiftKey; + var targetNode, targetPos; + if (pos.inside > -1) { + targetNode = view.state.doc.nodeAt(pos.inside); + targetPos = pos.inside; + } else { + var $pos = view.state.doc.resolve(pos.pos); + targetNode = $pos.parent; + targetPos = $pos.depth ? $pos.before() : 0; + } + var target = flushed ? null : event.target; + var targetDesc = target ? view.docView.nearestDesc(target, true) : null; + this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null; + var selection = view.state.selection; + if (event.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos) this.mightDrag = { + node: targetNode, + pos: targetPos, + addAttr: !!(this.target && !this.target.draggable), + setUneditable: !!(this.target && gecko && !this.target.hasAttribute("contentEditable")) + }; + if (this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable)) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) this.target.draggable = true; + if (this.mightDrag.setUneditable) setTimeout(function () { + if (_this8.view.input.mouseDown == _this8) _this8.target.setAttribute("contentEditable", "false"); + }, 20); + this.view.domObserver.start(); + } + view.root.addEventListener("mouseup", this.up = this.up.bind(this)); + view.root.addEventListener("mousemove", this.move = this.move.bind(this)); + setSelectionOrigin(view, "pointer"); + } + _createClass(MouseDown, [{ + key: "done", + value: function done() { + var _this9 = this; + this.view.root.removeEventListener("mouseup", this.up); + this.view.root.removeEventListener("mousemove", this.move); + if (this.mightDrag && this.target) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) this.target.removeAttribute("draggable"); + if (this.mightDrag.setUneditable) this.target.removeAttribute("contentEditable"); + this.view.domObserver.start(); + } + if (this.delayedSelectionSync) setTimeout(function () { + return selectionToDOM(_this9.view); + }); + this.view.input.mouseDown = null; + } + }, { + key: "up", + value: function up(event) { + this.done(); + if (!this.view.dom.contains(event.target)) return; + var pos = this.pos; + if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event)); + this.updateAllowDefault(event); + if (this.allowDefault || !pos) { + setSelectionOrigin(this.view, "pointer"); + } else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) { + event.preventDefault(); + } else if (event.button == 0 && (this.flushed || safari && this.mightDrag && !this.mightDrag.node.isAtom || chrome && !this.view.state.selection.visible && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) { + updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer"); + event.preventDefault(); + } else { + setSelectionOrigin(this.view, "pointer"); + } + } + }, { + key: "move", + value: function move(event) { + this.updateAllowDefault(event); + setSelectionOrigin(this.view, "pointer"); + if (event.buttons == 0) this.done(); + } + }, { + key: "updateAllowDefault", + value: function updateAllowDefault(event) { + if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true; + } + }]); + return MouseDown; +}(); +handlers.touchstart = function (view) { + view.input.lastTouch = Date.now(); + forceDOMFlush(view); + setSelectionOrigin(view, "pointer"); +}; +handlers.touchmove = function (view) { + view.input.lastTouch = Date.now(); + setSelectionOrigin(view, "pointer"); +}; +handlers.contextmenu = function (view) { + return forceDOMFlush(view); +}; +function inOrNearComposition(view, event) { + if (view.composing) return true; + if (safari && Math.abs(event.timeStamp - view.input.compositionEndedAt) < 500) { + view.input.compositionEndedAt = -2e8; + return true; + } + return false; +} +var timeoutComposition = android ? 5000 : -1; +editHandlers.compositionstart = editHandlers.compositionupdate = function (view) { + if (!view.composing) { + view.domObserver.flush(); + var state = view.state, + $pos = state.selection.$to; + if (state.selection instanceof prosemirrorState.TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(function (m) { + return m.type.spec.inclusive === false; + }))) { + view.markCursor = view.state.storedMarks || $pos.marks(); + endComposition(view, true); + view.markCursor = null; + } else { + endComposition(view, !state.selection.empty); + if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) { + var sel = view.domSelectionRange(); + for (var node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) { + var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1]; + if (!before) break; + if (before.nodeType == 3) { + var _sel = view.domSelection(); + if (_sel) _sel.collapse(before, before.nodeValue.length); + break; + } else { + node = before; + offset = -1; + } + } + } + } + view.input.composing = true; + } + scheduleComposeEnd(view, timeoutComposition); +}; +editHandlers.compositionend = function (view, event) { + if (view.composing) { + view.input.composing = false; + view.input.compositionEndedAt = event.timeStamp; + view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0; + view.input.compositionNode = null; + if (view.input.compositionPendingChanges) Promise.resolve().then(function () { + return view.domObserver.flush(); + }); + view.input.compositionID++; + scheduleComposeEnd(view, 20); + } +}; +function scheduleComposeEnd(view, delay) { + clearTimeout(view.input.composingTimeout); + if (delay > -1) view.input.composingTimeout = setTimeout(function () { + return endComposition(view); + }, delay); +} +function clearComposition(view) { + if (view.composing) { + view.input.composing = false; + view.input.compositionEndedAt = timestampFromCustomEvent(); + } + while (view.input.compositionNodes.length > 0) view.input.compositionNodes.pop().markParentsDirty(); +} +function findCompositionNode(view) { + var sel = view.domSelectionRange(); + if (!sel.focusNode) return null; + var textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset); + var textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset); + if (textBefore && textAfter && textBefore != textAfter) { + var descAfter = textAfter.pmViewDesc, + lastChanged = view.domObserver.lastChangedTextNode; + if (textBefore == lastChanged || textAfter == lastChanged) return lastChanged; + if (!descAfter || !descAfter.isText(textAfter.nodeValue)) { + return textAfter; + } else if (view.input.compositionNode == textAfter) { + var descBefore = textBefore.pmViewDesc; + if (!(!descBefore || !descBefore.isText(textBefore.nodeValue))) return textAfter; + } + } + return textBefore || textAfter; +} +function timestampFromCustomEvent() { + var event = document.createEvent("Event"); + event.initEvent("event", true, true); + return event.timeStamp; +} +function endComposition(view) { + var restarting = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + if (android && view.domObserver.flushingSoon >= 0) return; + view.domObserver.forceFlush(); + clearComposition(view); + if (restarting || view.docView && view.docView.dirty) { + var sel = selectionFromDOM(view); + if (sel && !sel.eq(view.state.selection)) view.dispatch(view.state.tr.setSelection(sel));else if ((view.markCursor || restarting) && !view.state.selection.empty) view.dispatch(view.state.tr.deleteSelection());else view.updateState(view.state); + return true; + } + return false; +} +function captureCopy(view, dom) { + if (!view.dom.parentNode) return; + var wrap = view.dom.parentNode.appendChild(document.createElement("div")); + wrap.appendChild(dom); + wrap.style.cssText = "position: fixed; left: -10000px; top: 10px"; + var sel = getSelection(), + range = document.createRange(); + range.selectNodeContents(dom); + view.dom.blur(); + sel.removeAllRanges(); + sel.addRange(range); + setTimeout(function () { + if (wrap.parentNode) wrap.parentNode.removeChild(wrap); + view.focus(); + }, 50); +} +var brokenClipboardAPI = ie && ie_version < 15 || ios && webkit_version < 604; +handlers.copy = editHandlers.cut = function (view, _event) { + var event = _event; + var sel = view.state.selection, + cut = event.type == "cut"; + if (sel.empty) return; + var data = brokenClipboardAPI ? null : event.clipboardData; + var slice = sel.content(), + _serializeForClipboar = serializeForClipboard(view, slice), + dom = _serializeForClipboar.dom, + text = _serializeForClipboar.text; + if (data) { + event.preventDefault(); + data.clearData(); + data.setData("text/html", dom.innerHTML); + data.setData("text/plain", text); + } else { + captureCopy(view, dom); + } + if (cut) view.dispatch(view.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut")); +}; +function sliceSingleNode(slice) { + return slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1 ? slice.content.firstChild : null; +} +function capturePaste(view, event) { + if (!view.dom.parentNode) return; + var plainText = view.input.shiftKey || view.state.selection.$from.parent.type.spec.code; + var target = view.dom.parentNode.appendChild(document.createElement(plainText ? "textarea" : "div")); + if (!plainText) target.contentEditable = "true"; + target.style.cssText = "position: fixed; left: -10000px; top: 10px"; + target.focus(); + var plain = view.input.shiftKey && view.input.lastKeyCode != 45; + setTimeout(function () { + view.focus(); + if (target.parentNode) target.parentNode.removeChild(target); + if (plainText) doPaste(view, target.value, null, plain, event);else doPaste(view, target.textContent, target.innerHTML, plain, event); + }, 50); +} +function doPaste(view, text, html, preferPlain, event) { + var slice = parseFromClipboard(view, text, html, preferPlain, view.state.selection.$from); + if (view.someProp("handlePaste", function (f) { + return f(view, event, slice || prosemirrorModel.Slice.empty); + })) return true; + if (!slice) return false; + var singleNode = sliceSingleNode(slice); + var tr = singleNode ? view.state.tr.replaceSelectionWith(singleNode, preferPlain) : view.state.tr.replaceSelection(slice); + view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste")); + return true; +} +function getText(clipboardData) { + var text = clipboardData.getData("text/plain") || clipboardData.getData("Text"); + if (text) return text; + var uris = clipboardData.getData("text/uri-list"); + return uris ? uris.replace(/\r?\n/g, " ") : ""; +} +editHandlers.paste = function (view, _event) { + var event = _event; + if (view.composing && !android) return; + var data = brokenClipboardAPI ? null : event.clipboardData; + var plain = view.input.shiftKey && view.input.lastKeyCode != 45; + if (data && doPaste(view, getText(data), data.getData("text/html"), plain, event)) event.preventDefault();else capturePaste(view, event); +}; +var Dragging = _createClass(function Dragging(slice, move, node) { + _classCallCheck(this, Dragging); + this.slice = slice; + this.move = move; + this.node = node; +}); +var dragCopyModifier = mac ? "altKey" : "ctrlKey"; +handlers.dragstart = function (view, _event) { + var event = _event; + var mouseDown = view.input.mouseDown; + if (mouseDown) mouseDown.done(); + if (!event.dataTransfer) return; + var sel = view.state.selection; + var pos = sel.empty ? null : view.posAtCoords(eventCoords(event)); + var node; + if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof prosemirrorState.NodeSelection ? sel.to - 1 : sel.to)) ;else if (mouseDown && mouseDown.mightDrag) { + node = prosemirrorState.NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos); + } else if (event.target && event.target.nodeType == 1) { + var desc = view.docView.nearestDesc(event.target, true); + if (desc && desc.node.type.spec.draggable && desc != view.docView) node = prosemirrorState.NodeSelection.create(view.state.doc, desc.posBefore); + } + var draggedSlice = (node || view.state.selection).content(); + var _serializeForClipboar2 = serializeForClipboard(view, draggedSlice), + dom = _serializeForClipboar2.dom, + text = _serializeForClipboar2.text, + slice = _serializeForClipboar2.slice; + if (!event.dataTransfer.files.length || !chrome || chrome_version > 120) event.dataTransfer.clearData(); + event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML); + event.dataTransfer.effectAllowed = "copyMove"; + if (!brokenClipboardAPI) event.dataTransfer.setData("text/plain", text); + view.dragging = new Dragging(slice, !event[dragCopyModifier], node); +}; +handlers.dragend = function (view) { + var dragging = view.dragging; + window.setTimeout(function () { + if (view.dragging == dragging) view.dragging = null; + }, 50); +}; +editHandlers.dragover = editHandlers.dragenter = function (_, e) { + return e.preventDefault(); +}; +editHandlers.drop = function (view, _event) { + var event = _event; + var dragging = view.dragging; + view.dragging = null; + if (!event.dataTransfer) return; + var eventPos = view.posAtCoords(eventCoords(event)); + if (!eventPos) return; + var $mouse = view.state.doc.resolve(eventPos.pos); + var slice = dragging && dragging.slice; + if (slice) { + view.someProp("transformPasted", function (f) { + slice = f(slice, view); + }); + } else { + slice = parseFromClipboard(view, getText(event.dataTransfer), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse); + } + var move = !!(dragging && !event[dragCopyModifier]); + if (view.someProp("handleDrop", function (f) { + return f(view, event, slice || prosemirrorModel.Slice.empty, move); + })) { + event.preventDefault(); + return; + } + if (!slice) return; + event.preventDefault(); + var insertPos = slice ? prosemirrorTransform.dropPoint(view.state.doc, $mouse.pos, slice) : $mouse.pos; + if (insertPos == null) insertPos = $mouse.pos; + var tr = view.state.tr; + if (move) { + var node = dragging.node; + if (node) node.replace(tr);else tr.deleteSelection(); + } + var pos = tr.mapping.map(insertPos); + var isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1; + var beforeInsert = tr.doc; + if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild);else tr.replaceRange(pos, pos, slice); + if (tr.doc.eq(beforeInsert)) return; + var $pos = tr.doc.resolve(pos); + if (isNode && prosemirrorState.NodeSelection.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) { + tr.setSelection(new prosemirrorState.NodeSelection($pos)); + } else { + var end = tr.mapping.map(insertPos); + tr.mapping.maps[tr.mapping.maps.length - 1].forEach(function (_from, _to, _newFrom, newTo) { + return end = newTo; + }); + tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end))); + } + view.focus(); + view.dispatch(tr.setMeta("uiEvent", "drop")); +}; +handlers.focus = function (view) { + view.input.lastFocus = Date.now(); + if (!view.focused) { + view.domObserver.stop(); + view.dom.classList.add("ProseMirror-focused"); + view.domObserver.start(); + view.focused = true; + setTimeout(function () { + if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.domSelectionRange())) selectionToDOM(view); + }, 20); + } +}; +handlers.blur = function (view, _event) { + var event = _event; + if (view.focused) { + view.domObserver.stop(); + view.dom.classList.remove("ProseMirror-focused"); + view.domObserver.start(); + if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domObserver.currentSelection.clear(); + view.focused = false; + } +}; +handlers.beforeinput = function (view, _event) { + var event = _event; + if (chrome && android && event.inputType == "deleteContentBackward") { + view.domObserver.flushSoon(); + var domChangeCount = view.input.domChangeCount; + setTimeout(function () { + if (view.input.domChangeCount != domChangeCount) return; + view.dom.blur(); + view.focus(); + if (view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(8, "Backspace")); + })) return; + var $cursor = view.state.selection.$cursor; + if ($cursor && $cursor.pos > 0) view.dispatch(view.state.tr["delete"]($cursor.pos - 1, $cursor.pos).scrollIntoView()); + }, 50); + } +}; +for (var prop in editHandlers) handlers[prop] = editHandlers[prop]; +function compareObjs(a, b) { + if (a == b) return true; + for (var p in a) if (a[p] !== b[p]) return false; + for (var _p in b) if (!(_p in a)) return false; + return true; +} +var WidgetType = function () { + function WidgetType(toDOM, spec) { + _classCallCheck(this, WidgetType); + this.toDOM = toDOM; + this.spec = spec || noSpec; + this.side = this.spec.side || 0; + } + _createClass(WidgetType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var _mapping$mapResult = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1), + pos = _mapping$mapResult.pos, + deleted = _mapping$mapResult.deleted; + return deleted ? null : new Decoration(pos - offset, pos - offset, this); + } + }, { + key: "valid", + value: function valid() { + return true; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof WidgetType && (this.spec.key && this.spec.key == other.spec.key || this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)); + } + }, { + key: "destroy", + value: function destroy(node) { + if (this.spec.destroy) this.spec.destroy(node); + } + }]); + return WidgetType; +}(); +var InlineType = function () { + function InlineType(attrs, spec) { + _classCallCheck(this, InlineType); + this.attrs = attrs; + this.spec = spec || noSpec; + } + _createClass(InlineType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var from = mapping.map(span.from + oldOffset, this.spec.inclusiveStart ? -1 : 1) - offset; + var to = mapping.map(span.to + oldOffset, this.spec.inclusiveEnd ? 1 : -1) - offset; + return from >= to ? null : new Decoration(from, to, this); + } + }, { + key: "valid", + value: function valid(_, span) { + return span.from < span.to; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof InlineType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); + } + }, { + key: "destroy", + value: function destroy() {} + }], [{ + key: "is", + value: function is(span) { + return span.type instanceof InlineType; + } + }]); + return InlineType; +}(); +var NodeType = function () { + function NodeType(attrs, spec) { + _classCallCheck(this, NodeType); + this.attrs = attrs; + this.spec = spec || noSpec; + } + _createClass(NodeType, [{ + key: "map", + value: function map(mapping, span, offset, oldOffset) { + var from = mapping.mapResult(span.from + oldOffset, 1); + if (from.deleted) return null; + var to = mapping.mapResult(span.to + oldOffset, -1); + if (to.deleted || to.pos <= from.pos) return null; + return new Decoration(from.pos - offset, to.pos - offset, this); + } + }, { + key: "valid", + value: function valid(node, span) { + var _node$content$findInd = node.content.findIndex(span.from), + index = _node$content$findInd.index, + offset = _node$content$findInd.offset, + child; + return offset == span.from && !(child = node.child(index)).isText && offset + child.nodeSize == span.to; + } + }, { + key: "eq", + value: function eq(other) { + return this == other || other instanceof NodeType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); + } + }, { + key: "destroy", + value: function destroy() {} + }]); + return NodeType; +}(); +var Decoration = function () { + function Decoration(from, to, type) { + _classCallCheck(this, Decoration); + this.from = from; + this.to = to; + this.type = type; + } + _createClass(Decoration, [{ + key: "copy", + value: function copy(from, to) { + return new Decoration(from, to, this.type); + } + }, { + key: "eq", + value: function eq(other) { + var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return this.type.eq(other.type) && this.from + offset == other.from && this.to + offset == other.to; + } + }, { + key: "map", + value: function map(mapping, offset, oldOffset) { + return this.type.map(mapping, this, offset, oldOffset); + } + }, { + key: "spec", + get: function get() { + return this.type.spec; + } + }, { + key: "inline", + get: function get() { + return this.type instanceof InlineType; + } + }, { + key: "widget", + get: function get() { + return this.type instanceof WidgetType; + } + }], [{ + key: "widget", + value: function widget(pos, toDOM, spec) { + return new Decoration(pos, pos, new WidgetType(toDOM, spec)); + } + }, { + key: "inline", + value: function inline(from, to, attrs, spec) { + return new Decoration(from, to, new InlineType(attrs, spec)); + } + }, { + key: "node", + value: function node(from, to, attrs, spec) { + return new Decoration(from, to, new NodeType(attrs, spec)); + } + }]); + return Decoration; +}(); +var none = [], + noSpec = {}; +var DecorationSet = function () { + function DecorationSet(local, children) { + _classCallCheck(this, DecorationSet); + this.local = local.length ? local : none; + this.children = children.length ? children : none; + } + _createClass(DecorationSet, [{ + key: "find", + value: function find(start, end, predicate) { + var result = []; + this.findInner(start == null ? 0 : start, end == null ? 1e9 : end, result, 0, predicate); + return result; + } + }, { + key: "findInner", + value: function findInner(start, end, result, offset, predicate) { + for (var i = 0; i < this.local.length; i++) { + var span = this.local[i]; + if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset, span.to + offset)); + } + for (var _i5 = 0; _i5 < this.children.length; _i5 += 3) { + if (this.children[_i5] < end && this.children[_i5 + 1] > start) { + var childOff = this.children[_i5] + 1; + this.children[_i5 + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate); + } + } + } + }, { + key: "map", + value: function map(mapping, doc, options) { + if (this == empty || mapping.maps.length == 0) return this; + return this.mapInner(mapping, doc, 0, 0, options || noSpec); + } + }, { + key: "mapInner", + value: function mapInner(mapping, node, offset, oldOffset, options) { + var newLocal; + for (var i = 0; i < this.local.length; i++) { + var mapped = this.local[i].map(mapping, offset, oldOffset); + if (mapped && mapped.type.valid(node, mapped)) (newLocal || (newLocal = [])).push(mapped);else if (options.onRemove) options.onRemove(this.local[i].spec); + } + if (this.children.length) return mapChildren(this.children, newLocal || [], mapping, node, offset, oldOffset, options);else return newLocal ? new DecorationSet(newLocal.sort(byPos), none) : empty; + } + }, { + key: "add", + value: function add(doc, decorations) { + if (!decorations.length) return this; + if (this == empty) return DecorationSet.create(doc, decorations); + return this.addInner(doc, decorations, 0); + } + }, { + key: "addInner", + value: function addInner(doc, decorations, offset) { + var _this10 = this; + var children, + childIndex = 0; + doc.forEach(function (childNode, childOffset) { + var baseOffset = childOffset + offset, + found; + if (!(found = takeSpansForNode(decorations, childNode, baseOffset))) return; + if (!children) children = _this10.children.slice(); + while (childIndex < children.length && children[childIndex] < childOffset) childIndex += 3; + if (children[childIndex] == childOffset) children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found, baseOffset + 1);else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec)); + childIndex += 3; + }); + var local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset); + for (var i = 0; i < local.length; i++) if (!local[i].type.valid(doc, local[i])) local.splice(i--, 1); + return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, children || this.children); + } + }, { + key: "remove", + value: function remove(decorations) { + if (decorations.length == 0 || this == empty) return this; + return this.removeInner(decorations, 0); + } + }, { + key: "removeInner", + value: function removeInner(decorations, offset) { + var children = this.children, + local = this.local; + for (var i = 0; i < children.length; i += 3) { + var found = void 0; + var from = children[i] + offset, + to = children[i + 1] + offset; + for (var j = 0, span; j < decorations.length; j++) if (span = decorations[j]) { + if (span.from > from && span.to < to) { + decorations[j] = null; + (found || (found = [])).push(span); + } + } + if (!found) continue; + if (children == this.children) children = this.children.slice(); + var removed = children[i + 2].removeInner(found, from + 1); + if (removed != empty) { + children[i + 2] = removed; + } else { + children.splice(i, 3); + i -= 3; + } + } + if (local.length) for (var _i6 = 0, _span; _i6 < decorations.length; _i6++) if (_span = decorations[_i6]) { + for (var _j2 = 0; _j2 < local.length; _j2++) if (local[_j2].eq(_span, offset)) { + if (local == this.local) local = this.local.slice(); + local.splice(_j2--, 1); + } + } + if (children == this.children && local == this.local) return this; + return local.length || children.length ? new DecorationSet(local, children) : empty; + } + }, { + key: "forChild", + value: function forChild(offset, node) { + if (this == empty) return this; + if (node.isLeaf) return DecorationSet.empty; + var child, local; + for (var i = 0; i < this.children.length; i += 3) if (this.children[i] >= offset) { + if (this.children[i] == offset) child = this.children[i + 2]; + break; + } + var start = offset + 1, + end = start + node.content.size; + for (var _i7 = 0; _i7 < this.local.length; _i7++) { + var dec = this.local[_i7]; + if (dec.from < end && dec.to > start && dec.type instanceof InlineType) { + var from = Math.max(start, dec.from) - start, + to = Math.min(end, dec.to) - start; + if (from < to) (local || (local = [])).push(dec.copy(from, to)); + } + } + if (local) { + var localSet = new DecorationSet(local.sort(byPos), none); + return child ? new DecorationGroup([localSet, child]) : localSet; + } + return child || empty; + } + }, { + key: "eq", + value: function eq(other) { + if (this == other) return true; + if (!(other instanceof DecorationSet) || this.local.length != other.local.length || this.children.length != other.children.length) return false; + for (var i = 0; i < this.local.length; i++) if (!this.local[i].eq(other.local[i])) return false; + for (var _i8 = 0; _i8 < this.children.length; _i8 += 3) if (this.children[_i8] != other.children[_i8] || this.children[_i8 + 1] != other.children[_i8 + 1] || !this.children[_i8 + 2].eq(other.children[_i8 + 2])) return false; + return true; + } + }, { + key: "locals", + value: function locals(node) { + return removeOverlap(this.localsInner(node)); + } + }, { + key: "localsInner", + value: function localsInner(node) { + if (this == empty) return none; + if (node.inlineContent || !this.local.some(InlineType.is)) return this.local; + var result = []; + for (var i = 0; i < this.local.length; i++) { + if (!(this.local[i].type instanceof InlineType)) result.push(this.local[i]); + } + return result; + } + }, { + key: "forEachSet", + value: function forEachSet(f) { + f(this); + } + }], [{ + key: "create", + value: function create(doc, decorations) { + return decorations.length ? buildTree(decorations, doc, 0, noSpec) : empty; + } + }]); + return DecorationSet; +}(); +DecorationSet.empty = new DecorationSet([], []); +DecorationSet.removeOverlap = removeOverlap; +var empty = DecorationSet.empty; +var DecorationGroup = function () { + function DecorationGroup(members) { + _classCallCheck(this, DecorationGroup); + this.members = members; + } + _createClass(DecorationGroup, [{ + key: "map", + value: function map(mapping, doc) { + var mappedDecos = this.members.map(function (member) { + return member.map(mapping, doc, noSpec); + }); + return DecorationGroup.from(mappedDecos); + } + }, { + key: "forChild", + value: function forChild(offset, child) { + if (child.isLeaf) return DecorationSet.empty; + var found = []; + for (var i = 0; i < this.members.length; i++) { + var result = this.members[i].forChild(offset, child); + if (result == empty) continue; + if (result instanceof DecorationGroup) found = found.concat(result.members);else found.push(result); + } + return DecorationGroup.from(found); + } + }, { + key: "eq", + value: function eq(other) { + if (!(other instanceof DecorationGroup) || other.members.length != this.members.length) return false; + for (var i = 0; i < this.members.length; i++) if (!this.members[i].eq(other.members[i])) return false; + return true; + } + }, { + key: "locals", + value: function locals(node) { + var result, + sorted = true; + for (var i = 0; i < this.members.length; i++) { + var locals = this.members[i].localsInner(node); + if (!locals.length) continue; + if (!result) { + result = locals; + } else { + if (sorted) { + result = result.slice(); + sorted = false; + } + for (var j = 0; j < locals.length; j++) result.push(locals[j]); + } + } + return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none; + } + }, { + key: "forEachSet", + value: function forEachSet(f) { + for (var i = 0; i < this.members.length; i++) this.members[i].forEachSet(f); + } + }], [{ + key: "from", + value: function from(members) { + switch (members.length) { + case 0: + return empty; + case 1: + return members[0]; + default: + return new DecorationGroup(members.every(function (m) { + return m instanceof DecorationSet; + }) ? members : members.reduce(function (r, m) { + return r.concat(m instanceof DecorationSet ? m : m.members); + }, [])); + } + } + }]); + return DecorationGroup; +}(); +function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) { + var children = oldChildren.slice(); + var _loop4 = function _loop4(_baseOffset) { + var moved = 0; + mapping.maps[i].forEach(function (oldStart, oldEnd, newStart, newEnd) { + var dSize = newEnd - newStart - (oldEnd - oldStart); + for (var _i12 = 0; _i12 < children.length; _i12 += 3) { + var end = children[_i12 + 1]; + if (end < 0 || oldStart > end + _baseOffset - moved) continue; + var start = children[_i12] + _baseOffset - moved; + if (oldEnd >= start) { + children[_i12 + 1] = oldStart <= start ? -2 : -1; + } else if (oldStart >= _baseOffset && dSize) { + children[_i12] += dSize; + children[_i12 + 1] += dSize; + } + } + moved += dSize; + }); + _baseOffset = mapping.maps[i].map(_baseOffset, -1); + baseOffset = _baseOffset; + }; + for (var i = 0, baseOffset = oldOffset; i < mapping.maps.length; i++) { + _loop4(baseOffset); + } + var mustRebuild = false; + for (var _i9 = 0; _i9 < children.length; _i9 += 3) if (children[_i9 + 1] < 0) { + if (children[_i9 + 1] == -2) { + mustRebuild = true; + children[_i9 + 1] = -1; + continue; + } + var from = mapping.map(oldChildren[_i9] + oldOffset), + fromLocal = from - offset; + if (fromLocal < 0 || fromLocal >= node.content.size) { + mustRebuild = true; + continue; + } + var to = mapping.map(oldChildren[_i9 + 1] + oldOffset, -1), + toLocal = to - offset; + var _node$content$findInd2 = node.content.findIndex(fromLocal), + index = _node$content$findInd2.index, + childOffset = _node$content$findInd2.offset; + var childNode = node.maybeChild(index); + if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) { + var mapped = children[_i9 + 2].mapInner(mapping, childNode, from + 1, oldChildren[_i9] + oldOffset + 1, options); + if (mapped != empty) { + children[_i9] = fromLocal; + children[_i9 + 1] = toLocal; + children[_i9 + 2] = mapped; + } else { + children[_i9 + 1] = -2; + mustRebuild = true; + } + } else { + mustRebuild = true; + } + } + if (mustRebuild) { + var decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal, mapping, offset, oldOffset, options); + var built = buildTree(decorations, node, 0, options); + newLocal = built.local; + for (var _i10 = 0; _i10 < children.length; _i10 += 3) if (children[_i10 + 1] < 0) { + children.splice(_i10, 3); + _i10 -= 3; + } + for (var _i11 = 0, j = 0; _i11 < built.children.length; _i11 += 3) { + var _from2 = built.children[_i11]; + while (j < children.length && children[j] < _from2) j += 3; + children.splice(j, 0, built.children[_i11], built.children[_i11 + 1], built.children[_i11 + 2]); + } + } + return new DecorationSet(newLocal.sort(byPos), children); +} +function moveSpans(spans, offset) { + if (!offset || !spans.length) return spans; + var result = []; + for (var i = 0; i < spans.length; i++) { + var span = spans[i]; + result.push(new Decoration(span.from + offset, span.to + offset, span.type)); + } + return result; +} +function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) { + function gather(set, oldOffset) { + for (var i = 0; i < set.local.length; i++) { + var mapped = set.local[i].map(mapping, offset, oldOffset); + if (mapped) decorations.push(mapped);else if (options.onRemove) options.onRemove(set.local[i].spec); + } + for (var _i13 = 0; _i13 < set.children.length; _i13 += 3) gather(set.children[_i13 + 2], set.children[_i13] + oldOffset + 1); + } + for (var i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1); + return decorations; +} +function takeSpansForNode(spans, node, offset) { + if (node.isLeaf) return null; + var end = offset + node.nodeSize, + found = null; + for (var i = 0, span; i < spans.length; i++) { + if ((span = spans[i]) && span.from > offset && span.to < end) { + (found || (found = [])).push(span); + spans[i] = null; + } + } + return found; +} +function withoutNulls(array) { + var result = []; + for (var i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]); + return result; +} +function buildTree(spans, node, offset, options) { + var children = [], + hasNulls = false; + node.forEach(function (childNode, localStart) { + var found = takeSpansForNode(spans, childNode, localStart + offset); + if (found) { + hasNulls = true; + var subtree = buildTree(found, childNode, offset + localStart + 1, options); + if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree); + } + }); + var locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos); + for (var i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i])) { + if (options.onRemove) options.onRemove(locals[i].spec); + locals.splice(i--, 1); + } + return locals.length || children.length ? new DecorationSet(locals, children) : empty; +} +function byPos(a, b) { + return a.from - b.from || a.to - b.to; +} +function removeOverlap(spans) { + var working = spans; + for (var i = 0; i < working.length - 1; i++) { + var span = working[i]; + if (span.from != span.to) for (var j = i + 1; j < working.length; j++) { + var next = working[j]; + if (next.from == span.from) { + if (next.to != span.to) { + if (working == spans) working = spans.slice(); + working[j] = next.copy(next.from, span.to); + insertAhead(working, j + 1, next.copy(span.to, next.to)); + } + continue; + } else { + if (next.from < span.to) { + if (working == spans) working = spans.slice(); + working[i] = span.copy(span.from, next.from); + insertAhead(working, j, span.copy(next.from, span.to)); + } + break; + } + } + } + return working; +} +function insertAhead(array, i, deco) { + while (i < array.length && byPos(deco, array[i]) > 0) i++; + array.splice(i, 0, deco); +} +function viewDecorations(view) { + var found = []; + view.someProp("decorations", function (f) { + var result = f(view.state); + if (result && result != empty) found.push(result); + }); + if (view.cursorWrapper) found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco])); + return DecorationGroup.from(found); +} +var observeOptions = { + childList: true, + characterData: true, + characterDataOldValue: true, + attributes: true, + attributeOldValue: true, + subtree: true +}; +var useCharData = ie && ie_version <= 11; +var SelectionState = function () { + function SelectionState() { + _classCallCheck(this, SelectionState); + this.anchorNode = null; + this.anchorOffset = 0; + this.focusNode = null; + this.focusOffset = 0; + } + _createClass(SelectionState, [{ + key: "set", + value: function set(sel) { + this.anchorNode = sel.anchorNode; + this.anchorOffset = sel.anchorOffset; + this.focusNode = sel.focusNode; + this.focusOffset = sel.focusOffset; + } + }, { + key: "clear", + value: function clear() { + this.anchorNode = this.focusNode = null; + } + }, { + key: "eq", + value: function eq(sel) { + return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset; + } + }]); + return SelectionState; +}(); +var DOMObserver = function () { + function DOMObserver(view, handleDOMChange) { + var _this11 = this; + _classCallCheck(this, DOMObserver); + this.view = view; + this.handleDOMChange = handleDOMChange; + this.queue = []; + this.flushingSoon = -1; + this.observer = null; + this.currentSelection = new SelectionState(); + this.onCharData = null; + this.suppressingSelectionUpdates = false; + this.lastChangedTextNode = null; + this.observer = window.MutationObserver && new window.MutationObserver(function (mutations) { + for (var i = 0; i < mutations.length; i++) _this11.queue.push(mutations[i]); + if (ie && ie_version <= 11 && mutations.some(function (m) { + return m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length; + })) _this11.flushSoon();else _this11.flush(); + }); + if (useCharData) { + this.onCharData = function (e) { + _this11.queue.push({ + target: e.target, + type: "characterData", + oldValue: e.prevValue + }); + _this11.flushSoon(); + }; + } + this.onSelectionChange = this.onSelectionChange.bind(this); + } + _createClass(DOMObserver, [{ + key: "flushSoon", + value: function flushSoon() { + var _this12 = this; + if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(function () { + _this12.flushingSoon = -1; + _this12.flush(); + }, 20); + } + }, { + key: "forceFlush", + value: function forceFlush() { + if (this.flushingSoon > -1) { + window.clearTimeout(this.flushingSoon); + this.flushingSoon = -1; + this.flush(); + } + } + }, { + key: "start", + value: function start() { + if (this.observer) { + this.observer.takeRecords(); + this.observer.observe(this.view.dom, observeOptions); + } + if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData); + this.connectSelection(); + } + }, { + key: "stop", + value: function stop() { + var _this13 = this; + if (this.observer) { + var take = this.observer.takeRecords(); + if (take.length) { + for (var i = 0; i < take.length; i++) this.queue.push(take[i]); + window.setTimeout(function () { + return _this13.flush(); + }, 20); + } + this.observer.disconnect(); + } + if (this.onCharData) this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData); + this.disconnectSelection(); + } + }, { + key: "connectSelection", + value: function connectSelection() { + this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange); + } + }, { + key: "disconnectSelection", + value: function disconnectSelection() { + this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange); + } + }, { + key: "suppressSelectionUpdates", + value: function suppressSelectionUpdates() { + var _this14 = this; + this.suppressingSelectionUpdates = true; + setTimeout(function () { + return _this14.suppressingSelectionUpdates = false; + }, 50); + } + }, { + key: "onSelectionChange", + value: function onSelectionChange() { + if (!hasFocusAndSelection(this.view)) return; + if (this.suppressingSelectionUpdates) return selectionToDOM(this.view); + if (ie && ie_version <= 11 && !this.view.state.selection.empty) { + var sel = this.view.domSelectionRange(); + if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon(); + } + this.flush(); + } + }, { + key: "setCurSelection", + value: function setCurSelection() { + this.currentSelection.set(this.view.domSelectionRange()); + } + }, { + key: "ignoreSelectionChange", + value: function ignoreSelectionChange(sel) { + if (!sel.focusNode) return true; + var ancestors = new Set(), + container; + for (var scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan); + for (var _scan = sel.anchorNode; _scan; _scan = parentNode(_scan)) if (ancestors.has(_scan)) { + container = _scan; + break; + } + var desc = container && this.view.docView.nearestDesc(container); + if (desc && desc.ignoreMutation({ + type: "selection", + target: container.nodeType == 3 ? container.parentNode : container + })) { + this.setCurSelection(); + return true; + } + } + }, { + key: "pendingRecords", + value: function pendingRecords() { + if (this.observer) { + var _iterator2 = _createForOfIteratorHelper(this.observer.takeRecords()), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var mut = _step2.value; + this.queue.push(mut); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + return this.queue; + } + }, { + key: "selectionChanged", + value: function selectionChanged(sel) { + return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel); + } + }, { + key: "flush", + value: function flush() { + var view = this.view; + if (!view.docView || this.flushingSoon > -1) return; + var mutations = this.pendingRecords(); + if (mutations.length) this.queue = []; + var sel = view.domSelectionRange(), + newSel = this.selectionChanged(sel); + var from = -1, + to = -1, + typeOver = false, + added = []; + if (view.editable) { + for (var i = 0; i < mutations.length; i++) { + var result = this.registerMutation(mutations[i], added); + if (result) { + from = from < 0 ? result.from : Math.min(result.from, from); + to = to < 0 ? result.to : Math.max(result.to, to); + if (result.typeOver) typeOver = true; + } + } + } + if (gecko && added.length) { + var brs = added.filter(function (n) { + return n.nodeName == "BR"; + }); + if (brs.length == 2) { + var _brs = _slicedToArray(brs, 2), + a = _brs[0], + b = _brs[1]; + if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();else a.remove(); + } else { + var focusNode = this.currentSelection.focusNode; + var _iterator3 = _createForOfIteratorHelper(brs), + _step3; + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var br = _step3.value; + var parent = br.parentNode; + if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove(); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + } + var readSel = null; + if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(prosemirrorState.Selection.near(view.state.doc.resolve(0), 1))) { + view.input.lastFocus = 0; + selectionToDOM(view); + this.currentSelection.set(sel); + view.scrollToSelection(); + } else if (from > -1 || newSel) { + if (from > -1) { + view.docView.markDirty(from, to); + checkCSS(view); + } + this.handleDOMChange(from, to, typeOver, added); + if (view.docView && view.docView.dirty) view.updateState(view.state);else if (!this.currentSelection.eq(sel)) selectionToDOM(view); + this.currentSelection.set(sel); + } + } + }, { + key: "registerMutation", + value: function registerMutation(mut, added) { + if (added.indexOf(mut.target) > -1) return null; + var desc = this.view.docView.nearestDesc(mut.target); + if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null; + if (!desc || desc.ignoreMutation(mut)) return null; + if (mut.type == "childList") { + for (var i = 0; i < mut.addedNodes.length; i++) { + var node = mut.addedNodes[i]; + added.push(node); + if (node.nodeType == 3) this.lastChangedTextNode = node; + } + if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return { + from: desc.posBefore, + to: desc.posAfter + }; + var prev = mut.previousSibling, + next = mut.nextSibling; + if (ie && ie_version <= 11 && mut.addedNodes.length) { + for (var _i14 = 0; _i14 < mut.addedNodes.length; _i14++) { + var _mut$addedNodes$_i = mut.addedNodes[_i14], + previousSibling = _mut$addedNodes$_i.previousSibling, + nextSibling = _mut$addedNodes$_i.nextSibling; + if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling; + if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) next = nextSibling; + } + } + var fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0; + var from = desc.localPosFromDOM(mut.target, fromOffset, -1); + var toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length; + var to = desc.localPosFromDOM(mut.target, toOffset, 1); + return { + from: from, + to: to + }; + } else if (mut.type == "attributes") { + return { + from: desc.posAtStart - desc.border, + to: desc.posAtEnd + desc.border + }; + } else { + this.lastChangedTextNode = mut.target; + return { + from: desc.posAtStart, + to: desc.posAtEnd, + typeOver: mut.target.nodeValue == mut.oldValue + }; + } + } + }]); + return DOMObserver; +}(); +var cssChecked = new WeakMap(); +var cssCheckWarned = false; +function checkCSS(view) { + if (cssChecked.has(view)) return; + cssChecked.set(view, null); + if (['normal', 'nowrap', 'pre-line'].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) { + view.requiresGeckoHackNode = gecko; + if (cssCheckWarned) return; + console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."); + cssCheckWarned = true; + } +} +function rangeToSelectionRange(view, range) { + var anchorNode = range.startContainer, + anchorOffset = range.startOffset; + var focusNode = range.endContainer, + focusOffset = range.endOffset; + var currentAnchor = view.domAtPos(view.state.selection.anchor); + if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) { + var _ref5 = [focusNode, focusOffset, anchorNode, anchorOffset]; + anchorNode = _ref5[0]; + anchorOffset = _ref5[1]; + focusNode = _ref5[2]; + focusOffset = _ref5[3]; + } + return { + anchorNode: anchorNode, + anchorOffset: anchorOffset, + focusNode: focusNode, + focusOffset: focusOffset + }; +} +function safariShadowSelectionRange(view, selection) { + if (selection.getComposedRanges) { + var range = selection.getComposedRanges(view.root)[0]; + if (range) return rangeToSelectionRange(view, range); + } + var found; + function read(event) { + event.preventDefault(); + event.stopImmediatePropagation(); + found = event.getTargetRanges()[0]; + } + view.dom.addEventListener("beforeinput", read, true); + document.execCommand("indent"); + view.dom.removeEventListener("beforeinput", read, true); + return found ? rangeToSelectionRange(view, found) : null; +} +function blockParent(view, node) { + for (var p = node.parentNode; p && p != view.dom; p = p.parentNode) { + var desc = view.docView.nearestDesc(p, true); + if (desc && desc.node.isBlock) return p; + } + return null; +} +function parseBetween(view, from_, to_) { + var _view$docView$parseRa = view.docView.parseRange(from_, to_), + parent = _view$docView$parseRa.node, + fromOffset = _view$docView$parseRa.fromOffset, + toOffset = _view$docView$parseRa.toOffset, + from = _view$docView$parseRa.from, + to = _view$docView$parseRa.to; + var domSel = view.domSelectionRange(); + var find; + var anchor = domSel.anchorNode; + if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) { + find = [{ + node: anchor, + offset: domSel.anchorOffset + }]; + if (!selectionCollapsed(domSel)) find.push({ + node: domSel.focusNode, + offset: domSel.focusOffset + }); + } + if (chrome && view.input.lastKeyCode === 8) { + for (var off = toOffset; off > fromOffset; off--) { + var node = parent.childNodes[off - 1], + desc = node.pmViewDesc; + if (node.nodeName == "BR" && !desc) { + toOffset = off; + break; + } + if (!desc || desc.size) break; + } + } + var startDoc = view.state.doc; + var parser = view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema); + var $from = startDoc.resolve(from); + var sel = null, + doc = parser.parse(parent, { + topNode: $from.parent, + topMatch: $from.parent.contentMatchAt($from.index()), + topOpen: true, + from: fromOffset, + to: toOffset, + preserveWhitespace: $from.parent.type.whitespace == "pre" ? "full" : true, + findPositions: find, + ruleFromNode: ruleFromNode, + context: $from + }); + if (find && find[0].pos != null) { + var _anchor = find[0].pos, + head = find[1] && find[1].pos; + if (head == null) head = _anchor; + sel = { + anchor: _anchor + from, + head: head + from + }; + } + return { + doc: doc, + sel: sel, + from: from, + to: to + }; +} +function ruleFromNode(dom) { + var desc = dom.pmViewDesc; + if (desc) { + return desc.parseRule(); + } else if (dom.nodeName == "BR" && dom.parentNode) { + if (safari && /^(ul|ol)$/i.test(dom.parentNode.nodeName)) { + var skip = document.createElement("div"); + skip.appendChild(document.createElement("li")); + return { + skip: skip + }; + } else if (dom.parentNode.lastChild == dom || safari && /^(tr|table)$/i.test(dom.parentNode.nodeName)) { + return { + ignore: true + }; + } + } else if (dom.nodeName == "IMG" && dom.getAttribute("mark-placeholder")) { + return { + ignore: true + }; + } + return null; +} +var isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i; +function readDOMChange(view, from, to, typeOver, addedNodes) { + var compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0); + view.input.compositionPendingChanges = 0; + if (from < 0) { + var origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null; + var newSel = selectionFromDOM(view, origin); + if (newSel && !view.state.selection.eq(newSel)) { + if (chrome && android && view.input.lastKeyCode === 13 && Date.now() - 100 < view.input.lastKeyCodeTime && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) return; + var _tr = view.state.tr.setSelection(newSel); + if (origin == "pointer") _tr.setMeta("pointer", true);else if (origin == "key") _tr.scrollIntoView(); + if (compositionID) _tr.setMeta("composition", compositionID); + view.dispatch(_tr); + } + return; + } + var $before = view.state.doc.resolve(from); + var shared = $before.sharedDepth(to); + from = $before.before(shared + 1); + to = view.state.doc.resolve(to).after(shared + 1); + var sel = view.state.selection; + var parse = parseBetween(view, from, to); + var doc = view.state.doc, + compare = doc.slice(parse.from, parse.to); + var preferredPos, preferredSide; + if (view.input.lastKeyCode === 8 && Date.now() - 100 < view.input.lastKeyCodeTime) { + preferredPos = view.state.selection.to; + preferredSide = "end"; + } else { + preferredPos = view.state.selection.from; + preferredSide = "start"; + } + view.input.lastKeyCode = null; + var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide); + if (change) view.input.domChangeCount++; + if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) { + return n.nodeType == 1 && !isInline.test(n.nodeName); + }) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) { + view.input.lastIOSEnter = 0; + return; + } + if (!change) { + if (typeOver && sel instanceof prosemirrorState.TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) { + change = { + start: sel.from, + endA: sel.to, + endB: sel.to + }; + } else { + if (parse.sel) { + var _sel2 = resolveSelection(view, view.state.doc, parse.sel); + if (_sel2 && !_sel2.eq(view.state.selection)) { + var _tr2 = view.state.tr.setSelection(_sel2); + if (compositionID) _tr2.setMeta("composition", compositionID); + view.dispatch(_tr2); + } + } + return; + } + } + if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof prosemirrorState.TextSelection) { + if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) { + change.start = view.state.selection.from; + } else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse.to) { + change.endB += view.state.selection.to - change.endA; + change.endA = view.state.selection.to; + } + } + if (ie && ie_version <= 11 && change.endB == change.start + 1 && change.endA == change.start && change.start > parse.from && parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == " \xA0") { + change.start--; + change.endA--; + change.endB--; + } + var $from = parse.doc.resolveNoCache(change.start - parse.from); + var $to = parse.doc.resolveNoCache(change.endB - parse.from); + var $fromA = doc.resolve(change.start); + var inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA; + var nextSel; + if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some(function (n) { + return n.nodeName == "DIV" || n.nodeName == "P"; + })) || !inlineChange && $from.pos < parse.doc.content.size && !$from.sameParent($to) && (nextSel = prosemirrorState.Selection.findFrom(parse.doc.resolve($from.pos + 1), 1, true)) && nextSel.head == $to.pos) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + })) { + view.input.lastIOSEnter = 0; + return; + } + if (view.state.selection.anchor > change.start && looksLikeBackspace(doc, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(8, "Backspace")); + })) { + if (android && chrome) view.domObserver.suppressSelectionUpdates(); + return; + } + if (chrome && android && change.endB == change.start) view.input.lastAndroidDelete = Date.now(); + if (android && !inlineChange && $from.start() != $to.start() && $to.parentOffset == 0 && $from.depth == $to.depth && parse.sel && parse.sel.anchor == parse.sel.head && parse.sel.head == change.endA) { + change.endB -= 2; + $to = parse.doc.resolveNoCache(change.endB - parse.from); + setTimeout(function () { + view.someProp("handleKeyDown", function (f) { + return f(view, keyEvent(13, "Enter")); + }); + }, 20); + } + var chFrom = change.start, + chTo = change.endA; + var tr, storedMarks, markChange; + if (inlineChange) { + if ($from.pos == $to.pos) { + if (ie && ie_version <= 11 && $from.parentOffset == 0) { + view.domObserver.suppressSelectionUpdates(); + setTimeout(function () { + return selectionToDOM(view); + }, 20); + } + tr = view.state.tr["delete"](chFrom, chTo); + storedMarks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA)); + } else if (change.endA == change.endB && (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), $fromA.parent.content.cut($fromA.parentOffset, change.endA - $fromA.start())))) { + tr = view.state.tr; + if (markChange.type == "add") tr.addMark(chFrom, chTo, markChange.mark);else tr.removeMark(chFrom, chTo, markChange.mark); + } else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) { + var text = $from.parent.textBetween($from.parentOffset, $to.parentOffset); + if (view.someProp("handleTextInput", function (f) { + return f(view, chFrom, chTo, text); + })) return; + tr = view.state.tr.insertText(text, chFrom, chTo); + } + } + if (!tr) tr = view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from)); + if (parse.sel) { + var _sel3 = resolveSelection(view, tr.doc, parse.sel); + if (_sel3 && !(chrome && android && view.composing && _sel3.empty && (change.start != change.endB || view.input.lastAndroidDelete < Date.now() - 100) && (_sel3.head == chFrom || _sel3.head == tr.mapping.map(chTo) - 1) || ie && _sel3.empty && _sel3.head == chFrom)) tr.setSelection(_sel3); + } + if (storedMarks) tr.ensureMarks(storedMarks); + if (compositionID) tr.setMeta("composition", compositionID); + view.dispatch(tr.scrollIntoView()); +} +function resolveSelection(view, doc, parsedSel) { + if (Math.max(parsedSel.anchor, parsedSel.head) > doc.content.size) return null; + return selectionBetween(view, doc.resolve(parsedSel.anchor), doc.resolve(parsedSel.head)); +} +function isMarkChange(cur, prev) { + var curMarks = cur.firstChild.marks, + prevMarks = prev.firstChild.marks; + var added = curMarks, + removed = prevMarks, + type, + mark, + update; + for (var i = 0; i < prevMarks.length; i++) added = prevMarks[i].removeFromSet(added); + for (var _i15 = 0; _i15 < curMarks.length; _i15++) removed = curMarks[_i15].removeFromSet(removed); + if (added.length == 1 && removed.length == 0) { + mark = added[0]; + type = "add"; + update = function update(node) { + return node.mark(mark.addToSet(node.marks)); + }; + } else if (added.length == 0 && removed.length == 1) { + mark = removed[0]; + type = "remove"; + update = function update(node) { + return node.mark(mark.removeFromSet(node.marks)); + }; + } else { + return null; + } + var updated = []; + for (var _i16 = 0; _i16 < prev.childCount; _i16++) updated.push(update(prev.child(_i16))); + if (prosemirrorModel.Fragment.from(updated).eq(cur)) return { + mark: mark, + type: type + }; +} +function looksLikeBackspace(old, start, end, $newStart, $newEnd) { + if (end - start <= $newEnd.pos - $newStart.pos || skipClosingAndOpening($newStart, true, false) < $newEnd.pos) return false; + var $start = old.resolve(start); + if (!$newStart.parent.isTextblock) { + var after = $start.nodeAfter; + return after != null && end == start + after.nodeSize; + } + if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock) return false; + var $next = old.resolve(skipClosingAndOpening($start, true, true)); + if (!$next.parent.isTextblock || $next.pos > end || skipClosingAndOpening($next, true, false) < end) return false; + return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content); +} +function skipClosingAndOpening($pos, fromEnd, mayOpen) { + var depth = $pos.depth, + end = fromEnd ? $pos.end() : $pos.pos; + while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) { + depth--; + end++; + fromEnd = false; + } + if (mayOpen) { + var next = $pos.node(depth).maybeChild($pos.indexAfter(depth)); + while (next && !next.isLeaf) { + next = next.firstChild; + end++; + } + } + return end; +} +function findDiff(a, b, pos, preferredPos, preferredSide) { + var start = a.findDiffStart(b, pos); + if (start == null) return null; + var _a$findDiffEnd = a.findDiffEnd(b, pos + a.size, pos + b.size), + endA = _a$findDiffEnd.a, + endB = _a$findDiffEnd.b; + if (preferredSide == "end") { + var adjust = Math.max(0, start - Math.min(endA, endB)); + preferredPos -= endA + adjust - start; + } + if (endA < start && a.size < b.size) { + var move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0; + start -= move; + if (start && start < b.size && isSurrogatePair(b.textBetween(start - 1, start + 1))) start += move ? 1 : -1; + endB = start + (endB - endA); + endA = start; + } else if (endB < start) { + var _move = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0; + start -= _move; + if (start && start < a.size && isSurrogatePair(a.textBetween(start - 1, start + 1))) start += _move ? 1 : -1; + endA = start + (endA - endB); + endB = start; + } + return { + start: start, + endA: endA, + endB: endB + }; +} +function isSurrogatePair(str) { + if (str.length != 2) return false; + var a = str.charCodeAt(0), + b = str.charCodeAt(1); + return a >= 0xDC00 && a <= 0xDFFF && b >= 0xD800 && b <= 0xDBFF; +} +var __serializeForClipboard = serializeForClipboard; +var __parseFromClipboard = parseFromClipboard; +var __endComposition = endComposition; +var EditorView = function () { + function EditorView(place, props) { + var _this15 = this; + _classCallCheck(this, EditorView); + this._root = null; + this.focused = false; + this.trackWrites = null; + this.mounted = false; + this.markCursor = null; + this.cursorWrapper = null; + this.lastSelectedViewDesc = undefined; + this.input = new InputState(); + this.prevDirectPlugins = []; + this.pluginViews = []; + this.requiresGeckoHackNode = false; + this.dragging = null; + this._props = props; + this.state = props.state; + this.directPlugins = props.plugins || []; + this.directPlugins.forEach(checkStateComponent); + this.dispatch = this.dispatch.bind(this); + this.dom = place && place.mount || document.createElement("div"); + if (place) { + if (place.appendChild) place.appendChild(this.dom);else if (typeof place == "function") place(this.dom);else if (place.mount) this.mounted = true; + } + this.editable = getEditable(this); + updateCursorWrapper(this); + this.nodeViews = buildNodeViews(this); + this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this); + this.domObserver = new DOMObserver(this, function (from, to, typeOver, added) { + return readDOMChange(_this15, from, to, typeOver, added); + }); + this.domObserver.start(); + initInput(this); + this.updatePluginViews(); + } + _createClass(EditorView, [{ + key: "composing", + get: function get() { + return this.input.composing; + } + }, { + key: "props", + get: function get() { + if (this._props.state != this.state) { + var prev = this._props; + this._props = {}; + for (var name in prev) this._props[name] = prev[name]; + this._props.state = this.state; + } + return this._props; + } + }, { + key: "update", + value: function update(props) { + if (props.handleDOMEvents != this._props.handleDOMEvents) ensureListeners(this); + var prevProps = this._props; + this._props = props; + if (props.plugins) { + props.plugins.forEach(checkStateComponent); + this.directPlugins = props.plugins; + } + this.updateStateInner(props.state, prevProps); + } + }, { + key: "setProps", + value: function setProps(props) { + var updated = {}; + for (var name in this._props) updated[name] = this._props[name]; + updated.state = this.state; + for (var _name2 in props) updated[_name2] = props[_name2]; + this.update(updated); + } + }, { + key: "updateState", + value: function updateState(state) { + this.updateStateInner(state, this._props); + } + }, { + key: "updateStateInner", + value: function updateStateInner(state, prevProps) { + var _a; + var prev = this.state, + redraw = false, + updateSel = false; + if (state.storedMarks && this.composing) { + clearComposition(this); + updateSel = true; + } + this.state = state; + var pluginsChanged = prev.plugins != state.plugins || this._props.plugins != prevProps.plugins; + if (pluginsChanged || this._props.plugins != prevProps.plugins || this._props.nodeViews != prevProps.nodeViews) { + var nodeViews = buildNodeViews(this); + if (changedNodeViews(nodeViews, this.nodeViews)) { + this.nodeViews = nodeViews; + redraw = true; + } + } + if (pluginsChanged || prevProps.handleDOMEvents != this._props.handleDOMEvents) { + ensureListeners(this); + } + this.editable = getEditable(this); + updateCursorWrapper(this); + var innerDeco = viewDecorations(this), + outerDeco = computeDocDeco(this); + var scroll = prev.plugins != state.plugins && !prev.doc.eq(state.doc) ? "reset" : state.scrollToSelection > prev.scrollToSelection ? "to selection" : "preserve"; + var updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco); + if (updateDoc || !state.selection.eq(prev.selection)) updateSel = true; + var oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this); + if (updateSel) { + this.domObserver.stop(); + var forceSelUpdate = updateDoc && (ie || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection); + if (updateDoc) { + var chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null; + if (this.composing) this.input.compositionNode = findCompositionNode(this); + if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) { + this.docView.updateOuterDeco(outerDeco); + this.docView.destroy(); + this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this); + } + if (chromeKludge && !this.trackWrites) forceSelUpdate = true; + } + if (forceSelUpdate || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && anchorInRightPlace(this))) { + selectionToDOM(this, forceSelUpdate); + } else { + syncNodeSelection(this, state.selection); + this.domObserver.setCurSelection(); + } + this.domObserver.start(); + } + this.updatePluginViews(prev); + if (((_a = this.dragging) === null || _a === void 0 ? void 0 : _a.node) && !prev.doc.eq(state.doc)) this.updateDraggedNode(this.dragging, prev); + if (scroll == "reset") { + this.dom.scrollTop = 0; + } else if (scroll == "to selection") { + this.scrollToSelection(); + } else if (oldScrollPos) { + resetScrollPos(oldScrollPos); + } + } + }, { + key: "scrollToSelection", + value: function scrollToSelection() { + var _this16 = this; + var startDOM = this.domSelectionRange().focusNode; + if (this.someProp("handleScrollToSelection", function (f) { + return f(_this16); + })) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) { + var target = this.docView.domAfterPos(this.state.selection.from); + if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM); + } else { + scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM); + } + } + }, { + key: "destroyPluginViews", + value: function destroyPluginViews() { + var view; + while (view = this.pluginViews.pop()) if (view.destroy) view.destroy(); + } + }, { + key: "updatePluginViews", + value: function updatePluginViews(prevState) { + if (!prevState || prevState.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) { + this.prevDirectPlugins = this.directPlugins; + this.destroyPluginViews(); + for (var i = 0; i < this.directPlugins.length; i++) { + var plugin = this.directPlugins[i]; + if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this)); + } + for (var _i17 = 0; _i17 < this.state.plugins.length; _i17++) { + var _plugin = this.state.plugins[_i17]; + if (_plugin.spec.view) this.pluginViews.push(_plugin.spec.view(this)); + } + } else { + for (var _i18 = 0; _i18 < this.pluginViews.length; _i18++) { + var pluginView = this.pluginViews[_i18]; + if (pluginView.update) pluginView.update(this, prevState); + } + } + } + }, { + key: "updateDraggedNode", + value: function updateDraggedNode(dragging, prev) { + var sel = dragging.node, + found = -1; + if (this.state.doc.nodeAt(sel.from) == sel.node) { + found = sel.from; + } else { + var movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size); + var moved = movedPos > 0 && this.state.doc.nodeAt(movedPos); + if (moved == sel.node) found = movedPos; + } + this.dragging = new Dragging(dragging.slice, dragging.move, found < 0 ? undefined : prosemirrorState.NodeSelection.create(this.state.doc, found)); + } + }, { + key: "someProp", + value: function someProp(propName, f) { + var prop = this._props && this._props[propName], + value; + if (prop != null && (value = f ? f(prop) : prop)) return value; + for (var i = 0; i < this.directPlugins.length; i++) { + var _prop = this.directPlugins[i].props[propName]; + if (_prop != null && (value = f ? f(_prop) : _prop)) return value; + } + var plugins = this.state.plugins; + if (plugins) for (var _i19 = 0; _i19 < plugins.length; _i19++) { + var _prop2 = plugins[_i19].props[propName]; + if (_prop2 != null && (value = f ? f(_prop2) : _prop2)) return value; + } + } + }, { + key: "hasFocus", + value: function hasFocus() { + if (ie) { + var node = this.root.activeElement; + if (node == this.dom) return true; + if (!node || !this.dom.contains(node)) return false; + while (node && this.dom != node && this.dom.contains(node)) { + if (node.contentEditable == 'false') return false; + node = node.parentElement; + } + return true; + } + return this.root.activeElement == this.dom; + } + }, { + key: "focus", + value: function focus() { + this.domObserver.stop(); + if (this.editable) focusPreventScroll(this.dom); + selectionToDOM(this); + this.domObserver.start(); + } + }, { + key: "root", + get: function get() { + var _this17 = this; + var cached = this._root; + if (cached == null) { + var _loop5 = function _loop5(search) { + if (search.nodeType == 9 || search.nodeType == 11 && search.host) { + if (!search.getSelection) Object.getPrototypeOf(search).getSelection = function () { + return search.ownerDocument.getSelection(); + }; + return { + v: _this17._root = search + }; + } + }, + _ret3; + for (var search = this.dom.parentNode; search; search = search.parentNode) { + _ret3 = _loop5(search); + if (_ret3) return _ret3.v; + } + } + return cached || document; + } + }, { + key: "updateRoot", + value: function updateRoot() { + this._root = null; + } + }, { + key: "posAtCoords", + value: function posAtCoords(coords) { + return _posAtCoords(this, coords); + } + }, { + key: "coordsAtPos", + value: function coordsAtPos(pos) { + var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return _coordsAtPos(this, pos, side); + } + }, { + key: "domAtPos", + value: function domAtPos(pos) { + var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + return this.docView.domFromPos(pos, side); + } + }, { + key: "nodeDOM", + value: function nodeDOM(pos) { + var desc = this.docView.descAt(pos); + return desc ? desc.nodeDOM : null; + } + }, { + key: "posAtDOM", + value: function posAtDOM(node, offset) { + var bias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; + var pos = this.docView.posFromDOM(node, offset, bias); + if (pos == null) throw new RangeError("DOM position not inside the editor"); + return pos; + } + }, { + key: "endOfTextblock", + value: function endOfTextblock(dir, state) { + return _endOfTextblock(this, state || this.state, dir); + } + }, { + key: "pasteHTML", + value: function pasteHTML(html, event) { + return doPaste(this, "", html, false, event || new ClipboardEvent("paste")); + } + }, { + key: "pasteText", + value: function pasteText(text, event) { + return doPaste(this, text, null, true, event || new ClipboardEvent("paste")); + } + }, { + key: "destroy", + value: function destroy() { + if (!this.docView) return; + destroyInput(this); + this.destroyPluginViews(); + if (this.mounted) { + this.docView.update(this.state.doc, [], viewDecorations(this), this); + this.dom.textContent = ""; + } else if (this.dom.parentNode) { + this.dom.parentNode.removeChild(this.dom); + } + this.docView.destroy(); + this.docView = null; + clearReusedRange(); + } + }, { + key: "isDestroyed", + get: function get() { + return this.docView == null; + } + }, { + key: "dispatchEvent", + value: function dispatchEvent(event) { + return _dispatchEvent(this, event); + } + }, { + key: "dispatch", + value: function dispatch(tr) { + var dispatchTransaction = this._props.dispatchTransaction; + if (dispatchTransaction) dispatchTransaction.call(this, tr);else this.updateState(this.state.apply(tr)); + } + }, { + key: "domSelectionRange", + value: function domSelectionRange() { + var sel = this.domSelection(); + if (!sel) return { + focusNode: null, + focusOffset: 0, + anchorNode: null, + anchorOffset: 0 + }; + return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel; + } + }, { + key: "domSelection", + value: function domSelection() { + return this.root.getSelection(); + } + }]); + return EditorView; +}(); +function computeDocDeco(view) { + var attrs = Object.create(null); + attrs["class"] = "ProseMirror"; + attrs.contenteditable = String(view.editable); + view.someProp("attributes", function (value) { + if (typeof value == "function") value = value(view.state); + if (value) for (var attr in value) { + if (attr == "class") attrs["class"] += " " + value[attr];else if (attr == "style") attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") attrs[attr] = String(value[attr]); + } + }); + if (!attrs.translate) attrs.translate = "no"; + return [Decoration.node(0, view.state.doc.content.size, attrs)]; +} +function updateCursorWrapper(view) { + if (view.markCursor) { + var dom = document.createElement("img"); + dom.className = "ProseMirror-separator"; + dom.setAttribute("mark-placeholder", "true"); + dom.setAttribute("alt", ""); + view.cursorWrapper = { + dom: dom, + deco: Decoration.widget(view.state.selection.from, dom, { + raw: true, + marks: view.markCursor + }) + }; + } else { + view.cursorWrapper = null; + } +} +function getEditable(view) { + return !view.someProp("editable", function (value) { + return value(view.state) === false; + }); +} +function selectionContextChanged(sel1, sel2) { + var depth = Math.min(sel1.$anchor.sharedDepth(sel1.head), sel2.$anchor.sharedDepth(sel2.head)); + return sel1.$anchor.start(depth) != sel2.$anchor.start(depth); +} +function buildNodeViews(view) { + var result = Object.create(null); + function add(obj) { + for (var _prop3 in obj) if (!Object.prototype.hasOwnProperty.call(result, _prop3)) result[_prop3] = obj[_prop3]; + } + view.someProp("nodeViews", add); + view.someProp("markViews", add); + return result; +} +function changedNodeViews(a, b) { + var nA = 0, + nB = 0; + for (var _prop4 in a) { + if (a[_prop4] != b[_prop4]) return true; + nA++; + } + for (var _ in b) nB++; + return nA != nB; +} +function checkStateComponent(plugin) { + if (plugin.spec.state || plugin.spec.filterTransaction || plugin.spec.appendTransaction) throw new RangeError("Plugins passed directly to the view must not have a state component"); +} +exports.Decoration = Decoration; +exports.DecorationSet = DecorationSet; +exports.EditorView = EditorView; +exports.__endComposition = __endComposition; +exports.__parseFromClipboard = __parseFromClipboard; +exports.__serializeForClipboard = __serializeForClipboard; + +}); +define("linkify-it",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var uc_micro = require('uc.micro'); + +function reFactory (opts) { + const re = {}; + opts = opts || {}; + + re.src_Any = uc_micro.Any.source; + re.src_Cc = uc_micro.Cc.source; + re.src_Z = uc_micro.Z.source; + re.src_P = uc_micro.P.source; + + // \p{\Z\P\Cc\CF} (white spaces + control + format + punctuation) + re.src_ZPCc = [re.src_Z, re.src_P, re.src_Cc].join('|'); + + // \p{\Z\Cc} (white spaces + control) + re.src_ZCc = [re.src_Z, re.src_Cc].join('|'); + + // Experimental. List of chars, completely prohibited in links + // because can separate it from other part of text + const text_separators = '[><\uff5c]'; + + // All possible word characters (everything without punctuation, spaces & controls) + // Defined via punctuation & spaces to save space + // Should be something like \p{\L\N\S\M} (\w but without `_`) + re.src_pseudo_letter = '(?:(?!' + text_separators + '|' + re.src_ZPCc + ')' + re.src_Any + ')'; + // The same as abothe but without [0-9] + // var src_pseudo_letter_non_d = '(?:(?![0-9]|' + src_ZPCc + ')' + src_Any + ')'; + + re.src_ip4 = + + '(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; + + // Prohibit any of "@/[]()" in user/pass to avoid wrong domain fetch. + re.src_auth = '(?:(?:(?!' + re.src_ZCc + '|[@/\\[\\]()]).)+@)?'; + + re.src_port = + + '(?::(?:6(?:[0-4]\\d{3}|5(?:[0-4]\\d{2}|5(?:[0-2]\\d|3[0-5])))|[1-5]?\\d{1,4}))?'; + + re.src_host_terminator = + + '(?=$|' + text_separators + '|' + re.src_ZPCc + ')' + + '(?!' + (opts['---'] ? '-(?!--)|' : '-|') + '_|:\\d|\\.-|\\.(?!$|' + re.src_ZPCc + '))'; + + re.src_path = + + '(?:' + + '[/?#]' + + '(?:' + + '(?!' + re.src_ZCc + '|' + text_separators + '|[()[\\]{}.,"\'?!\\-;]).|' + + '\\[(?:(?!' + re.src_ZCc + '|\\]).)*\\]|' + + '\\((?:(?!' + re.src_ZCc + '|[)]).)*\\)|' + + '\\{(?:(?!' + re.src_ZCc + '|[}]).)*\\}|' + + '\\"(?:(?!' + re.src_ZCc + '|["]).)+\\"|' + + "\\'(?:(?!" + re.src_ZCc + "|[']).)+\\'|" + + + // allow `I'm_king` if no pair found + "\\'(?=" + re.src_pseudo_letter + '|[-])|' + + + // google has many dots in "google search" links (#66, #81). + // github has ... in commit range links, + // Restrict to + // - english + // - percent-encoded + // - parts of file path + // - params separator + // until more examples found. + '\\.{2,}[a-zA-Z0-9%/&]|' + + + '\\.(?!' + re.src_ZCc + '|[.]|$)|' + + (opts['---'] + ? '\\-(?!--(?:[^-]|$))(?:-*)|' // `---` => long dash, terminate + : '\\-+|' + ) + + // allow `,,,` in paths + ',(?!' + re.src_ZCc + '|$)|' + + + // allow `;` if not followed by space-like char + ';(?!' + re.src_ZCc + '|$)|' + + + // allow `!!!` in paths, but not at the end + '\\!+(?!' + re.src_ZCc + '|[!]|$)|' + + + '\\?(?!' + re.src_ZCc + '|[?]|$)' + + ')+' + + '|\\/' + + ')?'; + + // Allow anything in markdown spec, forbid quote (") at the first position + // because emails enclosed in quotes are far more common + re.src_email_name = + + '[\\-;:&=\\+\\$,\\.a-zA-Z0-9_][\\-;:&=\\+\\$,\\"\\.a-zA-Z0-9_]*'; + + re.src_xn = + + 'xn--[a-z0-9\\-]{1,59}'; + + // More to read about domain names + // http://serverfault.com/questions/638260/ + + re.src_domain_root = + + // Allow letters & digits (http://test1) + '(?:' + + re.src_xn + + '|' + + re.src_pseudo_letter + '{1,63}' + + ')'; + + re.src_domain = + + '(?:' + + re.src_xn + + '|' + + '(?:' + re.src_pseudo_letter + ')' + + '|' + + '(?:' + re.src_pseudo_letter + '(?:-|' + re.src_pseudo_letter + '){0,61}' + re.src_pseudo_letter + ')' + + ')'; + + re.src_host = + + '(?:' + + // Don't need IP check, because digits are already allowed in normal domain names + // src_ip4 + + // '|' + + '(?:(?:(?:' + re.src_domain + ')\\.)*' + re.src_domain/* _root */ + ')' + + ')'; + + re.tpl_host_fuzzy = + + '(?:' + + re.src_ip4 + + '|' + + '(?:(?:(?:' + re.src_domain + ')\\.)+(?:%TLDS%))' + + ')'; + + re.tpl_host_no_ip_fuzzy = + + '(?:(?:(?:' + re.src_domain + ')\\.)+(?:%TLDS%))'; + + re.src_host_strict = + + re.src_host + re.src_host_terminator; + + re.tpl_host_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_host_terminator; + + re.src_host_port_strict = + + re.src_host + re.src_port + re.src_host_terminator; + + re.tpl_host_port_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_port + re.src_host_terminator; + + re.tpl_host_port_no_ip_fuzzy_strict = + + re.tpl_host_no_ip_fuzzy + re.src_port + re.src_host_terminator; + + // + // Main rules + // + + // Rude test fuzzy links by host, for quick deny + re.tpl_host_fuzzy_test = + + 'localhost|www\\.|\\.\\d{1,3}\\.|(?:\\.(?:%TLDS%)(?:' + re.src_ZPCc + '|>|$))'; + + re.tpl_email_fuzzy = + + '(^|' + text_separators + '|"|\\(|' + re.src_ZCc + ')' + + '(' + re.src_email_name + '@' + re.tpl_host_fuzzy_strict + ')'; + + re.tpl_link_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + re.src_ZPCc + '))' + + '((?![$+<=>^`|\uff5c])' + re.tpl_host_port_fuzzy_strict + re.src_path + ')'; + + re.tpl_link_no_ip_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + re.src_ZPCc + '))' + + '((?![$+<=>^`|\uff5c])' + re.tpl_host_port_no_ip_fuzzy_strict + re.src_path + ')'; + + return re +} + +// +// Helpers +// + +// Merge objects +// +function assign (obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1); + + sources.forEach(function (source) { + if (!source) { return } + + Object.keys(source).forEach(function (key) { + obj[key] = source[key]; + }); + }); + + return obj +} + +function _class (obj) { return Object.prototype.toString.call(obj) } +function isString (obj) { return _class(obj) === '[object String]' } +function isObject (obj) { return _class(obj) === '[object Object]' } +function isRegExp (obj) { return _class(obj) === '[object RegExp]' } +function isFunction (obj) { return _class(obj) === '[object Function]' } + +function escapeRE (str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&') } + +// + +const defaultOptions = { + fuzzyLink: true, + fuzzyEmail: true, + fuzzyIP: false +}; + +function isOptionsObj (obj) { + return Object.keys(obj || {}).reduce(function (acc, k) { + /* eslint-disable-next-line no-prototype-builtins */ + return acc || defaultOptions.hasOwnProperty(k) + }, false) +} + +const defaultSchemas = { + 'http:': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.http = new RegExp( + '^\\/\\/' + self.re.src_auth + self.re.src_host_port_strict + self.re.src_path, 'i' + ); + } + if (self.re.http.test(tail)) { + return tail.match(self.re.http)[0].length + } + return 0 + } + }, + 'https:': 'http:', + 'ftp:': 'http:', + '//': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.no_http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.no_http = new RegExp( + '^' + + self.re.src_auth + + // Don't allow single-level domains, because of false positives like '//test' + // with code comments + '(?:localhost|(?:(?:' + self.re.src_domain + ')\\.)+' + self.re.src_domain_root + ')' + + self.re.src_port + + self.re.src_host_terminator + + self.re.src_path, + + 'i' + ); + } + + if (self.re.no_http.test(tail)) { + // should not be `://` & `///`, that protects from errors in protocol name + if (pos >= 3 && text[pos - 3] === ':') { return 0 } + if (pos >= 3 && text[pos - 3] === '/') { return 0 } + return tail.match(self.re.no_http)[0].length + } + return 0 + } + }, + 'mailto:': { + validate: function (text, pos, self) { + const tail = text.slice(pos); + + if (!self.re.mailto) { + self.re.mailto = new RegExp( + '^' + self.re.src_email_name + '@' + self.re.src_host_strict, 'i' + ); + } + if (self.re.mailto.test(tail)) { + return tail.match(self.re.mailto)[0].length + } + return 0 + } + } +}; + +// RE pattern for 2-character tlds (autogenerated by ./support/tlds_2char_gen.js) +/* eslint-disable-next-line max-len */ +const tlds_2ch_src_re = 'a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]'; + +// DON'T try to make PRs with changes. Extend TLDs with LinkifyIt.tlds() instead +const tlds_default = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|'); + +function resetScanCache (self) { + self.__index__ = -1; + self.__text_cache__ = ''; +} + +function createValidator (re) { + return function (text, pos) { + const tail = text.slice(pos); + + if (re.test(tail)) { + return tail.match(re)[0].length + } + return 0 + } +} + +function createNormalizer () { + return function (match, self) { + self.normalize(match); + } +} + +// Schemas compiler. Build regexps. +// +function compile (self) { + // Load & clone RE patterns. + const re = self.re = reFactory(self.__opts__); + + // Define dynamic patterns + const tlds = self.__tlds__.slice(); + + self.onCompile(); + + if (!self.__tlds_replaced__) { + tlds.push(tlds_2ch_src_re); + } + tlds.push(re.src_xn); + + re.src_tlds = tlds.join('|'); + + function untpl (tpl) { return tpl.replace('%TLDS%', re.src_tlds) } + + re.email_fuzzy = RegExp(untpl(re.tpl_email_fuzzy), 'i'); + re.link_fuzzy = RegExp(untpl(re.tpl_link_fuzzy), 'i'); + re.link_no_ip_fuzzy = RegExp(untpl(re.tpl_link_no_ip_fuzzy), 'i'); + re.host_fuzzy_test = RegExp(untpl(re.tpl_host_fuzzy_test), 'i'); + + // + // Compile each schema + // + + const aliases = []; + + self.__compiled__ = {}; // Reset compiled data + + function schemaError (name, val) { + throw new Error('(LinkifyIt) Invalid schema "' + name + '": ' + val) + } + + Object.keys(self.__schemas__).forEach(function (name) { + const val = self.__schemas__[name]; + + // skip disabled methods + if (val === null) { return } + + const compiled = { validate: null, link: null }; + + self.__compiled__[name] = compiled; + + if (isObject(val)) { + if (isRegExp(val.validate)) { + compiled.validate = createValidator(val.validate); + } else if (isFunction(val.validate)) { + compiled.validate = val.validate; + } else { + schemaError(name, val); + } + + if (isFunction(val.normalize)) { + compiled.normalize = val.normalize; + } else if (!val.normalize) { + compiled.normalize = createNormalizer(); + } else { + schemaError(name, val); + } + + return + } + + if (isString(val)) { + aliases.push(name); + return + } + + schemaError(name, val); + }); + + // + // Compile postponed aliases + // + + aliases.forEach(function (alias) { + if (!self.__compiled__[self.__schemas__[alias]]) { + // Silently fail on missed schemas to avoid errons on disable. + // schemaError(alias, self.__schemas__[alias]); + return + } + + self.__compiled__[alias].validate = + self.__compiled__[self.__schemas__[alias]].validate; + self.__compiled__[alias].normalize = + self.__compiled__[self.__schemas__[alias]].normalize; + }); + + // + // Fake record for guessed links + // + self.__compiled__[''] = { validate: null, normalize: createNormalizer() }; + + // + // Build schema condition + // + const slist = Object.keys(self.__compiled__) + .filter(function (name) { + // Filter disabled & fake schemas + return name.length > 0 && self.__compiled__[name] + }) + .map(escapeRE) + .join('|'); + // (?!_) cause 1.5x slowdown + self.re.schema_test = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'i'); + self.re.schema_search = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'ig'); + self.re.schema_at_start = RegExp('^' + self.re.schema_search.source, 'i'); + + self.re.pretest = RegExp( + '(' + self.re.schema_test.source + ')|(' + self.re.host_fuzzy_test.source + ')|@', + 'i' + ); + + // + // Cleanup + // + + resetScanCache(self); +} + +/** + * class Match + * + * Match result. Single element of array, returned by [[LinkifyIt#match]] + **/ +function Match (self, shift) { + const start = self.__index__; + const end = self.__last_index__; + const text = self.__text_cache__.slice(start, end); + + /** + * Match#schema -> String + * + * Prefix (protocol) for matched string. + **/ + this.schema = self.__schema__.toLowerCase(); + /** + * Match#index -> Number + * + * First position of matched string. + **/ + this.index = start + shift; + /** + * Match#lastIndex -> Number + * + * Next position after matched string. + **/ + this.lastIndex = end + shift; + /** + * Match#raw -> String + * + * Matched string. + **/ + this.raw = text; + /** + * Match#text -> String + * + * Notmalized text of matched string. + **/ + this.text = text; + /** + * Match#url -> String + * + * Normalized url of matched string. + **/ + this.url = text; +} + +function createMatch (self, shift) { + const match = new Match(self, shift); + + self.__compiled__[match.schema].normalize(match, self); + + return match +} + +/** + * class LinkifyIt + **/ + +/** + * new LinkifyIt(schemas, options) + * - schemas (Object): Optional. Additional schemas to validate (prefix/validator) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Creates new linkifier instance with optional additional schemas. + * Can be called without `new` keyword for convenience. + * + * By default understands: + * + * - `http(s)://...` , `ftp://...`, `mailto:...` & `//...` links + * - "fuzzy" links and emails (example.com, foo@bar.com). + * + * `schemas` is an object, where each key/value describes protocol/rule: + * + * - __key__ - link prefix (usually, protocol name with `:` at the end, `skype:` + * for example). `linkify-it` makes shure that prefix is not preceeded with + * alphanumeric char and symbols. Only whitespaces and punctuation allowed. + * - __value__ - rule to check tail after link prefix + * - _String_ - just alias to existing rule + * - _Object_ + * - _validate_ - validator function (should return matched length on success), + * or `RegExp`. + * - _normalize_ - optional function to normalize text & url of matched result + * (for example, for @twitter mentions). + * + * `options`: + * + * - __fuzzyLink__ - recognige URL-s without `http(s):` prefix. Default `true`. + * - __fuzzyIP__ - allow IPs in fuzzy links above. Can conflict with some texts + * like version numbers. Default `false`. + * - __fuzzyEmail__ - recognize emails without `mailto:` prefix. + * + **/ +function LinkifyIt (schemas, options) { + if (!(this instanceof LinkifyIt)) { + return new LinkifyIt(schemas, options) + } + + if (!options) { + if (isOptionsObj(schemas)) { + options = schemas; + schemas = {}; + } + } + + this.__opts__ = assign({}, defaultOptions, options); + + // Cache last tested result. Used to skip repeating steps on next `match` call. + this.__index__ = -1; + this.__last_index__ = -1; // Next scan position + this.__schema__ = ''; + this.__text_cache__ = ''; + + this.__schemas__ = assign({}, defaultSchemas, schemas); + this.__compiled__ = {}; + + this.__tlds__ = tlds_default; + this.__tlds_replaced__ = false; + + this.re = {}; + + compile(this); +} + +/** chainable + * LinkifyIt#add(schema, definition) + * - schema (String): rule name (fixed pattern prefix) + * - definition (String|RegExp|Object): schema definition + * + * Add new rule definition. See constructor description for details. + **/ +LinkifyIt.prototype.add = function add (schema, definition) { + this.__schemas__[schema] = definition; + compile(this); + return this +}; + +/** chainable + * LinkifyIt#set(options) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Set recognition options for links without schema. + **/ +LinkifyIt.prototype.set = function set (options) { + this.__opts__ = assign(this.__opts__, options); + return this +}; + +/** + * LinkifyIt#test(text) -> Boolean + * + * Searches linkifiable pattern and returns `true` on success or `false` on fail. + **/ +LinkifyIt.prototype.test = function test (text) { + // Reset scan cache + this.__text_cache__ = text; + this.__index__ = -1; + + if (!text.length) { return false } + + let m, ml, me, len, shift, next, re, tld_pos, at_pos; + + // try to scan for link with schema - that's the most simple rule + if (this.re.schema_test.test(text)) { + re = this.re.schema_search; + re.lastIndex = 0; + while ((m = re.exec(text)) !== null) { + len = this.testSchemaAt(text, m[2], re.lastIndex); + if (len) { + this.__schema__ = m[2]; + this.__index__ = m.index + m[1].length; + this.__last_index__ = m.index + m[0].length + len; + break + } + } + } + + if (this.__opts__.fuzzyLink && this.__compiled__['http:']) { + // guess schemaless links + tld_pos = text.search(this.re.host_fuzzy_test); + if (tld_pos >= 0) { + // if tld is located after found link - no need to check fuzzy pattern + if (this.__index__ < 0 || tld_pos < this.__index__) { + if ((ml = text.match(this.__opts__.fuzzyIP ? this.re.link_fuzzy : this.re.link_no_ip_fuzzy)) !== null) { + shift = ml.index + ml[1].length; + + if (this.__index__ < 0 || shift < this.__index__) { + this.__schema__ = ''; + this.__index__ = shift; + this.__last_index__ = ml.index + ml[0].length; + } + } + } + } + } + + if (this.__opts__.fuzzyEmail && this.__compiled__['mailto:']) { + // guess schemaless emails + at_pos = text.indexOf('@'); + if (at_pos >= 0) { + // We can't skip this check, because this cases are possible: + // 192.168.1.1@gmail.com, my.in@example.com + if ((me = text.match(this.re.email_fuzzy)) !== null) { + shift = me.index + me[1].length; + next = me.index + me[0].length; + + if (this.__index__ < 0 || shift < this.__index__ || + (shift === this.__index__ && next > this.__last_index__)) { + this.__schema__ = 'mailto:'; + this.__index__ = shift; + this.__last_index__ = next; + } + } + } + } + + return this.__index__ >= 0 +}; + +/** + * LinkifyIt#pretest(text) -> Boolean + * + * Very quick check, that can give false positives. Returns true if link MAY BE + * can exists. Can be used for speed optimization, when you need to check that + * link NOT exists. + **/ +LinkifyIt.prototype.pretest = function pretest (text) { + return this.re.pretest.test(text) +}; + +/** + * LinkifyIt#testSchemaAt(text, name, position) -> Number + * - text (String): text to scan + * - name (String): rule (schema) name + * - position (Number): text offset to check from + * + * Similar to [[LinkifyIt#test]] but checks only specific protocol tail exactly + * at given position. Returns length of found pattern (0 on fail). + **/ +LinkifyIt.prototype.testSchemaAt = function testSchemaAt (text, schema, pos) { + // If not supported schema check requested - terminate + if (!this.__compiled__[schema.toLowerCase()]) { + return 0 + } + return this.__compiled__[schema.toLowerCase()].validate(text, pos, this) +}; + +/** + * LinkifyIt#match(text) -> Array|null + * + * Returns array of found link descriptions or `null` on fail. We strongly + * recommend to use [[LinkifyIt#test]] first, for best speed. + * + * ##### Result match description + * + * - __schema__ - link schema, can be empty for fuzzy links, or `//` for + * protocol-neutral links. + * - __index__ - offset of matched text + * - __lastIndex__ - index of next char after mathch end + * - __raw__ - matched text + * - __text__ - normalized text + * - __url__ - link, generated from matched text + **/ +LinkifyIt.prototype.match = function match (text) { + const result = []; + let shift = 0; + + // Try to take previous element from cache, if .test() called before + if (this.__index__ >= 0 && this.__text_cache__ === text) { + result.push(createMatch(this, shift)); + shift = this.__last_index__; + } + + // Cut head if cache was used + let tail = shift ? text.slice(shift) : text; + + // Scan string until end reached + while (this.test(tail)) { + result.push(createMatch(this, shift)); + + tail = tail.slice(this.__last_index__); + shift += this.__last_index__; + } + + if (result.length) { + return result + } + + return null +}; + +/** + * LinkifyIt#matchAtStart(text) -> Match|null + * + * Returns fully-formed (not fuzzy) link if it starts at the beginning + * of the string, and null otherwise. + **/ +LinkifyIt.prototype.matchAtStart = function matchAtStart (text) { + // Reset scan cache + this.__text_cache__ = text; + this.__index__ = -1; + + if (!text.length) return null + + const m = this.re.schema_at_start.exec(text); + if (!m) return null + + const len = this.testSchemaAt(text, m[2], m[0].length); + if (!len) return null + + this.__schema__ = m[2]; + this.__index__ = m.index + m[1].length; + this.__last_index__ = m.index + m[0].length + len; + + return createMatch(this, 0) +}; + +/** chainable + * LinkifyIt#tlds(list [, keepOld]) -> this + * - list (Array): list of tlds + * - keepOld (Boolean): merge with current list if `true` (`false` by default) + * + * Load (or merge) new tlds list. Those are user for fuzzy links (without prefix) + * to avoid false positives. By default this algorythm used: + * + * - hostname with any 2-letter root zones are ok. + * - biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф + * are ok. + * - encoded (`xn--...`) root zones are ok. + * + * If list is replaced, then exact match for 2-chars root zones will be checked. + **/ +LinkifyIt.prototype.tlds = function tlds (list, keepOld) { + list = Array.isArray(list) ? list : [list]; + + if (!keepOld) { + this.__tlds__ = list.slice(); + this.__tlds_replaced__ = true; + compile(this); + return this + } + + this.__tlds__ = this.__tlds__.concat(list) + .sort() + .filter(function (el, idx, arr) { + return el !== arr[idx - 1] + }) + .reverse(); + + compile(this); + return this +}; + +/** + * LinkifyIt#normalize(match) + * + * Default normalizer (if schema does not define it's own). + **/ +LinkifyIt.prototype.normalize = function normalize (match) { + // Do minimal possible changes by default. Need to collect feedback prior + // to move forward https://github.com/markdown-it/linkify-it/issues/1 + + if (!match.schema) { match.url = 'http://' + match.url; } + + if (match.schema === 'mailto:' && !/^mailto:/i.test(match.url)) { + match.url = 'mailto:' + match.url; + } +}; + +/** + * LinkifyIt#onCompile() + * + * Override to modify basic RegExp-s. + **/ +LinkifyIt.prototype.onCompile = function onCompile () { +}; + +module.exports = LinkifyIt; + +}); +define("markdown-it",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var mdurl = require('mdurl'); +var ucmicro = require('uc.micro'); +var entities = require('entities'); +var LinkifyIt = require('linkify-it'); +var punycode = require('punycode.js'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var mdurl__namespace = /*#__PURE__*/_interopNamespaceDefault(mdurl); +var ucmicro__namespace = /*#__PURE__*/_interopNamespaceDefault(ucmicro); + +// Utilities +// + +function _class(obj) { + return Object.prototype.toString.call(obj); +} +function isString(obj) { + return _class(obj) === '[object String]'; +} +const _hasOwnProperty = Object.prototype.hasOwnProperty; +function has(object, key) { + return _hasOwnProperty.call(object, key); +} + +// Merge objects +// +function assign(obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1); + sources.forEach(function (source) { + if (!source) { + return; + } + if (typeof source !== 'object') { + throw new TypeError(source + 'must be object'); + } + Object.keys(source).forEach(function (key) { + obj[key] = source[key]; + }); + }); + return obj; +} + +// Remove element from array and put another array at those position. +// Useful for some operations with tokens +function arrayReplaceAt(src, pos, newElements) { + return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)); +} +function isValidEntityCode(c) { + /* eslint no-bitwise:0 */ + // broken sequence + if (c >= 0xD800 && c <= 0xDFFF) { + return false; + } + // never used + if (c >= 0xFDD0 && c <= 0xFDEF) { + return false; + } + if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { + return false; + } + // control codes + if (c >= 0x00 && c <= 0x08) { + return false; + } + if (c === 0x0B) { + return false; + } + if (c >= 0x0E && c <= 0x1F) { + return false; + } + if (c >= 0x7F && c <= 0x9F) { + return false; + } + // out of range + if (c > 0x10FFFF) { + return false; + } + return true; +} +function fromCodePoint(c) { + /* eslint no-bitwise:0 */ + if (c > 0xffff) { + c -= 0x10000; + const surrogate1 = 0xd800 + (c >> 10); + const surrogate2 = 0xdc00 + (c & 0x3ff); + return String.fromCharCode(surrogate1, surrogate2); + } + return String.fromCharCode(c); +} +const UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g; +const ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; +const UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi'); +const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i; +function replaceEntityPattern(match, name) { + if (name.charCodeAt(0) === 0x23 /* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { + const code = name[1].toLowerCase() === 'x' ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10); + if (isValidEntityCode(code)) { + return fromCodePoint(code); + } + return match; + } + const decoded = entities.decodeHTML(match); + if (decoded !== match) { + return decoded; + } + return match; +} + +/* function replaceEntities(str) { + if (str.indexOf('&') < 0) { return str; } + + return str.replace(ENTITY_RE, replaceEntityPattern); +} */ + +function unescapeMd(str) { + if (str.indexOf('\\') < 0) { + return str; + } + return str.replace(UNESCAPE_MD_RE, '$1'); +} +function unescapeAll(str) { + if (str.indexOf('\\') < 0 && str.indexOf('&') < 0) { + return str; + } + return str.replace(UNESCAPE_ALL_RE, function (match, escaped, entity) { + if (escaped) { + return escaped; + } + return replaceEntityPattern(match, entity); + }); +} +const HTML_ESCAPE_TEST_RE = /[&<>"]/; +const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; +const HTML_REPLACEMENTS = { + '&': '&', + '<': '<', + '>': '>', + '"': '"' +}; +function replaceUnsafeChar(ch) { + return HTML_REPLACEMENTS[ch]; +} +function escapeHtml(str) { + if (HTML_ESCAPE_TEST_RE.test(str)) { + return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); + } + return str; +} +const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g; +function escapeRE(str) { + return str.replace(REGEXP_ESCAPE_RE, '\\$&'); +} +function isSpace(code) { + switch (code) { + case 0x09: + case 0x20: + return true; + } + return false; +} + +// Zs (unicode class) || [\t\f\v\r\n] +function isWhiteSpace(code) { + if (code >= 0x2000 && code <= 0x200A) { + return true; + } + switch (code) { + case 0x09: // \t + case 0x0A: // \n + case 0x0B: // \v + case 0x0C: // \f + case 0x0D: // \r + case 0x20: + case 0xA0: + case 0x1680: + case 0x202F: + case 0x205F: + case 0x3000: + return true; + } + return false; +} + +/* eslint-disable max-len */ + +// Currently without astral characters support. +function isPunctChar(ch) { + return ucmicro__namespace.P.test(ch) || ucmicro__namespace.S.test(ch); +} + +// Markdown ASCII punctuation characters. +// +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +// +// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range. +// +function isMdAsciiPunct(ch) { + switch (ch) { + case 0x21 /* ! */: + case 0x22 /* " */: + case 0x23 /* # */: + case 0x24 /* $ */: + case 0x25 /* % */: + case 0x26 /* & */: + case 0x27 /* ' */: + case 0x28 /* ( */: + case 0x29 /* ) */: + case 0x2A /* * */: + case 0x2B /* + */: + case 0x2C /* , */: + case 0x2D /* - */: + case 0x2E /* . */: + case 0x2F /* / */: + case 0x3A /* : */: + case 0x3B /* ; */: + case 0x3C /* < */: + case 0x3D /* = */: + case 0x3E /* > */: + case 0x3F /* ? */: + case 0x40 /* @ */: + case 0x5B /* [ */: + case 0x5C /* \ */: + case 0x5D /* ] */: + case 0x5E /* ^ */: + case 0x5F /* _ */: + case 0x60 /* ` */: + case 0x7B /* { */: + case 0x7C /* | */: + case 0x7D /* } */: + case 0x7E /* ~ */: + return true; + default: + return false; + } +} + +// Hepler to unify [reference labels]. +// +function normalizeReference(str) { + // Trim and collapse whitespace + // + str = str.trim().replace(/\s+/g, ' '); + + // In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug + // fixed in v12 (couldn't find any details). + // + // So treat this one as a special case + // (remove this when node v10 is no longer supported). + // + if ('ẞ'.toLowerCase() === 'Ṿ') { + str = str.replace(/ẞ/g, 'ß'); + } + + // .toLowerCase().toUpperCase() should get rid of all differences + // between letter variants. + // + // Simple .toLowerCase() doesn't normalize 125 code points correctly, + // and .toUpperCase doesn't normalize 6 of them (list of exceptions: + // İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently + // uppercased versions). + // + // Here's an example showing how it happens. Lets take greek letter omega: + // uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ) + // + // Unicode entries: + // 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8; + // 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398 + // 03D1;GREEK THETA SYMBOL;Ll;0;L; 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398 + // 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L; 0398;;;;N;;;;03B8; + // + // Case-insensitive comparison should treat all of them as equivalent. + // + // But .toLowerCase() doesn't change ϑ (it's already lowercase), + // and .toUpperCase() doesn't change ϴ (already uppercase). + // + // Applying first lower then upper case normalizes any character: + // '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398' + // + // Note: this is equivalent to unicode case folding; unicode normalization + // is a different step that is not required here. + // + // Final result should be uppercased, because it's later stored in an object + // (this avoid a conflict with Object.prototype members, + // most notably, `__proto__`) + // + return str.toLowerCase().toUpperCase(); +} + +// Re-export libraries commonly used in both markdown-it and its plugins, +// so plugins won't have to depend on them explicitly, which reduces their +// bundled size (e.g. a browser build). +// +const lib = { + mdurl: mdurl__namespace, + ucmicro: ucmicro__namespace +}; + +var utils = /*#__PURE__*/Object.freeze({ + __proto__: null, + arrayReplaceAt: arrayReplaceAt, + assign: assign, + escapeHtml: escapeHtml, + escapeRE: escapeRE, + fromCodePoint: fromCodePoint, + has: has, + isMdAsciiPunct: isMdAsciiPunct, + isPunctChar: isPunctChar, + isSpace: isSpace, + isString: isString, + isValidEntityCode: isValidEntityCode, + isWhiteSpace: isWhiteSpace, + lib: lib, + normalizeReference: normalizeReference, + unescapeAll: unescapeAll, + unescapeMd: unescapeMd +}); + +// Parse link label +// +// this function assumes that first character ("[") already matches; +// returns the end of the label +// + +function parseLinkLabel(state, start, disableNested) { + let level, found, marker, prevPos; + const max = state.posMax; + const oldPos = state.pos; + state.pos = start + 1; + level = 1; + while (state.pos < max) { + marker = state.src.charCodeAt(state.pos); + if (marker === 0x5D /* ] */) { + level--; + if (level === 0) { + found = true; + break; + } + } + prevPos = state.pos; + state.md.inline.skipToken(state); + if (marker === 0x5B /* [ */) { + if (prevPos === state.pos - 1) { + // increase level if we find text `[`, which is not a part of any token + level++; + } else if (disableNested) { + state.pos = oldPos; + return -1; + } + } + } + let labelEnd = -1; + if (found) { + labelEnd = state.pos; + } + + // restore old state + state.pos = oldPos; + return labelEnd; +} + +// Parse link destination +// + +function parseLinkDestination(str, start, max) { + let code; + let pos = start; + const result = { + ok: false, + pos: 0, + str: '' + }; + if (str.charCodeAt(pos) === 0x3C /* < */) { + pos++; + while (pos < max) { + code = str.charCodeAt(pos); + if (code === 0x0A /* \n */) { + return result; + } + if (code === 0x3C /* < */) { + return result; + } + if (code === 0x3E /* > */) { + result.pos = pos + 1; + result.str = unescapeAll(str.slice(start + 1, pos)); + result.ok = true; + return result; + } + if (code === 0x5C /* \ */ && pos + 1 < max) { + pos += 2; + continue; + } + pos++; + } + + // no closing '>' + return result; + } + + // this should be ... } else { ... branch + + let level = 0; + while (pos < max) { + code = str.charCodeAt(pos); + if (code === 0x20) { + break; + } + + // ascii control characters + if (code < 0x20 || code === 0x7F) { + break; + } + if (code === 0x5C /* \ */ && pos + 1 < max) { + if (str.charCodeAt(pos + 1) === 0x20) { + break; + } + pos += 2; + continue; + } + if (code === 0x28 /* ( */) { + level++; + if (level > 32) { + return result; + } + } + if (code === 0x29 /* ) */) { + if (level === 0) { + break; + } + level--; + } + pos++; + } + if (start === pos) { + return result; + } + if (level !== 0) { + return result; + } + result.str = unescapeAll(str.slice(start, pos)); + result.pos = pos; + result.ok = true; + return result; +} + +// Parse link title +// + + +// Parse link title within `str` in [start, max] range, +// or continue previous parsing if `prev_state` is defined (equal to result of last execution). +// +function parseLinkTitle(str, start, max, prev_state) { + let code; + let pos = start; + const state = { + // if `true`, this is a valid link title + ok: false, + // if `true`, this link can be continued on the next line + can_continue: false, + // if `ok`, it's the position of the first character after the closing marker + pos: 0, + // if `ok`, it's the unescaped title + str: '', + // expected closing marker character code + marker: 0 + }; + if (prev_state) { + // this is a continuation of a previous parseLinkTitle call on the next line, + // used in reference links only + state.str = prev_state.str; + state.marker = prev_state.marker; + } else { + if (pos >= max) { + return state; + } + let marker = str.charCodeAt(pos); + if (marker !== 0x22 /* " */ && marker !== 0x27 /* ' */ && marker !== 0x28 /* ( */) { + return state; + } + start++; + pos++; + + // if opening marker is "(", switch it to closing marker ")" + if (marker === 0x28) { + marker = 0x29; + } + state.marker = marker; + } + while (pos < max) { + code = str.charCodeAt(pos); + if (code === state.marker) { + state.pos = pos + 1; + state.str += unescapeAll(str.slice(start, pos)); + state.ok = true; + return state; + } else if (code === 0x28 /* ( */ && state.marker === 0x29 /* ) */) { + return state; + } else if (code === 0x5C /* \ */ && pos + 1 < max) { + pos++; + } + pos++; + } + + // no closing marker found, but this link title may continue on the next line (for references) + state.can_continue = true; + state.str += unescapeAll(str.slice(start, pos)); + return state; +} + +// Just a shortcut for bulk export + +var helpers = /*#__PURE__*/Object.freeze({ + __proto__: null, + parseLinkDestination: parseLinkDestination, + parseLinkLabel: parseLinkLabel, + parseLinkTitle: parseLinkTitle +}); + +/** + * class Renderer + * + * Generates HTML from parsed token stream. Each instance has independent + * copy of rules. Those can be rewritten with ease. Also, you can add new + * rules if you create plugin and adds new token types. + **/ + +const default_rules = {}; +default_rules.code_inline = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + return '' + escapeHtml(token.content) + '
'; +}; +default_rules.code_block = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + return '' + escapeHtml(tokens[idx].content) + '\n'; +}; +default_rules.fence = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + const info = token.info ? unescapeAll(token.info).trim() : ''; + let langName = ''; + let langAttrs = ''; + if (info) { + const arr = info.split(/(\s+)/g); + langName = arr[0]; + langAttrs = arr.slice(2).join(''); + } + let highlighted; + if (options.highlight) { + highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content); + } else { + highlighted = escapeHtml(token.content); + } + if (highlighted.indexOf('${highlighted}\n`; + } + return `
${highlighted}
\n`; +}; +default_rules.image = function (tokens, idx, options, env, slf) { + const token = tokens[idx]; + + // "alt" attr MUST be set, even if empty. Because it's mandatory and + // should be placed on proper position for tests. + // + // Replace content with actual value + + token.attrs[token.attrIndex('alt')][1] = slf.renderInlineAsText(token.children, options, env); + return slf.renderToken(tokens, idx, options); +}; +default_rules.hardbreak = function (tokens, idx, options /*, env */) { + return options.xhtmlOut ? '
\n' : '
\n'; +}; +default_rules.softbreak = function (tokens, idx, options /*, env */) { + return options.breaks ? options.xhtmlOut ? '
\n' : '
\n' : '\n'; +}; +default_rules.text = function (tokens, idx /*, options, env */) { + return escapeHtml(tokens[idx].content); +}; +default_rules.html_block = function (tokens, idx /*, options, env */) { + return tokens[idx].content; +}; +default_rules.html_inline = function (tokens, idx /*, options, env */) { + return tokens[idx].content; +}; + +/** + * new Renderer() + * + * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults. + **/ +function Renderer() { + /** + * Renderer#rules -> Object + * + * Contains render rules for tokens. Can be updated and extended. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.renderer.rules.strong_open = function () { return ''; }; + * md.renderer.rules.strong_close = function () { return ''; }; + * + * var result = md.renderInline(...); + * ``` + * + * Each rule is called as independent static function with fixed signature: + * + * ```javascript + * function my_token_render(tokens, idx, options, env, renderer) { + * // ... + * return renderedHTML; + * } + * ``` + * + * See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs) + * for more details and examples. + **/ + this.rules = assign({}, default_rules); +} + +/** + * Renderer.renderAttrs(token) -> String + * + * Render token attributes to string. + **/ +Renderer.prototype.renderAttrs = function renderAttrs(token) { + let i, l, result; + if (!token.attrs) { + return ''; + } + result = ''; + for (i = 0, l = token.attrs.length; i < l; i++) { + result += ' ' + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"'; + } + return result; +}; + +/** + * Renderer.renderToken(tokens, idx, options) -> String + * - tokens (Array): list of tokens + * - idx (Numbed): token index to render + * - options (Object): params of parser instance + * + * Default token renderer. Can be overriden by custom function + * in [[Renderer#rules]]. + **/ +Renderer.prototype.renderToken = function renderToken(tokens, idx, options) { + const token = tokens[idx]; + let result = ''; + + // Tight list paragraphs + if (token.hidden) { + return ''; + } + + // Insert a newline between hidden paragraph and subsequent opening + // block-level tag. + // + // For example, here we should insert a newline before blockquote: + // - a + // > + // + if (token.block && token.nesting !== -1 && idx && tokens[idx - 1].hidden) { + result += '\n'; + } + + // Add token name, e.g. ``. + // + needLf = false; + } + } + } + } + result += needLf ? '>\n' : '>'; + return result; +}; + +/** + * Renderer.renderInline(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * The same as [[Renderer.render]], but for single token of `inline` type. + **/ +Renderer.prototype.renderInline = function (tokens, options, env) { + let result = ''; + const rules = this.rules; + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type; + if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this); + } else { + result += this.renderToken(tokens, i, options); + } + } + return result; +}; + +/** internal + * Renderer.renderInlineAsText(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Special kludge for image `alt` attributes to conform CommonMark spec. + * Don't try to use it! Spec requires to show `alt` content with stripped markup, + * instead of simple escaping. + **/ +Renderer.prototype.renderInlineAsText = function (tokens, options, env) { + let result = ''; + for (let i = 0, len = tokens.length; i < len; i++) { + switch (tokens[i].type) { + case 'text': + result += tokens[i].content; + break; + case 'image': + result += this.renderInlineAsText(tokens[i].children, options, env); + break; + case 'html_inline': + case 'html_block': + result += tokens[i].content; + break; + case 'softbreak': + case 'hardbreak': + result += '\n'; + break; + // all other tokens are skipped + } + } + return result; +}; + +/** + * Renderer.render(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Takes token stream and generates HTML. Probably, you will never need to call + * this method directly. + **/ +Renderer.prototype.render = function (tokens, options, env) { + let result = ''; + const rules = this.rules; + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type; + if (type === 'inline') { + result += this.renderInline(tokens[i].children, options, env); + } else if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this); + } else { + result += this.renderToken(tokens, i, options, env); + } + } + return result; +}; + +/** + * class Ruler + * + * Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and + * [[MarkdownIt#inline]] to manage sequences of functions (rules): + * + * - keep rules in defined order + * - assign the name to each rule + * - enable/disable rules + * - add/replace rules + * - allow assign rules to additional named chains (in the same) + * - cacheing lists of active rules + * + * You will not need use this class directly until write plugins. For simple + * rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and + * [[MarkdownIt.use]]. + **/ + +/** + * new Ruler() + **/ +function Ruler() { + // List of added rules. Each element is: + // + // { + // name: XXX, + // enabled: Boolean, + // fn: Function(), + // alt: [ name2, name3 ] + // } + // + this.__rules__ = []; + + // Cached rule chains. + // + // First level - chain name, '' for default. + // Second level - diginal anchor for fast filtering by charcodes. + // + this.__cache__ = null; +} + +// Helper methods, should not be used directly + +// Find rule index by name +// +Ruler.prototype.__find__ = function (name) { + for (let i = 0; i < this.__rules__.length; i++) { + if (this.__rules__[i].name === name) { + return i; + } + } + return -1; +}; + +// Build rules lookup cache +// +Ruler.prototype.__compile__ = function () { + const self = this; + const chains = ['']; + + // collect unique names + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { + return; + } + rule.alt.forEach(function (altName) { + if (chains.indexOf(altName) < 0) { + chains.push(altName); + } + }); + }); + self.__cache__ = {}; + chains.forEach(function (chain) { + self.__cache__[chain] = []; + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { + return; + } + if (chain && rule.alt.indexOf(chain) < 0) { + return; + } + self.__cache__[chain].push(rule.fn); + }); + }); +}; + +/** + * Ruler.at(name, fn [, options]) + * - name (String): rule name to replace. + * - fn (Function): new rule function. + * - options (Object): new rule options (not mandatory). + * + * Replace rule by name with new function & options. Throws error if name not + * found. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * Replace existing typographer replacement rule with new one: + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.at('replacements', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.at = function (name, fn, options) { + const index = this.__find__(name); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + name); + } + this.__rules__[index].fn = fn; + this.__rules__[index].alt = opt.alt || []; + this.__cache__ = null; +}; + +/** + * Ruler.before(beforeName, ruleName, fn [, options]) + * - beforeName (String): new rule will be added before this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain before one with given name. See also + * [[Ruler.after]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.block.ruler.before('paragraph', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.before = function (beforeName, ruleName, fn, options) { + const index = this.__find__(beforeName); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + beforeName); + } + this.__rules__.splice(index, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.after(afterName, ruleName, fn [, options]) + * - afterName (String): new rule will be added after this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain after one with given name. See also + * [[Ruler.before]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.inline.ruler.after('text', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.after = function (afterName, ruleName, fn, options) { + const index = this.__find__(afterName); + const opt = options || {}; + if (index === -1) { + throw new Error('Parser rule not found: ' + afterName); + } + this.__rules__.splice(index + 1, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.push(ruleName, fn [, options]) + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Push new rule to the end of chain. See also + * [[Ruler.before]], [[Ruler.after]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.push('my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.push = function (ruleName, fn, options) { + const opt = options || {}; + this.__rules__.push({ + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }); + this.__cache__ = null; +}; + +/** + * Ruler.enable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to enable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.disable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.enable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + const result = []; + + // Search by name and enable + list.forEach(function (name) { + const idx = this.__find__(name); + if (idx < 0) { + if (ignoreInvalid) { + return; + } + throw new Error('Rules manager: invalid rule name ' + name); + } + this.__rules__[idx].enabled = true; + result.push(name); + }, this); + this.__cache__ = null; + return result; +}; + +/** + * Ruler.enableOnly(list [, ignoreInvalid]) + * - list (String|Array): list of rule names to enable (whitelist). + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names, and disable everything else. If any rule name + * not found - throw Error. Errors can be disabled by second param. + * + * See also [[Ruler.disable]], [[Ruler.enable]]. + **/ +Ruler.prototype.enableOnly = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + this.__rules__.forEach(function (rule) { + rule.enabled = false; + }); + this.enable(list, ignoreInvalid); +}; + +/** + * Ruler.disable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Disable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.enable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.disable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { + list = [list]; + } + const result = []; + + // Search by name and disable + list.forEach(function (name) { + const idx = this.__find__(name); + if (idx < 0) { + if (ignoreInvalid) { + return; + } + throw new Error('Rules manager: invalid rule name ' + name); + } + this.__rules__[idx].enabled = false; + result.push(name); + }, this); + this.__cache__ = null; + return result; +}; + +/** + * Ruler.getRules(chainName) -> Array + * + * Return array of active functions (rules) for given chain name. It analyzes + * rules configuration, compiles caches if not exists and returns result. + * + * Default chain name is `''` (empty string). It can't be skipped. That's + * done intentionally, to keep signature monomorphic for high speed. + **/ +Ruler.prototype.getRules = function (chainName) { + if (this.__cache__ === null) { + this.__compile__(); + } + + // Chain can be empty, if rules disabled. But we still have to return Array. + return this.__cache__[chainName] || []; +}; + +// Token class + +/** + * class Token + **/ + +/** + * new Token(type, tag, nesting) + * + * Create new token and fill passed properties. + **/ +function Token(type, tag, nesting) { + /** + * Token#type -> String + * + * Type of the token (string, e.g. "paragraph_open") + **/ + this.type = type; + + /** + * Token#tag -> String + * + * html tag name, e.g. "p" + **/ + this.tag = tag; + + /** + * Token#attrs -> Array + * + * Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]` + **/ + this.attrs = null; + + /** + * Token#map -> Array + * + * Source map info. Format: `[ line_begin, line_end ]` + **/ + this.map = null; + + /** + * Token#nesting -> Number + * + * Level change (number in {-1, 0, 1} set), where: + * + * - `1` means the tag is opening + * - `0` means the tag is self-closing + * - `-1` means the tag is closing + **/ + this.nesting = nesting; + + /** + * Token#level -> Number + * + * nesting level, the same as `state.level` + **/ + this.level = 0; + + /** + * Token#children -> Array + * + * An array of child nodes (inline and img tokens) + **/ + this.children = null; + + /** + * Token#content -> String + * + * In a case of self-closing tag (code, html, fence, etc.), + * it has contents of this tag. + **/ + this.content = ''; + + /** + * Token#markup -> String + * + * '*' or '_' for emphasis, fence string for fence, etc. + **/ + this.markup = ''; + + /** + * Token#info -> String + * + * Additional information: + * + * - Info string for "fence" tokens + * - The value "auto" for autolink "link_open" and "link_close" tokens + * - The string value of the item marker for ordered-list "list_item_open" tokens + **/ + this.info = ''; + + /** + * Token#meta -> Object + * + * A place for plugins to store an arbitrary data + **/ + this.meta = null; + + /** + * Token#block -> Boolean + * + * True for block-level tokens, false for inline tokens. + * Used in renderer to calculate line breaks + **/ + this.block = false; + + /** + * Token#hidden -> Boolean + * + * If it's true, ignore this element when rendering. Used for tight lists + * to hide paragraphs. + **/ + this.hidden = false; +} + +/** + * Token.attrIndex(name) -> Number + * + * Search attribute index by name. + **/ +Token.prototype.attrIndex = function attrIndex(name) { + if (!this.attrs) { + return -1; + } + const attrs = this.attrs; + for (let i = 0, len = attrs.length; i < len; i++) { + if (attrs[i][0] === name) { + return i; + } + } + return -1; +}; + +/** + * Token.attrPush(attrData) + * + * Add `[ name, value ]` attribute to list. Init attrs if necessary + **/ +Token.prototype.attrPush = function attrPush(attrData) { + if (this.attrs) { + this.attrs.push(attrData); + } else { + this.attrs = [attrData]; + } +}; + +/** + * Token.attrSet(name, value) + * + * Set `name` attribute to `value`. Override old value if exists. + **/ +Token.prototype.attrSet = function attrSet(name, value) { + const idx = this.attrIndex(name); + const attrData = [name, value]; + if (idx < 0) { + this.attrPush(attrData); + } else { + this.attrs[idx] = attrData; + } +}; + +/** + * Token.attrGet(name) + * + * Get the value of attribute `name`, or null if it does not exist. + **/ +Token.prototype.attrGet = function attrGet(name) { + const idx = this.attrIndex(name); + let value = null; + if (idx >= 0) { + value = this.attrs[idx][1]; + } + return value; +}; + +/** + * Token.attrJoin(name, value) + * + * Join value to existing attribute via space. Or create new attribute if not + * exists. Useful to operate with token classes. + **/ +Token.prototype.attrJoin = function attrJoin(name, value) { + const idx = this.attrIndex(name); + if (idx < 0) { + this.attrPush([name, value]); + } else { + this.attrs[idx][1] = this.attrs[idx][1] + ' ' + value; + } +}; + +// Core state object +// + +function StateCore(src, md, env) { + this.src = src; + this.env = env; + this.tokens = []; + this.inlineMode = false; + this.md = md; // link to parser instance +} + +// re-export Token class to use in core rules +StateCore.prototype.Token = Token; + +// Normalize input string + +// https://spec.commonmark.org/0.29/#line-ending +const NEWLINES_RE = /\r\n?|\n/g; +const NULL_RE = /\0/g; +function normalize(state) { + let str; + + // Normalize newlines + str = state.src.replace(NEWLINES_RE, '\n'); + + // Replace NULL characters + str = str.replace(NULL_RE, '\uFFFD'); + state.src = str; +} + +function block(state) { + let token; + if (state.inlineMode) { + token = new state.Token('inline', '', 0); + token.content = state.src; + token.map = [0, 1]; + token.children = []; + state.tokens.push(token); + } else { + state.md.block.parse(state.src, state.md, state.env, state.tokens); + } +} + +function inline(state) { + const tokens = state.tokens; + + // Parse inlines + for (let i = 0, l = tokens.length; i < l; i++) { + const tok = tokens[i]; + if (tok.type === 'inline') { + state.md.inline.parse(tok.content, state.md, state.env, tok.children); + } + } +} + +// Replace link-like texts with link nodes. +// +// Currently restricted by `md.validateLink()` to http/https/ftp +// + +function isLinkOpen$1(str) { + return /^\s]/i.test(str); +} +function isLinkClose$1(str) { + return /^<\/a\s*>/i.test(str); +} +function linkify$1(state) { + const blockTokens = state.tokens; + if (!state.md.options.linkify) { + return; + } + for (let j = 0, l = blockTokens.length; j < l; j++) { + if (blockTokens[j].type !== 'inline' || !state.md.linkify.pretest(blockTokens[j].content)) { + continue; + } + let tokens = blockTokens[j].children; + let htmlLinkLevel = 0; + + // We scan from the end, to keep position when new tags added. + // Use reversed logic in links start/end match + for (let i = tokens.length - 1; i >= 0; i--) { + const currentToken = tokens[i]; + + // Skip content of markdown links + if (currentToken.type === 'link_close') { + i--; + while (tokens[i].level !== currentToken.level && tokens[i].type !== 'link_open') { + i--; + } + continue; + } + + // Skip content of html tag links + if (currentToken.type === 'html_inline') { + if (isLinkOpen$1(currentToken.content) && htmlLinkLevel > 0) { + htmlLinkLevel--; + } + if (isLinkClose$1(currentToken.content)) { + htmlLinkLevel++; + } + } + if (htmlLinkLevel > 0) { + continue; + } + if (currentToken.type === 'text' && state.md.linkify.test(currentToken.content)) { + const text = currentToken.content; + let links = state.md.linkify.match(text); + + // Now split string to nodes + const nodes = []; + let level = currentToken.level; + let lastPos = 0; + + // forbid escape sequence at the start of the string, + // this avoids http\://example.com/ from being linkified as + // http:
//example.com/ + if (links.length > 0 && links[0].index === 0 && i > 0 && tokens[i - 1].type === 'text_special') { + links = links.slice(1); + } + for (let ln = 0; ln < links.length; ln++) { + const url = links[ln].url; + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) { + continue; + } + let urlText = links[ln].text; + + // Linkifier might send raw hostnames like "example.com", where url + // starts with domain name. So we prepend http:// in those cases, + // and remove it afterwards. + // + if (!links[ln].schema) { + urlText = state.md.normalizeLinkText('http://' + urlText).replace(/^http:\/\//, ''); + } else if (links[ln].schema === 'mailto:' && !/^mailto:/i.test(urlText)) { + urlText = state.md.normalizeLinkText('mailto:' + urlText).replace(/^mailto:/, ''); + } else { + urlText = state.md.normalizeLinkText(urlText); + } + const pos = links[ln].index; + if (pos > lastPos) { + const token = new state.Token('text', '', 0); + token.content = text.slice(lastPos, pos); + token.level = level; + nodes.push(token); + } + const token_o = new state.Token('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.level = level++; + token_o.markup = 'linkify'; + token_o.info = 'auto'; + nodes.push(token_o); + const token_t = new state.Token('text', '', 0); + token_t.content = urlText; + token_t.level = level; + nodes.push(token_t); + const token_c = new state.Token('link_close', 'a', -1); + token_c.level = --level; + token_c.markup = 'linkify'; + token_c.info = 'auto'; + nodes.push(token_c); + lastPos = links[ln].lastIndex; + } + if (lastPos < text.length) { + const token = new state.Token('text', '', 0); + token.content = text.slice(lastPos); + token.level = level; + nodes.push(token); + } + + // replace current node + blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes); + } + } + } +} + +// Simple typographic replacements +// +// (c) (C) → © +// (tm) (TM) → ™ +// (r) (R) → ® +// +- → ± +// ... → … (also ?.... → ?.., !.... → !..) +// ???????? → ???, !!!!! → !!!, `,,` → `,` +// -- → –, --- → — +// + +// TODO: +// - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾ +// - multiplications 2 x 4 -> 2 × 4 + +const RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/; + +// Workaround for phantomjs - need regex without /g flag, +// or root check will fail every second time +const SCOPED_ABBR_TEST_RE = /\((c|tm|r)\)/i; +const SCOPED_ABBR_RE = /\((c|tm|r)\)/ig; +const SCOPED_ABBR = { + c: '©', + r: '®', + tm: '™' +}; +function replaceFn(match, name) { + return SCOPED_ABBR[name.toLowerCase()]; +} +function replace_scoped(inlineTokens) { + let inside_autolink = 0; + for (let i = inlineTokens.length - 1; i >= 0; i--) { + const token = inlineTokens[i]; + if (token.type === 'text' && !inside_autolink) { + token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn); + } + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } + } +} +function replace_rare(inlineTokens) { + let inside_autolink = 0; + for (let i = inlineTokens.length - 1; i >= 0; i--) { + const token = inlineTokens[i]; + if (token.type === 'text' && !inside_autolink) { + if (RARE_RE.test(token.content)) { + token.content = token.content.replace(/\+-/g, '±') + // .., ..., ....... -> … + // but ?..... & !..... -> ?.. & !.. + .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..').replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') + // em-dash + .replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014') + // en-dash + .replace(/(^|\s)--(?=\s|$)/mg, '$1\u2013').replace(/(^|[^-\s])--(?=[^-\s]|$)/mg, '$1\u2013'); + } + } + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } + } +} +function replace(state) { + let blkIdx; + if (!state.md.options.typographer) { + return; + } + for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { + if (state.tokens[blkIdx].type !== 'inline') { + continue; + } + if (SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) { + replace_scoped(state.tokens[blkIdx].children); + } + if (RARE_RE.test(state.tokens[blkIdx].content)) { + replace_rare(state.tokens[blkIdx].children); + } + } +} + +// Convert straight quotation marks to typographic ones +// + +const QUOTE_TEST_RE = /['"]/; +const QUOTE_RE = /['"]/g; +const APOSTROPHE = '\u2019'; /* ’ */ + +function replaceAt(str, index, ch) { + return str.slice(0, index) + ch + str.slice(index + 1); +} +function process_inlines(tokens, state) { + let j; + const stack = []; + for (let i = 0; i < tokens.length; i++) { + const token = tokens[i]; + const thisLevel = tokens[i].level; + for (j = stack.length - 1; j >= 0; j--) { + if (stack[j].level <= thisLevel) { + break; + } + } + stack.length = j + 1; + if (token.type !== 'text') { + continue; + } + let text = token.content; + let pos = 0; + let max = text.length; + + /* eslint no-labels:0,block-scoped-var:0 */ + OUTER: while (pos < max) { + QUOTE_RE.lastIndex = pos; + const t = QUOTE_RE.exec(text); + if (!t) { + break; + } + let canOpen = true; + let canClose = true; + pos = t.index + 1; + const isSingle = t[0] === "'"; + + // Find previous character, + // default to space if it's the beginning of the line + // + let lastChar = 0x20; + if (t.index - 1 >= 0) { + lastChar = text.charCodeAt(t.index - 1); + } else { + for (j = i - 1; j >= 0; j--) { + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // lastChar defaults to 0x20 + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' + + lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1); + break; + } + } + + // Find next character, + // default to space if it's the end of the line + // + let nextChar = 0x20; + if (pos < max) { + nextChar = text.charCodeAt(pos); + } else { + for (j = i + 1; j < tokens.length; j++) { + if (tokens[j].type === 'softbreak' || tokens[j].type === 'hardbreak') break; // nextChar defaults to 0x20 + if (!tokens[j].content) continue; // should skip all tokens except 'text', 'html_inline' or 'code_inline' + + nextChar = tokens[j].content.charCodeAt(0); + break; + } + } + const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)); + const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)); + const isLastWhiteSpace = isWhiteSpace(lastChar); + const isNextWhiteSpace = isWhiteSpace(nextChar); + if (isNextWhiteSpace) { + canOpen = false; + } else if (isNextPunctChar) { + if (!(isLastWhiteSpace || isLastPunctChar)) { + canOpen = false; + } + } + if (isLastWhiteSpace) { + canClose = false; + } else if (isLastPunctChar) { + if (!(isNextWhiteSpace || isNextPunctChar)) { + canClose = false; + } + } + if (nextChar === 0x22 /* " */ && t[0] === '"') { + if (lastChar >= 0x30 /* 0 */ && lastChar <= 0x39 /* 9 */) { + // special case: 1"" - count first quote as an inch + canClose = canOpen = false; + } + } + if (canOpen && canClose) { + // Replace quotes in the middle of punctuation sequence, but not + // in the middle of the words, i.e.: + // + // 1. foo " bar " baz - not replaced + // 2. foo-"-bar-"-baz - replaced + // 3. foo"bar"baz - not replaced + // + canOpen = isLastPunctChar; + canClose = isNextPunctChar; + } + if (!canOpen && !canClose) { + // middle of word + if (isSingle) { + token.content = replaceAt(token.content, t.index, APOSTROPHE); + } + continue; + } + if (canClose) { + // this could be a closing quote, rewind the stack to get a match + for (j = stack.length - 1; j >= 0; j--) { + let item = stack[j]; + if (stack[j].level < thisLevel) { + break; + } + if (item.single === isSingle && stack[j].level === thisLevel) { + item = stack[j]; + let openQuote; + let closeQuote; + if (isSingle) { + openQuote = state.md.options.quotes[2]; + closeQuote = state.md.options.quotes[3]; + } else { + openQuote = state.md.options.quotes[0]; + closeQuote = state.md.options.quotes[1]; + } + + // replace token.content *before* tokens[item.token].content, + // because, if they are pointing at the same token, replaceAt + // could mess up indices when quote length != 1 + token.content = replaceAt(token.content, t.index, closeQuote); + tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, openQuote); + pos += closeQuote.length - 1; + if (item.token === i) { + pos += openQuote.length - 1; + } + text = token.content; + max = text.length; + stack.length = j; + continue OUTER; + } + } + } + if (canOpen) { + stack.push({ + token: i, + pos: t.index, + single: isSingle, + level: thisLevel + }); + } else if (canClose && isSingle) { + token.content = replaceAt(token.content, t.index, APOSTROPHE); + } + } + } +} +function smartquotes(state) { + /* eslint max-depth:0 */ + if (!state.md.options.typographer) { + return; + } + for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { + if (state.tokens[blkIdx].type !== 'inline' || !QUOTE_TEST_RE.test(state.tokens[blkIdx].content)) { + continue; + } + process_inlines(state.tokens[blkIdx].children, state); + } +} + +// Join raw text tokens with the rest of the text +// +// This is set as a separate rule to provide an opportunity for plugins +// to run text replacements after text join, but before escape join. +// +// For example, `\:)` shouldn't be replaced with an emoji. +// + +function text_join(state) { + let curr, last; + const blockTokens = state.tokens; + const l = blockTokens.length; + for (let j = 0; j < l; j++) { + if (blockTokens[j].type !== 'inline') continue; + const tokens = blockTokens[j].children; + const max = tokens.length; + for (curr = 0; curr < max; curr++) { + if (tokens[curr].type === 'text_special') { + tokens[curr].type = 'text'; + } + } + for (curr = last = 0; curr < max; curr++) { + if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { + // collapse two adjacent text nodes + tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content; + } else { + if (curr !== last) { + tokens[last] = tokens[curr]; + } + last++; + } + } + if (curr !== last) { + tokens.length = last; + } + } +} + +/** internal + * class Core + * + * Top-level rules executor. Glues block/inline parsers and does intermediate + * transformations. + **/ + +const _rules$2 = [['normalize', normalize], ['block', block], ['inline', inline], ['linkify', linkify$1], ['replacements', replace], ['smartquotes', smartquotes], +// `text_join` finds `text_special` tokens (for escape sequences) +// and joins them with the rest of the text +['text_join', text_join]]; + +/** + * new Core() + **/ +function Core() { + /** + * Core#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of core rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules$2.length; i++) { + this.ruler.push(_rules$2[i][0], _rules$2[i][1]); + } +} + +/** + * Core.process(state) + * + * Executes core chain rules. + **/ +Core.prototype.process = function (state) { + const rules = this.ruler.getRules(''); + for (let i = 0, l = rules.length; i < l; i++) { + rules[i](state); + } +}; +Core.prototype.State = StateCore; + +// Parser state class + +function StateBlock(src, md, env, tokens) { + this.src = src; + + // link to parser instance + this.md = md; + this.env = env; + + // + // Internal state vartiables + // + + this.tokens = tokens; + this.bMarks = []; // line begin offsets for fast jumps + this.eMarks = []; // line end offsets for fast jumps + this.tShift = []; // offsets of the first non-space characters (tabs not expanded) + this.sCount = []; // indents for each line (tabs expanded) + + // An amount of virtual spaces (tabs expanded) between beginning + // of each line (bMarks) and real beginning of that line. + // + // It exists only as a hack because blockquotes override bMarks + // losing information in the process. + // + // It's used only when expanding tabs, you can think about it as + // an initial tab length, e.g. bsCount=21 applied to string `\t123` + // means first tab should be expanded to 4-21%4 === 3 spaces. + // + this.bsCount = []; + + // block parser variables + + // required block content indent (for example, if we are + // inside a list, it would be positioned after list marker) + this.blkIndent = 0; + this.line = 0; // line index in src + this.lineMax = 0; // lines count + this.tight = false; // loose/tight mode for lists + this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any) + this.listIndent = -1; // indent of the current list block (-1 if there isn't any) + + // can be 'blockquote', 'list', 'root', 'paragraph' or 'reference' + // used in lists to determine if they interrupt a paragraph + this.parentType = 'root'; + this.level = 0; + + // Create caches + // Generate markers. + const s = this.src; + for (let start = 0, pos = 0, indent = 0, offset = 0, len = s.length, indent_found = false; pos < len; pos++) { + const ch = s.charCodeAt(pos); + if (!indent_found) { + if (isSpace(ch)) { + indent++; + if (ch === 0x09) { + offset += 4 - offset % 4; + } else { + offset++; + } + continue; + } else { + indent_found = true; + } + } + if (ch === 0x0A || pos === len - 1) { + if (ch !== 0x0A) { + pos++; + } + this.bMarks.push(start); + this.eMarks.push(pos); + this.tShift.push(indent); + this.sCount.push(offset); + this.bsCount.push(0); + indent_found = false; + indent = 0; + offset = 0; + start = pos + 1; + } + } + + // Push fake entry to simplify cache bounds checks + this.bMarks.push(s.length); + this.eMarks.push(s.length); + this.tShift.push(0); + this.sCount.push(0); + this.bsCount.push(0); + this.lineMax = this.bMarks.length - 1; // don't count last fake line +} + +// Push new token to "stream". +// +StateBlock.prototype.push = function (type, tag, nesting) { + const token = new Token(type, tag, nesting); + token.block = true; + if (nesting < 0) this.level--; // closing tag + token.level = this.level; + if (nesting > 0) this.level++; // opening tag + + this.tokens.push(token); + return token; +}; +StateBlock.prototype.isEmpty = function isEmpty(line) { + return this.bMarks[line] + this.tShift[line] >= this.eMarks[line]; +}; +StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) { + for (let max = this.lineMax; from < max; from++) { + if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) { + break; + } + } + return from; +}; + +// Skip spaces from given position. +StateBlock.prototype.skipSpaces = function skipSpaces(pos) { + for (let max = this.src.length; pos < max; pos++) { + const ch = this.src.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + } + return pos; +}; + +// Skip spaces from given position in reverse. +StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) { + if (pos <= min) { + return pos; + } + while (pos > min) { + if (!isSpace(this.src.charCodeAt(--pos))) { + return pos + 1; + } + } + return pos; +}; + +// Skip char codes from given position +StateBlock.prototype.skipChars = function skipChars(pos, code) { + for (let max = this.src.length; pos < max; pos++) { + if (this.src.charCodeAt(pos) !== code) { + break; + } + } + return pos; +}; + +// Skip char codes reverse from given position - 1 +StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) { + if (pos <= min) { + return pos; + } + while (pos > min) { + if (code !== this.src.charCodeAt(--pos)) { + return pos + 1; + } + } + return pos; +}; + +// cut lines range from source. +StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) { + if (begin >= end) { + return ''; + } + const queue = new Array(end - begin); + for (let i = 0, line = begin; line < end; line++, i++) { + let lineIndent = 0; + const lineStart = this.bMarks[line]; + let first = lineStart; + let last; + if (line + 1 < end || keepLastLF) { + // No need for bounds check because we have fake entry on tail. + last = this.eMarks[line] + 1; + } else { + last = this.eMarks[line]; + } + while (first < last && lineIndent < indent) { + const ch = this.src.charCodeAt(first); + if (isSpace(ch)) { + if (ch === 0x09) { + lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4; + } else { + lineIndent++; + } + } else if (first - lineStart < this.tShift[line]) { + // patched tShift masked characters to look like spaces (blockquotes, list markers) + lineIndent++; + } else { + break; + } + first++; + } + if (lineIndent > indent) { + // partially expanding tabs in code blocks, e.g '\t\tfoobar' + // with indent=2 becomes ' \tfoobar' + queue[i] = new Array(lineIndent - indent + 1).join(' ') + this.src.slice(first, last); + } else { + queue[i] = this.src.slice(first, last); + } + } + return queue.join(''); +}; + +// re-export Token class to use in block rules +StateBlock.prototype.Token = Token; + +// GFM table, https://github.github.com/gfm/#tables-extension- + + +// Limit the amount of empty autocompleted cells in a table, +// see https://github.com/markdown-it/markdown-it/issues/1000, +// +// Both pulldown-cmark and commonmark-hs limit the number of cells this way to ~200k. +// We set it to 65k, which can expand user input by a factor of x370 +// (256x256 square is 1.8kB expanded into 650kB). +const MAX_AUTOCOMPLETED_CELLS = 0x10000; +function getLine(state, line) { + const pos = state.bMarks[line] + state.tShift[line]; + const max = state.eMarks[line]; + return state.src.slice(pos, max); +} +function escapedSplit(str) { + const result = []; + const max = str.length; + let pos = 0; + let ch = str.charCodeAt(pos); + let isEscaped = false; + let lastPos = 0; + let current = ''; + while (pos < max) { + if (ch === 0x7c /* | */) { + if (!isEscaped) { + // pipe separating cells, '|' + result.push(current + str.substring(lastPos, pos)); + current = ''; + lastPos = pos + 1; + } else { + // escaped pipe, '\|' + current += str.substring(lastPos, pos - 1); + lastPos = pos; + } + } + isEscaped = ch === 0x5c /* \ */; + pos++; + ch = str.charCodeAt(pos); + } + result.push(current + str.substring(lastPos)); + return result; +} +function table(state, startLine, endLine, silent) { + // should have at least two lines + if (startLine + 2 > endLine) { + return false; + } + let nextLine = startLine + 1; + if (state.sCount[nextLine] < state.blkIndent) { + return false; + } + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + return false; + } + + // first character of the second line should be '|', '-', ':', + // and no other characters are allowed but spaces; + // basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp + + let pos = state.bMarks[nextLine] + state.tShift[nextLine]; + if (pos >= state.eMarks[nextLine]) { + return false; + } + const firstCh = state.src.charCodeAt(pos++); + if (firstCh !== 0x7C /* | */ && firstCh !== 0x2D /* - */ && firstCh !== 0x3A /* : */) { + return false; + } + if (pos >= state.eMarks[nextLine]) { + return false; + } + const secondCh = state.src.charCodeAt(pos++); + if (secondCh !== 0x7C /* | */ && secondCh !== 0x2D /* - */ && secondCh !== 0x3A /* : */ && !isSpace(secondCh)) { + return false; + } + + // if first character is '-', then second character must not be a space + // (due to parsing ambiguity with list) + if (firstCh === 0x2D /* - */ && isSpace(secondCh)) { + return false; + } + while (pos < state.eMarks[nextLine]) { + const ch = state.src.charCodeAt(pos); + if (ch !== 0x7C /* | */ && ch !== 0x2D /* - */ && ch !== 0x3A /* : */ && !isSpace(ch)) { + return false; + } + pos++; + } + let lineText = getLine(state, startLine + 1); + let columns = lineText.split('|'); + const aligns = []; + for (let i = 0; i < columns.length; i++) { + const t = columns[i].trim(); + if (!t) { + // allow empty columns before and after table, but not in between columns; + // e.g. allow ` |---| `, disallow ` ---||--- ` + if (i === 0 || i === columns.length - 1) { + continue; + } else { + return false; + } + } + if (!/^:?-+:?$/.test(t)) { + return false; + } + if (t.charCodeAt(t.length - 1) === 0x3A /* : */) { + aligns.push(t.charCodeAt(0) === 0x3A /* : */ ? 'center' : 'right'); + } else if (t.charCodeAt(0) === 0x3A /* : */) { + aligns.push('left'); + } else { + aligns.push(''); + } + } + lineText = getLine(state, startLine).trim(); + if (lineText.indexOf('|') === -1) { + return false; + } + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + columns = escapedSplit(lineText); + if (columns.length && columns[0] === '') columns.shift(); + if (columns.length && columns[columns.length - 1] === '') columns.pop(); + + // header row will define an amount of columns in the entire table, + // and align row should be exactly the same (the rest of the rows can differ) + const columnCount = columns.length; + if (columnCount === 0 || columnCount !== aligns.length) { + return false; + } + if (silent) { + return true; + } + const oldParentType = state.parentType; + state.parentType = 'table'; + + // use 'blockquote' lists for termination because it's + // the most similar to tables + const terminatorRules = state.md.block.ruler.getRules('blockquote'); + const token_to = state.push('table_open', 'table', 1); + const tableLines = [startLine, 0]; + token_to.map = tableLines; + const token_tho = state.push('thead_open', 'thead', 1); + token_tho.map = [startLine, startLine + 1]; + const token_htro = state.push('tr_open', 'tr', 1); + token_htro.map = [startLine, startLine + 1]; + for (let i = 0; i < columns.length; i++) { + const token_ho = state.push('th_open', 'th', 1); + if (aligns[i]) { + token_ho.attrs = [['style', 'text-align:' + aligns[i]]]; + } + const token_il = state.push('inline', '', 0); + token_il.content = columns[i].trim(); + token_il.children = []; + state.push('th_close', 'th', -1); + } + state.push('tr_close', 'tr', -1); + state.push('thead_close', 'thead', -1); + let tbodyLines; + let autocompletedCells = 0; + for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + lineText = getLine(state, nextLine).trim(); + if (!lineText) { + break; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + break; + } + columns = escapedSplit(lineText); + if (columns.length && columns[0] === '') columns.shift(); + if (columns.length && columns[columns.length - 1] === '') columns.pop(); + + // note: autocomplete count can be negative if user specifies more columns than header, + // but that does not affect intended use (which is limiting expansion) + autocompletedCells += columnCount - columns.length; + if (autocompletedCells > MAX_AUTOCOMPLETED_CELLS) { + break; + } + if (nextLine === startLine + 2) { + const token_tbo = state.push('tbody_open', 'tbody', 1); + token_tbo.map = tbodyLines = [startLine + 2, 0]; + } + const token_tro = state.push('tr_open', 'tr', 1); + token_tro.map = [nextLine, nextLine + 1]; + for (let i = 0; i < columnCount; i++) { + const token_tdo = state.push('td_open', 'td', 1); + if (aligns[i]) { + token_tdo.attrs = [['style', 'text-align:' + aligns[i]]]; + } + const token_il = state.push('inline', '', 0); + token_il.content = columns[i] ? columns[i].trim() : ''; + token_il.children = []; + state.push('td_close', 'td', -1); + } + state.push('tr_close', 'tr', -1); + } + if (tbodyLines) { + state.push('tbody_close', 'tbody', -1); + tbodyLines[1] = nextLine; + } + state.push('table_close', 'table', -1); + tableLines[1] = nextLine; + state.parentType = oldParentType; + state.line = nextLine; + return true; +} + +// Code block (4 spaces padded) + +function code(state, startLine, endLine /*, silent */) { + if (state.sCount[startLine] - state.blkIndent < 4) { + return false; + } + let nextLine = startLine + 1; + let last = nextLine; + while (nextLine < endLine) { + if (state.isEmpty(nextLine)) { + nextLine++; + continue; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + nextLine++; + last = nextLine; + continue; + } + break; + } + state.line = last; + const token = state.push('code_block', 'code', 0); + token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + '\n'; + token.map = [startLine, state.line]; + return true; +} + +// fences (``` lang, ~~~ lang) + +function fence(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (pos + 3 > max) { + return false; + } + const marker = state.src.charCodeAt(pos); + if (marker !== 0x7E /* ~ */ && marker !== 0x60 /* ` */) { + return false; + } + + // scan marker length + let mem = pos; + pos = state.skipChars(pos, marker); + let len = pos - mem; + if (len < 3) { + return false; + } + const markup = state.src.slice(mem, pos); + const params = state.src.slice(pos, max); + if (marker === 0x60 /* ` */) { + if (params.indexOf(String.fromCharCode(marker)) >= 0) { + return false; + } + } + + // Since start is found, we can report success here in validation mode + if (silent) { + return true; + } + + // search end of block + let nextLine = startLine; + let haveEndMarker = false; + for (;;) { + nextLine++; + if (nextLine >= endLine) { + // unclosed block should be autoclosed by end of document. + // also block seems to be autoclosed by end of parent + break; + } + pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + if (pos < max && state.sCount[nextLine] < state.blkIndent) { + // non-empty line with negative indent should stop the list: + // - ``` + // test + break; + } + if (state.src.charCodeAt(pos) !== marker) { + continue; + } + if (state.sCount[nextLine] - state.blkIndent >= 4) { + // closing fence should be indented less than 4 spaces + continue; + } + pos = state.skipChars(pos, marker); + + // closing code fence must be at least as long as the opening one + if (pos - mem < len) { + continue; + } + + // make sure tail has spaces only + pos = state.skipSpaces(pos); + if (pos < max) { + continue; + } + haveEndMarker = true; + // found! + break; + } + + // If a fence has heading spaces, they should be removed from its inner block + len = state.sCount[startLine]; + state.line = nextLine + (haveEndMarker ? 1 : 0); + const token = state.push('fence', 'code', 0); + token.info = params; + token.content = state.getLines(startLine + 1, nextLine, len, true); + token.markup = markup; + token.map = [startLine, state.line]; + return true; +} + +// Block quotes + +function blockquote(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + const oldLineMax = state.lineMax; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + + // check the block quote marker + if (state.src.charCodeAt(pos) !== 0x3E /* > */) { + return false; + } + + // we know that it's going to be a valid blockquote, + // so no point trying to find the end of it in silent mode + if (silent) { + return true; + } + const oldBMarks = []; + const oldBSCount = []; + const oldSCount = []; + const oldTShift = []; + const terminatorRules = state.md.block.ruler.getRules('blockquote'); + const oldParentType = state.parentType; + state.parentType = 'blockquote'; + let lastLineEmpty = false; + let nextLine; + + // Search the end of the block + // + // Block ends with either: + // 1. an empty line outside: + // ``` + // > test + // + // ``` + // 2. an empty line inside: + // ``` + // > + // test + // ``` + // 3. another tag: + // ``` + // > test + // - - - + // ``` + for (nextLine = startLine; nextLine < endLine; nextLine++) { + // check if it's outdented, i.e. it's inside list item and indented + // less than said list item: + // + // ``` + // 1. anything + // > current blockquote + // 2. checking this line + // ``` + const isOutdented = state.sCount[nextLine] < state.blkIndent; + pos = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + if (pos >= max) { + // Case 1: line is not inside the blockquote, and this line is empty. + break; + } + if (state.src.charCodeAt(pos++) === 0x3E /* > */ && !isOutdented) { + // This line is inside the blockquote. + + // set offset past spaces and ">" + let initial = state.sCount[nextLine] + 1; + let spaceAfterMarker; + let adjustTab; + + // skip one optional space after '>' + if (state.src.charCodeAt(pos) === 0x20 /* space */) { + // ' > test ' + // ^ -- position start of line here: + pos++; + initial++; + adjustTab = false; + spaceAfterMarker = true; + } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { + spaceAfterMarker = true; + if ((state.bsCount[nextLine] + initial) % 4 === 3) { + // ' >\t test ' + // ^ -- position start of line here (tab has width===1) + pos++; + initial++; + adjustTab = false; + } else { + // ' >\t test ' + // ^ -- position start of line here + shift bsCount slightly + // to make extra space appear + adjustTab = true; + } + } else { + spaceAfterMarker = false; + } + let offset = initial; + oldBMarks.push(state.bMarks[nextLine]); + state.bMarks[nextLine] = pos; + while (pos < max) { + const ch = state.src.charCodeAt(pos); + if (isSpace(ch)) { + if (ch === 0x09) { + offset += 4 - (offset + state.bsCount[nextLine] + (adjustTab ? 1 : 0)) % 4; + } else { + offset++; + } + } else { + break; + } + pos++; + } + lastLineEmpty = pos >= max; + oldBSCount.push(state.bsCount[nextLine]); + state.bsCount[nextLine] = state.sCount[nextLine] + 1 + (spaceAfterMarker ? 1 : 0); + oldSCount.push(state.sCount[nextLine]); + state.sCount[nextLine] = offset - initial; + oldTShift.push(state.tShift[nextLine]); + state.tShift[nextLine] = pos - state.bMarks[nextLine]; + continue; + } + + // Case 2: line is not inside the blockquote, and the last line was empty. + if (lastLineEmpty) { + break; + } + + // Case 3: another tag found. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + // Quirk to enforce "hard termination mode" for paragraphs; + // normally if you call `tokenize(state, startLine, nextLine)`, + // paragraphs will look below nextLine for paragraph continuation, + // but if blockquote is terminated by another tag, they shouldn't + state.lineMax = nextLine; + if (state.blkIndent !== 0) { + // state.blkIndent was non-zero, we now set it to zero, + // so we need to re-calculate all offsets to appear as + // if indent wasn't changed + oldBMarks.push(state.bMarks[nextLine]); + oldBSCount.push(state.bsCount[nextLine]); + oldTShift.push(state.tShift[nextLine]); + oldSCount.push(state.sCount[nextLine]); + state.sCount[nextLine] -= state.blkIndent; + } + break; + } + oldBMarks.push(state.bMarks[nextLine]); + oldBSCount.push(state.bsCount[nextLine]); + oldTShift.push(state.tShift[nextLine]); + oldSCount.push(state.sCount[nextLine]); + + // A negative indentation means that this is a paragraph continuation + // + state.sCount[nextLine] = -1; + } + const oldIndent = state.blkIndent; + state.blkIndent = 0; + const token_o = state.push('blockquote_open', 'blockquote', 1); + token_o.markup = '>'; + const lines = [startLine, 0]; + token_o.map = lines; + state.md.block.tokenize(state, startLine, nextLine); + const token_c = state.push('blockquote_close', 'blockquote', -1); + token_c.markup = '>'; + state.lineMax = oldLineMax; + state.parentType = oldParentType; + lines[1] = state.line; + + // Restore original tShift; this might not be necessary since the parser + // has already been here, but just to make sure we can do that. + for (let i = 0; i < oldTShift.length; i++) { + state.bMarks[i + startLine] = oldBMarks[i]; + state.tShift[i + startLine] = oldTShift[i]; + state.sCount[i + startLine] = oldSCount[i]; + state.bsCount[i + startLine] = oldBSCount[i]; + } + state.blkIndent = oldIndent; + return true; +} + +// Horizontal rule + +function hr(state, startLine, endLine, silent) { + const max = state.eMarks[startLine]; + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + let pos = state.bMarks[startLine] + state.tShift[startLine]; + const marker = state.src.charCodeAt(pos++); + + // Check hr marker + if (marker !== 0x2A /* * */ && marker !== 0x2D /* - */ && marker !== 0x5F /* _ */) { + return false; + } + + // markers can be mixed with spaces, but there should be at least 3 of them + + let cnt = 1; + while (pos < max) { + const ch = state.src.charCodeAt(pos++); + if (ch !== marker && !isSpace(ch)) { + return false; + } + if (ch === marker) { + cnt++; + } + } + if (cnt < 3) { + return false; + } + if (silent) { + return true; + } + state.line = startLine + 1; + const token = state.push('hr', 'hr', 0); + token.map = [startLine, state.line]; + token.markup = Array(cnt + 1).join(String.fromCharCode(marker)); + return true; +} + +// Lists + + +// Search `[-+*][\n ]`, returns next pos after marker on success +// or -1 on fail. +function skipBulletListMarker(state, startLine) { + const max = state.eMarks[startLine]; + let pos = state.bMarks[startLine] + state.tShift[startLine]; + const marker = state.src.charCodeAt(pos++); + // Check bullet + if (marker !== 0x2A /* * */ && marker !== 0x2D /* - */ && marker !== 0x2B /* + */) { + return -1; + } + if (pos < max) { + const ch = state.src.charCodeAt(pos); + if (!isSpace(ch)) { + // " -test " - is not a list item + return -1; + } + } + return pos; +} + +// Search `\d+[.)][\n ]`, returns next pos after marker on success +// or -1 on fail. +function skipOrderedListMarker(state, startLine) { + const start = state.bMarks[startLine] + state.tShift[startLine]; + const max = state.eMarks[startLine]; + let pos = start; + + // List marker should have at least 2 chars (digit + dot) + if (pos + 1 >= max) { + return -1; + } + let ch = state.src.charCodeAt(pos++); + if (ch < 0x30 /* 0 */ || ch > 0x39 /* 9 */) { + return -1; + } + for (;;) { + // EOL -> fail + if (pos >= max) { + return -1; + } + ch = state.src.charCodeAt(pos++); + if (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) { + // List marker should have no more than 9 digits + // (prevents integer overflow in browsers) + if (pos - start >= 10) { + return -1; + } + continue; + } + + // found valid marker + if (ch === 0x29 /* ) */ || ch === 0x2e /* . */) { + break; + } + return -1; + } + if (pos < max) { + ch = state.src.charCodeAt(pos); + if (!isSpace(ch)) { + // " 1.test " - is not a list item + return -1; + } + } + return pos; +} +function markTightParagraphs(state, idx) { + const level = state.level + 2; + for (let i = idx + 2, l = state.tokens.length - 2; i < l; i++) { + if (state.tokens[i].level === level && state.tokens[i].type === 'paragraph_open') { + state.tokens[i + 2].hidden = true; + state.tokens[i].hidden = true; + i += 2; + } + } +} +function list(state, startLine, endLine, silent) { + let max, pos, start, token; + let nextLine = startLine; + let tight = true; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + return false; + } + + // Special case: + // - item 1 + // - item 2 + // - item 3 + // - item 4 + // - this one is a paragraph continuation + if (state.listIndent >= 0 && state.sCount[nextLine] - state.listIndent >= 4 && state.sCount[nextLine] < state.blkIndent) { + return false; + } + let isTerminatingParagraph = false; + + // limit conditions when list can interrupt + // a paragraph (validation mode only) + if (silent && state.parentType === 'paragraph') { + // Next list item should still terminate previous list item; + // + // This code can fail if plugins use blkIndent as well as lists, + // but I hope the spec gets fixed long before that happens. + // + if (state.sCount[nextLine] >= state.blkIndent) { + isTerminatingParagraph = true; + } + } + + // Detect list type and position after marker + let isOrdered; + let markerValue; + let posAfterMarker; + if ((posAfterMarker = skipOrderedListMarker(state, nextLine)) >= 0) { + isOrdered = true; + start = state.bMarks[nextLine] + state.tShift[nextLine]; + markerValue = Number(state.src.slice(start, posAfterMarker - 1)); + + // If we're starting a new ordered list right after + // a paragraph, it should start with 1. + if (isTerminatingParagraph && markerValue !== 1) return false; + } else if ((posAfterMarker = skipBulletListMarker(state, nextLine)) >= 0) { + isOrdered = false; + } else { + return false; + } + + // If we're starting a new unordered list right after + // a paragraph, first line should not be empty. + if (isTerminatingParagraph) { + if (state.skipSpaces(posAfterMarker) >= state.eMarks[nextLine]) return false; + } + + // For validation mode we can terminate immediately + if (silent) { + return true; + } + + // We should terminate list on style change. Remember first one to compare. + const markerCharCode = state.src.charCodeAt(posAfterMarker - 1); + + // Start list + const listTokIdx = state.tokens.length; + if (isOrdered) { + token = state.push('ordered_list_open', 'ol', 1); + if (markerValue !== 1) { + token.attrs = [['start', markerValue]]; + } + } else { + token = state.push('bullet_list_open', 'ul', 1); + } + const listLines = [nextLine, 0]; + token.map = listLines; + token.markup = String.fromCharCode(markerCharCode); + + // + // Iterate list items + // + + let prevEmptyEnd = false; + const terminatorRules = state.md.block.ruler.getRules('list'); + const oldParentType = state.parentType; + state.parentType = 'list'; + while (nextLine < endLine) { + pos = posAfterMarker; + max = state.eMarks[nextLine]; + const initial = state.sCount[nextLine] + posAfterMarker - (state.bMarks[nextLine] + state.tShift[nextLine]); + let offset = initial; + while (pos < max) { + const ch = state.src.charCodeAt(pos); + if (ch === 0x09) { + offset += 4 - (offset + state.bsCount[nextLine]) % 4; + } else if (ch === 0x20) { + offset++; + } else { + break; + } + pos++; + } + const contentStart = pos; + let indentAfterMarker; + if (contentStart >= max) { + // trimming space in "- \n 3" case, indent is 1 here + indentAfterMarker = 1; + } else { + indentAfterMarker = offset - initial; + } + + // If we have more than 4 spaces, the indent is 1 + // (the rest is just indented code block) + if (indentAfterMarker > 4) { + indentAfterMarker = 1; + } + + // " - test" + // ^^^^^ - calculating total length of this thing + const indent = initial + indentAfterMarker; + + // Run subparser & write tokens + token = state.push('list_item_open', 'li', 1); + token.markup = String.fromCharCode(markerCharCode); + const itemLines = [nextLine, 0]; + token.map = itemLines; + if (isOrdered) { + token.info = state.src.slice(start, posAfterMarker - 1); + } + + // change current state, then restore it after parser subcall + const oldTight = state.tight; + const oldTShift = state.tShift[nextLine]; + const oldSCount = state.sCount[nextLine]; + + // - example list + // ^ listIndent position will be here + // ^ blkIndent position will be here + // + const oldListIndent = state.listIndent; + state.listIndent = state.blkIndent; + state.blkIndent = indent; + state.tight = true; + state.tShift[nextLine] = contentStart - state.bMarks[nextLine]; + state.sCount[nextLine] = offset; + if (contentStart >= max && state.isEmpty(nextLine + 1)) { + // workaround for this case + // (list item is empty, list terminates before "foo"): + // ~~~~~~~~ + // - + // + // foo + // ~~~~~~~~ + state.line = Math.min(state.line + 2, endLine); + } else { + state.md.block.tokenize(state, nextLine, endLine, true); + } + + // If any of list item is tight, mark list as tight + if (!state.tight || prevEmptyEnd) { + tight = false; + } + // Item become loose if finish with empty line, + // but we should filter last element, because it means list finish + prevEmptyEnd = state.line - nextLine > 1 && state.isEmpty(state.line - 1); + state.blkIndent = state.listIndent; + state.listIndent = oldListIndent; + state.tShift[nextLine] = oldTShift; + state.sCount[nextLine] = oldSCount; + state.tight = oldTight; + token = state.push('list_item_close', 'li', -1); + token.markup = String.fromCharCode(markerCharCode); + nextLine = state.line; + itemLines[1] = nextLine; + if (nextLine >= endLine) { + break; + } + + // + // Try to check if list is terminated or continued. + // + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[nextLine] - state.blkIndent >= 4) { + break; + } + + // fail if terminating block found + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + + // fail if list has another type + if (isOrdered) { + posAfterMarker = skipOrderedListMarker(state, nextLine); + if (posAfterMarker < 0) { + break; + } + start = state.bMarks[nextLine] + state.tShift[nextLine]; + } else { + posAfterMarker = skipBulletListMarker(state, nextLine); + if (posAfterMarker < 0) { + break; + } + } + if (markerCharCode !== state.src.charCodeAt(posAfterMarker - 1)) { + break; + } + } + + // Finalize list + if (isOrdered) { + token = state.push('ordered_list_close', 'ol', -1); + } else { + token = state.push('bullet_list_close', 'ul', -1); + } + token.markup = String.fromCharCode(markerCharCode); + listLines[1] = nextLine; + state.line = nextLine; + state.parentType = oldParentType; + + // mark paragraphs tight if needed + if (tight) { + markTightParagraphs(state, listTokIdx); + } + return true; +} + +function reference(state, startLine, _endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + let nextLine = startLine + 1; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (state.src.charCodeAt(pos) !== 0x5B /* [ */) { + return false; + } + function getNextLine(nextLine) { + const endLine = state.lineMax; + if (nextLine >= endLine || state.isEmpty(nextLine)) { + // empty line or end of input + return null; + } + let isContinuation = false; + + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + isContinuation = true; + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + isContinuation = true; + } + if (!isContinuation) { + const terminatorRules = state.md.block.ruler.getRules('reference'); + const oldParentType = state.parentType; + state.parentType = 'reference'; + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + state.parentType = oldParentType; + if (terminate) { + // terminated by another block + return null; + } + } + const pos = state.bMarks[nextLine] + state.tShift[nextLine]; + const max = state.eMarks[nextLine]; + + // max + 1 explicitly includes the newline + return state.src.slice(pos, max + 1); + } + let str = state.src.slice(pos, max + 1); + max = str.length; + let labelEnd = -1; + for (pos = 1; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x5B /* [ */) { + return false; + } else if (ch === 0x5D /* ] */) { + labelEnd = pos; + break; + } else if (ch === 0x0A /* \n */) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (ch === 0x5C /* \ */) { + pos++; + if (pos < max && str.charCodeAt(pos) === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } + } + } + if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 0x3A /* : */) { + return false; + } + + // [label]: destination 'title' + // ^^^ skip optional whitespace here + for (pos = labelEnd + 2; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (isSpace(ch)) ; else { + break; + } + } + + // [label]: destination 'title' + // ^^^^^^^^^^^ parse this + const destRes = state.md.helpers.parseLinkDestination(str, pos, max); + if (!destRes.ok) { + return false; + } + const href = state.md.normalizeLink(destRes.str); + if (!state.md.validateLink(href)) { + return false; + } + pos = destRes.pos; + + // save cursor state, we could require to rollback later + const destEndPos = pos; + const destEndLineNo = nextLine; + + // [label]: destination 'title' + // ^^^ skipping those spaces + const start = pos; + for (; pos < max; pos++) { + const ch = str.charCodeAt(pos); + if (ch === 0x0A) { + const lineContent = getNextLine(nextLine); + if (lineContent !== null) { + str += lineContent; + max = str.length; + nextLine++; + } + } else if (isSpace(ch)) ; else { + break; + } + } + + // [label]: destination 'title' + // ^^^^^^^ parse this + let titleRes = state.md.helpers.parseLinkTitle(str, pos, max); + while (titleRes.can_continue) { + const lineContent = getNextLine(nextLine); + if (lineContent === null) break; + str += lineContent; + pos = max; + max = str.length; + nextLine++; + titleRes = state.md.helpers.parseLinkTitle(str, pos, max, titleRes); + } + let title; + if (pos < max && start !== pos && titleRes.ok) { + title = titleRes.str; + pos = titleRes.pos; + } else { + title = ''; + pos = destEndPos; + nextLine = destEndLineNo; + } + + // skip trailing spaces until the rest of the line + while (pos < max) { + const ch = str.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + pos++; + } + if (pos < max && str.charCodeAt(pos) !== 0x0A) { + if (title) { + // garbage at the end of the line after title, + // but it could still be a valid reference if we roll back + title = ''; + pos = destEndPos; + nextLine = destEndLineNo; + while (pos < max) { + const ch = str.charCodeAt(pos); + if (!isSpace(ch)) { + break; + } + pos++; + } + } + } + if (pos < max && str.charCodeAt(pos) !== 0x0A) { + // garbage at the end of the line + return false; + } + const label = normalizeReference(str.slice(1, labelEnd)); + if (!label) { + // CommonMark 0.20 disallows empty labels + return false; + } + + // Reference can not terminate anything. This check is for safety only. + /* istanbul ignore if */ + if (silent) { + return true; + } + if (typeof state.env.references === 'undefined') { + state.env.references = {}; + } + if (typeof state.env.references[label] === 'undefined') { + state.env.references[label] = { + title, + href + }; + } + state.line = nextLine; + return true; +} + +// List of valid html blocks names, according to commonmark spec +// https://spec.commonmark.org/0.30/#html-blocks + +var block_names = ['address', 'article', 'aside', 'base', 'basefont', 'blockquote', 'body', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dialog', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'iframe', 'legend', 'li', 'link', 'main', 'menu', 'menuitem', 'nav', 'noframes', 'ol', 'optgroup', 'option', 'p', 'param', 'search', 'section', 'summary', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul']; + +// Regexps to match html elements + +const attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; +const unquoted = '[^"\'=<>`\\x00-\\x20]+'; +const single_quoted = "'[^']*'"; +const double_quoted = '"[^"]*"'; +const attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')'; +const attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)'; +const open_tag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>'; +const close_tag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>'; +const comment = ''; +const processing = '<[?][\\s\\S]*?[?]>'; +const declaration = ']*>'; +const cdata = ''; +const HTML_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + '|' + comment + '|' + processing + '|' + declaration + '|' + cdata + ')'); +const HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')'); + +// HTML block + + +// An array of opening and corresponding closing sequences for html tags, +// last argument defines whether it can terminate a paragraph or not +// +const HTML_SEQUENCES = [[/^<(script|pre|style|textarea)(?=(\s|>|$))/i, /<\/(script|pre|style|textarea)>/i, true], [/^/, true], [/^<\?/, /\?>/, true], [/^/, true], [/^/, true], [new RegExp('^|$))', 'i'), /^$/, true], [new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false]]; +function html_block(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + if (!state.md.options.html) { + return false; + } + if (state.src.charCodeAt(pos) !== 0x3C /* < */) { + return false; + } + let lineText = state.src.slice(pos, max); + let i = 0; + for (; i < HTML_SEQUENCES.length; i++) { + if (HTML_SEQUENCES[i][0].test(lineText)) { + break; + } + } + if (i === HTML_SEQUENCES.length) { + return false; + } + if (silent) { + // true if this sequence can be a terminator, false otherwise + return HTML_SEQUENCES[i][2]; + } + let nextLine = startLine + 1; + + // If we are here - we detected HTML block. + // Let's roll down till block end. + if (!HTML_SEQUENCES[i][1].test(lineText)) { + for (; nextLine < endLine; nextLine++) { + if (state.sCount[nextLine] < state.blkIndent) { + break; + } + pos = state.bMarks[nextLine] + state.tShift[nextLine]; + max = state.eMarks[nextLine]; + lineText = state.src.slice(pos, max); + if (HTML_SEQUENCES[i][1].test(lineText)) { + if (lineText.length !== 0) { + nextLine++; + } + break; + } + } + } + state.line = nextLine; + const token = state.push('html_block', '', 0); + token.map = [startLine, nextLine]; + token.content = state.getLines(startLine, nextLine, state.blkIndent, true); + return true; +} + +// heading (#, ##, ...) + +function heading(state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine]; + let max = state.eMarks[startLine]; + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + let ch = state.src.charCodeAt(pos); + if (ch !== 0x23 /* # */ || pos >= max) { + return false; + } + + // count heading level + let level = 1; + ch = state.src.charCodeAt(++pos); + while (ch === 0x23 /* # */ && pos < max && level <= 6) { + level++; + ch = state.src.charCodeAt(++pos); + } + if (level > 6 || pos < max && !isSpace(ch)) { + return false; + } + if (silent) { + return true; + } + + // Let's cut tails like ' ### ' from the end of string + + max = state.skipSpacesBack(max, pos); + const tmp = state.skipCharsBack(max, 0x23, pos); // # + if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) { + max = tmp; + } + state.line = startLine + 1; + const token_o = state.push('heading_open', 'h' + String(level), 1); + token_o.markup = '########'.slice(0, level); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = state.src.slice(pos, max).trim(); + token_i.map = [startLine, state.line]; + token_i.children = []; + const token_c = state.push('heading_close', 'h' + String(level), -1); + token_c.markup = '########'.slice(0, level); + return true; +} + +// lheading (---, ===) + +function lheading(state, startLine, endLine /*, silent */) { + const terminatorRules = state.md.block.ruler.getRules('paragraph'); + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { + return false; + } + const oldParentType = state.parentType; + state.parentType = 'paragraph'; // use paragraph to match terminatorRules + + // jump line-by-line until empty one or EOF + let level = 0; + let marker; + let nextLine = startLine + 1; + for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + continue; + } + + // + // Check for underline in setext header + // + if (state.sCount[nextLine] >= state.blkIndent) { + let pos = state.bMarks[nextLine] + state.tShift[nextLine]; + const max = state.eMarks[nextLine]; + if (pos < max) { + marker = state.src.charCodeAt(pos); + if (marker === 0x2D /* - */ || marker === 0x3D /* = */) { + pos = state.skipChars(pos, marker); + pos = state.skipSpaces(pos); + if (pos >= max) { + level = marker === 0x3D /* = */ ? 1 : 2; + break; + } + } + } + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + continue; + } + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + } + if (!level) { + // Didn't find valid underline + return false; + } + const content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); + state.line = nextLine + 1; + const token_o = state.push('heading_open', 'h' + String(level), 1); + token_o.markup = String.fromCharCode(marker); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = content; + token_i.map = [startLine, state.line - 1]; + token_i.children = []; + const token_c = state.push('heading_close', 'h' + String(level), -1); + token_c.markup = String.fromCharCode(marker); + state.parentType = oldParentType; + return true; +} + +// Paragraph + +function paragraph(state, startLine, endLine) { + const terminatorRules = state.md.block.ruler.getRules('paragraph'); + const oldParentType = state.parentType; + let nextLine = startLine + 1; + state.parentType = 'paragraph'; + + // jump line-by-line until empty one or EOF + for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { + // this would be a code block normally, but after paragraph + // it's considered a lazy continuation regardless of what's there + if (state.sCount[nextLine] - state.blkIndent > 3) { + continue; + } + + // quirk for blockquotes, this line should already be checked by that rule + if (state.sCount[nextLine] < 0) { + continue; + } + + // Some tags can terminate paragraph without empty line. + let terminate = false; + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true; + break; + } + } + if (terminate) { + break; + } + } + const content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); + state.line = nextLine; + const token_o = state.push('paragraph_open', 'p', 1); + token_o.map = [startLine, state.line]; + const token_i = state.push('inline', '', 0); + token_i.content = content; + token_i.map = [startLine, state.line]; + token_i.children = []; + state.push('paragraph_close', 'p', -1); + state.parentType = oldParentType; + return true; +} + +/** internal + * class ParserBlock + * + * Block-level tokenizer. + **/ + +const _rules$1 = [ +// First 2 params - rule name & source. Secondary array - list of rules, +// which can be terminated by this one. +['table', table, ['paragraph', 'reference']], ['code', code], ['fence', fence, ['paragraph', 'reference', 'blockquote', 'list']], ['blockquote', blockquote, ['paragraph', 'reference', 'blockquote', 'list']], ['hr', hr, ['paragraph', 'reference', 'blockquote', 'list']], ['list', list, ['paragraph', 'reference', 'blockquote']], ['reference', reference], ['html_block', html_block, ['paragraph', 'reference', 'blockquote']], ['heading', heading, ['paragraph', 'reference', 'blockquote']], ['lheading', lheading], ['paragraph', paragraph]]; + +/** + * new ParserBlock() + **/ +function ParserBlock() { + /** + * ParserBlock#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of block rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules$1.length; i++) { + this.ruler.push(_rules$1[i][0], _rules$1[i][1], { + alt: (_rules$1[i][2] || []).slice() + }); + } +} + +// Generate tokens for input range +// +ParserBlock.prototype.tokenize = function (state, startLine, endLine) { + const rules = this.ruler.getRules(''); + const len = rules.length; + const maxNesting = state.md.options.maxNesting; + let line = startLine; + let hasEmptyLines = false; + while (line < endLine) { + state.line = line = state.skipEmptyLines(line); + if (line >= endLine) { + break; + } + + // Termination condition for nested calls. + // Nested calls currently used for blockquotes & lists + if (state.sCount[line] < state.blkIndent) { + break; + } + + // If nesting level exceeded - skip tail to the end. That's not ordinary + // situation and we should not care about content. + if (state.level >= maxNesting) { + state.line = endLine; + break; + } + + // Try all possible rules. + // On success, rule should: + // + // - update `state.line` + // - update `state.tokens` + // - return true + const prevLine = state.line; + let ok = false; + for (let i = 0; i < len; i++) { + ok = rules[i](state, line, endLine, false); + if (ok) { + if (prevLine >= state.line) { + throw new Error("block rule didn't increment state.line"); + } + break; + } + } + + // this can only happen if user disables paragraph rule + if (!ok) throw new Error('none of the block rules matched'); + + // set state.tight if we had an empty line before current tag + // i.e. latest empty line should not count + state.tight = !hasEmptyLines; + + // paragraph might "eat" one newline after it in nested lists + if (state.isEmpty(state.line - 1)) { + hasEmptyLines = true; + } + line = state.line; + if (line < endLine && state.isEmpty(line)) { + hasEmptyLines = true; + line++; + state.line = line; + } + } +}; + +/** + * ParserBlock.parse(str, md, env, outTokens) + * + * Process input string and push block tokens into `outTokens` + **/ +ParserBlock.prototype.parse = function (src, md, env, outTokens) { + if (!src) { + return; + } + const state = new this.State(src, md, env, outTokens); + this.tokenize(state, state.line, state.lineMax); +}; +ParserBlock.prototype.State = StateBlock; + +// Inline parser state + +function StateInline(src, md, env, outTokens) { + this.src = src; + this.env = env; + this.md = md; + this.tokens = outTokens; + this.tokens_meta = Array(outTokens.length); + this.pos = 0; + this.posMax = this.src.length; + this.level = 0; + this.pending = ''; + this.pendingLevel = 0; + + // Stores { start: end } pairs. Useful for backtrack + // optimization of pairs parse (emphasis, strikes). + this.cache = {}; + + // List of emphasis-like delimiters for current tag + this.delimiters = []; + + // Stack of delimiter lists for upper level tags + this._prev_delimiters = []; + + // backtick length => last seen position + this.backticks = {}; + this.backticksScanned = false; + + // Counter used to disable inline linkify-it execution + // inside and markdown links + this.linkLevel = 0; +} + +// Flush pending text +// +StateInline.prototype.pushPending = function () { + const token = new Token('text', '', 0); + token.content = this.pending; + token.level = this.pendingLevel; + this.tokens.push(token); + this.pending = ''; + return token; +}; + +// Push new token to "stream". +// If pending text exists - flush it as text token +// +StateInline.prototype.push = function (type, tag, nesting) { + if (this.pending) { + this.pushPending(); + } + const token = new Token(type, tag, nesting); + let token_meta = null; + if (nesting < 0) { + // closing tag + this.level--; + this.delimiters = this._prev_delimiters.pop(); + } + token.level = this.level; + if (nesting > 0) { + // opening tag + this.level++; + this._prev_delimiters.push(this.delimiters); + this.delimiters = []; + token_meta = { + delimiters: this.delimiters + }; + } + this.pendingLevel = this.level; + this.tokens.push(token); + this.tokens_meta.push(token_meta); + return token; +}; + +// Scan a sequence of emphasis-like markers, and determine whether +// it can start an emphasis sequence or end an emphasis sequence. +// +// - start - position to scan from (it should point at a valid marker); +// - canSplitWord - determine if these markers can be found inside a word +// +StateInline.prototype.scanDelims = function (start, canSplitWord) { + const max = this.posMax; + const marker = this.src.charCodeAt(start); + + // treat beginning of the line as a whitespace + const lastChar = start > 0 ? this.src.charCodeAt(start - 1) : 0x20; + let pos = start; + while (pos < max && this.src.charCodeAt(pos) === marker) { + pos++; + } + const count = pos - start; + + // treat end of the line as a whitespace + const nextChar = pos < max ? this.src.charCodeAt(pos) : 0x20; + const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)); + const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)); + const isLastWhiteSpace = isWhiteSpace(lastChar); + const isNextWhiteSpace = isWhiteSpace(nextChar); + const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar); + const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar); + const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar); + const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar); + return { + can_open, + can_close, + length: count + }; +}; + +// re-export Token class to use in block rules +StateInline.prototype.Token = Token; + +// Skip text characters for text token, place those to pending buffer +// and increment current pos + +// Rule to skip pure text +// '{}$%@~+=:' reserved for extentions + +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ + +// !!!! Don't confuse with "Markdown ASCII Punctuation" chars +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +function isTerminatorChar(ch) { + switch (ch) { + case 0x0A /* \n */: + case 0x21 /* ! */: + case 0x23 /* # */: + case 0x24 /* $ */: + case 0x25 /* % */: + case 0x26 /* & */: + case 0x2A /* * */: + case 0x2B /* + */: + case 0x2D /* - */: + case 0x3A /* : */: + case 0x3C /* < */: + case 0x3D /* = */: + case 0x3E /* > */: + case 0x40 /* @ */: + case 0x5B /* [ */: + case 0x5C /* \ */: + case 0x5D /* ] */: + case 0x5E /* ^ */: + case 0x5F /* _ */: + case 0x60 /* ` */: + case 0x7B /* { */: + case 0x7D /* } */: + case 0x7E /* ~ */: + return true; + default: + return false; + } +} +function text(state, silent) { + let pos = state.pos; + while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) { + pos++; + } + if (pos === state.pos) { + return false; + } + if (!silent) { + state.pending += state.src.slice(state.pos, pos); + } + state.pos = pos; + return true; +} + +// Alternative implementation, for memory. +// +// It costs 10% of performance, but allows extend terminators list, if place it +// to `ParserInline` property. Probably, will switch to it sometime, such +// flexibility required. + +/* +var TERMINATOR_RE = /[\n!#$%&*+\-:<=>@[\\\]^_`{}~]/; + +module.exports = function text(state, silent) { + var pos = state.pos, + idx = state.src.slice(pos).search(TERMINATOR_RE); + + // first char is terminator -> empty text + if (idx === 0) { return false; } + + // no terminator -> text till end of string + if (idx < 0) { + if (!silent) { state.pending += state.src.slice(pos); } + state.pos = state.src.length; + return true; + } + + if (!silent) { state.pending += state.src.slice(pos, pos + idx); } + + state.pos += idx; + + return true; +}; */ + +// Process links like https://example.org/ + +// RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) +const SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i; +function linkify(state, silent) { + if (!state.md.options.linkify) return false; + if (state.linkLevel > 0) return false; + const pos = state.pos; + const max = state.posMax; + if (pos + 3 > max) return false; + if (state.src.charCodeAt(pos) !== 0x3A /* : */) return false; + if (state.src.charCodeAt(pos + 1) !== 0x2F /* / */) return false; + if (state.src.charCodeAt(pos + 2) !== 0x2F /* / */) return false; + const match = state.pending.match(SCHEME_RE); + if (!match) return false; + const proto = match[1]; + const link = state.md.linkify.matchAtStart(state.src.slice(pos - proto.length)); + if (!link) return false; + let url = link.url; + + // invalid link, but still detected by linkify somehow; + // need to check to prevent infinite loop below + if (url.length <= proto.length) return false; + + // disallow '*' at the end of the link (conflicts with emphasis) + url = url.replace(/\*+$/, ''); + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) return false; + if (!silent) { + state.pending = state.pending.slice(0, -proto.length); + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'linkify'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'linkify'; + token_c.info = 'auto'; + } + state.pos += url.length - proto.length; + return true; +} + +// Proceess '\n' + +function newline(state, silent) { + let pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x0A /* \n */) { + return false; + } + const pmax = state.pending.length - 1; + const max = state.posMax; + + // ' \n' -> hardbreak + // Lookup in pending chars is bad practice! Don't copy to other rules! + // Pending string is stored in concat mode, indexed lookups will cause + // convertion to flat mode. + if (!silent) { + if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) { + if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) { + // Find whitespaces tail of pending chars. + let ws = pmax - 1; + while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 0x20) ws--; + state.pending = state.pending.slice(0, ws); + state.push('hardbreak', 'br', 0); + } else { + state.pending = state.pending.slice(0, -1); + state.push('softbreak', 'br', 0); + } + } else { + state.push('softbreak', 'br', 0); + } + } + pos++; + + // skip heading spaces for next line + while (pos < max && isSpace(state.src.charCodeAt(pos))) { + pos++; + } + state.pos = pos; + return true; +} + +// Process escaped chars and hardbreaks + +const ESCAPED = []; +for (let i = 0; i < 256; i++) { + ESCAPED.push(0); +} +'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-'.split('').forEach(function (ch) { + ESCAPED[ch.charCodeAt(0)] = 1; +}); +function escape(state, silent) { + let pos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(pos) !== 0x5C /* \ */) return false; + pos++; + + // '\' at the end of the inline block + if (pos >= max) return false; + let ch1 = state.src.charCodeAt(pos); + if (ch1 === 0x0A) { + if (!silent) { + state.push('hardbreak', 'br', 0); + } + pos++; + // skip leading whitespaces from next line + while (pos < max) { + ch1 = state.src.charCodeAt(pos); + if (!isSpace(ch1)) break; + pos++; + } + state.pos = pos; + return true; + } + let escapedStr = state.src[pos]; + if (ch1 >= 0xD800 && ch1 <= 0xDBFF && pos + 1 < max) { + const ch2 = state.src.charCodeAt(pos + 1); + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + escapedStr += state.src[pos + 1]; + pos++; + } + } + const origStr = '\\' + escapedStr; + if (!silent) { + const token = state.push('text_special', '', 0); + if (ch1 < 256 && ESCAPED[ch1] !== 0) { + token.content = escapedStr; + } else { + token.content = origStr; + } + token.markup = origStr; + token.info = 'escape'; + } + state.pos = pos + 1; + return true; +} + +// Parse backticks + +function backtick(state, silent) { + let pos = state.pos; + const ch = state.src.charCodeAt(pos); + if (ch !== 0x60 /* ` */) { + return false; + } + const start = pos; + pos++; + const max = state.posMax; + + // scan marker length + while (pos < max && state.src.charCodeAt(pos) === 0x60 /* ` */) { + pos++; + } + const marker = state.src.slice(start, pos); + const openerLength = marker.length; + if (state.backticksScanned && (state.backticks[openerLength] || 0) <= start) { + if (!silent) state.pending += marker; + state.pos += openerLength; + return true; + } + let matchEnd = pos; + let matchStart; + + // Nothing found in the cache, scan until the end of the line (or until marker is found) + while ((matchStart = state.src.indexOf('`', matchEnd)) !== -1) { + matchEnd = matchStart + 1; + + // scan marker length + while (matchEnd < max && state.src.charCodeAt(matchEnd) === 0x60 /* ` */) { + matchEnd++; + } + const closerLength = matchEnd - matchStart; + if (closerLength === openerLength) { + // Found matching closer length. + if (!silent) { + const token = state.push('code_inline', 'code', 0); + token.markup = marker; + token.content = state.src.slice(pos, matchStart).replace(/\n/g, ' ').replace(/^ (.+) $/, '$1'); + } + state.pos = matchEnd; + return true; + } + + // Some different length found, put it in cache as upper limit of where closer can be found + state.backticks[closerLength] = matchStart; + } + + // Scanned through the end, didn't find anything + state.backticksScanned = true; + if (!silent) state.pending += marker; + state.pos += openerLength; + return true; +} + +// ~~strike through~~ +// + +// Insert each marker as a separate text token, and add it to delimiter list +// +function strikethrough_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent) { + return false; + } + if (marker !== 0x7E /* ~ */) { + return false; + } + const scanned = state.scanDelims(state.pos, true); + let len = scanned.length; + const ch = String.fromCharCode(marker); + if (len < 2) { + return false; + } + let token; + if (len % 2) { + token = state.push('text', '', 0); + token.content = ch; + len--; + } + for (let i = 0; i < len; i += 2) { + token = state.push('text', '', 0); + token.content = ch + ch; + state.delimiters.push({ + marker, + length: 0, + // disable "rule of 3" length checks meant for emphasis + token: state.tokens.length - 1, + end: -1, + open: scanned.can_open, + close: scanned.can_close + }); + } + state.pos += scanned.length; + return true; +} +function postProcess$1(state, delimiters) { + let token; + const loneMarkers = []; + const max = delimiters.length; + for (let i = 0; i < max; i++) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x7E /* ~ */) { + continue; + } + if (startDelim.end === -1) { + continue; + } + const endDelim = delimiters[startDelim.end]; + token = state.tokens[startDelim.token]; + token.type = 's_open'; + token.tag = 's'; + token.nesting = 1; + token.markup = '~~'; + token.content = ''; + token = state.tokens[endDelim.token]; + token.type = 's_close'; + token.tag = 's'; + token.nesting = -1; + token.markup = '~~'; + token.content = ''; + if (state.tokens[endDelim.token - 1].type === 'text' && state.tokens[endDelim.token - 1].content === '~') { + loneMarkers.push(endDelim.token - 1); + } + } + + // If a marker sequence has an odd number of characters, it's splitted + // like this: `~~~~~` -> `~` + `~~` + `~~`, leaving one marker at the + // start of the sequence. + // + // So, we have to move all those markers after subsequent s_close tags. + // + while (loneMarkers.length) { + const i = loneMarkers.pop(); + let j = i + 1; + while (j < state.tokens.length && state.tokens[j].type === 's_close') { + j++; + } + j--; + if (i !== j) { + token = state.tokens[j]; + state.tokens[j] = state.tokens[i]; + state.tokens[i] = token; + } + } +} + +// Walk through delimiter list and replace text tokens with tags +// +function strikethrough_postProcess(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess$1(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + postProcess$1(state, tokens_meta[curr].delimiters); + } + } +} +var r_strikethrough = { + tokenize: strikethrough_tokenize, + postProcess: strikethrough_postProcess +}; + +// Process *this* and _that_ +// + +// Insert each marker as a separate text token, and add it to delimiter list +// +function emphasis_tokenize(state, silent) { + const start = state.pos; + const marker = state.src.charCodeAt(start); + if (silent) { + return false; + } + if (marker !== 0x5F /* _ */ && marker !== 0x2A /* * */) { + return false; + } + const scanned = state.scanDelims(state.pos, marker === 0x2A); + for (let i = 0; i < scanned.length; i++) { + const token = state.push('text', '', 0); + token.content = String.fromCharCode(marker); + state.delimiters.push({ + // Char code of the starting marker (number). + // + marker, + // Total length of these series of delimiters. + // + length: scanned.length, + // A position of the token this delimiter corresponds to. + // + token: state.tokens.length - 1, + // If this delimiter is matched as a valid opener, `end` will be + // equal to its position, otherwise it's `-1`. + // + end: -1, + // Boolean flags that determine if this delimiter could open or close + // an emphasis. + // + open: scanned.can_open, + close: scanned.can_close + }); + } + state.pos += scanned.length; + return true; +} +function postProcess(state, delimiters) { + const max = delimiters.length; + for (let i = max - 1; i >= 0; i--) { + const startDelim = delimiters[i]; + if (startDelim.marker !== 0x5F /* _ */ && startDelim.marker !== 0x2A /* * */) { + continue; + } + + // Process only opening markers + if (startDelim.end === -1) { + continue; + } + const endDelim = delimiters[startDelim.end]; + + // If the previous delimiter has the same marker and is adjacent to this one, + // merge those into one strong delimiter. + // + // `whatever` -> `whatever` + // + const isStrong = i > 0 && delimiters[i - 1].end === startDelim.end + 1 && + // check that first two markers match and adjacent + delimiters[i - 1].marker === startDelim.marker && delimiters[i - 1].token === startDelim.token - 1 && + // check that last two markers are adjacent (we can safely assume they match) + delimiters[startDelim.end + 1].token === endDelim.token + 1; + const ch = String.fromCharCode(startDelim.marker); + const token_o = state.tokens[startDelim.token]; + token_o.type = isStrong ? 'strong_open' : 'em_open'; + token_o.tag = isStrong ? 'strong' : 'em'; + token_o.nesting = 1; + token_o.markup = isStrong ? ch + ch : ch; + token_o.content = ''; + const token_c = state.tokens[endDelim.token]; + token_c.type = isStrong ? 'strong_close' : 'em_close'; + token_c.tag = isStrong ? 'strong' : 'em'; + token_c.nesting = -1; + token_c.markup = isStrong ? ch + ch : ch; + token_c.content = ''; + if (isStrong) { + state.tokens[delimiters[i - 1].token].content = ''; + state.tokens[delimiters[startDelim.end + 1].token].content = ''; + i--; + } + } +} + +// Walk through delimiter list and replace text tokens with tags +// +function emphasis_post_process(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + postProcess(state, state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + postProcess(state, tokens_meta[curr].delimiters); + } + } +} +var r_emphasis = { + tokenize: emphasis_tokenize, + postProcess: emphasis_post_process +}; + +// Process [link]( "stuff") + +function link(state, silent) { + let code, label, res, ref; + let href = ''; + let title = ''; + let start = state.pos; + let parseReference = true; + if (state.src.charCodeAt(state.pos) !== 0x5B /* [ */) { + return false; + } + const oldPos = state.pos; + const max = state.posMax; + const labelStart = state.pos + 1; + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true); + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { + return false; + } + let pos = labelEnd + 1; + if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) { + // + // Inline link + // + + // might have found a valid shortcut link, disable reference parsing + parseReference = false; + + // [link]( "title" ) + // ^^ skipping these spaces + pos++; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + if (pos >= max) { + return false; + } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos; + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax); + if (res.ok) { + href = state.md.normalizeLink(res.str); + if (state.md.validateLink(href)) { + pos = res.pos; + } else { + href = ''; + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); + if (pos < max && start !== pos && res.ok) { + title = res.str; + pos = res.pos; + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + } + } + if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) { + // parsing a valid shortcut link failed, fallback to reference + parseReference = true; + } + pos++; + } + if (parseReference) { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { + return false; + } + if (pos < max && state.src.charCodeAt(pos) === 0x5B /* [ */) { + start = pos + 1; + pos = state.md.helpers.parseLinkLabel(state, pos); + if (pos >= 0) { + label = state.src.slice(start, pos++); + } else { + pos = labelEnd + 1; + } + } else { + pos = labelEnd + 1; + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { + label = state.src.slice(labelStart, labelEnd); + } + ref = state.env.references[normalizeReference(label)]; + if (!ref) { + state.pos = oldPos; + return false; + } + href = ref.href; + title = ref.title; + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + state.pos = labelStart; + state.posMax = labelEnd; + const token_o = state.push('link_open', 'a', 1); + const attrs = [['href', href]]; + token_o.attrs = attrs; + if (title) { + attrs.push(['title', title]); + } + state.linkLevel++; + state.md.inline.tokenize(state); + state.linkLevel--; + state.push('link_close', 'a', -1); + } + state.pos = pos; + state.posMax = max; + return true; +} + +// Process ![image]( "title") + +function image(state, silent) { + let code, content, label, pos, ref, res, title, start; + let href = ''; + const oldPos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(state.pos) !== 0x21 /* ! */) { + return false; + } + if (state.src.charCodeAt(state.pos + 1) !== 0x5B /* [ */) { + return false; + } + const labelStart = state.pos + 2; + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false); + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { + return false; + } + pos = labelEnd + 1; + if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) { + // + // Inline link + // + + // [link]( "title" ) + // ^^ skipping these spaces + pos++; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + if (pos >= max) { + return false; + } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos; + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax); + if (res.ok) { + href = state.md.normalizeLink(res.str); + if (state.md.validateLink(href)) { + pos = res.pos; + } else { + href = ''; + } + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos; + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); + if (pos < max && start !== pos && res.ok) { + title = res.str; + pos = res.pos; + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos); + if (!isSpace(code) && code !== 0x0A) { + break; + } + } + } else { + title = ''; + } + if (pos >= max || state.src.charCodeAt(pos) !== 0x29 /* ) */) { + state.pos = oldPos; + return false; + } + pos++; + } else { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { + return false; + } + if (pos < max && state.src.charCodeAt(pos) === 0x5B /* [ */) { + start = pos + 1; + pos = state.md.helpers.parseLinkLabel(state, pos); + if (pos >= 0) { + label = state.src.slice(start, pos++); + } else { + pos = labelEnd + 1; + } + } else { + pos = labelEnd + 1; + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { + label = state.src.slice(labelStart, labelEnd); + } + ref = state.env.references[normalizeReference(label)]; + if (!ref) { + state.pos = oldPos; + return false; + } + href = ref.href; + title = ref.title; + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + content = state.src.slice(labelStart, labelEnd); + const tokens = []; + state.md.inline.parse(content, state.md, state.env, tokens); + const token = state.push('image', 'img', 0); + const attrs = [['src', href], ['alt', '']]; + token.attrs = attrs; + token.children = tokens; + token.content = content; + if (title) { + attrs.push(['title', title]); + } + } + state.pos = pos; + state.posMax = max; + return true; +} + +// Process autolinks '' + +/* eslint max-len:0 */ +const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/; +/* eslint-disable-next-line no-control-regex */ +const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/; +function autolink(state, silent) { + let pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x3C /* < */) { + return false; + } + const start = state.pos; + const max = state.posMax; + for (;;) { + if (++pos >= max) return false; + const ch = state.src.charCodeAt(pos); + if (ch === 0x3C /* < */) return false; + if (ch === 0x3E /* > */) break; + } + const url = state.src.slice(start + 1, pos); + if (AUTOLINK_RE.test(url)) { + const fullUrl = state.md.normalizeLink(url); + if (!state.md.validateLink(fullUrl)) { + return false; + } + if (!silent) { + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'autolink'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'autolink'; + token_c.info = 'auto'; + } + state.pos += url.length + 2; + return true; + } + if (EMAIL_RE.test(url)) { + const fullUrl = state.md.normalizeLink('mailto:' + url); + if (!state.md.validateLink(fullUrl)) { + return false; + } + if (!silent) { + const token_o = state.push('link_open', 'a', 1); + token_o.attrs = [['href', fullUrl]]; + token_o.markup = 'autolink'; + token_o.info = 'auto'; + const token_t = state.push('text', '', 0); + token_t.content = state.md.normalizeLinkText(url); + const token_c = state.push('link_close', 'a', -1); + token_c.markup = 'autolink'; + token_c.info = 'auto'; + } + state.pos += url.length + 2; + return true; + } + return false; +} + +// Process html tags + +function isLinkOpen(str) { + return /^\s]/i.test(str); +} +function isLinkClose(str) { + return /^<\/a\s*>/i.test(str); +} +function isLetter(ch) { + /* eslint no-bitwise:0 */ + const lc = ch | 0x20; // to lower case + return lc >= 0x61 /* a */ && lc <= 0x7a /* z */; +} +function html_inline(state, silent) { + if (!state.md.options.html) { + return false; + } + + // Check start + const max = state.posMax; + const pos = state.pos; + if (state.src.charCodeAt(pos) !== 0x3C /* < */ || pos + 2 >= max) { + return false; + } + + // Quick fail on second char + const ch = state.src.charCodeAt(pos + 1); + if (ch !== 0x21 /* ! */ && ch !== 0x3F /* ? */ && ch !== 0x2F /* / */ && !isLetter(ch)) { + return false; + } + const match = state.src.slice(pos).match(HTML_TAG_RE); + if (!match) { + return false; + } + if (!silent) { + const token = state.push('html_inline', '', 0); + token.content = match[0]; + if (isLinkOpen(token.content)) state.linkLevel++; + if (isLinkClose(token.content)) state.linkLevel--; + } + state.pos += match[0].length; + return true; +} + +// Process html entity - {, ¯, ", ... + +const DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i; +const NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i; +function entity(state, silent) { + const pos = state.pos; + const max = state.posMax; + if (state.src.charCodeAt(pos) !== 0x26 /* & */) return false; + if (pos + 1 >= max) return false; + const ch = state.src.charCodeAt(pos + 1); + if (ch === 0x23 /* # */) { + const match = state.src.slice(pos).match(DIGITAL_RE); + if (match) { + if (!silent) { + const code = match[1][0].toLowerCase() === 'x' ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10); + const token = state.push('text_special', '', 0); + token.content = isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD); + token.markup = match[0]; + token.info = 'entity'; + } + state.pos += match[0].length; + return true; + } + } else { + const match = state.src.slice(pos).match(NAMED_RE); + if (match) { + const decoded = entities.decodeHTML(match[0]); + if (decoded !== match[0]) { + if (!silent) { + const token = state.push('text_special', '', 0); + token.content = decoded; + token.markup = match[0]; + token.info = 'entity'; + } + state.pos += match[0].length; + return true; + } + } + } + return false; +} + +// For each opening emphasis-like marker find a matching closing one +// + +function processDelimiters(delimiters) { + const openersBottom = {}; + const max = delimiters.length; + if (!max) return; + + // headerIdx is the first delimiter of the current (where closer is) delimiter run + let headerIdx = 0; + let lastTokenIdx = -2; // needs any value lower than -1 + const jumps = []; + for (let closerIdx = 0; closerIdx < max; closerIdx++) { + const closer = delimiters[closerIdx]; + jumps.push(0); + + // markers belong to same delimiter run if: + // - they have adjacent tokens + // - AND markers are the same + // + if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) { + headerIdx = closerIdx; + } + lastTokenIdx = closer.token; + + // Length is only used for emphasis-specific "rule of 3", + // if it's not defined (in strikethrough or 3rd party plugins), + // we can default it to 0 to disable those checks. + // + closer.length = closer.length || 0; + if (!closer.close) continue; + + // Previously calculated lower bounds (previous fails) + // for each marker, each delimiter length modulo 3, + // and for whether this closer can be an opener; + // https://github.com/commonmark/cmark/commit/34250e12ccebdc6372b8b49c44fab57c72443460 + /* eslint-disable-next-line no-prototype-builtins */ + if (!openersBottom.hasOwnProperty(closer.marker)) { + openersBottom[closer.marker] = [-1, -1, -1, -1, -1, -1]; + } + const minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + closer.length % 3]; + let openerIdx = headerIdx - jumps[headerIdx] - 1; + let newMinOpenerIdx = openerIdx; + for (; openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) { + const opener = delimiters[openerIdx]; + if (opener.marker !== closer.marker) continue; + if (opener.open && opener.end < 0) { + let isOddMatch = false; + + // from spec: + // + // If one of the delimiters can both open and close emphasis, then the + // sum of the lengths of the delimiter runs containing the opening and + // closing delimiters must not be a multiple of 3 unless both lengths + // are multiples of 3. + // + if (opener.close || closer.open) { + if ((opener.length + closer.length) % 3 === 0) { + if (opener.length % 3 !== 0 || closer.length % 3 !== 0) { + isOddMatch = true; + } + } + } + if (!isOddMatch) { + // If previous delimiter cannot be an opener, we can safely skip + // the entire sequence in future checks. This is required to make + // sure algorithm has linear complexity (see *_*_*_*_*_... case). + // + const lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? jumps[openerIdx - 1] + 1 : 0; + jumps[closerIdx] = closerIdx - openerIdx + lastJump; + jumps[openerIdx] = lastJump; + closer.open = false; + opener.end = closerIdx; + opener.close = false; + newMinOpenerIdx = -1; + // treat next token as start of run, + // it optimizes skips in **<...>**a**<...>** pathological case + lastTokenIdx = -2; + break; + } + } + } + if (newMinOpenerIdx !== -1) { + // If match for this delimiter run failed, we want to set lower bound for + // future lookups. This is required to make sure algorithm has linear + // complexity. + // + // See details here: + // https://github.com/commonmark/cmark/issues/178#issuecomment-270417442 + // + openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length || 0) % 3] = newMinOpenerIdx; + } + } +} +function link_pairs(state) { + const tokens_meta = state.tokens_meta; + const max = state.tokens_meta.length; + processDelimiters(state.delimiters); + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + processDelimiters(tokens_meta[curr].delimiters); + } + } +} + +// Clean up tokens after emphasis and strikethrough postprocessing: +// merge adjacent text nodes into one and re-calculate all token levels +// +// This is necessary because initially emphasis delimiter markers (*, _, ~) +// are treated as their own separate text tokens. Then emphasis rule either +// leaves them as text (needed to merge with adjacent text) or turns them +// into opening/closing tags (which messes up levels inside). +// + +function fragments_join(state) { + let curr, last; + let level = 0; + const tokens = state.tokens; + const max = state.tokens.length; + for (curr = last = 0; curr < max; curr++) { + // re-calculate levels after emphasis/strikethrough turns some text nodes + // into opening/closing tags + if (tokens[curr].nesting < 0) level--; // closing tag + tokens[curr].level = level; + if (tokens[curr].nesting > 0) level++; // opening tag + + if (tokens[curr].type === 'text' && curr + 1 < max && tokens[curr + 1].type === 'text') { + // collapse two adjacent text nodes + tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content; + } else { + if (curr !== last) { + tokens[last] = tokens[curr]; + } + last++; + } + } + if (curr !== last) { + tokens.length = last; + } +} + +/** internal + * class ParserInline + * + * Tokenizes paragraph content. + **/ + + +// Parser rules + +const _rules = [['text', text], ['linkify', linkify], ['newline', newline], ['escape', escape], ['backticks', backtick], ['strikethrough', r_strikethrough.tokenize], ['emphasis', r_emphasis.tokenize], ['link', link], ['image', image], ['autolink', autolink], ['html_inline', html_inline], ['entity', entity]]; + +// `rule2` ruleset was created specifically for emphasis/strikethrough +// post-processing and may be changed in the future. +// +// Don't use this for anything except pairs (plugins working with `balance_pairs`). +// +const _rules2 = [['balance_pairs', link_pairs], ['strikethrough', r_strikethrough.postProcess], ['emphasis', r_emphasis.postProcess], +// rules for pairs separate '**' into its own text tokens, which may be left unused, +// rule below merges unused segments back with the rest of the text +['fragments_join', fragments_join]]; + +/** + * new ParserInline() + **/ +function ParserInline() { + /** + * ParserInline#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of inline rules. + **/ + this.ruler = new Ruler(); + for (let i = 0; i < _rules.length; i++) { + this.ruler.push(_rules[i][0], _rules[i][1]); + } + + /** + * ParserInline#ruler2 -> Ruler + * + * [[Ruler]] instance. Second ruler used for post-processing + * (e.g. in emphasis-like rules). + **/ + this.ruler2 = new Ruler(); + for (let i = 0; i < _rules2.length; i++) { + this.ruler2.push(_rules2[i][0], _rules2[i][1]); + } +} + +// Skip single token by running all rules in validation mode; +// returns `true` if any rule reported success +// +ParserInline.prototype.skipToken = function (state) { + const pos = state.pos; + const rules = this.ruler.getRules(''); + const len = rules.length; + const maxNesting = state.md.options.maxNesting; + const cache = state.cache; + if (typeof cache[pos] !== 'undefined') { + state.pos = cache[pos]; + return; + } + let ok = false; + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + // Increment state.level and decrement it later to limit recursion. + // It's harmless to do here, because no tokens are created. But ideally, + // we'd need a separate private state variable for this purpose. + // + state.level++; + ok = rules[i](state, true); + state.level--; + if (ok) { + if (pos >= state.pos) { + throw new Error("inline rule didn't increment state.pos"); + } + break; + } + } + } else { + // Too much nesting, just skip until the end of the paragraph. + // + // NOTE: this will cause links to behave incorrectly in the following case, + // when an amount of `[` is exactly equal to `maxNesting + 1`: + // + // [[[[[[[[[[[[[[[[[[[[[foo]() + // + // TODO: remove this workaround when CM standard will allow nested links + // (we can replace it by preventing links from being parsed in + // validation mode) + // + state.pos = state.posMax; + } + if (!ok) { + state.pos++; + } + cache[pos] = state.pos; +}; + +// Generate tokens for input range +// +ParserInline.prototype.tokenize = function (state) { + const rules = this.ruler.getRules(''); + const len = rules.length; + const end = state.posMax; + const maxNesting = state.md.options.maxNesting; + while (state.pos < end) { + // Try all possible rules. + // On success, rule should: + // + // - update `state.pos` + // - update `state.tokens` + // - return true + const prevPos = state.pos; + let ok = false; + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + ok = rules[i](state, false); + if (ok) { + if (prevPos >= state.pos) { + throw new Error("inline rule didn't increment state.pos"); + } + break; + } + } + } + if (ok) { + if (state.pos >= end) { + break; + } + continue; + } + state.pending += state.src[state.pos++]; + } + if (state.pending) { + state.pushPending(); + } +}; + +/** + * ParserInline.parse(str, md, env, outTokens) + * + * Process input string and push inline tokens into `outTokens` + **/ +ParserInline.prototype.parse = function (str, md, env, outTokens) { + const state = new this.State(str, md, env, outTokens); + this.tokenize(state); + const rules = this.ruler2.getRules(''); + const len = rules.length; + for (let i = 0; i < len; i++) { + rules[i](state); + } +}; +ParserInline.prototype.State = StateInline; + +// markdown-it default options + +var cfg_default = { + options: { + // Enable HTML tags in source + html: false, + // Use '/' to close single tags (
) + xhtmlOut: false, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: false, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: true, + // Convert '\n' in paragraphs into
+ breaks: false, + // CSS language prefix for fenced blocks + langPrefix: 'language-', + // autoconvert URL-like texts to links + linkify: false, + // Enable some language-neutral replacements + quotes beautification + typographer: false, + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', + /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with = 0) { + try { + parsed.hostname = punycode.toASCII(parsed.hostname); + } catch (er) {/**/} + } + } + return mdurl__namespace.encode(mdurl__namespace.format(parsed)); +} +function normalizeLinkText(url) { + const parsed = mdurl__namespace.parse(url, true); + if (parsed.hostname) { + // Encode hostnames in urls like: + // `http://host/`, `https://host/`, `mailto:user@host`, `//host/` + // + // We don't encode unknown schemas, because it's likely that we encode + // something we shouldn't (e.g. `skype:name` treated as `skype:host`) + // + if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) { + try { + parsed.hostname = punycode.toUnicode(parsed.hostname); + } catch (er) {/**/} + } + } + + // add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720 + return mdurl__namespace.decode(mdurl__namespace.format(parsed), mdurl__namespace.decode.defaultChars + '%'); +} + +/** + * class MarkdownIt + * + * Main parser/renderer class. + * + * ##### Usage + * + * ```javascript + * // node.js, "classic" way: + * var MarkdownIt = require('markdown-it'), + * md = new MarkdownIt(); + * var result = md.render('# markdown-it rulezz!'); + * + * // node.js, the same, but with sugar: + * var md = require('markdown-it')(); + * var result = md.render('# markdown-it rulezz!'); + * + * // browser without AMD, added to "window" on script load + * // Note, there are no dash. + * var md = window.markdownit(); + * var result = md.render('# markdown-it rulezz!'); + * ``` + * + * Single line rendering, without paragraph wrap: + * + * ```javascript + * var md = require('markdown-it')(); + * var result = md.renderInline('__markdown-it__ rulezz!'); + * ``` + **/ + +/** + * new MarkdownIt([presetName, options]) + * - presetName (String): optional, `commonmark` / `zero` + * - options (Object) + * + * Creates parser instanse with given config. Can be called without `new`. + * + * ##### presetName + * + * MarkdownIt provides named presets as a convenience to quickly + * enable/disable active syntax rules and options for common use cases. + * + * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.mjs) - + * configures parser to strict [CommonMark](http://commonmark.org/) mode. + * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.mjs) - + * similar to GFM, used when no preset name given. Enables all available rules, + * but still without html, typographer & autolinker. + * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.mjs) - + * all rules disabled. Useful to quickly setup your config via `.enable()`. + * For example, when you need only `bold` and `italic` markup and nothing else. + * + * ##### options: + * + * - __html__ - `false`. Set `true` to enable HTML tags in source. Be careful! + * That's not safe! You may need external sanitizer to protect output from XSS. + * It's better to extend features via plugins, instead of enabling HTML. + * - __xhtmlOut__ - `false`. Set `true` to add '/' when closing single tags + * (`
`). This is needed only for full CommonMark compatibility. In real + * world you will need HTML output. + * - __breaks__ - `false`. Set `true` to convert `\n` in paragraphs into `
`. + * - __langPrefix__ - `language-`. CSS language class prefix for fenced blocks. + * Can be useful for external highlighters. + * - __linkify__ - `false`. Set `true` to autoconvert URL-like text to links. + * - __typographer__ - `false`. Set `true` to enable [some language-neutral + * replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs) + + * quotes beautification (smartquotes). + * - __quotes__ - `“”‘’`, String or Array. Double + single quotes replacement + * pairs, when typographer enabled and smartquotes on. For example, you can + * use `'«»„“'` for Russian, `'„“‚‘'` for German, and + * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp). + * - __highlight__ - `null`. Highlighter function for fenced code blocks. + * Highlighter `function (str, lang)` should return escaped HTML. It can also + * return empty string if the source was not changed and should be escaped + * externaly. If result starts with ` or ``): + * + * ```javascript + * var hljs = require('highlight.js') // https://highlightjs.org/ + * + * // Actual default values + * var md = require('markdown-it')({ + * highlight: function (str, lang) { + * if (lang && hljs.getLanguage(lang)) { + * try { + * return '
' +
+ *                hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+ *                '
'; + * } catch (__) {} + * } + * + * return '
' + md.utils.escapeHtml(str) + '
'; + * } + * }); + * ``` + * + **/ +function MarkdownIt(presetName, options) { + if (!(this instanceof MarkdownIt)) { + return new MarkdownIt(presetName, options); + } + if (!options) { + if (!isString(presetName)) { + options = presetName || {}; + presetName = 'default'; + } + } + + /** + * MarkdownIt#inline -> ParserInline + * + * Instance of [[ParserInline]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.inline = new ParserInline(); + + /** + * MarkdownIt#block -> ParserBlock + * + * Instance of [[ParserBlock]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.block = new ParserBlock(); + + /** + * MarkdownIt#core -> Core + * + * Instance of [[Core]] chain executor. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.core = new Core(); + + /** + * MarkdownIt#renderer -> Renderer + * + * Instance of [[Renderer]]. Use it to modify output look. Or to add rendering + * rules for new token types, generated by plugins. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * function myToken(tokens, idx, options, env, self) { + * //... + * return result; + * }; + * + * md.renderer.rules['my_token'] = myToken + * ``` + * + * See [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs). + **/ + this.renderer = new Renderer(); + + /** + * MarkdownIt#linkify -> LinkifyIt + * + * [linkify-it](https://github.com/markdown-it/linkify-it) instance. + * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.mjs) + * rule. + **/ + this.linkify = new LinkifyIt(); + + /** + * MarkdownIt#validateLink(url) -> Boolean + * + * Link validation function. CommonMark allows too much in links. By default + * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas + * except some embedded image types. + * + * You can change this behaviour: + * + * ```javascript + * var md = require('markdown-it')(); + * // enable everything + * md.validateLink = function () { return true; } + * ``` + **/ + this.validateLink = validateLink; + + /** + * MarkdownIt#normalizeLink(url) -> String + * + * Function used to encode link url to a machine-readable format, + * which includes url-encoding, punycode, etc. + **/ + this.normalizeLink = normalizeLink; + + /** + * MarkdownIt#normalizeLinkText(url) -> String + * + * Function used to decode link url to a human-readable format` + **/ + this.normalizeLinkText = normalizeLinkText; + + // Expose utils & helpers for easy acces from plugins + + /** + * MarkdownIt#utils -> utils + * + * Assorted utility functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs). + **/ + this.utils = utils; + + /** + * MarkdownIt#helpers -> helpers + * + * Link components parser functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers). + **/ + this.helpers = assign({}, helpers); + this.options = {}; + this.configure(presetName); + if (options) { + this.set(options); + } +} + +/** chainable + * MarkdownIt.set(options) + * + * Set parser options (in the same format as in constructor). Probably, you + * will never need it, but you can change options after constructor call. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .set({ html: true, breaks: true }) + * .set({ typographer, true }); + * ``` + * + * __Note:__ To achieve the best possible performance, don't modify a + * `markdown-it` instance options on the fly. If you need multiple configurations + * it's best to create multiple instances and initialize each with separate + * config. + **/ +MarkdownIt.prototype.set = function (options) { + assign(this.options, options); + return this; +}; + +/** chainable, internal + * MarkdownIt.configure(presets) + * + * Batch load of all options and compenent settings. This is internal method, + * and you probably will not need it. But if you will - see available presets + * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets) + * + * We strongly recommend to use presets instead of direct config loads. That + * will give better compatibility with next versions. + **/ +MarkdownIt.prototype.configure = function (presets) { + const self = this; + if (isString(presets)) { + const presetName = presets; + presets = config[presetName]; + if (!presets) { + throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name'); + } + } + if (!presets) { + throw new Error('Wrong `markdown-it` preset, can\'t be empty'); + } + if (presets.options) { + self.set(presets.options); + } + if (presets.components) { + Object.keys(presets.components).forEach(function (name) { + if (presets.components[name].rules) { + self[name].ruler.enableOnly(presets.components[name].rules); + } + if (presets.components[name].rules2) { + self[name].ruler2.enableOnly(presets.components[name].rules2); + } + }); + } + return this; +}; + +/** chainable + * MarkdownIt.enable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to enable + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable list or rules. It will automatically find appropriate components, + * containing rules with given names. If rule not found, and `ignoreInvalid` + * not set - throws exception. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .enable(['sub', 'sup']) + * .disable('smartquotes'); + * ``` + **/ +MarkdownIt.prototype.enable = function (list, ignoreInvalid) { + let result = []; + if (!Array.isArray(list)) { + list = [list]; + } + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.enable(list, true)); + }, this); + result = result.concat(this.inline.ruler2.enable(list, true)); + const missed = list.filter(function (name) { + return result.indexOf(name) < 0; + }); + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to enable unknown rule(s): ' + missed); + } + return this; +}; + +/** chainable + * MarkdownIt.disable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * The same as [[MarkdownIt.enable]], but turn specified rules off. + **/ +MarkdownIt.prototype.disable = function (list, ignoreInvalid) { + let result = []; + if (!Array.isArray(list)) { + list = [list]; + } + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.disable(list, true)); + }, this); + result = result.concat(this.inline.ruler2.disable(list, true)); + const missed = list.filter(function (name) { + return result.indexOf(name) < 0; + }); + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to disable unknown rule(s): ' + missed); + } + return this; +}; + +/** chainable + * MarkdownIt.use(plugin, params) + * + * Load specified plugin with given params into current parser instance. + * It's just a sugar to call `plugin(md, params)` with curring. + * + * ##### Example + * + * ```javascript + * var iterator = require('markdown-it-for-inline'); + * var md = require('markdown-it')() + * .use(iterator, 'foo_replace', 'text', function (tokens, idx) { + * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar'); + * }); + * ``` + **/ +MarkdownIt.prototype.use = function (plugin /*, params, ... */) { + const args = [this].concat(Array.prototype.slice.call(arguments, 1)); + plugin.apply(plugin, args); + return this; +}; + +/** internal + * MarkdownIt.parse(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * Parse input string and return list of block tokens (special token type + * "inline" will contain list of inline tokens). You should not call this + * method directly, until you write custom renderer (for example, to produce + * AST). + * + * `env` is used to pass data between "distributed" rules and return additional + * metadata like reference info, needed for the renderer. It also can be used to + * inject data in specific cases. Usually, you will be ok to pass `{}`, + * and then pass updated object to renderer. + **/ +MarkdownIt.prototype.parse = function (src, env) { + if (typeof src !== 'string') { + throw new Error('Input data should be a String'); + } + const state = new this.core.State(src, this, env); + this.core.process(state); + return state.tokens; +}; + +/** + * MarkdownIt.render(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Render markdown string into html. It does all magic for you :). + * + * `env` can be used to inject additional metadata (`{}` by default). + * But you will not need it with high probability. See also comment + * in [[MarkdownIt.parse]]. + **/ +MarkdownIt.prototype.render = function (src, env) { + env = env || {}; + return this.renderer.render(this.parse(src, env), this.options, env); +}; + +/** internal + * MarkdownIt.parseInline(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * The same as [[MarkdownIt.parse]] but skip all block rules. It returns the + * block tokens list with the single `inline` element, containing parsed inline + * tokens in `children` property. Also updates `env` object. + **/ +MarkdownIt.prototype.parseInline = function (src, env) { + const state = new this.core.State(src, this, env); + state.inlineMode = true; + this.core.process(state); + return state.tokens; +}; + +/** + * MarkdownIt.renderInline(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Similar to [[MarkdownIt.render]] but for single paragraph content. Result + * will NOT be wrapped into `

` tags. + **/ +MarkdownIt.prototype.renderInline = function (src, env) { + env = env || {}; + return this.renderer.render(this.parseInline(src, env), this.options, env); +}; + +module.exports = MarkdownIt; + +}); +define("mdurl",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +/* eslint-disable no-bitwise */ + +const decodeCache = {}; + +function getDecodeCache (exclude) { + let cache = decodeCache[exclude]; + if (cache) { return cache } + + cache = decodeCache[exclude] = []; + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i); + cache.push(ch); + } + + for (let i = 0; i < exclude.length; i++) { + const ch = exclude.charCodeAt(i); + cache[ch] = '%' + ('0' + ch.toString(16).toUpperCase()).slice(-2); + } + + return cache +} + +// Decode percent-encoded string. +// +function decode (string, exclude) { + if (typeof exclude !== 'string') { + exclude = decode.defaultChars; + } + + const cache = getDecodeCache(exclude); + + return string.replace(/(%[a-f0-9]{2})+/gi, function (seq) { + let result = ''; + + for (let i = 0, l = seq.length; i < l; i += 3) { + const b1 = parseInt(seq.slice(i + 1, i + 3), 16); + + if (b1 < 0x80) { + result += cache[b1]; + continue + } + + if ((b1 & 0xE0) === 0xC0 && (i + 3 < l)) { + // 110xxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + + if ((b2 & 0xC0) === 0x80) { + const chr = ((b1 << 6) & 0x7C0) | (b2 & 0x3F); + + if (chr < 0x80) { + result += '\ufffd\ufffd'; + } else { + result += String.fromCharCode(chr); + } + + i += 3; + continue + } + } + + if ((b1 & 0xF0) === 0xE0 && (i + 6 < l)) { + // 1110xxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + const b3 = parseInt(seq.slice(i + 7, i + 9), 16); + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) { + const chr = ((b1 << 12) & 0xF000) | ((b2 << 6) & 0xFC0) | (b3 & 0x3F); + + if (chr < 0x800 || (chr >= 0xD800 && chr <= 0xDFFF)) { + result += '\ufffd\ufffd\ufffd'; + } else { + result += String.fromCharCode(chr); + } + + i += 6; + continue + } + } + + if ((b1 & 0xF8) === 0xF0 && (i + 9 < l)) { + // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16); + const b3 = parseInt(seq.slice(i + 7, i + 9), 16); + const b4 = parseInt(seq.slice(i + 10, i + 12), 16); + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80 && (b4 & 0xC0) === 0x80) { + let chr = ((b1 << 18) & 0x1C0000) | ((b2 << 12) & 0x3F000) | ((b3 << 6) & 0xFC0) | (b4 & 0x3F); + + if (chr < 0x10000 || chr > 0x10FFFF) { + result += '\ufffd\ufffd\ufffd\ufffd'; + } else { + chr -= 0x10000; + result += String.fromCharCode(0xD800 + (chr >> 10), 0xDC00 + (chr & 0x3FF)); + } + + i += 9; + continue + } + } + + result += '\ufffd'; + } + + return result + }) +} + +decode.defaultChars = ';/?:@&=+$,#'; +decode.componentChars = ''; + +const encodeCache = {}; + +// Create a lookup array where anything but characters in `chars` string +// and alphanumeric chars is percent-encoded. +// +function getEncodeCache (exclude) { + let cache = encodeCache[exclude]; + if (cache) { return cache } + + cache = encodeCache[exclude] = []; + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i); + + if (/^[0-9a-z]$/i.test(ch)) { + // always allow unencoded alphanumeric characters + cache.push(ch); + } else { + cache.push('%' + ('0' + i.toString(16).toUpperCase()).slice(-2)); + } + } + + for (let i = 0; i < exclude.length; i++) { + cache[exclude.charCodeAt(i)] = exclude[i]; + } + + return cache +} + +// Encode unsafe characters with percent-encoding, skipping already +// encoded sequences. +// +// - string - string to encode +// - exclude - list of characters to ignore (in addition to a-zA-Z0-9) +// - keepEscaped - don't encode '%' in a correct escape sequence (default: true) +// +function encode (string, exclude, keepEscaped) { + if (typeof exclude !== 'string') { + // encode(string, keepEscaped) + keepEscaped = exclude; + exclude = encode.defaultChars; + } + + if (typeof keepEscaped === 'undefined') { + keepEscaped = true; + } + + const cache = getEncodeCache(exclude); + let result = ''; + + for (let i = 0, l = string.length; i < l; i++) { + const code = string.charCodeAt(i); + + if (keepEscaped && code === 0x25 /* % */ && i + 2 < l) { + if (/^[0-9a-f]{2}$/i.test(string.slice(i + 1, i + 3))) { + result += string.slice(i, i + 3); + i += 2; + continue + } + } + + if (code < 128) { + result += cache[code]; + continue + } + + if (code >= 0xD800 && code <= 0xDFFF) { + if (code >= 0xD800 && code <= 0xDBFF && i + 1 < l) { + const nextCode = string.charCodeAt(i + 1); + if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) { + result += encodeURIComponent(string[i] + string[i + 1]); + i++; + continue + } + } + result += '%EF%BF%BD'; + continue + } + + result += encodeURIComponent(string[i]); + } + + return result +} + +encode.defaultChars = ";/?:@&=+$,-_.!~*'()#"; +encode.componentChars = "-_.!~*'()"; + +function format (url) { + let result = ''; + + result += url.protocol || ''; + result += url.slashes ? '//' : ''; + result += url.auth ? url.auth + '@' : ''; + + if (url.hostname && url.hostname.indexOf(':') !== -1) { + // ipv6 address + result += '[' + url.hostname + ']'; + } else { + result += url.hostname || ''; + } + + result += url.port ? ':' + url.port : ''; + result += url.pathname || ''; + result += url.search || ''; + result += url.hash || ''; + + return result +} + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// +// Changes from joyent/node: +// +// 1. No leading slash in paths, +// e.g. in `url.parse('http://foo?bar')` pathname is ``, not `/` +// +// 2. Backslashes are not replaced with slashes, +// so `http:\\example.org\` is treated like a relative path +// +// 3. Trailing colon is treated like a part of the path, +// i.e. in `http://example.org:foo` pathname is `:foo` +// +// 4. Nothing is URL-encoded in the resulting object, +// (in joyent/node some chars in auth and paths are encoded) +// +// 5. `url.parse()` does not have `parseQueryString` argument +// +// 6. Removed extraneous result properties: `host`, `path`, `query`, etc., +// which can be constructed using other parts of the url. +// + +function Url () { + this.protocol = null; + this.slashes = null; + this.auth = null; + this.port = null; + this.hostname = null; + this.hash = null; + this.search = null; + this.pathname = null; +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +const protocolPattern = /^([a-z0-9.+-]+:)/i; +const portPattern = /:[0-9]*$/; + +// Special case for a simple path URL +/* eslint-disable-next-line no-useless-escape */ +const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/; + +// RFC 2396: characters reserved for delimiting URLs. +// We actually just auto-escape these. +const delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t']; + +// RFC 2396: characters not allowed for various reasons. +const unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims); + +// Allowed by RFCs, but cause of XSS attacks. Always escape these. +const autoEscape = ['\''].concat(unwise); +// Characters that are never ever allowed in a hostname. +// Note that any invalid chars are also handled, but these +// are the ones that are *expected* to be seen, so we fast-path +// them. +const nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape); +const hostEndingChars = ['/', '?', '#']; +const hostnameMaxLen = 255; +const hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/; +const hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/; +// protocols that can allow "unsafe" and "unwise" chars. +// protocols that never have a hostname. +const hostlessProtocol = { + javascript: true, + 'javascript:': true +}; +// protocols that always contain a // bit. +const slashedProtocol = { + http: true, + https: true, + ftp: true, + gopher: true, + file: true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true +}; + +function urlParse (url, slashesDenoteHost) { + if (url && url instanceof Url) return url + + const u = new Url(); + u.parse(url, slashesDenoteHost); + return u +} + +Url.prototype.parse = function (url, slashesDenoteHost) { + let lowerProto, hec, slashes; + let rest = url; + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim(); + + if (!slashesDenoteHost && url.split('#').length === 1) { + // Try fast path regexp + const simplePath = simplePathPattern.exec(rest); + if (simplePath) { + this.pathname = simplePath[1]; + if (simplePath[2]) { + this.search = simplePath[2]; + } + return this + } + } + + let proto = protocolPattern.exec(rest); + if (proto) { + proto = proto[0]; + lowerProto = proto.toLowerCase(); + this.protocol = proto; + rest = rest.substr(proto.length); + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + /* eslint-disable-next-line no-useless-escape */ + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + slashes = rest.substr(0, 2) === '//'; + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2); + this.slashes = true; + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + let hostEnd = -1; + for (let i = 0; i < hostEndingChars.length; i++) { + hec = rest.indexOf(hostEndingChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec; + } + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + let auth, atSign; + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@'); + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd); + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign); + rest = rest.slice(atSign + 1); + this.auth = auth; + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1; + for (let i = 0; i < nonHostChars.length; i++) { + hec = rest.indexOf(nonHostChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec; + } + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) { + hostEnd = rest.length; + } + + if (rest[hostEnd - 1] === ':') { hostEnd--; } + const host = rest.slice(0, hostEnd); + rest = rest.slice(hostEnd); + + // pull out port. + this.parseHost(host); + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || ''; + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + const ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']'; + + // validate a little. + if (!ipv6Hostname) { + const hostparts = this.hostname.split(/\./); + for (let i = 0, l = hostparts.length; i < l; i++) { + const part = hostparts[i]; + if (!part) { continue } + if (!part.match(hostnamePartPattern)) { + let newpart = ''; + for (let j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x'; + } else { + newpart += part[j]; + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + const validParts = hostparts.slice(0, i); + const notHost = hostparts.slice(i + 1); + const bit = part.match(hostnamePartStart); + if (bit) { + validParts.push(bit[1]); + notHost.unshift(bit[2]); + } + if (notHost.length) { + rest = notHost.join('.') + rest; + } + this.hostname = validParts.join('.'); + break + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = ''; + } + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2); + } + } + + // chop off from the tail first. + const hash = rest.indexOf('#'); + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash); + rest = rest.slice(0, hash); + } + const qm = rest.indexOf('?'); + if (qm !== -1) { + this.search = rest.substr(qm); + rest = rest.slice(0, qm); + } + if (rest) { this.pathname = rest; } + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = ''; + } + + return this +}; + +Url.prototype.parseHost = function (host) { + let port = portPattern.exec(host); + if (port) { + port = port[0]; + if (port !== ':') { + this.port = port.substr(1); + } + host = host.substr(0, host.length - port.length); + } + if (host) { this.hostname = host; } +}; + +exports.decode = decode; +exports.encode = encode; +exports.format = format; +exports.parse = urlParse; + +}); +define("orderedmap",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +// ::- Persistent data structure representing an ordered mapping from +// strings to values, with some convenient update methods. +function OrderedMap(content) { + this.content = content; +} + +OrderedMap.prototype = { + constructor: OrderedMap, + + find: function(key) { + for (var i = 0; i < this.content.length; i += 2) + if (this.content[i] === key) return i + return -1 + }, + + // :: (string) → ?any + // Retrieve the value stored under `key`, or return undefined when + // no such key exists. + get: function(key) { + var found = this.find(key); + return found == -1 ? undefined : this.content[found + 1] + }, + + // :: (string, any, ?string) → OrderedMap + // Create a new map by replacing the value of `key` with a new + // value, or adding a binding to the end of the map. If `newKey` is + // given, the key of the binding will be replaced with that key. + update: function(key, value, newKey) { + var self = newKey && newKey != key ? this.remove(newKey) : this; + var found = self.find(key), content = self.content.slice(); + if (found == -1) { + content.push(newKey || key, value); + } else { + content[found + 1] = value; + if (newKey) content[found] = newKey; + } + return new OrderedMap(content) + }, + + // :: (string) → OrderedMap + // Return a map with the given key removed, if it existed. + remove: function(key) { + var found = this.find(key); + if (found == -1) return this + var content = this.content.slice(); + content.splice(found, 2); + return new OrderedMap(content) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the start of the map. + addToStart: function(key, value) { + return new OrderedMap([key, value].concat(this.remove(key).content)) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the end of the map. + addToEnd: function(key, value) { + var content = this.remove(key).content.slice(); + content.push(key, value); + return new OrderedMap(content) + }, + + // :: (string, string, any) → OrderedMap + // Add a key after the given key. If `place` is not found, the new + // key is added to the end. + addBefore: function(place, key, value) { + var without = this.remove(key), content = without.content.slice(); + var found = without.find(place); + content.splice(found == -1 ? content.length : found, 0, key, value); + return new OrderedMap(content) + }, + + // :: ((key: string, value: any)) + // Call the given function for each key/value pair in the map, in + // order. + forEach: function(f) { + for (var i = 0; i < this.content.length; i += 2) + f(this.content[i], this.content[i + 1]); + }, + + // :: (union) → OrderedMap + // Create a new map by prepending the keys in this map that don't + // appear in `map` before the keys in `map`. + prepend: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(map.content.concat(this.subtract(map).content)) + }, + + // :: (union) → OrderedMap + // Create a new map by appending the keys in this map that don't + // appear in `map` after the keys in `map`. + append: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(this.subtract(map).content.concat(map.content)) + }, + + // :: (union) → OrderedMap + // Create a map containing all the keys in this map that don't + // appear in `map`. + subtract: function(map) { + var result = this; + map = OrderedMap.from(map); + for (var i = 0; i < map.content.length; i += 2) + result = result.remove(map.content[i]); + return result + }, + + // :: () → Object + // Turn ordered map into a plain object. + toObject: function() { + var result = {}; + this.forEach(function(key, value) { result[key] = value; }); + return result + }, + + // :: number + // The amount of keys in this map. + get size() { + return this.content.length >> 1 + } +}; + +// :: (?union) → OrderedMap +// Return a map with the given content. If null, create an empty +// map. If given an ordered map, return that map itself. If given an +// object, create a map from the object's properties. +OrderedMap.from = function(value) { + if (value instanceof OrderedMap) return value + var content = []; + if (value) for (var prop in value) content.push(prop, value[prop]); + return new OrderedMap(content) +}; + +module.exports = OrderedMap; + +}); +define("punycode.js",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +/** Highest positive signed 32-bit float value */ +const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 + +/** Bootstring parameters */ +const base = 36; +const tMin = 1; +const tMax = 26; +const skew = 38; +const damp = 700; +const initialBias = 72; +const initialN = 128; // 0x80 +const delimiter = '-'; // '\x2D' + +/** Regular expressions */ +const regexPunycode = /^xn--/; +const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too. +const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators + +/** Error messages */ +const errors = { + 'overflow': 'Overflow: input needs wider integers to process', + 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', + 'invalid-input': 'Invalid input' +}; + +/** Convenience shortcuts */ +const baseMinusTMin = base - tMin; +const floor = Math.floor; +const stringFromCharCode = String.fromCharCode; + +/*--------------------------------------------------------------------------*/ + +/** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ +function error(type) { + throw new RangeError(errors[type]); +} + +/** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ +function map(array, callback) { + const result = []; + let length = array.length; + while (length--) { + result[length] = callback(array[length]); + } + return result; +} + +/** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {String} A new string of characters returned by the callback + * function. + */ +function mapDomain(domain, callback) { + const parts = domain.split('@'); + let result = ''; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + '@'; + domain = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + domain = domain.replace(regexSeparators, '\x2E'); + const labels = domain.split('.'); + const encoded = map(labels, callback).join('.'); + return result + encoded; +} + +/** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ +function ucs2decode(string) { + const output = []; + let counter = 0; + const length = string.length; + while (counter < length) { + const value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + // It's a high surrogate, and there is a next character. + const extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { // Low surrogate. + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + // It's an unmatched surrogate; only append this code unit, in case the + // next code unit is the high surrogate of a surrogate pair. + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; +} + +/** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ +const ucs2encode = codePoints => String.fromCodePoint(...codePoints); + +/** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ +const basicToDigit = function(codePoint) { + if (codePoint >= 0x30 && codePoint < 0x3A) { + return 26 + (codePoint - 0x30); + } + if (codePoint >= 0x41 && codePoint < 0x5B) { + return codePoint - 0x41; + } + if (codePoint >= 0x61 && codePoint < 0x7B) { + return codePoint - 0x61; + } + return base; +}; + +/** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ +const digitToBasic = function(digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); +}; + +/** + * Bias adaptation function as per section 3.4 of RFC 3492. + * https://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ +const adapt = function(delta, numPoints, firstTime) { + let k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); +}; + +/** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ +const decode = function(input) { + // Don't use UCS-2. + const output = []; + const inputLength = input.length; + let i = 0; + let n = initialN; + let bias = initialBias; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + let basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + + for (let j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 0x80) { + error('not-basic'); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + const oldi = i; + for (let w = 1, k = base; /* no condition */; k += base) { + + if (index >= inputLength) { + error('invalid-input'); + } + + const digit = basicToDigit(input.charCodeAt(index++)); + + if (digit >= base) { + error('invalid-input'); + } + if (digit > floor((maxInt - i) / w)) { + error('overflow'); + } + + i += digit * w; + const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + + if (digit < t) { + break; + } + + const baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error('overflow'); + } + + w *= baseMinusT; + + } + + const out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error('overflow'); + } + + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output. + output.splice(i++, 0, n); + + } + + return String.fromCodePoint(...output); +}; + +/** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ +const encode = function(input) { + const output = []; + + // Convert the input in UCS-2 to an array of Unicode code points. + input = ucs2decode(input); + + // Cache the length. + const inputLength = input.length; + + // Initialize the state. + let n = initialN; + let delta = 0; + let bias = initialBias; + + // Handle the basic code points. + for (const currentValue of input) { + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); + } + } + + const basicLength = output.length; + let handledCPCount = basicLength; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string with a delimiter unless it's empty. + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + + // All non-basic code points < n have been handled already. Find the next + // larger one: + let m = maxInt; + for (const currentValue of input) { + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow. + const handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error('overflow'); + } + + delta += (m - n) * handledCPCountPlusOne; + n = m; + + for (const currentValue of input) { + if (currentValue < n && ++delta > maxInt) { + error('overflow'); + } + if (currentValue === n) { + // Represent delta as a generalized variable-length integer. + let q = delta; + for (let k = base; /* no condition */; k += base) { + const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + if (q < t) { + break; + } + const qMinusT = q - t; + const baseMinusT = base - t; + output.push( + stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) + ); + q = floor(qMinusT / baseMinusT); + } + + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength); + delta = 0; + ++handledCPCount; + } + } + + ++delta; + ++n; + + } + return output.join(''); +}; + +/** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ +const toUnicode = function(input) { + return mapDomain(input, function(string) { + return regexPunycode.test(string) + ? decode(string.slice(4).toLowerCase()) + : string; + }); +}; + +/** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ +const toASCII = function(input) { + return mapDomain(input, function(string) { + return regexNonASCII.test(string) + ? 'xn--' + encode(string) + : string; + }); +}; + +/*--------------------------------------------------------------------------*/ + +/** Define the public API */ +const punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + 'version': '2.3.1', + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + 'ucs2': { + 'decode': ucs2decode, + 'encode': ucs2encode + }, + 'decode': decode, + 'encode': encode, + 'toASCII': toASCII, + 'toUnicode': toUnicode +}; + +module.exports = punycode; + +}); +define("rope-sequence",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var GOOD_LEAF_SIZE = 200; + +// :: class A rope sequence is a persistent sequence data structure +// that supports appending, prepending, and slicing without doing a +// full copy. It is represented as a mostly-balanced tree. +var RopeSequence = function RopeSequence () {}; + +RopeSequence.prototype.append = function append (other) { + if (!other.length) { return this } + other = RopeSequence.from(other); + + return (!this.length && other) || + (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) || + (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) || + this.appendInner(other) +}; + +// :: (union<[T], RopeSequence>) → RopeSequence +// Prepend an array or other rope to this one, returning a new rope. +RopeSequence.prototype.prepend = function prepend (other) { + if (!other.length) { return this } + return RopeSequence.from(other).append(this) +}; + +RopeSequence.prototype.appendInner = function appendInner (other) { + return new Append(this, other) +}; + +// :: (?number, ?number) → RopeSequence +// Create a rope repesenting a sub-sequence of this rope. +RopeSequence.prototype.slice = function slice (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from >= to) { return RopeSequence.empty } + return this.sliceInner(Math.max(0, from), Math.min(this.length, to)) +}; + +// :: (number) → T +// Retrieve the element at the given position from this rope. +RopeSequence.prototype.get = function get (i) { + if (i < 0 || i >= this.length) { return undefined } + return this.getInner(i) +}; + +// :: ((element: T, index: number) → ?bool, ?number, ?number) +// Call the given function for each element between the given +// indices. This tends to be more efficient than looping over the +// indices and calling `get`, because it doesn't have to descend the +// tree for every element. +RopeSequence.prototype.forEach = function forEach (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from <= to) + { this.forEachInner(f, from, to, 0); } + else + { this.forEachInvertedInner(f, from, to, 0); } +}; + +// :: ((element: T, index: number) → U, ?number, ?number) → [U] +// Map the given functions over the elements of the rope, producing +// a flat array. +RopeSequence.prototype.map = function map (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + var result = []; + this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to); + return result +}; + +// :: (?union<[T], RopeSequence>) → RopeSequence +// Create a rope representing the given array, or return the rope +// itself if a rope was given. +RopeSequence.from = function from (values) { + if (values instanceof RopeSequence) { return values } + return values && values.length ? new Leaf(values) : RopeSequence.empty +}; + +var Leaf = /*@__PURE__*/(function (RopeSequence) { + function Leaf(values) { + RopeSequence.call(this); + this.values = values; + } + + if ( RopeSequence ) Leaf.__proto__ = RopeSequence; + Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Leaf.prototype.constructor = Leaf; + + var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } }; + + Leaf.prototype.flatten = function flatten () { + return this.values + }; + + Leaf.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + return new Leaf(this.values.slice(from, to)) + }; + + Leaf.prototype.getInner = function getInner (i) { + return this.values[i] + }; + + Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) { + for (var i = from; i < to; i++) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + for (var i = from - 1; i >= to; i--) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.leafAppend = function leafAppend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(this.values.concat(other.flatten())) } + }; + + Leaf.prototype.leafPrepend = function leafPrepend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(other.flatten().concat(this.values)) } + }; + + prototypeAccessors.length.get = function () { return this.values.length }; + + prototypeAccessors.depth.get = function () { return 0 }; + + Object.defineProperties( Leaf.prototype, prototypeAccessors ); + + return Leaf; +}(RopeSequence)); + +// :: RopeSequence +// The empty rope sequence. +RopeSequence.empty = new Leaf([]); + +var Append = /*@__PURE__*/(function (RopeSequence) { + function Append(left, right) { + RopeSequence.call(this); + this.left = left; + this.right = right; + this.length = left.length + right.length; + this.depth = Math.max(left.depth, right.depth) + 1; + } + + if ( RopeSequence ) Append.__proto__ = RopeSequence; + Append.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Append.prototype.constructor = Append; + + Append.prototype.flatten = function flatten () { + return this.left.flatten().concat(this.right.flatten()) + }; + + Append.prototype.getInner = function getInner (i) { + return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length) + }; + + Append.prototype.forEachInner = function forEachInner (f, from, to, start) { + var leftLen = this.left.length; + if (from < leftLen && + this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false) + { return false } + if (to > leftLen && + this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) + { return false } + }; + + Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + var leftLen = this.left.length; + if (from > leftLen && + this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) + { return false } + if (to < leftLen && + this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false) + { return false } + }; + + Append.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + var leftLen = this.left.length; + if (to <= leftLen) { return this.left.slice(from, to) } + if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) } + return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen)) + }; + + Append.prototype.leafAppend = function leafAppend (other) { + var inner = this.right.leafAppend(other); + if (inner) { return new Append(this.left, inner) } + }; + + Append.prototype.leafPrepend = function leafPrepend (other) { + var inner = this.left.leafPrepend(other); + if (inner) { return new Append(inner, this.right) } + }; + + Append.prototype.appendInner = function appendInner (other) { + if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) + { return new Append(this.left, new Append(this.right, other)) } + return new Append(this, other) + }; + + return Append; +}(RopeSequence)); + +module.exports = RopeSequence; + +}); +define("uc.micro",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +var regex$5 = /[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; + +var regex$4 = /[\0-\x1F\x7F-\x9F]/; + +var regex$3 = /[\xAD\u0600-\u0605\u061C\u06DD\u070F\u0890\u0891\u08E2\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF\uFFF9-\uFFFB]|\uD804[\uDCBD\uDCCD]|\uD80D[\uDC30-\uDC3F]|\uD82F[\uDCA0-\uDCA3]|\uD834[\uDD73-\uDD7A]|\uDB40[\uDC01\uDC20-\uDC7F]/; + +var regex$2 = /[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/; + +var regex$1 = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC2\uFD40-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA]/; + +var regex = /[ \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/; + +exports.Any = regex$5; +exports.Cc = regex$4; +exports.Cf = regex$3; +exports.P = regex$2; +exports.S = regex$1; +exports.Z = regex; + +}); +define("w3c-keyname",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var base = { + 8: "Backspace", + 9: "Tab", + 10: "Enter", + 12: "NumLock", + 13: "Enter", + 16: "Shift", + 17: "Control", + 18: "Alt", + 20: "CapsLock", + 27: "Escape", + 32: " ", + 33: "PageUp", + 34: "PageDown", + 35: "End", + 36: "Home", + 37: "ArrowLeft", + 38: "ArrowUp", + 39: "ArrowRight", + 40: "ArrowDown", + 44: "PrintScreen", + 45: "Insert", + 46: "Delete", + 59: ";", + 61: "=", + 91: "Meta", + 92: "Meta", + 106: "*", + 107: "+", + 108: ",", + 109: "-", + 110: ".", + 111: "/", + 144: "NumLock", + 145: "ScrollLock", + 160: "Shift", + 161: "Shift", + 162: "Control", + 163: "Control", + 164: "Alt", + 165: "Alt", + 173: "-", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" +}; + +var shift = { + 48: ")", + 49: "!", + 50: "@", + 51: "#", + 52: "$", + 53: "%", + 54: "^", + 55: "&", + 56: "*", + 57: "(", + 59: ":", + 61: "+", + 173: "_", + 186: ":", + 187: "+", + 188: "<", + 189: "_", + 190: ">", + 191: "?", + 192: "~", + 219: "{", + 220: "|", + 221: "}", + 222: "\"" +}; + +var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform); +var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); + +// Fill in the digit keys +for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i); + +// The function keys +for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i; + +// And the alphabetic keys +for (var i = 65; i <= 90; i++) { + base[i] = String.fromCharCode(i + 32); + shift[i] = String.fromCharCode(i); +} + +// For each code that doesn't have a shift-equivalent, copy the base name +for (var code in base) if (!shift.hasOwnProperty(code)) shift[code] = base[code]; + +function keyName(event) { + // On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`. + // On IE, shift effect is never included in `.key`. + var ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || + ie && event.shiftKey && event.key && event.key.length == 1 || + event.key == "Unidentified"; + var name = (!ignoreKey && event.key) || + (event.shiftKey ? shift : base)[event.keyCode] || + event.key || "Unidentified"; + // Edge sometimes produces wrong names (Issue #3) + if (name == "Esc") name = "Escape"; + if (name == "Del") name = "Delete"; + // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/ + if (name == "Left") name = "ArrowLeft"; + if (name == "Up") name = "ArrowUp"; + if (name == "Right") name = "ArrowRight"; + if (name == "Down") name = "ArrowDown"; + return name +} + +exports.base = base; +exports.keyName = keyName; +exports.shift = shift; + +}); +define("entities",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLAttribute = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.DecodingMode = exports.EntityDecoder = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.EntityLevel = void 0; +var decode_js_1 = require("./decode.js"); +var encode_js_1 = require("./encode.js"); +var escape_js_1 = require("./escape.js"); +/** The level of entities to support. */ +var EntityLevel; +(function (EntityLevel) { + /** Support only XML entities. */ + EntityLevel[EntityLevel["XML"] = 0] = "XML"; + /** Support HTML entities, which are a superset of XML entities. */ + EntityLevel[EntityLevel["HTML"] = 1] = "HTML"; +})(EntityLevel = exports.EntityLevel || (exports.EntityLevel = {})); +var EncodingMode; +(function (EncodingMode) { + /** + * The output is UTF-8 encoded. Only characters that need escaping within + * XML will be escaped. + */ + EncodingMode[EncodingMode["UTF8"] = 0] = "UTF8"; + /** + * The output consists only of ASCII characters. Characters that need + * escaping within HTML, and characters that aren't ASCII characters will + * be escaped. + */ + EncodingMode[EncodingMode["ASCII"] = 1] = "ASCII"; + /** + * Encode all characters that have an equivalent entity, as well as all + * characters that are not ASCII characters. + */ + EncodingMode[EncodingMode["Extensive"] = 2] = "Extensive"; + /** + * Encode all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + EncodingMode[EncodingMode["Attribute"] = 3] = "Attribute"; + /** + * Encode all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + EncodingMode[EncodingMode["Text"] = 4] = "Text"; +})(EncodingMode = exports.EncodingMode || (exports.EncodingMode = {})); +/** + * Decodes a string with entities. + * + * @param data String to decode. + * @param options Decoding options. + */ +function decode(data, options) { + if (options === void 0) { options = EntityLevel.XML; } + var level = typeof options === "number" ? options : options.level; + if (level === EntityLevel.HTML) { + var mode = typeof options === "object" ? options.mode : undefined; + return (0, decode_js_1.decodeHTML)(data, mode); + } + return (0, decode_js_1.decodeXML)(data); +} +exports.decode = decode; +/** + * Decodes a string with entities. Does not allow missing trailing semicolons for entities. + * + * @param data String to decode. + * @param options Decoding options. + * @deprecated Use `decode` with the `mode` set to `Strict`. + */ +function decodeStrict(data, options) { + var _a; + if (options === void 0) { options = EntityLevel.XML; } + var opts = typeof options === "number" ? { level: options } : options; + (_a = opts.mode) !== null && _a !== void 0 ? _a : (opts.mode = decode_js_1.DecodingMode.Strict); + return decode(data, opts); +} +exports.decodeStrict = decodeStrict; +/** + * Encodes a string with entities. + * + * @param data String to encode. + * @param options Encoding options. + */ +function encode(data, options) { + if (options === void 0) { options = EntityLevel.XML; } + var opts = typeof options === "number" ? { level: options } : options; + // Mode `UTF8` just escapes XML entities + if (opts.mode === EncodingMode.UTF8) + return (0, escape_js_1.escapeUTF8)(data); + if (opts.mode === EncodingMode.Attribute) + return (0, escape_js_1.escapeAttribute)(data); + if (opts.mode === EncodingMode.Text) + return (0, escape_js_1.escapeText)(data); + if (opts.level === EntityLevel.HTML) { + if (opts.mode === EncodingMode.ASCII) { + return (0, encode_js_1.encodeNonAsciiHTML)(data); + } + return (0, encode_js_1.encodeHTML)(data); + } + // ASCII and Extensive are equivalent + return (0, escape_js_1.encodeXML)(data); +} +exports.encode = encode; +var escape_js_2 = require("./escape.js"); +Object.defineProperty(exports, "encodeXML", { enumerable: true, get: function () { return escape_js_2.encodeXML; } }); +Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return escape_js_2.escape; } }); +Object.defineProperty(exports, "escapeUTF8", { enumerable: true, get: function () { return escape_js_2.escapeUTF8; } }); +Object.defineProperty(exports, "escapeAttribute", { enumerable: true, get: function () { return escape_js_2.escapeAttribute; } }); +Object.defineProperty(exports, "escapeText", { enumerable: true, get: function () { return escape_js_2.escapeText; } }); +var encode_js_2 = require("./encode.js"); +Object.defineProperty(exports, "encodeHTML", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +Object.defineProperty(exports, "encodeNonAsciiHTML", { enumerable: true, get: function () { return encode_js_2.encodeNonAsciiHTML; } }); +// Legacy aliases (deprecated) +Object.defineProperty(exports, "encodeHTML4", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +Object.defineProperty(exports, "encodeHTML5", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } }); +var decode_js_2 = require("./decode.js"); +Object.defineProperty(exports, "EntityDecoder", { enumerable: true, get: function () { return decode_js_2.EntityDecoder; } }); +Object.defineProperty(exports, "DecodingMode", { enumerable: true, get: function () { return decode_js_2.DecodingMode; } }); +Object.defineProperty(exports, "decodeXML", { enumerable: true, get: function () { return decode_js_2.decodeXML; } }); +Object.defineProperty(exports, "decodeHTML", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTMLStrict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeHTMLAttribute", { enumerable: true, get: function () { return decode_js_2.decodeHTMLAttribute; } }); +// Legacy aliases (deprecated) +Object.defineProperty(exports, "decodeHTML4", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTML5", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } }); +Object.defineProperty(exports, "decodeHTML4Strict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeHTML5Strict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } }); +Object.defineProperty(exports, "decodeXMLStrict", { enumerable: true, get: function () { return decode_js_2.decodeXML; } }); + +}); +define("entities/decode",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTMLAttribute = exports.decodeHTML = exports.determineBranch = exports.EntityDecoder = exports.DecodingMode = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0; +var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js")); +exports.htmlDecodeTree = decode_data_html_js_1.default; +var decode_data_xml_js_1 = __importDefault(require("./generated/decode-data-xml.js")); +exports.xmlDecodeTree = decode_data_xml_js_1.default; +var decode_codepoint_js_1 = __importStar(require("./decode_codepoint.js")); +exports.decodeCodePoint = decode_codepoint_js_1.default; +var decode_codepoint_js_2 = require("./decode_codepoint.js"); +Object.defineProperty(exports, "replaceCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } }); +Object.defineProperty(exports, "fromCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.fromCodePoint; } }); +var CharCodes; +(function (CharCodes) { + CharCodes[CharCodes["NUM"] = 35] = "NUM"; + CharCodes[CharCodes["SEMI"] = 59] = "SEMI"; + CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS"; + CharCodes[CharCodes["ZERO"] = 48] = "ZERO"; + CharCodes[CharCodes["NINE"] = 57] = "NINE"; + CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A"; + CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F"; + CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X"; + CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z"; + CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A"; + CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F"; + CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z"; +})(CharCodes || (CharCodes = {})); +/** Bit that needs to be set to convert an upper case ASCII character to lower case */ +var TO_LOWER_BIT = 32; +var BinTrieFlags; +(function (BinTrieFlags) { + BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH"; + BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH"; + BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE"; +})(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {})); +function isNumber(code) { + return code >= CharCodes.ZERO && code <= CharCodes.NINE; +} +function isHexadecimalCharacter(code) { + return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F)); +} +function isAsciiAlphaNumeric(code) { + return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) || + isNumber(code)); +} +/** + * Checks if the given character is a valid end character for an entity in an attribute. + * + * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error. + * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state + */ +function isEntityInAttributeInvalidEnd(code) { + return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code); +} +var EntityDecoderState; +(function (EntityDecoderState) { + EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart"; + EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart"; + EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal"; + EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex"; + EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity"; +})(EntityDecoderState || (EntityDecoderState = {})); +var DecodingMode; +(function (DecodingMode) { + /** Entities in text nodes that can end with any character. */ + DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy"; + /** Only allow entities terminated with a semicolon. */ + DecodingMode[DecodingMode["Strict"] = 1] = "Strict"; + /** Entities in attributes have limitations on ending characters. */ + DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute"; +})(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {})); +/** + * Token decoder with support of writing partial entities. + */ +var EntityDecoder = /** @class */ (function () { + function EntityDecoder( + /** The tree used to decode entities. */ + decodeTree, + /** + * The function that is called when a codepoint is decoded. + * + * For multi-byte named entities, this will be called multiple times, + * with the second codepoint, and the same `consumed` value. + * + * @param codepoint The decoded codepoint. + * @param consumed The number of bytes consumed by the decoder. + */ + emitCodePoint, + /** An object that is used to produce errors. */ + errors) { + this.decodeTree = decodeTree; + this.emitCodePoint = emitCodePoint; + this.errors = errors; + /** The current state of the decoder. */ + this.state = EntityDecoderState.EntityStart; + /** Characters that were consumed while parsing an entity. */ + this.consumed = 1; + /** + * The result of the entity. + * + * Either the result index of a numeric entity, or the codepoint of a + * numeric entity. + */ + this.result = 0; + /** The current index in the decode tree. */ + this.treeIndex = 0; + /** The number of characters that were consumed in excess. */ + this.excess = 1; + /** The mode in which the decoder is operating. */ + this.decodeMode = DecodingMode.Strict; + } + /** Resets the instance to make it reusable. */ + EntityDecoder.prototype.startEntity = function (decodeMode) { + this.decodeMode = decodeMode; + this.state = EntityDecoderState.EntityStart; + this.result = 0; + this.treeIndex = 0; + this.excess = 1; + this.consumed = 1; + }; + /** + * Write an entity to the decoder. This can be called multiple times with partial entities. + * If the entity is incomplete, the decoder will return -1. + * + * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the + * entity is incomplete, and resume when the next string is written. + * + * @param string The string containing the entity (or a continuation of the entity). + * @param offset The offset at which the entity begins. Should be 0 if this is not the first call. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.write = function (str, offset) { + switch (this.state) { + case EntityDecoderState.EntityStart: { + if (str.charCodeAt(offset) === CharCodes.NUM) { + this.state = EntityDecoderState.NumericStart; + this.consumed += 1; + return this.stateNumericStart(str, offset + 1); + } + this.state = EntityDecoderState.NamedEntity; + return this.stateNamedEntity(str, offset); + } + case EntityDecoderState.NumericStart: { + return this.stateNumericStart(str, offset); + } + case EntityDecoderState.NumericDecimal: { + return this.stateNumericDecimal(str, offset); + } + case EntityDecoderState.NumericHex: { + return this.stateNumericHex(str, offset); + } + case EntityDecoderState.NamedEntity: { + return this.stateNamedEntity(str, offset); + } + } + }; + /** + * Switches between the numeric decimal and hexadecimal states. + * + * Equivalent to the `Numeric character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericStart = function (str, offset) { + if (offset >= str.length) { + return -1; + } + if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) { + this.state = EntityDecoderState.NumericHex; + this.consumed += 1; + return this.stateNumericHex(str, offset + 1); + } + this.state = EntityDecoderState.NumericDecimal; + return this.stateNumericDecimal(str, offset); + }; + EntityDecoder.prototype.addToNumericResult = function (str, start, end, base) { + if (start !== end) { + var digitCount = end - start; + this.result = + this.result * Math.pow(base, digitCount) + + parseInt(str.substr(start, digitCount), base); + this.consumed += digitCount; + } + }; + /** + * Parses a hexadecimal numeric entity. + * + * Equivalent to the `Hexademical character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericHex = function (str, offset) { + var startIdx = offset; + while (offset < str.length) { + var char = str.charCodeAt(offset); + if (isNumber(char) || isHexadecimalCharacter(char)) { + offset += 1; + } + else { + this.addToNumericResult(str, startIdx, offset, 16); + return this.emitNumericEntity(char, 3); + } + } + this.addToNumericResult(str, startIdx, offset, 16); + return -1; + }; + /** + * Parses a decimal numeric entity. + * + * Equivalent to the `Decimal character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNumericDecimal = function (str, offset) { + var startIdx = offset; + while (offset < str.length) { + var char = str.charCodeAt(offset); + if (isNumber(char)) { + offset += 1; + } + else { + this.addToNumericResult(str, startIdx, offset, 10); + return this.emitNumericEntity(char, 2); + } + } + this.addToNumericResult(str, startIdx, offset, 10); + return -1; + }; + /** + * Validate and emit a numeric entity. + * + * Implements the logic from the `Hexademical character reference start + * state` and `Numeric character reference end state` in the HTML spec. + * + * @param lastCp The last code point of the entity. Used to see if the + * entity was terminated with a semicolon. + * @param expectedLength The minimum number of characters that should be + * consumed. Used to validate that at least one digit + * was consumed. + * @returns The number of characters that were consumed. + */ + EntityDecoder.prototype.emitNumericEntity = function (lastCp, expectedLength) { + var _a; + // Ensure we consumed at least one digit. + if (this.consumed <= expectedLength) { + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); + return 0; + } + // Figure out if this is a legit end of the entity + if (lastCp === CharCodes.SEMI) { + this.consumed += 1; + } + else if (this.decodeMode === DecodingMode.Strict) { + return 0; + } + this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed); + if (this.errors) { + if (lastCp !== CharCodes.SEMI) { + this.errors.missingSemicolonAfterCharacterReference(); + } + this.errors.validateNumericCharacterReference(this.result); + } + return this.consumed; + }; + /** + * Parses a named entity. + * + * Equivalent to the `Named character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + EntityDecoder.prototype.stateNamedEntity = function (str, offset) { + var decodeTree = this.decodeTree; + var current = decodeTree[this.treeIndex]; + // The mask is the number of bytes of the value, including the current byte. + var valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + for (; offset < str.length; offset++, this.excess++) { + var char = str.charCodeAt(offset); + this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char); + if (this.treeIndex < 0) { + return this.result === 0 || + // If we are parsing an attribute + (this.decodeMode === DecodingMode.Attribute && + // We shouldn't have consumed any characters after the entity, + (valueLength === 0 || + // And there should be no invalid characters. + isEntityInAttributeInvalidEnd(char))) + ? 0 + : this.emitNotTerminatedNamedEntity(); + } + current = decodeTree[this.treeIndex]; + valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + // If the branch is a value, store it and continue + if (valueLength !== 0) { + // If the entity is terminated by a semicolon, we are done. + if (char === CharCodes.SEMI) { + return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess); + } + // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it. + if (this.decodeMode !== DecodingMode.Strict) { + this.result = this.treeIndex; + this.consumed += this.excess; + this.excess = 0; + } + } + } + return -1; + }; + /** + * Emit a named entity that was not terminated with a semicolon. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.emitNotTerminatedNamedEntity = function () { + var _a; + var _b = this, result = _b.result, decodeTree = _b.decodeTree; + var valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14; + this.emitNamedEntityData(result, valueLength, this.consumed); + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference(); + return this.consumed; + }; + /** + * Emit a named entity. + * + * @param result The index of the entity in the decode tree. + * @param valueLength The number of bytes in the entity. + * @param consumed The number of characters consumed. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.emitNamedEntityData = function (result, valueLength, consumed) { + var decodeTree = this.decodeTree; + this.emitCodePoint(valueLength === 1 + ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH + : decodeTree[result + 1], consumed); + if (valueLength === 3) { + // For multi-byte values, we need to emit the second byte. + this.emitCodePoint(decodeTree[result + 2], consumed); + } + return consumed; + }; + /** + * Signal to the parser that the end of the input was reached. + * + * Remaining data will be emitted and relevant errors will be produced. + * + * @returns The number of characters consumed. + */ + EntityDecoder.prototype.end = function () { + var _a; + switch (this.state) { + case EntityDecoderState.NamedEntity: { + // Emit a named entity if we have one. + return this.result !== 0 && + (this.decodeMode !== DecodingMode.Attribute || + this.result === this.treeIndex) + ? this.emitNotTerminatedNamedEntity() + : 0; + } + // Otherwise, emit a numeric entity if we have one. + case EntityDecoderState.NumericDecimal: { + return this.emitNumericEntity(0, 2); + } + case EntityDecoderState.NumericHex: { + return this.emitNumericEntity(0, 3); + } + case EntityDecoderState.NumericStart: { + (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed); + return 0; + } + case EntityDecoderState.EntityStart: { + // Return 0 if we have no entity. + return 0; + } + } + }; + return EntityDecoder; +}()); +exports.EntityDecoder = EntityDecoder; +/** + * Creates a function that decodes entities in a string. + * + * @param decodeTree The decode tree. + * @returns A function that decodes entities in a string. + */ +function getDecoder(decodeTree) { + var ret = ""; + var decoder = new EntityDecoder(decodeTree, function (str) { return (ret += (0, decode_codepoint_js_1.fromCodePoint)(str)); }); + return function decodeWithTrie(str, decodeMode) { + var lastIndex = 0; + var offset = 0; + while ((offset = str.indexOf("&", offset)) >= 0) { + ret += str.slice(lastIndex, offset); + decoder.startEntity(decodeMode); + var len = decoder.write(str, + // Skip the "&" + offset + 1); + if (len < 0) { + lastIndex = offset + decoder.end(); + break; + } + lastIndex = offset + len; + // If `len` is 0, skip the current `&` and continue. + offset = len === 0 ? lastIndex + 1 : lastIndex; + } + var result = ret + str.slice(lastIndex); + // Make sure we don't keep a reference to the final string. + ret = ""; + return result; + }; +} +/** + * Determines the branch of the current node that is taken given the current + * character. This function is used to traverse the trie. + * + * @param decodeTree The trie. + * @param current The current node. + * @param nodeIdx The index right after the current node and its value. + * @param char The current character. + * @returns The index of the next node, or -1 if no branch is taken. + */ +function determineBranch(decodeTree, current, nodeIdx, char) { + var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; + var jumpOffset = current & BinTrieFlags.JUMP_TABLE; + // Case 1: Single branch encoded in jump offset + if (branchCount === 0) { + return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1; + } + // Case 2: Multiple branches encoded in jump table + if (jumpOffset) { + var value = char - jumpOffset; + return value < 0 || value >= branchCount + ? -1 + : decodeTree[nodeIdx + value] - 1; + } + // Case 3: Multiple branches encoded in dictionary + // Binary search for the character. + var lo = nodeIdx; + var hi = lo + branchCount - 1; + while (lo <= hi) { + var mid = (lo + hi) >>> 1; + var midVal = decodeTree[mid]; + if (midVal < char) { + lo = mid + 1; + } + else if (midVal > char) { + hi = mid - 1; + } + else { + return decodeTree[mid + branchCount]; + } + } + return -1; +} +exports.determineBranch = determineBranch; +var htmlDecoder = getDecoder(decode_data_html_js_1.default); +var xmlDecoder = getDecoder(decode_data_xml_js_1.default); +/** + * Decodes an HTML string. + * + * @param str The string to decode. + * @param mode The decoding mode. + * @returns The decoded string. + */ +function decodeHTML(str, mode) { + if (mode === void 0) { mode = DecodingMode.Legacy; } + return htmlDecoder(str, mode); +} +exports.decodeHTML = decodeHTML; +/** + * Decodes an HTML string in an attribute. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeHTMLAttribute(str) { + return htmlDecoder(str, DecodingMode.Attribute); +} +exports.decodeHTMLAttribute = decodeHTMLAttribute; +/** + * Decodes an HTML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeHTMLStrict(str) { + return htmlDecoder(str, DecodingMode.Strict); +} +exports.decodeHTMLStrict = decodeHTMLStrict; +/** + * Decodes an XML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +function decodeXML(str) { + return xmlDecoder(str, DecodingMode.Strict); +} +exports.decodeXML = decodeXML; + +}); +define("entities/encode",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.encodeNonAsciiHTML = exports.encodeHTML = void 0; +var encode_html_js_1 = __importDefault(require("./generated/encode-html.js")); +var escape_js_1 = require("./escape.js"); +var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g; +/** + * Encodes all characters in the input using HTML entities. This includes + * characters that are valid ASCII characters in HTML documents, such as `#`. + * + * To get a more compact output, consider using the `encodeNonAsciiHTML` + * function, which will only encode characters that are not valid in HTML + * documents, as well as non-ASCII characters. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +function encodeHTML(data) { + return encodeHTMLTrieRe(htmlReplacer, data); +} +exports.encodeHTML = encodeHTML; +/** + * Encodes all non-ASCII characters, as well as characters not valid in HTML + * documents using HTML entities. This function will not encode characters that + * are valid in HTML documents, such as `#`. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +function encodeNonAsciiHTML(data) { + return encodeHTMLTrieRe(escape_js_1.xmlReplacer, data); +} +exports.encodeNonAsciiHTML = encodeNonAsciiHTML; +function encodeHTMLTrieRe(regExp, str) { + var ret = ""; + var lastIdx = 0; + var match; + while ((match = regExp.exec(str)) !== null) { + var i = match.index; + ret += str.substring(lastIdx, i); + var char = str.charCodeAt(i); + var next = encode_html_js_1.default.get(char); + if (typeof next === "object") { + // We are in a branch. Try to match the next char. + if (i + 1 < str.length) { + var nextChar = str.charCodeAt(i + 1); + var value = typeof next.n === "number" + ? next.n === nextChar + ? next.o + : undefined + : next.n.get(nextChar); + if (value !== undefined) { + ret += value; + lastIdx = regExp.lastIndex += 1; + continue; + } + } + next = next.v; + } + // We might have a tree node without a value; skip and use a numeric entity. + if (next !== undefined) { + ret += next; + lastIdx = i + 1; + } + else { + var cp = (0, escape_js_1.getCodePoint)(str, i); + ret += "&#x".concat(cp.toString(16), ";"); + // Increase by 1 if we have a surrogate pair + lastIdx = regExp.lastIndex += Number(cp !== char); + } + } + return ret + str.substr(lastIdx); +} + +}); +define("entities/escape",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.getCodePoint = exports.xmlReplacer = void 0; +exports.xmlReplacer = /["&'<>$\x80-\uFFFF]/g; +var xmlCodeMap = new Map([ + [34, """], + [38, "&"], + [39, "'"], + [60, "<"], + [62, ">"], +]); +// For compatibility with node < 4, we wrap `codePointAt` +exports.getCodePoint = +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition +String.prototype.codePointAt != null + ? function (str, index) { return str.codePointAt(index); } + : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + function (c, index) { + return (c.charCodeAt(index) & 0xfc00) === 0xd800 + ? (c.charCodeAt(index) - 0xd800) * 0x400 + + c.charCodeAt(index + 1) - + 0xdc00 + + 0x10000 + : c.charCodeAt(index); + }; +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using XML entities. + * + * If a character has no equivalent entity, a + * numeric hexadecimal reference (eg. `ü`) will be used. + */ +function encodeXML(str) { + var ret = ""; + var lastIdx = 0; + var match; + while ((match = exports.xmlReplacer.exec(str)) !== null) { + var i = match.index; + var char = str.charCodeAt(i); + var next = xmlCodeMap.get(char); + if (next !== undefined) { + ret += str.substring(lastIdx, i) + next; + lastIdx = i + 1; + } + else { + ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";"); + // Increase by 1 if we have a surrogate pair + lastIdx = exports.xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800); + } + } + return ret + str.substr(lastIdx); +} +exports.encodeXML = encodeXML; +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using numeric hexadecimal reference (eg. `ü`). + * + * Have a look at `escapeUTF8` if you want a more concise output at the expense + * of reduced transportability. + * + * @param data String to escape. + */ +exports.escape = encodeXML; +/** + * Creates a function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + * + * @param regex Regular expression to match characters to escape. + * @param map Map of characters to escape to their entities. + * + * @returns Function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + */ +function getEscaper(regex, map) { + return function escape(data) { + var match; + var lastIdx = 0; + var result = ""; + while ((match = regex.exec(data))) { + if (lastIdx !== match.index) { + result += data.substring(lastIdx, match.index); + } + // We know that this character will be in the map. + result += map.get(match[0].charCodeAt(0)); + // Every match will be of length 1 + lastIdx = match.index + 1; + } + return result + data.substring(lastIdx); + }; +} +/** + * Encodes all characters not valid in XML documents using XML entities. + * + * Note that the output will be character-set dependent. + * + * @param data String to escape. + */ +exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap); +/** + * Encodes all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([ + [34, """], + [38, "&"], + [160, " "], +])); +/** + * Encodes all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([ + [38, "&"], + [60, "<"], + [62, ">"], + [160, " "], +])); + +}); +define("entities/decode_codepoint",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 +var _a; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.replaceCodePoint = exports.fromCodePoint = void 0; +var decodeMap = new Map([ + [0, 65533], + // C1 Unicode control character reference replacements + [128, 8364], + [130, 8218], + [131, 402], + [132, 8222], + [133, 8230], + [134, 8224], + [135, 8225], + [136, 710], + [137, 8240], + [138, 352], + [139, 8249], + [140, 338], + [142, 381], + [145, 8216], + [146, 8217], + [147, 8220], + [148, 8221], + [149, 8226], + [150, 8211], + [151, 8212], + [152, 732], + [153, 8482], + [154, 353], + [155, 8250], + [156, 339], + [158, 382], + [159, 376], +]); +/** + * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point. + */ +exports.fromCodePoint = +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins +(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) { + var output = ""; + if (codePoint > 0xffff) { + codePoint -= 0x10000; + output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800); + codePoint = 0xdc00 | (codePoint & 0x3ff); + } + output += String.fromCharCode(codePoint); + return output; +}; +/** + * Replace the given code point with a replacement character if it is a + * surrogate or is outside the valid range. Otherwise return the code + * point unchanged. + */ +function replaceCodePoint(codePoint) { + var _a; + if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) { + return 0xfffd; + } + return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint; +} +exports.replaceCodePoint = replaceCodePoint; +/** + * Replace the code point if relevant, then convert it to a string. + * + * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead. + * @param codePoint The code point to decode. + * @returns The decoded code point. + */ +function decodeCodePoint(codePoint) { + return (0, exports.fromCodePoint)(replaceCodePoint(codePoint)); +} +exports.default = decodeCodePoint; + +}); +define("entities/generated/decode-data-html",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-decode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = new Uint16Array( +// prettier-ignore +"\u1d41<\xd5\u0131\u028a\u049d\u057b\u05d0\u0675\u06de\u07a2\u07d6\u080f\u0a4a\u0a91\u0da1\u0e6d\u0f09\u0f26\u10ca\u1228\u12e1\u1415\u149d\u14c3\u14df\u1525\0\0\0\0\0\0\u156b\u16cd\u198d\u1c12\u1ddd\u1f7e\u2060\u21b0\u228d\u23c0\u23fb\u2442\u2824\u2912\u2d08\u2e48\u2fce\u3016\u32ba\u3639\u37ac\u38fe\u3a28\u3a71\u3ae0\u3b2e\u0800EMabcfglmnoprstu\\bfms\x7f\x84\x8b\x90\x95\x98\xa6\xb3\xb9\xc8\xcflig\u803b\xc6\u40c6P\u803b&\u4026cute\u803b\xc1\u40c1reve;\u4102\u0100iyx}rc\u803b\xc2\u40c2;\u4410r;\uc000\ud835\udd04rave\u803b\xc0\u40c0pha;\u4391acr;\u4100d;\u6a53\u0100gp\x9d\xa1on;\u4104f;\uc000\ud835\udd38plyFunction;\u6061ing\u803b\xc5\u40c5\u0100cs\xbe\xc3r;\uc000\ud835\udc9cign;\u6254ilde\u803b\xc3\u40c3ml\u803b\xc4\u40c4\u0400aceforsu\xe5\xfb\xfe\u0117\u011c\u0122\u0127\u012a\u0100cr\xea\xf2kslash;\u6216\u0176\xf6\xf8;\u6ae7ed;\u6306y;\u4411\u0180crt\u0105\u010b\u0114ause;\u6235noullis;\u612ca;\u4392r;\uc000\ud835\udd05pf;\uc000\ud835\udd39eve;\u42d8c\xf2\u0113mpeq;\u624e\u0700HOacdefhilorsu\u014d\u0151\u0156\u0180\u019e\u01a2\u01b5\u01b7\u01ba\u01dc\u0215\u0273\u0278\u027ecy;\u4427PY\u803b\xa9\u40a9\u0180cpy\u015d\u0162\u017aute;\u4106\u0100;i\u0167\u0168\u62d2talDifferentialD;\u6145leys;\u612d\u0200aeio\u0189\u018e\u0194\u0198ron;\u410cdil\u803b\xc7\u40c7rc;\u4108nint;\u6230ot;\u410a\u0100dn\u01a7\u01adilla;\u40b8terDot;\u40b7\xf2\u017fi;\u43a7rcle\u0200DMPT\u01c7\u01cb\u01d1\u01d6ot;\u6299inus;\u6296lus;\u6295imes;\u6297o\u0100cs\u01e2\u01f8kwiseContourIntegral;\u6232eCurly\u0100DQ\u0203\u020foubleQuote;\u601duote;\u6019\u0200lnpu\u021e\u0228\u0247\u0255on\u0100;e\u0225\u0226\u6237;\u6a74\u0180git\u022f\u0236\u023aruent;\u6261nt;\u622fourIntegral;\u622e\u0100fr\u024c\u024e;\u6102oduct;\u6210nterClockwiseContourIntegral;\u6233oss;\u6a2fcr;\uc000\ud835\udc9ep\u0100;C\u0284\u0285\u62d3ap;\u624d\u0580DJSZacefios\u02a0\u02ac\u02b0\u02b4\u02b8\u02cb\u02d7\u02e1\u02e6\u0333\u048d\u0100;o\u0179\u02a5trahd;\u6911cy;\u4402cy;\u4405cy;\u440f\u0180grs\u02bf\u02c4\u02c7ger;\u6021r;\u61a1hv;\u6ae4\u0100ay\u02d0\u02d5ron;\u410e;\u4414l\u0100;t\u02dd\u02de\u6207a;\u4394r;\uc000\ud835\udd07\u0100af\u02eb\u0327\u0100cm\u02f0\u0322ritical\u0200ADGT\u0300\u0306\u0316\u031ccute;\u40b4o\u0174\u030b\u030d;\u42d9bleAcute;\u42ddrave;\u4060ilde;\u42dcond;\u62c4ferentialD;\u6146\u0470\u033d\0\0\0\u0342\u0354\0\u0405f;\uc000\ud835\udd3b\u0180;DE\u0348\u0349\u034d\u40a8ot;\u60dcqual;\u6250ble\u0300CDLRUV\u0363\u0372\u0382\u03cf\u03e2\u03f8ontourIntegra\xec\u0239o\u0274\u0379\0\0\u037b\xbb\u0349nArrow;\u61d3\u0100eo\u0387\u03a4ft\u0180ART\u0390\u0396\u03a1rrow;\u61d0ightArrow;\u61d4e\xe5\u02cang\u0100LR\u03ab\u03c4eft\u0100AR\u03b3\u03b9rrow;\u67f8ightArrow;\u67faightArrow;\u67f9ight\u0100AT\u03d8\u03derrow;\u61d2ee;\u62a8p\u0241\u03e9\0\0\u03efrrow;\u61d1ownArrow;\u61d5erticalBar;\u6225n\u0300ABLRTa\u0412\u042a\u0430\u045e\u047f\u037crrow\u0180;BU\u041d\u041e\u0422\u6193ar;\u6913pArrow;\u61f5reve;\u4311eft\u02d2\u043a\0\u0446\0\u0450ightVector;\u6950eeVector;\u695eector\u0100;B\u0459\u045a\u61bdar;\u6956ight\u01d4\u0467\0\u0471eeVector;\u695fector\u0100;B\u047a\u047b\u61c1ar;\u6957ee\u0100;A\u0486\u0487\u62a4rrow;\u61a7\u0100ct\u0492\u0497r;\uc000\ud835\udc9frok;\u4110\u0800NTacdfglmopqstux\u04bd\u04c0\u04c4\u04cb\u04de\u04e2\u04e7\u04ee\u04f5\u0521\u052f\u0536\u0552\u055d\u0560\u0565G;\u414aH\u803b\xd0\u40d0cute\u803b\xc9\u40c9\u0180aiy\u04d2\u04d7\u04dcron;\u411arc\u803b\xca\u40ca;\u442dot;\u4116r;\uc000\ud835\udd08rave\u803b\xc8\u40c8ement;\u6208\u0100ap\u04fa\u04fecr;\u4112ty\u0253\u0506\0\0\u0512mallSquare;\u65fberySmallSquare;\u65ab\u0100gp\u0526\u052aon;\u4118f;\uc000\ud835\udd3csilon;\u4395u\u0100ai\u053c\u0549l\u0100;T\u0542\u0543\u6a75ilde;\u6242librium;\u61cc\u0100ci\u0557\u055ar;\u6130m;\u6a73a;\u4397ml\u803b\xcb\u40cb\u0100ip\u056a\u056fsts;\u6203onentialE;\u6147\u0280cfios\u0585\u0588\u058d\u05b2\u05ccy;\u4424r;\uc000\ud835\udd09lled\u0253\u0597\0\0\u05a3mallSquare;\u65fcerySmallSquare;\u65aa\u0370\u05ba\0\u05bf\0\0\u05c4f;\uc000\ud835\udd3dAll;\u6200riertrf;\u6131c\xf2\u05cb\u0600JTabcdfgorst\u05e8\u05ec\u05ef\u05fa\u0600\u0612\u0616\u061b\u061d\u0623\u066c\u0672cy;\u4403\u803b>\u403emma\u0100;d\u05f7\u05f8\u4393;\u43dcreve;\u411e\u0180eiy\u0607\u060c\u0610dil;\u4122rc;\u411c;\u4413ot;\u4120r;\uc000\ud835\udd0a;\u62d9pf;\uc000\ud835\udd3eeater\u0300EFGLST\u0635\u0644\u064e\u0656\u065b\u0666qual\u0100;L\u063e\u063f\u6265ess;\u62dbullEqual;\u6267reater;\u6aa2ess;\u6277lantEqual;\u6a7eilde;\u6273cr;\uc000\ud835\udca2;\u626b\u0400Aacfiosu\u0685\u068b\u0696\u069b\u069e\u06aa\u06be\u06caRDcy;\u442a\u0100ct\u0690\u0694ek;\u42c7;\u405eirc;\u4124r;\u610clbertSpace;\u610b\u01f0\u06af\0\u06b2f;\u610dizontalLine;\u6500\u0100ct\u06c3\u06c5\xf2\u06a9rok;\u4126mp\u0144\u06d0\u06d8ownHum\xf0\u012fqual;\u624f\u0700EJOacdfgmnostu\u06fa\u06fe\u0703\u0707\u070e\u071a\u071e\u0721\u0728\u0744\u0778\u078b\u078f\u0795cy;\u4415lig;\u4132cy;\u4401cute\u803b\xcd\u40cd\u0100iy\u0713\u0718rc\u803b\xce\u40ce;\u4418ot;\u4130r;\u6111rave\u803b\xcc\u40cc\u0180;ap\u0720\u072f\u073f\u0100cg\u0734\u0737r;\u412ainaryI;\u6148lie\xf3\u03dd\u01f4\u0749\0\u0762\u0100;e\u074d\u074e\u622c\u0100gr\u0753\u0758ral;\u622bsection;\u62c2isible\u0100CT\u076c\u0772omma;\u6063imes;\u6062\u0180gpt\u077f\u0783\u0788on;\u412ef;\uc000\ud835\udd40a;\u4399cr;\u6110ilde;\u4128\u01eb\u079a\0\u079ecy;\u4406l\u803b\xcf\u40cf\u0280cfosu\u07ac\u07b7\u07bc\u07c2\u07d0\u0100iy\u07b1\u07b5rc;\u4134;\u4419r;\uc000\ud835\udd0dpf;\uc000\ud835\udd41\u01e3\u07c7\0\u07ccr;\uc000\ud835\udca5rcy;\u4408kcy;\u4404\u0380HJacfos\u07e4\u07e8\u07ec\u07f1\u07fd\u0802\u0808cy;\u4425cy;\u440cppa;\u439a\u0100ey\u07f6\u07fbdil;\u4136;\u441ar;\uc000\ud835\udd0epf;\uc000\ud835\udd42cr;\uc000\ud835\udca6\u0580JTaceflmost\u0825\u0829\u082c\u0850\u0863\u09b3\u09b8\u09c7\u09cd\u0a37\u0a47cy;\u4409\u803b<\u403c\u0280cmnpr\u0837\u083c\u0841\u0844\u084dute;\u4139bda;\u439bg;\u67ealacetrf;\u6112r;\u619e\u0180aey\u0857\u085c\u0861ron;\u413ddil;\u413b;\u441b\u0100fs\u0868\u0970t\u0500ACDFRTUVar\u087e\u08a9\u08b1\u08e0\u08e6\u08fc\u092f\u095b\u0390\u096a\u0100nr\u0883\u088fgleBracket;\u67e8row\u0180;BR\u0899\u089a\u089e\u6190ar;\u61e4ightArrow;\u61c6eiling;\u6308o\u01f5\u08b7\0\u08c3bleBracket;\u67e6n\u01d4\u08c8\0\u08d2eeVector;\u6961ector\u0100;B\u08db\u08dc\u61c3ar;\u6959loor;\u630aight\u0100AV\u08ef\u08f5rrow;\u6194ector;\u694e\u0100er\u0901\u0917e\u0180;AV\u0909\u090a\u0910\u62a3rrow;\u61a4ector;\u695aiangle\u0180;BE\u0924\u0925\u0929\u62b2ar;\u69cfqual;\u62b4p\u0180DTV\u0937\u0942\u094cownVector;\u6951eeVector;\u6960ector\u0100;B\u0956\u0957\u61bfar;\u6958ector\u0100;B\u0965\u0966\u61bcar;\u6952ight\xe1\u039cs\u0300EFGLST\u097e\u098b\u0995\u099d\u09a2\u09adqualGreater;\u62daullEqual;\u6266reater;\u6276ess;\u6aa1lantEqual;\u6a7dilde;\u6272r;\uc000\ud835\udd0f\u0100;e\u09bd\u09be\u62d8ftarrow;\u61daidot;\u413f\u0180npw\u09d4\u0a16\u0a1bg\u0200LRlr\u09de\u09f7\u0a02\u0a10eft\u0100AR\u09e6\u09ecrrow;\u67f5ightArrow;\u67f7ightArrow;\u67f6eft\u0100ar\u03b3\u0a0aight\xe1\u03bfight\xe1\u03caf;\uc000\ud835\udd43er\u0100LR\u0a22\u0a2ceftArrow;\u6199ightArrow;\u6198\u0180cht\u0a3e\u0a40\u0a42\xf2\u084c;\u61b0rok;\u4141;\u626a\u0400acefiosu\u0a5a\u0a5d\u0a60\u0a77\u0a7c\u0a85\u0a8b\u0a8ep;\u6905y;\u441c\u0100dl\u0a65\u0a6fiumSpace;\u605flintrf;\u6133r;\uc000\ud835\udd10nusPlus;\u6213pf;\uc000\ud835\udd44c\xf2\u0a76;\u439c\u0480Jacefostu\u0aa3\u0aa7\u0aad\u0ac0\u0b14\u0b19\u0d91\u0d97\u0d9ecy;\u440acute;\u4143\u0180aey\u0ab4\u0ab9\u0aberon;\u4147dil;\u4145;\u441d\u0180gsw\u0ac7\u0af0\u0b0eative\u0180MTV\u0ad3\u0adf\u0ae8ediumSpace;\u600bhi\u0100cn\u0ae6\u0ad8\xeb\u0ad9eryThi\xee\u0ad9ted\u0100GL\u0af8\u0b06reaterGreate\xf2\u0673essLes\xf3\u0a48Line;\u400ar;\uc000\ud835\udd11\u0200Bnpt\u0b22\u0b28\u0b37\u0b3areak;\u6060BreakingSpace;\u40a0f;\u6115\u0680;CDEGHLNPRSTV\u0b55\u0b56\u0b6a\u0b7c\u0ba1\u0beb\u0c04\u0c5e\u0c84\u0ca6\u0cd8\u0d61\u0d85\u6aec\u0100ou\u0b5b\u0b64ngruent;\u6262pCap;\u626doubleVerticalBar;\u6226\u0180lqx\u0b83\u0b8a\u0b9bement;\u6209ual\u0100;T\u0b92\u0b93\u6260ilde;\uc000\u2242\u0338ists;\u6204reater\u0380;EFGLST\u0bb6\u0bb7\u0bbd\u0bc9\u0bd3\u0bd8\u0be5\u626fqual;\u6271ullEqual;\uc000\u2267\u0338reater;\uc000\u226b\u0338ess;\u6279lantEqual;\uc000\u2a7e\u0338ilde;\u6275ump\u0144\u0bf2\u0bfdownHump;\uc000\u224e\u0338qual;\uc000\u224f\u0338e\u0100fs\u0c0a\u0c27tTriangle\u0180;BE\u0c1a\u0c1b\u0c21\u62eaar;\uc000\u29cf\u0338qual;\u62ecs\u0300;EGLST\u0c35\u0c36\u0c3c\u0c44\u0c4b\u0c58\u626equal;\u6270reater;\u6278ess;\uc000\u226a\u0338lantEqual;\uc000\u2a7d\u0338ilde;\u6274ested\u0100GL\u0c68\u0c79reaterGreater;\uc000\u2aa2\u0338essLess;\uc000\u2aa1\u0338recedes\u0180;ES\u0c92\u0c93\u0c9b\u6280qual;\uc000\u2aaf\u0338lantEqual;\u62e0\u0100ei\u0cab\u0cb9verseElement;\u620cghtTriangle\u0180;BE\u0ccb\u0ccc\u0cd2\u62ebar;\uc000\u29d0\u0338qual;\u62ed\u0100qu\u0cdd\u0d0cuareSu\u0100bp\u0ce8\u0cf9set\u0100;E\u0cf0\u0cf3\uc000\u228f\u0338qual;\u62e2erset\u0100;E\u0d03\u0d06\uc000\u2290\u0338qual;\u62e3\u0180bcp\u0d13\u0d24\u0d4eset\u0100;E\u0d1b\u0d1e\uc000\u2282\u20d2qual;\u6288ceeds\u0200;EST\u0d32\u0d33\u0d3b\u0d46\u6281qual;\uc000\u2ab0\u0338lantEqual;\u62e1ilde;\uc000\u227f\u0338erset\u0100;E\u0d58\u0d5b\uc000\u2283\u20d2qual;\u6289ilde\u0200;EFT\u0d6e\u0d6f\u0d75\u0d7f\u6241qual;\u6244ullEqual;\u6247ilde;\u6249erticalBar;\u6224cr;\uc000\ud835\udca9ilde\u803b\xd1\u40d1;\u439d\u0700Eacdfgmoprstuv\u0dbd\u0dc2\u0dc9\u0dd5\u0ddb\u0de0\u0de7\u0dfc\u0e02\u0e20\u0e22\u0e32\u0e3f\u0e44lig;\u4152cute\u803b\xd3\u40d3\u0100iy\u0dce\u0dd3rc\u803b\xd4\u40d4;\u441eblac;\u4150r;\uc000\ud835\udd12rave\u803b\xd2\u40d2\u0180aei\u0dee\u0df2\u0df6cr;\u414cga;\u43a9cron;\u439fpf;\uc000\ud835\udd46enCurly\u0100DQ\u0e0e\u0e1aoubleQuote;\u601cuote;\u6018;\u6a54\u0100cl\u0e27\u0e2cr;\uc000\ud835\udcaaash\u803b\xd8\u40d8i\u016c\u0e37\u0e3cde\u803b\xd5\u40d5es;\u6a37ml\u803b\xd6\u40d6er\u0100BP\u0e4b\u0e60\u0100ar\u0e50\u0e53r;\u603eac\u0100ek\u0e5a\u0e5c;\u63deet;\u63b4arenthesis;\u63dc\u0480acfhilors\u0e7f\u0e87\u0e8a\u0e8f\u0e92\u0e94\u0e9d\u0eb0\u0efcrtialD;\u6202y;\u441fr;\uc000\ud835\udd13i;\u43a6;\u43a0usMinus;\u40b1\u0100ip\u0ea2\u0eadncareplan\xe5\u069df;\u6119\u0200;eio\u0eb9\u0eba\u0ee0\u0ee4\u6abbcedes\u0200;EST\u0ec8\u0ec9\u0ecf\u0eda\u627aqual;\u6aaflantEqual;\u627cilde;\u627eme;\u6033\u0100dp\u0ee9\u0eeeuct;\u620fortion\u0100;a\u0225\u0ef9l;\u621d\u0100ci\u0f01\u0f06r;\uc000\ud835\udcab;\u43a8\u0200Ufos\u0f11\u0f16\u0f1b\u0f1fOT\u803b\"\u4022r;\uc000\ud835\udd14pf;\u611acr;\uc000\ud835\udcac\u0600BEacefhiorsu\u0f3e\u0f43\u0f47\u0f60\u0f73\u0fa7\u0faa\u0fad\u1096\u10a9\u10b4\u10bearr;\u6910G\u803b\xae\u40ae\u0180cnr\u0f4e\u0f53\u0f56ute;\u4154g;\u67ebr\u0100;t\u0f5c\u0f5d\u61a0l;\u6916\u0180aey\u0f67\u0f6c\u0f71ron;\u4158dil;\u4156;\u4420\u0100;v\u0f78\u0f79\u611cerse\u0100EU\u0f82\u0f99\u0100lq\u0f87\u0f8eement;\u620builibrium;\u61cbpEquilibrium;\u696fr\xbb\u0f79o;\u43a1ght\u0400ACDFTUVa\u0fc1\u0feb\u0ff3\u1022\u1028\u105b\u1087\u03d8\u0100nr\u0fc6\u0fd2gleBracket;\u67e9row\u0180;BL\u0fdc\u0fdd\u0fe1\u6192ar;\u61e5eftArrow;\u61c4eiling;\u6309o\u01f5\u0ff9\0\u1005bleBracket;\u67e7n\u01d4\u100a\0\u1014eeVector;\u695dector\u0100;B\u101d\u101e\u61c2ar;\u6955loor;\u630b\u0100er\u102d\u1043e\u0180;AV\u1035\u1036\u103c\u62a2rrow;\u61a6ector;\u695biangle\u0180;BE\u1050\u1051\u1055\u62b3ar;\u69d0qual;\u62b5p\u0180DTV\u1063\u106e\u1078ownVector;\u694feeVector;\u695cector\u0100;B\u1082\u1083\u61bear;\u6954ector\u0100;B\u1091\u1092\u61c0ar;\u6953\u0100pu\u109b\u109ef;\u611dndImplies;\u6970ightarrow;\u61db\u0100ch\u10b9\u10bcr;\u611b;\u61b1leDelayed;\u69f4\u0680HOacfhimoqstu\u10e4\u10f1\u10f7\u10fd\u1119\u111e\u1151\u1156\u1161\u1167\u11b5\u11bb\u11bf\u0100Cc\u10e9\u10eeHcy;\u4429y;\u4428FTcy;\u442ccute;\u415a\u0280;aeiy\u1108\u1109\u110e\u1113\u1117\u6abcron;\u4160dil;\u415erc;\u415c;\u4421r;\uc000\ud835\udd16ort\u0200DLRU\u112a\u1134\u113e\u1149ownArrow\xbb\u041eeftArrow\xbb\u089aightArrow\xbb\u0fddpArrow;\u6191gma;\u43a3allCircle;\u6218pf;\uc000\ud835\udd4a\u0272\u116d\0\0\u1170t;\u621aare\u0200;ISU\u117b\u117c\u1189\u11af\u65a1ntersection;\u6293u\u0100bp\u118f\u119eset\u0100;E\u1197\u1198\u628fqual;\u6291erset\u0100;E\u11a8\u11a9\u6290qual;\u6292nion;\u6294cr;\uc000\ud835\udcaear;\u62c6\u0200bcmp\u11c8\u11db\u1209\u120b\u0100;s\u11cd\u11ce\u62d0et\u0100;E\u11cd\u11d5qual;\u6286\u0100ch\u11e0\u1205eeds\u0200;EST\u11ed\u11ee\u11f4\u11ff\u627bqual;\u6ab0lantEqual;\u627dilde;\u627fTh\xe1\u0f8c;\u6211\u0180;es\u1212\u1213\u1223\u62d1rset\u0100;E\u121c\u121d\u6283qual;\u6287et\xbb\u1213\u0580HRSacfhiors\u123e\u1244\u1249\u1255\u125e\u1271\u1276\u129f\u12c2\u12c8\u12d1ORN\u803b\xde\u40deADE;\u6122\u0100Hc\u124e\u1252cy;\u440by;\u4426\u0100bu\u125a\u125c;\u4009;\u43a4\u0180aey\u1265\u126a\u126fron;\u4164dil;\u4162;\u4422r;\uc000\ud835\udd17\u0100ei\u127b\u1289\u01f2\u1280\0\u1287efore;\u6234a;\u4398\u0100cn\u128e\u1298kSpace;\uc000\u205f\u200aSpace;\u6009lde\u0200;EFT\u12ab\u12ac\u12b2\u12bc\u623cqual;\u6243ullEqual;\u6245ilde;\u6248pf;\uc000\ud835\udd4bipleDot;\u60db\u0100ct\u12d6\u12dbr;\uc000\ud835\udcafrok;\u4166\u0ae1\u12f7\u130e\u131a\u1326\0\u132c\u1331\0\0\0\0\0\u1338\u133d\u1377\u1385\0\u13ff\u1404\u140a\u1410\u0100cr\u12fb\u1301ute\u803b\xda\u40dar\u0100;o\u1307\u1308\u619fcir;\u6949r\u01e3\u1313\0\u1316y;\u440eve;\u416c\u0100iy\u131e\u1323rc\u803b\xdb\u40db;\u4423blac;\u4170r;\uc000\ud835\udd18rave\u803b\xd9\u40d9acr;\u416a\u0100di\u1341\u1369er\u0100BP\u1348\u135d\u0100ar\u134d\u1350r;\u405fac\u0100ek\u1357\u1359;\u63dfet;\u63b5arenthesis;\u63ddon\u0100;P\u1370\u1371\u62c3lus;\u628e\u0100gp\u137b\u137fon;\u4172f;\uc000\ud835\udd4c\u0400ADETadps\u1395\u13ae\u13b8\u13c4\u03e8\u13d2\u13d7\u13f3rrow\u0180;BD\u1150\u13a0\u13a4ar;\u6912ownArrow;\u61c5ownArrow;\u6195quilibrium;\u696eee\u0100;A\u13cb\u13cc\u62a5rrow;\u61a5own\xe1\u03f3er\u0100LR\u13de\u13e8eftArrow;\u6196ightArrow;\u6197i\u0100;l\u13f9\u13fa\u43d2on;\u43a5ing;\u416ecr;\uc000\ud835\udcb0ilde;\u4168ml\u803b\xdc\u40dc\u0480Dbcdefosv\u1427\u142c\u1430\u1433\u143e\u1485\u148a\u1490\u1496ash;\u62abar;\u6aeby;\u4412ash\u0100;l\u143b\u143c\u62a9;\u6ae6\u0100er\u1443\u1445;\u62c1\u0180bty\u144c\u1450\u147aar;\u6016\u0100;i\u144f\u1455cal\u0200BLST\u1461\u1465\u146a\u1474ar;\u6223ine;\u407ceparator;\u6758ilde;\u6240ThinSpace;\u600ar;\uc000\ud835\udd19pf;\uc000\ud835\udd4dcr;\uc000\ud835\udcb1dash;\u62aa\u0280cefos\u14a7\u14ac\u14b1\u14b6\u14bcirc;\u4174dge;\u62c0r;\uc000\ud835\udd1apf;\uc000\ud835\udd4ecr;\uc000\ud835\udcb2\u0200fios\u14cb\u14d0\u14d2\u14d8r;\uc000\ud835\udd1b;\u439epf;\uc000\ud835\udd4fcr;\uc000\ud835\udcb3\u0480AIUacfosu\u14f1\u14f5\u14f9\u14fd\u1504\u150f\u1514\u151a\u1520cy;\u442fcy;\u4407cy;\u442ecute\u803b\xdd\u40dd\u0100iy\u1509\u150drc;\u4176;\u442br;\uc000\ud835\udd1cpf;\uc000\ud835\udd50cr;\uc000\ud835\udcb4ml;\u4178\u0400Hacdefos\u1535\u1539\u153f\u154b\u154f\u155d\u1560\u1564cy;\u4416cute;\u4179\u0100ay\u1544\u1549ron;\u417d;\u4417ot;\u417b\u01f2\u1554\0\u155boWidt\xe8\u0ad9a;\u4396r;\u6128pf;\u6124cr;\uc000\ud835\udcb5\u0be1\u1583\u158a\u1590\0\u15b0\u15b6\u15bf\0\0\0\0\u15c6\u15db\u15eb\u165f\u166d\0\u1695\u169b\u16b2\u16b9\0\u16becute\u803b\xe1\u40e1reve;\u4103\u0300;Ediuy\u159c\u159d\u15a1\u15a3\u15a8\u15ad\u623e;\uc000\u223e\u0333;\u623frc\u803b\xe2\u40e2te\u80bb\xb4\u0306;\u4430lig\u803b\xe6\u40e6\u0100;r\xb2\u15ba;\uc000\ud835\udd1erave\u803b\xe0\u40e0\u0100ep\u15ca\u15d6\u0100fp\u15cf\u15d4sym;\u6135\xe8\u15d3ha;\u43b1\u0100ap\u15dfc\u0100cl\u15e4\u15e7r;\u4101g;\u6a3f\u0264\u15f0\0\0\u160a\u0280;adsv\u15fa\u15fb\u15ff\u1601\u1607\u6227nd;\u6a55;\u6a5clope;\u6a58;\u6a5a\u0380;elmrsz\u1618\u1619\u161b\u161e\u163f\u164f\u1659\u6220;\u69a4e\xbb\u1619sd\u0100;a\u1625\u1626\u6221\u0461\u1630\u1632\u1634\u1636\u1638\u163a\u163c\u163e;\u69a8;\u69a9;\u69aa;\u69ab;\u69ac;\u69ad;\u69ae;\u69aft\u0100;v\u1645\u1646\u621fb\u0100;d\u164c\u164d\u62be;\u699d\u0100pt\u1654\u1657h;\u6222\xbb\xb9arr;\u637c\u0100gp\u1663\u1667on;\u4105f;\uc000\ud835\udd52\u0380;Eaeiop\u12c1\u167b\u167d\u1682\u1684\u1687\u168a;\u6a70cir;\u6a6f;\u624ad;\u624bs;\u4027rox\u0100;e\u12c1\u1692\xf1\u1683ing\u803b\xe5\u40e5\u0180cty\u16a1\u16a6\u16a8r;\uc000\ud835\udcb6;\u402amp\u0100;e\u12c1\u16af\xf1\u0288ilde\u803b\xe3\u40e3ml\u803b\xe4\u40e4\u0100ci\u16c2\u16c8onin\xf4\u0272nt;\u6a11\u0800Nabcdefiklnoprsu\u16ed\u16f1\u1730\u173c\u1743\u1748\u1778\u177d\u17e0\u17e6\u1839\u1850\u170d\u193d\u1948\u1970ot;\u6aed\u0100cr\u16f6\u171ek\u0200ceps\u1700\u1705\u170d\u1713ong;\u624cpsilon;\u43f6rime;\u6035im\u0100;e\u171a\u171b\u623dq;\u62cd\u0176\u1722\u1726ee;\u62bded\u0100;g\u172c\u172d\u6305e\xbb\u172drk\u0100;t\u135c\u1737brk;\u63b6\u0100oy\u1701\u1741;\u4431quo;\u601e\u0280cmprt\u1753\u175b\u1761\u1764\u1768aus\u0100;e\u010a\u0109ptyv;\u69b0s\xe9\u170cno\xf5\u0113\u0180ahw\u176f\u1771\u1773;\u43b2;\u6136een;\u626cr;\uc000\ud835\udd1fg\u0380costuvw\u178d\u179d\u17b3\u17c1\u17d5\u17db\u17de\u0180aiu\u1794\u1796\u179a\xf0\u0760rc;\u65efp\xbb\u1371\u0180dpt\u17a4\u17a8\u17adot;\u6a00lus;\u6a01imes;\u6a02\u0271\u17b9\0\0\u17becup;\u6a06ar;\u6605riangle\u0100du\u17cd\u17d2own;\u65bdp;\u65b3plus;\u6a04e\xe5\u1444\xe5\u14adarow;\u690d\u0180ako\u17ed\u1826\u1835\u0100cn\u17f2\u1823k\u0180lst\u17fa\u05ab\u1802ozenge;\u69ebriangle\u0200;dlr\u1812\u1813\u1818\u181d\u65b4own;\u65beeft;\u65c2ight;\u65b8k;\u6423\u01b1\u182b\0\u1833\u01b2\u182f\0\u1831;\u6592;\u65914;\u6593ck;\u6588\u0100eo\u183e\u184d\u0100;q\u1843\u1846\uc000=\u20e5uiv;\uc000\u2261\u20e5t;\u6310\u0200ptwx\u1859\u185e\u1867\u186cf;\uc000\ud835\udd53\u0100;t\u13cb\u1863om\xbb\u13cctie;\u62c8\u0600DHUVbdhmptuv\u1885\u1896\u18aa\u18bb\u18d7\u18db\u18ec\u18ff\u1905\u190a\u1910\u1921\u0200LRlr\u188e\u1890\u1892\u1894;\u6557;\u6554;\u6556;\u6553\u0280;DUdu\u18a1\u18a2\u18a4\u18a6\u18a8\u6550;\u6566;\u6569;\u6564;\u6567\u0200LRlr\u18b3\u18b5\u18b7\u18b9;\u655d;\u655a;\u655c;\u6559\u0380;HLRhlr\u18ca\u18cb\u18cd\u18cf\u18d1\u18d3\u18d5\u6551;\u656c;\u6563;\u6560;\u656b;\u6562;\u655fox;\u69c9\u0200LRlr\u18e4\u18e6\u18e8\u18ea;\u6555;\u6552;\u6510;\u650c\u0280;DUdu\u06bd\u18f7\u18f9\u18fb\u18fd;\u6565;\u6568;\u652c;\u6534inus;\u629flus;\u629eimes;\u62a0\u0200LRlr\u1919\u191b\u191d\u191f;\u655b;\u6558;\u6518;\u6514\u0380;HLRhlr\u1930\u1931\u1933\u1935\u1937\u1939\u193b\u6502;\u656a;\u6561;\u655e;\u653c;\u6524;\u651c\u0100ev\u0123\u1942bar\u803b\xa6\u40a6\u0200ceio\u1951\u1956\u195a\u1960r;\uc000\ud835\udcb7mi;\u604fm\u0100;e\u171a\u171cl\u0180;bh\u1968\u1969\u196b\u405c;\u69c5sub;\u67c8\u016c\u1974\u197el\u0100;e\u1979\u197a\u6022t\xbb\u197ap\u0180;Ee\u012f\u1985\u1987;\u6aae\u0100;q\u06dc\u06db\u0ce1\u19a7\0\u19e8\u1a11\u1a15\u1a32\0\u1a37\u1a50\0\0\u1ab4\0\0\u1ac1\0\0\u1b21\u1b2e\u1b4d\u1b52\0\u1bfd\0\u1c0c\u0180cpr\u19ad\u19b2\u19ddute;\u4107\u0300;abcds\u19bf\u19c0\u19c4\u19ca\u19d5\u19d9\u6229nd;\u6a44rcup;\u6a49\u0100au\u19cf\u19d2p;\u6a4bp;\u6a47ot;\u6a40;\uc000\u2229\ufe00\u0100eo\u19e2\u19e5t;\u6041\xee\u0693\u0200aeiu\u19f0\u19fb\u1a01\u1a05\u01f0\u19f5\0\u19f8s;\u6a4don;\u410ddil\u803b\xe7\u40e7rc;\u4109ps\u0100;s\u1a0c\u1a0d\u6a4cm;\u6a50ot;\u410b\u0180dmn\u1a1b\u1a20\u1a26il\u80bb\xb8\u01adptyv;\u69b2t\u8100\xa2;e\u1a2d\u1a2e\u40a2r\xe4\u01b2r;\uc000\ud835\udd20\u0180cei\u1a3d\u1a40\u1a4dy;\u4447ck\u0100;m\u1a47\u1a48\u6713ark\xbb\u1a48;\u43c7r\u0380;Ecefms\u1a5f\u1a60\u1a62\u1a6b\u1aa4\u1aaa\u1aae\u65cb;\u69c3\u0180;el\u1a69\u1a6a\u1a6d\u42c6q;\u6257e\u0261\u1a74\0\0\u1a88rrow\u0100lr\u1a7c\u1a81eft;\u61baight;\u61bb\u0280RSacd\u1a92\u1a94\u1a96\u1a9a\u1a9f\xbb\u0f47;\u64c8st;\u629birc;\u629aash;\u629dnint;\u6a10id;\u6aefcir;\u69c2ubs\u0100;u\u1abb\u1abc\u6663it\xbb\u1abc\u02ec\u1ac7\u1ad4\u1afa\0\u1b0aon\u0100;e\u1acd\u1ace\u403a\u0100;q\xc7\xc6\u026d\u1ad9\0\0\u1ae2a\u0100;t\u1ade\u1adf\u402c;\u4040\u0180;fl\u1ae8\u1ae9\u1aeb\u6201\xee\u1160e\u0100mx\u1af1\u1af6ent\xbb\u1ae9e\xf3\u024d\u01e7\u1afe\0\u1b07\u0100;d\u12bb\u1b02ot;\u6a6dn\xf4\u0246\u0180fry\u1b10\u1b14\u1b17;\uc000\ud835\udd54o\xe4\u0254\u8100\xa9;s\u0155\u1b1dr;\u6117\u0100ao\u1b25\u1b29rr;\u61b5ss;\u6717\u0100cu\u1b32\u1b37r;\uc000\ud835\udcb8\u0100bp\u1b3c\u1b44\u0100;e\u1b41\u1b42\u6acf;\u6ad1\u0100;e\u1b49\u1b4a\u6ad0;\u6ad2dot;\u62ef\u0380delprvw\u1b60\u1b6c\u1b77\u1b82\u1bac\u1bd4\u1bf9arr\u0100lr\u1b68\u1b6a;\u6938;\u6935\u0270\u1b72\0\0\u1b75r;\u62dec;\u62dfarr\u0100;p\u1b7f\u1b80\u61b6;\u693d\u0300;bcdos\u1b8f\u1b90\u1b96\u1ba1\u1ba5\u1ba8\u622arcap;\u6a48\u0100au\u1b9b\u1b9ep;\u6a46p;\u6a4aot;\u628dr;\u6a45;\uc000\u222a\ufe00\u0200alrv\u1bb5\u1bbf\u1bde\u1be3rr\u0100;m\u1bbc\u1bbd\u61b7;\u693cy\u0180evw\u1bc7\u1bd4\u1bd8q\u0270\u1bce\0\0\u1bd2re\xe3\u1b73u\xe3\u1b75ee;\u62ceedge;\u62cfen\u803b\xa4\u40a4earrow\u0100lr\u1bee\u1bf3eft\xbb\u1b80ight\xbb\u1bbde\xe4\u1bdd\u0100ci\u1c01\u1c07onin\xf4\u01f7nt;\u6231lcty;\u632d\u0980AHabcdefhijlorstuwz\u1c38\u1c3b\u1c3f\u1c5d\u1c69\u1c75\u1c8a\u1c9e\u1cac\u1cb7\u1cfb\u1cff\u1d0d\u1d7b\u1d91\u1dab\u1dbb\u1dc6\u1dcdr\xf2\u0381ar;\u6965\u0200glrs\u1c48\u1c4d\u1c52\u1c54ger;\u6020eth;\u6138\xf2\u1133h\u0100;v\u1c5a\u1c5b\u6010\xbb\u090a\u016b\u1c61\u1c67arow;\u690fa\xe3\u0315\u0100ay\u1c6e\u1c73ron;\u410f;\u4434\u0180;ao\u0332\u1c7c\u1c84\u0100gr\u02bf\u1c81r;\u61catseq;\u6a77\u0180glm\u1c91\u1c94\u1c98\u803b\xb0\u40b0ta;\u43b4ptyv;\u69b1\u0100ir\u1ca3\u1ca8sht;\u697f;\uc000\ud835\udd21ar\u0100lr\u1cb3\u1cb5\xbb\u08dc\xbb\u101e\u0280aegsv\u1cc2\u0378\u1cd6\u1cdc\u1ce0m\u0180;os\u0326\u1cca\u1cd4nd\u0100;s\u0326\u1cd1uit;\u6666amma;\u43ddin;\u62f2\u0180;io\u1ce7\u1ce8\u1cf8\u40f7de\u8100\xf7;o\u1ce7\u1cf0ntimes;\u62c7n\xf8\u1cf7cy;\u4452c\u026f\u1d06\0\0\u1d0arn;\u631eop;\u630d\u0280lptuw\u1d18\u1d1d\u1d22\u1d49\u1d55lar;\u4024f;\uc000\ud835\udd55\u0280;emps\u030b\u1d2d\u1d37\u1d3d\u1d42q\u0100;d\u0352\u1d33ot;\u6251inus;\u6238lus;\u6214quare;\u62a1blebarwedg\xe5\xfan\u0180adh\u112e\u1d5d\u1d67ownarrow\xf3\u1c83arpoon\u0100lr\u1d72\u1d76ef\xf4\u1cb4igh\xf4\u1cb6\u0162\u1d7f\u1d85karo\xf7\u0f42\u026f\u1d8a\0\0\u1d8ern;\u631fop;\u630c\u0180cot\u1d98\u1da3\u1da6\u0100ry\u1d9d\u1da1;\uc000\ud835\udcb9;\u4455l;\u69f6rok;\u4111\u0100dr\u1db0\u1db4ot;\u62f1i\u0100;f\u1dba\u1816\u65bf\u0100ah\u1dc0\u1dc3r\xf2\u0429a\xf2\u0fa6angle;\u69a6\u0100ci\u1dd2\u1dd5y;\u445fgrarr;\u67ff\u0900Dacdefglmnopqrstux\u1e01\u1e09\u1e19\u1e38\u0578\u1e3c\u1e49\u1e61\u1e7e\u1ea5\u1eaf\u1ebd\u1ee1\u1f2a\u1f37\u1f44\u1f4e\u1f5a\u0100Do\u1e06\u1d34o\xf4\u1c89\u0100cs\u1e0e\u1e14ute\u803b\xe9\u40e9ter;\u6a6e\u0200aioy\u1e22\u1e27\u1e31\u1e36ron;\u411br\u0100;c\u1e2d\u1e2e\u6256\u803b\xea\u40ealon;\u6255;\u444dot;\u4117\u0100Dr\u1e41\u1e45ot;\u6252;\uc000\ud835\udd22\u0180;rs\u1e50\u1e51\u1e57\u6a9aave\u803b\xe8\u40e8\u0100;d\u1e5c\u1e5d\u6a96ot;\u6a98\u0200;ils\u1e6a\u1e6b\u1e72\u1e74\u6a99nters;\u63e7;\u6113\u0100;d\u1e79\u1e7a\u6a95ot;\u6a97\u0180aps\u1e85\u1e89\u1e97cr;\u4113ty\u0180;sv\u1e92\u1e93\u1e95\u6205et\xbb\u1e93p\u01001;\u1e9d\u1ea4\u0133\u1ea1\u1ea3;\u6004;\u6005\u6003\u0100gs\u1eaa\u1eac;\u414bp;\u6002\u0100gp\u1eb4\u1eb8on;\u4119f;\uc000\ud835\udd56\u0180als\u1ec4\u1ece\u1ed2r\u0100;s\u1eca\u1ecb\u62d5l;\u69e3us;\u6a71i\u0180;lv\u1eda\u1edb\u1edf\u43b5on\xbb\u1edb;\u43f5\u0200csuv\u1eea\u1ef3\u1f0b\u1f23\u0100io\u1eef\u1e31rc\xbb\u1e2e\u0269\u1ef9\0\0\u1efb\xed\u0548ant\u0100gl\u1f02\u1f06tr\xbb\u1e5dess\xbb\u1e7a\u0180aei\u1f12\u1f16\u1f1als;\u403dst;\u625fv\u0100;D\u0235\u1f20D;\u6a78parsl;\u69e5\u0100Da\u1f2f\u1f33ot;\u6253rr;\u6971\u0180cdi\u1f3e\u1f41\u1ef8r;\u612fo\xf4\u0352\u0100ah\u1f49\u1f4b;\u43b7\u803b\xf0\u40f0\u0100mr\u1f53\u1f57l\u803b\xeb\u40ebo;\u60ac\u0180cip\u1f61\u1f64\u1f67l;\u4021s\xf4\u056e\u0100eo\u1f6c\u1f74ctatio\xee\u0559nential\xe5\u0579\u09e1\u1f92\0\u1f9e\0\u1fa1\u1fa7\0\0\u1fc6\u1fcc\0\u1fd3\0\u1fe6\u1fea\u2000\0\u2008\u205allingdotse\xf1\u1e44y;\u4444male;\u6640\u0180ilr\u1fad\u1fb3\u1fc1lig;\u8000\ufb03\u0269\u1fb9\0\0\u1fbdg;\u8000\ufb00ig;\u8000\ufb04;\uc000\ud835\udd23lig;\u8000\ufb01lig;\uc000fj\u0180alt\u1fd9\u1fdc\u1fe1t;\u666dig;\u8000\ufb02ns;\u65b1of;\u4192\u01f0\u1fee\0\u1ff3f;\uc000\ud835\udd57\u0100ak\u05bf\u1ff7\u0100;v\u1ffc\u1ffd\u62d4;\u6ad9artint;\u6a0d\u0100ao\u200c\u2055\u0100cs\u2011\u2052\u03b1\u201a\u2030\u2038\u2045\u2048\0\u2050\u03b2\u2022\u2025\u2027\u202a\u202c\0\u202e\u803b\xbd\u40bd;\u6153\u803b\xbc\u40bc;\u6155;\u6159;\u615b\u01b3\u2034\0\u2036;\u6154;\u6156\u02b4\u203e\u2041\0\0\u2043\u803b\xbe\u40be;\u6157;\u615c5;\u6158\u01b6\u204c\0\u204e;\u615a;\u615d8;\u615el;\u6044wn;\u6322cr;\uc000\ud835\udcbb\u0880Eabcdefgijlnorstv\u2082\u2089\u209f\u20a5\u20b0\u20b4\u20f0\u20f5\u20fa\u20ff\u2103\u2112\u2138\u0317\u213e\u2152\u219e\u0100;l\u064d\u2087;\u6a8c\u0180cmp\u2090\u2095\u209dute;\u41f5ma\u0100;d\u209c\u1cda\u43b3;\u6a86reve;\u411f\u0100iy\u20aa\u20aerc;\u411d;\u4433ot;\u4121\u0200;lqs\u063e\u0642\u20bd\u20c9\u0180;qs\u063e\u064c\u20c4lan\xf4\u0665\u0200;cdl\u0665\u20d2\u20d5\u20e5c;\u6aa9ot\u0100;o\u20dc\u20dd\u6a80\u0100;l\u20e2\u20e3\u6a82;\u6a84\u0100;e\u20ea\u20ed\uc000\u22db\ufe00s;\u6a94r;\uc000\ud835\udd24\u0100;g\u0673\u061bmel;\u6137cy;\u4453\u0200;Eaj\u065a\u210c\u210e\u2110;\u6a92;\u6aa5;\u6aa4\u0200Eaes\u211b\u211d\u2129\u2134;\u6269p\u0100;p\u2123\u2124\u6a8arox\xbb\u2124\u0100;q\u212e\u212f\u6a88\u0100;q\u212e\u211bim;\u62e7pf;\uc000\ud835\udd58\u0100ci\u2143\u2146r;\u610am\u0180;el\u066b\u214e\u2150;\u6a8e;\u6a90\u8300>;cdlqr\u05ee\u2160\u216a\u216e\u2173\u2179\u0100ci\u2165\u2167;\u6aa7r;\u6a7aot;\u62d7Par;\u6995uest;\u6a7c\u0280adels\u2184\u216a\u2190\u0656\u219b\u01f0\u2189\0\u218epro\xf8\u209er;\u6978q\u0100lq\u063f\u2196les\xf3\u2088i\xed\u066b\u0100en\u21a3\u21adrtneqq;\uc000\u2269\ufe00\xc5\u21aa\u0500Aabcefkosy\u21c4\u21c7\u21f1\u21f5\u21fa\u2218\u221d\u222f\u2268\u227dr\xf2\u03a0\u0200ilmr\u21d0\u21d4\u21d7\u21dbrs\xf0\u1484f\xbb\u2024il\xf4\u06a9\u0100dr\u21e0\u21e4cy;\u444a\u0180;cw\u08f4\u21eb\u21efir;\u6948;\u61adar;\u610firc;\u4125\u0180alr\u2201\u220e\u2213rts\u0100;u\u2209\u220a\u6665it\xbb\u220alip;\u6026con;\u62b9r;\uc000\ud835\udd25s\u0100ew\u2223\u2229arow;\u6925arow;\u6926\u0280amopr\u223a\u223e\u2243\u225e\u2263rr;\u61fftht;\u623bk\u0100lr\u2249\u2253eftarrow;\u61a9ightarrow;\u61aaf;\uc000\ud835\udd59bar;\u6015\u0180clt\u226f\u2274\u2278r;\uc000\ud835\udcbdas\xe8\u21f4rok;\u4127\u0100bp\u2282\u2287ull;\u6043hen\xbb\u1c5b\u0ae1\u22a3\0\u22aa\0\u22b8\u22c5\u22ce\0\u22d5\u22f3\0\0\u22f8\u2322\u2367\u2362\u237f\0\u2386\u23aa\u23b4cute\u803b\xed\u40ed\u0180;iy\u0771\u22b0\u22b5rc\u803b\xee\u40ee;\u4438\u0100cx\u22bc\u22bfy;\u4435cl\u803b\xa1\u40a1\u0100fr\u039f\u22c9;\uc000\ud835\udd26rave\u803b\xec\u40ec\u0200;ino\u073e\u22dd\u22e9\u22ee\u0100in\u22e2\u22e6nt;\u6a0ct;\u622dfin;\u69dcta;\u6129lig;\u4133\u0180aop\u22fe\u231a\u231d\u0180cgt\u2305\u2308\u2317r;\u412b\u0180elp\u071f\u230f\u2313in\xe5\u078ear\xf4\u0720h;\u4131f;\u62b7ed;\u41b5\u0280;cfot\u04f4\u232c\u2331\u233d\u2341are;\u6105in\u0100;t\u2338\u2339\u621eie;\u69dddo\xf4\u2319\u0280;celp\u0757\u234c\u2350\u235b\u2361al;\u62ba\u0100gr\u2355\u2359er\xf3\u1563\xe3\u234darhk;\u6a17rod;\u6a3c\u0200cgpt\u236f\u2372\u2376\u237by;\u4451on;\u412ff;\uc000\ud835\udd5aa;\u43b9uest\u803b\xbf\u40bf\u0100ci\u238a\u238fr;\uc000\ud835\udcben\u0280;Edsv\u04f4\u239b\u239d\u23a1\u04f3;\u62f9ot;\u62f5\u0100;v\u23a6\u23a7\u62f4;\u62f3\u0100;i\u0777\u23aelde;\u4129\u01eb\u23b8\0\u23bccy;\u4456l\u803b\xef\u40ef\u0300cfmosu\u23cc\u23d7\u23dc\u23e1\u23e7\u23f5\u0100iy\u23d1\u23d5rc;\u4135;\u4439r;\uc000\ud835\udd27ath;\u4237pf;\uc000\ud835\udd5b\u01e3\u23ec\0\u23f1r;\uc000\ud835\udcbfrcy;\u4458kcy;\u4454\u0400acfghjos\u240b\u2416\u2422\u2427\u242d\u2431\u2435\u243bppa\u0100;v\u2413\u2414\u43ba;\u43f0\u0100ey\u241b\u2420dil;\u4137;\u443ar;\uc000\ud835\udd28reen;\u4138cy;\u4445cy;\u445cpf;\uc000\ud835\udd5ccr;\uc000\ud835\udcc0\u0b80ABEHabcdefghjlmnoprstuv\u2470\u2481\u2486\u248d\u2491\u250e\u253d\u255a\u2580\u264e\u265e\u2665\u2679\u267d\u269a\u26b2\u26d8\u275d\u2768\u278b\u27c0\u2801\u2812\u0180art\u2477\u247a\u247cr\xf2\u09c6\xf2\u0395ail;\u691barr;\u690e\u0100;g\u0994\u248b;\u6a8bar;\u6962\u0963\u24a5\0\u24aa\0\u24b1\0\0\0\0\0\u24b5\u24ba\0\u24c6\u24c8\u24cd\0\u24f9ute;\u413amptyv;\u69b4ra\xee\u084cbda;\u43bbg\u0180;dl\u088e\u24c1\u24c3;\u6991\xe5\u088e;\u6a85uo\u803b\xab\u40abr\u0400;bfhlpst\u0899\u24de\u24e6\u24e9\u24eb\u24ee\u24f1\u24f5\u0100;f\u089d\u24e3s;\u691fs;\u691d\xeb\u2252p;\u61abl;\u6939im;\u6973l;\u61a2\u0180;ae\u24ff\u2500\u2504\u6aabil;\u6919\u0100;s\u2509\u250a\u6aad;\uc000\u2aad\ufe00\u0180abr\u2515\u2519\u251drr;\u690crk;\u6772\u0100ak\u2522\u252cc\u0100ek\u2528\u252a;\u407b;\u405b\u0100es\u2531\u2533;\u698bl\u0100du\u2539\u253b;\u698f;\u698d\u0200aeuy\u2546\u254b\u2556\u2558ron;\u413e\u0100di\u2550\u2554il;\u413c\xec\u08b0\xe2\u2529;\u443b\u0200cqrs\u2563\u2566\u256d\u257da;\u6936uo\u0100;r\u0e19\u1746\u0100du\u2572\u2577har;\u6967shar;\u694bh;\u61b2\u0280;fgqs\u258b\u258c\u0989\u25f3\u25ff\u6264t\u0280ahlrt\u2598\u25a4\u25b7\u25c2\u25e8rrow\u0100;t\u0899\u25a1a\xe9\u24f6arpoon\u0100du\u25af\u25b4own\xbb\u045ap\xbb\u0966eftarrows;\u61c7ight\u0180ahs\u25cd\u25d6\u25derrow\u0100;s\u08f4\u08a7arpoon\xf3\u0f98quigarro\xf7\u21f0hreetimes;\u62cb\u0180;qs\u258b\u0993\u25falan\xf4\u09ac\u0280;cdgs\u09ac\u260a\u260d\u261d\u2628c;\u6aa8ot\u0100;o\u2614\u2615\u6a7f\u0100;r\u261a\u261b\u6a81;\u6a83\u0100;e\u2622\u2625\uc000\u22da\ufe00s;\u6a93\u0280adegs\u2633\u2639\u263d\u2649\u264bppro\xf8\u24c6ot;\u62d6q\u0100gq\u2643\u2645\xf4\u0989gt\xf2\u248c\xf4\u099bi\xed\u09b2\u0180ilr\u2655\u08e1\u265asht;\u697c;\uc000\ud835\udd29\u0100;E\u099c\u2663;\u6a91\u0161\u2669\u2676r\u0100du\u25b2\u266e\u0100;l\u0965\u2673;\u696alk;\u6584cy;\u4459\u0280;acht\u0a48\u2688\u268b\u2691\u2696r\xf2\u25c1orne\xf2\u1d08ard;\u696bri;\u65fa\u0100io\u269f\u26a4dot;\u4140ust\u0100;a\u26ac\u26ad\u63b0che\xbb\u26ad\u0200Eaes\u26bb\u26bd\u26c9\u26d4;\u6268p\u0100;p\u26c3\u26c4\u6a89rox\xbb\u26c4\u0100;q\u26ce\u26cf\u6a87\u0100;q\u26ce\u26bbim;\u62e6\u0400abnoptwz\u26e9\u26f4\u26f7\u271a\u272f\u2741\u2747\u2750\u0100nr\u26ee\u26f1g;\u67ecr;\u61fdr\xeb\u08c1g\u0180lmr\u26ff\u270d\u2714eft\u0100ar\u09e6\u2707ight\xe1\u09f2apsto;\u67fcight\xe1\u09fdparrow\u0100lr\u2725\u2729ef\xf4\u24edight;\u61ac\u0180afl\u2736\u2739\u273dr;\u6985;\uc000\ud835\udd5dus;\u6a2dimes;\u6a34\u0161\u274b\u274fst;\u6217\xe1\u134e\u0180;ef\u2757\u2758\u1800\u65cange\xbb\u2758ar\u0100;l\u2764\u2765\u4028t;\u6993\u0280achmt\u2773\u2776\u277c\u2785\u2787r\xf2\u08a8orne\xf2\u1d8car\u0100;d\u0f98\u2783;\u696d;\u600eri;\u62bf\u0300achiqt\u2798\u279d\u0a40\u27a2\u27ae\u27bbquo;\u6039r;\uc000\ud835\udcc1m\u0180;eg\u09b2\u27aa\u27ac;\u6a8d;\u6a8f\u0100bu\u252a\u27b3o\u0100;r\u0e1f\u27b9;\u601arok;\u4142\u8400<;cdhilqr\u082b\u27d2\u2639\u27dc\u27e0\u27e5\u27ea\u27f0\u0100ci\u27d7\u27d9;\u6aa6r;\u6a79re\xe5\u25f2mes;\u62c9arr;\u6976uest;\u6a7b\u0100Pi\u27f5\u27f9ar;\u6996\u0180;ef\u2800\u092d\u181b\u65c3r\u0100du\u2807\u280dshar;\u694ahar;\u6966\u0100en\u2817\u2821rtneqq;\uc000\u2268\ufe00\xc5\u281e\u0700Dacdefhilnopsu\u2840\u2845\u2882\u288e\u2893\u28a0\u28a5\u28a8\u28da\u28e2\u28e4\u0a83\u28f3\u2902Dot;\u623a\u0200clpr\u284e\u2852\u2863\u287dr\u803b\xaf\u40af\u0100et\u2857\u2859;\u6642\u0100;e\u285e\u285f\u6720se\xbb\u285f\u0100;s\u103b\u2868to\u0200;dlu\u103b\u2873\u2877\u287bow\xee\u048cef\xf4\u090f\xf0\u13d1ker;\u65ae\u0100oy\u2887\u288cmma;\u6a29;\u443cash;\u6014asuredangle\xbb\u1626r;\uc000\ud835\udd2ao;\u6127\u0180cdn\u28af\u28b4\u28c9ro\u803b\xb5\u40b5\u0200;acd\u1464\u28bd\u28c0\u28c4s\xf4\u16a7ir;\u6af0ot\u80bb\xb7\u01b5us\u0180;bd\u28d2\u1903\u28d3\u6212\u0100;u\u1d3c\u28d8;\u6a2a\u0163\u28de\u28e1p;\u6adb\xf2\u2212\xf0\u0a81\u0100dp\u28e9\u28eeels;\u62a7f;\uc000\ud835\udd5e\u0100ct\u28f8\u28fdr;\uc000\ud835\udcc2pos\xbb\u159d\u0180;lm\u2909\u290a\u290d\u43bctimap;\u62b8\u0c00GLRVabcdefghijlmoprstuvw\u2942\u2953\u297e\u2989\u2998\u29da\u29e9\u2a15\u2a1a\u2a58\u2a5d\u2a83\u2a95\u2aa4\u2aa8\u2b04\u2b07\u2b44\u2b7f\u2bae\u2c34\u2c67\u2c7c\u2ce9\u0100gt\u2947\u294b;\uc000\u22d9\u0338\u0100;v\u2950\u0bcf\uc000\u226b\u20d2\u0180elt\u295a\u2972\u2976ft\u0100ar\u2961\u2967rrow;\u61cdightarrow;\u61ce;\uc000\u22d8\u0338\u0100;v\u297b\u0c47\uc000\u226a\u20d2ightarrow;\u61cf\u0100Dd\u298e\u2993ash;\u62afash;\u62ae\u0280bcnpt\u29a3\u29a7\u29ac\u29b1\u29ccla\xbb\u02deute;\u4144g;\uc000\u2220\u20d2\u0280;Eiop\u0d84\u29bc\u29c0\u29c5\u29c8;\uc000\u2a70\u0338d;\uc000\u224b\u0338s;\u4149ro\xf8\u0d84ur\u0100;a\u29d3\u29d4\u666el\u0100;s\u29d3\u0b38\u01f3\u29df\0\u29e3p\u80bb\xa0\u0b37mp\u0100;e\u0bf9\u0c00\u0280aeouy\u29f4\u29fe\u2a03\u2a10\u2a13\u01f0\u29f9\0\u29fb;\u6a43on;\u4148dil;\u4146ng\u0100;d\u0d7e\u2a0aot;\uc000\u2a6d\u0338p;\u6a42;\u443dash;\u6013\u0380;Aadqsx\u0b92\u2a29\u2a2d\u2a3b\u2a41\u2a45\u2a50rr;\u61d7r\u0100hr\u2a33\u2a36k;\u6924\u0100;o\u13f2\u13f0ot;\uc000\u2250\u0338ui\xf6\u0b63\u0100ei\u2a4a\u2a4ear;\u6928\xed\u0b98ist\u0100;s\u0ba0\u0b9fr;\uc000\ud835\udd2b\u0200Eest\u0bc5\u2a66\u2a79\u2a7c\u0180;qs\u0bbc\u2a6d\u0be1\u0180;qs\u0bbc\u0bc5\u2a74lan\xf4\u0be2i\xed\u0bea\u0100;r\u0bb6\u2a81\xbb\u0bb7\u0180Aap\u2a8a\u2a8d\u2a91r\xf2\u2971rr;\u61aear;\u6af2\u0180;sv\u0f8d\u2a9c\u0f8c\u0100;d\u2aa1\u2aa2\u62fc;\u62facy;\u445a\u0380AEadest\u2ab7\u2aba\u2abe\u2ac2\u2ac5\u2af6\u2af9r\xf2\u2966;\uc000\u2266\u0338rr;\u619ar;\u6025\u0200;fqs\u0c3b\u2ace\u2ae3\u2aeft\u0100ar\u2ad4\u2ad9rro\xf7\u2ac1ightarro\xf7\u2a90\u0180;qs\u0c3b\u2aba\u2aealan\xf4\u0c55\u0100;s\u0c55\u2af4\xbb\u0c36i\xed\u0c5d\u0100;r\u0c35\u2afei\u0100;e\u0c1a\u0c25i\xe4\u0d90\u0100pt\u2b0c\u2b11f;\uc000\ud835\udd5f\u8180\xac;in\u2b19\u2b1a\u2b36\u40acn\u0200;Edv\u0b89\u2b24\u2b28\u2b2e;\uc000\u22f9\u0338ot;\uc000\u22f5\u0338\u01e1\u0b89\u2b33\u2b35;\u62f7;\u62f6i\u0100;v\u0cb8\u2b3c\u01e1\u0cb8\u2b41\u2b43;\u62fe;\u62fd\u0180aor\u2b4b\u2b63\u2b69r\u0200;ast\u0b7b\u2b55\u2b5a\u2b5flle\xec\u0b7bl;\uc000\u2afd\u20e5;\uc000\u2202\u0338lint;\u6a14\u0180;ce\u0c92\u2b70\u2b73u\xe5\u0ca5\u0100;c\u0c98\u2b78\u0100;e\u0c92\u2b7d\xf1\u0c98\u0200Aait\u2b88\u2b8b\u2b9d\u2ba7r\xf2\u2988rr\u0180;cw\u2b94\u2b95\u2b99\u619b;\uc000\u2933\u0338;\uc000\u219d\u0338ghtarrow\xbb\u2b95ri\u0100;e\u0ccb\u0cd6\u0380chimpqu\u2bbd\u2bcd\u2bd9\u2b04\u0b78\u2be4\u2bef\u0200;cer\u0d32\u2bc6\u0d37\u2bc9u\xe5\u0d45;\uc000\ud835\udcc3ort\u026d\u2b05\0\0\u2bd6ar\xe1\u2b56m\u0100;e\u0d6e\u2bdf\u0100;q\u0d74\u0d73su\u0100bp\u2beb\u2bed\xe5\u0cf8\xe5\u0d0b\u0180bcp\u2bf6\u2c11\u2c19\u0200;Ees\u2bff\u2c00\u0d22\u2c04\u6284;\uc000\u2ac5\u0338et\u0100;e\u0d1b\u2c0bq\u0100;q\u0d23\u2c00c\u0100;e\u0d32\u2c17\xf1\u0d38\u0200;Ees\u2c22\u2c23\u0d5f\u2c27\u6285;\uc000\u2ac6\u0338et\u0100;e\u0d58\u2c2eq\u0100;q\u0d60\u2c23\u0200gilr\u2c3d\u2c3f\u2c45\u2c47\xec\u0bd7lde\u803b\xf1\u40f1\xe7\u0c43iangle\u0100lr\u2c52\u2c5ceft\u0100;e\u0c1a\u2c5a\xf1\u0c26ight\u0100;e\u0ccb\u2c65\xf1\u0cd7\u0100;m\u2c6c\u2c6d\u43bd\u0180;es\u2c74\u2c75\u2c79\u4023ro;\u6116p;\u6007\u0480DHadgilrs\u2c8f\u2c94\u2c99\u2c9e\u2ca3\u2cb0\u2cb6\u2cd3\u2ce3ash;\u62adarr;\u6904p;\uc000\u224d\u20d2ash;\u62ac\u0100et\u2ca8\u2cac;\uc000\u2265\u20d2;\uc000>\u20d2nfin;\u69de\u0180Aet\u2cbd\u2cc1\u2cc5rr;\u6902;\uc000\u2264\u20d2\u0100;r\u2cca\u2ccd\uc000<\u20d2ie;\uc000\u22b4\u20d2\u0100At\u2cd8\u2cdcrr;\u6903rie;\uc000\u22b5\u20d2im;\uc000\u223c\u20d2\u0180Aan\u2cf0\u2cf4\u2d02rr;\u61d6r\u0100hr\u2cfa\u2cfdk;\u6923\u0100;o\u13e7\u13e5ear;\u6927\u1253\u1a95\0\0\0\0\0\0\0\0\0\0\0\0\0\u2d2d\0\u2d38\u2d48\u2d60\u2d65\u2d72\u2d84\u1b07\0\0\u2d8d\u2dab\0\u2dc8\u2dce\0\u2ddc\u2e19\u2e2b\u2e3e\u2e43\u0100cs\u2d31\u1a97ute\u803b\xf3\u40f3\u0100iy\u2d3c\u2d45r\u0100;c\u1a9e\u2d42\u803b\xf4\u40f4;\u443e\u0280abios\u1aa0\u2d52\u2d57\u01c8\u2d5alac;\u4151v;\u6a38old;\u69bclig;\u4153\u0100cr\u2d69\u2d6dir;\u69bf;\uc000\ud835\udd2c\u036f\u2d79\0\0\u2d7c\0\u2d82n;\u42dbave\u803b\xf2\u40f2;\u69c1\u0100bm\u2d88\u0df4ar;\u69b5\u0200acit\u2d95\u2d98\u2da5\u2da8r\xf2\u1a80\u0100ir\u2d9d\u2da0r;\u69beoss;\u69bbn\xe5\u0e52;\u69c0\u0180aei\u2db1\u2db5\u2db9cr;\u414dga;\u43c9\u0180cdn\u2dc0\u2dc5\u01cdron;\u43bf;\u69b6pf;\uc000\ud835\udd60\u0180ael\u2dd4\u2dd7\u01d2r;\u69b7rp;\u69b9\u0380;adiosv\u2dea\u2deb\u2dee\u2e08\u2e0d\u2e10\u2e16\u6228r\xf2\u1a86\u0200;efm\u2df7\u2df8\u2e02\u2e05\u6a5dr\u0100;o\u2dfe\u2dff\u6134f\xbb\u2dff\u803b\xaa\u40aa\u803b\xba\u40bagof;\u62b6r;\u6a56lope;\u6a57;\u6a5b\u0180clo\u2e1f\u2e21\u2e27\xf2\u2e01ash\u803b\xf8\u40f8l;\u6298i\u016c\u2e2f\u2e34de\u803b\xf5\u40f5es\u0100;a\u01db\u2e3as;\u6a36ml\u803b\xf6\u40f6bar;\u633d\u0ae1\u2e5e\0\u2e7d\0\u2e80\u2e9d\0\u2ea2\u2eb9\0\0\u2ecb\u0e9c\0\u2f13\0\0\u2f2b\u2fbc\0\u2fc8r\u0200;ast\u0403\u2e67\u2e72\u0e85\u8100\xb6;l\u2e6d\u2e6e\u40b6le\xec\u0403\u0269\u2e78\0\0\u2e7bm;\u6af3;\u6afdy;\u443fr\u0280cimpt\u2e8b\u2e8f\u2e93\u1865\u2e97nt;\u4025od;\u402eil;\u6030enk;\u6031r;\uc000\ud835\udd2d\u0180imo\u2ea8\u2eb0\u2eb4\u0100;v\u2ead\u2eae\u43c6;\u43d5ma\xf4\u0a76ne;\u660e\u0180;tv\u2ebf\u2ec0\u2ec8\u43c0chfork\xbb\u1ffd;\u43d6\u0100au\u2ecf\u2edfn\u0100ck\u2ed5\u2eddk\u0100;h\u21f4\u2edb;\u610e\xf6\u21f4s\u0480;abcdemst\u2ef3\u2ef4\u1908\u2ef9\u2efd\u2f04\u2f06\u2f0a\u2f0e\u402bcir;\u6a23ir;\u6a22\u0100ou\u1d40\u2f02;\u6a25;\u6a72n\u80bb\xb1\u0e9dim;\u6a26wo;\u6a27\u0180ipu\u2f19\u2f20\u2f25ntint;\u6a15f;\uc000\ud835\udd61nd\u803b\xa3\u40a3\u0500;Eaceinosu\u0ec8\u2f3f\u2f41\u2f44\u2f47\u2f81\u2f89\u2f92\u2f7e\u2fb6;\u6ab3p;\u6ab7u\xe5\u0ed9\u0100;c\u0ece\u2f4c\u0300;acens\u0ec8\u2f59\u2f5f\u2f66\u2f68\u2f7eppro\xf8\u2f43urlye\xf1\u0ed9\xf1\u0ece\u0180aes\u2f6f\u2f76\u2f7approx;\u6ab9qq;\u6ab5im;\u62e8i\xed\u0edfme\u0100;s\u2f88\u0eae\u6032\u0180Eas\u2f78\u2f90\u2f7a\xf0\u2f75\u0180dfp\u0eec\u2f99\u2faf\u0180als\u2fa0\u2fa5\u2faalar;\u632eine;\u6312urf;\u6313\u0100;t\u0efb\u2fb4\xef\u0efbrel;\u62b0\u0100ci\u2fc0\u2fc5r;\uc000\ud835\udcc5;\u43c8ncsp;\u6008\u0300fiopsu\u2fda\u22e2\u2fdf\u2fe5\u2feb\u2ff1r;\uc000\ud835\udd2epf;\uc000\ud835\udd62rime;\u6057cr;\uc000\ud835\udcc6\u0180aeo\u2ff8\u3009\u3013t\u0100ei\u2ffe\u3005rnion\xf3\u06b0nt;\u6a16st\u0100;e\u3010\u3011\u403f\xf1\u1f19\xf4\u0f14\u0a80ABHabcdefhilmnoprstux\u3040\u3051\u3055\u3059\u30e0\u310e\u312b\u3147\u3162\u3172\u318e\u3206\u3215\u3224\u3229\u3258\u326e\u3272\u3290\u32b0\u32b7\u0180art\u3047\u304a\u304cr\xf2\u10b3\xf2\u03ddail;\u691car\xf2\u1c65ar;\u6964\u0380cdenqrt\u3068\u3075\u3078\u307f\u308f\u3094\u30cc\u0100eu\u306d\u3071;\uc000\u223d\u0331te;\u4155i\xe3\u116emptyv;\u69b3g\u0200;del\u0fd1\u3089\u308b\u308d;\u6992;\u69a5\xe5\u0fd1uo\u803b\xbb\u40bbr\u0580;abcfhlpstw\u0fdc\u30ac\u30af\u30b7\u30b9\u30bc\u30be\u30c0\u30c3\u30c7\u30cap;\u6975\u0100;f\u0fe0\u30b4s;\u6920;\u6933s;\u691e\xeb\u225d\xf0\u272el;\u6945im;\u6974l;\u61a3;\u619d\u0100ai\u30d1\u30d5il;\u691ao\u0100;n\u30db\u30dc\u6236al\xf3\u0f1e\u0180abr\u30e7\u30ea\u30eer\xf2\u17e5rk;\u6773\u0100ak\u30f3\u30fdc\u0100ek\u30f9\u30fb;\u407d;\u405d\u0100es\u3102\u3104;\u698cl\u0100du\u310a\u310c;\u698e;\u6990\u0200aeuy\u3117\u311c\u3127\u3129ron;\u4159\u0100di\u3121\u3125il;\u4157\xec\u0ff2\xe2\u30fa;\u4440\u0200clqs\u3134\u3137\u313d\u3144a;\u6937dhar;\u6969uo\u0100;r\u020e\u020dh;\u61b3\u0180acg\u314e\u315f\u0f44l\u0200;ips\u0f78\u3158\u315b\u109cn\xe5\u10bbar\xf4\u0fa9t;\u65ad\u0180ilr\u3169\u1023\u316esht;\u697d;\uc000\ud835\udd2f\u0100ao\u3177\u3186r\u0100du\u317d\u317f\xbb\u047b\u0100;l\u1091\u3184;\u696c\u0100;v\u318b\u318c\u43c1;\u43f1\u0180gns\u3195\u31f9\u31fcht\u0300ahlrst\u31a4\u31b0\u31c2\u31d8\u31e4\u31eerrow\u0100;t\u0fdc\u31ada\xe9\u30c8arpoon\u0100du\u31bb\u31bfow\xee\u317ep\xbb\u1092eft\u0100ah\u31ca\u31d0rrow\xf3\u0feaarpoon\xf3\u0551ightarrows;\u61c9quigarro\xf7\u30cbhreetimes;\u62ccg;\u42daingdotse\xf1\u1f32\u0180ahm\u320d\u3210\u3213r\xf2\u0feaa\xf2\u0551;\u600foust\u0100;a\u321e\u321f\u63b1che\xbb\u321fmid;\u6aee\u0200abpt\u3232\u323d\u3240\u3252\u0100nr\u3237\u323ag;\u67edr;\u61fer\xeb\u1003\u0180afl\u3247\u324a\u324er;\u6986;\uc000\ud835\udd63us;\u6a2eimes;\u6a35\u0100ap\u325d\u3267r\u0100;g\u3263\u3264\u4029t;\u6994olint;\u6a12ar\xf2\u31e3\u0200achq\u327b\u3280\u10bc\u3285quo;\u603ar;\uc000\ud835\udcc7\u0100bu\u30fb\u328ao\u0100;r\u0214\u0213\u0180hir\u3297\u329b\u32a0re\xe5\u31f8mes;\u62cai\u0200;efl\u32aa\u1059\u1821\u32ab\u65b9tri;\u69celuhar;\u6968;\u611e\u0d61\u32d5\u32db\u32df\u332c\u3338\u3371\0\u337a\u33a4\0\0\u33ec\u33f0\0\u3428\u3448\u345a\u34ad\u34b1\u34ca\u34f1\0\u3616\0\0\u3633cute;\u415bqu\xef\u27ba\u0500;Eaceinpsy\u11ed\u32f3\u32f5\u32ff\u3302\u330b\u330f\u331f\u3326\u3329;\u6ab4\u01f0\u32fa\0\u32fc;\u6ab8on;\u4161u\xe5\u11fe\u0100;d\u11f3\u3307il;\u415frc;\u415d\u0180Eas\u3316\u3318\u331b;\u6ab6p;\u6abaim;\u62e9olint;\u6a13i\xed\u1204;\u4441ot\u0180;be\u3334\u1d47\u3335\u62c5;\u6a66\u0380Aacmstx\u3346\u334a\u3357\u335b\u335e\u3363\u336drr;\u61d8r\u0100hr\u3350\u3352\xeb\u2228\u0100;o\u0a36\u0a34t\u803b\xa7\u40a7i;\u403bwar;\u6929m\u0100in\u3369\xf0nu\xf3\xf1t;\u6736r\u0100;o\u3376\u2055\uc000\ud835\udd30\u0200acoy\u3382\u3386\u3391\u33a0rp;\u666f\u0100hy\u338b\u338fcy;\u4449;\u4448rt\u026d\u3399\0\0\u339ci\xe4\u1464ara\xec\u2e6f\u803b\xad\u40ad\u0100gm\u33a8\u33b4ma\u0180;fv\u33b1\u33b2\u33b2\u43c3;\u43c2\u0400;deglnpr\u12ab\u33c5\u33c9\u33ce\u33d6\u33de\u33e1\u33e6ot;\u6a6a\u0100;q\u12b1\u12b0\u0100;E\u33d3\u33d4\u6a9e;\u6aa0\u0100;E\u33db\u33dc\u6a9d;\u6a9fe;\u6246lus;\u6a24arr;\u6972ar\xf2\u113d\u0200aeit\u33f8\u3408\u340f\u3417\u0100ls\u33fd\u3404lsetm\xe9\u336ahp;\u6a33parsl;\u69e4\u0100dl\u1463\u3414e;\u6323\u0100;e\u341c\u341d\u6aaa\u0100;s\u3422\u3423\u6aac;\uc000\u2aac\ufe00\u0180flp\u342e\u3433\u3442tcy;\u444c\u0100;b\u3438\u3439\u402f\u0100;a\u343e\u343f\u69c4r;\u633ff;\uc000\ud835\udd64a\u0100dr\u344d\u0402es\u0100;u\u3454\u3455\u6660it\xbb\u3455\u0180csu\u3460\u3479\u349f\u0100au\u3465\u346fp\u0100;s\u1188\u346b;\uc000\u2293\ufe00p\u0100;s\u11b4\u3475;\uc000\u2294\ufe00u\u0100bp\u347f\u348f\u0180;es\u1197\u119c\u3486et\u0100;e\u1197\u348d\xf1\u119d\u0180;es\u11a8\u11ad\u3496et\u0100;e\u11a8\u349d\xf1\u11ae\u0180;af\u117b\u34a6\u05b0r\u0165\u34ab\u05b1\xbb\u117car\xf2\u1148\u0200cemt\u34b9\u34be\u34c2\u34c5r;\uc000\ud835\udcc8tm\xee\xf1i\xec\u3415ar\xe6\u11be\u0100ar\u34ce\u34d5r\u0100;f\u34d4\u17bf\u6606\u0100an\u34da\u34edight\u0100ep\u34e3\u34eapsilo\xee\u1ee0h\xe9\u2eafs\xbb\u2852\u0280bcmnp\u34fb\u355e\u1209\u358b\u358e\u0480;Edemnprs\u350e\u350f\u3511\u3515\u351e\u3523\u352c\u3531\u3536\u6282;\u6ac5ot;\u6abd\u0100;d\u11da\u351aot;\u6ac3ult;\u6ac1\u0100Ee\u3528\u352a;\u6acb;\u628alus;\u6abfarr;\u6979\u0180eiu\u353d\u3552\u3555t\u0180;en\u350e\u3545\u354bq\u0100;q\u11da\u350feq\u0100;q\u352b\u3528m;\u6ac7\u0100bp\u355a\u355c;\u6ad5;\u6ad3c\u0300;acens\u11ed\u356c\u3572\u3579\u357b\u3326ppro\xf8\u32faurlye\xf1\u11fe\xf1\u11f3\u0180aes\u3582\u3588\u331bppro\xf8\u331aq\xf1\u3317g;\u666a\u0680123;Edehlmnps\u35a9\u35ac\u35af\u121c\u35b2\u35b4\u35c0\u35c9\u35d5\u35da\u35df\u35e8\u35ed\u803b\xb9\u40b9\u803b\xb2\u40b2\u803b\xb3\u40b3;\u6ac6\u0100os\u35b9\u35bct;\u6abeub;\u6ad8\u0100;d\u1222\u35c5ot;\u6ac4s\u0100ou\u35cf\u35d2l;\u67c9b;\u6ad7arr;\u697bult;\u6ac2\u0100Ee\u35e4\u35e6;\u6acc;\u628blus;\u6ac0\u0180eiu\u35f4\u3609\u360ct\u0180;en\u121c\u35fc\u3602q\u0100;q\u1222\u35b2eq\u0100;q\u35e7\u35e4m;\u6ac8\u0100bp\u3611\u3613;\u6ad4;\u6ad6\u0180Aan\u361c\u3620\u362drr;\u61d9r\u0100hr\u3626\u3628\xeb\u222e\u0100;o\u0a2b\u0a29war;\u692alig\u803b\xdf\u40df\u0be1\u3651\u365d\u3660\u12ce\u3673\u3679\0\u367e\u36c2\0\0\0\0\0\u36db\u3703\0\u3709\u376c\0\0\0\u3787\u0272\u3656\0\0\u365bget;\u6316;\u43c4r\xeb\u0e5f\u0180aey\u3666\u366b\u3670ron;\u4165dil;\u4163;\u4442lrec;\u6315r;\uc000\ud835\udd31\u0200eiko\u3686\u369d\u36b5\u36bc\u01f2\u368b\0\u3691e\u01004f\u1284\u1281a\u0180;sv\u3698\u3699\u369b\u43b8ym;\u43d1\u0100cn\u36a2\u36b2k\u0100as\u36a8\u36aeppro\xf8\u12c1im\xbb\u12acs\xf0\u129e\u0100as\u36ba\u36ae\xf0\u12c1rn\u803b\xfe\u40fe\u01ec\u031f\u36c6\u22e7es\u8180\xd7;bd\u36cf\u36d0\u36d8\u40d7\u0100;a\u190f\u36d5r;\u6a31;\u6a30\u0180eps\u36e1\u36e3\u3700\xe1\u2a4d\u0200;bcf\u0486\u36ec\u36f0\u36f4ot;\u6336ir;\u6af1\u0100;o\u36f9\u36fc\uc000\ud835\udd65rk;\u6ada\xe1\u3362rime;\u6034\u0180aip\u370f\u3712\u3764d\xe5\u1248\u0380adempst\u3721\u374d\u3740\u3751\u3757\u375c\u375fngle\u0280;dlqr\u3730\u3731\u3736\u3740\u3742\u65b5own\xbb\u1dbbeft\u0100;e\u2800\u373e\xf1\u092e;\u625cight\u0100;e\u32aa\u374b\xf1\u105aot;\u65ecinus;\u6a3alus;\u6a39b;\u69cdime;\u6a3bezium;\u63e2\u0180cht\u3772\u377d\u3781\u0100ry\u3777\u377b;\uc000\ud835\udcc9;\u4446cy;\u445brok;\u4167\u0100io\u378b\u378ex\xf4\u1777head\u0100lr\u3797\u37a0eftarro\xf7\u084fightarrow\xbb\u0f5d\u0900AHabcdfghlmoprstuw\u37d0\u37d3\u37d7\u37e4\u37f0\u37fc\u380e\u381c\u3823\u3834\u3851\u385d\u386b\u38a9\u38cc\u38d2\u38ea\u38f6r\xf2\u03edar;\u6963\u0100cr\u37dc\u37e2ute\u803b\xfa\u40fa\xf2\u1150r\u01e3\u37ea\0\u37edy;\u445eve;\u416d\u0100iy\u37f5\u37farc\u803b\xfb\u40fb;\u4443\u0180abh\u3803\u3806\u380br\xf2\u13adlac;\u4171a\xf2\u13c3\u0100ir\u3813\u3818sht;\u697e;\uc000\ud835\udd32rave\u803b\xf9\u40f9\u0161\u3827\u3831r\u0100lr\u382c\u382e\xbb\u0957\xbb\u1083lk;\u6580\u0100ct\u3839\u384d\u026f\u383f\0\0\u384arn\u0100;e\u3845\u3846\u631cr\xbb\u3846op;\u630fri;\u65f8\u0100al\u3856\u385acr;\u416b\u80bb\xa8\u0349\u0100gp\u3862\u3866on;\u4173f;\uc000\ud835\udd66\u0300adhlsu\u114b\u3878\u387d\u1372\u3891\u38a0own\xe1\u13b3arpoon\u0100lr\u3888\u388cef\xf4\u382digh\xf4\u382fi\u0180;hl\u3899\u389a\u389c\u43c5\xbb\u13faon\xbb\u389aparrows;\u61c8\u0180cit\u38b0\u38c4\u38c8\u026f\u38b6\0\0\u38c1rn\u0100;e\u38bc\u38bd\u631dr\xbb\u38bdop;\u630eng;\u416fri;\u65f9cr;\uc000\ud835\udcca\u0180dir\u38d9\u38dd\u38e2ot;\u62f0lde;\u4169i\u0100;f\u3730\u38e8\xbb\u1813\u0100am\u38ef\u38f2r\xf2\u38a8l\u803b\xfc\u40fcangle;\u69a7\u0780ABDacdeflnoprsz\u391c\u391f\u3929\u392d\u39b5\u39b8\u39bd\u39df\u39e4\u39e8\u39f3\u39f9\u39fd\u3a01\u3a20r\xf2\u03f7ar\u0100;v\u3926\u3927\u6ae8;\u6ae9as\xe8\u03e1\u0100nr\u3932\u3937grt;\u699c\u0380eknprst\u34e3\u3946\u394b\u3952\u395d\u3964\u3996app\xe1\u2415othin\xe7\u1e96\u0180hir\u34eb\u2ec8\u3959op\xf4\u2fb5\u0100;h\u13b7\u3962\xef\u318d\u0100iu\u3969\u396dgm\xe1\u33b3\u0100bp\u3972\u3984setneq\u0100;q\u397d\u3980\uc000\u228a\ufe00;\uc000\u2acb\ufe00setneq\u0100;q\u398f\u3992\uc000\u228b\ufe00;\uc000\u2acc\ufe00\u0100hr\u399b\u399fet\xe1\u369ciangle\u0100lr\u39aa\u39afeft\xbb\u0925ight\xbb\u1051y;\u4432ash\xbb\u1036\u0180elr\u39c4\u39d2\u39d7\u0180;be\u2dea\u39cb\u39cfar;\u62bbq;\u625alip;\u62ee\u0100bt\u39dc\u1468a\xf2\u1469r;\uc000\ud835\udd33tr\xe9\u39aesu\u0100bp\u39ef\u39f1\xbb\u0d1c\xbb\u0d59pf;\uc000\ud835\udd67ro\xf0\u0efbtr\xe9\u39b4\u0100cu\u3a06\u3a0br;\uc000\ud835\udccb\u0100bp\u3a10\u3a18n\u0100Ee\u3980\u3a16\xbb\u397en\u0100Ee\u3992\u3a1e\xbb\u3990igzag;\u699a\u0380cefoprs\u3a36\u3a3b\u3a56\u3a5b\u3a54\u3a61\u3a6airc;\u4175\u0100di\u3a40\u3a51\u0100bg\u3a45\u3a49ar;\u6a5fe\u0100;q\u15fa\u3a4f;\u6259erp;\u6118r;\uc000\ud835\udd34pf;\uc000\ud835\udd68\u0100;e\u1479\u3a66at\xe8\u1479cr;\uc000\ud835\udccc\u0ae3\u178e\u3a87\0\u3a8b\0\u3a90\u3a9b\0\0\u3a9d\u3aa8\u3aab\u3aaf\0\0\u3ac3\u3ace\0\u3ad8\u17dc\u17dftr\xe9\u17d1r;\uc000\ud835\udd35\u0100Aa\u3a94\u3a97r\xf2\u03c3r\xf2\u09f6;\u43be\u0100Aa\u3aa1\u3aa4r\xf2\u03b8r\xf2\u09eba\xf0\u2713is;\u62fb\u0180dpt\u17a4\u3ab5\u3abe\u0100fl\u3aba\u17a9;\uc000\ud835\udd69im\xe5\u17b2\u0100Aa\u3ac7\u3acar\xf2\u03cer\xf2\u0a01\u0100cq\u3ad2\u17b8r;\uc000\ud835\udccd\u0100pt\u17d6\u3adcr\xe9\u17d4\u0400acefiosu\u3af0\u3afd\u3b08\u3b0c\u3b11\u3b15\u3b1b\u3b21c\u0100uy\u3af6\u3afbte\u803b\xfd\u40fd;\u444f\u0100iy\u3b02\u3b06rc;\u4177;\u444bn\u803b\xa5\u40a5r;\uc000\ud835\udd36cy;\u4457pf;\uc000\ud835\udd6acr;\uc000\ud835\udcce\u0100cm\u3b26\u3b29y;\u444el\u803b\xff\u40ff\u0500acdefhiosw\u3b42\u3b48\u3b54\u3b58\u3b64\u3b69\u3b6d\u3b74\u3b7a\u3b80cute;\u417a\u0100ay\u3b4d\u3b52ron;\u417e;\u4437ot;\u417c\u0100et\u3b5d\u3b61tr\xe6\u155fa;\u43b6r;\uc000\ud835\udd37cy;\u4436grarr;\u61ddpf;\uc000\ud835\udd6bcr;\uc000\ud835\udccf\u0100jn\u3b85\u3b87;\u600dj;\u600c" + .split("") + .map(function (c) { return c.charCodeAt(0); })); + +}); +define("entities/generated/encode-html",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-encode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +function restoreDiff(arr) { + for (var i = 1; i < arr.length; i++) { + arr[i][0] += arr[i - 1][0] + 1; + } + return arr; +} +// prettier-ignore +exports.default = new Map(/* #__PURE__ */ restoreDiff([[9, " "], [0, " "], [22, "!"], [0, """], [0, "#"], [0, "$"], [0, "%"], [0, "&"], [0, "'"], [0, "("], [0, ")"], [0, "*"], [0, "+"], [0, ","], [1, "."], [0, "/"], [10, ":"], [0, ";"], [0, { v: "<", n: 8402, o: "<⃒" }], [0, { v: "=", n: 8421, o: "=⃥" }], [0, { v: ">", n: 8402, o: ">⃒" }], [0, "?"], [0, "@"], [26, "["], [0, "\"], [0, "]"], [0, "^"], [0, "_"], [0, "`"], [5, { n: 106, o: "fj" }], [20, "{"], [0, "|"], [0, "}"], [34, " "], [0, "¡"], [0, "¢"], [0, "£"], [0, "¤"], [0, "¥"], [0, "¦"], [0, "§"], [0, "¨"], [0, "©"], [0, "ª"], [0, "«"], [0, "¬"], [0, "­"], [0, "®"], [0, "¯"], [0, "°"], [0, "±"], [0, "²"], [0, "³"], [0, "´"], [0, "µ"], [0, "¶"], [0, "·"], [0, "¸"], [0, "¹"], [0, "º"], [0, "»"], [0, "¼"], [0, "½"], [0, "¾"], [0, "¿"], [0, "À"], [0, "Á"], [0, "Â"], [0, "Ã"], [0, "Ä"], [0, "Å"], [0, "Æ"], [0, "Ç"], [0, "È"], [0, "É"], [0, "Ê"], [0, "Ë"], [0, "Ì"], [0, "Í"], [0, "Î"], [0, "Ï"], [0, "Ð"], [0, "Ñ"], [0, "Ò"], [0, "Ó"], [0, "Ô"], [0, "Õ"], [0, "Ö"], [0, "×"], [0, "Ø"], [0, "Ù"], [0, "Ú"], [0, "Û"], [0, "Ü"], [0, "Ý"], [0, "Þ"], [0, "ß"], [0, "à"], [0, "á"], [0, "â"], [0, "ã"], [0, "ä"], [0, "å"], [0, "æ"], [0, "ç"], [0, "è"], [0, "é"], [0, "ê"], [0, "ë"], [0, "ì"], [0, "í"], [0, "î"], [0, "ï"], [0, "ð"], [0, "ñ"], [0, "ò"], [0, "ó"], [0, "ô"], [0, "õ"], [0, "ö"], [0, "÷"], [0, "ø"], [0, "ù"], [0, "ú"], [0, "û"], [0, "ü"], [0, "ý"], [0, "þ"], [0, "ÿ"], [0, "Ā"], [0, "ā"], [0, "Ă"], [0, "ă"], [0, "Ą"], [0, "ą"], [0, "Ć"], [0, "ć"], [0, "Ĉ"], [0, "ĉ"], [0, "Ċ"], [0, "ċ"], [0, "Č"], [0, "č"], [0, "Ď"], [0, "ď"], [0, "Đ"], [0, "đ"], [0, "Ē"], [0, "ē"], [2, "Ė"], [0, "ė"], [0, "Ę"], [0, "ę"], [0, "Ě"], [0, "ě"], [0, "Ĝ"], [0, "ĝ"], [0, "Ğ"], [0, "ğ"], [0, "Ġ"], [0, "ġ"], [0, "Ģ"], [1, "Ĥ"], [0, "ĥ"], [0, "Ħ"], [0, "ħ"], [0, "Ĩ"], [0, "ĩ"], [0, "Ī"], [0, "ī"], [2, "Į"], [0, "į"], [0, "İ"], [0, "ı"], [0, "IJ"], [0, "ij"], [0, "Ĵ"], [0, "ĵ"], [0, "Ķ"], [0, "ķ"], [0, "ĸ"], [0, "Ĺ"], [0, "ĺ"], [0, "Ļ"], [0, "ļ"], [0, "Ľ"], [0, "ľ"], [0, "Ŀ"], [0, "ŀ"], [0, "Ł"], [0, "ł"], [0, "Ń"], [0, "ń"], [0, "Ņ"], [0, "ņ"], [0, "Ň"], [0, "ň"], [0, "ʼn"], [0, "Ŋ"], [0, "ŋ"], [0, "Ō"], [0, "ō"], [2, "Ő"], [0, "ő"], [0, "Œ"], [0, "œ"], [0, "Ŕ"], [0, "ŕ"], [0, "Ŗ"], [0, "ŗ"], [0, "Ř"], [0, "ř"], [0, "Ś"], [0, "ś"], [0, "Ŝ"], [0, "ŝ"], [0, "Ş"], [0, "ş"], [0, "Š"], [0, "š"], [0, "Ţ"], [0, "ţ"], [0, "Ť"], [0, "ť"], [0, "Ŧ"], [0, "ŧ"], [0, "Ũ"], [0, "ũ"], [0, "Ū"], [0, "ū"], [0, "Ŭ"], [0, "ŭ"], [0, "Ů"], [0, "ů"], [0, "Ű"], [0, "ű"], [0, "Ų"], [0, "ų"], [0, "Ŵ"], [0, "ŵ"], [0, "Ŷ"], [0, "ŷ"], [0, "Ÿ"], [0, "Ź"], [0, "ź"], [0, "Ż"], [0, "ż"], [0, "Ž"], [0, "ž"], [19, "ƒ"], [34, "Ƶ"], [63, "ǵ"], [65, "ȷ"], [142, "ˆ"], [0, "ˇ"], [16, "˘"], [0, "˙"], [0, "˚"], [0, "˛"], [0, "˜"], [0, "˝"], [51, "̑"], [127, "Α"], [0, "Β"], [0, "Γ"], [0, "Δ"], [0, "Ε"], [0, "Ζ"], [0, "Η"], [0, "Θ"], [0, "Ι"], [0, "Κ"], [0, "Λ"], [0, "Μ"], [0, "Ν"], [0, "Ξ"], [0, "Ο"], [0, "Π"], [0, "Ρ"], [1, "Σ"], [0, "Τ"], [0, "Υ"], [0, "Φ"], [0, "Χ"], [0, "Ψ"], [0, "Ω"], [7, "α"], [0, "β"], [0, "γ"], [0, "δ"], [0, "ε"], [0, "ζ"], [0, "η"], [0, "θ"], [0, "ι"], [0, "κ"], [0, "λ"], [0, "μ"], [0, "ν"], [0, "ξ"], [0, "ο"], [0, "π"], [0, "ρ"], [0, "ς"], [0, "σ"], [0, "τ"], [0, "υ"], [0, "φ"], [0, "χ"], [0, "ψ"], [0, "ω"], [7, "ϑ"], [0, "ϒ"], [2, "ϕ"], [0, "ϖ"], [5, "Ϝ"], [0, "ϝ"], [18, "ϰ"], [0, "ϱ"], [3, "ϵ"], [0, "϶"], [10, "Ё"], [0, "Ђ"], [0, "Ѓ"], [0, "Є"], [0, "Ѕ"], [0, "І"], [0, "Ї"], [0, "Ј"], [0, "Љ"], [0, "Њ"], [0, "Ћ"], [0, "Ќ"], [1, "Ў"], [0, "Џ"], [0, "А"], [0, "Б"], [0, "В"], [0, "Г"], [0, "Д"], [0, "Е"], [0, "Ж"], [0, "З"], [0, "И"], [0, "Й"], [0, "К"], [0, "Л"], [0, "М"], [0, "Н"], [0, "О"], [0, "П"], [0, "Р"], [0, "С"], [0, "Т"], [0, "У"], [0, "Ф"], [0, "Х"], [0, "Ц"], [0, "Ч"], [0, "Ш"], [0, "Щ"], [0, "Ъ"], [0, "Ы"], [0, "Ь"], [0, "Э"], [0, "Ю"], [0, "Я"], [0, "а"], [0, "б"], [0, "в"], [0, "г"], [0, "д"], [0, "е"], [0, "ж"], [0, "з"], [0, "и"], [0, "й"], [0, "к"], [0, "л"], [0, "м"], [0, "н"], [0, "о"], [0, "п"], [0, "р"], [0, "с"], [0, "т"], [0, "у"], [0, "ф"], [0, "х"], [0, "ц"], [0, "ч"], [0, "ш"], [0, "щ"], [0, "ъ"], [0, "ы"], [0, "ь"], [0, "э"], [0, "ю"], [0, "я"], [1, "ё"], [0, "ђ"], [0, "ѓ"], [0, "є"], [0, "ѕ"], [0, "і"], [0, "ї"], [0, "ј"], [0, "љ"], [0, "њ"], [0, "ћ"], [0, "ќ"], [1, "ў"], [0, "џ"], [7074, " "], [0, " "], [0, " "], [0, " "], [1, " "], [0, " "], [0, " "], [0, " "], [0, "​"], [0, "‌"], [0, "‍"], [0, "‎"], [0, "‏"], [0, "‐"], [2, "–"], [0, "—"], [0, "―"], [0, "‖"], [1, "‘"], [0, "’"], [0, "‚"], [1, "“"], [0, "”"], [0, "„"], [1, "†"], [0, "‡"], [0, "•"], [2, "‥"], [0, "…"], [9, "‰"], [0, "‱"], [0, "′"], [0, "″"], [0, "‴"], [0, "‵"], [3, "‹"], [0, "›"], [3, "‾"], [2, "⁁"], [1, "⁃"], [0, "⁄"], [10, "⁏"], [7, "⁗"], [7, { v: " ", n: 8202, o: "  " }], [0, "⁠"], [0, "⁡"], [0, "⁢"], [0, "⁣"], [72, "€"], [46, "⃛"], [0, "⃜"], [37, "ℂ"], [2, "℅"], [4, "ℊ"], [0, "ℋ"], [0, "ℌ"], [0, "ℍ"], [0, "ℎ"], [0, "ℏ"], [0, "ℐ"], [0, "ℑ"], [0, "ℒ"], [0, "ℓ"], [1, "ℕ"], [0, "№"], [0, "℗"], [0, "℘"], [0, "ℙ"], [0, "ℚ"], [0, "ℛ"], [0, "ℜ"], [0, "ℝ"], [0, "℞"], [3, "™"], [1, "ℤ"], [2, "℧"], [0, "ℨ"], [0, "℩"], [2, "ℬ"], [0, "ℭ"], [1, "ℯ"], [0, "ℰ"], [0, "ℱ"], [1, "ℳ"], [0, "ℴ"], [0, "ℵ"], [0, "ℶ"], [0, "ℷ"], [0, "ℸ"], [12, "ⅅ"], [0, "ⅆ"], [0, "ⅇ"], [0, "ⅈ"], [10, "⅓"], [0, "⅔"], [0, "⅕"], [0, "⅖"], [0, "⅗"], [0, "⅘"], [0, "⅙"], [0, "⅚"], [0, "⅛"], [0, "⅜"], [0, "⅝"], [0, "⅞"], [49, "←"], [0, "↑"], [0, "→"], [0, "↓"], [0, "↔"], [0, "↕"], [0, "↖"], [0, "↗"], [0, "↘"], [0, "↙"], [0, "↚"], [0, "↛"], [1, { v: "↝", n: 824, o: "↝̸" }], [0, "↞"], [0, "↟"], [0, "↠"], [0, "↡"], [0, "↢"], [0, "↣"], [0, "↤"], [0, "↥"], [0, "↦"], [0, "↧"], [1, "↩"], [0, "↪"], [0, "↫"], [0, "↬"], [0, "↭"], [0, "↮"], [1, "↰"], [0, "↱"], [0, "↲"], [0, "↳"], [1, "↵"], [0, "↶"], [0, "↷"], [2, "↺"], [0, "↻"], [0, "↼"], [0, "↽"], [0, "↾"], [0, "↿"], [0, "⇀"], [0, "⇁"], [0, "⇂"], [0, "⇃"], [0, "⇄"], [0, "⇅"], [0, "⇆"], [0, "⇇"], [0, "⇈"], [0, "⇉"], [0, "⇊"], [0, "⇋"], [0, "⇌"], [0, "⇍"], [0, "⇎"], [0, "⇏"], [0, "⇐"], [0, "⇑"], [0, "⇒"], [0, "⇓"], [0, "⇔"], [0, "⇕"], [0, "⇖"], [0, "⇗"], [0, "⇘"], [0, "⇙"], [0, "⇚"], [0, "⇛"], [1, "⇝"], [6, "⇤"], [0, "⇥"], [15, "⇵"], [7, "⇽"], [0, "⇾"], [0, "⇿"], [0, "∀"], [0, "∁"], [0, { v: "∂", n: 824, o: "∂̸" }], [0, "∃"], [0, "∄"], [0, "∅"], [1, "∇"], [0, "∈"], [0, "∉"], [1, "∋"], [0, "∌"], [2, "∏"], [0, "∐"], [0, "∑"], [0, "−"], [0, "∓"], [0, "∔"], [1, "∖"], [0, "∗"], [0, "∘"], [1, "√"], [2, "∝"], [0, "∞"], [0, "∟"], [0, { v: "∠", n: 8402, o: "∠⃒" }], [0, "∡"], [0, "∢"], [0, "∣"], [0, "∤"], [0, "∥"], [0, "∦"], [0, "∧"], [0, "∨"], [0, { v: "∩", n: 65024, o: "∩︀" }], [0, { v: "∪", n: 65024, o: "∪︀" }], [0, "∫"], [0, "∬"], [0, "∭"], [0, "∮"], [0, "∯"], [0, "∰"], [0, "∱"], [0, "∲"], [0, "∳"], [0, "∴"], [0, "∵"], [0, "∶"], [0, "∷"], [0, "∸"], [1, "∺"], [0, "∻"], [0, { v: "∼", n: 8402, o: "∼⃒" }], [0, { v: "∽", n: 817, o: "∽̱" }], [0, { v: "∾", n: 819, o: "∾̳" }], [0, "∿"], [0, "≀"], [0, "≁"], [0, { v: "≂", n: 824, o: "≂̸" }], [0, "≃"], [0, "≄"], [0, "≅"], [0, "≆"], [0, "≇"], [0, "≈"], [0, "≉"], [0, "≊"], [0, { v: "≋", n: 824, o: "≋̸" }], [0, "≌"], [0, { v: "≍", n: 8402, o: "≍⃒" }], [0, { v: "≎", n: 824, o: "≎̸" }], [0, { v: "≏", n: 824, o: "≏̸" }], [0, { v: "≐", n: 824, o: "≐̸" }], [0, "≑"], [0, "≒"], [0, "≓"], [0, "≔"], [0, "≕"], [0, "≖"], [0, "≗"], [1, "≙"], [0, "≚"], [1, "≜"], [2, "≟"], [0, "≠"], [0, { v: "≡", n: 8421, o: "≡⃥" }], [0, "≢"], [1, { v: "≤", n: 8402, o: "≤⃒" }], [0, { v: "≥", n: 8402, o: "≥⃒" }], [0, { v: "≦", n: 824, o: "≦̸" }], [0, { v: "≧", n: 824, o: "≧̸" }], [0, { v: "≨", n: 65024, o: "≨︀" }], [0, { v: "≩", n: 65024, o: "≩︀" }], [0, { v: "≪", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≪̸"], [7577, "≪⃒"]])) }], [0, { v: "≫", n: new Map(/* #__PURE__ */ restoreDiff([[824, "≫̸"], [7577, "≫⃒"]])) }], [0, "≬"], [0, "≭"], [0, "≮"], [0, "≯"], [0, "≰"], [0, "≱"], [0, "≲"], [0, "≳"], [0, "≴"], [0, "≵"], [0, "≶"], [0, "≷"], [0, "≸"], [0, "≹"], [0, "≺"], [0, "≻"], [0, "≼"], [0, "≽"], [0, "≾"], [0, { v: "≿", n: 824, o: "≿̸" }], [0, "⊀"], [0, "⊁"], [0, { v: "⊂", n: 8402, o: "⊂⃒" }], [0, { v: "⊃", n: 8402, o: "⊃⃒" }], [0, "⊄"], [0, "⊅"], [0, "⊆"], [0, "⊇"], [0, "⊈"], [0, "⊉"], [0, { v: "⊊", n: 65024, o: "⊊︀" }], [0, { v: "⊋", n: 65024, o: "⊋︀" }], [1, "⊍"], [0, "⊎"], [0, { v: "⊏", n: 824, o: "⊏̸" }], [0, { v: "⊐", n: 824, o: "⊐̸" }], [0, "⊑"], [0, "⊒"], [0, { v: "⊓", n: 65024, o: "⊓︀" }], [0, { v: "⊔", n: 65024, o: "⊔︀" }], [0, "⊕"], [0, "⊖"], [0, "⊗"], [0, "⊘"], [0, "⊙"], [0, "⊚"], [0, "⊛"], [1, "⊝"], [0, "⊞"], [0, "⊟"], [0, "⊠"], [0, "⊡"], [0, "⊢"], [0, "⊣"], [0, "⊤"], [0, "⊥"], [1, "⊧"], [0, "⊨"], [0, "⊩"], [0, "⊪"], [0, "⊫"], [0, "⊬"], [0, "⊭"], [0, "⊮"], [0, "⊯"], [0, "⊰"], [1, "⊲"], [0, "⊳"], [0, { v: "⊴", n: 8402, o: "⊴⃒" }], [0, { v: "⊵", n: 8402, o: "⊵⃒" }], [0, "⊶"], [0, "⊷"], [0, "⊸"], [0, "⊹"], [0, "⊺"], [0, "⊻"], [1, "⊽"], [0, "⊾"], [0, "⊿"], [0, "⋀"], [0, "⋁"], [0, "⋂"], [0, "⋃"], [0, "⋄"], [0, "⋅"], [0, "⋆"], [0, "⋇"], [0, "⋈"], [0, "⋉"], [0, "⋊"], [0, "⋋"], [0, "⋌"], [0, "⋍"], [0, "⋎"], [0, "⋏"], [0, "⋐"], [0, "⋑"], [0, "⋒"], [0, "⋓"], [0, "⋔"], [0, "⋕"], [0, "⋖"], [0, "⋗"], [0, { v: "⋘", n: 824, o: "⋘̸" }], [0, { v: "⋙", n: 824, o: "⋙̸" }], [0, { v: "⋚", n: 65024, o: "⋚︀" }], [0, { v: "⋛", n: 65024, o: "⋛︀" }], [2, "⋞"], [0, "⋟"], [0, "⋠"], [0, "⋡"], [0, "⋢"], [0, "⋣"], [2, "⋦"], [0, "⋧"], [0, "⋨"], [0, "⋩"], [0, "⋪"], [0, "⋫"], [0, "⋬"], [0, "⋭"], [0, "⋮"], [0, "⋯"], [0, "⋰"], [0, "⋱"], [0, "⋲"], [0, "⋳"], [0, "⋴"], [0, { v: "⋵", n: 824, o: "⋵̸" }], [0, "⋶"], [0, "⋷"], [1, { v: "⋹", n: 824, o: "⋹̸" }], [0, "⋺"], [0, "⋻"], [0, "⋼"], [0, "⋽"], [0, "⋾"], [6, "⌅"], [0, "⌆"], [1, "⌈"], [0, "⌉"], [0, "⌊"], [0, "⌋"], [0, "⌌"], [0, "⌍"], [0, "⌎"], [0, "⌏"], [0, "⌐"], [1, "⌒"], [0, "⌓"], [1, "⌕"], [0, "⌖"], [5, "⌜"], [0, "⌝"], [0, "⌞"], [0, "⌟"], [2, "⌢"], [0, "⌣"], [9, "⌭"], [0, "⌮"], [7, "⌶"], [6, "⌽"], [1, "⌿"], [60, "⍼"], [51, "⎰"], [0, "⎱"], [2, "⎴"], [0, "⎵"], [0, "⎶"], [37, "⏜"], [0, "⏝"], [0, "⏞"], [0, "⏟"], [2, "⏢"], [4, "⏧"], [59, "␣"], [164, "Ⓢ"], [55, "─"], [1, "│"], [9, "┌"], [3, "┐"], [3, "└"], [3, "┘"], [3, "├"], [7, "┤"], [7, "┬"], [7, "┴"], [7, "┼"], [19, "═"], [0, "║"], [0, "╒"], [0, "╓"], [0, "╔"], [0, "╕"], [0, "╖"], [0, "╗"], [0, "╘"], [0, "╙"], [0, "╚"], [0, "╛"], [0, "╜"], [0, "╝"], [0, "╞"], [0, "╟"], [0, "╠"], [0, "╡"], [0, "╢"], [0, "╣"], [0, "╤"], [0, "╥"], [0, "╦"], [0, "╧"], [0, "╨"], [0, "╩"], [0, "╪"], [0, "╫"], [0, "╬"], [19, "▀"], [3, "▄"], [3, "█"], [8, "░"], [0, "▒"], [0, "▓"], [13, "□"], [8, "▪"], [0, "▫"], [1, "▭"], [0, "▮"], [2, "▱"], [1, "△"], [0, "▴"], [0, "▵"], [2, "▸"], [0, "▹"], [3, "▽"], [0, "▾"], [0, "▿"], [2, "◂"], [0, "◃"], [6, "◊"], [0, "○"], [32, "◬"], [2, "◯"], [8, "◸"], [0, "◹"], [0, "◺"], [0, "◻"], [0, "◼"], [8, "★"], [0, "☆"], [7, "☎"], [49, "♀"], [1, "♂"], [29, "♠"], [2, "♣"], [1, "♥"], [0, "♦"], [3, "♪"], [2, "♭"], [0, "♮"], [0, "♯"], [163, "✓"], [3, "✗"], [8, "✠"], [21, "✶"], [33, "❘"], [25, "❲"], [0, "❳"], [84, "⟈"], [0, "⟉"], [28, "⟦"], [0, "⟧"], [0, "⟨"], [0, "⟩"], [0, "⟪"], [0, "⟫"], [0, "⟬"], [0, "⟭"], [7, "⟵"], [0, "⟶"], [0, "⟷"], [0, "⟸"], [0, "⟹"], [0, "⟺"], [1, "⟼"], [2, "⟿"], [258, "⤂"], [0, "⤃"], [0, "⤄"], [0, "⤅"], [6, "⤌"], [0, "⤍"], [0, "⤎"], [0, "⤏"], [0, "⤐"], [0, "⤑"], [0, "⤒"], [0, "⤓"], [2, "⤖"], [2, "⤙"], [0, "⤚"], [0, "⤛"], [0, "⤜"], [0, "⤝"], [0, "⤞"], [0, "⤟"], [0, "⤠"], [2, "⤣"], [0, "⤤"], [0, "⤥"], [0, "⤦"], [0, "⤧"], [0, "⤨"], [0, "⤩"], [0, "⤪"], [8, { v: "⤳", n: 824, o: "⤳̸" }], [1, "⤵"], [0, "⤶"], [0, "⤷"], [0, "⤸"], [0, "⤹"], [2, "⤼"], [0, "⤽"], [7, "⥅"], [2, "⥈"], [0, "⥉"], [0, "⥊"], [0, "⥋"], [2, "⥎"], [0, "⥏"], [0, "⥐"], [0, "⥑"], [0, "⥒"], [0, "⥓"], [0, "⥔"], [0, "⥕"], [0, "⥖"], [0, "⥗"], [0, "⥘"], [0, "⥙"], [0, "⥚"], [0, "⥛"], [0, "⥜"], [0, "⥝"], [0, "⥞"], [0, "⥟"], [0, "⥠"], [0, "⥡"], [0, "⥢"], [0, "⥣"], [0, "⥤"], [0, "⥥"], [0, "⥦"], [0, "⥧"], [0, "⥨"], [0, "⥩"], [0, "⥪"], [0, "⥫"], [0, "⥬"], [0, "⥭"], [0, "⥮"], [0, "⥯"], [0, "⥰"], [0, "⥱"], [0, "⥲"], [0, "⥳"], [0, "⥴"], [0, "⥵"], [0, "⥶"], [1, "⥸"], [0, "⥹"], [1, "⥻"], [0, "⥼"], [0, "⥽"], [0, "⥾"], [0, "⥿"], [5, "⦅"], [0, "⦆"], [4, "⦋"], [0, "⦌"], [0, "⦍"], [0, "⦎"], [0, "⦏"], [0, "⦐"], [0, "⦑"], [0, "⦒"], [0, "⦓"], [0, "⦔"], [0, "⦕"], [0, "⦖"], [3, "⦚"], [1, "⦜"], [0, "⦝"], [6, "⦤"], [0, "⦥"], [0, "⦦"], [0, "⦧"], [0, "⦨"], [0, "⦩"], [0, "⦪"], [0, "⦫"], [0, "⦬"], [0, "⦭"], [0, "⦮"], [0, "⦯"], [0, "⦰"], [0, "⦱"], [0, "⦲"], [0, "⦳"], [0, "⦴"], [0, "⦵"], [0, "⦶"], [0, "⦷"], [1, "⦹"], [1, "⦻"], [0, "⦼"], [1, "⦾"], [0, "⦿"], [0, "⧀"], [0, "⧁"], [0, "⧂"], [0, "⧃"], [0, "⧄"], [0, "⧅"], [3, "⧉"], [3, "⧍"], [0, "⧎"], [0, { v: "⧏", n: 824, o: "⧏̸" }], [0, { v: "⧐", n: 824, o: "⧐̸" }], [11, "⧜"], [0, "⧝"], [0, "⧞"], [4, "⧣"], [0, "⧤"], [0, "⧥"], [5, "⧫"], [8, "⧴"], [1, "⧶"], [9, "⨀"], [0, "⨁"], [0, "⨂"], [1, "⨄"], [1, "⨆"], [5, "⨌"], [0, "⨍"], [2, "⨐"], [0, "⨑"], [0, "⨒"], [0, "⨓"], [0, "⨔"], [0, "⨕"], [0, "⨖"], [0, "⨗"], [10, "⨢"], [0, "⨣"], [0, "⨤"], [0, "⨥"], [0, "⨦"], [0, "⨧"], [1, "⨩"], [0, "⨪"], [2, "⨭"], [0, "⨮"], [0, "⨯"], [0, "⨰"], [0, "⨱"], [1, "⨳"], [0, "⨴"], [0, "⨵"], [0, "⨶"], [0, "⨷"], [0, "⨸"], [0, "⨹"], [0, "⨺"], [0, "⨻"], [0, "⨼"], [2, "⨿"], [0, "⩀"], [1, "⩂"], [0, "⩃"], [0, "⩄"], [0, "⩅"], [0, "⩆"], [0, "⩇"], [0, "⩈"], [0, "⩉"], [0, "⩊"], [0, "⩋"], [0, "⩌"], [0, "⩍"], [2, "⩐"], [2, "⩓"], [0, "⩔"], [0, "⩕"], [0, "⩖"], [0, "⩗"], [0, "⩘"], [1, "⩚"], [0, "⩛"], [0, "⩜"], [0, "⩝"], [1, "⩟"], [6, "⩦"], [3, "⩪"], [2, { v: "⩭", n: 824, o: "⩭̸" }], [0, "⩮"], [0, "⩯"], [0, { v: "⩰", n: 824, o: "⩰̸" }], [0, "⩱"], [0, "⩲"], [0, "⩳"], [0, "⩴"], [0, "⩵"], [1, "⩷"], [0, "⩸"], [0, "⩹"], [0, "⩺"], [0, "⩻"], [0, "⩼"], [0, { v: "⩽", n: 824, o: "⩽̸" }], [0, { v: "⩾", n: 824, o: "⩾̸" }], [0, "⩿"], [0, "⪀"], [0, "⪁"], [0, "⪂"], [0, "⪃"], [0, "⪄"], [0, "⪅"], [0, "⪆"], [0, "⪇"], [0, "⪈"], [0, "⪉"], [0, "⪊"], [0, "⪋"], [0, "⪌"], [0, "⪍"], [0, "⪎"], [0, "⪏"], [0, "⪐"], [0, "⪑"], [0, "⪒"], [0, "⪓"], [0, "⪔"], [0, "⪕"], [0, "⪖"], [0, "⪗"], [0, "⪘"], [0, "⪙"], [0, "⪚"], [2, "⪝"], [0, "⪞"], [0, "⪟"], [0, "⪠"], [0, { v: "⪡", n: 824, o: "⪡̸" }], [0, { v: "⪢", n: 824, o: "⪢̸" }], [1, "⪤"], [0, "⪥"], [0, "⪦"], [0, "⪧"], [0, "⪨"], [0, "⪩"], [0, "⪪"], [0, "⪫"], [0, { v: "⪬", n: 65024, o: "⪬︀" }], [0, { v: "⪭", n: 65024, o: "⪭︀" }], [0, "⪮"], [0, { v: "⪯", n: 824, o: "⪯̸" }], [0, { v: "⪰", n: 824, o: "⪰̸" }], [2, "⪳"], [0, "⪴"], [0, "⪵"], [0, "⪶"], [0, "⪷"], [0, "⪸"], [0, "⪹"], [0, "⪺"], [0, "⪻"], [0, "⪼"], [0, "⪽"], [0, "⪾"], [0, "⪿"], [0, "⫀"], [0, "⫁"], [0, "⫂"], [0, "⫃"], [0, "⫄"], [0, { v: "⫅", n: 824, o: "⫅̸" }], [0, { v: "⫆", n: 824, o: "⫆̸" }], [0, "⫇"], [0, "⫈"], [2, { v: "⫋", n: 65024, o: "⫋︀" }], [0, { v: "⫌", n: 65024, o: "⫌︀" }], [2, "⫏"], [0, "⫐"], [0, "⫑"], [0, "⫒"], [0, "⫓"], [0, "⫔"], [0, "⫕"], [0, "⫖"], [0, "⫗"], [0, "⫘"], [0, "⫙"], [0, "⫚"], [0, "⫛"], [8, "⫤"], [1, "⫦"], [0, "⫧"], [0, "⫨"], [0, "⫩"], [1, "⫫"], [0, "⫬"], [0, "⫭"], [0, "⫮"], [0, "⫯"], [0, "⫰"], [0, "⫱"], [0, "⫲"], [0, "⫳"], [9, { v: "⫽", n: 8421, o: "⫽⃥" }], [44343, { n: new Map(/* #__PURE__ */ restoreDiff([[56476, "𝒜"], [1, "𝒞"], [0, "𝒟"], [2, "𝒢"], [2, "𝒥"], [0, "𝒦"], [2, "𝒩"], [0, "𝒪"], [0, "𝒫"], [0, "𝒬"], [1, "𝒮"], [0, "𝒯"], [0, "𝒰"], [0, "𝒱"], [0, "𝒲"], [0, "𝒳"], [0, "𝒴"], [0, "𝒵"], [0, "𝒶"], [0, "𝒷"], [0, "𝒸"], [0, "𝒹"], [1, "𝒻"], [1, "𝒽"], [0, "𝒾"], [0, "𝒿"], [0, "𝓀"], [0, "𝓁"], [0, "𝓂"], [0, "𝓃"], [1, "𝓅"], [0, "𝓆"], [0, "𝓇"], [0, "𝓈"], [0, "𝓉"], [0, "𝓊"], [0, "𝓋"], [0, "𝓌"], [0, "𝓍"], [0, "𝓎"], [0, "𝓏"], [52, "𝔄"], [0, "𝔅"], [1, "𝔇"], [0, "𝔈"], [0, "𝔉"], [0, "𝔊"], [2, "𝔍"], [0, "𝔎"], [0, "𝔏"], [0, "𝔐"], [0, "𝔑"], [0, "𝔒"], [0, "𝔓"], [0, "𝔔"], [1, "𝔖"], [0, "𝔗"], [0, "𝔘"], [0, "𝔙"], [0, "𝔚"], [0, "𝔛"], [0, "𝔜"], [1, "𝔞"], [0, "𝔟"], [0, "𝔠"], [0, "𝔡"], [0, "𝔢"], [0, "𝔣"], [0, "𝔤"], [0, "𝔥"], [0, "𝔦"], [0, "𝔧"], [0, "𝔨"], [0, "𝔩"], [0, "𝔪"], [0, "𝔫"], [0, "𝔬"], [0, "𝔭"], [0, "𝔮"], [0, "𝔯"], [0, "𝔰"], [0, "𝔱"], [0, "𝔲"], [0, "𝔳"], [0, "𝔴"], [0, "𝔵"], [0, "𝔶"], [0, "𝔷"], [0, "𝔸"], [0, "𝔹"], [1, "𝔻"], [0, "𝔼"], [0, "𝔽"], [0, "𝔾"], [1, "𝕀"], [0, "𝕁"], [0, "𝕂"], [0, "𝕃"], [0, "𝕄"], [1, "𝕆"], [3, "𝕊"], [0, "𝕋"], [0, "𝕌"], [0, "𝕍"], [0, "𝕎"], [0, "𝕏"], [0, "𝕐"], [1, "𝕒"], [0, "𝕓"], [0, "𝕔"], [0, "𝕕"], [0, "𝕖"], [0, "𝕗"], [0, "𝕘"], [0, "𝕙"], [0, "𝕚"], [0, "𝕛"], [0, "𝕜"], [0, "𝕝"], [0, "𝕞"], [0, "𝕟"], [0, "𝕠"], [0, "𝕡"], [0, "𝕢"], [0, "𝕣"], [0, "𝕤"], [0, "𝕥"], [0, "𝕦"], [0, "𝕧"], [0, "𝕨"], [0, "𝕩"], [0, "𝕪"], [0, "𝕫"]])) }], [8906, "ff"], [0, "fi"], [0, "fl"], [0, "ffi"], [0, "ffl"]])); + +}); +define("entities/generated/decode-data-xml",["require","exports"],(require,exports)=>{var module={get exports(){return exports},set exports(value){exports._replace(value);exports=value}}; +"use strict"; +// Generated using scripts/write-decode-map.ts +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = new Uint16Array( +// prettier-ignore +"\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022" + .split("") + .map(function (c) { return c.charCodeAt(0); })); + +}); +/* + * Support for source maps in V8 stack traces + * https://github.com/evanw/node-source-map-support + */ +/* + The buffer module from node.js, for the browser. + + @author Feross Aboukhadijeh + license MIT +*/ +(this.define||function(R,U){this.sourceMapSupport=U()})("browser-source-map-support",function(R){(function e(C,J,A){function p(f,c){if(!J[f]){if(!C[f]){var l="function"==typeof require&&require;if(!c&&l)return l(f,!0);if(t)return t(f,!0);throw Error("Cannot find module '"+f+"'");}l=J[f]={exports:{}};C[f][0].call(l.exports,function(q){var r=C[f][1][q];return p(r?r:q)},l,l.exports,e,C,J,A)}return J[f].exports}for(var t="function"==typeof require&&require,m=0;mm)return-1;if(58>m)return m-48+52;if(91>m)return m-65;if(123>m)return m-97+26}var t="undefined"!==typeof Uint8Array?Uint8Array:Array;e.toByteArray=function(m){function f(d){q[k++]=d}if(0>16);f((u&65280)>>8);f(u&255)}2===l?(u=p(m.charAt(c))<<2|p(m.charAt(c+1))>>4,f(u&255)):1===l&&(u=p(m.charAt(c))<<10|p(m.charAt(c+1))<<4|p(m.charAt(c+2))>>2,f(u>>8&255),f(u&255));return q};e.fromByteArray=function(m){var f=m.length%3,c="",l;var q=0;for(l=m.length-f;q> +18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r&63);c+=r}switch(f){case 1:r=m[m.length-1];c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>2);c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r<<4&63);c+="==";break;case 2:r=(m[m.length-2]<<8)+ +m[m.length-1],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>10),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>4&63),c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r<<2&63),c+="="}return c}})("undefined"===typeof A?this.base64js={}:A)},{}],3:[function(C,J,A){},{}],4:[function(C,J,A){(function(e){var p=Object.prototype.toString,t="function"===typeof e.alloc&&"function"===typeof e.allocUnsafe&&"function"=== +typeof e.from;J.exports=function(m,f,c){if("number"===typeof m)throw new TypeError('"value" argument must not be a number');if("ArrayBuffer"===p.call(m).slice(8,-1)){f>>>=0;var l=m.byteLength-f;if(0>l)throw new RangeError("'offset' is out of bounds");if(void 0===c)c=l;else if(c>>>=0,c>l)throw new RangeError("'length' is out of bounds");return t?e.from(m.slice(f,f+c)):new e(new Uint8Array(m.slice(f,f+c)))}if("string"===typeof m){c=f;if("string"!==typeof c||""===c)c="utf8";if(!e.isEncoding(c))throw new TypeError('"encoding" must be a valid string encoding'); +return t?e.from(m,c):new e(m,c)}return t?e.from(m):new e(m)}}).call(this,C("buffer").Buffer)},{buffer:5}],5:[function(C,J,A){function e(a,b,h){if(!(this instanceof e))return new e(a,b,h);var w=typeof a;if("number"===w)var y=0>>0:0;else if("string"===w){if("base64"===b)for(a=(a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")).replace(L,"");0!==a.length%4;)a+="=";y=e.byteLength(a,b)}else if("object"===w&&null!==a)"Buffer"===a.type&&z(a.data)&&(a=a.data),y=0<+a.length?Math.floor(+a.length):0;else throw new TypeError("must start with number, buffer, array or string"); +if(this.length>G)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+G.toString(16)+" bytes");if(e.TYPED_ARRAY_SUPPORT)var I=e._augment(new Uint8Array(y));else I=this,I.length=y,I._isBuffer=!0;if(e.TYPED_ARRAY_SUPPORT&&"number"===typeof a.byteLength)I._set(a);else{var K=a;if(z(K)||e.isBuffer(K)||K&&"object"===typeof K&&"number"===typeof K.length)if(e.isBuffer(a))for(b=0;ba)throw new RangeError("offset is not uint");if(a+b>h)throw new RangeError("Trying to access beyond buffer length");}function m(a,b,h,w,y,I){if(!e.isBuffer(a))throw new TypeError("buffer must be a Buffer instance");if(b>y||ba.length)throw new TypeError("index out of range"); +}function f(a,b,h,w){0>b&&(b=65535+b+1);for(var y=0,I=Math.min(a.length-h,2);y>>8*(w?y:1-y)}function c(a,b,h,w){0>b&&(b=4294967295+b+1);for(var y=0,I=Math.min(a.length-h,4);y>>8*(w?y:3-y)&255}function l(a,b,h,w,y,I){if(b>y||ba.length)throw new TypeError("index out of range");}function q(a,b,h,w,y){y||l(a,b,h,4,3.4028234663852886E38,-3.4028234663852886E38);v.write(a,b,h,w,23,4);return h+4}function r(a, +b,h,w,y){y||l(a,b,h,8,1.7976931348623157E308,-1.7976931348623157E308);v.write(a,b,h,w,52,8);return h+8}function k(a){for(var b=[],h=0;h=w)b.push(w);else{var y=h;55296<=w&&57343>=w&&h++;w=encodeURIComponent(a.slice(y,h+1)).substr(1).split("%");for(y=0;y=b.length||y>=a.length);y++)b[y+ +h]=a[y];return y}function g(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}var n=C("base64-js"),v=C("ieee754"),z=C("is-array");A.Buffer=e;A.SlowBuffer=e;A.INSPECT_MAX_BYTES=50;e.poolSize=8192;var G=1073741823;e.TYPED_ARRAY_SUPPORT=function(){try{var a=new ArrayBuffer(0),b=new Uint8Array(a);b.foo=function(){return 42};return 42===b.foo()&&"function"===typeof b.subarray&&0===(new Uint8Array(1)).subarray(1,1).byteLength}catch(h){return!1}}();e.isBuffer=function(a){return!(null== +a||!a._isBuffer)};e.compare=function(a,b){if(!e.isBuffer(a)||!e.isBuffer(b))throw new TypeError("Arguments must be Buffers");for(var h=a.length,w=b.length,y=0,I=Math.min(h,w);y>>1;break;case "utf8":case "utf-8":h=k(a).length;break;case "base64":h=n.toByteArray(a).length; +break;default:h=a.length}return h};e.prototype.length=void 0;e.prototype.parent=void 0;e.prototype.toString=function(a,b,h){var w=!1;b>>>=0;h=void 0===h||Infinity===h?this.length:h>>>0;a||(a="utf8");0>b&&(b=0);h>this.length&&(h=this.length);if(h<=b)return"";for(;;)switch(a){case "hex":a=b;b=h;h=this.length;if(!a||0>a)a=0;if(!b||0>b||b>h)b=h;w="";for(h=a;hw?"0"+w.toString(16):w.toString(16),w=a+w;return w;case "utf8":case "utf-8":w=a="";for(h=Math.min(this.length,h);b= +this[b]?(a+=g(w)+String.fromCharCode(this[b]),w=""):w+="%"+this[b].toString(16);return a+g(w);case "ascii":return p(this,b,h);case "binary":return p(this,b,h);case "base64":return b=0===b&&h===this.length?n.fromByteArray(this):n.fromByteArray(this.slice(b,h)),b;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":b=this.slice(b,h);h="";for(a=0;ab&&(a+=" ... "));return""};e.prototype.compare=function(a){if(!e.isBuffer(a))throw new TypeError("Argument must be a Buffer");return e.compare(this,a)};e.prototype.get=function(a){console.log(".get() is deprecated. Access using array indexes instead."); +return this.readUInt8(a)};e.prototype.set=function(a,b){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(a,b)};e.prototype.write=function(a,b,h,w){if(isFinite(b))isFinite(h)||(w=h,h=void 0);else{var y=w;w=b;b=h;h=y}b=Number(b)||0;y=this.length-b;h?(h=Number(h),h>y&&(h=y)):h=y;w=String(w||"utf8").toLowerCase();switch(w){case "hex":b=Number(b)||0;w=this.length-b;h?(h=Number(h),h>w&&(h=w)):h=w;w=a.length;if(0!==w%2)throw Error("Invalid hex string");h>w/ +2&&(h=w/2);for(w=0;w>8;K%=256;y.push(K);y.push(w)}a=d(y,this,b,h,2);break;default:throw new TypeError("Unknown encoding: "+ +w);}return a};e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};e.prototype.slice=function(a,b){var h=this.length;a=~~a;b=void 0===b?h:~~b;0>a?(a+=h,0>a&&(a=0)):a>h&&(a=h);0>b?(b+=h,0>b&&(b=0)):b>h&&(b=h);b>>=0;h||m(this,a,b,1,255,0);e.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));this[b]=a;return b+1};e.prototype.writeUInt16LE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,2,65535,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):f(this,a,b,!0);return b+2};e.prototype.writeUInt16BE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,2,65535,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):f(this,a,b,!1);return b+2};e.prototype.writeUInt32LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,4294967295,0);e.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=a):c(this,a,b,!0);return b+4};e.prototype.writeUInt32BE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,4,4294967295,0);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a):c(this,a,b,!1);return b+4};e.prototype.writeInt8=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,1,127,-128);e.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));0>a&&(a=255+a+1);this[b]=a;return b+1};e.prototype.writeInt16LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,2,32767,-32768);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8):f(this,a,b,!0);return b+2};e.prototype.writeInt16BE=function(a, +b,h){a=+a;b>>>=0;h||m(this,a,b,2,32767,-32768);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a):f(this,a,b,!1);return b+2};e.prototype.writeInt32LE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,2147483647,-2147483648);e.TYPED_ARRAY_SUPPORT?(this[b]=a,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):c(this,a,b,!0);return b+4};e.prototype.writeInt32BE=function(a,b,h){a=+a;b>>>=0;h||m(this,a,b,4,2147483647,-2147483648);0>a&&(a=4294967295+a+1);e.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+ +2]=a>>>8,this[b+3]=a):c(this,a,b,!1);return b+4};e.prototype.writeFloatLE=function(a,b,h){return q(this,a,b,!0,h)};e.prototype.writeFloatBE=function(a,b,h){return q(this,a,b,!1,h)};e.prototype.writeDoubleLE=function(a,b,h){return r(this,a,b,!0,h)};e.prototype.writeDoubleBE=function(a,b,h){return r(this,a,b,!1,h)};e.prototype.copy=function(a,b,h,w){h||(h=0);w||0===w||(w=this.length);b||(b=0);if(w!==h&&0!==a.length&&0!==this.length){if(wb||b>=a.length)throw new TypeError("targetStart out of bounds"); +if(0>h||h>=this.length)throw new TypeError("sourceStart out of bounds");if(0>w||w>this.length)throw new TypeError("sourceEnd out of bounds");w>this.length&&(w=this.length);a.length-bw||!e.TYPED_ARRAY_SUPPORT)for(var y=0;yb||b>=this.length)throw new TypeError("start out of bounds"); +if(0>h||h>this.length)throw new TypeError("end out of bounds");if("number"===typeof a)for(;b>1,r=-7;f=t?f-1:0;var k=t?-1:1,u=e[p+f];f+=k;t=u&(1<<-r)-1;u>>=-r;for(r+=c;0>=-r;for(r+=m;0>1,u=23===f?Math.pow(2,-24)-Math.pow(2,-77):0;c=m?0:c-1;var d=m?1:-1,g=0>p||0===p&&0>1/p?1:0;p=Math.abs(p);isNaN(p)||Infinity===p?(p=isNaN(p)?1:0,m=r):(m=Math.floor(Math.log(p)/Math.LN2),1>p*(l=Math.pow(2,-m))&&(m--,l*=2),p=1<=m+k?p+u/l:p+u*Math.pow(2,1-k),2<=p*l&&(m++,l/=2),m+k>=r?(p=0,m=r):1<=m+k?(p=(p*l-1)*Math.pow(2,f),m+=k):(p=p*Math.pow(2,k-1)*Math.pow(2,f),m=0));for(;8<=f;e[t+c]=p&255,c+= +d,p/=256,f-=8);m=m<z?[]:n.slice(v,z-v+1)}c=A.resolve(c).substr(1);l=A.resolve(l).substr(1); +for(var r=q(c.split("/")),k=q(l.split("/")),u=Math.min(r.length,k.length),d=u,g=0;gl&&(l=c.length+l);return c.substr(l,q)}}).call(this,C("g5I+bs"))},{"g5I+bs":9}],9:[function(C,J,A){function e(){}C=J.exports={};C.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(t){return window.setImmediate(t)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var p=[];window.addEventListener("message",function(t){var m=t.source;m!==window&&null!== +m||"process-tick"!==t.data||(t.stopPropagation(),0p?(-p<<1)+1:p<<1;do p=m&31,m>>>=5,0=f)throw Error("Expected more digits in base 64 VLQ value.");var q=e.decode(p.charCodeAt(t++));if(-1===q)throw Error("Invalid base64 digit: "+p.charAt(t-1));var r=!!(q&32);q&=31;c+=q<>1;m.value=1===(c&1)?-p:p;m.rest=t}},{"./base64":12}],12:[function(C, +J,A){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");A.encode=function(p){if(0<=p&&p=p?p-65:97<=p&&122>=p?p-97+26:48<=p&&57>=p?p-48+52:43==p?62:47==p?63:-1}},{}],13:[function(C,J,A){function e(p,t,m,f,c,l){var q=Math.floor((t-p)/2)+p,r=c(m,f[q],!0);return 0===r?q:0p?-1:p}A.GREATEST_LOWER_BOUND=1;A.LEAST_UPPER_BOUND=2;A.search=function(p,t,m,f){if(0===t.length)return-1;p=e(-1,t.length,p,t,m,f||A.GREATEST_LOWER_BOUND);if(0>p)return-1;for(;0<=p-1&&0===m(t[p],t[p-1],!0);)--p;return p}},{}],14:[function(C,J,A){function e(){this._array=[];this._sorted=!0;this._last={generatedLine:-1,generatedColumn:0}}var p=C("./util");e.prototype.unsortedForEach=function(t,m){this._array.forEach(t,m)};e.prototype.add=function(t){var m=this._last,f=m.generatedLine, +c=t.generatedLine,l=m.generatedColumn,q=t.generatedColumn;c>f||c==f&&q>=l||0>=p.compareByGeneratedPositionsInflated(m,t)?this._last=t:this._sorted=!1;this._array.push(t)};e.prototype.toArray=function(){this._sorted||(this._array.sort(p.compareByGeneratedPositionsInflated),this._sorted=!0);return this._array};A.MappingList=e},{"./util":19}],15:[function(C,J,A){function e(t,m,f){var c=t[m];t[m]=t[f];t[f]=c}function p(t,m,f,c){if(f=m(t[r],q)&&(l+=1,e(t,l,r));e(t,l+1,r);l+=1;p(t,m,f,l-1);p(t,m,l+1,c)}}A.quickSort=function(t,m){p(t,m,0,t.length-1)}},{}],16:[function(C,J,A){function e(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));return null!=d.sections?new m(d,u):new p(d,u)}function p(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));var g=f.getArg(d,"version"),n=f.getArg(d,"sources"),v=f.getArg(d,"names",[]),z=f.getArg(d,"sourceRoot",null),G=f.getArg(d,"sourcesContent",null),D=f.getArg(d, +"mappings");d=f.getArg(d,"file",null);if(g!=this._version)throw Error("Unsupported version: "+g);z&&(z=f.normalize(z));n=n.map(String).map(f.normalize).map(function(L){return z&&f.isAbsolute(z)&&f.isAbsolute(L)?f.relative(z,L):L});this._names=l.fromArray(v.map(String),!0);this._sources=l.fromArray(n,!0);this.sourceRoot=z;this.sourcesContent=G;this._mappings=D;this._sourceMapURL=u;this.file=d}function t(){this.generatedColumn=this.generatedLine=0;this.name=this.originalColumn=this.originalLine=this.source= +null}function m(k,u){var d=k;"string"===typeof k&&(d=f.parseSourceMapInput(k));var g=f.getArg(d,"version");d=f.getArg(d,"sections");if(g!=this._version)throw Error("Unsupported version: "+g);this._sources=new l;this._names=new l;var n={line:-1,column:0};this._sections=d.map(function(v){if(v.url)throw Error("Support for url field in sections not implemented.");var z=f.getArg(v,"offset"),G=f.getArg(z,"line"),D=f.getArg(z,"column");if(G=k[d])throw new TypeError("Line must be greater than or equal to 1, got "+ +k[d]);if(0>k[g])throw new TypeError("Column must be greater than or equal to 0, got "+k[g]);return c.search(k,u,n,v)};p.prototype.computeColumnSpans=function(){for(var k=0;k=this._sources.size()&&!this.sourcesContent.some(function(k){return null==k}):!1};p.prototype.sourceContentFor=function(k,u){if(!this.sourcesContent)return null;var d=k;null!=this.sourceRoot&&(d=f.relative(this.sourceRoot,d));if(this._sources.has(d))return this.sourcesContent[this._sources.indexOf(d)]; +var g=this.sources,n;for(n=0;n +g||95!==d.charCodeAt(g-1)||95!==d.charCodeAt(g-2)||111!==d.charCodeAt(g-3)||116!==d.charCodeAt(g-4)||111!==d.charCodeAt(g-5)||114!==d.charCodeAt(g-6)||112!==d.charCodeAt(g-7)||95!==d.charCodeAt(g-8)||95!==d.charCodeAt(g-9))return!1;for(g-=10;0<=g;g--)if(36!==d.charCodeAt(g))return!1;return!0}function r(d,g){return d===g?0:null===d?1:null===g?-1:d>g?1:-1}A.getArg=function(d,g,n){if(g in d)return d[g];if(3===arguments.length)return n;throw Error('"'+g+'" is a required argument.');};var k=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/, +u=/^data:.+,.+$/;A.urlParse=e;A.urlGenerate=p;A.normalize=t;A.join=m;A.isAbsolute=function(d){return"/"===d.charAt(0)||k.test(d)};A.relative=function(d,g){""===d&&(d=".");d=d.replace(/\/$/,"");for(var n=0;0!==g.indexOf(d+"/");){var v=d.lastIndexOf("/");if(0>v)return g;d=d.slice(0,v);if(d.match(/^([^\/]+:\/)?\/*$/))return g;++n}return Array(n+1).join("../")+g.substr(d.length+1)};C=!("__proto__"in Object.create(null));A.toSetString=C?f:c;A.fromSetString=C?f:l;A.compareByOriginalPositions=function(d, +g,n){var v=r(d.source,g.source);if(0!==v)return v;v=d.originalLine-g.originalLine;if(0!==v)return v;v=d.originalColumn-g.originalColumn;if(0!==v||n)return v;v=d.generatedColumn-g.generatedColumn;if(0!==v)return v;v=d.generatedLine-g.generatedLine;return 0!==v?v:r(d.name,g.name)};A.compareByGeneratedPositionsDeflated=function(d,g,n){var v=d.generatedLine-g.generatedLine;if(0!==v)return v;v=d.generatedColumn-g.generatedColumn;if(0!==v||n)return v;v=r(d.source,g.source);if(0!==v)return v;v=d.originalLine- +g.originalLine;if(0!==v)return v;v=d.originalColumn-g.originalColumn;return 0!==v?v:r(d.name,g.name)};A.compareByGeneratedPositionsInflated=function(d,g){var n=d.generatedLine-g.generatedLine;if(0!==n)return n;n=d.generatedColumn-g.generatedColumn;if(0!==n)return n;n=r(d.source,g.source);if(0!==n)return n;n=d.originalLine-g.originalLine;if(0!==n)return n;n=d.originalColumn-g.originalColumn;return 0!==n?n:r(d.name,g.name)};A.parseSourceMapInput=function(d){return JSON.parse(d.replace(/^\)]}'[^\n]*\n/, +""))};A.computeSourceURL=function(d,g,n){g=g||"";d&&("/"!==d[d.length-1]&&"/"!==g[0]&&(d+="/"),g=d+g);if(n){d=e(n);if(!d)throw Error("sourceMapURL could not be parsed");d.path&&(n=d.path.lastIndexOf("/"),0<=n&&(d.path=d.path.substring(0,n+1)));g=m(p(d),g)}return t(g)}},{}],20:[function(C,J,A){A.SourceMapGenerator=C("./lib/source-map-generator").SourceMapGenerator;A.SourceMapConsumer=C("./lib/source-map-consumer").SourceMapConsumer;A.SourceNode=C("./lib/source-node").SourceNode},{"./lib/source-map-consumer":16, +"./lib/source-map-generator":17,"./lib/source-node":18}],21:[function(C,J,A){(function(e){function p(){return"browser"===a?!0:"node"===a?!1:"undefined"!==typeof window&&"function"===typeof XMLHttpRequest&&!(window.require&&window.module&&window.process&&"renderer"===window.process.type)}function t(x){return function(B){for(var F=0;F";B=this.getLineNumber();null!=B&&(x+=":"+B,(B= +this.getColumnNumber())&&(x+=":"+B))}B="";var F=this.getFunctionName(),E=!0,H=this.isConstructor();if(this.isToplevel()||H)H?B+="new "+(F||""):F?B+=F:(B+=x,E=!1);else{H=this.getTypeName();"[object Object]"===H&&(H="null");var M=this.getMethodName();F?(H&&0!=F.indexOf(H)&&(B+=H+"."),B+=F,M&&F.indexOf("."+M)!=F.length-M.length-1&&(B+=" [as "+M+"]")):B+=H+"."+(M||"")}E&&(B+=" ("+x+")");return B}function q(x){var B={};Object.getOwnPropertyNames(Object.getPrototypeOf(x)).forEach(function(F){B[F]= +/^(?:is|get)/.test(F)?function(){return x[F].call(x)}:x[F]});B.toString=l;return B}function r(x,B){void 0===B&&(B={nextPosition:null,curPosition:null});if(x.isNative())return B.curPosition=null,x;var F=x.getFileName()||x.getScriptNameOrSourceURL();if(F){var E=x.getLineNumber(),H=x.getColumnNumber()-1,M=/^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/,S=M.test;var V="object"===typeof e&&null!==e?e.version:"";M=S.call(M,V)?0:62;1===E&&H>M&&!p()&&!x.isEval()&&(H-=M);var O= +f({source:F,line:E,column:H});B.curPosition=O;x=q(x);var T=x.getFunctionName;x.getFunctionName=function(){return null==B.nextPosition?T():B.nextPosition.name||T()};x.getFileName=function(){return O.source};x.getLineNumber=function(){return O.line};x.getColumnNumber=function(){return O.column+1};x.getScriptNameOrSourceURL=function(){return O.source};return x}var Q=x.isEval()&&x.getEvalOrigin();Q&&(Q=c(Q),x=q(x),x.getEvalOrigin=function(){return Q});return x}function k(x,B){L&&(b={},h={});for(var F= +(x.name||"Error")+": "+(x.message||""),E={nextPosition:null,curPosition:null},H=[],M=B.length-1;0<=M;M--)H.push("\n at "+r(B[M],E)),E.nextPosition=E.curPosition;E.curPosition=E.nextPosition=null;return F+H.reverse().join("")}function u(x){var B=/\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(x.stack);if(B){x=B[1];var F=+B[2];B=+B[3];var E=b[x];if(!E&&v&&v.existsSync(x))try{E=v.readFileSync(x,"utf8")}catch(H){E=""}if(E&&(E=E.split(/(?:\r\n|\r|\n)/)[F-1]))return x+":"+F+"\n"+E+"\n"+Array(B).join(" ")+ +"^"}return null}function d(){var x=e.emit;e.emit=function(B){if("uncaughtException"===B){var F=arguments[1]&&arguments[1].stack,E=0{}) +define("crelt",[],()=>{}) diff --git a/lang/en-nz.js b/lang/en-nz.js new file mode 100644 index 0000000..c13ee38 --- /dev/null +++ b/lang/en-nz.js @@ -0,0 +1 @@ +(function(factory){if(typeof module==="object"&&typeof module.exports==="object"){var v=factory(require, exports);if(v!==undefined)module.exports=v}else if(typeof define==="function"&&define.amd){define(["require","exports"],factory);}})(function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});let s=t=>typeof t=="string"?t:Array.isArray(t)?t.map(s).join(""):typeof t.content=="object"?s(t.content):t.content;let ii=u=>(typeof u=="object"||typeof u=="function")&&Symbol.iterator in u;let c=c=>({content:c,toString(){return s(this.content)}});let j=(a,s,v)=>{a=(!a?[]:Array.isArray(a)?a:ii(a)?[...a]:[a]);return (v?a.map(v):a).flatMap((v,i)=>i!v?0:typeof v.length=="number"?v.length:typeof v.size=="number"?v.size:ii(v)?[...v].length:typeof v=="object"?Object.keys(v).length:0;var q={"fluff4me/title":_=>c([{content:"fluff4.me / Tell your story!"}]),"home/label":_=>c([{content:"home"}]),"shared/preview":_=>c([{content:"Preview"}]),"shared/prompt/confirm":_=>c([{content:"Are you sure?"}]),"shared/prompt/reauth":_=>c([{content:"To perform this action, reauthenticate to verify your identity:"}]),"shared/term/chapters":_=>c([{content:"Chapters"}]),"shared/action/login-or-signup":_=>c([{content:"Log In or Sign Up"}]),"shared/action/view":_=>c([{content:"View"}]),"shared/action/love":_=>c([{content:"Love"}]),"shared/action/edit":_=>c([{content:"Edit"}]),"shared/action/follow":_=>c([{content:"Follow"}]),"shared/action/ignore":_=>c([{content:"Ignore"}]),"shared/action/delete":(...a)=>c([{content:"Delete"},{content:(a[0]?[{content:" "},a[0]]:[])}]),"shared/action/save":_=>c([{content:"Save Changes"}]),"shared/action/create":_=>c([{content:"Create!"}]),"shared/action/cancel":_=>c([{content:"Cancel"}]),"shared/action/confirm":_=>c([{content:"Confirm"}]),"shared/toast/failed-to-save":(...a)=>c([{content:"Failed to save "},{content:a[0]}]),"shared/toast/saved":(...a)=>c([{content:"Saved "},{content:a[0]}]),"shared/form/name/label":_=>c([{content:"Name"}]),"shared/form/vanity/label":_=>c([{content:"Vanity"}]),"shared/form/description/label":_=>c([{content:"Description"}]),"shared/form/body/label":_=>c([{content:"Body"}]),"component/popover/button":(...a)=>c([{content:"open "},{content:(a[0]?a[0]:[{content:"details"}])},{content:(a[1]?[{content:" "},a[1]]:[])}]),"component/popover":(...a)=>c([{content:(a[0]?a[0]:[{content:"details"}])}]),"component/paginator/error":_=>c([{content:"Failed to load content."}]),"component/paginator/error/retry":_=>c([{content:"Retry"}]),"component/text-editor/toolbar/group/inline":_=>c([{content:"inline formatting"}]),"component/text-editor/toolbar/button/strong":_=>c([{content:"strong (bold)"}]),"component/text-editor/toolbar/button/em":_=>c([{content:"emphasis (italic)"}]),"component/text-editor/toolbar/button/underline":_=>c([{content:"underline"}]),"component/text-editor/toolbar/button/strikethrough":_=>c([{content:"strikethrough"}]),"component/text-editor/toolbar/button/subscript":_=>c([{content:"subscript"}]),"component/text-editor/toolbar/button/superscript":_=>c([{content:"superscript"}]),"component/text-editor/toolbar/button/code":_=>c([{content:"code"}]),"component/text-editor/toolbar/button/link":_=>c([{content:"link"}]),"component/text-editor/toolbar/button/other-formatting":_=>c([{content:"other formatting options"}]),"component/text-editor/toolbar/group/block":_=>c([{content:"block formatting"}]),"component/text-editor/toolbar/button/align":(...a)=>c([{content:"text align (currently "},{content:a[0]},{content:")"}]),"component/text-editor/toolbar/button/align-left":_=>c([{content:"align left"}]),"component/text-editor/toolbar/button/align-centre":_=>c([{content:"centre"}]),"component/text-editor/toolbar/button/align-right":_=>c([{content:"align right"}]),"component/text-editor/toolbar/button/align/currently/left":_=>c([{content:"aligned left"}]),"component/text-editor/toolbar/button/align/currently/right":_=>c([{content:"aligned right"}]),"component/text-editor/toolbar/button/align/currently/centre":_=>c([{content:"centred"}]),"component/text-editor/toolbar/button/align/currently/mixed":_=>c([{content:"mixed"}]),"component/text-editor/toolbar/button/block-type":(...a)=>c([{content:"block type (currently "},{content:a[0]},{content:")"}]),"component/text-editor/toolbar/button/code-block":_=>c([{content:"code block"}]),"component/text-editor/toolbar/button/paragraph":_=>c([{content:"paragraph"}]),"component/text-editor/toolbar/button/block-type/currently/code-block":_=>c([{content:"code block"}]),"component/text-editor/toolbar/button/block-type/currently/paragraph":_=>c([{content:"paragraph"}]),"component/text-editor/toolbar/button/block-type/currently/mixed":_=>c([{content:"mixed"}]),"component/text-editor/toolbar/group/wrapper":_=>c([{content:"block wrappers"}]),"component/text-editor/toolbar/button/lift":_=>c([{content:"unwrap"}]),"component/text-editor/toolbar/button/bullet-list":_=>c([{content:"wrap in list"}]),"component/text-editor/toolbar/button/ordered-list":_=>c([{content:"wrap in ordered list"}]),"component/text-editor/toolbar/button/blockquote":_=>c([{content:"wrap in block quote"}]),"component/text-editor/toolbar/group/insert":_=>c([{content:"insert"}]),"component/text-editor/toolbar/button/hr":_=>c([{content:"horizontal rule"}]),"component/text-editor/toolbar/group/actions":_=>c([{content:"actions"}]),"component/text-editor/toolbar/button/undo":_=>c([{content:"undo"}]),"component/text-editor/toolbar/button/redo":_=>c([{content:"redo"}]),"component/text-editor/toolbar/button/fullscreen":_=>c([{content:"fullscreen"}]),"component/text-editor/toolbar/button/unfullscreen":_=>c([{content:"exit fullscreen"}]),"component/text-editor/formatting/none":_=>c([{content:"no formatting"}]),"component/text-editor/formatting/strong":_=>c([{content:"strong (bolded)"}]),"component/text-editor/formatting/em":_=>c([{content:"emphasised (italic)"}]),"component/text-editor/formatting/underline":_=>c([{content:"underlined"}]),"component/text-editor/formatting/strikethrough":_=>c([{content:"strikethrough"}]),"component/text-editor/formatting/subscript":_=>c([{content:"subscript"}]),"component/text-editor/formatting/superscript":_=>c([{content:"superscript"}]),"component/text-editor/formatting/code":_=>c([{content:"code"}]),"component/text-editor/formatting/link":_=>c([{content:"link"}]),"masthead/skip-navigation":_=>c([{content:"Skip Navigation"}]),"masthead/user/notifications/alt":_=>c([{content:"notifications"}]),"masthead/primary-nav/alt":_=>c([{content:"primary"}]),"masthead/user/profile/alt":_=>c([{content:"profile"}]),"masthead/user/profile/popover/login":(...a) => q["shared/action/login-or-signup"](...a),"masthead/user/profile/popover/profile":_=>c([{content:"View Profile"}]),"masthead/user/profile/popover/account":_=>c([{content:"Account Settings"}]),"work/chapters/label":(...a) => q["shared/term/chapters"](...a),"work/description/empty":_=>c([{content:"This work has no description."}]),"author/description/empty":_=>c([{content:"This author prefers to remain elusive and mysterious..."}]),"view/container/alt":_=>c([{content:"main content"}]),"view/shared/login-required/title":_=>c([{content:"Log-in required"}]),"view/shared/login-required/description":_=>c([{content:"You must log in or sign up to view this content."}]),"view/shared/login-required/action":(...a) => q["shared/action/login-or-signup"](...a),"view/error/title":(...a)=>c([{content:"Error "},{content:a[0]?.CODE}]),"view/error/description-404":_=>c([{content:"Your adventure has come to a close, your questions left unanswered, your goals unfulfilled. What will you do?"}]),"view/feed/main/title":_=>c([{content:"Recent Updates"}]),"view/feed/content/empty":_=>c([{content:"And all was quiet..."}]),"view/account/name/label":(...a) => q["shared/form/name/label"](...a),"view/account/name/hint":_=>c([{content:"Your display name or penname — the name your comments and works are attributed to. This can be changed whenever you like, and doesn't have to be unique."}]),"view/account/vanity/label":(...a) => q["shared/form/vanity/label"](...a),"view/account/vanity/hint":_=>c([{content:"Your username, and what people use to "},{content:[{content:"@ping"}],tag:`B`},{content:" you in comments. This "},{content:[{content:"can"}],tag:`I`},{content:" be changed whenever you like, but "},{content:[{content:"must always be unique"}],tag:`B`},{content:"."}]),"view/account/vanity/url-preview":(...a) => q["shared/preview"](...a),"view/account/description/label":(...a) => q["shared/form/description/label"](...a),"view/account/description/hint":_=>c([{content:"This bio will appear on your profile above any works."}]),"view/account/support-link/label":_=>c([{content:"Support Link"}]),"view/account/support-link/hint":_=>c([{content:"An optional link that people can use to support you. You could link directly to a payment or subscription platform, or you could use a service like Linktree."}]),"view/account/support-message/label":_=>c([{content:"Message"}]),"view/account/support-message/hint":_=>c([{content:"A message to display instead of the support link itself. This is required, and will default to \"Support My Writing.\"\nIf you want it to actually display the link, for whatever reason, you can put the link here as well."}]),"view/account/support-message/placeholder":_=>c([{content:"Support My Writing"}]),"view/account/pronouns/label":_=>c([{content:"Pronouns"}]),"view/account/pronouns/hint":_=>c([{content:"The pronouns that others should refer to you with. These will appear next to your name, usually."}]),"view/account/action/logout":_=>c([{content:"Log Out"}]),"view/account/action/delete":_=>c([{content:"Delete Account"}]),"view/account/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](_=>c([{content:"| account data"}]), ...a),"view/account/toast/saved":(...a) => q["shared/toast/saved"](_=>c([{content:"| account data"}]), ...a),"view/account/auth/service/accessibility/connect":(...a)=>c([{content:"connect "},{content:a[0]}]),"view/account/auth/service/accessibility/disconnect":(...a)=>c([{content:"disconnect "},{content:a[0]},{content:" account "},{content:a[1]}]),"view/account/auth/none/title":_=>c([{content:"Log in or sign up"}]),"view/account/auth/none/description":_=>c([{content:"fluff4.me does not store an email address or password for your account. You must authenticate with a third-party service to begin."}]),"view/account/auth/has-authorisations/title":_=>c([{content:"Authorisations"}]),"view/account/auth/has-authorisations/description":_=>c([{content:"Your authorisation(s) are not currently associated with a fluff4.me account. You may authenticate with additional third party services to log in or sign up."}]),"view/account/auth/logged-in/title":_=>c([{content:"Authorisations"}]),"view/account/auth/logged-in/description":_=>c([{content:"These third party service accounts are linked to your fluff4.me account and may be used to log in."}]),"view/account/create/title":_=>c([{content:"Create account"}]),"view/account/create/description":_=>c([{content:"The "},{content:[{content:"connected third party service accounts"}],tag:`LINK(#authorisations)`},{content:" will be used for login."}]),"view/account/create/submit":_=>c([{content:"Sign Up!"}]),"view/account/update/title":_=>c([{content:"Update profile"}]),"view/account/update/submit":(...a) => q["shared/action/save"](...a),"view/author/works/title":_=>c([{content:"Works"}]),"view/author/works/content/empty":_=>c([{content:"This author has not yet shared any work..."}]),"view/author/works/action/label/new":_=>c([{content:"New Work"}]),"view/author/works/action/label/view":(...a) => q["shared/action/view"](...a),"view/author/works/action/label/edit":(...a) => q["shared/action/edit"](...a),"view/author/works/action/label/follow":(...a) => q["shared/action/follow"](...a),"view/author/works/action/label/ignore":(...a) => q["shared/action/ignore"](...a),"view/author/works/action/label/delete":(...a) => q["shared/action/delete"](...a),"view/work-edit/shared/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](...a),"view/work-edit/shared/toast/saved":(...a) => q["shared/toast/saved"](...a),"view/work-edit/shared/form/name/label":(...a) => q["shared/form/name/label"](...a),"view/work-edit/shared/form/name/hint":_=>c([{content:"The name of your work. This does not have to be unique."}]),"view/work-edit/shared/form/vanity/label":(...a) => q["shared/form/vanity/label"](...a),"view/work-edit/shared/form/vanity/hint":_=>c([{content:"The identifier for this work, which will appear in its URL."}]),"view/work-edit/shared/form/vanity/url-preview":(...a) => q["shared/preview"](...a),"view/work-edit/shared/form/description/label":(...a) => q["shared/form/description/label"](...a),"view/work-edit/shared/form/description/hint":_=>c([{content:"A simple 1-2 sentence description of the work. This will be the only descriptive text shown when works are displayed in lists."}]),"view/work-edit/shared/form/synopsis/label":_=>c([{content:"Synopsis"}]),"view/work-edit/shared/form/synopsis/hint":_=>c([{content:"The full text describing this work. This will only appear in the full work view."}]),"view/work-edit/create/title":_=>c([{content:"Create work"}]),"view/work-edit/create/submit":(...a) => q["shared/action/create"](...a),"view/work-edit/update/title":_=>c([{content:"Edit work"}]),"view/work-edit/update/submit":(...a) => q["shared/action/save"](...a),"view/work-edit/update/action/delete":_=>c([{content:"Delete Work"}]),"view/work/chapters/title":(...a) => q["shared/term/chapters"](...a),"view/work/chapters/content/empty":_=>c([{content:"This work does not contain any chapters."}]),"view/work/chapters/action/label/new":_=>c([{content:"New Chapter"}]),"view/work/chapters/action/label/view":(...a) => q["shared/action/view"](...a),"view/work/chapters/action/label/love":(...a) => q["shared/action/love"](...a),"view/work/chapters/action/label/edit":(...a) => q["shared/action/edit"](...a),"view/work/chapters/action/label/delete":(...a) => q["shared/action/delete"](...a),"view/chapter-edit/shared/toast/failed-to-save":(...a) => q["shared/toast/failed-to-save"](_=>c([{content:"| chapter"}]), ...a),"view/chapter-edit/shared/toast/saved":(...a) => q["shared/toast/saved"](_=>c([{content:"| chapter"}]), ...a),"view/chapter-edit/shared/form/name/label":(...a) => q["shared/form/name/label"](...a),"view/chapter-edit/shared/form/name/hint":_=>c([{content:"The name of this chapter. This does not have to be unique."}]),"view/chapter-edit/shared/form/body/label":(...a) => q["shared/form/body/label"](...a),"view/chapter-edit/shared/form/body/hint":_=>c([{content:"The content of this chapter. There is no specific character count limit, but if your chapter exceeds 1MB it will be rejected. You will probably never run into this."}]),"view/chapter-edit/create/title":_=>c([{content:"Create chapter"}]),"view/chapter-edit/create/submit":(...a) => q["shared/action/create"](...a),"view/chapter-edit/update/title":_=>c([{content:"Edit chapter"}]),"view/chapter-edit/update/submit":(...a) => q["shared/action/save"](...a),"view/chapter-edit/update/action/delete":_=>c([{content:"Delete Chapter"}]),"view/chapter/title":(...a)=>c([...a[0]?[{content:a[0]},{content:". "}]:[],{content:a[1]}]),};exports.default=q}) \ No newline at end of file diff --git a/oembed.json b/oembed.json new file mode 100644 index 0000000..1c06a0c --- /dev/null +++ b/oembed.json @@ -0,0 +1,6 @@ +{ + "author_name": "Tell your story!", + "provider_name": "fluff4.me", + "provider_url": "https://fluff4.me", + "type": "photo" +} \ No newline at end of file diff --git a/style/index.css b/style/index.css new file mode 100644 index 0000000..ae0f3b7 --- /dev/null +++ b/style/index.css @@ -0,0 +1,2743 @@ +@import url("https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"); +@import url("https://fonts.googleapis.com/css2?family=Kanit&display=swap"); + +@property --transition-duration { + syntax: "