{"id":23033723,"url":"https://github.com/sawyerclick/svelte-lazy-loader","last_synced_at":"2025-08-14T15:33:02.172Z","repository":{"id":57375275,"uuid":"463787371","full_name":"sawyerclick/svelte-lazy-loader","owner":"sawyerclick","description":"A lazy-loader component library for Svelte","archived":false,"fork":false,"pushed_at":"2022-03-29T02:52:40.000Z","size":4622,"stargazers_count":21,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-09T01:07:07.862Z","etag":null,"topics":["intersection-observer","lazy","package","svelte"],"latest_commit_sha":null,"homepage":"https://svelte-lazy-loader.sawyer.codes/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sawyerclick.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-26T07:39:21.000Z","updated_at":"2024-10-17T11:05:47.000Z","dependencies_parsed_at":"2022-09-05T13:21:14.128Z","dependency_job_id":null,"html_url":"https://github.com/sawyerclick/svelte-lazy-loader","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sawyerclick%2Fsvelte-lazy-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sawyerclick%2Fsvelte-lazy-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sawyerclick%2Fsvelte-lazy-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sawyerclick%2Fsvelte-lazy-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sawyerclick","download_url":"https://codeload.github.com/sawyerclick/svelte-lazy-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229841495,"owners_count":18132567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["intersection-observer","lazy","package","svelte"],"created_at":"2024-12-15T16:18:03.768Z","updated_at":"2024-12-15T16:18:04.458Z","avatar_url":"https://github.com/sawyerclick.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svelte-lazy-loader\n\nA component library for effortlessly loading media using a shared IntersectionObserver instance if native lazy-loading doesn't exist.\n\n## Table of Contents\n- [svelte-lazy-loader](#svelte-lazy-loader)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n  - [Components](#components)\n    - [Image](#image)\n      - [Usage](#usage)\n      - [API](#api)\n    - [Picture](#picture)\n      - [Usage](#usage-1)\n      - [API](#api-1)\n  - [License](#license)\n\n## Installation\n\n```shell\nnpm i svelte-lazy-loader\n```\n\n## Components\n\n### Image\n\nAn expansion of the HTMLImageElement that, if a browser cannot natively lazy-load, uses a shared IntersectionObserver instance to performantly lazy load images. This components takes several native attributes and passes them through to the underlying HTMLImageElement. A few component-specific props are available to facilitate lazy-loading.\n\nThe out-of-the-box implementation of this component features a blur transition effect. The CSS can be altered using [Svelte's style props](https://svelte.dev/docs#template-syntax-component-directives---style-props).\n\n#### Usage\n\n```html\n\u003cscript\u003e\n\timport { Image } from 'svelte-lazy-loader\n\u003c/script\u003e\n\n\u003cImage loading=\"lazy\" src=\"path/to/image.jpg\" alt=\"A description of the image\" /\u003e\n```\n\n#### API\n\n| Parameter | Default | Description |\n| -------- | ------- | ----------- |\n| src | `placeholder` | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src). The path to the image. Defaults to the `{placeholder}` prop. |\n| srcset | `src` | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset). If passed, defines which images should be presented. Defaults to the `src` prop, which defaults to the `placeholder` prop. |\n| loading | 'lazy' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading). If `lazy`, lazy-load image through native browser functionality if it exists or through IntersectionObserver if it doesn't. If `eager`, image is loaded immediately. |\n| alt | ' ' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt). A description of the image. |\n| draggable | false | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable). If `false`, the element can not be dragged. If `true`, the element can be dragged. |\n| decoding | 'async' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding). If `async`, decode the image asynchronously to reduce delay in presenting other content. If `sync`, decode the image synchronously for atomic presentation with other content. If `default`, default mode, which indicates no preference for the decoding mode. The browser decides what is best for the user. |\n| width | '100%' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width). An integer value indicating the width of the image. |\n| height | '100%' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height). An integer value indicating the height of the image. |\n| classes | ' ' | Additional classes to be added to the `\u003cimg\u003e` element. |\n| placeholder | 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8+fOvJAAI7AMKHxaZiQAAAABJRU5ErkJggg==' | If `loading='lazy'`, this value is the placeholder until the image is loaded. Accepts strings, including paths or base64 images such as the default. |\n| on:load | event | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload). An event forwarded from the `\u003cimg/\u003e` element when the image is loaded. |\n| --transition | 'filter cubic-bezier(0.4, 0, 0.2, 1) 300ms' | The CSS transition that occurs on image load. |\n| --filter | 'blur(2px)' | The filter to apply to the image when unloaded. Transitions out when image is loaded. |\n\n### Picture\n\n#### Usage\n\nSimilarly to the above Image component, this component uses a shared IntersectionObserver instance to performantly lazy-load images if native lazy-loading doesn't exist. Sources can be passed through a default [slot](https://svelte.dev/tutorial/slots) while `\u003cimg/\u003e` attributes are passed as props using the API below. `\u003csource\u003e` elements' `srcset` attributed should be set at `data-srcset`.\n\nSimilar to above, the out-of-the-box implementation of this component features a blur transition effect. The CSS can be altered using [Svelte's style props](https://svelte.dev/docs#template-syntax-component-directives---style-props).\n\nThis example uses [vite-imagetools](https://www.npmjs.com/package/vite-imagetools) create images at compile-time via [sharp](https://sharp.pixelplumbing.com/).\n\n*Note: The `srcset` attribute for `\u003csource\u003e` elements should be set at data-srcset for lazyloading to work properly.*\n\n```html\n\u003cscript\u003e\n\timport { Picture } from 'svelte-lazy-loader';\n\n\timport blurred from '$lib/site/san-felipe-del-morro-castle.jpg?w=100\u0026jpg\u0026blur=10'\n\timport sources from '$lib/site/san-felipe-del-morro-castle.jpg?format=webp;avif;jpg\u0026metadata'\n\u003c/script\u003e\n\n\u003cPicture placeholder={blurred} src=\"images/san-felipe-del-morro-castle.jpg\" alt=\"A few tourists walk up the lawn to the side of the old stone San Felipe del Morro Castle in San Juan, Puerto Rico\"\u003e\n\t{#each sources as { src, format }}\n\t\t\u003csource data-srcset={src} type=\"image/{format}\"/\u003e\n\t{/each}\n\u003c/Picture\u003e\n```\n\n\u003cPicture placeholder={blurred} src=\"images/san-felipe-del-morro-castle.jpg\" alt=\"A few tourists walk up the lawn to the side of the old stone San Felipe del Morro Castle in San Juan, Puerto Rico\"\u003e\n\t{#each sources as { src, format }}\n\t\t\u003csource data-srcset={src} type=\"image/{format}\"/\u003e\n\t{/each}\n\u003c/Picture\u003e\n\n#### API\n\n| Parameter | Default | Description |\n| -------- | ------- | ----------- |\n| src | `placeholder` | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src). The path to the image. Defaults to the `{placeholder}` prop. |\n| loading | 'lazy' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading). If `lazy`, lazy-load image through native browser functionality if it exists or through IntersectionObserver if it doesn't. If `eager`, image is loaded immediately. |\n| alt | ' ' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt). A description of the image. |\n| draggable | false | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable). If `false`, the element can not be dragged. If `true`, the element can be dragged. |\n| decoding | 'async' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding). If `async`, decode the image asynchronously to reduce delay in presenting other content. If `sync`, decode the image synchronously for atomic presentation with other content. If `default`, default mode, which indicates no preference for the decoding mode. The browser decides what is best for the user. |\n| width | '100%' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width). An integer value indicating the width of the image. |\n| height | '100%' | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height). An integer value indicating the height of the image. |\n| classes | ' ' | Additional classes to be added to the `\u003cpicture\u003e` element. |\n| placeholder | 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8+fOvJAAI7AMKHxaZiQAAAABJRU5ErkJggg==' | If `loading='lazy'`, this value is the placeholder until the image is loaded. Accepts strings, including paths or base64 images such as the default. |\n| on:load | event | [Defined as usual](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload). An event forwarded from the `\u003cimg/\u003e` element inside the `\u003cpicture\u003e` element when the image is loaded. |\n| --transition | 'filter cubic-bezier(0.4, 0, 0.2, 1) 300ms' | The CSS transition that occurs on image load. |\n| --filter | 'blur(2px)' | The filter to apply to the image when unloaded. Transitions out when image is loaded. |\n\n## License\n\n[MIT](https://github.com/sawyerclick/svelte-lazy-loader/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsawyerclick%2Fsvelte-lazy-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsawyerclick%2Fsvelte-lazy-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsawyerclick%2Fsvelte-lazy-loader/lists"}