mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
173 lines
17 KiB
JavaScript
173 lines
17 KiB
JavaScript
|
"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);
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* Source map information from input CSS.
|
||
|
* For example, source map after Sass compiler.
|
||
|
*
|
||
|
* This class will automatically find source map in input CSS or in file system
|
||
|
* near input file (according `from` option).
|
||
|
*
|
||
|
* @example
|
||
|
* const root = postcss.parse(css, { from: 'a.sass.css' })
|
||
|
* root.input.map //=> PreviousMap
|
||
|
*/
|
||
|
|
||
|
|
||
|
var PreviousMap = /*#__PURE__*/function () {
|
||
|
/**
|
||
|
* @param {string} css Input CSS source.
|
||
|
* @param {processOptions} [opts] {@link Processor#process} options.
|
||
|
*/
|
||
|
function PreviousMap(css, opts) {
|
||
|
this.loadAnnotation(css);
|
||
|
/**
|
||
|
* Was source map inlined by data-uri to input CSS.
|
||
|
*
|
||
|
* @type {boolean}
|
||
|
*/
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
/**
|
||
|
* Create a instance of `SourceMapGenerator` class
|
||
|
* from the `source-map` library to work with source map information.
|
||
|
*
|
||
|
* It is lazy method, so it will create object only on first call
|
||
|
* and then it will use cache.
|
||
|
*
|
||
|
* @return {SourceMapGenerator} Object with source map information.
|
||
|
*/
|
||
|
|
||
|
|
||
|
var _proto = PreviousMap.prototype;
|
||
|
|
||
|
_proto.consumer = function consumer() {
|
||
|
if (!this.consumerCache) {
|
||
|
this.consumerCache = new _sourceMap.default.SourceMapConsumer(this.text);
|
||
|
}
|
||
|
|
||
|
return this.consumerCache;
|
||
|
}
|
||
|
/**
|
||
|
* Does source map contains `sourcesContent` with input source text.
|
||
|
*
|
||
|
* @return {boolean} Is `sourcesContent` present.
|
||
|
*/
|
||
|
;
|
||
|
|
||
|
_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) {
|
||
|
// Locate the last sourceMappingURL to avoid picking up
|
||
|
// sourceMappingURLs from comments, strings, etc.
|
||
|
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;
|
||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXZpb3VzLW1hcC5lczYiXSwibmFtZXMiOlsiZnJvbUJhc2U2NCIsInN0ciIsIkJ1ZmZlciIsImZyb20iLCJ0b1N0cmluZyIsIndpbmRvdyIsImF0b2IiLCJQcmV2aW91c01hcCIsImNzcyIsIm9wdHMiLCJsb2FkQW5ub3RhdGlvbiIsImlubGluZSIsInN0YXJ0V2l0aCIsImFubm90YXRpb24iLCJwcmV2IiwibWFwIiwidW5kZWZpbmVkIiwidGV4dCIsImxvYWRNYXAiLCJjb25zdW1lciIsImNvbnN1bWVyQ2FjaGUiLCJtb3ppbGxhIiwiU291cmNlTWFwQ29uc3VtZXIiLCJ3aXRoQ29udGVudCIsInNvdXJjZXNDb250ZW50IiwibGVuZ3RoIiwic3RyaW5nIiwic3RhcnQiLCJzdWJzdHIiLCJnZXRBbm5vdGF0aW9uVVJMIiwic291cmNlTWFwU3RyaW5nIiwibWF0Y2giLCJ0cmltIiwiYW5ub3RhdGlvbnMiLCJsYXN0QW5ub3RhdGlvbiIsImRlY29kZUlubGluZSIsImJhc2VDaGFyc2V0VXJpIiwiYmFzZVVyaSIsInVyaSIsImRlY29kZVVSSUNvbXBvbmVudCIsInRlc3QiLCJSZWdFeHAiLCJsYXN0TWF0Y2giLCJlbmNvZGluZyIsIkVycm9yIiwiZmlsZSIsInByZXZQYXRoIiwiZnMiLCJleGlzdHNTeW5jIiwicmVhZEZpbGVTeW5jIiwiU291cmNlTWFwR2VuZXJhdG9yIiwiZnJvbVNvdXJjZU1hcCIsImlzTWFwIiwiSlNPTiIsInN0cmluZ2lmeSIsInBhdGgiLCJqb2luIiwiZGlybmFtZSIsInJvb3QiLCJtYXBwaW5ncyIsIl9tYXBwaW5ncyJdLCJtYXBwaW5ncyI6Ijs7Ozs7Q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