Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | 8x 8x 8x 8x 13066x 13066x 819x 8x 802x 802x 802x 49x 49x 49x 802x 734x 10x 10x 10x 10x 10x 10x 10x 5x 5x 4x 3x 3x 3x 3x 5x 10x 10x 10x 10x 10x 9x 3895x 3895x 3895x 3895x 6x 6x 6x 3x 3x 1x 2x 1x 1x 6x 3895x 3895x | import {
useCallback,
useEffect,
useRef,
useState,
type ReactNode,
} from 'react';
import { createPortal } from 'react-dom';
import type { CaptureMode } from './lib/Db';
// Static, trusted SVG markup (24×24, stroked).
const ICONS = {
visible:
'<rect x="3" y="4" width="18" height="13" rx="2"/><path d="M8 21h8M12 17v4"/>',
full: '<rect x="5" y="2" width="14" height="20" rx="2"/><path d="M12 6.5v9M8.5 12 12 15.5 15.5 12"/>',
selection:
'<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"/><path d="M12 9v6M9 12h6"/>',
tabs: '<rect x="7" y="3" width="14" height="12" rx="2"/><path d="M17 19H6a2 2 0 0 1-2-2V8"/>',
history:
'<path d="M3 12a9 9 0 1 0 2.6-6.4L3 8"/><path d="M3 3v5h5M12 7.5V12l3 2"/>',
select: '<path d="M5 3.5 18.5 10l-6 1.8-2.2 6.2z"/>',
crop: '<path d="M6 2v14a2 2 0 0 0 2 2h14M2 6h14a2 2 0 0 1 2 2v14"/>',
arrow: '<path d="M5 19 19 5M9 5h10v10"/>',
rect: '<rect x="4" y="5" width="16" height="14" rx="1.5"/>',
ellipse: '<ellipse cx="12" cy="12" rx="9" ry="7"/>',
line: '<path d="M5 19 19 5"/>',
pen: '<path d="M15.5 4.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4z"/><path d="M13.5 6.5l3 3"/>',
highlight:
'<path d="m9 11-5 5v4h4l5-5"/><path d="m9 11 6-6 4 4-6 6zM14 20h6"/>',
text: '<path d="M5 7V5h14v2M12 5v14M9 19h6"/>',
step: '<circle cx="12" cy="12" r="9"/><path d="M10.5 9.5 12.5 8v8"/>',
blur: '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M4 9.3h16M4 14.7h16M9.3 4v16M14.7 4v16"/>',
undo: '<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>',
redo: '<path d="m15 14 5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>',
copy: '<rect x="8" y="8" width="13" height="13" rx="2"/><path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/>',
download: '<path d="M12 3v12M7 10l5 5 5-5M4 21h16"/>',
pdf: '<path d="M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><path d="M14 3v6h6M8 13h8M8 17h5"/>',
scanText:
'<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"/><path d="M8 9h8M8 12h8M8 15h5"/>',
print:
'<path d="M6 9V3h12v6M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="7" rx="1"/>',
trash: '<path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3"/>',
check: '<path d="m5 12.5 4.5 4.5L19 7.5"/>',
search: '<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>',
back: '<path d="M15 18 9 12l6-6"/>',
minus: '<path d="M5 12h14"/>',
plus: '<path d="M12 5v14M5 12h14"/>',
timer: '<circle cx="12" cy="13" r="8"/><path d="M12 9v4l2.5 2M9 2h6"/>',
lock: '<rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
chevron: '<path d="m6 9 6 6 6-6"/>',
reset: '<path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/>',
keyboard:
'<rect x="2" y="6" width="20" height="12" rx="2"/><path d="M6 10h.01M10 10h.01M14 10h.01M18 10h.01M7 14h10"/>',
image:
'<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-5-5L5 21"/>',
window:
'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 9h18M6.5 6.5h.01M9.5 6.5h.01"/>',
settings:
'<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>',
close: '<path d="M6 6l12 12M18 6 6 18"/>',
alert: '<circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5M12 16.5h.01"/>',
coffee:
'<path class="coffee-handle" d="M17 8h1a4 4 0 1 1 0 8h-1"/><path class="coffee-cup" d="M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z"/><path class="coffee-steam coffee-steam-1" d="M6 2v3"/><path class="coffee-steam coffee-steam-2" d="M10 2v3"/><path class="coffee-steam coffee-steam-3" d="M14 2v3"/>',
} as const;
export const SUPPORT_URL = 'https://buymeacoffee.com/projectra';
export const SUPPORT_LABEL = 'Support Daguerre on Buy Me a Coffee';
export const SUPPORT_TEXT =
"Daguerre is 100% free. If you'd like to support its development, buying a coffee is warmly appreciated.";
export type IconName = keyof typeof ICONS;
export function Icon({
name,
size = 18,
className,
}: {
name: IconName;
size?: number;
className?: string;
}) {
const classes = ['icon', `icon-${name}`, className].filter(Boolean).join(' ');
return (
<svg
width={size}
height={size}
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth={1.75}
strokeLinecap='round'
strokeLinejoin='round'
aria-hidden='true'
className={classes}
dangerouslySetInnerHTML={{ __html: ICONS[name] }}
/>
);
}
export function Logo({
size = 28,
mono = false,
}: {
size?: number;
mono?: boolean;
}) {
return (
<svg
width={size}
height={size}
viewBox='0 0 28 28'
aria-hidden='true'
className={mono ? 'logo logo-mono' : 'logo'}
>
{!mono && (
<>
<defs>
<linearGradient id='sc-onyx' x1='0' y1='0' x2='0' y2='1'>
<stop offset='0' stopColor='#2a2a2f' />
<stop offset='1' stopColor='#050506' />
</linearGradient>
<linearGradient id='sc-silver' x1='0' y1='0' x2='1' y2='1'>
<stop offset='0' stopColor='#ffffff' />
<stop offset='0.5' stopColor='#c9ccd2' />
<stop offset='1' stopColor='#8e929a' />
</linearGradient>
</defs>
<rect
x='0.5'
y='0.5'
width='27'
height='27'
rx='7.5'
fill='url(#sc-onyx)'
stroke='rgba(255,255,255,.16)'
/>
</>
)}
<path
d={
mono
? 'M5 10V5h5M18 5h5v5M23 18v5h-5M10 23H5v-5'
: 'M8 11.5V8h3.5M16.5 8H20v3.5M20 16.5V20h-3.5M11.5 20H8v-3.5'
}
stroke={mono ? '#ffffff' : 'url(#sc-silver)'}
strokeWidth={mono ? '2.5' : '2.2'}
fill='none'
strokeLinecap='round'
strokeLinejoin='round'
/>
<circle
cx='14'
cy='14'
r={mono ? '2.4' : '2'}
fill={mono ? '#ffffff' : 'url(#sc-silver)'}
/>
</svg>
);
}
export const MODE_LABEL: Record<CaptureMode, string> = {
visible: 'Visible area',
full: 'Full page',
selection: 'Selection',
tabs: 'Tab',
screen: 'Screen',
window: 'Window',
};
export function useToast() {
const [message, setMessage] = useState<ReactNode>();
const timer = useRef<number>(undefined);
const show = useCallback((m: ReactNode, ms = 2600) => {
clearTimeout(timer.current);
setMessage(m);
timer.current = window.setTimeout(() => setMessage(undefined), ms);
}, []);
return [message, show] as const;
}
export function Toast({ message }: { message: ReactNode }) {
return (
<div
className='toast'
role='status'
aria-live='polite'
data-show={message ? '' : undefined}
>
{message}
</div>
);
}
/** Modal confirmation; keeps keyboard focus inside and cancels on Escape or a backdrop click. */
export function ConfirmDialog({
title,
children,
confirmLabel,
onConfirm,
onCancel,
}: {
title: string;
children: ReactNode;
confirmLabel: string;
onConfirm: () => void;
onCancel: () => void;
}) {
const dialog = useRef<HTMLDivElement>(null);
const cancel = useRef(onCancel);
cancel.current = onCancel;
useEffect(() => {
const previous = document.activeElement as HTMLElement | null;
dialog.current?.querySelector('button')?.focus();
// Capture phase, so page shortcuts underneath don't fire while the dialog is open.
const onKey = (e: KeyboardEvent) => {
e.stopPropagation();
if (e.key === 'Escape') return cancel.current();
if (e.key !== 'Tab') return;
e.preventDefault();
const buttons = [...dialog.current!.querySelectorAll('button')];
const i = buttons.indexOf(document.activeElement as HTMLButtonElement);
const step = e.shiftKey ? -1 : 1;
buttons[(i + step + buttons.length) % buttons.length].focus();
};
addEventListener('keydown', onKey, true);
return () => {
removeEventListener('keydown', onKey, true);
previous?.focus();
};
}, []);
return (
<div
className='dialog-backdrop'
onClick={(e) => e.target === e.currentTarget && onCancel()}
>
<div
ref={dialog}
className='dialog'
role='alertdialog'
aria-modal='true'
aria-labelledby='dialog-title'
aria-describedby='dialog-body'
>
<h2 id='dialog-title'>{title}</h2>
<p id='dialog-body'>{children}</p>
<div className='dialog-actions'>
<button type='button' className='btn ghost' onClick={onCancel}>
Cancel
</button>
<button type='button' className='btn danger' onClick={onConfirm}>
{confirmLabel}
</button>
</div>
</div>
</div>
);
}
export function Tooltip({
content,
children,
position = 'top',
}: {
content: string;
children: ReactNode;
position?: 'top' | 'bottom' | 'right' | 'left';
}) {
const [visible, setVisible] = useState(false);
const [coords, setCoords] = useState<{ top: number; left: number }>({
top: 0,
left: 0,
});
const triggerRef = useRef<HTMLDivElement>(null);
const show = () => {
Iif (!triggerRef.current) return;
const rect = triggerRef.current.getBoundingClientRect();
if (position === 'right') {
setCoords({
top: rect.top + rect.height / 2,
left: rect.right + 8,
});
} else if (position === 'bottom') {
setCoords({
top: rect.bottom + 8,
left: rect.left + rect.width / 2,
});
} else if (position === 'left') {
setCoords({
top: rect.top + rect.height / 2,
left: rect.left - 8,
});
} else {
setCoords({
top: rect.top - 8,
left: rect.left + rect.width / 2,
});
}
setVisible(true);
};
const hide = () => setVisible(false);
return (
<div
ref={triggerRef}
className='tooltip-wrapper'
onPointerEnter={show}
onPointerLeave={hide}
onMouseEnter={show}
onMouseLeave={hide}
onFocus={show}
onBlur={hide}
style={{
display: 'inline-flex',
overflow: 'visible',
position: 'relative',
}}
>
{children}
{visible &&
createPortal(
<div
className={`tooltip-pill tooltip-${position}`}
role='tooltip'
style={{
position: 'fixed',
top: coords.top,
left: coords.left,
transform:
position === 'right'
? 'translateY(-50%)'
: position === 'left'
? 'translate(-100%, -50%)'
: position === 'bottom'
? 'translateX(-50%)'
: 'translate(-50%, -100%)',
zIndex: 9999,
pointerEvents: 'none',
}}
>
{content}
</div>,
document.body,
)}
</div>
);
}
|