Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/Icon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const icons = {
slideAdd: 'M3 5h14v10H3zM20 15v6M17 18h6',
slideDelete: 'M3 5h18v12H3zM9 8l6 6M15 8l-6 6',
textBox: 'M3 5h18v14H3zM8 9h8M12 9v7',
// A table, and a slide on its stand: the group buttons of a narrow strip.
table: 'M3 4h18v16H3zM3 10h18M3 15h18M9 4v16',
slide: 'M3 4h18v12H3zM12 16v4M8 20h8',
// A sheet tab with a plus, a sheet tab crossed out.
sheetAdd: 'M3 4h12v9H3zM3 8h12M9 4v9M18 14v7M14.5 17.5h7',
sheetDelete: 'M3 4h18v12H3zM3 8h18M9 4v12M10 10.5l4 4M14 10.5l-4 4',
Expand Down
188 changes: 117 additions & 71 deletions src/components/viewer/Chrome.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
marking tools for a pdf - which is hidden until the pen is pressed. Under
that, the tabs of a workbook's sheets.

The strip is the apps' one: the two colours, bold, italic and underline, then
the groups - strikethrough, size and alignment; the table; the slide - with a
thin line before each. Where the row does not fit it never wraps: it closes
into the phone's strip, where a group button swaps the row for that group.

The demo puts all of it inside its own frame, which is hidden until something
renders; `/tryit` uses the bar as the page's only bar, where the mark on the
left has to stay put and everything about the document has to come and go. So
Expand All @@ -22,23 +27,23 @@ const {
class: className = 'border-b border-outline-variant bg-surface-container px-4 py-2.5',
} = Astro.props;

const swatch =
'relative flex h-7 w-7 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-surface';
const chevron =
'relative -ml-0.5 flex h-7 w-4 shrink-0 items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-surface';
const divider = 'mx-1.5 h-5 w-px shrink-0 bg-outline-variant';
const round =
'flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-outline transition-colors hover:bg-surface disabled:opacity-40 disabled:hover:bg-transparent';
const tool =
'flex h-7 min-w-7 shrink-0 items-center justify-center rounded-full border border-transparent px-1.5 text-sm leading-none transition-colors hover:bg-surface aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-on-primary disabled:opacity-40';

/* Point sizes a document commonly uses; the select shows the selection's own
size where it is one of these and nothing where it is not. */
/* Point sizes a document commonly uses, as plain numbers; the select shows the
selection's own size where it is one of these and a dash where it is not.
The stepper goes to the next of them. */
const sizes = [8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 48];

/* The alignments in the names `odr.editing.format({align})` takes. */
const aligns = [
{ align: 'left', label: 'Align left', icon: 'alignLeft' },
{ align: 'center', label: 'Centre', icon: 'alignCenter' },
{ align: 'center', label: 'Center', icon: 'alignCenter' },
{ align: 'right', label: 'Align right', icon: 'alignRight' },
{ align: 'justify', label: 'Justify', icon: 'alignJustify' },
] as const;
Expand All @@ -49,8 +54,8 @@ const structure = [
{ call: 'insertRows', where: 'above', label: 'Insert rows above', icon: 'rowAbove' },
{ call: 'insertRows', where: 'below', label: 'Insert rows below', icon: 'rowBelow' },
{ call: 'deleteRows', where: '', label: 'Delete rows', icon: 'rowDelete' },
{ call: 'insertColumns', where: 'left', label: 'Insert columns to the left', icon: 'columnLeft' },
{ call: 'insertColumns', where: 'right', label: 'Insert columns to the right', icon: 'columnRight' },
{ call: 'insertColumns', where: 'left', label: 'Insert columns left', icon: 'columnLeft' },
{ call: 'insertColumns', where: 'right', label: 'Insert columns right', icon: 'columnRight' },
{ call: 'deleteColumns', where: '', label: 'Delete columns', icon: 'columnDelete' },
] as const;

Expand Down Expand Up @@ -127,6 +132,15 @@ const marks = [
<span data-viewer-pen-edit class="flex"><Icon name="pencil" class="h-4 w-4" /></span>
<span data-viewer-pen-mark hidden class="flex"><Icon name="highlighter" class="h-4 w-4" /></span>
</button>
<!-- With Save, while the pen is down. -->
<span data-viewer-history hidden class="flex shrink-0 items-center gap-0.5">
<button data-viewer-undo type="button" disabled title="Undo (Ctrl+Z)" aria-label="Undo" class={round}>
<Icon name="undo" class="h-4 w-4" />
</button>
<button data-viewer-redo type="button" disabled title="Redo (Ctrl+Y)" aria-label="Redo" class={round}>
<Icon name="redo" class="h-4 w-4" />
</button>
</span>
<button
data-viewer-save
hidden
Expand Down Expand Up @@ -218,72 +232,92 @@ const marks = [
</div>

<!-- What the pen opens. Every group is hidden until the document says it
applies; the hint says what to do with the frame below. -->
applies. `data-viewer-in` names the group a tool belongs to where the
strip is narrow; `data-viewer-wide` is only there where it is wide. The
pen's tooltip says what to do with the frame below. -->
<div
data-viewer-tools
hidden
class="flex shrink-0 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-outline-variant bg-surface-container px-3 py-1.5 sm:px-4"
class="flex shrink-0 items-center overflow-x-auto border-b border-outline-variant bg-surface-container px-3 py-1.5 sm:px-4"
>
<div data-viewer-format hidden class="flex items-center gap-0.5">
<button data-viewer-style="bold" type="button" title="Bold (Ctrl+B)" aria-pressed="false" class={tool}
<button data-viewer-back hidden type="button" title="Back to all tools" aria-label="Back to all tools" class={tool}>
<Icon name="chevron" class="h-4 w-4 rotate-90" />
</button>

<div data-viewer-format hidden class="flex shrink-0 items-center gap-0.5">
<!-- The highlight, or a sheet's fill in its place, then the text's
colour: each the colour of its bar on a press, and the arrow beside it
opens the palette. The input is the browser's own picker, which the
palette's Other color... opens. -->
<span data-viewer-in="quick" class="flex items-center">
<button data-viewer-highlight type="button" title="Highlight" aria-label="Highlight" aria-pressed="false" class={tool}>
<span aria-hidden="true" class="flex flex-col items-center">
<Icon name="highlighter" class="h-3.5 w-3.5" />
<span data-viewer-highlight-bar class="mt-0.5 h-1 w-4 rounded-sm"></span>
</span>
</button>
<button data-viewer-fill type="button" title="Fill" aria-label="Fill" aria-pressed="false" class={tool}>
<span aria-hidden="true" class="flex flex-col items-center">
<Icon name="fill" class="h-3.5 w-3.5" />
<span data-viewer-fill-bar class="mt-0.5 h-1 w-4 rounded-sm"></span>
</span>
</button>
<button data-viewer-palette-open="highlight" type="button" title="Highlight colors" aria-label="Highlight colors" aria-haspopup="dialog" class={chevron}>
<Icon name="chevron" class="h-3 w-3" />
</button>
<button data-viewer-palette-open="fill" type="button" title="Fill colors" aria-label="Fill colors" aria-haspopup="dialog" class={chevron}>
<Icon name="chevron" class="h-3 w-3" />
</button>
<input data-viewer-highlight-color type="color" value="#fff59d" tabindex="-1" aria-hidden="true" class="sr-only" />
<input data-viewer-fill-color type="color" value="#c8e6c9" tabindex="-1" aria-hidden="true" class="sr-only" />
</span>
<span data-viewer-in="quick" class="flex items-center">
<button data-viewer-text-color type="button" title="Text color" aria-label="Text color" class={tool}>
<span aria-hidden="true" class="flex flex-col items-center text-sm font-semibold leading-none">
A<span data-viewer-color-bar class="mt-0.5 h-1 w-4 rounded-sm ring-1 ring-outline-variant"></span>
</span>
</button>
<button data-viewer-palette-open="color" type="button" title="Text colors" aria-label="Text colors" aria-haspopup="dialog" class={chevron}>
<Icon name="chevron" class="h-3 w-3" />
</button>
<input data-viewer-color type="color" value="#191c1e" tabindex="-1" aria-hidden="true" class="sr-only" />
</span>
<button data-viewer-in="quick" data-viewer-style="bold" type="button" title="Bold (Ctrl+B)" aria-pressed="false" class={tool}
><span class="font-bold">B</span></button
>
<button data-viewer-style="italic" type="button" title="Italic (Ctrl+I)" aria-pressed="false" class={tool}
<button data-viewer-in="quick" data-viewer-style="italic" type="button" title="Italic (Ctrl+I)" aria-pressed="false" class={tool}
><span class="italic">I</span></button
>
<button data-viewer-style="underline" type="button" title="Underline (Ctrl+U)" aria-pressed="false" class={tool}
<button data-viewer-in="quick" data-viewer-style="underline" type="button" title="Underline (Ctrl+U)" aria-pressed="false" class={tool}
><span class="underline">U</span></button
>
<button data-viewer-style="strikethrough" type="button" title="Strikethrough" aria-pressed="false" class={tool}
><span class="line-through">S</span></button
>
<!-- The colour of the text: an A over a bar in that colour, with the
picker laid invisibly on top, so a click anywhere on it opens it. -->
<label title="Text colour" class={swatch}>
<span class="sr-only">Text colour</span>
<span aria-hidden="true" class="flex flex-col items-center text-sm font-semibold leading-none">
A<span data-viewer-color-bar class="mt-0.5 h-1 w-4 rounded-sm ring-1 ring-outline-variant"></span>
</span>
<input data-viewer-color type="color" value="#191c1e" class="absolute inset-0 h-full w-full cursor-pointer opacity-0" />
</label>
<!-- The highlight and its own colour, as a split button: the button turns
it on and off, and the arrow next to it picks the colour it uses. -->
<button data-viewer-highlight type="button" title="Highlight" aria-pressed="false" class={tool}>
<span aria-hidden="true" class="flex flex-col items-center">
<Icon name="highlighter" class="h-3.5 w-3.5" />
<span data-viewer-highlight-bar class="mt-0.5 h-1 w-4 rounded-sm"></span>
</span>
</button>
<label data-viewer-highlight-pick title="Highlight colour" class={chevron}>
<span class="sr-only">Highlight colour</span>
<Icon name="chevron" class="h-3 w-3" />
<input data-viewer-highlight-color type="color" value="#fff59d" class="absolute inset-0 h-full w-full cursor-pointer opacity-0" />
</label>
<!-- The fill of a cell, as the same split button: only a sheet has one,
where a text document has the highlight. -->
<button data-viewer-fill type="button" title="Cell fill" aria-pressed="false" class={tool}>
<span aria-hidden="true" class="flex flex-col items-center">
<Icon name="fill" class="h-3.5 w-3.5" />
<span data-viewer-fill-bar class="mt-0.5 h-1 w-4 rounded-sm"></span>
</span>
<button data-viewer-group="text" hidden type="button" title="More text tools" aria-label="More text tools" class={`${tool} relative`}>
<span aria-hidden="true">Aa</span>
<!-- the corner mark of a group button -->
<span aria-hidden="true" class="absolute bottom-1 right-1 h-1.5 w-1.5 bg-current opacity-60 [clip-path:polygon(100%_0,100%_100%,0_100%)]"></span>
</button>
<label data-viewer-fill-pick title="Cell fill colour" class={chevron}>
<span class="sr-only">Cell fill colour</span>
<Icon name="chevron" class="h-3 w-3" />
<input data-viewer-fill-color type="color" value="#c8e6c9" class="absolute inset-0 h-full w-full cursor-pointer opacity-0" />
</label>
<select
data-viewer-size
title="Font size"
class="ml-1 h-6 cursor-pointer rounded-md border border-transparent bg-transparent py-0 pl-1.5 pr-1 text-xs text-on-surface-variant transition-colors hover:bg-surface"

<span data-viewer-wide class={divider}></span>
<button data-viewer-in="text" data-viewer-style="strikethrough" type="button" title="Strikethrough" aria-pressed="false" class={tool}
><span class="line-through">S</span></button
>
<option value="">Size</option>
{sizes.map((s) => <option value={`${s}pt`}>{s} pt</option>)}
</select>
<span data-viewer-in="text" class="ml-1 flex items-center">
<button data-viewer-wide data-viewer-size-step="-1" disabled type="button" title="Smaller text" aria-label="Smaller text" class={tool}>&minus;</button>
<select
data-viewer-size
title="Text size"
aria-label="Text size"
class="h-6 cursor-pointer rounded-md border border-transparent bg-transparent py-0 pl-1.5 pr-1 text-xs tabular-nums text-on-surface-variant transition-colors hover:bg-surface"
>
<option value="">&ndash;</option>
{sizes.map((s) => <option value={`${s}pt`} aria-label={`${s} pt`}>{s}</option>)}
</select>
<button data-viewer-wide data-viewer-size-step="1" disabled type="button" title="Larger text" aria-label="Larger text" class={tool}>+</button>
</span>
<!-- The alignment of the paragraphs or the cells the selection reaches.
A cell takes no justify, so the viewer hides that one for a sheet,
and a second press sets a cell back to the alignment of its value. -->
<span class="ml-1 flex items-center gap-0.5">
<span data-viewer-in="text" class="ml-1 flex items-center gap-0.5">
{
aligns.map((a) => (
<button data-viewer-align={a.align} type="button" title={a.label} aria-label={a.label} aria-pressed="false" class={tool}>
Expand All @@ -294,10 +328,18 @@ const marks = [
</span>
</div>

<button data-viewer-group="table" hidden type="button" title="Table" aria-label="Table" class={tool}>
<Icon name="table" class="h-4 w-4" />
</button>
<button data-viewer-group="slide" hidden type="button" title="Slide" aria-label="Slide" class={tool}>
<Icon name="slide" class="h-4 w-4" />
</button>

<!-- A sheet only: rows and columns, as many as the selection spans. Each
button is one undo step, and a header click selects a whole row or
column for them. -->
<div data-viewer-structure hidden class="flex items-center gap-0.5">
<div data-viewer-structure data-viewer-in="table" hidden class="flex shrink-0 items-center gap-0.5">
<span data-viewer-wide class={divider}></span>
{
structure.map((s) => (
<button
Expand All @@ -318,7 +360,8 @@ const marks = [
slide the caret is in; a text box on that slide; and that slide
removed or moved. A drawing has only the text box. The layouts are the
document's own, so the viewer fills the select from the page. -->
<div data-viewer-slides hidden class="flex items-center gap-0.5">
<div data-viewer-slides data-viewer-in="slide" hidden class="flex shrink-0 items-center gap-0.5">
<span data-viewer-wide class={divider}></span>
<span data-viewer-slide-only class="flex items-center gap-0.5">
<button data-viewer-slide-call="insertSlide" type="button" title="New slide after this one" aria-label="New slide after this one" class={tool}>
<Icon name="slideAdd" class="h-4 w-4" />
Expand Down Expand Up @@ -349,7 +392,8 @@ const marks = [

<!-- A workbook: the sheets themselves. Each button acts on the sheet shown
and is one undo step. -->
<div data-viewer-sheet-edit hidden class="flex items-center gap-0.5">
<div data-viewer-sheet-edit data-viewer-in="table" hidden class="flex shrink-0 items-center gap-0.5">
<span data-viewer-wide class={divider}></span>
<button data-viewer-sheet-call="insertSheet" type="button" title="New sheet after this one" aria-label="New sheet after this one" class={tool}>
<Icon name="sheetAdd" class="h-4 w-4" />
</button>
Expand All @@ -367,7 +411,7 @@ const marks = [
<!-- Every marking tool is the split button the document's highlight is:
the tool with a bar in its colour, and the arrow that picks it. The
viewer paints each bar from its input. -->
<div data-viewer-mark hidden class="flex flex-wrap items-center gap-x-1 gap-y-0.5">
<div data-viewer-mark hidden class="flex shrink-0 items-center gap-x-1">
{
marks.map((m) => (
<span class="flex items-center">
Expand All @@ -387,16 +431,18 @@ const marks = [
}
</div>

<div class="flex items-center gap-0.5">
<button data-viewer-undo type="button" disabled title="Undo (Ctrl+Z)" aria-label="Undo" class={tool}>
<Icon name="undo" class="h-4 w-4" />
</button>
<button data-viewer-redo type="button" disabled title="Redo (Ctrl+Y)" aria-label="Redo" class={tool}>
<Icon name="redo" class="h-4 w-4" />
</button>
</div>
</div>

<p data-viewer-tools-hint class="min-w-0 flex-1 truncate text-xs text-on-surface-variant"></p>
<!-- The palette of the colour tools, under the arrow that opened it: the
colours picked last, the colours on the page, the apps' forty, and the
browser's picker. The viewer fills it. -->
<div
data-viewer-palette
hidden
role="dialog"
aria-label="Colors"
class="fixed z-50 w-[17.5rem] rounded-xl border border-outline-variant bg-surface p-3 shadow-lg"
>
</div>

<!-- The sheets of a workbook, one shown at a time: the page turns to a tab
Expand Down
10 changes: 10 additions & 0 deletions src/scripts/frame-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
window.parent.postMessage(message, '*');
}

// A press in the document closes what the page has open over it, such as the palette.
document.addEventListener('pointerdown', function () { post({ type: 'press' }); }, true);

/*
Escape leaves whatever mode the pen turned on, unless something in the
frame - a sheet's cell editor, say - took the key for itself first.
Expand Down Expand Up @@ -247,6 +250,13 @@
case 'sheet':
sheetCall(String(m.call), Number(m.step) || 0);
break;
case 'getColors':
// The colours the document states, for the palette.
post({
type: 'colors',
colors: editing && typeof editing.documentColors === 'function' ? editing.documentColors() : [],
});
break;
case 'getSheets':
if (editing) post({ type: 'sheets', names: editing.sheetNames() });
break;
Expand Down
Loading