-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e65a85
commit 750723f
Showing
17 changed files
with
374 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"type": "module", | ||
"version": "0.4.4", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
|
This file contains 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,15 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
entries: ['src/index'], | ||
clean: true, | ||
declaration: true, | ||
externals: ['react', 'react-dom'], | ||
rollup: { | ||
emitCJS: true, | ||
inlineDependencies: true, | ||
resolve: { | ||
extensions: ['.ts', '.tsx'], | ||
}, | ||
}, | ||
}) |
This file contains 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,62 @@ | ||
{ | ||
"name": "@unlazy/solid", | ||
"version": "0.4.4", | ||
"packageManager": "[email protected]", | ||
"description": "Solid lazy loading library for placeholder images", | ||
"author": "Johann Schopplich <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://unlazy.byjohann.dev", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/johannschopplich/unlazy.git", | ||
"directory": "packages/solid" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/johannschopplich/unlazy/issues" | ||
}, | ||
"keywords": [ | ||
"async", | ||
"image", | ||
"intersection", | ||
"lazy", | ||
"loading", | ||
"lozad", | ||
"native", | ||
"observer", | ||
"responsive", | ||
"react" | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "pnpm -C playground run dev", | ||
"dev:build": "pnpm -C playground run build", | ||
"test:types": "tsc --noEmit" | ||
}, | ||
"peerDependencies": { | ||
"fast-blurhash": "^1.1.2", | ||
"solid-js": "^1.7.3" | ||
}, | ||
"dependencies": { | ||
"unlazy": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.15.12", | ||
"fast-blurhash": "^1.1.2", | ||
"solid-js": "^1.7.3", | ||
"vite-plugin-solid": "^2.7.0" | ||
} | ||
} |
This file contains 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,16 @@ | ||
/* @refresh granular */ | ||
import { LazyImage } from '../src' | ||
|
||
function App() { | ||
return ( | ||
<LazyImage | ||
blurhash="LKO2:N%2Tw=w]~RBVZRi};RPxuwH" | ||
autoSizes={true} | ||
data-srcset="image-320w.jpg 320w, image-640w.jpg 640w" | ||
width="640" | ||
height="640" | ||
/> | ||
) | ||
} | ||
|
||
export default App |
This file contains 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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>@unlazy/solid</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains 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,7 @@ | ||
import { render } from 'solid-js/web' | ||
import App from './App' | ||
|
||
const app = document.getElementById('app') | ||
|
||
if (app) | ||
render(() => <App />, app) |
This file contains 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,9 @@ | ||
{ | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains 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 @@ | ||
/// <reference types="vite/client" /> |
This file contains 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,6 @@ | ||
import { defineConfig } from 'vite' | ||
import solid from 'vite-plugin-solid' | ||
|
||
export default defineConfig({ | ||
plugins: [solid()], | ||
}) |
This file contains 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,38 @@ | ||
import { createEffect, createSignal, onCleanup } from 'solid-js' | ||
import { lazyLoad } from 'unlazy' | ||
import type { UnLazyLoadOptions } from 'unlazy' | ||
import type { JSX } from 'solid-js' | ||
|
||
interface Props | ||
extends JSX.ImgHTMLAttributes<HTMLImageElement>, | ||
Pick<UnLazyLoadOptions, 'blurhashSize'> { | ||
autoSizes?: boolean | ||
blurhash?: string | ||
} | ||
|
||
export function LazyImage(props: Props) { | ||
const [target, setTarget] = createSignal<HTMLImageElement | null>(null) | ||
|
||
createEffect(() => { | ||
const currentTarget = target() | ||
if (currentTarget) { | ||
const cleanup = lazyLoad(currentTarget, { | ||
blurhash: props.blurhash, | ||
blurhashSize: props.blurhashSize, | ||
}) | ||
|
||
onCleanup(() => { | ||
cleanup() | ||
}) | ||
} | ||
}) | ||
|
||
return ( | ||
<img | ||
ref={setTarget} | ||
data-sizes={props.autoSizes ? 'auto' : undefined} | ||
loading="lazy" | ||
{...props} | ||
/> | ||
) | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
/* Limit global types to those in the current package */ | ||
"typeRoots": ["./node_modules/@types"], | ||
"jsx": "preserve", | ||
"jsxImportSource": "solid-js" | ||
}, | ||
"include": ["src", "playground"], | ||
"exclude": ["**/dist"] | ||
} |
This file contains 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
Oops, something went wrong.