import type { IconifyJSON , IconifyIcon } from '@iconify/types' ; import type { IconifyIconName } from '@iconify/utils/lib/icon/name' ; import { stringToIcon } from '@iconify/utils/lib/icon/name' ; import type { IconifyIconSize , IconifyHorizontalIconAlignment , IconifyVerticalIconAlignment , } from '@iconify/utils/lib/customisations' ; import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions' ; import { iconExists , getIcon , addIcon , addCollection , getIconData , allowSimpleNames , } from '@iconify/core/lib/storage/functions' ; import { listIcons , shareStorage } from '@iconify/core/lib/storage/storage' ; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions' ; import { buildIcon } from '@iconify/core/lib/builder/functions' ; import { replaceIDs } from '@iconify/utils/lib/svg/id' ; import { calculateSize } from '@iconify/utils/lib/svg/size' ; import type { IconifyIconBuildResult } from '@iconify/utils/lib/svg/build' ; import { fullIcon } from '@iconify/utils/lib/icon' ; import type { IconifyAPIFunctions , IconifyAPIInternalFunctions , IconifyAPIQueryParams , IconifyAPICustomQueryParams , IconifyAPIMergeQueryParams , } from '@iconify/core/lib/api/functions' ; import type { IconifyAPIModule , IconifyAPISendQuery , IconifyAPIPrepareIconsQuery , } from '@iconify/core/lib/api/modules' ; import { setAPIModule } from '@iconify/core/lib/api/modules' ; import type { PartialIconifyAPIConfig , IconifyAPIConfig , GetAPIConfig , } from '@iconify/core/lib/api/config' ; import { addAPIProvider , getAPIConfig , listAPIProviders , } from '@iconify/core/lib/api/config' ; import { fetchAPIModule , setFetch } from '@iconify/core/lib/api/modules/fetch' ; import type { IconifyIconLoaderCallback , IconifyIconLoaderAbort , } from '@iconify/core/lib/api/icons' ; import { loadIcons } from '@iconify/core/lib/api/icons' ; import { sendAPIQuery } from '@iconify/core/lib/api/query' ; import { mergeParams } from '@iconify/core/lib/api/params' ; import { cache } from '@iconify/core/lib/cache' ; import { storeCache , loadCache } from '@iconify/core/lib/browser-storage' ; import { toggleBrowserCache } from '@iconify/core/lib/browser-storage/functions' ; import type { IconifyBrowserCacheType , IconifyBrowserCacheFunctions , } from '@iconify/core/lib/browser-storage/functions' ; import type { RawIconCustomisations , IconProps , IconifyIconCustomisations , IconifyIconProps , } from './props' ; import { render } from './render' ; import type { RenderResult } from './render' ; /**
 * Export required types
 */ export { IconifyStorageFunctions , IconifyBuilderFunctions , IconifyBrowserCacheFunctions , IconifyAPIFunctions , IconifyAPIInternalFunctions , } ; export { IconifyIcon , IconifyJSON , IconifyIconName } ; export { IconifyIconCustomisations , IconifyIconSize , IconifyHorizontalIconAlignment , IconifyVerticalIconAlignment , IconifyIconProps , IconProps , } ; export { IconifyAPIConfig , IconifyIconLoaderCallback , IconifyIconLoaderAbort , IconifyAPIModule , GetAPIConfig , IconifyAPIPrepareIconsQuery , IconifyAPISendQuery , PartialIconifyAPIConfig , IconifyAPIQueryParams , IconifyAPICustomQueryParams , IconifyAPIMergeQueryParams , } ; export { RawIconCustomisations , IconifyIconBuildResult } ; export { IconifyBrowserCacheType } ; /**
 * Enable cache
 */ function enableCache ( storage ) { toggleBrowserCache ( storage , true ) ; } /**
 * Disable cache
 */ function disableCache ( storage ) { toggleBrowserCache ( storage , false ) ; } /**
 * Initialise stuff
 */ allowSimpleNames ( true ) ; setAPIModule ( '' , fetchAPIModule ) ; /**
 * Browser stuff
 */ if ( typeof document !== 'undefined' && typeof window !== 'undefined' ) { cache . store = storeCache ; loadCache ( ) ; interface WindowWithIconifyStuff { IconifyPreload ? : IconifyJSON [ ] | IconifyJSON ; IconifyProviders ? : Record < string , PartialIconifyAPIConfig > ; } const _window = window as WindowWithIconifyStuff ; if ( _window . IconifyPreload !== void 0 ) { const preload = _window . IconifyPreload ; const err = 'Invalid IconifyPreload syntax.' ; if ( typeof preload === 'object' && preload !== null ) { ( preload instanceof Array ? preload : [ preload ] ) . forEach ( ( item ) => { try { if ( typeof item !== 'object' || item === null || item instanceof Array || typeof item . icons !== 'object' || typeof item . prefix !== 'string' || ! addCollection ( item ) ) { console . error ( err ) ; } } catch ( e ) { console . error ( err ) ; } } ) ; } } if ( _window . IconifyProviders !== void 0 ) { const providers = _window . IconifyProviders ; if ( typeof providers === 'object' && providers !== null ) { for ( let key in providers ) { const err = 'IconifyProviders[' + key + '] is invalid.' ; try { const value = providers [ key ] ; if ( typeof value !== 'object' || ! value || value . resources === void 0 ) { continue ; } if ( ! addAPIProvider ( key , value ) ) { console . error ( err ) ; } } catch ( e ) { console . error ( err ) ; } } } } } /**
 * Function to get icon status
 */ interface IconLoadingState { name : string ; abort : IconifyIconLoaderAbort ; } type IconComponentData = Required < IconifyIcon > | null ; interface IconState { name : string ; loading : IconLoadingState | null ; destroyed : boolean ; } type IconStateCallback = ( ) => void ; /**
 * Callback for when icon has been loaded (only triggered for icons loaded from API)
 */ export type IconifyIconOnLoad = ( name : string ) => void ; /**
 * checkIconState result
 */ export interface CheckIconStateResult { data : IconComponentData ; classes ? : string [ ] ; } /**
 * Check if component needs to be updated
 */ export function checkIconState ( icon , state , mounted , callback , onload ? ) { function abortLoading ( ) { if ( state . loading ) { state . loading . abort ( ) ; state . loading = null ; } } if ( typeof icon === 'object' && icon !== null && typeof icon . body === 'string' ) { state . name = '' ; abortLoading ( ) ; return { data : fullIcon ( icon ) } ; } let iconName ; if ( typeof icon !== 'string' || ( iconName = stringToIcon ( icon , false , true ) ) === null ) { abortLoading ( ) ; return null ; } const data = getIconData ( iconName ) ; if ( data === null ) { if ( mounted && ( ! state . loading || state . loading . name !== icon ) ) { abortLoading ( ) ; state . name = '' ; state . loading = { name : icon , abort : loadIcons ( [ iconName ] , callback ) , } ; } return null ; } abortLoading ( ) ; if ( state . name !== icon ) { state . name = icon ; if ( onload && ! state . destroyed ) { onload ( icon ) ; } } const classes = [ 'iconify' ] ; if ( iconName . prefix !== '' ) { classes . push ( 'iconify--' + iconName . prefix ) ; } if ( iconName . provider !== '' ) { classes . push ( 'iconify--' + iconName . provider ) ; } return { data , classes } ; } /**
 * Generate icon
 */ export function generateIcon ( icon , props ) { return icon ? render ( icon , props ) : null ; } /**
 * Internal API
 */ const _api = { getAPIConfig , setAPIModule , sendAPIQuery , setFetch , listAPIProviders , mergeParams , } ; /**
 * Export functions
 */ export { _api } ; export { addAPIProvider , loadIcons } ; export { iconExists , getIcon , listIcons , addIcon , addCollection , shareStorage } ; export { replaceIDs , calculateSize , buildIcon } ; export { enableCache , disableCache } ;