impr: use custom progress bar
This commit is contained in:
6 files changed
+60
-19
No files matched your search
@@ -14,7 +14,6 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@tailwindcss/postcss": "^4.1.8",
|
||||
"@types/nprogress": "^0.2.0",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"eslint": "^9.28.0",
|
||||
"eslint-plugin-svelte": "^3.9.1",
|
||||
@@ -23,7 +22,6 @@
|
||||
"linkify-it": "^5.0.0",
|
||||
"marked": "7.0.5",
|
||||
"marked-linkify-it": "^3.1.10",
|
||||
"nprogress": "^0.2.0",
|
||||
"postcss": "^8.4.30",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-svelte": "^3.2.7",
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<svelte:element
|
||||
this={settings.expandImages ? 'button' : 'a'}
|
||||
href={postLink(post)}
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900 cursor-pointer"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1, null))}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
size="16"
|
||||
micro
|
||||
class={[
|
||||
open && 'rotate-90',
|
||||
open && 'rotate-180',
|
||||
'transition-transform duration-300 ease-out',
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
let progress = $state(0)
|
||||
|
||||
let increaseInterval: number = -1
|
||||
let startTimeout: number = -1
|
||||
let stopTimeout: number = -1
|
||||
|
||||
export function start() {
|
||||
clearTimeout(stopTimeout)
|
||||
progress = 0
|
||||
startTimeout = setTimeout(() => {
|
||||
progress = 1
|
||||
// schedule a setInterval and run the code immediately
|
||||
;(function i() {
|
||||
if (progress < 100 && progress > 0)
|
||||
// slowly get closer and closer to 90% -- 100% doesnt look very good to be stuck on
|
||||
progress += (100 - (progress - 10)) / 4
|
||||
increaseInterval = setInterval(i, 400) as unknown as number
|
||||
})()
|
||||
}, 100) as unknown as number
|
||||
}
|
||||
|
||||
export function stop() {
|
||||
if (progress != 0) progress = 100
|
||||
// reset progress to 0 after bar disappears
|
||||
setTimeout(() => (progress = 0), 500)
|
||||
clearInterval(increaseInterval)
|
||||
clearTimeout(startTimeout)
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={[
|
||||
'fixed top-0 left-0 h-px z-[400] bg-primary-900 dark:bg-primary-100',
|
||||
progress == 100 && 'opacity-0',
|
||||
progress > 0 && 'use-transition',
|
||||
]}
|
||||
style="width: {progress}%;"
|
||||
id="progress-bar"
|
||||
></div>
|
||||
|
||||
<style>
|
||||
#progress-bar.use-transition {
|
||||
transition:
|
||||
width 0.7s cubic-bezier(0, 0, 0.22, 0.76),
|
||||
opacity 0.5s linear;
|
||||
}
|
||||
</style>
|
||||
+10
-15
@@ -13,25 +13,17 @@
|
||||
import { inDarkColorScheme, rgbToHex, theme } from '$lib/ui/colors.svelte.js'
|
||||
import { getDefaultColors } from '$lib/ui/presets'
|
||||
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
||||
import nProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import { onMount } from 'svelte'
|
||||
import { Forward, Icon } from 'svelte-hero-icons'
|
||||
import '../style/app.css'
|
||||
import NavigationProgress from '$lib/components/ui/layout/NavigationProgress.svelte'
|
||||
interface Props {
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { children }: Props = $props()
|
||||
|
||||
nProgress.configure({
|
||||
minimum: 0.4,
|
||||
trickleSpeed: 200,
|
||||
easing: 'ease-out',
|
||||
speed: 300,
|
||||
showSpinner: false,
|
||||
})
|
||||
|
||||
let progressBar = $state<{ start: () => void; stop: () => void }>()
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
if (window.location.hash == 'main') {
|
||||
@@ -71,12 +63,12 @@
|
||||
document.documentElement.dir =
|
||||
($locale == 'he' || $locale == 'ar') && settings.useRtl ? 'rtl' : 'ltr'
|
||||
})
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (navigating.to) nProgress.start()
|
||||
else nProgress.done()
|
||||
})
|
||||
$effect(() => {
|
||||
if (navigating.to) progressBar?.start()
|
||||
else progressBar?.stop()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -104,6 +96,7 @@
|
||||
<Button
|
||||
class="fixed -top-16 focus:top-0 left-0 m-4 z-300 transition-all"
|
||||
href="#main"
|
||||
onclick={() => document.getElementById('main')?.focus()}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Forward} mini size="16" />
|
||||
@@ -111,6 +104,8 @@
|
||||
Skip Navigation
|
||||
</Button>
|
||||
|
||||
<NavigationProgress bind:this={progressBar} />
|
||||
|
||||
<Shell>
|
||||
<Moderation />
|
||||
<ToastContainer />
|
||||
|
||||
Reference in new issue
Block a user