-
Notifications
You must be signed in to change notification settings - Fork 2
Add wiki #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add wiki #11
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f481ee1
add: create .gitignore to exclude VitePress cache directory
AxenoDev c6dd724
add: expand .gitignore to include additional log and cache files
AxenoDev a742de8
feat: add runtime API examples and custom styles for documentation
AxenoDev dd2f375
feat: add runtime API examples and custom styles for documentation
AxenoDev 74bd4de
add: update .gitignore to replace package-json.lock with bun.lock
AxenoDev 92b5015
feat: implement image caching limit and improve error handling
AxenoDev bda2b29
refactor: remove unused CachedImage import from index.md
AxenoDev 5d7c7a1
Update docs/.vitepress/config.mts
AxenoDev 7d05d48
Update docs/.vitepress/theme/components/CachedImage.vue
AxenoDev e013f7a
Update docs/.vitepress/theme/style/style.scss
AxenoDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .vitepress/cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import {defineConfig} from 'vitepress' | ||
|
|
||
| // https://vitepress.dev/reference/site-config | ||
| export default defineConfig({ | ||
| title: "KikoAPI docs", | ||
| description: "KikoAPI is a lightweight helper library for our Paper plugins that speeds up development.", | ||
| vite: { | ||
| css: { | ||
| preprocessorOptions: { | ||
| scss: { | ||
| api: "modern-compiler" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| srcDir: './pages', | ||
| appearance: 'force-dark', | ||
| themeConfig: { | ||
| search: { | ||
| provider: 'local' | ||
| }, | ||
| // https://vitepress.dev/reference/default-theme-config | ||
| nav: [ | ||
| {text: 'Home', link: '/'}, | ||
| {text: 'Examples', link: '/markdown-examples'} | ||
| ], | ||
|
|
||
| sidebar: [ | ||
| { | ||
| text: 'Examples', | ||
| items: [ | ||
| {text: 'Markdown Examples', link: '/markdown-examples'}, | ||
| {text: 'Runtime API Examples', link: '/api-examples'} | ||
| ] | ||
| } | ||
| ], | ||
|
|
||
| socialLinks: [ | ||
| {icon: 'github', link: 'https://github.com/KikoPlugins/KikoAPI'} | ||
| ] | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| <script setup lang="ts"> | ||
| import { ref, onMounted, watch } from 'vue'; | ||
|
|
||
| const props = defineProps<{ | ||
| src?: string; | ||
| placeholder?: string; | ||
| alt?: string; | ||
| }>(); | ||
|
|
||
| const imgSrc = ref<string>(''); | ||
| const isLoading = ref(true); | ||
| const hasError = ref(false); | ||
|
|
||
| const CACHE_PREFIX = 'cached_image_'; | ||
| const CACHE_EXPIRY = 7 * 24 * 60 * 60 * 1000; | ||
|
|
||
| interface CachedImageData { | ||
| data: string; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| const getCachedImage = (url: string): string | null => { | ||
| try { | ||
| const key = CACHE_PREFIX + btoa(url); | ||
| const cached = localStorage.getItem(key); | ||
| if (cached) { | ||
| const data: CachedImageData = JSON.parse(cached); | ||
| if (Date.now() - data.timestamp < CACHE_EXPIRY) { | ||
| return data.data; | ||
| } else { | ||
| localStorage.removeItem(key); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.warn('Failed to get cached image:', e); | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const setCachedImage = (url: string, dataUrl: string): void => { | ||
| try { | ||
| if (dataUrl.length > 5 * 1024 * 1024) { // 5MB limit | ||
| console.warn('Image is too large to cache:', url); | ||
| return; | ||
| } | ||
| const key = CACHE_PREFIX + btoa(url); | ||
| const data: CachedImageData = { | ||
| data: dataUrl, | ||
| timestamp: Date.now() | ||
| }; | ||
| localStorage.setItem(key, JSON.stringify(data)); | ||
| } catch (e) { | ||
| if (e instanceof DOMException && e.name === 'QuotaExceededError') { | ||
| console.warn('LocalStorage quota exceeded, cannot cache image:', e); | ||
| } else { | ||
| console.warn('Failed to retrieve cached image:', e); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const loadImage = (url: string): void => { | ||
| if (!url) { | ||
| imgSrc.value = props.placeholder || ''; | ||
| isLoading.value = false; | ||
| return; | ||
| } | ||
|
|
||
| const cached = getCachedImage(url); | ||
| if (cached) { | ||
| imgSrc.value = cached; | ||
| isLoading.value = false; | ||
| hasError.value = false; | ||
| return; | ||
| } | ||
|
|
||
| const img = new Image(); | ||
| img.crossOrigin = 'anonymous'; | ||
|
|
||
| img.onload = () => { | ||
| try { | ||
| const canvas = document.createElement('canvas'); | ||
| canvas.width = img.naturalWidth; | ||
| canvas.height = img.naturalHeight; | ||
| const ctx = canvas.getContext('2d'); | ||
| if (ctx) { | ||
| ctx.drawImage(img, 0, 0); | ||
| const dataUrl = canvas.toDataURL('image/png'); | ||
| setCachedImage(url, dataUrl); | ||
| imgSrc.value = dataUrl; | ||
| } else { | ||
| imgSrc.value = url; | ||
| } | ||
| } catch (e) { | ||
| console.warn('Failed to cache image, using original URL:', e); | ||
| imgSrc.value = url; | ||
| } | ||
| isLoading.value = false; | ||
| hasError.value = false; | ||
| }; | ||
|
|
||
| img.onerror = () => { | ||
| hasError.value = true; | ||
| isLoading.value = false; | ||
| imgSrc.value = props.placeholder || ''; | ||
| }; | ||
|
|
||
| img.src = url; | ||
| }; | ||
|
|
||
| onMounted(() => { | ||
| if (props.src) { | ||
| loadImage(props.src); | ||
| } else if (props.placeholder) { | ||
| imgSrc.value = props.placeholder; | ||
| isLoading.value = false; | ||
| } else { | ||
| isLoading.value = false; | ||
| } | ||
| }); | ||
| }); | ||
PuppyTransGirl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| watch(() => props.src, (newSrc) => { | ||
| if (newSrc) { | ||
| isLoading.value = true; | ||
| hasError.value = false; | ||
| loadImage(newSrc); | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="cached-image-wrapper"> | ||
| <img | ||
| v-if="imgSrc" | ||
| :src="imgSrc" | ||
| :alt="alt || ''" | ||
| :class="{ loading: isLoading, error: hasError }" | ||
| v-bind="$attrs" | ||
| /> | ||
| <div v-else-if="isLoading" class="loading-placeholder"> | ||
| <span>Loading...</span> | ||
| </div> | ||
| <div v-else-if="hasError" class="error-placeholder"> | ||
| <span>Failed to load image</span> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .cached-image-wrapper { | ||
| display: block; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| img { | ||
| display: block; | ||
| max-width: 100%; | ||
| height: auto; | ||
| transition: opacity 0.3s ease; | ||
| } | ||
|
|
||
| img.loading { | ||
| opacity: 0.5; | ||
| } | ||
|
|
||
| img.error { | ||
| opacity: 0.3; | ||
| } | ||
|
|
||
| .loading-placeholder, | ||
| .error-placeholder { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| min-height: 200px; | ||
| background: rgba(128, 128, 128, 0.1); | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| .loading-placeholder span { | ||
| color: var(--vp-c-text-2); | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .error-placeholder span { | ||
| color: var(--vp-c-danger); | ||
| font-size: 14px; | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.