diff --git a/src/icons.ts b/src/icons.ts index 1a47954f..f7c0c056 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -1,5 +1,5 @@ -import { library } from "@fortawesome/fontawesome-svg-core"; -import { faCircleCheck as farCircleCheck, faObjectUngroup } from "@fortawesome/free-regular-svg-icons"; +import { IconDefinition, IconPack, IconPrefix, library } from "@fortawesome/fontawesome-svg-core"; + import { faChrome as fabChrome, faFirefox as fabFirefox, @@ -12,166 +12,119 @@ import { faDiscord as fabDiscord, faCcPaypal as fabPaypal, } from "@fortawesome/free-brands-svg-icons"; -import { - faSunBright, - faMoon, - faEnvelope, - faCircle, - faBars, - faPlus, - faHexagonPlus, - faMinus, - faStar, - faSlash, - faLock, - faPen, - faFlag, - faCheck, - faChevronsDown, - faChevronRight, - faChevronLeft, - faGavel, - faCopy, - faExclamationTriangle, - faExclamation, - faExternalLinkAlt, - faCalendarAlt, - faPalette, - faCube, - faGear, - faUsersCog, - faEllipsisH, - faEllipsisV, - faColumns, - faTrash, - faTimes, - faSearch, - faReply, - faArrowLeft, - faChevronsRight, - faObjectGroup, - faLayerGroup, - faEye, - faEyeSlash, - faTag, - faLanguage, - faChevronDown, - faUser, - faUserPlus, - faUserMinus, - faSave, - faDownload, - faRotateRight, - faFire, - faHashtag, - faSeal, - faBrush, - faTicket, - faSmile, - faCreditCard, - faCakeSlice, - faClock, - faSquareQuestion, - faTrophy, - faGift, - faUserPen, - faTimer, - faListCheck, - faCodeBranch, - faPenField, - faWrench, - faUnlock, - faUndo, - faFilter, - faSquare, - faPumpkin, -} from "@fortawesome/sharp-solid-svg-icons"; -library.add( - faSunBright, - faMoon, - faEnvelope, - fabChrome, - fabFirefox, - fabEdge, - fabOpera, - fabTwitter, - fabGithub, - fabPaypal, - faCircle, - faBars, - faPlus, - faHexagonPlus, - faMinus, - fabTwitch, - fabYoutube, - fabDiscord, - faStar, - faCheck, - farCircleCheck, - faSlash, - faLock, - faUnlock, - faPen, - faFlag, - faSearch, - faChevronsDown, - faChevronRight, - faChevronLeft, - faGavel, - faCopy, - faExclamationTriangle, - faExclamation, - faExternalLinkAlt, - faCalendarAlt, - faPalette, - faCube, - faGear, - faUsersCog, - faEllipsisH, - faEllipsisV, - faColumns, - faTrash, - faTimes, - faSearch, - faReply, - faArrowLeft, - faChevronsRight, - faObjectGroup, - faObjectUngroup, - faLayerGroup, - faEye, - faEyeSlash, - faTag, - faLanguage, - faChevronDown, - faUser, - faUserPlus, - faUserMinus, - faSave, - faDownload, - faRotateRight, - faFire, - faHashtag, - faSeal, - faBrush, - faTicket, - faSmile, - faCreditCard, - faCakeSlice, - faClock, - faSquareQuestion, - faTrophy, - faGift, - faUserPen, - faTimer, - faListCheck, - faCodeBranch, - faPenField, - faWrench, - faCopy, - faUndo, - faFilter, - faSquare, - faPumpkin, -); +type FreeType = keyof typeof import("@fortawesome/free-solid-svg-icons"); +const freeIcons = { + faCircleCheck: null, + faObjectUngroup: null, + faMoon: null, + faEnvelope: null, + faCircle: null, + faBars: null, + faPlus: null, + faMinus: null, + faStar: null, + faSlash: null, + faLock: null, + faPen: null, + faFlag: null, + faCheck: null, + faChevronRight: null, + faChevronLeft: null, + faGavel: null, + faCopy: null, + faExclamationTriangle: null, + faExclamation: null, + faExternalLinkAlt: null, + faCalendarAlt: null, + faPalette: null, + faCube: null, + faGear: null, + faUsersCog: null, + faEllipsisH: null, + faEllipsisV: null, + faColumns: null, + faTrash: null, + faTimes: null, + faSearch: null, + faReply: null, + faArrowLeft: null, + faObjectGroup: null, + faLayerGroup: null, + faEye: null, + faEyeSlash: null, + faTag: null, + faLanguage: null, + faChevronDown: null, + faUser: null, + faUserPlus: null, + faUserMinus: null, + faSave: null, + faDownload: null, + faRotateRight: null, + faFire: null, + faHashtag: null, + faBrush: null, + faTicket: null, + faSmile: null, + faCreditCard: null, + faClock: null, + faTrophy: null, + faGift: null, + faUserPen: null, + faListCheck: null, + faCodeBranch: null, + faWrench: null, + faUnlock: null, + faUndo: null, + faFilter: null, + faSquare: null, +} as Record; + +type ProType = keyof typeof import("@fortawesome/sharp-solid-svg-icons"); +const proIcons = { + faCakeSlice: null, + faSquareQuestion: null, + faTimer: null, + faPenField: null, + faPumpkin: null, + faSunBright: null, + faHexagonPlus: null, + faChevronsDown: null, + faChevronsRight: null, + faSeal: null, +} as Record; + +export const loadIcons = async () => { + const isPro = import.meta.env.VITE_APP_FA_PRO === "true"; + + const pack = [] as IconDefinition[]; + if (isPro) { + await import("@fortawesome/sharp-solid-svg-icons").then((icons) => { + Object.keys({ ...proIcons, ...freeIcons }).forEach((key) => { + pack.push(icons[key] as IconDefinition); + }); + }); + } else { + await import("@fortawesome/free-solid-svg-icons").then((icons) => { + Object.keys(freeIcons).forEach((key) => { + pack.push(icons[key] as IconDefinition); + }); + }); + } + + const fab = [ + fabChrome, + fabFirefox, + fabEdge, + fabOpera, + fabTwitter, + fabGithub, + fabTwitch, + fabYoutube, + fabDiscord, + fabPaypal, + ]; + + library.add(...pack, ...fab); +}; diff --git a/src/main.ts b/src/main.ts index 0fe6d3a8..cc417897 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,25 +20,30 @@ import { createPinia } from "pinia"; import App from "@/App.vue"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; - -const app = createApp({ - setup() { - provide(DefaultApolloClient, apolloClient); - }, - render: () => h(App), -}); - -formkitConfig; -app.use(createHead()) - .use(createPinia()) - .use(router) - .use(i18n) - .use(formkit, formkitConfig) - .use(vWave) - .use(RouterPrefetch) - .component("font-awesome-icon", FontAwesomeIcon) - .component("Popper", Popper); - -directives(app); - -app.mount("#app"); +import { loadIcons } from "@/icons"; + +(async () => { + await loadIcons(); + + const app = createApp({ + setup() { + provide(DefaultApolloClient, apolloClient); + }, + render: () => h(App), + }); + + formkitConfig; + app.use(createHead()) + .use(createPinia()) + .use(router) + .use(i18n) + .use(formkit, formkitConfig) + .use(vWave) + .use(RouterPrefetch) + .component("font-awesome-icon", FontAwesomeIcon) + .component("Popper", Popper); + + directives(app); + + app.mount("#app"); +})();