@limetech/lime-elements 36.4.0-next.5 → 36.4.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/limel-icon.cjs.entry.js +31 -44
- package/dist/cjs/limel-list_2.cjs.entry.js +1 -1
- package/dist/cjs/limel-menu_2.cjs.entry.js +1 -1
- package/dist/collection/components/list/list.css +2 -2
- package/dist/collection/components/menu-list/menu-list.css +2 -2
- package/dist/collection/global/icon-cache.js +29 -42
- package/dist/esm/limel-icon.entry.js +31 -44
- package/dist/esm/limel-list_2.entry.js +1 -1
- package/dist/esm/limel-menu_2.entry.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-a030e9ab.entry.js → p-a3acc38f.entry.js} +1 -1
- package/dist/lime-elements/{p-f1d963ec.entry.js → p-b0bfec52.entry.js} +1 -1
- package/dist/lime-elements/p-d55d88a5.entry.js +1 -0
- package/dist/types/global/icon-cache.d.ts +6 -5
- package/package.json +5 -5
- package/dist/lime-elements/p-75d01713.entry.js +0 -1
|
@@ -5,50 +5,40 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const index = require('./index-287e25e0.js');
|
|
6
6
|
const config = require('./config-c6520559.js');
|
|
7
7
|
|
|
8
|
+
const CACHE_NAME = '@limetech/lime-elements/icons';
|
|
8
9
|
class IconCache {
|
|
9
10
|
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
this.cache = {};
|
|
14
|
-
/*
|
|
15
|
-
* Contains resolve functions for all unresolved promises that are waiting for SVG data.
|
|
16
|
-
*/
|
|
17
|
-
this.resolveFunctions = {};
|
|
11
|
+
this.promises = {};
|
|
12
|
+
this.cache = caches.open(CACHE_NAME);
|
|
18
13
|
}
|
|
19
14
|
/**
|
|
20
15
|
* Get icon data from the cache
|
|
21
16
|
* @param {string} name name of the icon
|
|
22
17
|
* @param {string} path path on the server where the assets are located
|
|
23
|
-
* @returns {string} svg markup
|
|
18
|
+
* @returns {Promise<string>} svg markup
|
|
24
19
|
*/
|
|
25
20
|
async get(name, path = '') {
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const cache = await this.cache;
|
|
22
|
+
const url = this.getUrl(name, path);
|
|
23
|
+
let response = await cache.match(url);
|
|
24
|
+
if (!response) {
|
|
25
|
+
response = await this.fetchData(url, cache);
|
|
28
26
|
}
|
|
29
|
-
return this.
|
|
27
|
+
return this.getIcon(response);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
this.resolveFunctions[name].push(resolve);
|
|
41
|
-
});
|
|
29
|
+
async fetchData(url, cache) {
|
|
30
|
+
let requestPromise = this.promises[url];
|
|
31
|
+
if (requestPromise === undefined) {
|
|
32
|
+
requestPromise = cache.add(url);
|
|
33
|
+
this.promises[url] = requestPromise;
|
|
34
|
+
}
|
|
35
|
+
await requestPromise;
|
|
36
|
+
return cache.match(url);
|
|
42
37
|
}
|
|
43
38
|
/*
|
|
44
|
-
*
|
|
39
|
+
* Get icon data from a response
|
|
45
40
|
*/
|
|
46
|
-
async
|
|
47
|
-
let iconPath = path || '';
|
|
48
|
-
if (path && !path.endsWith('/')) {
|
|
49
|
-
iconPath = `${path}/`;
|
|
50
|
-
}
|
|
51
|
-
const response = await fetch(`${iconPath}assets/icons/${name}.svg`);
|
|
41
|
+
async getIcon(response) {
|
|
52
42
|
let svgData = await response.text();
|
|
53
43
|
// Some of the icons in the Icons8 library have hard coded black color on some of the paths.
|
|
54
44
|
// In order to apply coloring with CSS, these have to be set to 'currentColor'
|
|
@@ -56,7 +46,7 @@ class IconCache {
|
|
|
56
46
|
if (!this.validSvg(svgData)) {
|
|
57
47
|
throw new Error('Invalid SVG');
|
|
58
48
|
}
|
|
59
|
-
|
|
49
|
+
return svgData;
|
|
60
50
|
}
|
|
61
51
|
/*
|
|
62
52
|
* Check if the given data is a valid SVG document
|
|
@@ -66,20 +56,17 @@ class IconCache {
|
|
|
66
56
|
const svgDoc = parser.parseFromString(data, 'image/svg+xml');
|
|
67
57
|
return svgDoc.documentElement.tagName.toLowerCase() === 'svg';
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
resolve(svgData);
|
|
76
|
-
});
|
|
77
|
-
this.resolveFunctions[name] = null;
|
|
59
|
+
getUrl(name, path) {
|
|
60
|
+
let iconPath = path || '';
|
|
61
|
+
if (path && !path.endsWith('/')) {
|
|
62
|
+
iconPath = `${path}/`;
|
|
63
|
+
}
|
|
64
|
+
return `${iconPath}assets/icons/${name}.svg`;
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
|
-
const
|
|
81
|
-
const iconCache = (() => {
|
|
82
|
-
return
|
|
67
|
+
const iconCache = new IconCache();
|
|
68
|
+
const iconCache$1 = (() => {
|
|
69
|
+
return iconCache;
|
|
83
70
|
})();
|
|
84
71
|
|
|
85
72
|
const iconCss = ":host{background-color:var(--icon-background-color, transparent);border-radius:50%;display:inline-block;line-height:0;box-sizing:border-box}:host svg{fill:currentColor;height:100%;pointer-events:none;width:100%}:host([hidden]){display:none}:host([size=x-small]){height:0.9375rem !important;width:0.9375rem !important}:host([size=small]){height:1.25rem !important;width:1.25rem !important}:host([size=medium]){height:1.5625rem !important;width:1.5625rem !important}:host([size=large]){height:1.875rem !important;width:1.875rem !important}:host([badge][size=x-small]){height:1.4375rem !important;width:1.4375rem !important}:host([badge][size=x-small])>div{margin:0.25rem}:host([badge][size=small]){height:1.875rem !important;width:1.875rem !important}:host([badge][size=small])>div{margin:0.3125rem}:host([badge][size=medium]){height:2.5rem !important;width:2.5rem !important}:host([badge][size=medium])>div{margin:0.5rem}:host([badge][size=large]){height:2.875rem !important;width:2.875rem !important}:host([badge][size=large])>div{margin:0.5rem}";
|
|
@@ -110,7 +97,7 @@ const Icon = class {
|
|
|
110
97
|
* @returns {string} the icon SVG data
|
|
111
98
|
*/
|
|
112
99
|
loadSvg(name) {
|
|
113
|
-
return iconCache.get(name, config.config.iconPath);
|
|
100
|
+
return iconCache$1.get(name, config.config.iconPath);
|
|
114
101
|
}
|
|
115
102
|
/*
|
|
116
103
|
* There is no way to style external SVG files with CSS, i.e. SVGs loaded
|