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: add the shared demo-page script's README and settings helpers
matin2dbe887e2cad
diff --git a/assets/js/handbook.js b/assets/js/handbook.jsnew file mode 100644index 00000000..c3cd392c--- /dev/null+++ b/assets/js/handbook.js@@ -0,0 +1,96 @@+/* Animation Handbook — shared behaviour for the demo pages.+ * These helpers turn a demo's README.md into the "Read more" section and build+ * the settings line for the copied prompt. They are exported for tests/handbook.test.js. */+(function (root, factory) {+ var api = factory();+ if (typeof module === 'object' && module.exports) module.exports = api;+ else root.Handbook = api;+})(typeof self !== 'undefined' ? self : this, function () {+ 'use strict';++ function escapeHtml(s) {+ return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');+ }++ // Text with Markdown code and bold markers removed, safe to insert as HTML.+ function plain(s) {+ return escapeHtml(String(s).replace(/`/g, '').replace(/\*\*/g, ''));+ }++ // Inline Markdown from README prose. Inline code becomes plain text: the site shows no code.+ function inline(md) {+ return escapeHtml(md)+ .replace(/`([^`]+)`/g, '$1')+ .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, '<a href="$2">$1</a>')+ .replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')+ .replace(/\*([^*\n]+)\*/g, '<em>$1</em>');+ }++ // A README split into { "What it is": "...", ... } by its "## " headings.+ function sections(md) {+ var out = {}, current = null, buf = [];+ String(md).replace(/\r\n?/g, '\n').split('\n').forEach(function (line) {+ var m = /^##\s+(.+?)\s*$/.exec(line);+ if (m) {+ if (current) out[current] = buf.join('\n').trim();+ current = m[1];+ buf = [];+ } else if (current) {+ buf.push(line);+ }+ });+ if (current) out[current] = buf.join('\n').trim();+ return out;+ }++ function paragraphs(text) {+ return String(text || '').split(/\n\s*\n/)+ .map(function (p) { return p.trim(); })+ .filter(Boolean)+ .map(function (p) { return '<p>' + inline(p.replace(/\s*\n\s*/g, ' ')) + '</p>'; })+ .join('');+ }++ function bullets(text) {+ return String(text || '').split('\n')+ .filter(function (l) { return /^\s*[-*]\s+/.test(l); })+ .map(function (l) { return inline(l.replace(/^\s*[-*]\s+/, '')); });+ }++ // "Duration (`--dur`)" becomes "Duration": parentheticals that hold code are dropped.+ function cleanName(s) {+ return plain(String(s).replace(/\s*\(`[^`]*`[^)]*\)/g, ''));+ }++ // The Key parameters table as [{ name, value, effect }], without its header and divider rows.+ function table(text) {+ var rows = String(text || '').split('\n')+ .filter(function (l) { return /^\s*\|/.test(l); })+ .map(function (l) {+ return l.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(function (c) { return c.trim(); });+ });+ return rows.slice(1)+ .filter(function (r) { return !r.every(function (c) { return /^:?-{2,}:?$/.test(c); }); })+ .map(function (r) { return { name: cleanName(r[0] || ''), value: plain(r[1] || ''), effect: inline(r[2] || '') }; });+ }++ // "- [Name](../slug/) — description" lines as [{ name, href, desc }].+ function seeAlso(text) {+ return String(text || '').split('\n').map(function (l) {+ var m = /^\s*[-*]\s+\[([^\]]+)\]\(([^)\s]+)\)\s*(?:[—–-]\s*(.*))?$/.exec(l);+ return m ? { name: plain(m[1]), href: m[2], desc: m[3] ? inline(m[3]) : '' } : null;+ }).filter(Boolean);+ }++ function settingsLine(items) {+ return (items || [])+ .filter(function (i) { return i && i.label && i.value; })+ .map(function (i) { return i.label + ' ' + i.value; })+ .join(', ');+ }++ return {+ escapeHtml: escapeHtml, plain: plain, inline: inline, sections: sections, paragraphs: paragraphs,+ bullets: bullets, cleanName: cleanName, table: table, seeAlso: seeAlso, settingsLine: settingsLine+ };+});diff --git a/tests/handbook.test.js b/tests/handbook.test.jsnew file mode 100644index 00000000..e7c31271--- /dev/null+++ b/tests/handbook.test.js@@ -0,0 +1,68 @@+// Unit tests for the pure helpers in assets/js/handbook.js.+// Run from the repo root: node --test "tests/*.test.js"+const test = require('node:test');+const assert = require('node:assert/strict');+const HB = require('../assets/js/handbook.js');++test('escapeHtml escapes markup characters', () => {+ assert.equal(HB.escapeHtml('<a href="x">&</a>'), '<a href="x">&</a>');+});++test('plain drops code and bold markers and escapes', () => {+ assert.equal(HB.plain('`ease-out` **fast** <b>'), 'ease-out fast <b>');+});++test('inline shows code as plain text and renders links, bold and italics', () => {+ assert.equal(HB.inline('Use `opacity` on **one** *hero* [card](../scale-in/)'),+ 'Use opacity on <strong>one</strong> <em>hero</em> <a href="../scale-in/">card</a>');+ assert.equal(HB.inline('a < b'), 'a < b');+});++test('sections splits a README by its ## headings', () => {+ const md = '# Title\r\n\r\n## What it is\r\nLine one\r\nline two\r\n\r\n## When to use it\r\n- A\r\n- B\r\n';+ assert.deepEqual(HB.sections(md), { 'What it is': 'Line one\nline two', 'When to use it': '- A\n- B' });+});++test('sections keeps ### lines inside the section they belong to', () => {+ assert.deepEqual(HB.sections('## A\n### not a section\nx'), { A: '### not a section\nx' });+});++test('paragraphs joins wrapped lines and splits on blank lines', () => {+ assert.equal(HB.paragraphs('One\ntwo.\n\nThree `x`.'), '<p>One two.</p><p>Three x.</p>');+ assert.equal(HB.paragraphs(undefined), '');+});++test('bullets returns the list items as inline HTML', () => {+ assert.deepEqual(HB.bullets('- Hero **copy**\nnot a bullet\n- Toasts'), ['Hero <strong>copy</strong>', 'Toasts']);+});++test('cleanName drops parentheticals that hold code', () => {+ assert.equal(HB.cleanName('Duration (`--dur`)'), 'Duration');+ assert.equal(HB.cleanName('Perspective (`--persp`, on parent)'), 'Perspective');+ assert.equal(HB.cleanName('Two curtains (split)'), 'Two curtains (split)');+});++test('table reads Key parameters rows and skips the header and divider', () => {+ const md = '| Parameter | Default | Effect |\n|-----------|---------|--------|\n' ++ '| Duration (`--dur`) | 600ms | Under 150ms **barely** registers |\n| Easing | `ease-out` | Settles gently |';+ assert.deepEqual(HB.table(md), [+ { name: 'Duration', value: '600ms', effect: 'Under 150ms <strong>barely</strong> registers' },+ { name: 'Easing', value: 'ease-out', effect: 'Settles gently' }+ ]);+ assert.deepEqual(HB.table(''), []);+});++test('seeAlso reads name, link and description', () => {+ const md = '- [Scale In](../scale-in/) — the same entrance without the overshoot\n- [Blur In](../blur-in/)\nText';+ assert.deepEqual(HB.seeAlso(md), [+ { name: 'Scale In', href: '../scale-in/', desc: 'the same entrance without the overshoot' },+ { name: 'Blur In', href: '../blur-in/', desc: '' }+ ]);+});++test('settingsLine joins label and value pairs and skips empty ones', () => {+ assert.equal(HB.settingsLine([+ { label: 'Duration', value: '600ms' }, { label: 'Easing', value: 'Ease out' }, { label: 'Mode', value: '' }+ ]), 'Duration 600ms, Easing Ease out');+ assert.equal(HB.settingsLine([]), '');+});