Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/wrap-ansi/index.js

    r59329aa re29cc2e  
    1111const END_CODE = 39;
    1212
    13 const ANSI_ESCAPE_BELL = '\u0007';
    14 const ANSI_CSI = '[';
    15 const ANSI_OSC = ']';
    16 const ANSI_SGR_TERMINATOR = 'm';
    17 const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
    18 
    19 const wrapAnsi = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
    20 const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;
     13const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`;
    2114
    2215// Calculate the length of words split on ' ', ignoring
     
    2922        const characters = [...word];
    3023
    31         let isInsideEscape = false;
    32         let isInsideLinkEscape = false;
     24        let insideEscape = false;
    3325        let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
    3426
     
    4436
    4537                if (ESCAPES.has(character)) {
    46                         isInsideEscape = true;
    47                         isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK);
     38                        insideEscape = true;
     39                } else if (insideEscape && character === 'm') {
     40                        insideEscape = false;
     41                        continue;
    4842                }
    4943
    50                 if (isInsideEscape) {
    51                         if (isInsideLinkEscape) {
    52                                 if (character === ANSI_ESCAPE_BELL) {
    53                                         isInsideEscape = false;
    54                                         isInsideLinkEscape = false;
    55                                 }
    56                         } else if (character === ANSI_SGR_TERMINATOR) {
    57                                 isInsideEscape = false;
    58                         }
    59 
     44                if (insideEscape) {
    6045                        continue;
    6146                }
     
    7762
    7863// Trims spaces from a string ignoring invisible sequences
    79 const stringVisibleTrimSpacesRight = string => {
    80         const words = string.split(' ');
     64const stringVisibleTrimSpacesRight = str => {
     65        const words = str.split(' ');
    8166        let last = words.length;
    8267
     
    9075
    9176        if (last === words.length) {
    92                 return string;
     77                return str;
    9378        }
    9479
     
    9681};
    9782
    98 // The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
     83// The wrap-ansi module can be invoked
     84// in either 'hard' or 'soft' wrap mode
    9985//
    100 // 'hard' will never allow a string to take up more than columns characters
     86// 'hard' will never allow a string to take up more
     87// than columns characters
    10188//
    10289// 'soft' allows long words to expand past the column length
     
    10693        }
    10794
    108         let returnValue = '';
     95        let pre = '';
     96        let ret = '';
    10997        let escapeCode;
    110         let escapeUrl;
    11198
    11299        const lengths = wordLengths(string);
     
    115102        for (const [index, word] of string.split(' ').entries()) {
    116103                if (options.trim !== false) {
    117                         rows[rows.length - 1] = rows[rows.length - 1].trimStart();
     104                        rows[rows.length - 1] = rows[rows.length - 1].trimLeft();
    118105                }
    119106
     
    133120                }
    134121
    135                 // In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
     122                // In 'hard' wrap mode, the length of a line is
     123                // never allowed to extend past 'columns'
    136124                if (options.hard && lengths[index] > columns) {
    137125                        const remainingColumns = (columns - rowLength);
     
    167155        }
    168156
    169         const pre = [...rows.join('\n')];
     157        pre = rows.join('\n');
    170158
    171         for (const [index, character] of pre.entries()) {
    172                 returnValue += character;
     159        for (const [index, character] of [...pre].entries()) {
     160                ret += character;
    173161
    174162                if (ESCAPES.has(character)) {
    175                         const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
    176                         if (groups.code !== undefined) {
    177                                 const code = Number.parseFloat(groups.code);
    178                                 escapeCode = code === END_CODE ? undefined : code;
    179                         } else if (groups.uri !== undefined) {
    180                                 escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
    181                         }
     163                        const code = parseFloat(/\d[^m]*/.exec(pre.slice(index, index + 4)));
     164                        escapeCode = code === END_CODE ? null : code;
    182165                }
    183166
    184167                const code = ansiStyles.codes.get(Number(escapeCode));
    185168
    186                 if (pre[index + 1] === '\n') {
    187                         if (escapeUrl) {
    188                                 returnValue += wrapAnsiHyperlink('');
    189                         }
    190 
    191                         if (escapeCode && code) {
    192                                 returnValue += wrapAnsi(code);
    193                         }
    194                 } else if (character === '\n') {
    195                         if (escapeCode && code) {
    196                                 returnValue += wrapAnsi(escapeCode);
    197                         }
    198 
    199                         if (escapeUrl) {
    200                                 returnValue += wrapAnsiHyperlink(escapeUrl);
     169                if (escapeCode && code) {
     170                        if (pre[index + 1] === '\n') {
     171                                ret += wrapAnsi(code);
     172                        } else if (character === '\n') {
     173                                ret += wrapAnsi(escapeCode);
    201174                        }
    202175                }
    203176        }
    204177
    205         return returnValue;
     178        return ret;
    206179};
    207180
     
    210183        return String(string)
    211184                .normalize()
    212                 .replace(/\r\n/g, '\n')
    213185                .split('\n')
    214186                .map(line => exec(line, columns, options))
Note: See TracChangeset for help on using the changeset viewer.