176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: one shared helper (pageCopyText) builds the copied prompt, for the demo pages and the home page
matinb8f123ec4895
diff --git a/assets/js/demo-page.js b/assets/js/demo-page.jsindex cccd88c4..4a2dcddd 100644--- a/assets/js/demo-page.js+++ b/assets/js/demo-page.js@@ -1,6 +1,6 @@/* Animation Handbook — shared behaviour for the guided-steps demo pages.- * Fills in "Your settings", Copy prompt, the README's "What it is" and "Similar- * animations", plays the demo on arrival, replays it when a setting changes, runs+ * Fills in "Your settings", Copy prompt (its text built by pageCopyText, which the home page uses too), the README's+ * "What it is" and "Similar animations", plays the demo on arrival, replays it when a setting changes, runs* Pause and CSS slow motion on loop pages, presses Show me on do-it pages (not on arrival* when the visitor has already acted in the stage) and tells the page when the visitor* takes over ("hb:input"), and follows reduced motion (Loop and Slow motion greyed out,@@ -91,6 +91,12 @@.join(', ');}+ // What Copy prompt copies: the prompt, then a blank line and "Settings from the demo: …" when the page has settings.+ function promptWithSettings(prompt, items) {+ var line = settingsLine(items);+ return prompt + (line ? '\n\nSettings from the demo: ' + line + '.' : '');+ }+// The prompt as HTML with each [part to fill in] highlighted.function markFill(text) {return escapeHtml(text).replace(/\[[^\]\n]+\]/g, function (part) {@@ -173,6 +179,17 @@});}+ // What Copy prompt copies on a page, with its settings as they are now. The home page runs it on a page it has+ // fetched and parsed, where every setting is at its default.+ function pageCopyText(doc, win) {+ var page = doc.querySelector('.hb-page');+ var promptEl = page && page.querySelector('.hb-prompt');+ if (!promptEl) return '';+ var tryStep = page.querySelector('.hb-try');+ var items = tryStep ? readSettings(doc, tryStep, win).filter(function (s) { return s.label && s.value; }) : [];+ return promptWithSettings(text(promptEl), items);+ }+function boot(doc, win) {var page = doc.querySelector('.hb-page');var promptEl = page && page.querySelector('.hb-prompt');@@ -199,10 +216,7 @@if (!tryStep) return [];return readSettings(doc, tryStep, win).filter(function (s) { return s.label && s.value; });}- function copyText() {- var line = settingsLine(settings());- return promptText + (line ? '\n\nSettings from the demo: ' + line + '.' : '');- }+ function copyText() { return pageCopyText(doc, win); }function replay() { if (replayCtl) replayCtl.click(); }// The prompt: highlight the part to fill in; on phones show five lines until "Show the full prompt".@@ -498,7 +512,8 @@return {escapeHtml: escapeHtml, plain: plain, isSafeHref: isSafeHref, inline: inline, sections: sections,- paragraphs: paragraphs, seeAlso: seeAlso, settingsLine: settingsLine, markFill: markFill, shorten: shorten,+ paragraphs: paragraphs, seeAlso: seeAlso, settingsLine: settingsLine, promptWithSettings: promptWithSettings,+ pageCopyText: pageCopyText, markFill: markFill, shorten: shorten,quoteText: quoteText, motionNote: motionNote, readSettings: readSettings, boot: boot};});diff --git a/tests/demo-page.test.js b/tests/demo-page.test.jsindex f016fb79..b568fc7a 100644--- a/tests/demo-page.test.js+++ b/tests/demo-page.test.js@@ -225,3 +225,26 @@ test('a scroll page with an empty sentence of its own gets the usual note, and oassert.equal(standInPage('do', true, { 'data-hb-motion-note': 'The layers stay still while the box scrolls' }).player.children.length, 0);assert.equal(standInPage('scroll', false, { 'data-hb-motion-note': 'The layers stay still while the box scrolls' }).player.children.length, 0);});++test('promptWithSettings adds the settings line only when a setting is complete', () => {+ assert.equal(DP.promptWithSettings('Add it.', [{ label: 'Speed', value: 'Normal' }, { label: 'Size', value: 'Big' }]),+ 'Add it.\n\nSettings from the demo: Speed: Normal, Size: Big.');+ assert.equal(DP.promptWithSettings('Add it.', []), 'Add it.');+ assert.equal(DP.promptWithSettings('Add it.', [{ label: 'Speed', value: '' }]), 'Add it.');+});++test('pageCopyText reads the prompt and the Try it settings of a page', () => {+ // A stand-in page: a prompt and a Try it step holding one group of choice buttons, "Speed", with "Normal" pressed.+ const pressed = { getAttribute: () => null, textContent: ' Normal ' };+ const seg = { hidden: false, parentElement: null, hasAttribute: () => false, closest: () => null, matches: () => false,+ getAttribute: name => (name === 'aria-labelledby' ? 'speed-lbl' : null), querySelector: () => pressed };+ const tryStep = { querySelectorAll: () => [seg] };+ const prompt = { textContent: 'Add a fade to [the card].' };+ const page = { querySelector: s => ({ '.hb-prompt': prompt, '.hb-try': tryStep })[s] || null };+ const doc = { querySelector: s => (s === '.hb-page' ? page : null), getElementById: id => (id === 'speed-lbl' ? { textContent: 'Speed' } : null) };+ const win = { getComputedStyle: () => ({ display: '' }) };+ assert.equal(DP.pageCopyText(doc, win), 'Add a fade to [the card].\n\nSettings from the demo: Speed: Normal.');+ const noSettings = { querySelector: s => (s === '.hb-prompt' ? prompt : null) };+ assert.equal(DP.pageCopyText({ querySelector: s => (s === '.hb-page' ? noSettings : null) }, win), 'Add a fade to [the card].');+ assert.equal(DP.pageCopyText({ querySelector: () => null }, win), '');+});