Skip to content

Commit

Permalink
Finalize frameworks integration 💞 (#136)
Browse files Browse the repository at this point in the history
* Let's 🚀 Qwik first 💞

* chore: upgrade all existing packages

* docs: finish up svelte adapter

* docs: fix up demo page

* docs: add changeset for @zoom-image/svelte 💞

* feat: add Vue integration 💞

* docs: modernization 💞
  • Loading branch information
willnguyen1312 authored May 23, 2023
1 parent b80f52e commit 9a2966f
Show file tree
Hide file tree
Showing 61 changed files with 1,073 additions and 259 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-lemons-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoom-image/svelte": minor
---

Initial release of @zoom-image/svelte 💞
5 changes: 5 additions & 0 deletions .changeset/silver-ducks-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoom-image/vue": minor
---

Initial release of @zoom-image/vue 💞
3 changes: 2 additions & 1 deletion examples/preact-ts/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function App() {
}

useEffect(() => {
setCroppedImage("")
if (zoomType === "wheel") {
const imageContainer = imageWheelContainerRef.current as HTMLDivElement
createZoomImageWheel(imageContainer)
Expand Down Expand Up @@ -130,7 +131,7 @@ function App() {
<div ref={imageWheelContainerRef} class="h-[300px] w-[300px] cursor-crosshair">
<img class="h-full w-full" alt="Large Pic" src="/large.webp" />
</div>
{croppedImage && <img src={croppedImage} class="h-[300px] w-[300px]" alt="Cropped image placeholder" />}
{croppedImage && <img src={croppedImage} class="h-[300px] w-[300px]" alt="Cropped placeholder" />}
</div>

<div class="flex space-x-2">
Expand Down
3 changes: 2 additions & 1 deletion examples/qwik-ts/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default component$(() => {

useVisibleTask$(({ track }) => {
track(() => zoomType.value)
croppedImage.value = ""

if (zoomType.value === "wheel" && imageWheelContainerRef.value) {
const imageContainer = imageWheelContainerRef.value
Expand Down Expand Up @@ -109,7 +110,7 @@ export default component$(() => {
<img class="h-full w-full" alt="Large Pic" src="/large.webp" />
</div>
{croppedImage.value && (
<img src={croppedImage.value} class="h-[300px] w-[300px]" alt="Cropped image placeholder" />
<img src={croppedImage.value} class="h-[300px] w-[300px]" alt="Cropped placeholder" />
)}
</div>

Expand Down
3 changes: 2 additions & 1 deletion examples/react-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function App() {
}

useEffect(() => {
setCroppedImage("")
if (zoomType === "wheel") {
const imageContainer = imageWheelContainerRef.current as HTMLDivElement
createZoomImageWheel(imageContainer)
Expand Down Expand Up @@ -130,7 +131,7 @@ function App() {
<div ref={imageWheelContainerRef} className="h-[300px] w-[300px] cursor-crosshair">
<img className="h-full w-full" alt="Large Pic" src="/large.webp" />
</div>
{croppedImage && <img src={croppedImage} className="h-[300px] w-[300px]" alt="Cropped image placeholder" />}
{croppedImage && <img src={croppedImage} className="h-[300px] w-[300px]" alt="Cropped placeholder" />}
</div>

<div className="flex space-x-2">
Expand Down
3 changes: 2 additions & 1 deletion examples/solid-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const App: Component = () => {
}

createEffect(() => {
setCroppedImage("")
if (zoomType() === "hover") {
createZoomImageHover(imageHoverContainer, {
zoomImageSource: "https://nam-assets.netlify.app/static/large.webp",
Expand Down Expand Up @@ -125,7 +126,7 @@ const App: Component = () => {
<div ref={imageWheelContainer} class="h-[300px] w-[300px] cursor-crosshair">
<img class="h-full w-full" alt="Large Pic" src="/large.webp" />
</div>
{croppedImage() && <img src={croppedImage()} class="h-[300px] w-[300px]" alt="Cropped image placeholder" />}
{croppedImage() && <img src={croppedImage()} class="h-[300px] w-[300px]" alt="Cropped placeholder" />}
</div>

<div class="flex space-x-2">
Expand Down
4 changes: 3 additions & 1 deletion examples/svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"dev": "vite"
},
"dependencies": {
"@zoom-image/core": "latest"
"@zoom-image/core": "latest",
"@zoom-image/svelte": "latest"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.3.0",
"@tsconfig/svelte": "^4.0.1",
"@unocss/reset": "^0.52.1",
"svelte": "^3.59.1",
"svelte-check": "^3.3.2",
"tslib": "^2.5.2",
Expand Down
Binary file added examples/svelte-ts/public/large.webp
Binary file not shown.
92 changes: 67 additions & 25 deletions examples/svelte-ts/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<script lang="ts">
import { onDestroy, tick } from "svelte"
import {
createZoomImageHover,
createZoomImageWheel,
createZoomImageMove,
createZoomImageClick,
} from "@zoom-image/core"
import { tick } from "svelte"
import { useZoomImageClick, useZoomImageHover, useZoomImageMove, useZoomImageWheel } from "@zoom-image/svelte"
import { cropImage } from "@zoom-image/core"
const tabs: {
name: string
Expand All @@ -19,54 +15,56 @@
{ name: "Click", href: "#", current: false, value: "click" },
]
$: zoomType = tabs.find((tab) => tab.current)?.value as "wheel" | "hover" | "move" | "click"
let croppedImage: string = ""
let imageWheelContainer: HTMLDivElement
let imageMoveContainer: HTMLDivElement
let imageHoverContainer: HTMLDivElement
let imageClickContainer: HTMLDivElement
let zoomTarget: HTMLDivElement
let cleanup: () => void = () => {}
const {
createZoomImage: createZoomImageWheel,
zoomImageState: zoomImageWheelState,
setZoomImageState: setZoomImageWheelState,
} = useZoomImageWheel()
const { createZoomImage: createZoomImageHover } = useZoomImageHover()
const { createZoomImage: createZoomImageMove } = useZoomImageMove()
const { createZoomImage: createZoomImageClick } = useZoomImageClick()
async function processZoom(zoomType: "wheel" | "hover" | "move" | "click") {
cleanup()
croppedImage = ""
await tick()
if (zoomType === "hover") {
const result = createZoomImageHover(imageHoverContainer, {
createZoomImageHover(imageHoverContainer, {
zoomImageSource: "https://nam-assets.netlify.app/static/large.webp",
customZoom: { width: 300, height: 500 },
zoomTarget,
scaleFactor: 0.5,
})
cleanup = result.cleanup
}
if (zoomType === "wheel") {
const result = createZoomImageWheel(imageWheelContainer)
cleanup = result.cleanup
createZoomImageWheel(imageWheelContainer)
}
if (zoomType === "move") {
cleanup = createZoomImageMove(imageMoveContainer, {
createZoomImageMove(imageMoveContainer, {
zoomImageSource: "https://nam-assets.netlify.app/static/large.webp",
}).cleanup
})
}
if (zoomType === "click") {
cleanup = createZoomImageClick(imageClickContainer, {
createZoomImageClick(imageClickContainer, {
zoomImageSource: "https://nam-assets.netlify.app/static/large.webp",
}).cleanup
})
}
}
$: processZoom(zoomType)
onDestroy(() => {
cleanup()
})
</script>

<div class="font-sans">
<div class="p-4 font-sans">
<nav class="flex space-x-4 pb-4" aria-label="Tabs">
{#each tabs as tab (tab.name)}
<a
Expand All @@ -86,9 +84,53 @@
</nav>

{#if zoomType === "wheel"}
<p>Scroll inside the image to see zoom in-out effect</p>
<div bind:this={imageWheelContainer} class="h-[300px] w-[300px] cursor-crosshair">
<img class="h-full w-full" alt="Large Pic" src="https://nam-assets.netlify.app/static/large.webp" />
<div class="space-y-4">
<p>Current zoom: {`${Math.round($zoomImageWheelState.currentZoom * 100)}%`}</p>
<p>Scroll inside the image to see zoom in-out effect</p>
<div class="mt-1 flex space-x-2">
<div bind:this={imageWheelContainer} class="h-[300px] w-[300px] cursor-crosshair">
<img class="h-full w-full" alt="Large Pic" src="/large.webp" />
</div>

{#if croppedImage !== ""}
<img src={croppedImage} class="h-[300px] w-[300px]" alt="Cropped placeholder" />
{/if}
</div>
<div class="flex space-x-2">
<button
on:click={() => {
setZoomImageWheelState({
currentZoom: $zoomImageWheelState.currentZoom + 0.5,
})
}}
class="text-dark-500 rounded bg-gray-100 p-2 text-sm font-medium"
>
Zoom in
</button>
<button
on:click={() => {
setZoomImageWheelState({
currentZoom: $zoomImageWheelState.currentZoom - 0.5,
})
}}
class="text-dark-500 rounded bg-gray-100 p-2 text-sm font-medium"
>
Zoom out
</button>
<button
class="text-dark-500 rounded bg-gray-100 p-2 text-sm font-medium"
on:click={() => {
croppedImage = cropImage({
currentZoom: $zoomImageWheelState.currentZoom,
image: imageWheelContainer.querySelector("img"),
positionX: $zoomImageWheelState.currentPositionX,
positionY: $zoomImageWheelState.currentPositionY,
})
}}
>
Crop image
</button>
</div>
</div>
{/if}

Expand Down
1 change: 1 addition & 0 deletions examples/svelte-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "virtual:uno.css"
import "@unocss/reset/tailwind.css"
import App from "./App.svelte"

const app = new App({
Expand Down
2 changes: 2 additions & 0 deletions examples/vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
},
"dependencies": {
"@zoom-image/core": "latest",
"@zoom-image/vue": "latest",
"vue": "^3.3.4"
},
"devDependencies": {
"@types/node": "^20.2.3",
"@unocss/reset": "^0.52.1",
"@vitejs/plugin-vue": "^4.2.3",
"@vue/tsconfig": "^0.4.0",
"npm-run-all": "^4.1.5",
Expand Down
Binary file removed examples/vue-ts/public/favicon.ico
Binary file not shown.
Binary file added examples/vue-ts/public/large.webp
Binary file not shown.
Loading

0 comments on commit 9a2966f

Please sign in to comment.