diff --git a/README.md b/README.md
index 6afa4b7..3d58c58 100644
--- a/README.md
+++ b/README.md
@@ -157,6 +157,7 @@ The engine needs very little markup:
| `data-auto="600"` on a section | its builds reveal by themselves, one every 600 ms (500 without a number), as soon as the slide shows; `→` and `←` take over |
| `data-skip` on a section | the slide is skipped: left out of the show, the slide numbers and the print, and still there in the edit view |
| `
` inside a slide | speaker notes, for the presenter and edit views |
+| `data-public` on the stage | set by **Save public copy…** on the copy it makes: the deck opens without the edit view |
The engine sets `.current` on the slide shown and `.on` on each build it
reveals, and adds a `` with the slide number to every
@@ -197,9 +198,16 @@ it looks.
it, for the question it answers; the next key goes on with the deck.
- **Undo** or `Cmd/Ctrl+Z` takes back one change. × on a row in the list of
unsaved edits removes just that edit.
-- **Save** or `Cmd/Ctrl+S` writes the deck: to a file you choose in Chromium,
- as a download elsewhere. It overwrites what is there, so reload first if an
- agent or editor changed the file since you opened it.
+- **Save** opens a menu with two choices:
+ - **Save**, or `Cmd/Ctrl+S` straight away, writes the deck: to a file you
+ choose in Chromium, as a download elsewhere. It overwrites what is there,
+ so reload first if an agent or editor changed the file since you opened it.
+ - **Save public copy…** makes a copy to send to your audience, named
+ `…-public.html`: the deck as it is now, without the speaker notes, the
+ skipped slides, the layouts and the comments between the slides. The menu
+ says what it leaves out, then it asks where to put the copy in Chromium and
+ downloads it elsewhere. The copy has no edit view, and not the code for it
+ either; it still presents and prints.
**Suggest** leaves the deck alone and collects notes for whoever edits the file:
@@ -307,6 +315,9 @@ Or copy or symlink [`skills/deck`](skills/deck) into `~/.claude/skills/`.
read it: self-closed SVG tags, `` in tables, entities. Comments and
indentation stay, and later saves change only what you changed.
- Photos sit beside the file, so a deck with photos travels as a folder.
+- A public copy has the engine without the code of the edit view, which
+ makes the file a good deal smaller. `update` puts the whole engine back;
+ the edit view then stays off until `data-public` is removed from the stage.
## Development
diff --git a/skills/deck/assets/template.html b/skills/deck/assets/template.html
index 4e58d0d..a4a8dce 100644
--- a/skills/deck/assets/template.html
+++ b/skills/deck/assets/template.html
@@ -625,6 +625,7 @@
Start from template.html
class="build" on any element revealed one at a time with →
data-auto="500" on a section its builds reveal by themselves, one every 500 ms
data-skip on a section left out of the show, its numbers and the print; the edit view still shows it
+ data-public on the stage a public copy made in the edit view, to hand out: it has no edit view
The engine sets .current on the slide shown, .on on each build revealed, and adds a to every slide.
URL: ?print opens the print dialog once loaded; ?presenter is the presenter window; ?view is one read-only slide, used
for the presenter's panes and the edit view's thumbnails and layout previews.
@@ -638,6 +639,7 @@
Start from template.html
// ?presenter is the window that S opens, ?view is one read-only slide in an iframe; anything else is the deck
const params = new URLSearchParams(location.search);
const mode = params.has('presenter') ? 'presenter' : params.has('view') ? 'view' : 'deck';
+ const canEdit = mode === 'deck' && !document.querySelector('#stage[data-public]'); // a public copy has no edit view
const here = location.href.split(/[?#]/)[0];
const KEY = 'deck:' + location.pathname;
const EDIT_KEY = KEY + ':edit';
@@ -776,7 +778,7 @@
case 's': case 'S':
if (mode === 'deck') presenterWin = open(here + '?presenter', 'deck-presenter', 'popup,width=1280,height=800');
break;
- case 'e': case 'E': if (mode === 'deck') edit(!editing); break;
+ case 'e': case 'E': if (canEdit) edit(!editing); break;
case 'Escape':
if (!editing) return false;
if (!ed.menu.hidden) showLayouts(false);
+ else if (!ed.copyBox.hidden) showCopy(false);
else if (ed.sel) select(null);
else edit(false);
break;
@@ -906,11 +909,11 @@
box.addEventListener('mousedown', e => e.preventDefault());
helpButton.addEventListener('click', () => showHelp(help.hidden));
box.querySelector('.c-back').addEventListener('click', () => act('ArrowLeft'));
- box.querySelector('.c-edit').addEventListener('click', () => { showHelp(false); act('e'); });
+ box.querySelector('.c-edit')?.addEventListener('click', () => { showHelp(false); act('e'); });
box.querySelector('.c-fwd').addEventListener('click', () => act('ArrowRight'));
box.querySelector('.c-present').addEventListener('click', () => { showHelp(false); act('s'); });
// a click elsewhere only dismisses them: seen first, so the slide does not advance as well
@@ -1112,6 +1115,7 @@
Start from template.html
status();
}
+ // ---- the edit view: a public copy leaves out everything from here to the line that ends it, so nothing above may need it there ----
// edit view (E, deck window only): thumbnails left, the slide with its notes below, unsaved edits or suggestions right
function edit(on) {
if (!ed) buildEdit();
@@ -1119,6 +1123,7 @@
' + labelled('e-mode-edit', 'Edit', 'pencil', 'A click on the slide selects, a double-click types') +
labelled('e-mode-suggest', 'Suggest', 'bubble', 'A click on the slide suggests a change') + '
if (ed.open && !ask.contains(e.target) && !ed.askTools.contains(e.target) && closeAsk()) drawEdit();
if (ed.typing && !ed.typing.el.contains(e.target)) commitText();
if (!menu.contains(e.target) && !ed.add.contains(e.target)) showLayouts(false);
+ if (!copyBox.contains(e.target) && !ed.save.contains(e.target)) showCopy(false);
if (!notes.contains(e.target)) notes.blur();
}, true);
addEventListener('resize', () => { if (ed.open) placeAsk(); });
@@ -1352,7 +1376,7 @@
Start from template.html
});
// the buttons never take focus, so Space and the arrows keep steering the deck, and the composer keeps what is typed in it
- for (const p of [bar, rail, panel, status, menu, ed.path]) p.addEventListener('mousedown', e => { if (e.target.closest('button')) e.preventDefault(); });
+ for (const p of [bar, rail, panel, status, menu, copyBox, ed.path]) p.addEventListener('mousedown', e => { if (e.target.closest('button')) e.preventDefault(); });
ed.modes.forEach((b, n) => b.addEventListener('click', () => setSuggesting(n === 1)));
setSuggesting(suggesting);
const clicks = {
@@ -1371,7 +1395,7 @@
Start from template.html
'.e-do-skip-slide': skipSlide,
'.e-do-drop-slide': () => deleteSlide(slides[i]),
'.e-do-undo': undoChange,
- '.e-save': saveDeck,
+ '.e-save': () => showCopy(copyBox.hidden),
// the show starts on this slide as a show does, with its builds still to come; E leaves with the slide as it looks here
'.e-show': () => { edit(false); show(i); },
'.e-present': () => act('s')
@@ -1423,7 +1447,9 @@
Start from template.html
showSlide(from);
});
stage.append(layer);
- document.body.append(bar, rail, status, panel, ask, menu);
+ copyBox.querySelector('.e-save-go').addEventListener('click', () => { showCopy(false); saveDeck(); });
+ copyBox.querySelector('.e-copy-go').addEventListener('click', publicCopy);
+ document.body.append(bar, rail, status, panel, ask, menu, copyBox);
}
// the layouts New slide offers: those in the deck's , or else one plain slide
function deckLayouts() {
@@ -2296,10 +2322,11 @@
Start from template.html
notes.blur();
}
// the deck as its file says it: this document without what the engine added to it, and laid out as the template is.
- // The parser moves or drops the white space around and
- function serialize() {
+ // The parser moves or drops the white space around and . `change` alters the copy before it is written
+ function serialize(change) {
const copy = document.documentElement.cloneNode(true);
- copy.querySelectorAll('#notes, #deck-controls, #edit-bar, #edit-rail, #edit-status, #edit, #edit-ask, #edit-layer, #edit-layouts, #edit-css, .slide > .counter:last-child').forEach(n => n.remove());
+ change?.(copy);
+ copy.querySelectorAll('#notes, #deck-controls, #edit-bar, #edit-rail, #edit-status, #edit, #edit-ask, #edit-layer, #edit-layouts, #edit-copy, #edit-css, .slide > .counter:last-child').forEach(n => n.remove());
copy.querySelectorAll('.slide.current').forEach(s => s.classList.remove('current'));
copy.querySelectorAll('.build.on').forEach(b => b.classList.remove('on'));
copy.classList.remove('editing');
@@ -2309,6 +2336,56 @@
Start from template.html
return [...document.childNodes].map(n => n === document.documentElement ? html
: n.nodeType === Node.DOCUMENT_TYPE_NODE ? '' : new XMLSerializer().serializeToString(n)).join('\n') + '\n';
}
+ function download(html, name) {
+ const a = Object.assign(document.createElement('a'), { href: URL.createObjectURL(new Blob([html], { type: 'text/html' })), download: name });
+ a.click();
+ setTimeout(() => URL.revokeObjectURL(a.href), 1000);
+ }
+ const HTML = [{ description: 'HTML', accept: { 'text/html': ['.html'] } }];
+ const copyName = () => (decodeURIComponent(location.pathname).split('/').pop() || 'index.html').replace(/(\.html?)?$/i, '-public$1');
+ // under the Save button: save the deck, or a public copy, with what that leaves out said before it is made
+ function showCopy(on) {
+ ed.copyBox.hidden = !on;
+ ed.save.setAttribute('aria-expanded', on);
+ if (!on) return;
+ const n = slides.length - shown().length;
+ ed.copyBox.querySelector('.e-copy-go small').textContent = 'A copy to send to your audience, without the speaker notes, ' +
+ (n ? `the ${n} skipped slide${n > 1 ? 's' : ''}` : 'any skipped slides') + ', the comments between the slides and the edit view.';
+ const r = ed.save.getBoundingClientRect();
+ ed.copyBox.style.top = r.bottom + 4 + 'px';
+ ed.copyBox.style.right = innerWidth - r.right + 'px';
+ }
+ // A copy to hand out, under a name of its own: the deck as it is now, without the speaker notes, the skipped slides,
+ // the layouts and the comments between the slides. It is marked so that it opens without the edit view, and an
+ // engine inlined in it loses the code of that view, most of its size. It goes to a file chosen in a dialog where
+ // the browser has one, else it downloads
+ async function publicCopy() {
+ settle();
+ showCopy(false);
+ const name = copyName(), html = serialize(copy => {
+ const all = copy.querySelector('#stage'), w = document.createTreeWalker(all, NodeFilter.SHOW_COMMENT), out = [];
+ while (w.nextNode()) out.push(w.currentNode);
+ [...out, ...copy.querySelectorAll('.s-notes, .slide[data-skip], template[data-deck="layouts"]')].forEach(drop);
+ all.setAttribute('data-public', '');
+ const engine = copy.querySelector('script[data-deck="engine"]');
+ if (engine) engine.textContent = engine.textContent.replace(/\n *\/\/ -+ the edit view[\s\S]*\/\/ -+ end of the edit view[^\n]*/, '');
+ });
+ let label = 'Saved a copy';
+ try {
+ if (window.showSaveFilePicker) {
+ const out = await (await showSaveFilePicker({ suggestedName: name, types: HTML })).createWritable();
+ await out.write(html);
+ await out.close();
+ } else {
+ download(html, name);
+ label = 'Downloaded';
+ }
+ } catch (e) {
+ if (e.name === 'AbortError') return; // the file dialog was cancelled
+ label = 'Save failed';
+ }
+ saved(label);
+ }
// write the deck: to a file chosen once per visit where the browser can, else as a download
async function saveDeck() {
settle();
@@ -2316,14 +2393,12 @@
ed.file = null;
label = 'Save failed';
}
- ed.save.lastChild.textContent = label;
- setTimeout(() => { ed.save.lastChild.textContent = 'Save'; }, 2000);
+ saved(label);
+ }
+ // what a save did, on the Save button for a moment
+ function saved(label) {
+ const text = ed.save.querySelector('span');
+ text.textContent = label;
+ setTimeout(() => { text.textContent = 'Save'; }, 2000);
}
// the clipboard API, or the older execCommand where a browser refuses it
function copyText(text) {
@@ -2350,9 +2430,10 @@
Start from template.html
};
return navigator.clipboard ? navigator.clipboard.writeText(text).then(() => true, old) : Promise.resolve(old());
}
+ // ---- end of the edit view ----
// a refresh stays in the edit view; here at the end, because that view uses everything above
- if (mode === 'deck' && store.get(EDIT_KEY)) edit(true);
+ if (canEdit && store.get(EDIT_KEY)) edit(true);
})();