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.

buffer.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. const SPACES_RE = /^[ \t]+$/;
  7. class Buffer {
  8. constructor(map) {
  9. this._map = null;
  10. this._buf = [];
  11. this._last = "";
  12. this._queue = [];
  13. this._position = {
  14. line: 1,
  15. column: 0
  16. };
  17. this._sourcePosition = {
  18. identifierName: null,
  19. line: null,
  20. column: null,
  21. filename: null
  22. };
  23. this._disallowedPop = null;
  24. this._map = map;
  25. }
  26. get() {
  27. this._flush();
  28. const map = this._map;
  29. const result = {
  30. code: this._buf.join("").trimRight(),
  31. map: null,
  32. rawMappings: map == null ? void 0 : map.getRawMappings()
  33. };
  34. if (map) {
  35. Object.defineProperty(result, "map", {
  36. configurable: true,
  37. enumerable: true,
  38. get() {
  39. return this.map = map.get();
  40. },
  41. set(value) {
  42. Object.defineProperty(this, "map", {
  43. value,
  44. writable: true
  45. });
  46. }
  47. });
  48. }
  49. return result;
  50. }
  51. append(str) {
  52. this._flush();
  53. const {
  54. line,
  55. column,
  56. filename,
  57. identifierName,
  58. force
  59. } = this._sourcePosition;
  60. this._append(str, line, column, identifierName, filename, force);
  61. }
  62. queue(str) {
  63. if (str === "\n") {
  64. while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {
  65. this._queue.shift();
  66. }
  67. }
  68. const {
  69. line,
  70. column,
  71. filename,
  72. identifierName,
  73. force
  74. } = this._sourcePosition;
  75. this._queue.unshift([str, line, column, identifierName, filename, force]);
  76. }
  77. _flush() {
  78. let item;
  79. while (item = this._queue.pop()) {
  80. this._append(...item);
  81. }
  82. }
  83. _append(str, line, column, identifierName, filename, force) {
  84. this._buf.push(str);
  85. this._last = str[str.length - 1];
  86. let i = str.indexOf("\n");
  87. let last = 0;
  88. if (i !== 0) {
  89. this._mark(line, column, identifierName, filename, force);
  90. }
  91. while (i !== -1) {
  92. this._position.line++;
  93. this._position.column = 0;
  94. last = i + 1;
  95. if (last < str.length) {
  96. this._mark(++line, 0, identifierName, filename, force);
  97. }
  98. i = str.indexOf("\n", last);
  99. }
  100. this._position.column += str.length - last;
  101. }
  102. _mark(line, column, identifierName, filename, force) {
  103. var _this$_map;
  104. (_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);
  105. }
  106. removeTrailingNewline() {
  107. if (this._queue.length > 0 && this._queue[0][0] === "\n") {
  108. this._queue.shift();
  109. }
  110. }
  111. removeLastSemicolon() {
  112. if (this._queue.length > 0 && this._queue[0][0] === ";") {
  113. this._queue.shift();
  114. }
  115. }
  116. endsWith(suffix) {
  117. if (suffix.length === 1) {
  118. let last;
  119. if (this._queue.length > 0) {
  120. const str = this._queue[0][0];
  121. last = str[str.length - 1];
  122. } else {
  123. last = this._last;
  124. }
  125. return last === suffix;
  126. }
  127. const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, "");
  128. if (suffix.length <= end.length) {
  129. return end.slice(-suffix.length) === suffix;
  130. }
  131. return false;
  132. }
  133. hasContent() {
  134. return this._queue.length > 0 || !!this._last;
  135. }
  136. exactSource(loc, cb) {
  137. this.source("start", loc, true);
  138. cb();
  139. this.source("end", loc);
  140. this._disallowPop("start", loc);
  141. }
  142. source(prop, loc, force) {
  143. if (prop && !loc) return;
  144. this._normalizePosition(prop, loc, this._sourcePosition, force);
  145. }
  146. withSource(prop, loc, cb) {
  147. if (!this._map) return cb();
  148. const originalLine = this._sourcePosition.line;
  149. const originalColumn = this._sourcePosition.column;
  150. const originalFilename = this._sourcePosition.filename;
  151. const originalIdentifierName = this._sourcePosition.identifierName;
  152. this.source(prop, loc);
  153. cb();
  154. if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) {
  155. this._sourcePosition.line = originalLine;
  156. this._sourcePosition.column = originalColumn;
  157. this._sourcePosition.filename = originalFilename;
  158. this._sourcePosition.identifierName = originalIdentifierName;
  159. this._sourcePosition.force = false;
  160. this._disallowedPop = null;
  161. }
  162. }
  163. _disallowPop(prop, loc) {
  164. if (prop && !loc) return;
  165. this._disallowedPop = this._normalizePosition(prop, loc);
  166. }
  167. _normalizePosition(prop, loc, targetObj, force) {
  168. const pos = loc ? loc[prop] : null;
  169. if (targetObj === undefined) {
  170. targetObj = {
  171. identifierName: null,
  172. line: null,
  173. column: null,
  174. filename: null,
  175. force: false
  176. };
  177. }
  178. const origLine = targetObj.line;
  179. const origColumn = targetObj.column;
  180. const origFilename = targetObj.filename;
  181. targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || null;
  182. targetObj.line = pos == null ? void 0 : pos.line;
  183. targetObj.column = pos == null ? void 0 : pos.column;
  184. targetObj.filename = loc == null ? void 0 : loc.filename;
  185. if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) {
  186. targetObj.force = force;
  187. }
  188. return targetObj;
  189. }
  190. getCurrentColumn() {
  191. const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
  192. const lastIndex = extra.lastIndexOf("\n");
  193. return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex;
  194. }
  195. getCurrentLine() {
  196. const extra = this._queue.reduce((acc, item) => item[0] + acc, "");
  197. let count = 0;
  198. for (let i = 0; i < extra.length; i++) {
  199. if (extra[i] === "\n") count++;
  200. }
  201. return this._position.line + count;
  202. }
  203. }
  204. exports.default = Buffer;