Skip to content

Commit 98e2142

Browse files
committed
chore: iconify-icon 2.3.0
1 parent 7bdd84d commit 98e2142

File tree

10 files changed

+7432
-671
lines changed

10 files changed

+7432
-671
lines changed

iconify-icon/2-latest/iconify-icon.cjs

Lines changed: 15 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Licensed under MIT.
88
*
99
* @license MIT
10-
* @version 2.2.0
10+
* @version 2.3.0
1111
*/
1212
'use strict';
1313

@@ -921,201 +921,6 @@ function sendAPIQuery(target, query, callback) {
921921
return redundancy.query(query, send, callback)().abort;
922922
}
923923

924-
const browserCacheVersion = "iconify2";
925-
const browserCachePrefix = "iconify";
926-
const browserCacheCountKey = browserCachePrefix + "-count";
927-
const browserCacheVersionKey = browserCachePrefix + "-version";
928-
const browserStorageHour = 36e5;
929-
const browserStorageCacheExpiration = 168;
930-
const browserStorageLimit = 50;
931-
932-
function getStoredItem(func, key) {
933-
try {
934-
return func.getItem(key);
935-
} catch (err) {
936-
}
937-
}
938-
function setStoredItem(func, key, value) {
939-
try {
940-
func.setItem(key, value);
941-
return true;
942-
} catch (err) {
943-
}
944-
}
945-
function removeStoredItem(func, key) {
946-
try {
947-
func.removeItem(key);
948-
} catch (err) {
949-
}
950-
}
951-
952-
function setBrowserStorageItemsCount(storage, value) {
953-
return setStoredItem(storage, browserCacheCountKey, value.toString());
954-
}
955-
function getBrowserStorageItemsCount(storage) {
956-
return parseInt(getStoredItem(storage, browserCacheCountKey)) || 0;
957-
}
958-
959-
const browserStorageConfig = {
960-
local: true,
961-
session: true
962-
};
963-
const browserStorageEmptyItems = {
964-
local: /* @__PURE__ */ new Set(),
965-
session: /* @__PURE__ */ new Set()
966-
};
967-
let browserStorageStatus = false;
968-
function setBrowserStorageStatus(status) {
969-
browserStorageStatus = status;
970-
}
971-
972-
let _window = typeof window === "undefined" ? {} : window;
973-
function getBrowserStorage(key) {
974-
const attr = key + "Storage";
975-
try {
976-
if (_window && _window[attr] && typeof _window[attr].length === "number") {
977-
return _window[attr];
978-
}
979-
} catch (err) {
980-
}
981-
browserStorageConfig[key] = false;
982-
}
983-
984-
function iterateBrowserStorage(key, callback) {
985-
const func = getBrowserStorage(key);
986-
if (!func) {
987-
return;
988-
}
989-
const version = getStoredItem(func, browserCacheVersionKey);
990-
if (version !== browserCacheVersion) {
991-
if (version) {
992-
const total2 = getBrowserStorageItemsCount(func);
993-
for (let i = 0; i < total2; i++) {
994-
removeStoredItem(func, browserCachePrefix + i.toString());
995-
}
996-
}
997-
setStoredItem(func, browserCacheVersionKey, browserCacheVersion);
998-
setBrowserStorageItemsCount(func, 0);
999-
return;
1000-
}
1001-
const minTime = Math.floor(Date.now() / browserStorageHour) - browserStorageCacheExpiration;
1002-
const parseItem = (index) => {
1003-
const name = browserCachePrefix + index.toString();
1004-
const item = getStoredItem(func, name);
1005-
if (typeof item !== "string") {
1006-
return;
1007-
}
1008-
try {
1009-
const data = JSON.parse(item);
1010-
if (typeof data === "object" && typeof data.cached === "number" && data.cached > minTime && typeof data.provider === "string" && typeof data.data === "object" && typeof data.data.prefix === "string" && // Valid item: run callback
1011-
callback(data, index)) {
1012-
return true;
1013-
}
1014-
} catch (err) {
1015-
}
1016-
removeStoredItem(func, name);
1017-
};
1018-
let total = getBrowserStorageItemsCount(func);
1019-
for (let i = total - 1; i >= 0; i--) {
1020-
if (!parseItem(i)) {
1021-
if (i === total - 1) {
1022-
total--;
1023-
setBrowserStorageItemsCount(func, total);
1024-
} else {
1025-
browserStorageEmptyItems[key].add(i);
1026-
}
1027-
}
1028-
}
1029-
}
1030-
1031-
function initBrowserStorage() {
1032-
if (browserStorageStatus) {
1033-
return;
1034-
}
1035-
setBrowserStorageStatus(true);
1036-
for (const key in browserStorageConfig) {
1037-
iterateBrowserStorage(key, (item) => {
1038-
const iconSet = item.data;
1039-
const provider = item.provider;
1040-
const prefix = iconSet.prefix;
1041-
const storage = getStorage(
1042-
provider,
1043-
prefix
1044-
);
1045-
if (!addIconSet(storage, iconSet).length) {
1046-
return false;
1047-
}
1048-
const lastModified = iconSet.lastModified || -1;
1049-
storage.lastModifiedCached = storage.lastModifiedCached ? Math.min(storage.lastModifiedCached, lastModified) : lastModified;
1050-
return true;
1051-
});
1052-
}
1053-
}
1054-
1055-
function updateLastModified(storage, lastModified) {
1056-
const lastValue = storage.lastModifiedCached;
1057-
if (
1058-
// Matches or newer
1059-
lastValue && lastValue >= lastModified
1060-
) {
1061-
return lastValue === lastModified;
1062-
}
1063-
storage.lastModifiedCached = lastModified;
1064-
if (lastValue) {
1065-
for (const key in browserStorageConfig) {
1066-
iterateBrowserStorage(key, (item) => {
1067-
const iconSet = item.data;
1068-
return item.provider !== storage.provider || iconSet.prefix !== storage.prefix || iconSet.lastModified === lastModified;
1069-
});
1070-
}
1071-
}
1072-
return true;
1073-
}
1074-
function storeInBrowserStorage(storage, data) {
1075-
if (!browserStorageStatus) {
1076-
initBrowserStorage();
1077-
}
1078-
function store(key) {
1079-
let func;
1080-
if (!browserStorageConfig[key] || !(func = getBrowserStorage(key))) {
1081-
return;
1082-
}
1083-
const set = browserStorageEmptyItems[key];
1084-
let index;
1085-
if (set.size) {
1086-
set.delete(index = Array.from(set).shift());
1087-
} else {
1088-
index = getBrowserStorageItemsCount(func);
1089-
if (index >= browserStorageLimit || !setBrowserStorageItemsCount(func, index + 1)) {
1090-
return;
1091-
}
1092-
}
1093-
const item = {
1094-
cached: Math.floor(Date.now() / browserStorageHour),
1095-
provider: storage.provider,
1096-
data
1097-
};
1098-
return setStoredItem(
1099-
func,
1100-
browserCachePrefix + index.toString(),
1101-
JSON.stringify(item)
1102-
);
1103-
}
1104-
if (data.lastModified && !updateLastModified(storage, data.lastModified)) {
1105-
return;
1106-
}
1107-
if (!Object.keys(data.icons).length) {
1108-
return;
1109-
}
1110-
if (data.not_found) {
1111-
data = Object.assign({}, data);
1112-
delete data.not_found;
1113-
}
1114-
if (!store("local")) {
1115-
store("session");
1116-
}
1117-
}
1118-
1119924
function emptyCallback() {
1120925
}
1121926
function loadedNewIcons(storage) {
@@ -1138,7 +943,7 @@ function checkIconNamesForAPI(icons) {
1138943
invalid
1139944
};
1140945
}
1141-
function parseLoaderResponse(storage, icons, data, isAPIResponse) {
946+
function parseLoaderResponse(storage, icons, data) {
1142947
function checkMissing() {
1143948
const pending = storage.pendingIcons;
1144949
icons.forEach((name) => {
@@ -1157,9 +962,6 @@ function parseLoaderResponse(storage, icons, data, isAPIResponse) {
1157962
checkMissing();
1158963
return;
1159964
}
1160-
if (isAPIResponse) {
1161-
storeInBrowserStorage(storage, data);
1162-
}
1163965
} catch (err) {
1164966
console.error(err);
1165967
}
@@ -1199,7 +1001,7 @@ function loadNewIcons(storage, icons) {
11991001
parsePossiblyAsyncResponse(
12001002
storage.loadIcons(icons2, prefix, provider),
12011003
(data) => {
1202-
parseLoaderResponse(storage, icons2, data, false);
1004+
parseLoaderResponse(storage, icons2, data);
12031005
}
12041006
);
12051007
return;
@@ -1214,27 +1016,27 @@ function loadNewIcons(storage, icons) {
12141016
[name]: data
12151017
}
12161018
} : null;
1217-
parseLoaderResponse(storage, [name], iconSet, false);
1019+
parseLoaderResponse(storage, [name], iconSet);
12181020
});
12191021
});
12201022
return;
12211023
}
12221024
const { valid, invalid } = checkIconNamesForAPI(icons2);
12231025
if (invalid.length) {
1224-
parseLoaderResponse(storage, invalid, null, false);
1026+
parseLoaderResponse(storage, invalid, null);
12251027
}
12261028
if (!valid.length) {
12271029
return;
12281030
}
12291031
const api = prefix.match(matchIconName) ? getAPIModule(provider) : null;
12301032
if (!api) {
1231-
parseLoaderResponse(storage, valid, null, false);
1033+
parseLoaderResponse(storage, valid, null);
12321034
return;
12331035
}
12341036
const params = api.prepare(provider, prefix, valid);
12351037
params.forEach((item) => {
12361038
sendAPIQuery(provider, item, (data) => {
1237-
parseLoaderResponse(storage, item.icons, data, true);
1039+
parseLoaderResponse(storage, item.icons, data);
12381040
});
12391041
});
12401042
});
@@ -1761,20 +1563,6 @@ function setCustomIconLoader$1(loader, prefix, provider) {
17611563
getStorage(provider || "", prefix).loadIcon = loader;
17621564
}
17631565

