@iconify_iconify.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  1. import {
  2. __spreadValues,
  3. init_define_APP_INFO
  4. } from "./chunk-XY75H3MP.js";
  5. // dep:@iconify_iconify
  6. init_define_APP_INFO();
  7. // node_modules/@iconify/iconify/dist/iconify.mjs
  8. init_define_APP_INFO();
  9. var matchName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
  10. var iconDefaults = Object.freeze({
  11. left: 0,
  12. top: 0,
  13. width: 16,
  14. height: 16,
  15. rotate: 0,
  16. vFlip: false,
  17. hFlip: false
  18. });
  19. function fullIcon(data) {
  20. return __spreadValues(__spreadValues({}, iconDefaults), data);
  21. }
  22. function mergeIconData(icon, alias) {
  23. const result = __spreadValues({}, icon);
  24. for (const key in iconDefaults) {
  25. const prop = key;
  26. if (alias[prop] !== void 0) {
  27. const value = alias[prop];
  28. if (result[prop] === void 0) {
  29. result[prop] = value;
  30. continue;
  31. }
  32. switch (prop) {
  33. case "rotate":
  34. result[prop] = (result[prop] + value) % 4;
  35. break;
  36. case "hFlip":
  37. case "vFlip":
  38. result[prop] = value !== result[prop];
  39. break;
  40. default:
  41. result[prop] = value;
  42. }
  43. }
  44. }
  45. return result;
  46. }
  47. function getIconData$1(data, name, full = false) {
  48. function getIcon2(name2, iteration) {
  49. if (data.icons[name2] !== void 0) {
  50. return Object.assign({}, data.icons[name2]);
  51. }
  52. if (iteration > 5) {
  53. return null;
  54. }
  55. const aliases = data.aliases;
  56. if (aliases && aliases[name2] !== void 0) {
  57. const item = aliases[name2];
  58. const result2 = getIcon2(item.parent, iteration + 1);
  59. if (result2) {
  60. return mergeIconData(result2, item);
  61. }
  62. return result2;
  63. }
  64. const chars = data.chars;
  65. if (!iteration && chars && chars[name2] !== void 0) {
  66. return getIcon2(chars[name2], iteration + 1);
  67. }
  68. return null;
  69. }
  70. const result = getIcon2(name, 0);
  71. if (result) {
  72. for (const key in iconDefaults) {
  73. if (result[key] === void 0 && data[key] !== void 0) {
  74. result[key] = data[key];
  75. }
  76. }
  77. }
  78. return result && full ? fullIcon(result) : result;
  79. }
  80. function isVariation(item) {
  81. for (const key in iconDefaults) {
  82. if (item[key] !== void 0) {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. function parseIconSet(data, callback2, options) {
  89. options = options || {};
  90. const names = [];
  91. if (typeof data !== "object" || typeof data.icons !== "object") {
  92. return names;
  93. }
  94. if (data.not_found instanceof Array) {
  95. data.not_found.forEach((name) => {
  96. callback2(name, null);
  97. names.push(name);
  98. });
  99. }
  100. const icons = data.icons;
  101. Object.keys(icons).forEach((name) => {
  102. const iconData = getIconData$1(data, name, true);
  103. if (iconData) {
  104. callback2(name, iconData);
  105. names.push(name);
  106. }
  107. });
  108. const parseAliases = options.aliases || "all";
  109. if (parseAliases !== "none" && typeof data.aliases === "object") {
  110. const aliases = data.aliases;
  111. Object.keys(aliases).forEach((name) => {
  112. if (parseAliases === "variations" && isVariation(aliases[name])) {
  113. return;
  114. }
  115. const iconData = getIconData$1(data, name, true);
  116. if (iconData) {
  117. callback2(name, iconData);
  118. names.push(name);
  119. }
  120. });
  121. }
  122. return names;
  123. }
  124. var optionalProperties = {
  125. provider: "string",
  126. aliases: "object",
  127. not_found: "object"
  128. };
  129. for (const prop in iconDefaults) {
  130. optionalProperties[prop] = typeof iconDefaults[prop];
  131. }
  132. function quicklyValidateIconSet(obj) {
  133. if (typeof obj !== "object" || obj === null) {
  134. return null;
  135. }
  136. const data = obj;
  137. if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
  138. return null;
  139. }
  140. for (const prop in optionalProperties) {
  141. if (obj[prop] !== void 0 && typeof obj[prop] !== optionalProperties[prop]) {
  142. return null;
  143. }
  144. }
  145. const icons = data.icons;
  146. for (const name in icons) {
  147. const icon = icons[name];
  148. if (!name.match(matchName) || typeof icon.body !== "string") {
  149. return null;
  150. }
  151. for (const prop in iconDefaults) {
  152. if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) {
  153. return null;
  154. }
  155. }
  156. }
  157. const aliases = data.aliases;
  158. if (aliases) {
  159. for (const name in aliases) {
  160. const icon = aliases[name];
  161. const parent = icon.parent;
  162. if (!name.match(matchName) || typeof parent !== "string" || !icons[parent] && !aliases[parent]) {
  163. return null;
  164. }
  165. for (const prop in iconDefaults) {
  166. if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) {
  167. return null;
  168. }
  169. }
  170. }
  171. }
  172. return data;
  173. }
  174. var stringToIcon = (value, validate, allowSimpleName, provider = "") => {
  175. const colonSeparated = value.split(":");
  176. if (value.slice(0, 1) === "@") {
  177. if (colonSeparated.length < 2 || colonSeparated.length > 3) {
  178. return null;
  179. }
  180. provider = colonSeparated.shift().slice(1);
  181. }
  182. if (colonSeparated.length > 3 || !colonSeparated.length) {
  183. return null;
  184. }
  185. if (colonSeparated.length > 1) {
  186. const name2 = colonSeparated.pop();
  187. const prefix = colonSeparated.pop();
  188. const result = {
  189. provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
  190. prefix,
  191. name: name2
  192. };
  193. return validate && !validateIcon(result) ? null : result;
  194. }
  195. const name = colonSeparated[0];
  196. const dashSeparated = name.split("-");
  197. if (dashSeparated.length > 1) {
  198. const result = {
  199. provider,
  200. prefix: dashSeparated.shift(),
  201. name: dashSeparated.join("-")
  202. };
  203. return validate && !validateIcon(result) ? null : result;
  204. }
  205. if (allowSimpleName && provider === "") {
  206. const result = {
  207. provider,
  208. prefix: "",
  209. name
  210. };
  211. return validate && !validateIcon(result, allowSimpleName) ? null : result;
  212. }
  213. return null;
  214. };
  215. var validateIcon = (icon, allowSimpleName) => {
  216. if (!icon) {
  217. return false;
  218. }
  219. return !!((icon.provider === "" || icon.provider.match(matchName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchName)) && icon.name.match(matchName));
  220. };
  221. var storageVersion = 1;
  222. var storage$1 = /* @__PURE__ */ Object.create(null);
  223. try {
  224. const w = window || self;
  225. if (w && w._iconifyStorage.version === storageVersion) {
  226. storage$1 = w._iconifyStorage.storage;
  227. }
  228. } catch (err) {
  229. }
  230. function shareStorage() {
  231. try {
  232. const w = window || self;
  233. if (w && !w._iconifyStorage) {
  234. w._iconifyStorage = {
  235. version: storageVersion,
  236. storage: storage$1
  237. };
  238. }
  239. } catch (err) {
  240. }
  241. }
  242. function newStorage(provider, prefix) {
  243. return {
  244. provider,
  245. prefix,
  246. icons: /* @__PURE__ */ Object.create(null),
  247. missing: /* @__PURE__ */ Object.create(null)
  248. };
  249. }
  250. function getStorage(provider, prefix) {
  251. if (storage$1[provider] === void 0) {
  252. storage$1[provider] = /* @__PURE__ */ Object.create(null);
  253. }
  254. const providerStorage = storage$1[provider];
  255. if (providerStorage[prefix] === void 0) {
  256. providerStorage[prefix] = newStorage(provider, prefix);
  257. }
  258. return providerStorage[prefix];
  259. }
  260. function addIconSet(storage2, data) {
  261. if (!quicklyValidateIconSet(data)) {
  262. return [];
  263. }
  264. const t = Date.now();
  265. return parseIconSet(data, (name, icon) => {
  266. if (icon) {
  267. storage2.icons[name] = icon;
  268. } else {
  269. storage2.missing[name] = t;
  270. }
  271. });
  272. }
  273. function addIconToStorage(storage2, name, icon) {
  274. try {
  275. if (typeof icon.body === "string") {
  276. storage2.icons[name] = Object.freeze(fullIcon(icon));
  277. return true;
  278. }
  279. } catch (err) {
  280. }
  281. return false;
  282. }
  283. function getIconFromStorage(storage2, name) {
  284. const value = storage2.icons[name];
  285. return value === void 0 ? null : value;
  286. }
  287. function listIcons(provider, prefix) {
  288. let allIcons = [];
  289. let providers;
  290. if (typeof provider === "string") {
  291. providers = [provider];
  292. } else {
  293. providers = Object.keys(storage$1);
  294. }
  295. providers.forEach((provider2) => {
  296. let prefixes;
  297. if (typeof provider2 === "string" && typeof prefix === "string") {
  298. prefixes = [prefix];
  299. } else {
  300. prefixes = storage$1[provider2] === void 0 ? [] : Object.keys(storage$1[provider2]);
  301. }
  302. prefixes.forEach((prefix2) => {
  303. const storage2 = getStorage(provider2, prefix2);
  304. const icons = Object.keys(storage2.icons).map((name) => (provider2 !== "" ? "@" + provider2 + ":" : "") + prefix2 + ":" + name);
  305. allIcons = allIcons.concat(icons);
  306. });
  307. });
  308. return allIcons;
  309. }
  310. var simpleNames = false;
  311. function allowSimpleNames(allow) {
  312. if (typeof allow === "boolean") {
  313. simpleNames = allow;
  314. }
  315. return simpleNames;
  316. }
  317. function getIconData(name) {
  318. const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name;
  319. return icon ? getIconFromStorage(getStorage(icon.provider, icon.prefix), icon.name) : null;
  320. }
  321. function addIcon(name, data) {
  322. const icon = stringToIcon(name, true, simpleNames);
  323. if (!icon) {
  324. return false;
  325. }
  326. const storage2 = getStorage(icon.provider, icon.prefix);
  327. return addIconToStorage(storage2, icon.name, data);
  328. }
  329. function addCollection(data, provider) {
  330. if (typeof data !== "object") {
  331. return false;
  332. }
  333. if (typeof provider !== "string") {
  334. provider = typeof data.provider === "string" ? data.provider : "";
  335. }
  336. if (simpleNames && provider === "" && (typeof data.prefix !== "string" || data.prefix === "")) {
  337. let added = false;
  338. if (quicklyValidateIconSet(data)) {
  339. data.prefix = "";
  340. parseIconSet(data, (name, icon) => {
  341. if (icon && addIcon(name, icon)) {
  342. added = true;
  343. }
  344. });
  345. }
  346. return added;
  347. }
  348. if (typeof data.prefix !== "string" || !validateIcon({
  349. provider,
  350. prefix: data.prefix,
  351. name: "a"
  352. })) {
  353. return false;
  354. }
  355. const storage2 = getStorage(provider, data.prefix);
  356. return !!addIconSet(storage2, data);
  357. }
  358. function iconExists(name) {
  359. return getIconData(name) !== null;
  360. }
  361. function getIcon(name) {
  362. const result = getIconData(name);
  363. return result ? __spreadValues({}, result) : null;
  364. }
  365. var defaults = Object.freeze({
  366. inline: false,
  367. width: null,
  368. height: null,
  369. hAlign: "center",
  370. vAlign: "middle",
  371. slice: false,
  372. hFlip: false,
  373. vFlip: false,
  374. rotate: 0
  375. });
  376. function mergeCustomisations(defaults2, item) {
  377. const result = {};
  378. for (const key in defaults2) {
  379. const attr = key;
  380. result[attr] = defaults2[attr];
  381. if (item[attr] === void 0) {
  382. continue;
  383. }
  384. const value = item[attr];
  385. switch (attr) {
  386. case "inline":
  387. case "slice":
  388. if (typeof value === "boolean") {
  389. result[attr] = value;
  390. }
  391. break;
  392. case "hFlip":
  393. case "vFlip":
  394. if (value === true) {
  395. result[attr] = !result[attr];
  396. }
  397. break;
  398. case "hAlign":
  399. case "vAlign":
  400. if (typeof value === "string" && value !== "") {
  401. result[attr] = value;
  402. }
  403. break;
  404. case "width":
  405. case "height":
  406. if (typeof value === "string" && value !== "" || typeof value === "number" && value || value === null) {
  407. result[attr] = value;
  408. }
  409. break;
  410. case "rotate":
  411. if (typeof value === "number") {
  412. result[attr] += value;
  413. }
  414. break;
  415. }
  416. }
  417. return result;
  418. }
  419. var unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
  420. var unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
  421. function calculateSize(size, ratio, precision) {
  422. if (ratio === 1) {
  423. return size;
  424. }
  425. precision = precision === void 0 ? 100 : precision;
  426. if (typeof size === "number") {
  427. return Math.ceil(size * ratio * precision) / precision;
  428. }
  429. if (typeof size !== "string") {
  430. return size;
  431. }
  432. const oldParts = size.split(unitsSplit);
  433. if (oldParts === null || !oldParts.length) {
  434. return size;
  435. }
  436. const newParts = [];
  437. let code = oldParts.shift();
  438. let isNumber = unitsTest.test(code);
  439. while (true) {
  440. if (isNumber) {
  441. const num = parseFloat(code);
  442. if (isNaN(num)) {
  443. newParts.push(code);
  444. } else {
  445. newParts.push(Math.ceil(num * ratio * precision) / precision);
  446. }
  447. } else {
  448. newParts.push(code);
  449. }
  450. code = oldParts.shift();
  451. if (code === void 0) {
  452. return newParts.join("");
  453. }
  454. isNumber = !isNumber;
  455. }
  456. }
  457. function preserveAspectRatio(props) {
  458. let result = "";
  459. switch (props.hAlign) {
  460. case "left":
  461. result += "xMin";
  462. break;
  463. case "right":
  464. result += "xMax";
  465. break;
  466. default:
  467. result += "xMid";
  468. }
  469. switch (props.vAlign) {
  470. case "top":
  471. result += "YMin";
  472. break;
  473. case "bottom":
  474. result += "YMax";
  475. break;
  476. default:
  477. result += "YMid";
  478. }
  479. result += props.slice ? " slice" : " meet";
  480. return result;
  481. }
  482. function iconToSVG(icon, customisations) {
  483. const box = {
  484. left: icon.left,
  485. top: icon.top,
  486. width: icon.width,
  487. height: icon.height
  488. };
  489. let body = icon.body;
  490. [icon, customisations].forEach((props) => {
  491. const transformations = [];
  492. const hFlip = props.hFlip;
  493. const vFlip = props.vFlip;
  494. let rotation = props.rotate;
  495. if (hFlip) {
  496. if (vFlip) {
  497. rotation += 2;
  498. } else {
  499. transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")");
  500. transformations.push("scale(-1 1)");
  501. box.top = box.left = 0;
  502. }
  503. } else if (vFlip) {
  504. transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")");
  505. transformations.push("scale(1 -1)");
  506. box.top = box.left = 0;
  507. }
  508. let tempValue;
  509. if (rotation < 0) {
  510. rotation -= Math.floor(rotation / 4) * 4;
  511. }
  512. rotation = rotation % 4;
  513. switch (rotation) {
  514. case 1:
  515. tempValue = box.height / 2 + box.top;
  516. transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")");
  517. break;
  518. case 2:
  519. transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")");
  520. break;
  521. case 3:
  522. tempValue = box.width / 2 + box.left;
  523. transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")");
  524. break;
  525. }
  526. if (rotation % 2 === 1) {
  527. if (box.left !== 0 || box.top !== 0) {
  528. tempValue = box.left;
  529. box.left = box.top;
  530. box.top = tempValue;
  531. }
  532. if (box.width !== box.height) {
  533. tempValue = box.width;
  534. box.width = box.height;
  535. box.height = tempValue;
  536. }
  537. }
  538. if (transformations.length) {
  539. body = '<g transform="' + transformations.join(" ") + '">' + body + "</g>";
  540. }
  541. });
  542. let width, height;
  543. if (customisations.width === null && customisations.height === null) {
  544. height = "1em";
  545. width = calculateSize(height, box.width / box.height);
  546. } else if (customisations.width !== null && customisations.height !== null) {
  547. width = customisations.width;
  548. height = customisations.height;
  549. } else if (customisations.height !== null) {
  550. height = customisations.height;
  551. width = calculateSize(height, box.width / box.height);
  552. } else {
  553. width = customisations.width;
  554. height = calculateSize(width, box.height / box.width);
  555. }
  556. if (width === "auto") {
  557. width = box.width;
  558. }
  559. if (height === "auto") {
  560. height = box.height;
  561. }
  562. width = typeof width === "string" ? width : width.toString() + "";
  563. height = typeof height === "string" ? height : height.toString() + "";
  564. const result = {
  565. attributes: {
  566. width,
  567. height,
  568. preserveAspectRatio: preserveAspectRatio(customisations),
  569. viewBox: box.left.toString() + " " + box.top.toString() + " " + box.width.toString() + " " + box.height.toString()
  570. },
  571. body
  572. };
  573. if (customisations.inline) {
  574. result.inline = true;
  575. }
  576. return result;
  577. }
  578. function buildIcon(icon, customisations) {
  579. return iconToSVG(fullIcon(icon), customisations ? mergeCustomisations(defaults, customisations) : defaults);
  580. }
  581. var regex = /\sid="(\S+)"/g;
  582. var randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
  583. var counter = 0;
  584. function replaceIDs(body, prefix = randomPrefix) {
  585. const ids = [];
  586. let match;
  587. while (match = regex.exec(body)) {
  588. ids.push(match[1]);
  589. }
  590. if (!ids.length) {
  591. return body;
  592. }
  593. ids.forEach((id) => {
  594. const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
  595. const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  596. body = body.replace(new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"), "$1" + newID + "$3");
  597. });
  598. return body;
  599. }
  600. var cacheVersion = "iconify2";
  601. var cachePrefix = "iconify";
  602. var countKey = cachePrefix + "-count";
  603. var versionKey = cachePrefix + "-version";
  604. var hour = 36e5;
  605. var cacheExpiration = 168;
  606. var config = {
  607. local: true,
  608. session: true
  609. };
  610. var loaded = false;
  611. var count = {
  612. local: 0,
  613. session: 0
  614. };
  615. var emptyList = {
  616. local: [],
  617. session: []
  618. };
  619. var _window = typeof window === "undefined" ? {} : window;
  620. function getGlobal(key) {
  621. const attr = key + "Storage";
  622. try {
  623. if (_window && _window[attr] && typeof _window[attr].length === "number") {
  624. return _window[attr];
  625. }
  626. } catch (err) {
  627. }
  628. config[key] = false;
  629. return null;
  630. }
  631. function setCount(storage2, key, value) {
  632. try {
  633. storage2.setItem(countKey, value.toString());
  634. count[key] = value;
  635. return true;
  636. } catch (err) {
  637. return false;
  638. }
  639. }
  640. function getCount(storage2) {
  641. const count2 = storage2.getItem(countKey);
  642. if (count2) {
  643. const total = parseInt(count2);
  644. return total ? total : 0;
  645. }
  646. return 0;
  647. }
  648. function initCache(storage2, key) {
  649. try {
  650. storage2.setItem(versionKey, cacheVersion);
  651. } catch (err) {
  652. }
  653. setCount(storage2, key, 0);
  654. }
  655. function destroyCache(storage2) {
  656. try {
  657. const total = getCount(storage2);
  658. for (let i = 0; i < total; i++) {
  659. storage2.removeItem(cachePrefix + i.toString());
  660. }
  661. } catch (err) {
  662. }
  663. }
  664. var loadCache = () => {
  665. if (loaded) {
  666. return;
  667. }
  668. loaded = true;
  669. const minTime = Math.floor(Date.now() / hour) - cacheExpiration;
  670. function load(key) {
  671. const func = getGlobal(key);
  672. if (!func) {
  673. return;
  674. }
  675. const getItem = (index) => {
  676. const name = cachePrefix + index.toString();
  677. const item = func.getItem(name);
  678. if (typeof item !== "string") {
  679. return false;
  680. }
  681. let valid = true;
  682. try {
  683. const data = JSON.parse(item);
  684. if (typeof data !== "object" || typeof data.cached !== "number" || data.cached < minTime || typeof data.provider !== "string" || typeof data.data !== "object" || typeof data.data.prefix !== "string") {
  685. valid = false;
  686. } else {
  687. const provider = data.provider;
  688. const prefix = data.data.prefix;
  689. const storage2 = getStorage(provider, prefix);
  690. valid = addIconSet(storage2, data.data).length > 0;
  691. }
  692. } catch (err) {
  693. valid = false;
  694. }
  695. if (!valid) {
  696. func.removeItem(name);
  697. }
  698. return valid;
  699. };
  700. try {
  701. const version = func.getItem(versionKey);
  702. if (version !== cacheVersion) {
  703. if (version) {
  704. destroyCache(func);
  705. }
  706. initCache(func, key);
  707. return;
  708. }
  709. let total = getCount(func);
  710. for (let i = total - 1; i >= 0; i--) {
  711. if (!getItem(i)) {
  712. if (i === total - 1) {
  713. total--;
  714. } else {
  715. emptyList[key].push(i);
  716. }
  717. }
  718. }
  719. setCount(func, key, total);
  720. } catch (err) {
  721. }
  722. }
  723. for (const key in config) {
  724. load(key);
  725. }
  726. };
  727. var storeCache = (provider, data) => {
  728. if (!loaded) {
  729. loadCache();
  730. }
  731. function store(key) {
  732. if (!config[key]) {
  733. return false;
  734. }
  735. const func = getGlobal(key);
  736. if (!func) {
  737. return false;
  738. }
  739. let index = emptyList[key].shift();
  740. if (index === void 0) {
  741. index = count[key];
  742. if (!setCount(func, key, index + 1)) {
  743. return false;
  744. }
  745. }
  746. try {
  747. const item = {
  748. cached: Math.floor(Date.now() / hour),
  749. provider,
  750. data
  751. };
  752. func.setItem(cachePrefix + index.toString(), JSON.stringify(item));
  753. } catch (err) {
  754. return false;
  755. }
  756. return true;
  757. }
  758. if (!Object.keys(data.icons).length) {
  759. return;
  760. }
  761. if (data.not_found) {
  762. data = Object.assign({}, data);
  763. delete data.not_found;
  764. }
  765. if (!store("local")) {
  766. store("session");
  767. }
  768. };
  769. var cache = {};
  770. function toggleBrowserCache(storage2, value) {
  771. switch (storage2) {
  772. case "local":
  773. case "session":
  774. config[storage2] = value;
  775. break;
  776. case "all":
  777. for (const key in config) {
  778. config[key] = value;
  779. }
  780. break;
  781. }
  782. }
  783. var storage = /* @__PURE__ */ Object.create(null);
  784. function setAPIModule(provider, item) {
  785. storage[provider] = item;
  786. }
  787. function getAPIModule(provider) {
  788. return storage[provider] || storage[""];
  789. }
  790. function createAPIConfig(source) {
  791. let resources;
  792. if (typeof source.resources === "string") {
  793. resources = [source.resources];
  794. } else {
  795. resources = source.resources;
  796. if (!(resources instanceof Array) || !resources.length) {
  797. return null;
  798. }
  799. }
  800. const result = {
  801. resources,
  802. path: source.path === void 0 ? "/" : source.path,
  803. maxURL: source.maxURL ? source.maxURL : 500,
  804. rotate: source.rotate ? source.rotate : 750,
  805. timeout: source.timeout ? source.timeout : 5e3,
  806. random: source.random === true,
  807. index: source.index ? source.index : 0,
  808. dataAfterTimeout: source.dataAfterTimeout !== false
  809. };
  810. return result;
  811. }
  812. var configStorage = /* @__PURE__ */ Object.create(null);
  813. var fallBackAPISources = [
  814. "https://api.simplesvg.com",
  815. "https://api.unisvg.com"
  816. ];
  817. var fallBackAPI = [];
  818. while (fallBackAPISources.length > 0) {
  819. if (fallBackAPISources.length === 1) {
  820. fallBackAPI.push(fallBackAPISources.shift());
  821. } else {
  822. if (Math.random() > 0.5) {
  823. fallBackAPI.push(fallBackAPISources.shift());
  824. } else {
  825. fallBackAPI.push(fallBackAPISources.pop());
  826. }
  827. }
  828. }
  829. configStorage[""] = createAPIConfig({
  830. resources: ["https://api.iconify.design"].concat(fallBackAPI)
  831. });
  832. function addAPIProvider(provider, customConfig) {
  833. const config2 = createAPIConfig(customConfig);
  834. if (config2 === null) {
  835. return false;
  836. }
  837. configStorage[provider] = config2;
  838. return true;
  839. }
  840. function getAPIConfig(provider) {
  841. return configStorage[provider];
  842. }
  843. function listAPIProviders() {
  844. return Object.keys(configStorage);
  845. }
  846. var mergeParams = (base, params) => {
  847. let result = base, hasParams = result.indexOf("?") !== -1;
  848. function paramToString(value) {
  849. switch (typeof value) {
  850. case "boolean":
  851. return value ? "true" : "false";
  852. case "number":
  853. return encodeURIComponent(value);
  854. case "string":
  855. return encodeURIComponent(value);
  856. default:
  857. throw new Error("Invalid parameter");
  858. }
  859. }
  860. Object.keys(params).forEach((key) => {
  861. let value;
  862. try {
  863. value = paramToString(params[key]);
  864. } catch (err) {
  865. return;
  866. }
  867. result += (hasParams ? "&" : "?") + encodeURIComponent(key) + "=" + value;
  868. hasParams = true;
  869. });
  870. return result;
  871. };
  872. var maxLengthCache = {};
  873. var pathCache = {};
  874. var detectFetch = () => {
  875. let callback2;
  876. try {
  877. callback2 = fetch;
  878. if (typeof callback2 === "function") {
  879. return callback2;
  880. }
  881. } catch (err) {
  882. }
  883. return null;
  884. };
  885. var fetchModule = detectFetch();
  886. function setFetch(fetch2) {
  887. fetchModule = fetch2;
  888. }
  889. function getFetch() {
  890. return fetchModule;
  891. }
  892. function calculateMaxLength(provider, prefix) {
  893. const config2 = getAPIConfig(provider);
  894. if (!config2) {
  895. return 0;
  896. }
  897. let result;
  898. if (!config2.maxURL) {
  899. result = 0;
  900. } else {
  901. let maxHostLength = 0;
  902. config2.resources.forEach((item) => {
  903. const host = item;
  904. maxHostLength = Math.max(maxHostLength, host.length);
  905. });
  906. const url = mergeParams(prefix + ".json", {
  907. icons: ""
  908. });
  909. result = config2.maxURL - maxHostLength - config2.path.length - url.length;
  910. }
  911. const cacheKey = provider + ":" + prefix;
  912. pathCache[provider] = config2.path;
  913. maxLengthCache[cacheKey] = result;
  914. return result;
  915. }
  916. function shouldAbort(status) {
  917. return status === 404;
  918. }
  919. var prepare = (provider, prefix, icons) => {
  920. const results = [];
  921. let maxLength = maxLengthCache[prefix];
  922. if (maxLength === void 0) {
  923. maxLength = calculateMaxLength(provider, prefix);
  924. }
  925. const type = "icons";
  926. let item = {
  927. type,
  928. provider,
  929. prefix,
  930. icons: []
  931. };
  932. let length = 0;
  933. icons.forEach((name, index) => {
  934. length += name.length + 1;
  935. if (length >= maxLength && index > 0) {
  936. results.push(item);
  937. item = {
  938. type,
  939. provider,
  940. prefix,
  941. icons: []
  942. };
  943. length = name.length;
  944. }
  945. item.icons.push(name);
  946. });
  947. results.push(item);
  948. return results;
  949. };
  950. function getPath(provider) {
  951. if (typeof provider === "string") {
  952. if (pathCache[provider] === void 0) {
  953. const config2 = getAPIConfig(provider);
  954. if (!config2) {
  955. return "/";
  956. }
  957. pathCache[provider] = config2.path;
  958. }
  959. return pathCache[provider];
  960. }
  961. return "/";
  962. }
  963. var send = (host, params, callback2) => {
  964. if (!fetchModule) {
  965. callback2("abort", 424);
  966. return;
  967. }
  968. let path = getPath(params.provider);
  969. switch (params.type) {
  970. case "icons": {
  971. const prefix = params.prefix;
  972. const icons = params.icons;
  973. const iconsList = icons.join(",");
  974. path += mergeParams(prefix + ".json", {
  975. icons: iconsList
  976. });
  977. break;
  978. }
  979. case "custom": {
  980. const uri = params.uri;
  981. path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri;
  982. break;
  983. }
  984. default:
  985. callback2("abort", 400);
  986. return;
  987. }
  988. let defaultError = 503;
  989. fetchModule(host + path).then((response) => {
  990. const status = response.status;
  991. if (status !== 200) {
  992. setTimeout(() => {
  993. callback2(shouldAbort(status) ? "abort" : "next", status);
  994. });
  995. return;
  996. }
  997. defaultError = 501;
  998. return response.json();
  999. }).then((data) => {
  1000. if (typeof data !== "object" || data === null) {
  1001. setTimeout(() => {
  1002. callback2("next", defaultError);
  1003. });
  1004. return;
  1005. }
  1006. setTimeout(() => {
  1007. callback2("success", data);
  1008. });
  1009. }).catch(() => {
  1010. callback2("next", defaultError);
  1011. });
  1012. };
  1013. var fetchAPIModule = {
  1014. prepare,
  1015. send
  1016. };
  1017. function sortIcons(icons) {
  1018. const result = {
  1019. loaded: [],
  1020. missing: [],
  1021. pending: []
  1022. };
  1023. const storage2 = /* @__PURE__ */ Object.create(null);
  1024. icons.sort((a, b) => {
  1025. if (a.provider !== b.provider) {
  1026. return a.provider.localeCompare(b.provider);
  1027. }
  1028. if (a.prefix !== b.prefix) {
  1029. return a.prefix.localeCompare(b.prefix);
  1030. }
  1031. return a.name.localeCompare(b.name);
  1032. });
  1033. let lastIcon = {
  1034. provider: "",
  1035. prefix: "",
  1036. name: ""
  1037. };
  1038. icons.forEach((icon) => {
  1039. if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) {
  1040. return;
  1041. }
  1042. lastIcon = icon;
  1043. const provider = icon.provider;
  1044. const prefix = icon.prefix;
  1045. const name = icon.name;
  1046. if (storage2[provider] === void 0) {
  1047. storage2[provider] = /* @__PURE__ */ Object.create(null);
  1048. }
  1049. const providerStorage = storage2[provider];
  1050. if (providerStorage[prefix] === void 0) {
  1051. providerStorage[prefix] = getStorage(provider, prefix);
  1052. }
  1053. const localStorage = providerStorage[prefix];
  1054. let list;
  1055. if (localStorage.icons[name] !== void 0) {
  1056. list = result.loaded;
  1057. } else if (prefix === "" || localStorage.missing[name] !== void 0) {
  1058. list = result.missing;
  1059. } else {
  1060. list = result.pending;
  1061. }
  1062. const item = {
  1063. provider,
  1064. prefix,
  1065. name
  1066. };
  1067. list.push(item);
  1068. });
  1069. return result;
  1070. }
  1071. var callbacks = /* @__PURE__ */ Object.create(null);
  1072. var pendingUpdates = /* @__PURE__ */ Object.create(null);
  1073. function removeCallback(sources, id) {
  1074. sources.forEach((source) => {
  1075. const provider = source.provider;
  1076. if (callbacks[provider] === void 0) {
  1077. return;
  1078. }
  1079. const providerCallbacks = callbacks[provider];
  1080. const prefix = source.prefix;
  1081. const items = providerCallbacks[prefix];
  1082. if (items) {
  1083. providerCallbacks[prefix] = items.filter((row) => row.id !== id);
  1084. }
  1085. });
  1086. }
  1087. function updateCallbacks(provider, prefix) {
  1088. if (pendingUpdates[provider] === void 0) {
  1089. pendingUpdates[provider] = /* @__PURE__ */ Object.create(null);
  1090. }
  1091. const providerPendingUpdates = pendingUpdates[provider];
  1092. if (!providerPendingUpdates[prefix]) {
  1093. providerPendingUpdates[prefix] = true;
  1094. setTimeout(() => {
  1095. providerPendingUpdates[prefix] = false;
  1096. if (callbacks[provider] === void 0 || callbacks[provider][prefix] === void 0) {
  1097. return;
  1098. }
  1099. const items = callbacks[provider][prefix].slice(0);
  1100. if (!items.length) {
  1101. return;
  1102. }
  1103. const storage2 = getStorage(provider, prefix);
  1104. let hasPending = false;
  1105. items.forEach((item) => {
  1106. const icons = item.icons;
  1107. const oldLength = icons.pending.length;
  1108. icons.pending = icons.pending.filter((icon) => {
  1109. if (icon.prefix !== prefix) {
  1110. return true;
  1111. }
  1112. const name = icon.name;
  1113. if (storage2.icons[name] !== void 0) {
  1114. icons.loaded.push({
  1115. provider,
  1116. prefix,
  1117. name
  1118. });
  1119. } else if (storage2.missing[name] !== void 0) {
  1120. icons.missing.push({
  1121. provider,
  1122. prefix,
  1123. name
  1124. });
  1125. } else {
  1126. hasPending = true;
  1127. return true;
  1128. }
  1129. return false;
  1130. });
  1131. if (icons.pending.length !== oldLength) {
  1132. if (!hasPending) {
  1133. removeCallback([
  1134. {
  1135. provider,
  1136. prefix
  1137. }
  1138. ], item.id);
  1139. }
  1140. item.callback(icons.loaded.slice(0), icons.missing.slice(0), icons.pending.slice(0), item.abort);
  1141. }
  1142. });
  1143. });
  1144. }
  1145. }
  1146. var idCounter = 0;
  1147. function storeCallback(callback2, icons, pendingSources) {
  1148. const id = idCounter++;
  1149. const abort = removeCallback.bind(null, pendingSources, id);
  1150. if (!icons.pending.length) {
  1151. return abort;
  1152. }
  1153. const item = {
  1154. id,
  1155. icons,
  1156. callback: callback2,
  1157. abort
  1158. };
  1159. pendingSources.forEach((source) => {
  1160. const provider = source.provider;
  1161. const prefix = source.prefix;
  1162. if (callbacks[provider] === void 0) {
  1163. callbacks[provider] = /* @__PURE__ */ Object.create(null);
  1164. }
  1165. const providerCallbacks = callbacks[provider];
  1166. if (providerCallbacks[prefix] === void 0) {
  1167. providerCallbacks[prefix] = [];
  1168. }
  1169. providerCallbacks[prefix].push(item);
  1170. });
  1171. return abort;
  1172. }
  1173. function listToIcons(list, validate = true, simpleNames2 = false) {
  1174. const result = [];
  1175. list.forEach((item) => {
  1176. const icon = typeof item === "string" ? stringToIcon(item, false, simpleNames2) : item;
  1177. if (!validate || validateIcon(icon, simpleNames2)) {
  1178. result.push({
  1179. provider: icon.provider,
  1180. prefix: icon.prefix,
  1181. name: icon.name
  1182. });
  1183. }
  1184. });
  1185. return result;
  1186. }
  1187. var defaultConfig = {
  1188. resources: [],
  1189. index: 0,
  1190. timeout: 2e3,
  1191. rotate: 750,
  1192. random: false,
  1193. dataAfterTimeout: false
  1194. };
  1195. function sendQuery(config2, payload, query, done) {
  1196. const resourcesCount = config2.resources.length;
  1197. const startIndex = config2.random ? Math.floor(Math.random() * resourcesCount) : config2.index;
  1198. let resources;
  1199. if (config2.random) {
  1200. let list = config2.resources.slice(0);
  1201. resources = [];
  1202. while (list.length > 1) {
  1203. const nextIndex = Math.floor(Math.random() * list.length);
  1204. resources.push(list[nextIndex]);
  1205. list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1));
  1206. }
  1207. resources = resources.concat(list);
  1208. } else {
  1209. resources = config2.resources.slice(startIndex).concat(config2.resources.slice(0, startIndex));
  1210. }
  1211. const startTime = Date.now();
  1212. let status = "pending";
  1213. let queriesSent = 0;
  1214. let lastError;
  1215. let timer = null;
  1216. let queue = [];
  1217. let doneCallbacks = [];
  1218. if (typeof done === "function") {
  1219. doneCallbacks.push(done);
  1220. }
  1221. function resetTimer() {
  1222. if (timer) {
  1223. clearTimeout(timer);
  1224. timer = null;
  1225. }
  1226. }
  1227. function abort() {
  1228. if (status === "pending") {
  1229. status = "aborted";
  1230. }
  1231. resetTimer();
  1232. queue.forEach((item) => {
  1233. if (item.status === "pending") {
  1234. item.status = "aborted";
  1235. }
  1236. });
  1237. queue = [];
  1238. }
  1239. function subscribe(callback2, overwrite) {
  1240. if (overwrite) {
  1241. doneCallbacks = [];
  1242. }
  1243. if (typeof callback2 === "function") {
  1244. doneCallbacks.push(callback2);
  1245. }
  1246. }
  1247. function getQueryStatus() {
  1248. return {
  1249. startTime,
  1250. payload,
  1251. status,
  1252. queriesSent,
  1253. queriesPending: queue.length,
  1254. subscribe,
  1255. abort
  1256. };
  1257. }
  1258. function failQuery() {
  1259. status = "failed";
  1260. doneCallbacks.forEach((callback2) => {
  1261. callback2(void 0, lastError);
  1262. });
  1263. }
  1264. function clearQueue() {
  1265. queue.forEach((item) => {
  1266. if (item.status === "pending") {
  1267. item.status = "aborted";
  1268. }
  1269. });
  1270. queue = [];
  1271. }
  1272. function moduleResponse(item, response, data) {
  1273. const isError = response !== "success";
  1274. queue = queue.filter((queued) => queued !== item);
  1275. switch (status) {
  1276. case "pending":
  1277. break;
  1278. case "failed":
  1279. if (isError || !config2.dataAfterTimeout) {
  1280. return;
  1281. }
  1282. break;
  1283. default:
  1284. return;
  1285. }
  1286. if (response === "abort") {
  1287. lastError = data;
  1288. failQuery();
  1289. return;
  1290. }
  1291. if (isError) {
  1292. lastError = data;
  1293. if (!queue.length) {
  1294. if (!resources.length) {
  1295. failQuery();
  1296. } else {
  1297. execNext();
  1298. }
  1299. }
  1300. return;
  1301. }
  1302. resetTimer();
  1303. clearQueue();
  1304. if (!config2.random) {
  1305. const index = config2.resources.indexOf(item.resource);
  1306. if (index !== -1 && index !== config2.index) {
  1307. config2.index = index;
  1308. }
  1309. }
  1310. status = "completed";
  1311. doneCallbacks.forEach((callback2) => {
  1312. callback2(data);
  1313. });
  1314. }
  1315. function execNext() {
  1316. if (status !== "pending") {
  1317. return;
  1318. }
  1319. resetTimer();
  1320. const resource = resources.shift();
  1321. if (resource === void 0) {
  1322. if (queue.length) {
  1323. timer = setTimeout(() => {
  1324. resetTimer();
  1325. if (status === "pending") {
  1326. clearQueue();
  1327. failQuery();
  1328. }
  1329. }, config2.timeout);
  1330. return;
  1331. }
  1332. failQuery();
  1333. return;
  1334. }
  1335. const item = {
  1336. status: "pending",
  1337. resource,
  1338. callback: (status2, data) => {
  1339. moduleResponse(item, status2, data);
  1340. }
  1341. };
  1342. queue.push(item);
  1343. queriesSent++;
  1344. timer = setTimeout(execNext, config2.rotate);
  1345. query(resource, payload, item.callback);
  1346. }
  1347. setTimeout(execNext);
  1348. return getQueryStatus;
  1349. }
  1350. function setConfig(config2) {
  1351. if (typeof config2 !== "object" || typeof config2.resources !== "object" || !(config2.resources instanceof Array) || !config2.resources.length) {
  1352. throw new Error("Invalid Reduncancy configuration");
  1353. }
  1354. const newConfig = /* @__PURE__ */ Object.create(null);
  1355. let key;
  1356. for (key in defaultConfig) {
  1357. if (config2[key] !== void 0) {
  1358. newConfig[key] = config2[key];
  1359. } else {
  1360. newConfig[key] = defaultConfig[key];
  1361. }
  1362. }
  1363. return newConfig;
  1364. }
  1365. function initRedundancy(cfg) {
  1366. const config2 = setConfig(cfg);
  1367. let queries = [];
  1368. function cleanup() {
  1369. queries = queries.filter((item) => item().status === "pending");
  1370. }
  1371. function query(payload, queryCallback, doneCallback) {
  1372. const query2 = sendQuery(config2, payload, queryCallback, (data, error) => {
  1373. cleanup();
  1374. if (doneCallback) {
  1375. doneCallback(data, error);
  1376. }
  1377. });
  1378. queries.push(query2);
  1379. return query2;
  1380. }
  1381. function find(callback2) {
  1382. const result = queries.find((value) => {
  1383. return callback2(value);
  1384. });
  1385. return result !== void 0 ? result : null;
  1386. }
  1387. const instance = {
  1388. query,
  1389. find,
  1390. setIndex: (index) => {
  1391. config2.index = index;
  1392. },
  1393. getIndex: () => config2.index,
  1394. cleanup
  1395. };
  1396. return instance;
  1397. }
  1398. function emptyCallback$1() {
  1399. }
  1400. var redundancyCache = /* @__PURE__ */ Object.create(null);
  1401. function getRedundancyCache(provider) {
  1402. if (redundancyCache[provider] === void 0) {
  1403. const config2 = getAPIConfig(provider);
  1404. if (!config2) {
  1405. return;
  1406. }
  1407. const redundancy = initRedundancy(config2);
  1408. const cachedReundancy = {
  1409. config: config2,
  1410. redundancy
  1411. };
  1412. redundancyCache[provider] = cachedReundancy;
  1413. }
  1414. return redundancyCache[provider];
  1415. }
  1416. function sendAPIQuery(target, query, callback2) {
  1417. let redundancy;
  1418. let send2;
  1419. if (typeof target === "string") {
  1420. const api = getAPIModule(target);
  1421. if (!api) {
  1422. callback2(void 0, 424);
  1423. return emptyCallback$1;
  1424. }
  1425. send2 = api.send;
  1426. const cached = getRedundancyCache(target);
  1427. if (cached) {
  1428. redundancy = cached.redundancy;
  1429. }
  1430. } else {
  1431. const config2 = createAPIConfig(target);
  1432. if (config2) {
  1433. redundancy = initRedundancy(config2);
  1434. const moduleKey = target.resources ? target.resources[0] : "";
  1435. const api = getAPIModule(moduleKey);
  1436. if (api) {
  1437. send2 = api.send;
  1438. }
  1439. }
  1440. }
  1441. if (!redundancy || !send2) {
  1442. callback2(void 0, 424);
  1443. return emptyCallback$1;
  1444. }
  1445. return redundancy.query(query, send2, callback2)().abort;
  1446. }
  1447. function emptyCallback() {
  1448. }
  1449. var pendingIcons = /* @__PURE__ */ Object.create(null);
  1450. var iconsToLoad = /* @__PURE__ */ Object.create(null);
  1451. var loaderFlags = /* @__PURE__ */ Object.create(null);
  1452. var queueFlags = /* @__PURE__ */ Object.create(null);
  1453. function loadedNewIcons(provider, prefix) {
  1454. if (loaderFlags[provider] === void 0) {
  1455. loaderFlags[provider] = /* @__PURE__ */ Object.create(null);
  1456. }
  1457. const providerLoaderFlags = loaderFlags[provider];
  1458. if (!providerLoaderFlags[prefix]) {
  1459. providerLoaderFlags[prefix] = true;
  1460. setTimeout(() => {
  1461. providerLoaderFlags[prefix] = false;
  1462. updateCallbacks(provider, prefix);
  1463. });
  1464. }
  1465. }
  1466. var errorsCache = /* @__PURE__ */ Object.create(null);
  1467. function loadNewIcons(provider, prefix, icons) {
  1468. function err() {
  1469. const key = (provider === "" ? "" : "@" + provider + ":") + prefix;
  1470. const time = Math.floor(Date.now() / 6e4);
  1471. if (errorsCache[key] < time) {
  1472. errorsCache[key] = time;
  1473. console.error('Unable to retrieve icons for "' + key + '" because API is not configured properly.');
  1474. }
  1475. }
  1476. if (iconsToLoad[provider] === void 0) {
  1477. iconsToLoad[provider] = /* @__PURE__ */ Object.create(null);
  1478. }
  1479. const providerIconsToLoad = iconsToLoad[provider];
  1480. if (queueFlags[provider] === void 0) {
  1481. queueFlags[provider] = /* @__PURE__ */ Object.create(null);
  1482. }
  1483. const providerQueueFlags = queueFlags[provider];
  1484. if (pendingIcons[provider] === void 0) {
  1485. pendingIcons[provider] = /* @__PURE__ */ Object.create(null);
  1486. }
  1487. const providerPendingIcons = pendingIcons[provider];
  1488. if (providerIconsToLoad[prefix] === void 0) {
  1489. providerIconsToLoad[prefix] = icons;
  1490. } else {
  1491. providerIconsToLoad[prefix] = providerIconsToLoad[prefix].concat(icons).sort();
  1492. }
  1493. if (!providerQueueFlags[prefix]) {
  1494. providerQueueFlags[prefix] = true;
  1495. setTimeout(() => {
  1496. providerQueueFlags[prefix] = false;
  1497. const icons2 = providerIconsToLoad[prefix];
  1498. delete providerIconsToLoad[prefix];
  1499. const api = getAPIModule(provider);
  1500. if (!api) {
  1501. err();
  1502. return;
  1503. }
  1504. const params = api.prepare(provider, prefix, icons2);
  1505. params.forEach((item) => {
  1506. sendAPIQuery(provider, item, (data, error) => {
  1507. const storage2 = getStorage(provider, prefix);
  1508. if (typeof data !== "object") {
  1509. if (error !== 404) {
  1510. return;
  1511. }
  1512. const t = Date.now();
  1513. item.icons.forEach((name) => {
  1514. storage2.missing[name] = t;
  1515. });
  1516. } else {
  1517. try {
  1518. const parsed = addIconSet(storage2, data);
  1519. if (!parsed.length) {
  1520. return;
  1521. }
  1522. const pending = providerPendingIcons[prefix];
  1523. parsed.forEach((name) => {
  1524. delete pending[name];
  1525. });
  1526. if (cache.store) {
  1527. cache.store(provider, data);
  1528. }
  1529. } catch (err2) {
  1530. console.error(err2);
  1531. }
  1532. }
  1533. loadedNewIcons(provider, prefix);
  1534. });
  1535. });
  1536. });
  1537. }
  1538. }
  1539. var isPending = (icon) => {
  1540. const provider = icon.provider;
  1541. const prefix = icon.prefix;
  1542. return pendingIcons[provider] && pendingIcons[provider][prefix] && pendingIcons[provider][prefix][icon.name] !== void 0;
  1543. };
  1544. var loadIcons = (icons, callback2) => {
  1545. const cleanedIcons = listToIcons(icons, true, allowSimpleNames());
  1546. const sortedIcons = sortIcons(cleanedIcons);
  1547. if (!sortedIcons.pending.length) {
  1548. let callCallback = true;
  1549. if (callback2) {
  1550. setTimeout(() => {
  1551. if (callCallback) {
  1552. callback2(sortedIcons.loaded, sortedIcons.missing, sortedIcons.pending, emptyCallback);
  1553. }
  1554. });
  1555. }
  1556. return () => {
  1557. callCallback = false;
  1558. };
  1559. }
  1560. const newIcons = /* @__PURE__ */ Object.create(null);
  1561. const sources = [];
  1562. let lastProvider, lastPrefix;
  1563. sortedIcons.pending.forEach((icon) => {
  1564. const provider = icon.provider;
  1565. const prefix = icon.prefix;
  1566. if (prefix === lastPrefix && provider === lastProvider) {
  1567. return;
  1568. }
  1569. lastProvider = provider;
  1570. lastPrefix = prefix;
  1571. sources.push({
  1572. provider,
  1573. prefix
  1574. });
  1575. if (pendingIcons[provider] === void 0) {
  1576. pendingIcons[provider] = /* @__PURE__ */ Object.create(null);
  1577. }
  1578. const providerPendingIcons = pendingIcons[provider];
  1579. if (providerPendingIcons[prefix] === void 0) {
  1580. providerPendingIcons[prefix] = /* @__PURE__ */ Object.create(null);
  1581. }
  1582. if (newIcons[provider] === void 0) {
  1583. newIcons[provider] = /* @__PURE__ */ Object.create(null);
  1584. }
  1585. const providerNewIcons = newIcons[provider];
  1586. if (providerNewIcons[prefix] === void 0) {
  1587. providerNewIcons[prefix] = [];
  1588. }
  1589. });
  1590. const time = Date.now();
  1591. sortedIcons.pending.forEach((icon) => {
  1592. const provider = icon.provider;
  1593. const prefix = icon.prefix;
  1594. const name = icon.name;
  1595. const pendingQueue = pendingIcons[provider][prefix];
  1596. if (pendingQueue[name] === void 0) {
  1597. pendingQueue[name] = time;
  1598. newIcons[provider][prefix].push(name);
  1599. }
  1600. });
  1601. sources.forEach((source) => {
  1602. const provider = source.provider;
  1603. const prefix = source.prefix;
  1604. if (newIcons[provider][prefix].length) {
  1605. loadNewIcons(provider, prefix, newIcons[provider][prefix]);
  1606. }
  1607. });
  1608. return callback2 ? storeCallback(callback2, sortedIcons, sources) : emptyCallback;
  1609. };
  1610. var loadIcon = (icon) => {
  1611. return new Promise((fulfill, reject) => {
  1612. const iconObj = typeof icon === "string" ? stringToIcon(icon) : icon;
  1613. loadIcons([iconObj || icon], (loaded2) => {
  1614. if (loaded2.length && iconObj) {
  1615. const storage2 = getStorage(iconObj.provider, iconObj.prefix);
  1616. const data = getIconFromStorage(storage2, iconObj.name);
  1617. if (data) {
  1618. fulfill(data);
  1619. return;
  1620. }
  1621. }
  1622. reject(icon);
  1623. });
  1624. });
  1625. };
  1626. var elementFinderProperty = "iconifyFinder" + Date.now();
  1627. var elementDataProperty = "iconifyData" + Date.now();
  1628. function renderIconInPlaceholder(placeholder, customisations, iconData, returnString) {
  1629. let span;
  1630. try {
  1631. span = document.createElement("span");
  1632. } catch (err) {
  1633. return returnString ? "" : null;
  1634. }
  1635. const data = iconToSVG(iconData, mergeCustomisations(defaults, customisations));
  1636. const placeholderElement = placeholder.element;
  1637. const finder2 = placeholder.finder;
  1638. const name = placeholder.name;
  1639. const placeholderClassName = placeholderElement ? placeholderElement.getAttribute("class") : "";
  1640. const filteredClassList = finder2 ? finder2.classFilter(placeholderClassName ? placeholderClassName.split(/\s+/) : []) : [];
  1641. const className = "iconify iconify--" + name.prefix + (name.provider === "" ? "" : " iconify--" + name.provider) + (filteredClassList.length ? " " + filteredClassList.join(" ") : "");
  1642. const html = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="' + className + '">' + replaceIDs(data.body) + "</svg>";
  1643. span.innerHTML = html;
  1644. const svg = span.childNodes[0];
  1645. const svgStyle = svg.style;
  1646. const svgAttributes = data.attributes;
  1647. Object.keys(svgAttributes).forEach((attr) => {
  1648. svg.setAttribute(attr, svgAttributes[attr]);
  1649. });
  1650. if (data.inline) {
  1651. svgStyle.verticalAlign = "-0.125em";
  1652. }
  1653. if (placeholderElement) {
  1654. const placeholderAttributes = placeholderElement.attributes;
  1655. for (let i = 0; i < placeholderAttributes.length; i++) {
  1656. const item = placeholderAttributes.item(i);
  1657. if (item) {
  1658. const name2 = item.name;
  1659. if (name2 !== "class" && name2 !== "style" && svgAttributes[name2] === void 0) {
  1660. try {
  1661. svg.setAttribute(name2, item.value);
  1662. } catch (err) {
  1663. }
  1664. }
  1665. }
  1666. }
  1667. const placeholderStyle = placeholderElement.style;
  1668. for (let i = 0; i < placeholderStyle.length; i++) {
  1669. const attr = placeholderStyle[i];
  1670. svgStyle[attr] = placeholderStyle[attr];
  1671. }
  1672. }
  1673. if (finder2) {
  1674. const elementData = {
  1675. name,
  1676. status: "loaded",
  1677. customisations
  1678. };
  1679. svg[elementDataProperty] = elementData;
  1680. svg[elementFinderProperty] = finder2;
  1681. }
  1682. const result = returnString ? span.innerHTML : svg;
  1683. if (placeholderElement && placeholderElement.parentNode) {
  1684. placeholderElement.parentNode.replaceChild(svg, placeholderElement);
  1685. } else {
  1686. span.removeChild(svg);
  1687. }
  1688. return result;
  1689. }
  1690. var nodes = [];
  1691. function findRootNode(node) {
  1692. for (let i = 0; i < nodes.length; i++) {
  1693. const item = nodes[i];
  1694. const root = typeof item.node === "function" ? item.node() : item.node;
  1695. if (root === node) {
  1696. return item;
  1697. }
  1698. }
  1699. }
  1700. function addRootNode(root, autoRemove = false) {
  1701. let node = findRootNode(root);
  1702. if (node) {
  1703. if (node.temporary) {
  1704. node.temporary = autoRemove;
  1705. }
  1706. return node;
  1707. }
  1708. node = {
  1709. node: root,
  1710. temporary: autoRemove
  1711. };
  1712. nodes.push(node);
  1713. return node;
  1714. }
  1715. function addBodyNode() {
  1716. if (document.documentElement) {
  1717. return addRootNode(document.documentElement);
  1718. }
  1719. nodes.push({
  1720. node: () => {
  1721. return document.documentElement;
  1722. }
  1723. });
  1724. }
  1725. function removeRootNode(root) {
  1726. nodes = nodes.filter((node) => {
  1727. const element = typeof node.node === "function" ? node.node() : node.node;
  1728. return root !== element;
  1729. });
  1730. }
  1731. function listRootNodes() {
  1732. return nodes;
  1733. }
  1734. function onReady(callback2) {
  1735. const doc = document;
  1736. if (doc.readyState === "complete" || doc.readyState !== "loading" && !doc.documentElement.doScroll) {
  1737. callback2();
  1738. } else {
  1739. doc.addEventListener("DOMContentLoaded", callback2);
  1740. window.addEventListener("load", callback2);
  1741. }
  1742. }
  1743. var callback = null;
  1744. var observerParams = {
  1745. childList: true,
  1746. subtree: true,
  1747. attributes: true
  1748. };
  1749. function queueScan(node) {
  1750. if (!node.observer) {
  1751. return;
  1752. }
  1753. const observer = node.observer;
  1754. if (!observer.pendingScan) {
  1755. observer.pendingScan = setTimeout(() => {
  1756. delete observer.pendingScan;
  1757. if (callback) {
  1758. callback(node);
  1759. }
  1760. });
  1761. }
  1762. }
  1763. function checkMutations(node, mutations) {
  1764. if (!node.observer) {
  1765. return;
  1766. }
  1767. const observer = node.observer;
  1768. if (!observer.pendingScan) {
  1769. for (let i = 0; i < mutations.length; i++) {
  1770. const item = mutations[i];
  1771. if (item.addedNodes && item.addedNodes.length > 0 || item.type === "attributes" && item.target[elementFinderProperty] !== void 0) {
  1772. if (!observer.paused) {
  1773. queueScan(node);
  1774. }
  1775. return;
  1776. }
  1777. }
  1778. }
  1779. }
  1780. function continueObserving(node, root) {
  1781. node.observer.instance.observe(root, observerParams);
  1782. }
  1783. function startObserver(node) {
  1784. let observer = node.observer;
  1785. if (observer && observer.instance) {
  1786. return;
  1787. }
  1788. const root = typeof node.node === "function" ? node.node() : node.node;
  1789. if (!root) {
  1790. return;
  1791. }
  1792. if (!observer) {
  1793. observer = {
  1794. paused: 0
  1795. };
  1796. node.observer = observer;
  1797. }
  1798. observer.instance = new MutationObserver(checkMutations.bind(null, node));
  1799. continueObserving(node, root);
  1800. if (!observer.paused) {
  1801. queueScan(node);
  1802. }
  1803. }
  1804. function startObservers() {
  1805. listRootNodes().forEach(startObserver);
  1806. }
  1807. function stopObserver(node) {
  1808. if (!node.observer) {
  1809. return;
  1810. }
  1811. const observer = node.observer;
  1812. if (observer.pendingScan) {
  1813. clearTimeout(observer.pendingScan);
  1814. delete observer.pendingScan;
  1815. }
  1816. if (observer.instance) {
  1817. observer.instance.disconnect();
  1818. delete observer.instance;
  1819. }
  1820. }
  1821. function initObserver(cb) {
  1822. const isRestart = callback !== null;
  1823. if (callback !== cb) {
  1824. callback = cb;
  1825. if (isRestart) {
  1826. listRootNodes().forEach(stopObserver);
  1827. }
  1828. }
  1829. if (isRestart) {
  1830. startObservers();
  1831. return;
  1832. }
  1833. onReady(startObservers);
  1834. }
  1835. function pauseObservingNode(node) {
  1836. (node ? [node] : listRootNodes()).forEach((node2) => {
  1837. if (!node2.observer) {
  1838. node2.observer = {
  1839. paused: 1
  1840. };
  1841. return;
  1842. }
  1843. const observer = node2.observer;
  1844. observer.paused++;
  1845. if (observer.paused > 1 || !observer.instance) {
  1846. return;
  1847. }
  1848. const instance = observer.instance;
  1849. instance.disconnect();
  1850. });
  1851. }
  1852. function pauseObserver(root) {
  1853. if (root) {
  1854. const node = findRootNode(root);
  1855. if (node) {
  1856. pauseObservingNode(node);
  1857. }
  1858. } else {
  1859. pauseObservingNode();
  1860. }
  1861. }
  1862. function resumeObservingNode(observer) {
  1863. (observer ? [observer] : listRootNodes()).forEach((node) => {
  1864. if (!node.observer) {
  1865. startObserver(node);
  1866. return;
  1867. }
  1868. const observer2 = node.observer;
  1869. if (observer2.paused) {
  1870. observer2.paused--;
  1871. if (!observer2.paused) {
  1872. const root = typeof node.node === "function" ? node.node() : node.node;
  1873. if (!root) {
  1874. return;
  1875. } else if (observer2.instance) {
  1876. continueObserving(node, root);
  1877. } else {
  1878. startObserver(node);
  1879. }
  1880. }
  1881. }
  1882. });
  1883. }
  1884. function resumeObserver(root) {
  1885. if (root) {
  1886. const node = findRootNode(root);
  1887. if (node) {
  1888. resumeObservingNode(node);
  1889. }
  1890. } else {
  1891. resumeObservingNode();
  1892. }
  1893. }
  1894. function observe(root, autoRemove = false) {
  1895. const node = addRootNode(root, autoRemove);
  1896. startObserver(node);
  1897. return node;
  1898. }
  1899. function stopObserving(root) {
  1900. const node = findRootNode(root);
  1901. if (node) {
  1902. stopObserver(node);
  1903. removeRootNode(root);
  1904. }
  1905. }
  1906. var finders = [];
  1907. function addFinder(finder2) {
  1908. if (finders.indexOf(finder2) === -1) {
  1909. finders.push(finder2);
  1910. }
  1911. }
  1912. function cleanIconName(name) {
  1913. if (typeof name === "string") {
  1914. name = stringToIcon(name);
  1915. }
  1916. return name === null || !validateIcon(name) ? null : name;
  1917. }
  1918. function compareCustomisations(list1, list2) {
  1919. const keys1 = Object.keys(list1);
  1920. const keys2 = Object.keys(list2);
  1921. if (keys1.length !== keys2.length) {
  1922. return false;
  1923. }
  1924. for (let i = 0; i < keys1.length; i++) {
  1925. const key = keys1[i];
  1926. if (list2[key] !== list1[key]) {
  1927. return false;
  1928. }
  1929. }
  1930. return true;
  1931. }
  1932. function findPlaceholders(root) {
  1933. const results = [];
  1934. finders.forEach((finder2) => {
  1935. const elements2 = finder2.find(root);
  1936. Array.prototype.forEach.call(elements2, (item) => {
  1937. const element = item;
  1938. if (element[elementFinderProperty] !== void 0 && element[elementFinderProperty] !== finder2) {
  1939. return;
  1940. }
  1941. const name = cleanIconName(finder2.name(element));
  1942. if (name === null) {
  1943. return;
  1944. }
  1945. element[elementFinderProperty] = finder2;
  1946. const placeholder = {
  1947. element,
  1948. finder: finder2,
  1949. name
  1950. };
  1951. results.push(placeholder);
  1952. });
  1953. });
  1954. const elements = root.querySelectorAll("svg.iconify");
  1955. Array.prototype.forEach.call(elements, (item) => {
  1956. const element = item;
  1957. const finder2 = element[elementFinderProperty];
  1958. const data = element[elementDataProperty];
  1959. if (!finder2 || !data) {
  1960. return;
  1961. }
  1962. const name = cleanIconName(finder2.name(element));
  1963. if (name === null) {
  1964. return;
  1965. }
  1966. let updated = false;
  1967. let customisations;
  1968. if (name.prefix !== data.name.prefix || name.name !== data.name.name) {
  1969. updated = true;
  1970. } else {
  1971. customisations = finder2.customisations(element);
  1972. if (!compareCustomisations(data.customisations, customisations)) {
  1973. updated = true;
  1974. }
  1975. }
  1976. if (updated) {
  1977. const placeholder = {
  1978. element,
  1979. finder: finder2,
  1980. name,
  1981. customisations
  1982. };
  1983. results.push(placeholder);
  1984. }
  1985. });
  1986. return results;
  1987. }
  1988. var scanQueued = false;
  1989. function checkPendingIcons() {
  1990. if (!scanQueued) {
  1991. scanQueued = true;
  1992. setTimeout(() => {
  1993. if (scanQueued) {
  1994. scanQueued = false;
  1995. scanDOM();
  1996. }
  1997. });
  1998. }
  1999. }
  2000. var compareIcons = (icon1, icon2) => {
  2001. return icon1 !== null && icon2 !== null && icon1.name === icon2.name && icon1.prefix === icon2.prefix;
  2002. };
  2003. function scanElement(root) {
  2004. const node = findRootNode(root);
  2005. if (!node) {
  2006. scanDOM({
  2007. node: root,
  2008. temporary: true
  2009. }, true);
  2010. } else {
  2011. scanDOM(node);
  2012. }
  2013. }
  2014. function scanDOM(node, addTempNode = false) {
  2015. scanQueued = false;
  2016. const iconsToLoad2 = /* @__PURE__ */ Object.create(null);
  2017. (node ? [node] : listRootNodes()).forEach((node2) => {
  2018. const root = typeof node2.node === "function" ? node2.node() : node2.node;
  2019. if (!root || !root.querySelectorAll) {
  2020. return;
  2021. }
  2022. let hasPlaceholders = false;
  2023. let paused = false;
  2024. findPlaceholders(root).forEach((item) => {
  2025. const element = item.element;
  2026. const iconName = item.name;
  2027. const provider = iconName.provider;
  2028. const prefix = iconName.prefix;
  2029. const name = iconName.name;
  2030. let data = element[elementDataProperty];
  2031. if (data !== void 0 && compareIcons(data.name, iconName)) {
  2032. switch (data.status) {
  2033. case "missing":
  2034. return;
  2035. case "loading":
  2036. if (isPending({
  2037. provider,
  2038. prefix,
  2039. name
  2040. })) {
  2041. hasPlaceholders = true;
  2042. return;
  2043. }
  2044. }
  2045. }
  2046. const storage2 = getStorage(provider, prefix);
  2047. if (storage2.icons[name] !== void 0) {
  2048. if (!paused && node2.observer) {
  2049. pauseObservingNode(node2);
  2050. paused = true;
  2051. }
  2052. const customisations = item.customisations !== void 0 ? item.customisations : item.finder.customisations(element);
  2053. renderIconInPlaceholder(item, customisations, getIconFromStorage(storage2, name));
  2054. return;
  2055. }
  2056. if (storage2.missing[name]) {
  2057. data = {
  2058. name: iconName,
  2059. status: "missing",
  2060. customisations: {}
  2061. };
  2062. element[elementDataProperty] = data;
  2063. return;
  2064. }
  2065. if (!isPending({ provider, prefix, name })) {
  2066. if (iconsToLoad2[provider] === void 0) {
  2067. iconsToLoad2[provider] = /* @__PURE__ */ Object.create(null);
  2068. }
  2069. const providerIconsToLoad = iconsToLoad2[provider];
  2070. if (providerIconsToLoad[prefix] === void 0) {
  2071. providerIconsToLoad[prefix] = /* @__PURE__ */ Object.create(null);
  2072. }
  2073. providerIconsToLoad[prefix][name] = true;
  2074. }
  2075. data = {
  2076. name: iconName,
  2077. status: "loading",
  2078. customisations: {}
  2079. };
  2080. element[elementDataProperty] = data;
  2081. hasPlaceholders = true;
  2082. });
  2083. if (node2.temporary && !hasPlaceholders) {
  2084. stopObserving(root);
  2085. } else if (addTempNode && hasPlaceholders) {
  2086. observe(root, true);
  2087. } else if (paused && node2.observer) {
  2088. resumeObservingNode(node2);
  2089. }
  2090. });
  2091. Object.keys(iconsToLoad2).forEach((provider) => {
  2092. const providerIconsToLoad = iconsToLoad2[provider];
  2093. Object.keys(providerIconsToLoad).forEach((prefix) => {
  2094. loadIcons(Object.keys(providerIconsToLoad[prefix]).map((name) => {
  2095. const icon = {
  2096. provider,
  2097. prefix,
  2098. name
  2099. };
  2100. return icon;
  2101. }), checkPendingIcons);
  2102. });
  2103. });
  2104. }
  2105. function rotateFromString(value, defaultValue = 0) {
  2106. const units = value.replace(/^-?[0-9.]*/, "");
  2107. function cleanup(value2) {
  2108. while (value2 < 0) {
  2109. value2 += 4;
  2110. }
  2111. return value2 % 4;
  2112. }
  2113. if (units === "") {
  2114. const num = parseInt(value);
  2115. return isNaN(num) ? 0 : cleanup(num);
  2116. } else if (units !== value) {
  2117. let split = 0;
  2118. switch (units) {
  2119. case "%":
  2120. split = 25;
  2121. break;
  2122. case "deg":
  2123. split = 90;
  2124. }
  2125. if (split) {
  2126. let num = parseFloat(value.slice(0, value.length - units.length));
  2127. if (isNaN(num)) {
  2128. return 0;
  2129. }
  2130. num = num / split;
  2131. return num % 1 === 0 ? cleanup(num) : 0;
  2132. }
  2133. }
  2134. return defaultValue;
  2135. }
  2136. var separator = /[\s,]+/;
  2137. function flipFromString(custom, flip) {
  2138. flip.split(separator).forEach((str) => {
  2139. const value = str.trim();
  2140. switch (value) {
  2141. case "horizontal":
  2142. custom.hFlip = true;
  2143. break;
  2144. case "vertical":
  2145. custom.vFlip = true;
  2146. break;
  2147. }
  2148. });
  2149. }
  2150. function alignmentFromString(custom, align) {
  2151. align.split(separator).forEach((str) => {
  2152. const value = str.trim();
  2153. switch (value) {
  2154. case "left":
  2155. case "center":
  2156. case "right":
  2157. custom.hAlign = value;
  2158. break;
  2159. case "top":
  2160. case "middle":
  2161. case "bottom":
  2162. custom.vAlign = value;
  2163. break;
  2164. case "slice":
  2165. case "crop":
  2166. custom.slice = true;
  2167. break;
  2168. case "meet":
  2169. custom.slice = false;
  2170. }
  2171. });
  2172. }
  2173. function hasAttribute(element, key) {
  2174. return element.hasAttribute(key);
  2175. }
  2176. function getAttribute(element, key) {
  2177. return element.getAttribute(key);
  2178. }
  2179. function getBooleanAttribute(element, key) {
  2180. const value = element.getAttribute(key);
  2181. if (value === key || value === "true") {
  2182. return true;
  2183. }
  2184. if (value === "" || value === "false") {
  2185. return false;
  2186. }
  2187. return null;
  2188. }
  2189. var booleanAttributes = [
  2190. "inline",
  2191. "hFlip",
  2192. "vFlip"
  2193. ];
  2194. var stringAttributes = [
  2195. "width",
  2196. "height"
  2197. ];
  2198. var mainClass = "iconify";
  2199. var inlineClass = "iconify-inline";
  2200. var selector = "i." + mainClass + ", span." + mainClass + ", i." + inlineClass + ", span." + inlineClass;
  2201. var finder = {
  2202. find: (root) => root.querySelectorAll(selector),
  2203. name: (element) => {
  2204. if (hasAttribute(element, "data-icon")) {
  2205. return getAttribute(element, "data-icon");
  2206. }
  2207. return null;
  2208. },
  2209. customisations: (element, defaultValues = {
  2210. inline: false
  2211. }) => {
  2212. const result = defaultValues;
  2213. const className = element.getAttribute("class");
  2214. const classList = className ? className.split(/\s+/) : [];
  2215. if (classList.indexOf(inlineClass) !== -1) {
  2216. result.inline = true;
  2217. }
  2218. if (hasAttribute(element, "data-rotate")) {
  2219. const value = rotateFromString(getAttribute(element, "data-rotate"));
  2220. if (value) {
  2221. result.rotate = value;
  2222. }
  2223. }
  2224. if (hasAttribute(element, "data-flip")) {
  2225. flipFromString(result, getAttribute(element, "data-flip"));
  2226. }
  2227. if (hasAttribute(element, "data-align")) {
  2228. alignmentFromString(result, getAttribute(element, "data-align"));
  2229. }
  2230. booleanAttributes.forEach((attr) => {
  2231. if (hasAttribute(element, "data-" + attr)) {
  2232. const value = getBooleanAttribute(element, "data-" + attr);
  2233. if (typeof value === "boolean") {
  2234. result[attr] = value;
  2235. }
  2236. }
  2237. });
  2238. stringAttributes.forEach((attr) => {
  2239. if (hasAttribute(element, "data-" + attr)) {
  2240. const value = getAttribute(element, "data-" + attr);
  2241. if (value !== "") {
  2242. result[attr] = value;
  2243. }
  2244. }
  2245. });
  2246. return result;
  2247. },
  2248. classFilter: (classList) => {
  2249. const result = [];
  2250. classList.forEach((className) => {
  2251. if (className !== "iconify" && className !== "" && className.slice(0, 9) !== "iconify--") {
  2252. result.push(className);
  2253. }
  2254. });
  2255. return result;
  2256. }
  2257. };
  2258. function generateIcon(name, customisations, returnString) {
  2259. const iconData = getIconData(name);
  2260. if (!iconData) {
  2261. return null;
  2262. }
  2263. const iconName = stringToIcon(name);
  2264. const changes = mergeCustomisations(defaults, typeof customisations === "object" ? customisations : {});
  2265. return renderIconInPlaceholder({
  2266. name: iconName
  2267. }, changes, iconData, returnString);
  2268. }
  2269. function getVersion() {
  2270. return "2.2.1";
  2271. }
  2272. function renderSVG(name, customisations) {
  2273. return generateIcon(name, customisations, false);
  2274. }
  2275. function renderHTML(name, customisations) {
  2276. return generateIcon(name, customisations, true);
  2277. }
  2278. function renderIcon(name, customisations) {
  2279. const iconData = getIconData(name);
  2280. if (!iconData) {
  2281. return null;
  2282. }
  2283. const changes = mergeCustomisations(defaults, typeof customisations === "object" ? customisations : {});
  2284. return iconToSVG(iconData, changes);
  2285. }
  2286. function scan(root) {
  2287. if (root) {
  2288. scanElement(root);
  2289. } else {
  2290. scanDOM();
  2291. }
  2292. }
  2293. if (typeof document !== "undefined" && typeof window !== "undefined") {
  2294. addBodyNode();
  2295. addFinder(finder);
  2296. const _window2 = window;
  2297. if (_window2.IconifyPreload !== void 0) {
  2298. const preload = _window2.IconifyPreload;
  2299. const err = "Invalid IconifyPreload syntax.";
  2300. if (typeof preload === "object" && preload !== null) {
  2301. (preload instanceof Array ? preload : [preload]).forEach((item) => {
  2302. try {
  2303. if (typeof item !== "object" || item === null || item instanceof Array || typeof item.icons !== "object" || typeof item.prefix !== "string" || !addCollection(item)) {
  2304. console.error(err);
  2305. }
  2306. } catch (e) {
  2307. console.error(err);
  2308. }
  2309. });
  2310. }
  2311. }
  2312. setTimeout(() => {
  2313. initObserver(scanDOM);
  2314. scanDOM();
  2315. });
  2316. }
  2317. function enableCache(storage2, enable) {
  2318. toggleBrowserCache(storage2, enable !== false);
  2319. }
  2320. function disableCache(storage2) {
  2321. toggleBrowserCache(storage2, true);
  2322. }
  2323. setAPIModule("", fetchAPIModule);
  2324. if (typeof document !== "undefined" && typeof window !== "undefined") {
  2325. cache.store = storeCache;
  2326. loadCache();
  2327. const _window2 = window;
  2328. if (_window2.IconifyProviders !== void 0) {
  2329. const providers = _window2.IconifyProviders;
  2330. if (typeof providers === "object" && providers !== null) {
  2331. for (const key in providers) {
  2332. const err = "IconifyProviders[" + key + "] is invalid.";
  2333. try {
  2334. const value = providers[key];
  2335. if (typeof value !== "object" || !value || value.resources === void 0) {
  2336. continue;
  2337. }
  2338. if (!addAPIProvider(key, value)) {
  2339. console.error(err);
  2340. }
  2341. } catch (e) {
  2342. console.error(err);
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. var _api = {
  2349. getAPIConfig,
  2350. setAPIModule,
  2351. sendAPIQuery,
  2352. setFetch,
  2353. getFetch,
  2354. listAPIProviders,
  2355. mergeParams
  2356. };
  2357. var Iconify = {
  2358. _api,
  2359. addAPIProvider,
  2360. loadIcons,
  2361. loadIcon,
  2362. iconExists,
  2363. getIcon,
  2364. listIcons,
  2365. addIcon,
  2366. addCollection,
  2367. shareStorage,
  2368. replaceIDs,
  2369. calculateSize,
  2370. buildIcon,
  2371. getVersion,
  2372. renderSVG,
  2373. renderHTML,
  2374. renderIcon,
  2375. scan,
  2376. observe,
  2377. stopObserving,
  2378. pauseObserver,
  2379. resumeObserver,
  2380. enableCache,
  2381. disableCache
  2382. };
  2383. try {
  2384. if (self.Iconify === void 0) {
  2385. self.Iconify = Iconify;
  2386. }
  2387. } catch (err) {
  2388. }
  2389. // dep:@iconify_iconify
  2390. var iconify_iconify_default = Iconify;
  2391. export {
  2392. _api,
  2393. addAPIProvider,
  2394. addCollection,
  2395. addIcon,
  2396. buildIcon,
  2397. calculateSize,
  2398. iconify_iconify_default as default,
  2399. disableCache,
  2400. enableCache,
  2401. getIcon,
  2402. getVersion,
  2403. iconExists,
  2404. listIcons,
  2405. loadIcon,
  2406. loadIcons,
  2407. observe,
  2408. pauseObserver,
  2409. renderHTML,
  2410. renderIcon,
  2411. renderSVG,
  2412. replaceIDs,
  2413. resumeObserver,
  2414. scan,
  2415. shareStorage,
  2416. stopObserving
  2417. };
  2418. /**
  2419. * (c) Iconify
  2420. *
  2421. * For the full copyright and license information, please view the license.txt or license.gpl.txt
  2422. * files at https://github.com/iconify/iconify
  2423. *
  2424. * Licensed under Apache 2.0 or GPL 2.0 at your option.
  2425. * If derivative product is not compatible with one of licenses, you can pick one of licenses.
  2426. *
  2427. * @license Apache 2.0
  2428. * @license GPL 2.0
  2429. * @version 2.2.1
  2430. */
  2431. //# sourceMappingURL=@iconify_iconify.js.map