Icard/angular-clarity-master(work.../node_modules/css-line-break/dist/css-line-break.es5.js

707 lines
80 KiB
JavaScript
Raw Permalink Normal View History

2024-07-16 14:55:36 +00:00
/*
* css-line-break 2.1.0 <https://github.com/niklasvh/css-line-break#readme>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
var toCodePoints = function (str) {
var codePoints = [];
var i = 0;
var length = str.length;
while (i < length) {
var value = str.charCodeAt(i++);
if (value >= 0xd800 && value <= 0xdbff && i < length) {
var extra = str.charCodeAt(i++);
if ((extra & 0xfc00) === 0xdc00) {
codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
}
else {
codePoints.push(value);
i--;
}
}
else {
codePoints.push(value);
}
}
return codePoints;
};
var fromCodePoint = function () {
var codePoints = [];
for (var _i = 0; _i < arguments.length; _i++) {
codePoints[_i] = arguments[_i];
}
if (String.fromCodePoint) {
return String.fromCodePoint.apply(String, codePoints);
}
var length = codePoints.length;
if (!length) {
return '';
}
var codeUnits = [];
var index = -1;
var result = '';
while (++index < length) {
var codePoint = codePoints[index];
if (codePoint <= 0xffff) {
codeUnits.push(codePoint);
}
else {
codePoint -= 0x10000;
codeUnits.push((codePoint >> 10) + 0xd800, (codePoint % 0x400) + 0xdc00);
}
if (index + 1 === length || codeUnits.length > 0x4000) {
result += String.fromCharCode.apply(String, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
var chars$2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup$2 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i$2 = 0; i$2 < chars$2.length; i$2++) {
lookup$2[chars$2.charCodeAt(i$2)] = i$2;
}
/*
* utrie 1.0.2 <https://github.com/niklasvh/utrie>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i$1 = 0; i$1 < chars$1.length; i$1++) {
lookup$1[chars$1.charCodeAt(i$1)] = i$1;
}
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var buffer = typeof ArrayBuffer !== 'undefined' &&
typeof Uint8Array !== 'undefined' &&
typeof Uint8Array.prototype.slice !== 'undefined'
? new ArrayBuffer(bufferLength)
: new Array(bufferLength);
var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup$1[base64.charCodeAt(i)];
encoded2 = lookup$1[base64.charCodeAt(i + 1)];
encoded3 = lookup$1[base64.charCodeAt(i + 2)];
encoded4 = lookup$1[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return buffer;
};
var polyUint16Array = function (buffer) {
var length = buffer.length;
var bytes = [];
for (var i = 0; i < length; i += 2) {
bytes.push((buffer[i + 1] << 8) | buffer[i]);
}
return bytes;
};
var polyUint32Array = function (buffer) {
var length = buffer.length;
var bytes = [];
for (var i = 0; i < length; i += 4) {
bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]);
}
return bytes;
};
/** Shift size for getting the index-2 table offset. */
var UTRIE2_SHIFT_2 = 5;
/** Shift size for getting the index-1 table offset. */
var UTRIE2_SHIFT_1 = 6 + 5;
/**
* Shift size for shifting left the index array values.
* Increases possible data size with 16-bit index values at the cost
* of compactability.
* This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY.
*/
var UTRIE2_INDEX_SHIFT = 2;
/**
* Difference between the two shift sizes,
* for getting an index-1 offset from an index-2 offset. 6=11-5
*/
var UTRIE2_SHIFT_1_2 = UTRIE2_SHIFT_1 - UTRIE2_SHIFT_2;
/**
* The part of the index-2 table for U+D800..U+DBFF stores values for
* lead surrogate code _units_ not code _points_.
* Values for lead surrogate code _points_ are indexed with this portion of the table.
* Length=32=0x20=0x400>>UTRIE2_SHIFT_2. (There are 1024=0x400 lead surrogates.)
*/
var UTRIE2_LSCP_INDEX_2_OFFSET = 0x10000 >> UTRIE2_SHIFT_2;
/** Number of entries in a data block. 32=0x20 */
var UTRIE2_DATA_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_2;
/** Mask for getting the lower bits for the in-data-block offset. */
var UTRIE2_DATA_MASK = UTRIE2_DATA_BLOCK_LENGTH - 1;
var UTRIE2_LSCP_INDEX_2_LENGTH = 0x400 >> UTRIE2_SHIFT_2;
/** Count the lengths of both BMP pieces. 2080=0x820 */
var UTRIE2_INDEX_2_BMP_LENGTH = UTRIE2_LSCP_INDEX_2_OFFSET + UTRIE2_LSCP_INDEX_2_LENGTH;
/**
* The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820.
* Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2.
*/
var UTRIE2_UTF8_2B_INDEX_2_OFFSET = UTRIE2_INDEX_2_BMP_LENGTH;
var UTRIE2_UTF8_2B_INDEX_2_LENGTH = 0x800 >> 6; /* U+0800 is the first code point after 2-byte UTF-8 */
/**
* The index-1 table, only used for supplementary code points, at offset 2112=0x840.
* Variable length, for code points up to highStart, where the last single-value range starts.
* Maximum length 512=0x200=0x100000>>UTRIE2_SHIFT_1.
* (For 0x100000 supplementary code points U+10000..U+10ffff.)
*
* The part of the index-2 table for supplementary code points starts
* after this index-1 table.
*
* Both the index-1 table and the following part of the index-2 table
* are omitted completely if there is only BMP data.
*/
var UTRIE2_INDEX_1_OFFSET = UTRIE2_UTF8_2B_INDEX_2_OFFSET + UTRIE2_UTF8_2B_INDEX_2_LENGTH;
/**
* Number of index-1 entries for the BMP. 32=0x20
* This part of the index-1 table is omitted from the serialized form.
*/
var UTRIE2_OMITTED_BMP_INDEX_1_LENGTH = 0x10000 >> UTRIE2_SHIFT_1;
/** Number of entries in an index-2 block. 64=0x40 */
var UTRIE2_INDEX_2_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_1_2;
/** Mask for getting the lower bits for the in-index-2-block offset. */
var UTRIE2_INDEX_2_MASK = UTRIE2_INDEX_2_BLOCK_LENGTH - 1;
var slice16 = function (view, start, end) {
if (view.slice) {
return view.slice(start, end);
}
return new Uint16Array(Array.prototype.slice.call(view, start, end));
};
var slice32 = function (view, start, end) {
if (view.slice) {
return view.slice(start, end);
}
return new Uint32Array(Array.prototype.slice.call(view, start, end));
};
var createTrieFromBase64 = function (base64, _byteLength) {
var buffer = decode(base64);
var view32 = Array.isArray(buffer) ? polyUint32Array(buffer) : new Uint32Array(buffer);
var view16 = Array.isArray(buffer) ? polyUint16Array(buffer) : new Uint16Array(buffer);
var headerLength = 24;
var index = slice16(view16, headerLength / 2, view32[4] / 2);
var data = view32[5] === 2
? slice16(view16, (headerLength + view32[4]) / 2)
: slice32(view32, Math.ceil((headerLength + view32[4]) / 4));
return new Trie(view32[0], view32[1], view32[2], view32[3], index, data);
};
var Trie = /** @class */ (function () {
function Trie(initialValue, errorValue, highStart, highValueIndex, index, data) {
this.initialValue = initialValue;
this.errorValue = errorValue;
this.highStart = highStart;
this.highValueIndex = highValueIndex;
this.index = index;
this.data = data;
}
/**
* Get the value for a code point as stored in the Trie.
*
* @param codePoint the code point
* @return the value
*/
Trie.prototype.get = function (codePoint) {
var ix;
if (codePoint >= 0) {
if (codePoint < 0x0d800 || (codePoint > 0x0dbff && codePoint <= 0x0ffff)) {
// Ordinary BMP code point, excluding leading surrogates.
// BMP uses a single level lookup. BMP index starts at offset 0 in the Trie2 index.
// 16 bit data is stored in the index array itself.
ix = this.index[codePoint >> UTRIE2_SHIFT_2];
ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
return this.data[ix];
}
if (codePoint <= 0xffff) {
// Lead Surrogate Code Point. A Separate index section is stored for
// lead surrogate code units and code points.
// The main index has the code unit data.
// For this function, we need the code point data.
// Note: this expression could be refactored for slightly improved efficiency, but
// surrogate code points will be so rare in practice that it's not worth it.
ix = this.index[UTRIE2_LSCP_INDEX_2_OFFSET + ((codePoint - 0xd800) >> UTRIE2_SHIFT_2)];
ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
return this.data[ix];
}
if (codePoint < this.highStart) {
// Supplemental code point, use two-level lookup.
ix = UTRIE2_INDEX_1_OFFSET - UTRIE2_OMITTED_BMP_INDEX_1_LENGTH + (codePoint >> UTRIE2_SHIFT_1);
ix = this.index[ix];
ix += (codePoint >> UTRIE2_SHIFT_2) & UTRIE2_INDEX_2_MASK;
ix = this.index[ix];
ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
return this.data[ix];
}
if (codePoint <= 0x10ffff) {
return this.data[this.highValueIndex];
}
}
// Fall through. The code point is outside of the legal range of 0..0x10ffff.
return this.errorValue;
};
return Trie;
}());
/*
* base64-arraybuffer 1.0.2 <https://github.com/niklasvh/base64-arraybuffer>
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
* Released under MIT License
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var base64 = 'KwAAAAAAAAAACA4AUD0AADAgAAACAAAAAAAIABAAGABAAEgAUABYAGAAaABgAGgAYgBqAF8AZwBgAGgAcQB5AHUAfQCFAI0AlQCdAKIAqgCyALoAYABoAGAAaABgAGgAwgDKAGAAaADGAM4A0wDbAOEA6QDxAPkAAQEJAQ8BFwF1AH0AHAEkASwBNAE6AUIBQQFJAVEBWQFhAWgBcAF4ATAAgAGGAY4BlQGXAZ8BpwGvAbUBvQHFAc0B0wHbAeMB6wHxAfkBAQIJAvEBEQIZAiECKQIxAjgCQAJGAk4CVgJeAmQCbAJ0AnwCgQKJApECmQKgAqgCsAK4ArwCxAIwAMwC0wLbAjAA4wLrAvMC+AIAAwcDDwMwABcDHQMlAy0DNQN1AD0DQQNJA0kDSQNRA1EDVwNZA1kDdQB1AGEDdQBpA20DdQN1AHsDdQCBA4kDkQN1AHUAmQOhA3UAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AKYDrgN1AHUAtgO+A8YDzgPWAxcD3gPjA+sD8wN1AHUA+wMDBAkEdQANBBUEHQQlBCoEFwMyBDgEYABABBcDSARQBFgEYARoBDAAcAQzAXgEgASIBJAEdQCXBHUAnwSnBK4EtgS6BMIEyAR1AHUAdQB1AHUAdQCVANAEYABgAGAAYABgAGAAYABgANgEYADcBOQEYADsBPQE/AQEBQwFFAUcBSQFLAU0BWQEPAVEBUsFUwVbBWAAYgVgAGoFcgV6BYIFigWRBWAAmQWfBaYFYABgAGAAYABgAKoFYACxBbAFuQW6BcEFwQXHBcEFwQXPBdMF2wXjBeoF8gX6BQIGCgYSBhoGIgYqBjIGOgZgAD4GRgZMBmAAUwZaBmAAYABgAGAAYABgAGAAYABgAGAAYABgAGIGYABpBnAGYABgAGAAYABgAGAAYABgAGAAYAB4Bn8GhQZgAGAAYAB1AHcDFQSLBmAAYABgAJMGdQA9A3UAmwajBqsGqwaVALMGuwbDBjAAywbSBtIG1QbSBtIG0gbSBtIG0gbdBuMG6wbzBvsGAwcLBxMHAwcbByMHJwcsBywHMQcsB9IGOAdAB0gHTgfSBkgHVgfSBtIG0gbSBtIG0gbSBtIG0gbSBiwHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAdgAGAALAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAdbB2MHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsB2kH0gZwB64EdQB1AHUAdQB1AHUAdQB1AHUHfQdgAIUHjQd1AHUAlQedB2AAYAClB6sHYACzB7YHvgfGB3UAzgfWBzMB3gfmB1EB7gf1B/0HlQENAQUIDQh1ABUIHQglCBcDLQg1CD0IRQhNCEEDUwh1AHUAdQBbCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZ
var LETTER_NUMBER_MODIFIER = 50;
// Non-tailorable Line Breaking Classes
var BK = 1; // Cause a line break (after)
var CR = 2; // Cause a line break (after), except between CR and LF
var LF = 3; // Cause a line break (after)
var CM = 4; // Prohibit a line break between the character and the preceding character
var NL = 5; // Cause a line break (after)
var WJ = 7; // Prohibit line breaks before and after
var ZW = 8; // Provide a break opportunity
var GL = 9; // Prohibit line breaks before and after
var SP = 10; // Enable indirect line breaks
var ZWJ = 11; // Prohibit line breaks within joiner sequences
// Break Opportunities
var B2 = 12; // Provide a line break opportunity before and after the character
var BA = 13; // Generally provide a line break opportunity after the character
var BB = 14; // Generally provide a line break opportunity before the character
var HY = 15; // Provide a line break opportunity after the character, except in numeric context
var CB = 16; // Provide a line break opportunity contingent on additional information
// Characters Prohibiting Certain Breaks
var CL = 17; // Prohibit line breaks before
var CP = 18; // Prohibit line breaks before
var EX = 19; // Prohibit line breaks before
var IN = 20; // Allow only indirect line breaks between pairs
var NS = 21; // Allow only indirect line breaks before
var OP = 22; // Prohibit line breaks after
var QU = 23; // Act like they are both opening and closing
// Numeric Context
var IS = 24; // Prevent breaks after any and before numeric
var NU = 25; // Form numeric expressions for line breaking purposes
var PO = 26; // Do not break following a numeric expression
var PR = 27; // Do not break in front of a numeric expression
var SY = 28; // Prevent a break before; and allow a break after
// Other Characters
var AI = 29; // Act like AL when the resolvedEAW is N; otherwise; act as ID
var AL = 30; // Are alphabetic characters or symbols that are used with alphabetic characters
var CJ = 31; // Treat as NS or ID for strict or normal breaking.
var EB = 32; // Do not break from following Emoji Modifier
var EM = 33; // Do not break from preceding Emoji Base
var H2 = 34; // Form Korean syllable blocks
var H3 = 35; // Form Korean syllable blocks
var HL = 36; // Do not break around a following hyphen; otherwise act as Alphabetic
var ID = 37; // Break before or after; except in some numeric context
var JL = 38; // Form Korean syllable blocks
var JV = 39; // Form Korean syllable blocks
var JT = 40; // Form Korean syllable blocks
var RI = 41; // Keep pairs together. For pairs; break before and after other classes
var SA = 42; // Provide a line break opportunity contingent on additional, language-specific context analysis
var XX = 43; // Have as yet unknown line breaking behavior or unassigned code positions
var ea_OP = [0x2329, 0xff08];
var BREAK_MANDATORY = '!';
var BREAK_NOT_ALLOWED = '×';
var BREAK_ALLOWED = '÷';
var UnicodeTrie = createTrieFromBase64(base64);
var ALPHABETICS = [AL, HL];
var HARD_LINE_BREAKS = [BK, CR, LF, NL];
var SPACE = [SP, ZW];
var PREFIX_POSTFIX = [PR, PO];
var LINE_BREAKS = HARD_LINE_BREAKS.concat(SPACE);
var KOREAN_SYLLABLE_BLOCK = [JL, JV, JT, H2, H3];
var HYPHEN = [HY, BA];
var codePointsToCharacterClasses = function (codePoints, lineBreak) {
if (lineBreak === void 0) { lineBreak = 'strict'; }
var types = [];
var indices = [];
var categories = [];
codePoints.forEach(function (codePoint, index) {
var classType = UnicodeTrie.get(codePoint);
if (classType > LETTER_NUMBER_MODIFIER) {
categories.push(true);
classType -= LETTER_NUMBER_MODIFIER;
}
else {
categories.push(false);
}
if (['normal', 'auto', 'loose'].indexOf(lineBreak) !== -1) {
// U+2010, U+2013, 〜 U+301C, U+30A0
if ([0x2010, 0x2013, 0x301c, 0x30a0].indexOf(codePoint) !== -1) {
indices.push(index);
return types.push(CB);
}
}
if (classType === CM || classType === ZWJ) {
// LB10 Treat any remaining combining mark or ZWJ as AL.
if (index === 0) {
indices.push(index);
return types.push(AL);
}
// LB9 Do not break a combining character sequence; treat it as if it has the line breaking class of
// the base character in all of the following rules. Treat ZWJ as if it were CM.
var prev = types[index - 1];
if (LINE_BREAKS.indexOf(prev) === -1) {
indices.push(indices[index - 1]);
return types.push(prev);
}
indices.push(index);
return types.push(AL);
}
indices.push(index);
if (classType === CJ) {
return types.push(lineBreak === 'strict' ? NS : ID);
}
if (classType === SA) {
return types.push(AL);
}
if (classType === AI) {
return types.push(AL);
}
// For supplementary characters, a useful default is to treat characters in the range 10000..1FFFD as AL
// and characters in the ranges 20000..2FFFD and 30000..3FFFD as ID, until the implementation can be revised
// to take into account the actual line breaking properties for these characters.
if (classType === XX) {
if ((codePoint >= 0x20000 && codePoint <= 0x2fffd) || (codePoint >= 0x30000 && codePoint <= 0x3fffd)) {
return types.push(ID);
}
else {
return types.push(AL);
}
}
types.push(classType);
});
return [indices, types, categories];
};
var isAdjacentWithSpaceIgnored = function (a, b, currentIndex, classTypes) {
var current = classTypes[currentIndex];
if (Array.isArray(a) ? a.indexOf(current) !== -1 : a === current) {
var i = currentIndex;
while (i <= classTypes.length) {
i++;
var next = classTypes[i];
if (next === b) {
return true;
}
if (next !== SP) {
break;
}
}
}
if (current === SP) {
var i = currentIndex;
while (i > 0) {
i--;
var prev = classTypes[i];
if (Array.isArray(a) ? a.indexOf(prev) !== -1 : a === prev) {
var n = currentIndex;
while (n <= classTypes.length) {
n++;
var next = classTypes[n];
if (next === b) {
return true;
}
if (next !== SP) {
break;
}
}
}
if (prev !== SP) {
break;
}
}
}
return false;
};
var previousNonSpaceClassType = function (currentIndex, classTypes) {
var i = currentIndex;
while (i >= 0) {
var type = classTypes[i];
if (type === SP) {
i--;
}
else {
return type;
}
}
return 0;
};
var _lineBreakAtIndex = function (codePoints, classTypes, indicies, index, forbiddenBreaks) {
if (indicies[index] === 0) {
return BREAK_NOT_ALLOWED;
}
var currentIndex = index - 1;
if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) {
return BREAK_NOT_ALLOWED;
}
var beforeIndex = currentIndex - 1;
var afterIndex = currentIndex + 1;
var current = classTypes[currentIndex];
// LB4 Always break after hard line breaks.
// LB5 Treat CR followed by LF, as well as CR, LF, and NL as hard line breaks.
var before = beforeIndex >= 0 ? classTypes[beforeIndex] : 0;
var next = classTypes[afterIndex];
if (current === CR && next === LF) {
return BREAK_NOT_ALLOWED;
}
if (HARD_LINE_BREAKS.indexOf(current) !== -1) {
return BREAK_MANDATORY;
}
// LB6 Do not break before hard line breaks.
if (HARD_LINE_BREAKS.indexOf(next) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB7 Do not break before spaces or zero width space.
if (SPACE.indexOf(next) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB8 Break before any character following a zero-width space, even if one or more spaces intervene.
if (previousNonSpaceClassType(currentIndex, classTypes) === ZW) {
return BREAK_ALLOWED;
}
// LB8a Do not break after a zero width joiner.
if (UnicodeTrie.get(codePoints[currentIndex]) === ZWJ) {
return BREAK_NOT_ALLOWED;
}
// zwj emojis
if ((current === EB || current === EM) && UnicodeTrie.get(codePoints[afterIndex]) === ZWJ) {
return BREAK_NOT_ALLOWED;
}
// LB11 Do not break before or after Word joiner and related characters.
if (current === WJ || next === WJ) {
return BREAK_NOT_ALLOWED;
}
// LB12 Do not break after NBSP and related characters.
if (current === GL) {
return BREAK_NOT_ALLOWED;
}
// LB12a Do not break before NBSP and related characters, except after spaces and hyphens.
if ([SP, BA, HY].indexOf(current) === -1 && next === GL) {
return BREAK_NOT_ALLOWED;
}
// LB13 Do not break before ] or ! or ; or /, even after spaces.
if ([CL, CP, EX, IS, SY].indexOf(next) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB14 Do not break after [, even after spaces.
if (previousNonSpaceClassType(currentIndex, classTypes) === OP) {
return BREAK_NOT_ALLOWED;
}
// LB15 Do not break within ‘”[, even with intervening spaces.
if (isAdjacentWithSpaceIgnored(QU, OP, currentIndex, classTypes)) {
return BREAK_NOT_ALLOWED;
}
// LB16 Do not break between closing punctuation and a nonstarter (lb=NS), even with intervening spaces.
if (isAdjacentWithSpaceIgnored([CL, CP], NS, currentIndex, classTypes)) {
return BREAK_NOT_ALLOWED;
}
// LB17 Do not break within ‘——’, even with intervening spaces.
if (isAdjacentWithSpaceIgnored(B2, B2, currentIndex, classTypes)) {
return BREAK_NOT_ALLOWED;
}
// LB18 Break after spaces.
if (current === SP) {
return BREAK_ALLOWED;
}
// LB19 Do not break before or after quotation marks, such as .
if (current === QU || next === QU) {
return BREAK_NOT_ALLOWED;
}
// LB20 Break before and after unresolved CB.
if (next === CB || current === CB) {
return BREAK_ALLOWED;
}
// LB21 Do not break before hyphen-minus, other hyphens, fixed-width spaces, small kana, and other non-starters, or after acute accents.
if ([BA, HY, NS].indexOf(next) !== -1 || current === BB) {
return BREAK_NOT_ALLOWED;
}
// LB21a Don't break after Hebrew + Hyphen.
if (before === HL && HYPHEN.indexOf(current) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB21b Dont break between Solidus and Hebrew letters.
if (current === SY && next === HL) {
return BREAK_NOT_ALLOWED;
}
// LB22 Do not break before ellipsis.
if (next === IN) {
return BREAK_NOT_ALLOWED;
}
// LB23 Do not break between digits and letters.
if ((ALPHABETICS.indexOf(next) !== -1 && current === NU) || (ALPHABETICS.indexOf(current) !== -1 && next === NU)) {
return BREAK_NOT_ALLOWED;
}
// LB23a Do not break between numeric prefixes and ideographs, or between ideographs and numeric postfixes.
if ((current === PR && [ID, EB, EM].indexOf(next) !== -1) ||
([ID, EB, EM].indexOf(current) !== -1 && next === PO)) {
return BREAK_NOT_ALLOWED;
}
// LB24 Do not break between numeric prefix/postfix and letters, or between letters and prefix/postfix.
if ((ALPHABETICS.indexOf(current) !== -1 && PREFIX_POSTFIX.indexOf(next) !== -1) ||
(PREFIX_POSTFIX.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1)) {
return BREAK_NOT_ALLOWED;
}
// LB25 Do not break between the following pairs of classes relevant to numbers:
if (
// (PR | PO) × ( OP | HY )? NU
([PR, PO].indexOf(current) !== -1 &&
(next === NU || ([OP, HY].indexOf(next) !== -1 && classTypes[afterIndex + 1] === NU))) ||
// ( OP | HY ) × NU
([OP, HY].indexOf(current) !== -1 && next === NU) ||
// NU × (NU | SY | IS)
(current === NU && [NU, SY, IS].indexOf(next) !== -1)) {
return BREAK_NOT_ALLOWED;
}
// NU (NU | SY | IS)* × (NU | SY | IS | CL | CP)
if ([NU, SY, IS, CL, CP].indexOf(next) !== -1) {
var prevIndex = currentIndex;
while (prevIndex >= 0) {
var type = classTypes[prevIndex];
if (type === NU) {
return BREAK_NOT_ALLOWED;
}
else if ([SY, IS].indexOf(type) !== -1) {
prevIndex--;
}
else {
break;
}
}
}
// NU (NU | SY | IS)* (CL | CP)? × (PO | PR))
if ([PR, PO].indexOf(next) !== -1) {
var prevIndex = [CL, CP].indexOf(current) !== -1 ? beforeIndex : currentIndex;
while (prevIndex >= 0) {
var type = classTypes[prevIndex];
if (type === NU) {
return BREAK_NOT_ALLOWED;
}
else if ([SY, IS].indexOf(type) !== -1) {
prevIndex--;
}
else {
break;
}
}
}
// LB26 Do not break a Korean syllable.
if ((JL === current && [JL, JV, H2, H3].indexOf(next) !== -1) ||
([JV, H2].indexOf(current) !== -1 && [JV, JT].indexOf(next) !== -1) ||
([JT, H3].indexOf(current) !== -1 && next === JT)) {
return BREAK_NOT_ALLOWED;
}
// LB27 Treat a Korean Syllable Block the same as ID.
if ((KOREAN_SYLLABLE_BLOCK.indexOf(current) !== -1 && [IN, PO].indexOf(next) !== -1) ||
(KOREAN_SYLLABLE_BLOCK.indexOf(next) !== -1 && current === PR)) {
return BREAK_NOT_ALLOWED;
}
// LB28 Do not break between alphabetics (“at”).
if (ALPHABETICS.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB29 Do not break between numeric punctuation and alphabetics (“e.g.”).
if (current === IS && ALPHABETICS.indexOf(next) !== -1) {
return BREAK_NOT_ALLOWED;
}
// LB30 Do not break between letters, numbers, or ordinary symbols and opening or closing parentheses.
if ((ALPHABETICS.concat(NU).indexOf(current) !== -1 &&
next === OP &&
ea_OP.indexOf(codePoints[afterIndex]) === -1) ||
(ALPHABETICS.concat(NU).indexOf(next) !== -1 && current === CP)) {
return BREAK_NOT_ALLOWED;
}
// LB30a Break between two regional indicator symbols if and only if there are an even number of regional
// indicators preceding the position of the break.
if (current === RI && next === RI) {
var i = indicies[currentIndex];
var count = 1;
while (i > 0) {
i--;
if (classTypes[i] === RI) {
count++;
}
else {
break;
}
}
if (count % 2 !== 0) {
return BREAK_NOT_ALLOWED;
}
}
// LB30b Do not break between an emoji base and an emoji modifier.
if (current === EB && next === EM) {
return BREAK_NOT_ALLOWED;
}
return BREAK_ALLOWED;
};
var cssFormattedClasses = function (codePoints, options) {
if (!options) {
options = { lineBreak: 'normal', wordBreak: 'normal' };
}
var _a = codePointsToCharacterClasses(codePoints, options.lineBreak), indicies = _a[0], classTypes = _a[1], isLetterNumber = _a[2];
if (options.wordBreak === 'break-all' || options.wordBreak === 'break-word') {
classTypes = classTypes.map(function (type) { return ([NU, AL, SA].indexOf(type) !== -1 ? ID : type); });
}
var forbiddenBreakpoints = options.wordBreak === 'keep-all'
? isLetterNumber.map(function (letterNumber, i) {
return letterNumber && codePoints[i] >= 0x4e00 && codePoints[i] <= 0x9fff;
})
: undefined;
return [indicies, classTypes, forbiddenBreakpoints];
};
var Break = /** @class */ (function () {
function Break(codePoints, lineBreak, start, end) {
this.codePoints = codePoints;
this.required = lineBreak === BREAK_MANDATORY;
this.start = start;
this.end = end;
}
Break.prototype.slice = function () {
return fromCodePoint.apply(void 0, this.codePoints.slice(this.start, this.end));
};
return Break;
}());
var LineBreaker = function (str, options) {
var codePoints = toCodePoints(str);
var _a = cssFormattedClasses(codePoints, options), indicies = _a[0], classTypes = _a[1], forbiddenBreakpoints = _a[2];
var length = codePoints.length;
var lastEnd = 0;
var nextIndex = 0;
return {
next: function () {
if (nextIndex >= length) {
return { done: true, value: null };
}
var lineBreak = BREAK_NOT_ALLOWED;
while (nextIndex < length &&
(lineBreak = _lineBreakAtIndex(codePoints, classTypes, indicies, ++nextIndex, forbiddenBreakpoints)) ===
BREAK_NOT_ALLOWED) { }
if (lineBreak !== BREAK_NOT_ALLOWED || nextIndex === length) {
var value = new Break(codePoints, lineBreak, lastEnd, nextIndex);
lastEnd = nextIndex;
return { value: value, done: false };
}
return { done: true, value: null };
},
};
};
export { LineBreaker, fromCodePoint, toCodePoints };
//# sourceMappingURL=css-line-break.es5.js.map