mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
Move FA kit-specific stuff to the FA icon library
This commit is contained in:
@@ -1,6 +1,36 @@
|
||||
import { getKitCode } from '../../utilities/base-path.js';
|
||||
import type { IconLibraryCache, UnregisteredIconLibrary } from './library.js';
|
||||
|
||||
let kitCode = '';
|
||||
|
||||
/** Sets the library's Web Awesome kit code. */
|
||||
export function setKitCode(code: string) {
|
||||
kitCode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the library's Web Awesome kit code.
|
||||
*
|
||||
* The kit code is used to fetch premium assets, so it needs to be set for certain components to work correctly. This
|
||||
* isn't something we can infer, so the user will need to provide it using the `data-fa-kit-code` attribute. This can
|
||||
* be on any element, but ideally it should exist on the script that imports Web Awesome.
|
||||
*
|
||||
* <script src="bundle.js" data-fa-kit-code="abc123"></script>
|
||||
*
|
||||
* Alternatively, you can set the kit code manually using the exported `setKitCode()` function.
|
||||
*
|
||||
*/
|
||||
export function getKitCode() {
|
||||
if (!kitCode) {
|
||||
const el = document.querySelector('[data-fa-kit-code]');
|
||||
|
||||
if (el) {
|
||||
setKitCode(el.getAttribute('data-fa-kit-code') || '');
|
||||
}
|
||||
}
|
||||
|
||||
return kitCode;
|
||||
}
|
||||
|
||||
function getIconUrl(name: string, family: string, variant: string) {
|
||||
const kitCode = getKitCode();
|
||||
const isPro = kitCode.length > 0;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
let basePath = '';
|
||||
let kitCode = '';
|
||||
|
||||
/** Sets the library's base path to the specified directory or URL. */
|
||||
export function setBasePath(path: string) {
|
||||
@@ -49,32 +48,3 @@ export function getBasePath(subpath = '') {
|
||||
// Return the base path without a trailing slash. If one exists, append the subpath separated by a slash.
|
||||
return basePath.replace(/\/$/, '') + (subpath ? `/${subpath.replace(/^\//, '')}` : ``);
|
||||
}
|
||||
|
||||
/** Sets the library's Web Awesome kit code. */
|
||||
export function setKitCode(code: string) {
|
||||
kitCode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the library's Web Awesome kit code.
|
||||
*
|
||||
* The kit code is used to fetch premium assets, so it needs to be set for certain components to work correctly. This
|
||||
* isn't something we can infer, so the user will need to provide it using the `data-fa-kit-code` attribute. This can
|
||||
* be on any element, but ideally it should exist on the script that imports Web Awesome.
|
||||
*
|
||||
* <script src="bundle.js" data-fa-kit-code="abc123"></script>
|
||||
*
|
||||
* Alternatively, you can set the kit code manually using the exported `setKitCode()` function.
|
||||
*
|
||||
*/
|
||||
export function getKitCode() {
|
||||
if (!kitCode) {
|
||||
const el = document.querySelector('[data-fa-kit-code]');
|
||||
|
||||
if (el) {
|
||||
setKitCode(el.getAttribute('data-fa-kit-code') || '');
|
||||
}
|
||||
}
|
||||
|
||||
return kitCode;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export { getKitCode, setKitCode } from './components/icon/library.default.js';
|
||||
export { registerIconLibrary, unregisterIconLibrary } from './components/icon/registry.js';
|
||||
export { discover, preventTurboFouce, startLoader, stopLoader } from './utilities/autoloader.js';
|
||||
export { getBasePath, getKitCode, setBasePath, setKitCode } from './utilities/base-path.js';
|
||||
export { getBasePath, setBasePath } from './utilities/base-path.js';
|
||||
export { allDefined } from './utilities/defined.js';
|
||||
export { registerTranslation } from './utilities/localize.js';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user