map-generator.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _sourceMap = _interopRequireDefault(require("source-map"));
  5. var _path = _interopRequireDefault(require("path"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
  8. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  9. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  10. var MapGenerator = /*#__PURE__*/function () {
  11. function MapGenerator(stringify, root, opts) {
  12. this.stringify = stringify;
  13. this.mapOpts = opts.map || {};
  14. this.root = root;
  15. this.opts = opts;
  16. }
  17. var _proto = MapGenerator.prototype;
  18. _proto.isMap = function isMap() {
  19. if (typeof this.opts.map !== 'undefined') {
  20. return !!this.opts.map;
  21. }
  22. return this.previous().length > 0;
  23. };
  24. _proto.previous = function previous() {
  25. var _this = this;
  26. if (!this.previousMaps) {
  27. this.previousMaps = [];
  28. this.root.walk(function (node) {
  29. if (node.source && node.source.input.map) {
  30. var map = node.source.input.map;
  31. if (_this.previousMaps.indexOf(map) === -1) {
  32. _this.previousMaps.push(map);
  33. }
  34. }
  35. });
  36. }
  37. return this.previousMaps;
  38. };
  39. _proto.isInline = function isInline() {
  40. if (typeof this.mapOpts.inline !== 'undefined') {
  41. return this.mapOpts.inline;
  42. }
  43. var annotation = this.mapOpts.annotation;
  44. if (typeof annotation !== 'undefined' && annotation !== true) {
  45. return false;
  46. }
  47. if (this.previous().length) {
  48. return this.previous().some(function (i) {
  49. return i.inline;
  50. });
  51. }
  52. return true;
  53. };
  54. _proto.isSourcesContent = function isSourcesContent() {
  55. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  56. return this.mapOpts.sourcesContent;
  57. }
  58. if (this.previous().length) {
  59. return this.previous().some(function (i) {
  60. return i.withContent();
  61. });
  62. }
  63. return true;
  64. };
  65. _proto.clearAnnotation = function clearAnnotation() {
  66. if (this.mapOpts.annotation === false) return;
  67. var node;
  68. for (var i = this.root.nodes.length - 1; i >= 0; i--) {
  69. node = this.root.nodes[i];
  70. if (node.type !== 'comment') continue;
  71. if (node.text.indexOf('# sourceMappingURL=') === 0) {
  72. this.root.removeChild(i);
  73. }
  74. }
  75. };
  76. _proto.setSourcesContent = function setSourcesContent() {
  77. var _this2 = this;
  78. var already = {};
  79. this.root.walk(function (node) {
  80. if (node.source) {
  81. var from = node.source.input.from;
  82. if (from && !already[from]) {
  83. already[from] = true;
  84. var relative = _this2.relative(from);
  85. _this2.map.setSourceContent(relative, node.source.input.css);
  86. }
  87. }
  88. });
  89. };
  90. _proto.applyPrevMaps = function applyPrevMaps() {
  91. for (var _iterator = _createForOfIteratorHelperLoose(this.previous()), _step; !(_step = _iterator()).done;) {
  92. var prev = _step.value;
  93. var from = this.relative(prev.file);
  94. var root = prev.root || _path.default.dirname(prev.file);
  95. var map = void 0;
  96. if (this.mapOpts.sourcesContent === false) {
  97. map = new _sourceMap.default.SourceMapConsumer(prev.text);
  98. if (map.sourcesContent) {
  99. map.sourcesContent = map.sourcesContent.map(function () {
  100. return null;
  101. });
  102. }
  103. } else {
  104. map = prev.consumer();
  105. }
  106. this.map.applySourceMap(map, from, this.relative(root));
  107. }
  108. };
  109. _proto.isAnnotation = function isAnnotation() {
  110. if (this.isInline()) {
  111. return true;
  112. }
  113. if (typeof this.mapOpts.annotation !== 'undefined') {
  114. return this.mapOpts.annotation;
  115. }
  116. if (this.previous().length) {
  117. return this.previous().some(function (i) {
  118. return i.annotation;
  119. });
  120. }
  121. return true;
  122. };
  123. _proto.toBase64 = function toBase64(str) {
  124. if (Buffer) {
  125. return Buffer.from(str).toString('base64');
  126. }
  127. return window.btoa(unescape(encodeURIComponent(str)));
  128. };
  129. _proto.addAnnotation = function addAnnotation() {
  130. var content;
  131. if (this.isInline()) {
  132. content = 'data:application/json;base64,' + this.toBase64(this.map.toString());
  133. } else if (typeof this.mapOpts.annotation === 'string') {
  134. content = this.mapOpts.annotation;
  135. } else {
  136. content = this.outputFile() + '.map';
  137. }
  138. var eol = '\n';
  139. if (this.css.indexOf('\r\n') !== -1) eol = '\r\n';
  140. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  141. };
  142. _proto.outputFile = function outputFile() {
  143. if (this.opts.to) {
  144. return this.relative(this.opts.to);
  145. }
  146. if (this.opts.from) {
  147. return this.relative(this.opts.from);
  148. }
  149. return 'to.css';
  150. };
  151. _proto.generateMap = function generateMap() {
  152. this.generateString();
  153. if (this.isSourcesContent()) this.setSourcesContent();
  154. if (this.previous().length > 0) this.applyPrevMaps();
  155. if (this.isAnnotation()) this.addAnnotation();
  156. if (this.isInline()) {
  157. return [this.css];
  158. }
  159. return [this.css, this.map];
  160. };
  161. _proto.relative = function relative(file) {
  162. if (file.indexOf('<') === 0) return file;
  163. if (/^\w+:\/\//.test(file)) return file;
  164. var from = this.opts.to ? _path.default.dirname(this.opts.to) : '.';
  165. if (typeof this.mapOpts.annotation === 'string') {
  166. from = _path.default.dirname(_path.default.resolve(from, this.mapOpts.annotation));
  167. }
  168. file = _path.default.relative(from, file);
  169. if (_path.default.sep === '\\') {
  170. return file.replace(/\\/g, '/');
  171. }
  172. return file;
  173. };
  174. _proto.sourcePath = function sourcePath(node) {
  175. if (this.mapOpts.from) {
  176. return this.mapOpts.from;
  177. }
  178. return this.relative(node.source.input.from);
  179. };
  180. _proto.generateString = function generateString() {
  181. var _this3 = this;
  182. this.css = '';
  183. this.map = new _sourceMap.default.SourceMapGenerator({
  184. file: this.outputFile()
  185. });
  186. var line = 1;
  187. var column = 1;
  188. var lines, last;
  189. this.stringify(this.root, function (str, node, type) {
  190. _this3.css += str;
  191. if (node && type !== 'end') {
  192. if (node.source && node.source.start) {
  193. _this3.map.addMapping({
  194. source: _this3.sourcePath(node),
  195. generated: {
  196. line: line,
  197. column: column - 1
  198. },
  199. original: {
  200. line: node.source.start.line,
  201. column: node.source.start.column - 1
  202. }
  203. });
  204. } else {
  205. _this3.map.addMapping({
  206. source: '<no source>',
  207. original: {
  208. line: 1,
  209. column: 0
  210. },
  211. generated: {
  212. line: line,
  213. column: column - 1
  214. }
  215. });
  216. }
  217. }
  218. lines = str.match(/\n/g);
  219. if (lines) {
  220. line += lines.length;
  221. last = str.lastIndexOf('\n');
  222. column = str.length - last;
  223. } else {
  224. column += str.length;
  225. }
  226. if (node && type !== 'start') {
  227. var p = node.parent || {
  228. raws: {}
  229. };
  230. if (node.type !== 'decl' || node !== p.last || p.raws.semicolon) {
  231. if (node.source && node.source.end) {
  232. _this3.map.addMapping({
  233. source: _this3.sourcePath(node),
  234. generated: {
  235. line: line,
  236. column: column - 2
  237. },
  238. original: {
  239. line: node.source.end.line,
  240. column: node.source.end.column - 1
  241. }
  242. });
  243. } else {
  244. _this3.map.addMapping({
  245. source: '<no source>',
  246. original: {
  247. line: 1,
  248. column: 0
  249. },
  250. generated: {
  251. line: line,
  252. column: column - 1
  253. }
  254. });
  255. }
  256. }
  257. }
  258. });
  259. };
  260. _proto.generate = function generate() {
  261. this.clearAnnotation();
  262. if (this.isMap()) {
  263. return this.generateMap();
  264. }
  265. var result = '';
  266. this.stringify(this.root, function (i) {
  267. result += i;
  268. });
  269. return [result];
  270. };
  271. return MapGenerator;
  272. }();
  273. var _default = MapGenerator;
  274. exports.default = _default;
  275. module.exports = exports.default;
  276. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1hcC1nZW5lcmF0b3IuZXM2Il0sIm5hbWVzIjpbIk1hcEdlbmVyYXRvciIsInN0cmluZ2lmeSIsInJvb3QiLCJvcHRzIiwibWFwT3B0cyIsIm1hcCIsImlzTWFwIiwicHJldmlvdXMiLCJsZW5ndGgiLCJwcmV2aW91c01hcHMiLCJ3YWxrIiwibm9kZSIsInNvdXJjZSIsImlucHV0IiwiaW5kZXhPZiIsInB1c2giLCJpc0lubGluZSIsImlubGluZSIsImFubm90YXRpb24iLCJzb21lIiwiaSIsImlzU291cmNlc0NvbnRlbnQiLCJzb3VyY2VzQ29udGVudCIsIndpdGhDb250ZW50IiwiY2xlYXJBbm5vdGF0aW9uIiwibm9kZXMiLCJ0eXBlIiwidGV4dCIsInJlbW92ZUNoaWxkIiwic2V0U291cmNlc0NvbnRlbnQiLCJhbHJlYWR5IiwiZnJvbSIsInJlbGF0aXZlIiwic2V0U291cmNlQ29udGVudCIsImNzcyIsImFwcGx5UHJldk1hcHMiLCJwcmV2IiwiZmlsZSIsInBhdGgiLCJkaXJuYW1lIi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gbm9kZS5zb3VyY2UuaW5wdXQubWFwXG4gICAgICAgICAgaWYgKHRoaXMucHJldmlvdXNNYXBzLmluZGV4T2YobWFwKSA9PT0gLTEpIHtcbiAgICAgICAgICAgIHRoaXMucHJldmlvdXNNYXBzLnB1c2gobWFwKVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9XG5cbiAgICByZXR1cm4gdGhpcy5wcmV2aW91c01hcHNcbiAgfVxuXG4gIGlzSW5saW5lICgpIHtcbiAgICBpZiAodHlwZW9mIHRoaXMubWFwT3B0cy5pbmxpbmUgIT09ICd1bmRlZmluZWQnKSB7XG4gICAgICByZXR1cm4gdGhpcy5tYXBPcHRzLmlubGluZVxuICAgIH1cblxuICAgIGxldCBhbm5vdGF0aW9uID0gdGhpcy5tYXBPcHRzLmFubm90YXRpb25cbiAgICBpZiAodHlwZW9mIGFubm90YXRpb24gIT09ICd1bmRlZmluZWQnICYmIGFubm90YXRpb24gIT09IHRydWUpIHtcbiAgICAgIHJldHVybiBmYWxzZVxuICAgIH1cblxuICAgIGlmICh0aGlzLnByZXZpb3VzKCkubGVuZ3RoKSB7XG4gICAgICByZXR1cm4gdGhpcy5wcmV2aW91cygpLnNvbWUoaSA9PiBpLmlubGluZSlcbiAgICB9XG4gICAgcmV0dXJuIHRydWVcbiAgfVxuXG4gIGlzU291cmNlc0NvbnRlbnQgKCkge1xuICAgIGlmICh0eXBlb2YgdGhpcy5tYXBPcHRzLnNvdXJjZXNDb250ZW50ICE9PSAndW5kZWZpbmVkJykge1xuICAgICAgcmV0dXJuIHRoaXMubWFwT3B0cy5zb3VyY2VzQ29udGVudFxuICAgIH1cbiAgICBpZiAodGhpcy5wcmV2aW91cygpLmxlbmd0aCkge1xuICAgICAgcmV0dXJuIHRoaXMucHJldmlvdXMoKS5zb21lKGkgPT4gaS53aXRoQ29udGVudCgpKVxuICAgIH1cbiAgICByZXR1cm4gdHJ1ZVxuICB9XG5cbiAgY2xlYXJBbm5vdGF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gICAgIGxpbmVzID0gc3RyLm1hdGNoKC9cXG4vZylcbiAgICAgIGlmIChsaW5lcykge1xuICAgICAgICBsaW5lICs9IGxpbmVzLmxlbmd0aFxuICAgICAgICBsYXN0ID0gc3RyLmxhc3RJbmRleE9mKCdcXG4nKVxuICAgICAgICBjb2x1bW4gPSBzdHIubGVuZ3RoIC0gbGFzdFxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgY29sdW1uICs9IHN0ci5sZW5ndGhcbiAgICAgIH1cblxuICAgICAgaWYgKG5vZGUgJiYgdHlwZSAhPT0gJ3N0YXJ0Jykge1xuICAgICAgICBsZXQgcCA9IG5vZGUucGFyZW50IHx8IHsgcmF3czogeyB9IH1cbiAgICAgICAgaWYgKG5vZGUudHlwZSAhPT0gJ2RlY2wnIHx8IG5vZGUgIT09IHAubGFzdCB8fCBwLnJhd3Muc2VtaWNvbG9uKSB7XG4gICAgICAgICAgaWYgKG5vZGUuc291cmNlICYmIG5vZGUuc291cmNlLmVuZCkge1xuICAgICAgICAgICAgdGhpcy5tYXAuYWRkTWFwcGluZyh7XG4gICAgICAgICAgICAgIHNvdXJjZTogdGhpcy5zb3VyY2VQYXRoKG5vZGUpLFxuICAgICAgICAgICAgICBnZW5lcmF0ZWQ6IHsgbGluZSwgY29sdW1uOiBjb2x1bW4gLSAyIH0sXG4gICAgICAgICAgICAgIG9yaWdpbmFsOiB7XG4gICAgICAgICAgICAgICAgbGluZTogbm9kZS5zb3VyY2UuZW5kLmxpbmUsXG4gICAgICAgICAgICAgICAgY29sdW1uOiBub2RlLnNvdXJjZS5lbmQuY29sdW1uIC0gMVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLm1hcC5hZGRNYXBwaW5nKHtcbiAgICAgICAgICAgICAgc291cmNlOiAnPG5vIHNvdXJjZT4nLFxuICAgICAgICAgICAgICBvcmlnaW5hbDogeyBsaW5lOiAxLCBjb2x1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