Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.codeFrameColumns = codeFrameColumns;
  6. exports.default = _default;
  7. var _highlight = _interopRequireWildcard(require("@babel/highlight"));
  8. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  9. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  10. let deprecationWarningShown = false;
  11. function getDefs(chalk) {
  12. return {
  13. gutter: chalk.grey,
  14. marker: chalk.red.bold,
  15. message: chalk.red.bold
  16. };
  17. }
  18. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  19. function getMarkerLines(loc, source, opts) {
  20. const startLoc = Object.assign({
  21. column: 0,
  22. line: -1
  23. }, loc.start);
  24. const endLoc = Object.assign({}, startLoc, loc.end);
  25. const {
  26. linesAbove = 2,
  27. linesBelow = 3
  28. } = opts || {};
  29. const startLine = startLoc.line;
  30. const startColumn = startLoc.column;
  31. const endLine = endLoc.line;
  32. const endColumn = endLoc.column;
  33. let start = Math.max(startLine - (linesAbove + 1), 0);
  34. let end = Math.min(source.length, endLine + linesBelow);
  35. if (startLine === -1) {
  36. start = 0;
  37. }
  38. if (endLine === -1) {
  39. end = source.length;
  40. }
  41. const lineDiff = endLine - startLine;
  42. const markerLines = {};
  43. if (lineDiff) {
  44. for (let i = 0; i <= lineDiff; i++) {
  45. const lineNumber = i + startLine;
  46. if (!startColumn) {
  47. markerLines[lineNumber] = true;
  48. } else if (i === 0) {
  49. const sourceLength = source[lineNumber - 1].length;
  50. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  51. } else if (i === lineDiff) {
  52. markerLines[lineNumber] = [0, endColumn];
  53. } else {
  54. const sourceLength = source[lineNumber - i].length;
  55. markerLines[lineNumber] = [0, sourceLength];
  56. }
  57. }
  58. } else {
  59. if (startColumn === endColumn) {
  60. if (startColumn) {
  61. markerLines[startLine] = [startColumn, 0];
  62. } else {
  63. markerLines[startLine] = true;
  64. }
  65. } else {
  66. markerLines[startLine] = [startColumn, endColumn - startColumn];
  67. }
  68. }
  69. return {
  70. start,
  71. end,
  72. markerLines
  73. };
  74. }
  75. function codeFrameColumns(rawLines, loc, opts = {}) {
  76. const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  77. const chalk = (0, _highlight.getChalk)(opts);
  78. const defs = getDefs(chalk);
  79. const maybeHighlight = (chalkFn, string) => {
  80. return highlighted ? chalkFn(string) : string;
  81. };
  82. const lines = rawLines.split(NEWLINE);
  83. const {
  84. start,
  85. end,
  86. markerLines
  87. } = getMarkerLines(loc, lines, opts);
  88. const hasColumns = loc.start && typeof loc.start.column === "number";
  89. const numberMaxWidth = String(end).length;
  90. const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
  91. let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
  92. const number = start + 1 + index;
  93. const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  94. const gutter = ` ${paddedNumber} | `;
  95. const hasMarker = markerLines[number];
  96. const lastMarkerLine = !markerLines[number + 1];
  97. if (hasMarker) {
  98. let markerLine = "";
  99. if (Array.isArray(hasMarker)) {
  100. const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  101. const numberOfMarkers = hasMarker[1] || 1;
  102. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  103. if (lastMarkerLine && opts.message) {
  104. markerLine += " " + maybeHighlight(defs.message, opts.message);
  105. }
  106. }
  107. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  108. } else {
  109. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  110. }
  111. }).join("\n");
  112. if (opts.message && !hasColumns) {
  113. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  114. }
  115. if (highlighted) {
  116. return chalk.reset(frame);
  117. } else {
  118. return frame;
  119. }
  120. }
  121. function _default(rawLines, lineNumber, colNumber, opts = {}) {
  122. if (!deprecationWarningShown) {
  123. deprecationWarningShown = true;
  124. const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  125. if (process.emitWarning) {
  126. process.emitWarning(message, "DeprecationWarning");
  127. } else {
  128. const deprecationError = new Error(message);
  129. deprecationError.name = "DeprecationWarning";
  130. console.warn(new Error(message));
  131. }
  132. }
  133. colNumber = Math.max(colNumber, 0);
  134. const location = {
  135. start: {
  136. column: colNumber,
  137. line: lineNumber
  138. }
  139. };
  140. return codeFrameColumns(rawLines, location, opts);
  141. }