current state before improvement pass

This commit is contained in:
2026-05-27 18:56:36 +03:00
parent 5eb27ab779
commit f0775b8ff0
23 changed files with 3563 additions and 1853 deletions
+82 -82
View File
@@ -1,138 +1,138 @@
<script lang="ts">
import { onMount } from "svelte"
import { listen } from "@tauri-apps/api/event"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { listen } from "@tauri-apps/api/event"
type Rect = {
x: number
y: number
width: number
height: number
}
type Rect = { x: number; y: number; width: number; height: number }
let hover: Rect | null = $state(null)
let scale: number = $state(1)
let originX: number = $state(0)
let originY: number = $state(0)
let dpr: number = $state(1)
let innerW: number = $state(0)
let innerH: number = $state(0)
let originX = 0, originY = 0, scale = 1
onMount(() => {
const win = getCurrentWebviewWindow()
let unlistenHover: (() => void) | null = null
let unlistenMoved: (() => void) | null = null
let unlisten: (() => void)[] = []
const refreshOrigin = async () => {
const refresh = async () => {
scale = await win.scaleFactor()
const pos = await win.innerPosition()
originX = pos.x
originY = pos.y
dpr = window.devicePixelRatio
innerW = window.innerWidth
innerH = window.innerHeight
originX = pos.x; originY = pos.y
}
void (async () => {
await refreshOrigin()
unlistenMoved = await win.onMoved(refreshOrigin)
unlistenHover = await listen<Rect>("picker-hover", (e) => {
hover = e.payload
})
await refresh()
unlisten.push(await win.onMoved(refresh))
unlisten.push(await listen<Rect>("picker-hover", (e) => { hover = e.payload }))
})()
return () => {
unlistenHover?.()
unlistenMoved?.()
}
return () => unlisten.forEach(fn => fn())
})
let style = $derived.by(() => {
let rectStyle = $derived.by(() => {
if (!hover) return ""
const left = (hover.x - originX) / scale
const top = (hover.y - originY) / scale
const width = hover.width / scale
const height = hover.height / scale
return `left: ${left}px; top: ${top}px; width: ${width}px; height: ${height}px;`
const l = (hover.x - originX) / scale
const t = (hover.y - originY) / scale
const w = hover.width / scale
const h = hover.height / scale
return `left:${l}px;top:${t}px;width:${w}px;height:${h}px`
})
</script>
<main>
<div class="dim"></div>
<div class="picker" aria-label="window picker - click a window to capture it, Esc to cancel">
<div class="dim" aria-hidden="true"></div>
{#if hover}
<div class="frame" style={style}>
<div class="dims">{hover.width} x {hover.height}</div>
<div class="frame" style={rectStyle} aria-hidden="true">
<span class="frame-label">{hover.width} x {hover.height}</span>
</div>
{/if}
<div class="hint">
origin=({originX},{originY}) scale={scale} dpr={dpr} inner={innerW}x{innerH} ·
<div class="hint" aria-live="polite">
{#if hover}
hover {hover.width}x{hover.height} @ ({hover.x},{hover.y})
click to capture - <kbd>{hover.width}x{hover.height}</kbd>
{:else}
move mouse over a window. Esc to cancel.
move mouse over a window to select it - <kbd>Esc</kbd> to cancel
{/if}
</div>
</main>
</div>
<style>
:global(html), :global(body), :global(#picker) {
margin: 0;
padding: 0;
margin: 0; padding: 0;
background: transparent;
height: 100vh;
width: 100vw;
height: 100vh; width: 100vw;
overflow: hidden;
cursor: crosshair;
}
main {
.picker {
position: relative;
width: 100vw;
height: 100vh;
width: 100vw; height: 100vh;
font-family: var(--mono, 'JetBrains Mono', monospace);
}
.dim {
position: absolute;
inset: 0;
background: rgba(10, 14, 12, 0.15);
position: absolute; inset: 0;
background: rgba(9, 9, 11, 0.15);
}
.frame {
position: absolute;
pointer-events: none;
background-color: transparent;
border: 2px solid #14B8A6;
background: transparent;
background-image:
linear-gradient(90deg, #4a8 50%, transparent 50%),
linear-gradient(90deg, #4a8 50%, transparent 50%),
linear-gradient(0deg, #4a8 50%, transparent 50%),
linear-gradient(0deg, #4a8 50%, transparent 50%);
background-position: 0 0, 0 100%, 0 0, 100% 0;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-size: 12px 2px, 12px 2px, 2px 12px, 2px 12px;
repeating-linear-gradient(90deg, #14B8A6 0px, #14B8A6 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(0deg, #14B8A6 0px, #14B8A6 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(90deg, #14B8A6 0px, #14B8A6 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(0deg, #14B8A6 0px, #14B8A6 8px, transparent 8px, transparent 12px);
background-position: 0 0, 0 0, 0 100%, 100% 0;
background-size: 12px 2px, 2px 12px, 12px 2px, 2px 12px;
background-repeat: repeat-x, repeat-y, repeat-x, repeat-y;
animation: march 0.4s linear infinite;
transition: left 0.08s ease, top 0.08s ease, width 0.08s ease, height 0.08s ease;
}
@keyframes march {
to {
background-position: 12px 0, -12px 100%, 0 -12px, 100% 12px;
}
to { background-position: 12px 0, 0 12px, -12px 100%, 100% -12px; }
}
.dims {
.frame-label {
position: absolute;
top: -22px;
left: 0;
padding: 1px 6px;
background: #4a8;
color: #0e1a16;
font: 11px ui-monospace, monospace;
border-radius: 3px;
top: -20px; left: 0;
padding: 2px 6px;
background: #14B8A6;
color: #020617;
font-size: 9px;
font-weight: 600;
font-family: var(--mono, 'JetBrains Mono', monospace);
letter-spacing: 0.04em;
border-radius: 2px;
white-space: nowrap;
}
.hint {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 6px 14px;
background: rgba(0, 0, 0, 0.7);
color: #fff;
position: fixed;
bottom: 20px; left: 50%; transform: translateX(-50%);
padding: 7px 18px;
background: rgba(9, 9, 11, 0.9);
backdrop-filter: blur(10px);
color: rgba(228, 228, 231, 0.85);
font-size: 12px;
font-family: var(--sans, system-ui, sans-serif);
border: 1px solid rgba(20, 184, 166, 0.2);
border-radius: 999px;
font: 13px ui-monospace, monospace;
white-space: nowrap;
pointer-events: none;
}
kbd {
display: inline-block;
padding: 0 4px;
background: rgba(20, 184, 166, 0.12);
border: 1px solid rgba(20, 184, 166, 0.3);
border-radius: 2px;
font-family: var(--mono, 'JetBrains Mono', monospace);
font-size: 10px;
color: #14B8A6;
}
</style>