UNPKG

@21epub/epub-thirdparty

Version:
89 lines (88 loc) 3.4 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Describes what to do with the indentation when pressing Enter. */ export var IndentAction; (function (IndentAction) { /** * Insert new line and copy the previous line's indentation. */ IndentAction[IndentAction["None"] = 0] = "None"; /** * Insert new line and indent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Indent"] = 1] = "Indent"; /** * Insert two new lines: * - the first one indented which will hold the cursor * - the second one at the same indentation level */ IndentAction[IndentAction["IndentOutdent"] = 2] = "IndentOutdent"; /** * Insert new line and outdent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Outdent"] = 3] = "Outdent"; })(IndentAction || (IndentAction = {})); /** * @internal */ export class StandardAutoClosingPairConditional { constructor(source) { this._standardAutoClosingPairConditionalBrand = undefined; this.open = source.open; this.close = source.close; // initially allowed in all tokens this._standardTokenMask = 0; if (Array.isArray(source.notIn)) { for (let i = 0, len = source.notIn.length; i < len; i++) { const notIn = source.notIn[i]; switch (notIn) { case 'string': this._standardTokenMask |= 2 /* String */; break; case 'comment': this._standardTokenMask |= 1 /* Comment */; break; case 'regex': this._standardTokenMask |= 4 /* RegEx */; break; } } } } isOK(standardToken) { return (this._standardTokenMask & standardToken) === 0; } } /** * @internal */ export class AutoClosingPairs { constructor(autoClosingPairs) { this.autoClosingPairsOpenByStart = new Map(); this.autoClosingPairsOpenByEnd = new Map(); this.autoClosingPairsCloseByStart = new Map(); this.autoClosingPairsCloseByEnd = new Map(); this.autoClosingPairsCloseSingleChar = new Map(); for (const pair of autoClosingPairs) { appendEntry(this.autoClosingPairsOpenByStart, pair.open.charAt(0), pair); appendEntry(this.autoClosingPairsOpenByEnd, pair.open.charAt(pair.open.length - 1), pair); appendEntry(this.autoClosingPairsCloseByStart, pair.close.charAt(0), pair); appendEntry(this.autoClosingPairsCloseByEnd, pair.close.charAt(pair.close.length - 1), pair); if (pair.close.length === 1 && pair.open.length === 1) { appendEntry(this.autoClosingPairsCloseSingleChar, pair.close, pair); } } } } function appendEntry(target, key, value) { if (target.has(key)) { target.get(key).push(value); } else { target.set(key, [value]); } }