1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.default = (function (window, options, logger) {
|
5 | var cache = null;
|
6 | if (options.env !== 'development') {
|
7 | try {
|
8 | cache = (typeof window.localStorage === 'undefined') ? null : window.localStorage;
|
9 | }
|
10 | catch (_) { }
|
11 | }
|
12 | return {
|
13 | setCSS: function (path, lastModified, modifyVars, styles) {
|
14 | if (cache) {
|
15 | logger.info("saving " + path + " to cache.");
|
16 | try {
|
17 | cache.setItem(path, styles);
|
18 | cache.setItem(path + ":timestamp", lastModified);
|
19 | if (modifyVars) {
|
20 | cache.setItem(path + ":vars", JSON.stringify(modifyVars));
|
21 | }
|
22 | }
|
23 | catch (e) {
|
24 |
|
25 | logger.error("failed to save \"" + path + "\" to local storage for caching.");
|
26 | }
|
27 | }
|
28 | },
|
29 | getCSS: function (path, webInfo, modifyVars) {
|
30 | var css = cache && cache.getItem(path);
|
31 | var timestamp = cache && cache.getItem(path + ":timestamp");
|
32 | var vars = cache && cache.getItem(path + ":vars");
|
33 | modifyVars = modifyVars || {};
|
34 | vars = vars || "{}";
|
35 | if (timestamp && webInfo.lastModified &&
|
36 | (new Date(webInfo.lastModified).valueOf() ===
|
37 | new Date(timestamp).valueOf()) &&
|
38 | JSON.stringify(modifyVars) === vars) {
|
39 |
|
40 | return css;
|
41 | }
|
42 | }
|
43 | };
|
44 | });
|
45 |
|
\ | No newline at end of file |