snapshot
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["svelte.svelte-vscode"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Svelte + TS + Vite
|
||||||
|
|
||||||
|
This template should help get you started developing with Svelte and TypeScript in Vite.
|
||||||
|
|
||||||
|
## Recommended IDE Setup
|
||||||
|
|
||||||
|
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||||
|
|
||||||
|
## Need an official Svelte framework?
|
||||||
|
|
||||||
|
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
||||||
|
|
||||||
|
## Technical considerations
|
||||||
|
|
||||||
|
**Why use this over SvelteKit?**
|
||||||
|
|
||||||
|
- It brings its own routing solution which might not be preferable for some users.
|
||||||
|
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
||||||
|
|
||||||
|
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
||||||
|
|
||||||
|
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
||||||
|
|
||||||
|
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
||||||
|
|
||||||
|
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
||||||
|
|
||||||
|
**Why include `.vscode/extensions.json`?**
|
||||||
|
|
||||||
|
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
||||||
|
|
||||||
|
**Why enable `allowJs` in the TS template?**
|
||||||
|
|
||||||
|
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
|
||||||
|
|
||||||
|
**Why is HMR not preserving my local component state?**
|
||||||
|
|
||||||
|
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
||||||
|
|
||||||
|
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// store.ts
|
||||||
|
// An extremely simple external store
|
||||||
|
import { writable } from 'svelte/store'
|
||||||
|
export default writable(0)
|
||||||
|
```
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Vite + Svelte + TS</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Generated
+1824
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "svelte-screenshot-app",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
||||||
|
"@tsconfig/svelte": "^5.0.2",
|
||||||
|
"svelte": "^4.2.12",
|
||||||
|
"svelte-check": "^3.6.7",
|
||||||
|
"tslib": "^2.6.2",
|
||||||
|
"typescript": "^5.2.2",
|
||||||
|
"vite": "^5.2.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"idb": "^8.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,161 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { IGalleryDb, IGalleryImage } from "./app";
|
||||||
|
import CompGalleryImage from "./CompGalleryImage.svelte";
|
||||||
|
import CompDialogImage from "./CompDialogImage.svelte";
|
||||||
|
|
||||||
|
export var db: IGalleryDb;
|
||||||
|
|
||||||
|
var videoReadyState = 0;
|
||||||
|
var showImage: IGalleryImage | null = null;
|
||||||
|
var video: HTMLVideoElement;
|
||||||
|
var canvas: HTMLCanvasElement;
|
||||||
|
var queryPage = db.selectImages("ix_when");
|
||||||
|
var queryPageImages = queryPage.result;
|
||||||
|
|
||||||
|
queryPage.setArgs({
|
||||||
|
direction: "prev",
|
||||||
|
});
|
||||||
|
queryPage.refresh();
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
const cleanup = new Array<CallableFunction>();
|
||||||
|
const context = canvas.getContext("2d");
|
||||||
|
if (!context) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const asyncTask = async () => {
|
||||||
|
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
||||||
|
const tracks = stream.getTracks();
|
||||||
|
|
||||||
|
video.srcObject = stream;
|
||||||
|
video.play();
|
||||||
|
|
||||||
|
const intervalId = setInterval(async () => {
|
||||||
|
canvas.width = video.videoWidth;
|
||||||
|
canvas.height = video.videoHeight;
|
||||||
|
|
||||||
|
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
const when = new Date();
|
||||||
|
const dataUrl = canvas.toDataURL("image/png");
|
||||||
|
|
||||||
|
const storedImageId = await db.storeImage({
|
||||||
|
when,
|
||||||
|
dataUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryPage.refresh();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
cleanup.push(() => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
|
||||||
|
tracks.forEach((track) => track.stop());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
asyncTask();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
for (const fn of cleanup) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="video-container">
|
||||||
|
<div class="video-feed">
|
||||||
|
<video bind:this={video} bind:readyState={videoReadyState}>
|
||||||
|
<track kind="captions" />
|
||||||
|
</video>
|
||||||
|
{#if videoReadyState == 4}
|
||||||
|
<div class="watermark">
|
||||||
|
<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle r="8" cx="8" cy="8" fill="red" />
|
||||||
|
</svg>
|
||||||
|
Live
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="gallery">
|
||||||
|
{#each $queryPageImages.images as image (image.id)}
|
||||||
|
<CompGalleryImage on:click={() => (showImage = image)} {image}></CompGalleryImage>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<canvas bind:this={canvas}></canvas>
|
||||||
|
|
||||||
|
{#if showImage}
|
||||||
|
<CompDialogImage bind:image={showImage}></CompDialogImage>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.video-container {
|
||||||
|
width: 600px;
|
||||||
|
height: 600px;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-feed {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.watermark {
|
||||||
|
top: 8px;
|
||||||
|
right: 8px;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
padding: 4px 12px;
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
column-gap: 8px;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
border: 3px solid crimson;
|
||||||
|
border-radius: 8px;
|
||||||
|
|
||||||
|
color: crimson;
|
||||||
|
font-weight: 800;
|
||||||
|
|
||||||
|
box-shadow: 0 0 3px #333;
|
||||||
|
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.watermark svg {
|
||||||
|
animation: on-air 0.75s ease-in-out 0s infinite both alternate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes on-air {
|
||||||
|
from {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
video {
|
||||||
|
max-width: 600px;
|
||||||
|
max-height: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery {
|
||||||
|
display: grid;
|
||||||
|
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
grid-template-columns: repeat(5, auto);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { createEventDispatcher } from "svelte";
|
||||||
|
import type { IGalleryImage } from "./app";
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
export var image: IGalleryImage | null = null;
|
||||||
|
|
||||||
|
export var next: number | null = null;
|
||||||
|
export var prev: number | null = null;
|
||||||
|
|
||||||
|
export var cycle: boolean = false;
|
||||||
|
|
||||||
|
var dialog: HTMLDialogElement;
|
||||||
|
|
||||||
|
function fireKeyDown(ev: KeyboardEvent) {
|
||||||
|
if (!image || !cycle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev.key == "ArrowLeft" && prev != null) {
|
||||||
|
dispatch("change", prev);
|
||||||
|
}
|
||||||
|
if (ev.key == "ArrowRight" && next != null) {
|
||||||
|
dispatch("change", next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (image && dialog?.open == false) {
|
||||||
|
dialog.showModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={(ev) => fireKeyDown(ev)} />
|
||||||
|
|
||||||
|
{#if image}
|
||||||
|
<dialog bind:this={dialog} class="dialog-container" on:close={() => (image = null)} on:cancel={() => (image = null)}>
|
||||||
|
<div class="dialog-header">
|
||||||
|
<button on:click={() => (image = null)}>Close</button>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-content">
|
||||||
|
<img src={image.dataUrl} alt={`Screenshot taken at ${image.when.toISOString()}`} />
|
||||||
|
</div>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
{#if cycle}
|
||||||
|
<button on:click={() => dispatch("change", prev)} disabled={prev == null}>«</button>
|
||||||
|
{/if}
|
||||||
|
<div class="dialog-image-info">
|
||||||
|
<p>{image.when.toLocaleString()}</p>
|
||||||
|
</div>
|
||||||
|
{#if cycle}
|
||||||
|
<button on:click={() => dispatch("change", next)} disabled={next == null}>»</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.dialog-container::backdrop {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: transparent;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-container {
|
||||||
|
margin: auto;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
row-gap: 8px;
|
||||||
|
|
||||||
|
min-width: 1200px;
|
||||||
|
|
||||||
|
border: 2px solid #333;
|
||||||
|
border-radius: 8px;
|
||||||
|
|
||||||
|
box-shadow: 0 0 3px #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-content {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
place-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-header {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
place-content: space-between;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { writable } from "svelte/store";
|
||||||
|
import type { IGalleryDb, IGalleryImage } from "./app";
|
||||||
|
import CompDialogImage from "./CompDialogImage.svelte";
|
||||||
|
import CompGalleryImage from "./CompGalleryImage.svelte";
|
||||||
|
|
||||||
|
interface IDialogButtons {
|
||||||
|
next: number | null;
|
||||||
|
prev: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export var db: IGalleryDb;
|
||||||
|
|
||||||
|
const buttons = writable<IDialogButtons>({
|
||||||
|
prev: null,
|
||||||
|
next: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
var page = 1;
|
||||||
|
var stop = 1;
|
||||||
|
var take = 20;
|
||||||
|
var showImage: IGalleryImage | null = null;
|
||||||
|
var queryPage = db.selectImages("ix_when");
|
||||||
|
var queryPageImages = queryPage.result;
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
if (!showImage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var start = 0;
|
||||||
|
var count = $queryPageImages.count - 1;
|
||||||
|
var index = $queryPageImages.images.indexOf(showImage);
|
||||||
|
var delta = (page - 1) * take + index;
|
||||||
|
|
||||||
|
buttons.set({
|
||||||
|
prev: delta > start ? delta - 1 : null,
|
||||||
|
next: delta < count ? delta + 1 : null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fireKeyDown(change: number | null = 0) {
|
||||||
|
if (!showImage || change == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var a = (page - 1) * take;
|
||||||
|
var b = (page + 0) * take - 1;
|
||||||
|
|
||||||
|
if (change < a) {
|
||||||
|
await query(page-1);
|
||||||
|
}
|
||||||
|
if (change > b) {
|
||||||
|
await query(page+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
showImage = $queryPageImages.images[change % take];
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function query(next: number) {
|
||||||
|
page = next;
|
||||||
|
queryPage.setArgs({
|
||||||
|
take: take,
|
||||||
|
skip: (page - 1) * take,
|
||||||
|
direction: "prev",
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryPage.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
$: stop = 1 + Math.floor($queryPageImages.count / take);
|
||||||
|
$: if (showImage) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
query(1);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="gallery-container">
|
||||||
|
<div class="gallery-images">
|
||||||
|
{#each $queryPageImages.images as image (image.id)}
|
||||||
|
<CompGalleryImage on:click={() => (showImage = image)} {image}></CompGalleryImage>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<div class="gallery-controls">
|
||||||
|
<button on:click={() => query(page - 1)} disabled={page == 1}>«</button>
|
||||||
|
{page} / {stop}
|
||||||
|
<button on:click={() => query(page + 1)} disabled={page == stop}>»</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if showImage}
|
||||||
|
<CompDialogImage bind:image={showImage} cycle={true} prev={$buttons.prev} next={$buttons.next} on:change={(ev) => fireKeyDown(ev.detail)}></CompDialogImage>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.gallery-images {
|
||||||
|
display: grid;
|
||||||
|
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
grid-template-columns: repeat(5, auto);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery-controls {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
column-gap: 8px;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery-container {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { IGalleryImage } from "./app";
|
||||||
|
|
||||||
|
export var image: IGalleryImage;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="image-gallery-image" on:click>
|
||||||
|
<div></div>
|
||||||
|
<img width="150" height="150" src={image.dataUrl} alt={`Screenshot taken at ${image.when.toISOString()}`} />
|
||||||
|
<p>{image.when.toLocaleString()}</p>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.image-gallery-image {
|
||||||
|
width: 180px;
|
||||||
|
height: 180px;
|
||||||
|
padding: 8px;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: 300;
|
||||||
|
font-family: inherit;
|
||||||
|
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-gallery-image img {
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import CompCamera from "./CompCamera.svelte";
|
||||||
|
import CompGallery from "./CompGallery.svelte";
|
||||||
|
|
||||||
|
import { initGallery } from "./app";
|
||||||
|
|
||||||
|
const dbTask = initGallery();
|
||||||
|
var mode = 2;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#await dbTask}
|
||||||
|
Loading...
|
||||||
|
{:then db}
|
||||||
|
<header>
|
||||||
|
<div class="grp">
|
||||||
|
<b>Live Stream Screenshot Capture</b>
|
||||||
|
</div>
|
||||||
|
<div class="space"></div>
|
||||||
|
<div class="grp">
|
||||||
|
<button on:click={() => (mode = 1)}>Live</button>
|
||||||
|
<button on:click={() => (mode = 2)}>Past</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{#if mode == 1}
|
||||||
|
<CompCamera {db}></CompCamera>
|
||||||
|
{/if}
|
||||||
|
{#if mode == 2}
|
||||||
|
<CompGallery {db}></CompGallery>
|
||||||
|
{/if}
|
||||||
|
</main>
|
||||||
|
{/await}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
header {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
border-bottom: 1px solid #111;
|
||||||
|
|
||||||
|
background: linear-gradient(#222, #333);
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding: 8px;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grp {
|
||||||
|
padding: 8px;
|
||||||
|
display: flex;
|
||||||
|
column-gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grp b {
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grp button {
|
||||||
|
min-width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.space {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
:root {
|
||||||
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
background-color: #242424;
|
||||||
|
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #646cff;
|
||||||
|
text-decoration: inherit;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #535bf2;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
place-items: center;
|
||||||
|
place-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 0.6em 1.2em;
|
||||||
|
|
||||||
|
border: 2px solid #444;
|
||||||
|
border-radius: 8px;
|
||||||
|
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: 500;
|
||||||
|
font-family: inherit;
|
||||||
|
|
||||||
|
box-shadow: 0 0 4px black;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
|
||||||
|
transition: border-color 0.25s;
|
||||||
|
}
|
||||||
|
button:not(button:disabled):hover {
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
border-color: #646cff;
|
||||||
|
}
|
||||||
|
button:not(button:disabled):focus,
|
||||||
|
button:not(button:disabled):focus-visible {
|
||||||
|
outline: 4px auto -webkit-focus-ring-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
color: #213547;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #747bff;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
}
|
||||||
+141
@@ -0,0 +1,141 @@
|
|||||||
|
import { openDB, type IDBPDatabase } from "idb";
|
||||||
|
import type { Readable } from "svelte/motion";
|
||||||
|
import { readable, writable } from "svelte/store";
|
||||||
|
|
||||||
|
export interface IGalleryImage {
|
||||||
|
id: IDBValidKey;
|
||||||
|
when: Date;
|
||||||
|
dataUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFetchGalleryImagesArgs {
|
||||||
|
constraint?: IDBKeyRange;
|
||||||
|
direction?: IDBCursorDirection;
|
||||||
|
take?: number;
|
||||||
|
skip?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFetchGalleryImagesPage {
|
||||||
|
count: number;
|
||||||
|
images: Array<IGalleryImage>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFetchGalleryImagesQuery {
|
||||||
|
result: Readable<IFetchGalleryImagesPage>;
|
||||||
|
|
||||||
|
refresh() : Promise<void>;
|
||||||
|
|
||||||
|
setArgs(args: IFetchGalleryImagesArgs): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IGalleryDb {
|
||||||
|
storeImage (image: Omit<IGalleryImage, 'id'>) : Promise<IDBValidKey>;
|
||||||
|
|
||||||
|
selectImages (index: string): IFetchGalleryImagesQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
const storeName = "images";
|
||||||
|
|
||||||
|
export async function initGallery() {
|
||||||
|
const updates = Array<CallableFunction>();
|
||||||
|
|
||||||
|
const db = await openDB("image-diary", 1, {
|
||||||
|
upgrade(db) {
|
||||||
|
const images = db.createObjectStore(storeName, { keyPath: "id", autoIncrement: true });
|
||||||
|
|
||||||
|
images.createIndex("ix_when", ["when"]);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const fnStoreImage = async (image: IGalleryImage) => {
|
||||||
|
const tx = db.transaction(storeName, "readwrite");
|
||||||
|
const id = await tx.objectStore(storeName).add(image);
|
||||||
|
|
||||||
|
await tx.done;
|
||||||
|
|
||||||
|
for (const update of updates) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fnSelectImages = (index: string): IFetchGalleryImagesQuery => {
|
||||||
|
var skip = 0;
|
||||||
|
var take = 5;
|
||||||
|
var direction: IDBCursorDirection = 'next';
|
||||||
|
var constraint: IDBKeyRange | null = null;
|
||||||
|
|
||||||
|
const setters = new Array<(v: IFetchGalleryImagesPage) => void>();
|
||||||
|
|
||||||
|
const fnRefresh = async () => {
|
||||||
|
if (setters.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('refresh', 'skip', skip, 'take', take, 'direction', direction, 'constraint', constraint);
|
||||||
|
|
||||||
|
const tx = db.transaction(storeName, "readonly");
|
||||||
|
const store = tx.objectStore(storeName);
|
||||||
|
const index = store.index("ix_when");
|
||||||
|
|
||||||
|
var shouldSkip = skip;
|
||||||
|
var shouldTake = take;
|
||||||
|
|
||||||
|
var result = new Array<IGalleryImage>();
|
||||||
|
|
||||||
|
const count = await index.count();
|
||||||
|
|
||||||
|
for await (const cursor of index.iterate(constraint, direction)) {
|
||||||
|
if (shouldSkip > 0) {
|
||||||
|
cursor.advance(skip);
|
||||||
|
|
||||||
|
shouldSkip = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldTake > 0) {
|
||||||
|
result.push(cursor.value);
|
||||||
|
|
||||||
|
shouldTake--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const set of setters) {
|
||||||
|
set({
|
||||||
|
count: count,
|
||||||
|
images: result
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await tx.done;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
result: readable<IFetchGalleryImagesPage>({count: 0, images: []}, (set) => {
|
||||||
|
setters.push(set);
|
||||||
|
updates.push(fnRefresh);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
setters.splice(setters.indexOf(set), 1);
|
||||||
|
updates.splice(updates.indexOf(fnRefresh), 1);
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
refresh: fnRefresh,
|
||||||
|
setArgs: (args) => {
|
||||||
|
constraint = args.constraint ?? null;
|
||||||
|
direction = args.direction ?? 'next';
|
||||||
|
skip = args.skip ?? 0;
|
||||||
|
take = args.take ?? 5;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
storeImage: fnStoreImage,
|
||||||
|
selectImages: fnSelectImages,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let count: number = 0
|
||||||
|
const increment = () => {
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={increment}>
|
||||||
|
count is {count}
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import './app.css'
|
||||||
|
import CompMain from './CompMain.svelte'
|
||||||
|
|
||||||
|
const app = new CompMain({
|
||||||
|
target: document.getElementById('app')!,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default app
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
/// <reference types="svelte" />
|
||||||
|
/// <reference types="vite/client" />
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||||
|
// for more information about preprocessors
|
||||||
|
preprocess: vitePreprocess(),
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
/**
|
||||||
|
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||||
|
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||||
|
* Note that setting allowJs false does not prevent the use
|
||||||
|
* of JS in `.svelte` files.
|
||||||
|
*/
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
||||||
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [svelte()],
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user