@parcel/codeframe 2.8.3 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/codeframe.js CHANGED
@@ -35740,9 +35740,9 @@ $5f04f11630a6945d$exports = ({ onlyFirst: onlyFirst = false } = {})=>{
35740
35740
  $5e2cf9f740fe0527$exports = (string)=>typeof string === "string" ? string.replace($5f04f11630a6945d$exports(), "") : string;
35741
35741
 
35742
35742
 
35743
- var $e19c725c5553b196$exports = {};
35743
+ var $55a95b67e18839c0$exports = {};
35744
35744
  /* eslint-disable yoda */ "use strict";
35745
- const $e19c725c5553b196$var$isFullwidthCodePoint = (codePoint)=>{
35745
+ const $55a95b67e18839c0$var$isFullwidthCodePoint = (codePoint)=>{
35746
35746
  if (Number.isNaN(codePoint)) return false;
35747
35747
  // Code points are derived from:
35748
35748
  // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
@@ -35764,8 +35764,8 @@ const $e19c725c5553b196$var$isFullwidthCodePoint = (codePoint)=>{
35764
35764
  0x20000 <= codePoint && codePoint <= 0x3FFFD)) return true;
35765
35765
  return false;
35766
35766
  };
35767
- $e19c725c5553b196$exports = $e19c725c5553b196$var$isFullwidthCodePoint;
35768
- $e19c725c5553b196$exports.default = $e19c725c5553b196$var$isFullwidthCodePoint;
35767
+ $55a95b67e18839c0$exports = $55a95b67e18839c0$var$isFullwidthCodePoint;
35768
+ $55a95b67e18839c0$exports.default = $55a95b67e18839c0$var$isFullwidthCodePoint;
35769
35769
 
35770
35770
 
35771
35771
  var $aaafc2d9fc2c7f45$exports = {};
@@ -35777,9 +35777,10 @@ $aaafc2d9fc2c7f45$exports = function() {
35777
35777
 
35778
35778
 
35779
35779
  const $ae1b0396e51a6d8c$var$stringWidth = (string)=>{
35780
- string = string.replace($aaafc2d9fc2c7f45$exports(), " ");
35781
35780
  if (typeof string !== "string" || string.length === 0) return 0;
35782
35781
  string = $5e2cf9f740fe0527$exports(string);
35782
+ if (string.length === 0) return 0;
35783
+ string = string.replace($aaafc2d9fc2c7f45$exports(), " ");
35783
35784
  let width = 0;
35784
35785
  for(let i = 0; i < string.length; i++){
35785
35786
  const code = string.codePointAt(i);
@@ -35789,7 +35790,7 @@ const $ae1b0396e51a6d8c$var$stringWidth = (string)=>{
35789
35790
  if (code >= 0x300 && code <= 0x36F) continue;
35790
35791
  // Surrogates
35791
35792
  if (code > 0xFFFF) i++;
35792
- width += $e19c725c5553b196$exports(code) ? 2 : 1;
35793
+ width += $55a95b67e18839c0$exports(code) ? 2 : 1;
35793
35794
  }
35794
35795
  return width;
35795
35796
  };
@@ -35800,33 +35801,6 @@ $ae1b0396e51a6d8c$exports.default = $ae1b0396e51a6d8c$var$stringWidth;
35800
35801
 
35801
35802
  var $0ae586f9cf7cb410$exports = {};
35802
35803
  "use strict";
35803
- var $0926ce0154f25409$exports = {};
35804
- /* eslint-disable yoda */ "use strict";
35805
- const $0926ce0154f25409$var$isFullwidthCodePoint = (codePoint)=>{
35806
- if (Number.isNaN(codePoint)) return false;
35807
- // Code points are derived from:
35808
- // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
35809
- if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
35810
- codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
35811
- codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
35812
- // CJK Radicals Supplement .. Enclosed CJK Letters and Months
35813
- 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
35814
- 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
35815
- 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
35816
- 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
35817
- 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
35818
- 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
35819
- 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
35820
- 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
35821
- 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
35822
- 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
35823
- 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
35824
- 0x20000 <= codePoint && codePoint <= 0x3FFFD)) return true;
35825
- return false;
35826
- };
35827
- $0926ce0154f25409$exports = $0926ce0154f25409$var$isFullwidthCodePoint;
35828
- $0926ce0154f25409$exports.default = $0926ce0154f25409$var$isFullwidthCodePoint;
35829
-
35830
35804
 
35831
35805
  var $84440f8e6725c936$exports = {};
35832
35806
  "use strict";
@@ -35901,7 +35875,7 @@ $0ae586f9cf7cb410$exports = (string, begin, end)=>{
35901
35875
  if (!isInsideEscape && !leftEscape) visible++;
35902
35876
  if (!$84440f8e6725c936$exports({
35903
35877
  exact: true
35904
- }).test(character) && $0926ce0154f25409$exports(character.codePointAt())) {
35878
+ }).test(character) && $55a95b67e18839c0$exports(character.codePointAt())) {
35905
35879
  visible++;
35906
35880
  if (typeof end !== "number") stringEnd++;
35907
35881
  }
