Files
piik/src/client/ui/native-window-caption.html
T

82 lines
4.2 KiB
HTML

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
<title>Piik</title>
<style>
__PIIK_PALETTE__
__PIIK_MODAL_BACKDROP__
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--wall); color: var(--ink); font: 12px system-ui; display: flex; align-items: center; user-select: none; }
body[data-standalone] { app-region: drag; }
body[data-panel] { background: var(--paper); }
.title { display: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 16px 8px; font-weight: 600; }
body[data-standalone] .title { display: block; flex: 1; }
/* The integrated caption already sits above the workspace's dialog backdrop. */
html[data-modal-material] body:not([data-standalone]) { background: transparent; }
html[data-modal-material] body[data-standalone]::before { content: ""; position: fixed; inset: 0; pointer-events: none; }
.controls { position: relative; display: flex; flex: none; gap: 3px; padding: 0 7px; app-region: no-drag; }
html[data-modal-material="image"] .controls { color: var(--primary-ink); }
button { app-region: no-drag; width: 38px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; }
button[data-action="share"] { width: auto; padding-inline: 12px; }
button[hidden] { display: none; }
button:hover { background: var(--control-hover); }
button:active { background: var(--control-selected); color: var(--control-selected-ink); }
button:focus-visible { outline: 2px solid var(--action); outline-offset: -2px; }
button:last-child:hover { background: var(--danger); color: var(--primary-ink); }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
</style>
<span class="title"></span><div class="controls"></div>
<script>
const controls = __PIIK_WINDOW_CONTROLS__;
let language = 'en';
let maximized = false;
if (window.piikCaptionStandalone) document.body.dataset.standalone = '';
const actions = ['minimize', 'maximize', 'close'];
if (!window.piikCaptionStandalone) actions.unshift('bookmarks');
for (const action of actions) {
const button = document.createElement('button');
button.dataset.action = action;
button.onclick = () => window.ipc.postMessage(action);
document.querySelector('.controls').append(button);
}
const share = document.createElement('button');
share.dataset.action = 'share';
share.hidden = true;
share.onclick = () => window.ipc.postMessage('share');
document.querySelector('.controls').prepend(share);
window.sharePicker = enabled => { share.hidden = !enabled; };
function render() {
document.documentElement.lang = language;
for (const button of document.querySelectorAll('button')) {
const name = button.dataset.action === 'maximize' && maximized ? 'restore' : button.dataset.action;
button.title = controls.labels[language][name === 'close' && window.piikCaptionStandalone ? 'closeWindow' : name];
button.setAttribute('aria-label', button.title);
if (name === 'share') { button.textContent = button.title; continue; }
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('viewBox', '0 0 24 24');
svg.setAttribute('aria-hidden', 'true');
for (const geometry of controls.icons[name]) {
const path = document.createElementNS(svg.namespaceURI, 'path');
path.setAttribute('d', geometry);
svg.append(path);
}
button.replaceChildren(svg);
}
}
window.updateAppearance = (theme, lang, material) => {
if (material) document.documentElement.dataset.modalMaterial = material;
else delete document.documentElement.dataset.modalMaterial;
document.documentElement.dataset.theme = theme;
language = lang;
render();
};
window.updateMaximized = value => { maximized = value; render(); };
window.usePanelSurface = () => { document.body.dataset.panel = ''; };
window.updateTitle = value => { document.querySelector('.title').textContent = value; };
render();
window.ipc.postMessage('ready');
</script>
</html>