resolver.mjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import "./chunk-EX6ADWAR.mjs";
  2. // src/resolver.ts
  3. import { toArray, uniq } from "@antfu/utils";
  4. import { camelToKebab } from "@iconify/utils/lib/misc/strings";
  5. // src/core/icon-sets.json
  6. var icon_sets_default = [
  7. "academicons",
  8. "akar-icons",
  9. "ant-design",
  10. "arcticons",
  11. "basil",
  12. "bi",
  13. "bpmn",
  14. "brandico",
  15. "bx",
  16. "bxl",
  17. "bxs",
  18. "bytesize",
  19. "carbon",
  20. "charm",
  21. "ci",
  22. "cib",
  23. "cif",
  24. "cil",
  25. "circle-flags",
  26. "circum",
  27. "clarity",
  28. "codicon",
  29. "covid",
  30. "cryptocurrency",
  31. "cryptocurrency-color",
  32. "dashicons",
  33. "devicon",
  34. "devicon-plain",
  35. "ei",
  36. "el",
  37. "emojione",
  38. "emojione-monotone",
  39. "emojione-v1",
  40. "entypo",
  41. "entypo-social",
  42. "eos-icons",
  43. "ep",
  44. "et",
  45. "eva",
  46. "fa",
  47. "fa-brands",
  48. "fa-regular",
  49. "fa-solid",
  50. "fa6-brands",
  51. "fa6-regular",
  52. "fa6-solid",
  53. "fad",
  54. "fe",
  55. "feather",
  56. "file-icons",
  57. "flag",
  58. "flagpack",
  59. "flat-color-icons",
  60. "flat-ui",
  61. "fluent",
  62. "fluent-emoji",
  63. "fluent-emoji-flat",
  64. "fluent-emoji-high-contrast",
  65. "fluent-mdl2",
  66. "fontelico",
  67. "fontisto",
  68. "formkit",
  69. "foundation",
  70. "fxemoji",
  71. "gala",
  72. "game-icons",
  73. "geo",
  74. "gg",
  75. "gis",
  76. "gridicons",
  77. "grommet-icons",
  78. "guidance",
  79. "healthicons",
  80. "heroicons",
  81. "heroicons-outline",
  82. "heroicons-solid",
  83. "humbleicons",
  84. "ic",
  85. "icomoon-free",
  86. "icon-park",
  87. "icon-park-outline",
  88. "icon-park-solid",
  89. "icon-park-twotone",
  90. "iconamoon",
  91. "iconoir",
  92. "icons8",
  93. "il",
  94. "ion",
  95. "iwwa",
  96. "jam",
  97. "la",
  98. "line-md",
  99. "logos",
  100. "ls",
  101. "lucide",
  102. "majesticons",
  103. "maki",
  104. "map",
  105. "material-symbols",
  106. "mdi",
  107. "mdi-light",
  108. "medical-icon",
  109. "memory",
  110. "mi",
  111. "mingcute",
  112. "mono-icons",
  113. "nimbus",
  114. "nonicons",
  115. "noto",
  116. "noto-v1",
  117. "octicon",
  118. "oi",
  119. "ooui",
  120. "openmoji",
  121. "pajamas",
  122. "pepicons",
  123. "pepicons-pencil",
  124. "pepicons-pop",
  125. "pepicons-print",
  126. "ph",
  127. "pixelarticons",
  128. "prime",
  129. "ps",
  130. "quill",
  131. "radix-icons",
  132. "raphael",
  133. "ri",
  134. "si-glyph",
  135. "simple-icons",
  136. "simple-line-icons",
  137. "skill-icons",
  138. "solar",
  139. "streamline",
  140. "streamline-emojis",
  141. "subway",
  142. "svg-spinners",
  143. "system-uicons",
  144. "tabler",
  145. "tdesign",
  146. "teenyicons",
  147. "topcoat",
  148. "twemoji",
  149. "typcn",
  150. "uil",
  151. "uim",
  152. "uis",
  153. "uit",
  154. "uiw",
  155. "vaadin",
  156. "vs",
  157. "vscode-icons",
  158. "websymbol",
  159. "whh",
  160. "wi",
  161. "wpf",
  162. "zmdi",
  163. "zondicons"
  164. ];
  165. // src/resolver.ts
  166. function ComponentsResolver(options = {}) {
  167. var _a;
  168. const {
  169. prefix: rawPrefix = (_a = options.componentPrefix) != null ? _a : "i",
  170. enabledCollections = icon_sets_default,
  171. alias = {},
  172. customCollections = [],
  173. extension
  174. } = options;
  175. const prefix = rawPrefix ? `${camelToKebab(rawPrefix)}-` : "";
  176. const ext = extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
  177. const collections = uniq([
  178. ...toArray(enabledCollections),
  179. ...toArray(customCollections),
  180. ...toArray(Object.keys(alias))
  181. ]);
  182. collections.sort((a, b) => b.length - a.length);
  183. return (name) => {
  184. const kebab = camelToKebab(name);
  185. if (!kebab.startsWith(prefix))
  186. return;
  187. const slice = kebab.slice(prefix.length);
  188. const collection = collections.find((i) => slice.startsWith(`${i}-`)) || collections.find((i) => slice.startsWith(i));
  189. if (!collection)
  190. return;
  191. let icon = slice.slice(collection.length);
  192. if (icon[0] === "-")
  193. icon = icon.slice(1);
  194. if (!icon)
  195. return;
  196. const resolvedCollection = alias[collection] || collection;
  197. if (collections.includes(resolvedCollection))
  198. return `~icons/${resolvedCollection}/${icon}${ext}`;
  199. };
  200. }
  201. export {
  202. ComponentsResolver as default
  203. };