@@ -35923,7 +35897,9 @@ const $796233c1fee0ccb8$var$DEFAULT_TERMINAL_WIDTH = 80;
35923
35897
  const $796233c1fee0ccb8$var$highlightSyntax = (txt, lang)=>{
35924
35898
  if (lang) try {
35925
35899
  return (0, (/*@__PURE__*/$parcel$interopDefault($9786466eb6148e3d$exports))).highlight(lang, txt).value;
35926
- } catch (e) {}
35900
+ } catch (e) {
35901
+ // fallback for unknown languages...
35902
+ }
35927
35903
  return (0, (/*@__PURE__*/$parcel$interopDefault($9786466eb6148e3d$exports))).highlightAuto(txt).value;
35928
35904
  };
35929
35905
  function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts = {}) {
@@ -35939,18 +35915,21 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
35939
35915
  before: 1,
35940
35916
  after: 2
35941
35917
  }
35942
- }; // Highlights messages and prefixes when colors are enabled
35918
+ };
35919
+ // Highlights messages and prefixes when colors are enabled
35943
35920
  const highlighter = (s, bold)=>{
35944
35921
  if (opts.useColor) {
35945
35922
  let redString = (0, ($parcel$interopDefault($dGKPK$chalk))).red(s);
35946
35923
  return bold ? (0, ($parcel$interopDefault($dGKPK$chalk))).bold(redString) : redString;
35947
35924
  }
35948
35925
  return s;
35949
- }; // Prefix lines with the line number
35926
+ };
35927
+ // Prefix lines with the line number
35950
35928
  const lineNumberPrefixer = (params)=>{
35951
35929
  let { lineNumber: lineNumber , lineNumberLength: lineNumberLength , isHighlighted: isHighlighted } = params;
35952
35930
  return `${isHighlighted ? highlighter(">") : " "} ${lineNumber ? lineNumber.padStart(lineNumberLength, " ") : " ".repeat(lineNumberLength)} | `;
35953
- }; // Make columns/lines start at 1
35931
+ };
35932
+ // Make columns/lines start at 1
35954
35933
  let originalHighlights = highlights;
35955
35934
  highlights = highlights.map((h)=>{
35956
35935
  return {
@@ -35964,9 +35943,11 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
35964
35943
  },
35965
35944
  message: h.message
35966
35945
  };
35967
- }); // Find first and last highlight
35946
+ });
35947
+ // Find first and last highlight
35968
35948
  let firstHighlight = highlights.length > 1 ? highlights.sort((a, b)=>a.start.line - b.start.line)[0] : highlights[0];
35969
- let lastHighlight = highlights.length > 1 ? highlights.sort((a, b)=>b.end.line - a.end.line)[0] : highlights[0]; // Calculate first and last line index of codeframe
35949
+ let lastHighlight = highlights.length > 1 ? highlights.sort((a, b)=>b.end.line - a.end.line)[0] : highlights[0];
35950
+ // Calculate first and last line index of codeframe
35970
35951
  let startLine = firstHighlight.start.line - opts.padding.before;
35971
35952
  startLine = startLine < 0 ? 0 : startLine;
