Add interface languages and improve themes and workspace controls for 0.1.36
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { tr } from '../i18n/index.ts';
|
||||
import { actionIcon, type ActionIcon } from "../ui/actionIcons";
|
||||
import { attachTooltip } from "../ui/tooltip";
|
||||
const tooltipCleanups = new WeakMap<HTMLElement, () => void>();
|
||||
@@ -43,12 +44,12 @@ function button(label: string, icon: ActionIcon, action: () => void) {
|
||||
function zoomImage(original: HTMLImageElement, trigger: HTMLButtonElement) {
|
||||
const dialog = document.createElement("dialog");
|
||||
dialog.className = "image-lightbox";
|
||||
dialog.setAttribute("aria-label", "Image zoom");
|
||||
dialog.setAttribute("aria-label", tr("Image zoom"));
|
||||
const header = document.createElement("div");
|
||||
header.className = "image-lightbox-toolbar";
|
||||
const name = document.createElement("span");
|
||||
name.className = "image-lightbox-name";
|
||||
name.textContent = original.dataset.mdSrc || original.alt || "Image";
|
||||
name.textContent = original.dataset.mdSrc || original.alt || tr("Image");
|
||||
const viewport = document.createElement("div");
|
||||
viewport.className = "image-lightbox-viewport";
|
||||
const image = original.cloneNode() as HTMLImageElement;
|
||||
@@ -62,14 +63,14 @@ function zoomImage(original: HTMLImageElement, trigger: HTMLButtonElement) {
|
||||
scale = next;
|
||||
image.style.width = scale ? `${image.naturalWidth * scale}px` : "";
|
||||
viewport.classList.toggle("is-zoomed", scale > 0);
|
||||
status.textContent = scale ? `${Math.round(scale * 100)}%` : "Fit";
|
||||
status.textContent = scale ? `${Math.round(scale * 100)}%` : tr("Fit");
|
||||
zoomOut.disabled = scale === 0;
|
||||
zoomIn.disabled = scale >= 4;
|
||||
}
|
||||
const zoomOut = button("Zoom out", "zoom-out", () => resize(scale <= .5 ? 0 : scale / 2));
|
||||
const zoomIn = button("Zoom in", "zoom-in", () => resize(scale ? Math.min(4, scale * 2) : 1));
|
||||
const fit = button("Fit image", "select", () => resize(0));
|
||||
const close = button("Close image", "close", () => dialog.close());
|
||||
const zoomOut = button(tr("Zoom out"), "zoom-out", () => resize(scale <= .5 ? 0 : scale / 2));
|
||||
const zoomIn = button(tr("Zoom in"), "zoom-in", () => resize(scale ? Math.min(4, scale * 2) : 1));
|
||||
const fit = button(tr("Fit image"), "select", () => resize(0));
|
||||
const close = button(tr("Close image"), "close", () => dialog.close());
|
||||
header.append(name, zoomOut, status, zoomIn, fit, close);
|
||||
viewport.append(image);
|
||||
dialog.append(header, viewport);
|
||||
@@ -93,17 +94,17 @@ export function imageControls(root: HTMLElement, actions: ImageActions = {}, mea
|
||||
frame.contentEditable = "false";
|
||||
frame.tabIndex = 0;
|
||||
frame.setAttribute("role", "group");
|
||||
frame.setAttribute("aria-label", `Image: ${image.alt || image.dataset.mdSrc || "image"}`);
|
||||
frame.setAttribute("aria-label", tr("Image: {name}", { name: image.alt || image.dataset.mdSrc || tr("Image") }));
|
||||
image.replaceWith(frame);
|
||||
frame.append(image);
|
||||
image.draggable = false;
|
||||
const toolbar = document.createElement("span");
|
||||
toolbar.className = "md-image-actions";
|
||||
let closeZoom: (() => void) | undefined;
|
||||
const zoom = button("Zoom in", "zoom-in", () => { closeZoom = zoomImage(image, zoom); });
|
||||
const zoom = button(tr("Zoom in"), "zoom-in", () => { closeZoom = zoomImage(image, zoom); });
|
||||
cleanup.push(() => closeZoom?.());
|
||||
toolbar.append(zoom);
|
||||
if (actions.edit) toolbar.append(button(actions.editing ? "Hide image source" : "Edit image source", "code", actions.editing && actions.done ? actions.done : actions.edit));
|
||||
if (actions.edit) toolbar.append(button(actions.editing ? tr("Hide image source") : tr("Edit image source"), "code", actions.editing && actions.done ? actions.done : actions.edit));
|
||||
frame.append(toolbar);
|
||||
cleanup.push(() => toolbar.querySelectorAll<HTMLButtonElement>("button").forEach(button => tooltipCleanups.get(button)?.()));
|
||||
let menu: HTMLElement | undefined;
|
||||
@@ -125,19 +126,19 @@ export function imageControls(root: HTMLElement, actions: ImageActions = {}, mea
|
||||
function openMenu(x: number, y: number) {
|
||||
closeMenu(false); select();
|
||||
const items: ActionMenuItem[] = [
|
||||
{ label: "Copy image", icon: "copy", run: () => void run(() => copyImage(image)) },
|
||||
...(actions.markdown ? [{ label: "Copy Markdown", icon: "code" as const, run: () => void run(() => navigator.clipboard.writeText(actions.markdown!())) }] : []),
|
||||
...(actions.swap ? [{ label: "Swap image…", icon: "swap" as const, run: () => void run(() => actions.swap!(image)) }] : []),
|
||||
...(actions.remove ? [{ label: "Remove image", icon: "trash" as const, run: () => void run(actions.remove!) }] : []),
|
||||
{ label: tr("Copy image"), icon: "copy", run: () => void run(() => copyImage(image)) },
|
||||
...(actions.markdown ? [{ label: tr("Copy Markdown"), icon: "code" as const, run: () => void run(() => navigator.clipboard.writeText(actions.markdown!())) }] : []),
|
||||
...(actions.swap ? [{ label: tr("Swap image…"), icon: "swap" as const, run: () => void run(() => actions.swap!(image)) }] : []),
|
||||
...(actions.remove ? [{ label: tr("Remove image"), icon: "trash" as const, run: () => void run(actions.remove!) }] : []),
|
||||
{ separator: true },
|
||||
{ label: "Zoom in", icon: "zoom-in", run: () => { closeMenu(false); closeZoom = zoomImage(image, zoom); } },
|
||||
...(actions.edit ? [{ label: "Edit image source", icon: "code" as const, run: () => void run(actions.edit!) }] : []),
|
||||
...(actions.open ? [{ label: "Open in new tab", icon: "external" as const, run: () => void run(() => actions.open!(image)) }] : []),
|
||||
{ label: "Copy path", icon: "link", run: () => void run(() => navigator.clipboard.writeText(image.dataset.mdSrc || "")) },
|
||||
...(actions.reveal && !/^https?:/i.test(image.dataset.mdSrc || "") ? [{ label: "Show in Explorer", icon: "external" as const, run: () => void run(() => actions.reveal!(image)) }] : []),
|
||||
{ label: tr("Zoom in"), icon: "zoom-in", run: () => { closeMenu(false); closeZoom = zoomImage(image, zoom); } },
|
||||
...(actions.edit ? [{ label: tr("Edit image source"), icon: "code" as const, run: () => void run(actions.edit!) }] : []),
|
||||
...(actions.open ? [{ label: tr("Open in new tab"), icon: "external" as const, run: () => void run(() => actions.open!(image)) }] : []),
|
||||
{ label: tr("Copy path"), icon: "link", run: () => void run(() => navigator.clipboard.writeText(image.dataset.mdSrc || "")) },
|
||||
...(actions.reveal && !/^https?:/i.test(image.dataset.mdSrc || "") ? [{ label: tr("Show in Explorer"), icon: "external" as const, run: () => void run(() => actions.reveal!(image)) }] : []),
|
||||
];
|
||||
openingMenu = true;
|
||||
try { menu = actionMenu(x, y, items, closeMenu, "Image actions"); }
|
||||
try { menu = actionMenu(x, y, items, closeMenu, tr("Image actions")); }
|
||||
finally { openingMenu = false; }
|
||||
}
|
||||
frame.addEventListener("mousedown", event => { if (!(event.target as Element).closest("button")) { event.preventDefault(); event.stopPropagation(); select(); } });
|
||||
|
||||
Reference in New Issue
Block a user