2021-05-14 18:39:12 +00:00
|
|
|
<script context="module">
|
|
|
|
|
|
|
|
// Export stuff.
|
|
|
|
// Important: duplicate of iconify.ts. When changing exports, they must be changed in both files.
|
|
|
|
import {
|
|
|
|
enableCache,
|
|
|
|
disableCache,
|
|
|
|
iconExists,
|
|
|
|
getIcon,
|
|
|
|
listIcons,
|
2022-01-09 08:21:53 +00:00
|
|
|
shareStorage,
|
2021-05-14 18:39:12 +00:00
|
|
|
addIcon,
|
|
|
|
addCollection,
|
|
|
|
calculateSize,
|
|
|
|
replaceIDs,
|
|
|
|
buildIcon,
|
|
|
|
loadIcons,
|
2022-01-13 20:19:49 +00:00
|
|
|
loadIcon,
|
2021-05-14 18:39:12 +00:00
|
|
|
addAPIProvider,
|
|
|
|
_api
|
|
|
|
} from './functions';
|
|
|
|
|
|
|
|
export {
|
|
|
|
enableCache,
|
|
|
|
disableCache,
|
|
|
|
iconExists,
|
|
|
|
getIcon,
|
|
|
|
listIcons,
|
2022-01-09 08:21:53 +00:00
|
|
|
shareStorage,
|
2021-05-14 18:39:12 +00:00
|
|
|
addIcon,
|
|
|
|
addCollection,
|
|
|
|
calculateSize,
|
|
|
|
replaceIDs,
|
|
|
|
buildIcon,
|
|
|
|
loadIcons,
|
2022-01-13 20:19:49 +00:00
|
|
|
loadIcon,
|
2021-05-14 18:39:12 +00:00
|
|
|
addAPIProvider,
|
|
|
|
_api
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
2021-04-30 17:10:03 +00:00
|
|
|
<script>
|
2021-11-10 11:18:35 +00:00
|
|
|
import { onMount, onDestroy, createEventDispatcher } from 'svelte';
|
2021-05-01 20:38:56 +00:00
|
|
|
import { checkIconState, generateIcon } from './functions';
|
|
|
|
|
|
|
|
// State
|
|
|
|
const state = {
|
|
|
|
// Last icon name
|
|
|
|
name: '',
|
|
|
|
|
|
|
|
// Loading status
|
|
|
|
loading: null,
|
2021-05-10 15:29:30 +00:00
|
|
|
|
|
|
|
// Destroyed status
|
|
|
|
destroyed: false,
|
2021-05-01 20:38:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Mounted status
|
|
|
|
let mounted = false;
|
|
|
|
|
|
|
|
// Callback counter
|
|
|
|
let counter = 0;
|
2021-04-30 17:10:03 +00:00
|
|
|
|
|
|
|
// Generated data
|
|
|
|
let data;
|
|
|
|
|
2021-11-10 11:18:35 +00:00
|
|
|
const onLoad = (icon) => {
|
|
|
|
// Legacy onLoad property
|
|
|
|
if (typeof $$props.onLoad === 'function') {
|
|
|
|
$$props.onLoad(icon);
|
|
|
|
}
|
|
|
|
// on:load event
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
dispatch('load', {
|
|
|
|
icon
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-01 20:38:56 +00:00
|
|
|
// Generate data
|
2021-04-30 17:10:03 +00:00
|
|
|
$: {
|
2021-05-01 20:38:56 +00:00
|
|
|
counter;
|
2021-11-10 11:18:35 +00:00
|
|
|
const iconData = checkIconState($$props.icon, state, mounted, loaded, onLoad);
|
2021-05-14 19:29:43 +00:00
|
|
|
data = iconData ? generateIcon(iconData.data, $$props) : null;
|
2021-05-13 12:46:50 +00:00
|
|
|
if (data && iconData.classes) {
|
|
|
|
// Add classes
|
|
|
|
data.attributes['class'] = (typeof $$props['class'] === 'string' ? $$props['class'] + ' ' : '') + iconData.classes.join(' ');
|
|
|
|
}
|
2021-04-30 17:10:03 +00:00
|
|
|
}
|
2021-05-01 20:38:56 +00:00
|
|
|
|
|
|
|
// Increase counter when loaded to force re-calculation of data
|
|
|
|
function loaded() {
|
|
|
|
counter ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force re-render
|
|
|
|
onMount(() => {
|
|
|
|
mounted = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Abort loading when component is destroyed
|
|
|
|
onDestroy(() => {
|
2021-05-10 15:29:30 +00:00
|
|
|
state.destroyed = true;
|
2021-05-01 20:38:56 +00:00
|
|
|
if (state.loading) {
|
|
|
|
state.loading.abort();
|
|
|
|
state.loading = null;
|
|
|
|
}
|
|
|
|
})
|
2021-04-30 17:10:03 +00:00
|
|
|
</script>
|
|
|
|
|
2021-05-10 15:32:28 +00:00
|
|
|
{#if data !== null}
|
2021-04-30 17:10:03 +00:00
|
|
|
<svg {...data.attributes}>
|
|
|
|
{@html data.body}
|
|
|
|
</svg>
|
|
|
|
{/if}
|