35972
35953
  let endLineIndex = lastHighlight.end.line + opts.padding.after;
@@ -35978,16 +35959,21 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
35978
35959
  endLineIndex = Math.min(maxLine, lastHighlight.end.line + opts.padding.after);
35979
35960
  tail = originalHighlights.filter((h)=>h.start.line > endLineIndex);
35980
35961
  }
35981
- let lineNumberLength = (endLineIndex + 1).toString(10).length; // Split input into lines and highlight syntax
35962
+ let lineNumberLength = (endLineIndex + 1).toString(10).length;
35963
+ // Split input into lines and highlight syntax
35982
35964
  let lines = code.split($796233c1fee0ccb8$var$NEWLINE);
35983
- let syntaxHighlightedLines = (opts.syntaxHighlighting ? $796233c1fee0ccb8$var$highlightSyntax(code, opts.language) : code).replace($796233c1fee0ccb8$var$TAB_REPLACE_REGEX, $796233c1fee0ccb8$var$TAB_REPLACEMENT).split($796233c1fee0ccb8$var$NEWLINE); // Loop over all lines and create codeframe
35965
+ let syntaxHighlightedLines = (opts.syntaxHighlighting ? $796233c1fee0ccb8$var$highlightSyntax(code, opts.language) : code).replace($796233c1fee0ccb8$var$TAB_REPLACE_REGEX, $796233c1fee0ccb8$var$TAB_REPLACEMENT).split($796233c1fee0ccb8$var$NEWLINE);
35966
+ // Loop over all lines and create codeframe
35984
35967
  let resultLines = [];
