aboutsummaryrefslogtreecommitdiff
path: root/node_modules/postcss/lib/previous-map.js
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/postcss/lib/previous-map.js
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/postcss/lib/previous-map.js')
-rw-r--r--node_modules/postcss/lib/previous-map.js170
1 files changed, 170 insertions, 0 deletions
diff --git a/node_modules/postcss/lib/previous-map.js b/node_modules/postcss/lib/previous-map.js
new file mode 100644
index 0000000..e222df9
--- /dev/null
+++ b/node_modules/postcss/lib/previous-map.js
@@ -0,0 +1,170 @@
+'use strict';
+
+exports.__esModule = true;
+
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
+
+var _sourceMap = require('source-map');
+
+var _sourceMap2 = _interopRequireDefault(_sourceMap);
+
+var _path = require('path');
+
+var _path2 = _interopRequireDefault(_path);
+
+var _fs = require('fs');
+
+var _fs2 = _interopRequireDefault(_fs);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+function fromBase64(str) {
+ if (Buffer) {
+ if (Buffer.from && Buffer.from !== Uint8Array.from) {
+ return Buffer.from(str, 'base64').toString();
+ } else {
+ return new Buffer(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 = function () {
+
+ /**
+ * @param {string} css - input CSS source
+ * @param {processOptions} [opts] - {@link Processor#process} options
+ */
+ function PreviousMap(css, opts) {
+ _classCallCheck(this, PreviousMap);
+
+ this.loadAnnotation(css);
+ /**
+ * @member {boolean} - Was source map inlined by data-uri to input 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;
+ }
+
+ /**
+ * 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
+ */
+
+
+ PreviousMap.prototype.consumer = function consumer() {
+ if (!this.consumerCache) {
+ this.consumerCache = new _sourceMap2.default.SourceMapConsumer(this.text);
+ }
+ return this.consumerCache;
+ };
+
+ /**
+ * Does source map contains `sourcesContent` with input source text.
+ *
+ * @return {boolean} Is `sourcesContent` present
+ */
+
+
+ PreviousMap.prototype.withContent = function withContent() {
+ return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
+ };
+
+ PreviousMap.prototype.startWith = function startWith(string, start) {
+ if (!string) return false;
+ return string.substr(0, start.length) === start;
+ };
+
+ PreviousMap.prototype.loadAnnotation = function loadAnnotation(css) {
+ var match = css.match(/\/\*\s*# sourceMappingURL=(.*)\s*\*\//);
+ if (match) this.annotation = match[1].trim();
+ };
+
+ PreviousMap.prototype.decodeInline = function decodeInline(text) {
+ // data:application/json;charset=utf-8;base64,
+ // data:application/json;charset=utf8;base64,
+ // data:application/json;base64,
+ var baseUri = /^data:application\/json;(?:charset=utf-?8;)?base64,/;
+ var uri = 'data:application/json,';
+
+ if (this.startWith(text, uri)) {
+ return decodeURIComponent(text.substr(uri.length));
+ } else if (baseUri.test(text)) {
+ return fromBase64(text.substr(RegExp.lastMatch.length));
+ } else {
+ var encoding = text.match(/data:application\/json;([^,]+),/)[1];
+ throw new Error('Unsupported source map encoding ' + encoding);
+ }
+ };
+
+ PreviousMap.prototype.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 && _fs2.default.existsSync && _fs2.default.existsSync(prevPath)) {
+ return _fs2.default.readFileSync(prevPath, 'utf-8').toString().trim();
+ } else {
+ throw new Error('Unable to load previous source map: ' + prevPath.toString());
+ }
+ } else if (prev instanceof _sourceMap2.default.SourceMapConsumer) {
+ return _sourceMap2.default.SourceMapGenerator.fromSourceMap(prev).toString();
+ } else if (prev instanceof _sourceMap2.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 = _path2.default.join(_path2.default.dirname(file), map);
+
+ this.root = _path2.default.dirname(map);
+ if (_fs2.default.existsSync && _fs2.default.existsSync(map)) {
+ return _fs2.default.readFileSync(map, 'utf-8').toString().trim();
+ } else {
+ return false;
+ }
+ }
+ };
+
+ PreviousMap.prototype.isMap = function isMap(map) {
+ if ((typeof map === 'undefined' ? 'undefined' : _typeof(map)) !== 'object') return false;
+ return typeof map.mappings === 'string' || typeof map._mappings === 'string';
+ };
+
+ return PreviousMap;
+}();
+
+exports.default = PreviousMap;
+module.exports = exports['default'];
+//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXZpb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IHtTb3VyY2VNYXBHZW5lcmF0b3J9IG9iamVjdCB3aXRoIHNvdXJjZSBtYXAgaW5mb3JtYXRpb25cbiAgICAgKi9cbiAgICBjb25zdW1lcigpIHtcbiAgICAgICAgaWYgKCAhdGhpcy5jb25zdW1lckNhY2hlICkge1xuICAgICAgICAgICAgdGhpcy5jb25zdW1lckNhY2hlID0gbmV3IG1vemlsbGEuU291cmNlTWFwQ29uc3VtZXIodGhpcy50ZXh0KTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy5jb25zdW1lckNhY2hlO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIERvZXMgc291cmNlIG1hcCBjb250YWlucyBgc291cmNlc0NvbnRlbnRgIHdpdGggaW5wdXQgc291cmNlIHRleHQuXG4gICAgICpcbiAgICAgKiBAcmV0dXJuIHtib29sZWFufSBJcyBgc291cmNlc0NvbnRlbnRgIHByZXNlbnRcbiAgICAgKi9cbiAgICB3aXRoQ29udGVudCgpIHtcbiAgICAgICAgcmV0dXJuICEhKHRoaXMuY29uc3VtZXIoKS5zb3VyY2VzQ29udGVudCAmJlxuICAgICAgICAgICAgICAgICAgdGhpcy5jb25zdW1lcigpLnNvdXJjZXNDb250ZW50Lmxlbmd0aCA+IDApO1xuICAgIH1cblxuICAgIHN0YXJ0V2l0aChzdHJpbmcsIHN0YXJ0KSB7XG4gICAgICAgIGlmICggIXN0cmluZyApIHJldHVybiBmYWxzZTtcbiAgICAgICAgcmV0dXJuIHN0cmluZy5zdWJzdHIoMCwgc3RhcnQubGVuZ3RoKSA9PT0gc3RhcnQ7XG4gICAgfVxuXG4gICAgbG9hZEFubm90YXRpb24oY3NzKSB7XG4gICAgICAgIGxldCBtYXRjaCA9IGNzcy5tYXRjaCgvXFwvXFwqXFxzKiMgc291cmNlTWFwcGluZ1VSTD0oLiopXFxzKlxcKlxcLy8pO1xuICAgICAgICBpZiAoIG1hdGNoICkgdGhpcy5hbm5vdGF0aW9uID0gbWF0Y2hbMV0ud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lmICggcHJldiApIHtcbiAgICAgICAgICAgIGlmICggdHlwZW9mIHByZXYgPT09ICdzdHJpbmcnICkge1xuICAgICAgICAgICAgICAgIHJldHVybiBwcmV2O1xuICAgICAgICAgICAgfSBlbHNlIGlmICggdHlwZW9mIHByZXYgPT09ICdmdW5jdGlvbicgKSB7XG4gICAgICAgICAgICAgICAgbGV0IHByZXZQYXRoID0gcHJldihmaWxlKTtcbiAgICAgICAgICAgICAgICBpZiAoIHByZXZQYXRoICYmIGZzLmV4aXN0c1N5bmMgJiYgZnMuZXhpc3RzU3luYyhwcmV2UGF0aCkgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmcy5yZWFkRmlsZVN5bmMocHJldlBhdGgsICd1dGYtOCcpLnRvU3RyaW5nKCkudHJpbSgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVW5hYmxlIHRvIGxvYWQgcHJldmlvdXMgc291cmNlIG1hcDogJyArXG4gICAgICAgICAgICAgICAgICAgIHByZXZQYXRoLnRvU3RyaW5nKCkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIHByZXYgaW5zdGFuY2VvZiBtb3ppbGxhLlNvdXJjZU1hcENvbnN1bWVyICkge1xuICAgICAgICAgICAgICAgIHJldHVybiBtb3ppbGxhLlNvdXJjZU1hcEdlbmVyYXRvclxuICAgICAgICAgICAgICAgICAgICAuZnJvbVNvdXJjZU1hcChwcmV2KS50b1N0cmluZygpO1xuICAgICAgICAgICAgfSBlbHNlIGlmICggcHJldiBpbnN0YW5jZW9mIG1vemlsbGEuU291cmNlTWFwR2VuZXJhdG9yICkge1xuICAgICAgICAgICAgICAgIHJldHVybiBwcmV2LnRvU3RyaW5nKCk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCB0aGlzLmlzTWFwKHByZXYpICkge1xuICAgICAgICAgICAgICAgIHJldHVybiBKU09OLnN0cmluZ2lmeShwcmV2KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdVbnN1cHBvcnRlZCBwcmV2aW91cyBzb3VyY2UgbWFwIGZvcm1hdDogJyArXG4gICAgICAgICAgICAgICAgICAgIHByZXYudG9TdHJpbmcoKSk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgfSBlbHNlIGlmICggdGhpcy5pbmxpbmUgKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5kZWNvZGVJbmxpbmUodGhpcy5hbm5vdGF0aW9uKTtcblxuICAgICAgICB9IGVsc2UgaWYgKCB0aGlzLmFubm90YXRpb24gKSB7XG4gICAgICAgICAgICBsZXQgbWFwID0gdGhpcy5hbm5vdGF0aW9uO1xuICAgICAgICAgICAgaWYgKCBmaWxlICkgbWFwID0gcGF0aC5qb2luKHBhdGguZGlybmFtZShmaWxlKSwgbWFwKTtcblxuICAgICAgICAgICAgdGhpcy5yb290ID0gcGF0aC5kaXJuYW1lKG1hcCk7XG4gICAgICAgICAgICBpZiAoIGZzLmV4aXN0c1N5bmMgJiYgZnMuZXhpc3RzU3luYyhtYXApICkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmcy5yZWFkRmlsZVN5bmMobWFwLCAndXRmLTgnKS50b1N0cmluZygpLnRyaW0oKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgaXNNYXAobWFwKSB7XG4gICAgICAgIGlmICggdHlwZW9mIG1hcCAhPT0gJ29iamVjdCcgKSByZXR1cm4gZmFsc2U7XG4gICAgICAgIHJldHVybiB0eXBlb2YgbWFwLm1hcHBpbmdzID09PSAnc3RyaW5nJyB8fFxuICAgICAgICAgICAgICAgdHlwZW9mIG1hcC5fbWFwcGluZ3MgPT09ICdzdHJpbmcnO1xuICAgIH1cbn1cblxuZXhwb3J0IGRlZmF1bHQgUHJldmlvdXNNYXA7XG4iXX0=