loader.mjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { getCustomIcon } from './custom.mjs';
  2. import { searchForIcon } from './modern.mjs';
  3. import 'debug';
  4. import './utils.mjs';
  5. import '../svg/build.mjs';
  6. import '../icon/defaults.mjs';
  7. import '../customisations/defaults.mjs';
  8. import '../svg/size.mjs';
  9. import '../svg/defs.mjs';
  10. import '../svg/trim.mjs';
  11. import '../icon-set/get-icon.mjs';
  12. import '../icon/merge.mjs';
  13. import '../icon/transformations.mjs';
  14. import '../icon-set/tree.mjs';
  15. const loadIcon = async (collection, icon, options) => {
  16. const custom = options?.customCollections?.[collection];
  17. if (custom) {
  18. if (typeof custom === "function") {
  19. let result;
  20. try {
  21. result = await custom(icon);
  22. } catch (err) {
  23. console.warn(
  24. `Failed to load custom icon "${icon}" in "${collection}":`,
  25. err
  26. );
  27. return;
  28. }
  29. if (result) {
  30. if (typeof result === "string") {
  31. return await getCustomIcon(
  32. () => result,
  33. collection,
  34. icon,
  35. options
  36. );
  37. }
  38. if ("icons" in result) {
  39. const ids = [
  40. icon,
  41. icon.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
  42. icon.replace(/([a-z])(\d+)/g, "$1-$2")
  43. ];
  44. return await searchForIcon(
  45. result,
  46. collection,
  47. ids,
  48. options
  49. );
  50. }
  51. }
  52. } else {
  53. return await getCustomIcon(custom, collection, icon, options);
  54. }
  55. }
  56. };
  57. export { loadIcon };