123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- "use strict";
- exports.__esModule = true;
- exports.default = void 0;
- var _sourceMap = _interopRequireDefault(require("source-map"));
- var _path = _interopRequireDefault(require("path"));
- var _fs = _interopRequireDefault(require("fs"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function fromBase64(str) {
- if (Buffer) {
- return Buffer.from(str, 'base64').toString();
- } else {
- return window.atob(str);
- }
- }
- var PreviousMap = function () {
-
- function PreviousMap(css, opts) {
- this.loadAnnotation(css);
-
- this.inline = this.startWith(this.annotation, 'data:');
- var prev = opts.map ? opts.map.prev : undefined;
- var text = this.loadMap(opts.from, prev);
- if (text) this.text = text;
- }
-
- var _proto = PreviousMap.prototype;
- _proto.consumer = function consumer() {
- if (!this.consumerCache) {
- this.consumerCache = new _sourceMap.default.SourceMapConsumer(this.text);
- }
- return this.consumerCache;
- }
-
- ;
- _proto.withContent = function withContent() {
- return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
- };
- _proto.startWith = function startWith(string, start) {
- if (!string) return false;
- return string.substr(0, start.length) === start;
- };
- _proto.getAnnotationURL = function getAnnotationURL(sourceMapString) {
- return sourceMapString.match(/\/\*\s*# sourceMappingURL=((?:(?!sourceMappingURL=).)*)\*\//)[1].trim();
- };
- _proto.loadAnnotation = function loadAnnotation(css) {
- var annotations = css.match(/\/\*\s*# sourceMappingURL=(?:(?!sourceMappingURL=).)*\*\//gm);
- if (annotations && annotations.length > 0) {
-
-
- var lastAnnotation = annotations[annotations.length - 1];
- if (lastAnnotation) {
- this.annotation = this.getAnnotationURL(lastAnnotation);
- }
- }
- };
- _proto.decodeInline = function decodeInline(text) {
- var baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
- var baseUri = /^data:application\/json;base64,/;
- var uri = 'data:application/json,';
- if (this.startWith(text, uri)) {
- return decodeURIComponent(text.substr(uri.length));
- }
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
- return fromBase64(text.substr(RegExp.lastMatch.length));
- }
- var encoding = text.match(/data:application\/json;([^,]+),/)[1];
- throw new Error('Unsupported source map encoding ' + encoding);
- };
- _proto.loadMap = function loadMap(file, prev) {
- if (prev === false) return false;
- if (prev) {
- if (typeof prev === 'string') {
- return prev;
- } else if (typeof prev === 'function') {
- var prevPath = prev(file);
- if (prevPath && _fs.default.existsSync && _fs.default.existsSync(prevPath)) {
- return _fs.default.readFileSync(prevPath, 'utf-8').toString().trim();
- } else {
- throw new Error('Unable to load previous source map: ' + prevPath.toString());
- }
- } else if (prev instanceof _sourceMap.default.SourceMapConsumer) {
- return _sourceMap.default.SourceMapGenerator.fromSourceMap(prev).toString();
- } else if (prev instanceof _sourceMap.default.SourceMapGenerator) {
- return prev.toString();
- } else if (this.isMap(prev)) {
- return JSON.stringify(prev);
- } else {
- throw new Error('Unsupported previous source map format: ' + prev.toString());
- }
- } else if (this.inline) {
- return this.decodeInline(this.annotation);
- } else if (this.annotation) {
- var map = this.annotation;
- if (file) map = _path.default.join(_path.default.dirname(file), map);
- this.root = _path.default.dirname(map);
- if (_fs.default.existsSync && _fs.default.existsSync(map)) {
- return _fs.default.readFileSync(map, 'utf-8').toString().trim();
- } else {
- return false;
- }
- }
- };
- _proto.isMap = function isMap(map) {
- if (typeof map !== 'object') return false;
- return typeof map.mappings === 'string' || typeof map._mappings === 'string';
- };
- return PreviousMap;
- }();
- var _default = PreviousMap;
- exports.default = _default;
- module.exports = exports.default;
|