1764-
function toggleBrowserCache(storage, value) {
1765-
switch (storage) {
1766-
case "local":
1767-
case "session":
1768-
browserStorageConfig[storage] = value;
1769-
break;
1770-
case "all":
1771-
for (const key in browserStorageConfig) {
1772-
browserStorageConfig[key] = value;
1773-
}
1774-
break;
1775-
}
1776-
}
1777-
17781566
/**
17791567
* Attribute to add
17801568
*/
@@ -1832,8 +1620,6 @@ function exportFunctions() {
18321620
//
18331621
}
18341622
if (_window) {
1835-
// Set cache and load existing cache
1836-
initBrowserStorage();
18371623
// Load icons from global "IconifyPreload"
18381624
if (_window.IconifyPreload !== void 0) {
18391625
const preload = _window.IconifyPreload;
@@ -1895,8 +1681,14 @@ function exportFunctions() {
18951681
listAPIProviders,
18961682
};
18971683
return {
1898-
enableCache: (storage) => toggleBrowserCache(storage, true),
1899-
disableCache: (storage) => toggleBrowserCache(storage, false),
1684+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1685+
enableCache: (storage) => {
1686+
// No longer used
1687+
},
1688+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1689+
disableCache: (storage) => {
1690+
// No longer used
1691+
},
19001692
iconLoaded: iconLoaded$1,
19011693
iconExists: iconLoaded$1, // deprecated, kept to avoid breaking changes
19021694
getIcon: getIcon$1,

iconify-icon/2-latest/iconify-icon.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export declare const _api: IconifyAPIInternalFunctions;
2626
*/
2727
export declare function appendCustomStyle(style: string): void;
2828

29+
/**
30+
* Storage types
31+
*
32+
* @deprecated This type is not used anymore
33+
*/
2934
declare type BrowserStorageType = 'local' | 'session';
3035

3136
export declare const buildIcon: (icon: IconifyIcon, customisations?: IconifyIconCustomisations) => IconifyIconBuildResult;
@@ -145,6 +150,8 @@ export declare type IconifyAPISendQuery = (host: string, params: IconifyAPIQuery
145150

146151
/**
147152
* Interface for exported functions
153+
*
154+
* @deprecated This type is not used anymore
148155
*/
149156
export declare interface IconifyBrowserCacheFunctions {
150157
enableCache: (storage: IconifyBrowserCacheType) => void;
@@ -153,6 +160,8 @@ export declare interface IconifyBrowserCacheFunctions {
153160

154161
/**
155162
* Cache types
163+
*
164+
* @deprecated This type is not used anymore
156165
*/
157166
export declare type IconifyBrowserCacheType = BrowserStorageType | 'all';
158167

0 commit comments

Comments
 (0)