diff --git a/bun.lockb b/bun.lockb index 21ce4e2..2c89d77 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 027ffd1..5645c19 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@sveltejs/vite-plugin-svelte": "^3.0.0", "@types/eslint": "^9.6.0", "@types/node": "^22.6.0", + "blob-util": "^2.0.2", "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", diff --git a/src/lib/sqlite.ts b/src/lib/sqlite.ts index f6affd3..a91f8ed 100644 --- a/src/lib/sqlite.ts +++ b/src/lib/sqlite.ts @@ -17,12 +17,21 @@ CREATE TABLE IF NOT EXISTS projects ( type Project = { id: string; title: string; - pages: { - title: string; - src: string; - background: string; - }[]; + pages: Page[]; }; -export type { Project }; +type Page = { + title: string; + src: string; + background: string; + iteraction: Iteraction[]; +}; + +type Iteraction = { + x: number; + y: number; + link: string; +}; + +export type { Project, Iteraction, Page }; export default db; diff --git a/src/routes/projects/[id]/+page.server.ts b/src/routes/projects/[id]/+page.server.ts index 4c20ea7..4ae541b 100644 --- a/src/routes/projects/[id]/+page.server.ts +++ b/src/routes/projects/[id]/+page.server.ts @@ -49,6 +49,7 @@ export const actions = { const file = form?.get('file') as File; const title = form?.get('title') as string; const color = form?.get('color') as string; + const iteractions = form?.get('iteractions') as string; console.log(file); @@ -68,7 +69,8 @@ export const actions = { proj.pages.push({ title: title, src: filename, - background: color + background: color, + iteraction: JSON.parse(iteractions) }); const buf = Buffer.from(await file.arrayBuffer()); diff --git a/src/routes/projects/[id]/+page.svelte b/src/routes/projects/[id]/+page.svelte index 0c87f6b..3af13a8 100644 --- a/src/routes/projects/[id]/+page.svelte +++ b/src/routes/projects/[id]/+page.svelte @@ -1,6 +1,8 @@ {#if browser} @@ -82,6 +109,12 @@ )} + +
+
+{JSON.stringify(pages)}
+
+
{/if} @@ -101,7 +134,96 @@
- + {#if blobUrl} +
+
+
+ {#each iteractions as i} + + {/each} + { + let rect = imageElement.getBoundingClientRect(); + imageX = Math.round(((e.clientX - rect.left) / rect.width) * 100); + imageY = Math.round(((e.clientY - rect.top) / rect.height) * 100); + imageWidth = rect.width; + imageHeight = rect.height; + }} + on:click={() => { + currentIteraction ||= { x: 0, y: 0, link: '' }; + currentIteraction.x = imageX; + currentIteraction.y = imageY; + }} + alt="" + /> +
+
+ { + currentIteraction ||= { x: 0, y: 0, link: '' }; + currentIteraction.link = iteractionUrl; + }} + on:mouseout={() => { + currentIteraction ||= { x: 0, y: 0, link: '' }; + currentIteraction.link = iteractionUrl; + }} + /> + { + iteractions.push({ + x: currentIteraction.x, + y: currentIteraction.y, + link: currentIteraction.link + }); + iteractions = iteractions; + }} + /> +
+
+ {imageX} {imageY} + + Iteraction: {JSON.stringify(currentIteraction)} + + +
+
+ {/if} + { + // @ts-ignore + readFile(fileInput.files[0]); + }} + />
@@ -156,10 +278,10 @@ {#each pages as page, key} {@const coord = key * chunk}
- +
- +
@@ -182,6 +304,20 @@ opacity: 0.3; } + .iteraction-box { + width: 30px; + height: 30px; + display: block; + background-color: #ff0000; + opacity: 0.3; + position: absolute; + z-index: 100; + } + + .blob-image-image { + position: relative; + } + .reader { display: flex; diff --git a/src/routes/projects/[id]/IteractiveImage.svelte b/src/routes/projects/[id]/IteractiveImage.svelte new file mode 100644 index 0000000..17f8348 --- /dev/null +++ b/src/routes/projects/[id]/IteractiveImage.svelte @@ -0,0 +1,64 @@ + + +
setCoords()}> + {#if page.iteraction !== undefined && browser} + {#each page.iteraction as i} + + {/each} + {/if} + +
+ +