Skip to content

Commit

Permalink
feat: integrate custom smiz lib (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlitgrace authored Jan 5, 2025
1 parent c045df7 commit e9eb553
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 20 deletions.
43 changes: 28 additions & 15 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"readable-numbers": "^1.0.8",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"svelte-medium-image-zoom": "^0.1.4",
"tailwind-merge": "^2.5.4",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.9",
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/components/quib.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { components } from '$lib/clients/v1';
import Avatar from '$lib/components/ui/avatar.svelte';
import BackdropImage from '$lib/components/ui/backdrop_image.svelte';
import Zoom from '$lib/components/ui/zoom.svelte';
import { cn } from '$lib/functions/classnames';
import { FormatDate } from '$lib/functions/date';
import { is_valid } from '$lib/functions/is_valid';
Expand Down Expand Up @@ -45,7 +46,11 @@
{quib.content}
</p>
{:else}
<BackdropImage src={quib.cover} class="z-10 max-h-[25rem]" />
<BackdropImage src={quib.cover} class="z-10">
<Zoom>
<img src={quib.cover} alt="" class="max-h-[25rem] object-contain" />
</Zoom>
</BackdropImage>
{/if}
{/snippet}

Expand Down
10 changes: 8 additions & 2 deletions frontend/src/lib/components/ui/backdrop_image.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script lang="ts">
import { cn } from '$lib/functions/classnames';
import type { Nullable } from '$lib/types/shared';
import type { Snippet } from 'svelte';
type Props = Partial<{
src: Nullable<string>;
class: string;
img_class: string;
backdrop_class: string;
children: Snippet<[]>;
}>;
let { src, class: klass, img_class, backdrop_class }: Props = $props();
let { src, class: klass, img_class, backdrop_class, children }: Props = $props();
</script>

<div
Expand All @@ -27,5 +29,9 @@
style="background-image: url({src});"
></div>
<!-- original img -->
<img {src} alt="" class={cn(img_class, 'object-contain')} />
{#if children}
{@render children()}
{:else}
<img {src} alt="" class={cn(img_class, 'object-contain')} />
{/if}
</div>
28 changes: 28 additions & 0 deletions frontend/src/lib/components/ui/zoom.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import Zoom from 'svelte-medium-image-zoom';
let { children } = $props();
</script>

<Zoom class_button="btn" zoom_margin={10}>
<!-- custom unzoom zoom buttons -->
{#snippet icon_zoom()}
<coreicons-shape-expand class="size-5"></coreicons-shape-expand>
{/snippet}
{#snippet icon_unzoom()}
<coreicons-shape-shrink class="size-5"></coreicons-shape-shrink>
{/snippet}
<!-- custom zoom content -->
{#snippet zoom_content({ img, button_unzoom, modal_state })}
<!-- zoomed image -->
{@render img()}
<div
class="opacity-0 transition-opacity"
class:opacity-100={modal_state === 'LOADING' || modal_state === 'LOADED'}
>
{@render button_unzoom()}
</div>
{/snippet}

{@render children()}
</Zoom>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import TopIcon from '$lib/components/icons/top.svelte';
import Avatar from '$lib/components/ui/avatar.svelte';
import BackdropImage from '$lib/components/ui/backdrop_image.svelte';
import Zoom from '$lib/components/ui/zoom.svelte';
import { cn } from '$lib/functions/classnames';
import { FormatDate } from '$lib/functions/date';
import { is_valid } from '$lib/functions/is_valid';
Expand Down Expand Up @@ -90,7 +91,11 @@
{quib.content}
</p>
{:else}
<BackdropImage src={quib.cover} class="max-h-[25rem]" />
<BackdropImage src={quib.cover} class="z-10">
<Zoom>
<img src={quib.cover} alt="" class="max-h-[25rem] object-contain" />
</Zoom>
</BackdropImage>
{/if}
<!-- quib options like vote share and more -->
<div class="flex items-center gap-4">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import Modals from '$lib/components/modals/index.svelte';
import Sidebar from '$lib/components/sidebar.svelte';
import { createAuthStore } from '$lib/stores/auth.svelte';
import '../app.css';
import '../styles/app.css';
import '../styles/smiz.css';
import { defineCustomElements } from '@coreproject-moe/icons/loader';
import { onMount, type Snippet } from 'svelte';
Expand Down
File renamed without changes.
106 changes: 106 additions & 0 deletions frontend/src/styles/smiz.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[data-smiz-ghost] {
position: absolute;
pointer-events: none;
}

[data-smiz-btn-zoom],
[data-smiz-btn-unzoom] {
/* background-color: rgba(0, 0, 0, 0.7); */
border-radius: 50%;
/* border: none; */
/* box-shadow: 0 0 1px rgba(255, 255, 255, 0.5); */
/* color: #fff; */
height: 40px;
margin: 0;
outline: none !important;
/* outline-offset: 2px; */
padding: 9px;
touch-action: manipulation;
width: 40px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}

[data-smiz-btn-zoom]:not(:focus):not(:active) {
position: absolute;
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
pointer-events: none;
white-space: nowrap;
width: 1px;
}

[data-smiz-btn-zoom] {
position: absolute;
inset: 10px 10px auto auto;
/* cursor: zoom-in; */
}

[data-smiz-btn-unzoom] {
position: absolute;
inset: 20px 20px auto auto;
/* cursor: zoom-out; */
z-index: 1;
}

[data-smiz-content='found'] img,
[data-smiz-content='found'] [role='img'],
[data-smiz-content='found'] [data-zoom] {
cursor: zoom-in;
}

[data-smiz-modal]::backdrop {
display: none;
}

[data-smiz-modal][open] {
position: fixed;
width: 100vw;
width: 100dvw;
height: 100vh;
height: 100dvh;
max-width: none;
max-height: none;
margin: 0;
padding: 0;
border: 0;
background: transparent;
overflow: hidden;
}

[data-smiz-modal-overlay] {
position: absolute;
inset: 0;
transition: background-color 0.3s;
}

[data-smiz-modal-overlay='hidden'] {
background-color: oklch(var(--b3) / 0);
}

[data-smiz-modal-overlay='visible'] {
background-color: oklch(var(--b3) / 0.55);
}

[data-smiz-modal-content] {
position: relative;
width: 100%;
height: 100%;
}

[data-smiz-modal-img] {
position: absolute;
cursor: zoom-out;
transform-origin: top left;
transition: transform 0.3s;
}

@media (prefers-reduced-motion: reduce) {
[data-smiz-modal-overlay],
[data-smiz-modal-img] {
transition-duration: 0.01ms !important;
}
}

0 comments on commit e9eb553

Please sign in to comment.