mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
build dist
This commit is contained in:
24
dist/lib/core/__mocks__/cache-storage.js
vendored
Normal file
24
dist/lib/core/__mocks__/cache-storage.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var MockCache = /** @class */ (function () {
|
||||
function MockCache() {
|
||||
this._cache = {};
|
||||
}
|
||||
MockCache.prototype.addImage = function (src) {
|
||||
var result = Promise.resolve();
|
||||
this._cache[src] = result;
|
||||
return result;
|
||||
};
|
||||
return MockCache;
|
||||
}());
|
||||
var current = new MockCache();
|
||||
var CacheStorage = /** @class */ (function () {
|
||||
function CacheStorage() {
|
||||
}
|
||||
CacheStorage.getInstance = function () {
|
||||
return current;
|
||||
};
|
||||
return CacheStorage;
|
||||
}());
|
||||
exports.CacheStorage = CacheStorage;
|
||||
//# sourceMappingURL=cache-storage.js.map
|
1
dist/lib/core/__mocks__/cache-storage.js.map
vendored
Normal file
1
dist/lib/core/__mocks__/cache-storage.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"cache-storage.js","sourceRoot":"","sources":["../../../../src/core/__mocks__/cache-storage.ts"],"names":[],"mappings":";;AAAA;IAII;QACI,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,4BAAQ,GAAR,UAAS,GAAW;QAChB,IAAM,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QAC1B,OAAO,MAAM,CAAC;IAClB,CAAC;IACL,gBAAC;AAAD,CAAC,AAbD,IAaC;AAED,IAAM,OAAO,GAAG,IAAI,SAAS,EAAE,CAAC;AAEhC;IAAA;IAIA,CAAC;IAHU,wBAAW,GAAlB;QACI,OAAO,OAAO,CAAC;IACnB,CAAC;IACL,mBAAC;AAAD,CAAC,AAJD,IAIC;AAJY,oCAAY"}
|
11
dist/lib/core/__mocks__/features.js
vendored
Normal file
11
dist/lib/core/__mocks__/features.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FEATURES = {
|
||||
SUPPORT_RANGE_BOUNDS: true,
|
||||
SUPPORT_SVG_DRAWING: true,
|
||||
SUPPORT_FOREIGNOBJECT_DRAWING: true,
|
||||
SUPPORT_CORS_IMAGES: true,
|
||||
SUPPORT_RESPONSE_TYPE: true,
|
||||
SUPPORT_CORS_XHR: true
|
||||
};
|
||||
//# sourceMappingURL=features.js.map
|
1
dist/lib/core/__mocks__/features.js.map
vendored
Normal file
1
dist/lib/core/__mocks__/features.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../../../src/core/__mocks__/features.ts"],"names":[],"mappings":";;AAAa,QAAA,QAAQ,GAAG;IACpB,oBAAoB,EAAE,IAAI;IAC1B,mBAAmB,EAAE,IAAI;IACzB,6BAA6B,EAAE,IAAI;IACnC,mBAAmB,EAAE,IAAI;IACzB,qBAAqB,EAAE,IAAI;IAC3B,gBAAgB,EAAE,IAAI;CACzB,CAAC"}
|
18
dist/lib/core/__mocks__/logger.js
vendored
Normal file
18
dist/lib/core/__mocks__/logger.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Logger = /** @class */ (function () {
|
||||
function Logger() {
|
||||
}
|
||||
Logger.prototype.debug = function () { };
|
||||
Logger.create = function () { };
|
||||
Logger.destroy = function () { };
|
||||
Logger.getInstance = function () {
|
||||
return logger;
|
||||
};
|
||||
Logger.prototype.info = function () { };
|
||||
Logger.prototype.error = function () { };
|
||||
return Logger;
|
||||
}());
|
||||
exports.Logger = Logger;
|
||||
var logger = new Logger();
|
||||
//# sourceMappingURL=logger.js.map
|
1
dist/lib/core/__mocks__/logger.js.map
vendored
Normal file
1
dist/lib/core/__mocks__/logger.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../src/core/__mocks__/logger.ts"],"names":[],"mappings":";;AAAA;IAAA;IAcA,CAAC;IAbG,sBAAK,GAAL,cAAS,CAAC;IAEH,aAAM,GAAb,cAAiB,CAAC;IAEX,cAAO,GAAd,cAAkB,CAAC;IAEZ,kBAAW,GAAlB;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,qBAAI,GAAJ,cAAQ,CAAC;IAET,sBAAK,GAAL,cAAS,CAAC;IACd,aAAC;AAAD,CAAC,AAdD,IAcC;AAdY,wBAAM;AAgBnB,IAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
420
dist/lib/core/__tests__/cache-storage.js
vendored
Normal file
420
dist/lib/core/__tests__/cache-storage.js
vendored
Normal file
@ -0,0 +1,420 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var _this = this;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var assert_1 = require("assert");
|
||||
var features_1 = require("../features");
|
||||
var cache_storage_1 = require("../cache-storage");
|
||||
var logger_1 = require("../logger");
|
||||
var proxy = 'http://example.com/proxy';
|
||||
var createMockContext = function (origin, opts) {
|
||||
if (opts === void 0) { opts = {}; }
|
||||
var context = {
|
||||
location: {
|
||||
href: origin
|
||||
},
|
||||
document: {
|
||||
createElement: function (_name) {
|
||||
var _href = '';
|
||||
return {
|
||||
set href(value) {
|
||||
_href = value;
|
||||
},
|
||||
get href() {
|
||||
return _href;
|
||||
},
|
||||
get protocol() {
|
||||
return new URL(_href).protocol;
|
||||
},
|
||||
get hostname() {
|
||||
return new URL(_href).hostname;
|
||||
},
|
||||
get port() {
|
||||
return new URL(_href).port;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
cache_storage_1.CacheStorage.setContext(context);
|
||||
logger_1.Logger.create({ id: 'test', enabled: false });
|
||||
return cache_storage_1.CacheStorage.create('test', __assign({ imageTimeout: 0, useCORS: false, allowTaint: false, proxy: proxy }, opts));
|
||||
};
|
||||
var images = [];
|
||||
var xhr = [];
|
||||
var sleep = function (timeout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, timeout); })];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
}); }); };
|
||||
var ImageMock = /** @class */ (function () {
|
||||
function ImageMock() {
|
||||
images.push(this);
|
||||
}
|
||||
return ImageMock;
|
||||
}());
|
||||
var XMLHttpRequestMock = /** @class */ (function () {
|
||||
function XMLHttpRequestMock() {
|
||||
this.sent = false;
|
||||
this.status = 500;
|
||||
this.timeout = 5000;
|
||||
xhr.push(this);
|
||||
}
|
||||
XMLHttpRequestMock.prototype.load = function (status, response) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
this.response = response;
|
||||
this.status = status;
|
||||
if (this.onload) {
|
||||
this.onload();
|
||||
}
|
||||
return [4 /*yield*/, sleep(0)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
XMLHttpRequestMock.prototype.open = function (method, url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
};
|
||||
XMLHttpRequestMock.prototype.send = function () {
|
||||
this.sent = true;
|
||||
};
|
||||
return XMLHttpRequestMock;
|
||||
}());
|
||||
Object.defineProperty(global, 'Image', { value: ImageMock, writable: true });
|
||||
Object.defineProperty(global, 'XMLHttpRequest', {
|
||||
value: XMLHttpRequestMock,
|
||||
writable: true
|
||||
});
|
||||
var setFeatures = function (opts) {
|
||||
if (opts === void 0) { opts = {}; }
|
||||
var defaults = {
|
||||
SUPPORT_SVG_DRAWING: true,
|
||||
SUPPORT_CORS_IMAGES: true,
|
||||
SUPPORT_CORS_XHR: true,
|
||||
SUPPORT_RESPONSE_TYPE: false
|
||||
};
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
Object.defineProperty(features_1.FEATURES, key, {
|
||||
value: typeof opts[key] === 'boolean' ? opts[key] : defaults[key],
|
||||
writable: true
|
||||
});
|
||||
});
|
||||
};
|
||||
describe('cache-storage', function () {
|
||||
beforeEach(function () { return setFeatures(); });
|
||||
afterEach(function () {
|
||||
xhr.splice(0, xhr.length);
|
||||
images.splice(0, images.length);
|
||||
});
|
||||
it('addImage adds images to cache', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', { proxy: null });
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test2.jpg')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 2);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://example.com/test.jpg');
|
||||
assert_1.deepStrictEqual(images[1].src, 'http://example.com/test2.jpg');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should not add duplicate entries', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com');
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 1);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://example.com/test.jpg');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
describe('svg', function () {
|
||||
it('should add svg images correctly', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com');
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.svg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test2.svg')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 2);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://example.com/test.svg');
|
||||
assert_1.deepStrictEqual(images[1].src, 'http://example.com/test2.svg');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('should omit svg images if not supported', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
setFeatures({ SUPPORT_SVG_DRAWING: false });
|
||||
cache = createMockContext('http://example.com');
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.svg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test2.svg')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 0);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
describe('cross-origin', function () {
|
||||
it('addImage should not add images it cannot load/render', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', {
|
||||
proxy: undefined
|
||||
});
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 0);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should add images if tainting enabled', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', {
|
||||
allowTaint: true,
|
||||
proxy: undefined
|
||||
});
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 1);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://html2canvas.hertzen.com/test.jpg');
|
||||
assert_1.deepStrictEqual(images[0].crossOrigin, undefined);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should add images if cors enabled', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', { useCORS: true });
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 1);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://html2canvas.hertzen.com/test.jpg');
|
||||
assert_1.deepStrictEqual(images[0].crossOrigin, 'anonymous');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should not add images if cors enabled but not supported', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
setFeatures({ SUPPORT_CORS_IMAGES: false });
|
||||
cache = createMockContext('http://example.com', {
|
||||
useCORS: true,
|
||||
proxy: undefined
|
||||
});
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 0);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should not add images to proxy if cors enabled', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', { useCORS: true });
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 1);
|
||||
assert_1.deepStrictEqual(images[0].src, 'http://html2canvas.hertzen.com/test.jpg');
|
||||
assert_1.deepStrictEqual(images[0].crossOrigin, 'anonymous');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('addImage should use proxy ', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com');
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(xhr.length, 1);
|
||||
assert_1.deepStrictEqual(xhr[0].url, proxy + "?url=" + encodeURIComponent('http://html2canvas.hertzen.com/test.jpg') + "&responseType=text");
|
||||
return [4 /*yield*/, xhr[0].load(200, '<data response>')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(images.length, 1);
|
||||
assert_1.deepStrictEqual(images[0].src, '<data response>');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('proxy should respect imageTimeout', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache, e_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', {
|
||||
imageTimeout: 10
|
||||
});
|
||||
return [4 /*yield*/, cache.addImage('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
assert_1.deepStrictEqual(xhr.length, 1);
|
||||
assert_1.deepStrictEqual(xhr[0].url, proxy + "?url=" + encodeURIComponent('http://html2canvas.hertzen.com/test.jpg') + "&responseType=text");
|
||||
assert_1.deepStrictEqual(xhr[0].timeout, 10);
|
||||
if (xhr[0].ontimeout) {
|
||||
xhr[0].ontimeout();
|
||||
}
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
_a.trys.push([2, 4, , 5]);
|
||||
return [4 /*yield*/, cache.match('http://html2canvas.hertzen.com/test.jpg')];
|
||||
case 3:
|
||||
_a.sent();
|
||||
assert_1.fail('Expected result to timeout');
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
e_1 = _a.sent();
|
||||
return [3 /*break*/, 5];
|
||||
case 5: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
it('match should return cache entry', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache, response;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com');
|
||||
return [4 /*yield*/, cache.addImage('http://example.com/test.jpg')];
|
||||
case 1:
|
||||
_a.sent();
|
||||
if (images[0].onload) {
|
||||
images[0].onload();
|
||||
}
|
||||
return [4 /*yield*/, cache.match('http://example.com/test.jpg')];
|
||||
case 2:
|
||||
response = _a.sent();
|
||||
assert_1.deepStrictEqual(response.src, 'http://example.com/test.jpg');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it('image should respect imageTimeout', function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var cache, e_2;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cache = createMockContext('http://example.com', { imageTimeout: 10 });
|
||||
cache.addImage('http://example.com/test.jpg');
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, cache.match('http://example.com/test.jpg')];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert_1.fail('Expected result to timeout');
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
e_2 = _a.sent();
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
//# sourceMappingURL=cache-storage.js.map
|
1
dist/lib/core/__tests__/cache-storage.js.map
vendored
Normal file
1
dist/lib/core/__tests__/cache-storage.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
25
dist/lib/core/__tests__/logger.js
vendored
Normal file
25
dist/lib/core/__tests__/logger.js
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var logger_1 = require("../logger");
|
||||
describe('logger', function () {
|
||||
var infoSpy;
|
||||
beforeEach(function () {
|
||||
infoSpy = jest.spyOn(console, 'info').mockImplementation(function () { });
|
||||
});
|
||||
afterEach(function () {
|
||||
infoSpy.mockRestore();
|
||||
});
|
||||
it('should call console.info when logger enabled', function () {
|
||||
var id = Math.random().toString();
|
||||
var logger = new logger_1.Logger({ id: id, enabled: true });
|
||||
logger.info('testing');
|
||||
expect(infoSpy).toHaveBeenLastCalledWith(id, expect.stringMatching(/\d+ms/), 'testing');
|
||||
});
|
||||
it("shouldn't call console.info when logger disabled", function () {
|
||||
var id = Math.random().toString();
|
||||
var logger = new logger_1.Logger({ id: id, enabled: false });
|
||||
logger.info('testing');
|
||||
expect(infoSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=logger.js.map
|
1
dist/lib/core/__tests__/logger.js.map
vendored
Normal file
1
dist/lib/core/__tests__/logger.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../src/core/__tests__/logger.ts"],"names":[],"mappings":";;AAAA,oCAAiC;AAEjC,QAAQ,CAAC,QAAQ,EAAE;IACf,IAAI,OAAY,CAAC;IAEjB,UAAU,CAAC;QACP,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,cAAO,CAAC,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC;QACN,OAAO,CAAC,WAAW,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE;QAC/C,IAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;QACpC,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAC,EAAE,IAAA,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,CAAC,wBAAwB,CAAC,EAAE,EAAE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IAC5F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACnD,IAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;QACpC,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAC,EAAE,IAAA,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
4
dist/lib/core/bitwise.js
vendored
Normal file
4
dist/lib/core/bitwise.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.contains = function (bit, value) { return (bit & value) !== 0; };
|
||||
//# sourceMappingURL=bitwise.js.map
|
1
dist/lib/core/bitwise.js.map
vendored
Normal file
1
dist/lib/core/bitwise.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"bitwise.js","sourceRoot":"","sources":["../../../src/core/bitwise.ts"],"names":[],"mappings":";;AAAa,QAAA,QAAQ,GAAG,UAAC,GAAW,EAAE,KAAa,IAAc,OAAA,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,EAAnB,CAAmB,CAAC"}
|
221
dist/lib/core/cache-storage.js
vendored
Normal file
221
dist/lib/core/cache-storage.js
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var features_1 = require("./features");
|
||||
var logger_1 = require("./logger");
|
||||
var CacheStorage = /** @class */ (function () {
|
||||
function CacheStorage() {
|
||||
}
|
||||
CacheStorage.create = function (name, options) {
|
||||
return (CacheStorage._caches[name] = new Cache(name, options));
|
||||
};
|
||||
CacheStorage.destroy = function (name) {
|
||||
delete CacheStorage._caches[name];
|
||||
};
|
||||
CacheStorage.open = function (name) {
|
||||
var cache = CacheStorage._caches[name];
|
||||
if (typeof cache !== 'undefined') {
|
||||
return cache;
|
||||
}
|
||||
throw new Error("Cache with key \"" + name + "\" not found");
|
||||
};
|
||||
CacheStorage.getOrigin = function (url) {
|
||||
var link = CacheStorage._link;
|
||||
if (!link) {
|
||||
return 'about:blank';
|
||||
}
|
||||
link.href = url;
|
||||
link.href = link.href; // IE9, LOL! - http://jsfiddle.net/niklasvh/2e48b/
|
||||
return link.protocol + link.hostname + link.port;
|
||||
};
|
||||
CacheStorage.isSameOrigin = function (src) {
|
||||
return CacheStorage.getOrigin(src) === CacheStorage._origin;
|
||||
};
|
||||
CacheStorage.setContext = function (window) {
|
||||
CacheStorage._link = window.document.createElement('a');
|
||||
CacheStorage._origin = CacheStorage.getOrigin(window.location.href);
|
||||
};
|
||||
CacheStorage.getInstance = function () {
|
||||
var current = CacheStorage._current;
|
||||
if (current === null) {
|
||||
throw new Error("No cache instance attached");
|
||||
}
|
||||
return current;
|
||||
};
|
||||
CacheStorage.attachInstance = function (cache) {
|
||||
CacheStorage._current = cache;
|
||||
};
|
||||
CacheStorage.detachInstance = function () {
|
||||
CacheStorage._current = null;
|
||||
};
|
||||
CacheStorage._caches = {};
|
||||
CacheStorage._origin = 'about:blank';
|
||||
CacheStorage._current = null;
|
||||
return CacheStorage;
|
||||
}());
|
||||
exports.CacheStorage = CacheStorage;
|
||||
var Cache = /** @class */ (function () {
|
||||
function Cache(id, options) {
|
||||
this.id = id;
|
||||
this._options = options;
|
||||
this._cache = {};
|
||||
}
|
||||
Cache.prototype.addImage = function (src) {
|
||||
var result = Promise.resolve();
|
||||
if (this.has(src)) {
|
||||
return result;
|
||||
}
|
||||
if (isBlobImage(src) || isRenderable(src)) {
|
||||
this._cache[src] = this.loadImage(src);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Cache.prototype.match = function (src) {
|
||||
return this._cache[src];
|
||||
};
|
||||
Cache.prototype.loadImage = function (key) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var isSameOrigin, useCORS, useProxy, src;
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
isSameOrigin = CacheStorage.isSameOrigin(key);
|
||||
useCORS = !isInlineImage(key) && this._options.useCORS === true && features_1.FEATURES.SUPPORT_CORS_IMAGES && !isSameOrigin;
|
||||
useProxy = !isInlineImage(key) &&
|
||||
!isSameOrigin &&
|
||||
typeof this._options.proxy === 'string' &&
|
||||
features_1.FEATURES.SUPPORT_CORS_XHR &&
|
||||
!useCORS;
|
||||
if (!isSameOrigin && this._options.allowTaint === false && !isInlineImage(key) && !useProxy && !useCORS) {
|
||||
return [2 /*return*/];
|
||||
}
|
||||
src = key;
|
||||
if (!useProxy) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.proxy(src)];
|
||||
case 1:
|
||||
src = _a.sent();
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
logger_1.Logger.getInstance(this.id).debug("Added image " + key.substring(0, 256));
|
||||
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
||||
var img = new Image();
|
||||
img.onload = function () { return resolve(img); };
|
||||
img.onerror = reject;
|
||||
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
|
||||
if (isInlineBase64Image(src) || useCORS) {
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.setAttribute('crossOrigin', 'anonymous');
|
||||
src = src + '?v=' + new Date().getTime();
|
||||
img.src = src;
|
||||
}
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.setAttribute('crossOrigin', 'anonymous');
|
||||
src = src + '?v=' + new Date().getTime();
|
||||
img.src = src;
|
||||
if (img.complete === true) {
|
||||
// Inline XML images may fail to parse, throwing an Error later on
|
||||
setTimeout(function () { return resolve(img); }, 500);
|
||||
}
|
||||
if (_this._options.imageTimeout > 0) {
|
||||
setTimeout(function () { return reject("Timed out (" + _this._options.imageTimeout + "ms) loading image"); }, _this._options.imageTimeout);
|
||||
}
|
||||
})];
|
||||
case 3: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Cache.prototype.has = function (key) {
|
||||
return typeof this._cache[key] !== 'undefined';
|
||||
};
|
||||
Cache.prototype.keys = function () {
|
||||
return Promise.resolve(Object.keys(this._cache));
|
||||
};
|
||||
Cache.prototype.proxy = function (src) {
|
||||
var _this = this;
|
||||
var proxy = this._options.proxy;
|
||||
if (!proxy) {
|
||||
throw new Error('No proxy defined');
|
||||
}
|
||||
var key = src.substring(0, 256);
|
||||
return new Promise(function (resolve, reject) {
|
||||
var responseType = features_1.FEATURES.SUPPORT_RESPONSE_TYPE ? 'blob' : 'text';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
if (responseType === 'text') {
|
||||
resolve(xhr.response);
|
||||
}
|
||||
else {
|
||||
var reader_1 = new FileReader();
|
||||
reader_1.addEventListener('load', function () { return resolve(reader_1.result); }, false);
|
||||
reader_1.addEventListener('error', function (e) { return reject(e); }, false);
|
||||
reader_1.readAsDataURL(xhr.response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
reject("Failed to proxy resource " + key + " with status code " + xhr.status);
|
||||
}
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.open('GET', proxy + "?url=" + encodeURIComponent(src) + "&responseType=" + responseType);
|
||||
if (responseType !== 'text' && xhr instanceof XMLHttpRequest) {
|
||||
xhr.responseType = responseType;
|
||||
}
|
||||
if (_this._options.imageTimeout) {
|
||||
var timeout_1 = _this._options.imageTimeout;
|
||||
xhr.timeout = timeout_1;
|
||||
xhr.ontimeout = function () { return reject("Timed out (" + timeout_1 + "ms) proxying " + key); };
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
};
|
||||
return Cache;
|
||||
}());
|
||||
exports.Cache = Cache;
|
||||
var INLINE_SVG = /^data:image\/svg\+xml/i;
|
||||
var INLINE_BASE64 = /^data:image\/.*;base64,/i;
|
||||
var INLINE_IMG = /^data:image\/.*/i;
|
||||
var isRenderable = function (src) { return features_1.FEATURES.SUPPORT_SVG_DRAWING || !isSVG(src); };
|
||||
var isInlineImage = function (src) { return INLINE_IMG.test(src); };
|
||||
var isInlineBase64Image = function (src) { return INLINE_BASE64.test(src); };
|
||||
var isBlobImage = function (src) { return src.substr(0, 4) === 'blob'; };
|
||||
var isSVG = function (src) { return src.substr(-3).toLowerCase() === 'svg' || INLINE_SVG.test(src); };
|
||||
//# sourceMappingURL=cache-storage.js.map
|
1
dist/lib/core/cache-storage.js.map
vendored
Normal file
1
dist/lib/core/cache-storage.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
146
dist/lib/core/features.js
vendored
Normal file
146
dist/lib/core/features.js
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var testRangeBounds = function (document) {
|
||||
var TEST_HEIGHT = 123;
|
||||
if (document.createRange) {
|
||||
var range = document.createRange();
|
||||
if (range.getBoundingClientRect) {
|
||||
var testElement = document.createElement('boundtest');
|
||||
testElement.style.height = TEST_HEIGHT + "px";
|
||||
testElement.style.display = 'block';
|
||||
document.body.appendChild(testElement);
|
||||
range.selectNode(testElement);
|
||||
var rangeBounds = range.getBoundingClientRect();
|
||||
var rangeHeight = Math.round(rangeBounds.height);
|
||||
document.body.removeChild(testElement);
|
||||
if (rangeHeight === TEST_HEIGHT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var testCORS = function () { return typeof new Image().crossOrigin !== 'undefined'; };
|
||||
var testResponseType = function () { return typeof new XMLHttpRequest().responseType === 'string'; };
|
||||
var testSVG = function (document) {
|
||||
var img = new Image();
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
return false;
|
||||
}
|
||||
img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
|
||||
try {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
canvas.toDataURL();
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var isGreenPixel = function (data) {
|
||||
return data[0] === 0 && data[1] === 255 && data[2] === 0 && data[3] === 255;
|
||||
};
|
||||
var testForeignObject = function (document) {
|
||||
var canvas = document.createElement('canvas');
|
||||
var size = 100;
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
var ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
return Promise.reject(false);
|
||||
}
|
||||
ctx.fillStyle = 'rgb(0, 255, 0)';
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
var img = new Image();
|
||||
var greenImageSrc = canvas.toDataURL();
|
||||
img.src = greenImageSrc;
|
||||
var svg = exports.createForeignObjectSVG(size, size, 0, 0, img);
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
return exports.loadSerializedSVG(svg)
|
||||
.then(function (img) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
var data = ctx.getImageData(0, 0, size, size).data;
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
var node = document.createElement('div');
|
||||
node.style.backgroundImage = "url(" + greenImageSrc + ")";
|
||||
node.style.height = size + "px";
|
||||
// Firefox 55 does not render inline <img /> tags
|
||||
return isGreenPixel(data)
|
||||
? exports.loadSerializedSVG(exports.createForeignObjectSVG(size, size, 0, 0, node))
|
||||
: Promise.reject(false);
|
||||
})
|
||||
.then(function (img) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
// Edge does not render background-images
|
||||
return isGreenPixel(ctx.getImageData(0, 0, size, size).data);
|
||||
})
|
||||
.catch(function () { return false; });
|
||||
};
|
||||
exports.createForeignObjectSVG = function (width, height, x, y, node) {
|
||||
var xmlns = 'http://www.w3.org/2000/svg';
|
||||
var svg = document.createElementNS(xmlns, 'svg');
|
||||
var foreignObject = document.createElementNS(xmlns, 'foreignObject');
|
||||
svg.setAttributeNS(null, 'width', width.toString());
|
||||
svg.setAttributeNS(null, 'height', height.toString());
|
||||
foreignObject.setAttributeNS(null, 'width', '100%');
|
||||
foreignObject.setAttributeNS(null, 'height', '100%');
|
||||
foreignObject.setAttributeNS(null, 'x', x.toString());
|
||||
foreignObject.setAttributeNS(null, 'y', y.toString());
|
||||
foreignObject.setAttributeNS(null, 'externalResourcesRequired', 'true');
|
||||
svg.appendChild(foreignObject);
|
||||
foreignObject.appendChild(node);
|
||||
return svg;
|
||||
};
|
||||
exports.loadSerializedSVG = function (svg) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var img = new Image();
|
||||
img.onload = function () { return resolve(img); };
|
||||
img.onerror = reject;
|
||||
img.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(new XMLSerializer().serializeToString(svg));
|
||||
});
|
||||
};
|
||||
exports.FEATURES = {
|
||||
get SUPPORT_RANGE_BOUNDS() {
|
||||
'use strict';
|
||||
var value = testRangeBounds(document);
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_RANGE_BOUNDS', { value: value });
|
||||
return value;
|
||||
},
|
||||
get SUPPORT_SVG_DRAWING() {
|
||||
'use strict';
|
||||
var value = testSVG(document);
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_SVG_DRAWING', { value: value });
|
||||
return value;
|
||||
},
|
||||
get SUPPORT_FOREIGNOBJECT_DRAWING() {
|
||||
'use strict';
|
||||
var value = typeof Array.from === 'function' && typeof window.fetch === 'function'
|
||||
? testForeignObject(document)
|
||||
: Promise.resolve(false);
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_FOREIGNOBJECT_DRAWING', { value: value });
|
||||
return value;
|
||||
},
|
||||
get SUPPORT_CORS_IMAGES() {
|
||||
'use strict';
|
||||
var value = testCORS();
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_CORS_IMAGES', { value: value });
|
||||
return value;
|
||||
},
|
||||
get SUPPORT_RESPONSE_TYPE() {
|
||||
'use strict';
|
||||
var value = testResponseType();
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_RESPONSE_TYPE', { value: value });
|
||||
return value;
|
||||
},
|
||||
get SUPPORT_CORS_XHR() {
|
||||
'use strict';
|
||||
var value = 'withCredentials' in new XMLHttpRequest();
|
||||
Object.defineProperty(exports.FEATURES, 'SUPPORT_CORS_XHR', { value: value });
|
||||
return value;
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=features.js.map
|
1
dist/lib/core/features.js.map
vendored
Normal file
1
dist/lib/core/features.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
78
dist/lib/core/logger.js
vendored
Normal file
78
dist/lib/core/logger.js
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Logger = /** @class */ (function () {
|
||||
function Logger(_a) {
|
||||
var id = _a.id, enabled = _a.enabled;
|
||||
this.id = id;
|
||||
this.enabled = enabled;
|
||||
this.start = Date.now();
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Logger.prototype.debug = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
if (this.enabled) {
|
||||
// eslint-disable-next-line no-console
|
||||
if (typeof window !== 'undefined' && window.console && typeof console.debug === 'function') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug.apply(console, [this.id, this.getTime() + "ms"].concat(args));
|
||||
}
|
||||
else {
|
||||
this.info.apply(this, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
Logger.prototype.getTime = function () {
|
||||
return Date.now() - this.start;
|
||||
};
|
||||
Logger.create = function (options) {
|
||||
Logger.instances[options.id] = new Logger(options);
|
||||
};
|
||||
Logger.destroy = function (id) {
|
||||
delete Logger.instances[id];
|
||||
};
|
||||
Logger.getInstance = function (id) {
|
||||
var instance = Logger.instances[id];
|
||||
if (typeof instance === 'undefined') {
|
||||
throw new Error("No logger instance found with id " + id);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Logger.prototype.info = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
if (this.enabled) {
|
||||
// eslint-disable-next-line no-console
|
||||
if (typeof window !== 'undefined' && window.console && typeof console.info === 'function') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.info.apply(console, [this.id, this.getTime() + "ms"].concat(args));
|
||||
}
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Logger.prototype.error = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
if (this.enabled) {
|
||||
// eslint-disable-next-line no-console
|
||||
if (typeof window !== 'undefined' && window.console && typeof console.error === 'function') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error.apply(console, [this.id, this.getTime() + "ms"].concat(args));
|
||||
}
|
||||
else {
|
||||
this.info.apply(this, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
Logger.instances = {};
|
||||
return Logger;
|
||||
}());
|
||||
exports.Logger = Logger;
|
||||
//# sourceMappingURL=logger.js.map
|
1
dist/lib/core/logger.js.map
vendored
Normal file
1
dist/lib/core/logger.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/core/logger.ts"],"names":[],"mappings":";;AAKA;IAOI,gBAAY,EAA4B;YAA3B,UAAE,EAAE,oBAAO;QACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED,8DAA8D;IAC9D,sBAAK,GAAL;QAAM,cAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,yBAAY;;QACd,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,sCAAsC;YACtC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;gBACxF,sCAAsC;gBACtC,OAAO,CAAC,KAAK,OAAb,OAAO,GAAO,IAAI,CAAC,EAAE,EAAK,IAAI,CAAC,OAAO,EAAE,OAAI,SAAK,IAAI,GAAE;aAC1D;iBAAM;gBACH,IAAI,CAAC,IAAI,OAAT,IAAI,EAAS,IAAI,EAAE;aACtB;SACJ;IACL,CAAC;IAED,wBAAO,GAAP;QACI,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,CAAC;IAEM,aAAM,GAAb,UAAc,OAAsB;QAChC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAEM,cAAO,GAAd,UAAe,EAAU;QACrB,OAAO,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IAEM,kBAAW,GAAlB,UAAmB,EAAU;QACzB,IAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,sCAAoC,EAAI,CAAC,CAAC;SAC7D;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,8DAA8D;IAC9D,qBAAI,GAAJ;QAAK,cAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,yBAAY;;QACb,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,sCAAsC;YACtC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;gBACvF,sCAAsC;gBACtC,OAAO,CAAC,IAAI,OAAZ,OAAO,GAAM,IAAI,CAAC,EAAE,EAAK,IAAI,CAAC,OAAO,EAAE,OAAI,SAAK,IAAI,GAAE;aACzD;SACJ;IACL,CAAC;IAED,8DAA8D;IAC9D,sBAAK,GAAL;QAAM,cAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,yBAAY;;QACd,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,sCAAsC;YACtC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;gBACxF,sCAAsC;gBACtC,OAAO,CAAC,KAAK,OAAb,OAAO,GAAO,IAAI,CAAC,EAAE,EAAK,IAAI,CAAC,OAAO,EAAE,OAAI,SAAK,IAAI,GAAE;aAC1D;iBAAM;gBACH,IAAI,CAAC,IAAI,OAAT,IAAI,EAAS,IAAI,EAAE;aACtB;SACJ;IACL,CAAC;IAnEM,gBAAS,GAA4B,EAAE,CAAC;IAoEnD,aAAC;CAAA,AArED,IAqEC;AArEY,wBAAM"}
|
4
dist/lib/core/util.js
vendored
Normal file
4
dist/lib/core/util.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SMALL_IMAGE = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
||||
//# sourceMappingURL=util.js.map
|
1
dist/lib/core/util.js.map
vendored
Normal file
1
dist/lib/core/util.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/core/util.ts"],"names":[],"mappings":";;AAAa,QAAA,WAAW,GAAG,gFAAgF,CAAC"}
|
Reference in New Issue
Block a user