Skip to content

Commit

Permalink
Format jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodevx committed Aug 25, 2024
1 parent b63acc3 commit ba403fb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
16 changes: 13 additions & 3 deletions src/lib/FxParallax.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ import Img from './SvelteImg.svelte'
import { observe } from './utils.js'
import { onMount } from 'svelte'
/**
* Class list forwarded to <img> wrapper
* @type {string}
*/
let classes = ''
export { classes as class }
/**
* @type {number} number between 0 to 1 to control speed relative to scroll
* Number between 0 to 1 to control speed relative to scroll:
* - value closer to 0 is faster, while a value closer to 1 is slower
* - value of 1 behaves normally
* - value of 0 effectively makes the element scroll fixed with the page
* @type {number}
*/
export let factor = 0.75
/** @type {HTMLImageElement|undefined} bindable reference to <img> element */
/**
* Bindable reference to &lt;img&gt; element
* @type {HTMLImageElement|undefined}
*/
export let ref = undefined
let mounted = false
Expand Down Expand Up @@ -61,11 +71,11 @@ onMount(() => {
on:leave={() => (inview = false)}
>
<Img
{...$$restProps}
style="height:{height}%;transform:translate(0,{offset}px)"
bind:ref
on:load
on:click
{...$$restProps}
/>
</div>

Expand Down
13 changes: 10 additions & 3 deletions src/lib/FxReveal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import Img from './SvelteImg.svelte'
import { observe, len, lqipToBackground } from './utils.js'
import { onMount } from 'svelte'
/** @type {Object} imagetools import */
/**
* Imagetools import meta
* @type {any}
*/
export let src = {}
/** @type {HTMLImageElement|undefined} bindable reference to <img> element */
/**
* Bindable reference to &lt;img&gt; element
* @type {HTMLImageElement|undefined}
*/
export let ref = undefined
let meta = {}
Expand Down Expand Up @@ -38,7 +45,7 @@ onMount(() => {
use:observe
on:enter={() => (inview = true)}
>
<Img src={meta} bind:ref on:load on:load={() => (loaded = true)} on:click {...$$restProps} />
<Img {...$$restProps} bind:ref on:load on:load={() => (loaded = true)} on:click src={meta} />
<div class="lqip" style:background />
</div>
{/if}
Expand Down
55 changes: 47 additions & 8 deletions src/lib/SvelteImg.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,46 @@
import Picture from './Picture.svelte'
import { len, lqipToBackground } from './utils.js'
/** @type {Object} imagetools import */
/**
* Imagetools import meta
* @type {any}
*/
export let src = {}
/** @type {string|undefined} img tag `sizes` attr */
/**
* &lt;img&gt; element `sizes` attr
* @type {string|undefined}
*/
export let sizes = undefined
/** @type {number|undefined} img width override */
/**
* &lt;img&gt; `width` override
* @type {number|undefined}
*/
export let width = undefined
/** @type {number|undefined} img height override */
/**
* &lt;img&gt; `height` override
* @type {number|undefined}
*/
export let height = undefined
/** @type {'lazy'|'eager'} img tag `loading` attr */
/**
* &lt;img&gt; element `loading` attr
* @type {'lazy'|'eager'}
*/
export let loading = 'lazy'
/** @type {'async'|'auto'|'sync'} img tag `decoding` attr */
/**
* &lt;img&gt; element `decoding` attr
* @type {'async'|'auto'|'sync'}
*/
export let decoding = 'async'
/** @type {HTMLImageElement|undefined} bindable reference to `<img>` element */
/**
* Bindable reference to &lt;img&gt; element
* @type {HTMLImageElement|undefined}
*/
export let ref = undefined
let sources = []
Expand All @@ -29,10 +56,23 @@ $: if (len(img)) {
}
</script>

<!-- @component
High-performance responsive/progressive images for SvelteKit.
@example
<script>
import Img from '@zerodevx/svelte-img'
import src from '$lib/assets/cat.jpg?as=run'
</script>
<Img {src} alt="cute cat" />
-->

{#if len(img)}
<Picture {sources} {sizes}>
<!-- svelte-ignore a11y-missing-attribute a11y-no-noninteractive-element-interactions -->
<img
{...$$restProps}
{loading}
{decoding}
width={width || img.w || undefined}
Expand All @@ -41,7 +81,6 @@ $: if (len(img)) {
bind:this={ref}
on:click
on:load
{...$$restProps}
src={img.src}
/>
</Picture>
Expand Down

0 comments on commit ba403fb

Please sign in to comment.