35985
35968
  for(let currentLineIndex = startLine; currentLineIndex < syntaxHighlightedLines.length; currentLineIndex++){
35986
35969
  if (currentLineIndex > endLineIndex) break;
35987
- if (currentLineIndex > syntaxHighlightedLines.length - 1) break; // Find highlights that need to get rendered on the current line
35988
- let lineHighlights = highlights.filter((highlight)=>highlight.start.line <= currentLineIndex && highlight.end.line >= currentLineIndex).sort((a, b)=>(a.start.line < currentLineIndex ? 0 : a.start.column) - (b.start.line < currentLineIndex ? 0 : b.start.column)); // Check if this line has a full line highlight
35970
+ if (currentLineIndex > syntaxHighlightedLines.length - 1) break;
35971
+ // Find highlights that need to get rendered on the current line
35972
+ let lineHighlights = highlights.filter((highlight)=>highlight.start.line <= currentLineIndex && highlight.end.line >= currentLineIndex).sort((a, b)=>(a.start.line < currentLineIndex ? 0 : a.start.column) - (b.start.line < currentLineIndex ? 0 : b.start.column));
35973
+ // Check if this line has a full line highlight
35989
35974
  let isWholeLine = lineHighlights.length && !!lineHighlights.find((h)=>h.start.line < currentLineIndex && h.end.line > currentLineIndex);
35990
- let lineLengthLimit = opts.terminalWidth > lineNumberLength + 7 ? opts.terminalWidth - (lineNumberLength + 5) : 10; // Split the line into line parts that will fit the provided terminal width
35975
+ let lineLengthLimit = opts.terminalWidth > lineNumberLength + 7 ? opts.terminalWidth - (lineNumberLength + 5) : 10;
35976
+ // Split the line into line parts that will fit the provided terminal width
35991
35977
  let colOffset = 0;
35992
35978
  let lineEndCol = lineLengthLimit;
35993
35979
  let syntaxHighlightedLine = syntaxHighlightedLines[currentLineIndex];
@@ -35999,7 +35985,8 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
35999
35985
  colOffset = colOffset > 0 ? colOffset : 0;
36000
35986
  lineEndCol = colOffset + lineLengthLimit;
36001
35987
  syntaxHighlightedLine = (0, (/*@__PURE__*/$parcel$interopDefault($0ae586f9cf7cb410$exports)))(syntaxHighlightedLine, colOffset, lineEndCol);
36002
- } // Write the syntax highlighted line part
35988
+ }
35989
+ // Write the syntax highlighted line part
36003
35990
  resultLines.push(lineNumberPrefixer({
36004
35991
  lineNumber: (currentLineIndex + 1).toString(10),
36005
35992
  lineNumberLength: lineNumberLength,
@@ -36015,18 +36002,21 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
36015
36002
  for(let highlightIndex = 0; highlightIndex < lineHighlights.length; highlightIndex++){
36016
36003
  // Set highlight to current highlight
36017
36004
  highlight = lineHighlights[highlightIndex];
36018
- highlightHasEnded = false; // Calculate the startColumn and get the real width by doing a substring of the original
36005
+ highlightHasEnded = false;
36006
+ // Calculate the startColumn and get the real width by doing a substring of the original
36019
36007
  // line and replacing tabs with our tab replacement to support tab handling
36020
36008
  let startCol = 0;
36021
36009
  if (highlight.start.line === currentLineIndex && highlight.start.column > colOffset) startCol = lines[currentLineIndex].substring(colOffset, highlight.start.column).replace($796233c1fee0ccb8$var$TAB_REPLACE_REGEX, $796233c1fee0ccb8$var$TAB_REPLACEMENT).length;
36022
- // Calculate the endColumn and get the real width by doing a substring of the original
36010
+ // Calculate the endColumn and get the real width by doing a substring of the original
36023
36011
  // line and replacing tabs with our tab replacement to support tab handling
36024
36012
  let endCol = lineWidth - 1;
36025
36013
  if (highlight.end.line === currentLineIndex) {
36026
- endCol = lines[currentLineIndex].substring(colOffset, highlight.end.column).replace($796233c1fee0ccb8$var$TAB_REPLACE_REGEX, $796233c1fee0ccb8$var$TAB_REPLACEMENT).length; // If the endCol is too big for this line part, trim it so we can handle it in the next one
36014
+ endCol = lines[currentLineIndex].substring(colOffset, highlight.end.column).replace($796233c1fee0ccb8$var$TAB_REPLACE_REGEX, $796233c1fee0ccb8$var$TAB_REPLACEMENT).length;
36015
+ // If the endCol is too big for this line part, trim it so we can handle it in the next one
36027
36016
  if (endCol > lineWidth) endCol = lineWidth - 1;
36028
36017
  highlightHasEnded = true;
36029
- } // If endcol is smaller than lastCol it overlaps with another highlight and is no longer visible, we can skip those
36018
+ }
36019
+ // If endcol is smaller than lastCol it overlaps with another highlight and is no longer visible, we can skip those
36030
36020
  if (endCol >= lastCol) {
36031
36021
  let characters = endCol - startCol + 1;
36032
36022
  if (startCol > lastCol) // startCol is before lastCol, so add spaces as padding before the highlight indicators
@@ -36034,12 +36024,15 @@ function $796233c1fee0ccb8$export$2e2bcd8739ae039(code, highlights, inputOpts =
36034
36024
  else if (lastCol > startCol) // If last column is larger than the start, there's overlap in highlights
36035
36025
  // This line adjusts the characters count to ensure we don't add too many characters
36036
36026
  characters += startCol - lastCol;
36037
- // Append the highlight indicators
36038
- highlightLine += highlighter("^".repeat(characters)); // Set the lastCol equal to character count between start of line part and highlight end-column
36027
+ // Append the highlight indicators
36028
+ highlightLine += highlighter("^".repeat(characters));
36029
+ // Set the lastCol equal to character count between start of line part and highlight end-column
36039
36030
  lastCol = endCol + 1;
36040
- } // There's no point in processing more highlights if we reached the end of the line
36031
+ }
36032
+ // There's no point in processing more highlights if we reached the end of the line
36041
36033
  if (endCol >= lineEndCol - 1) break;
36042
- } // Append the highlight message if the current highlights ends on this line part
36034
+ }
36035
+ // Append the highlight message if the current highlights ends on this line part
36043
36036
  if (highlight && highlight.message && highlightHasEnded) highlightLine += " " + highlighter(highlight.message, true);
36044
36037
  }
36045
36038
  if (highlightLine) resultLines.push(lineNumberPrefixer({