diff --git a/docs/modules/playground.mjs b/docs/modules/playground.mjs index 0237e7013..a630f661c 100644 --- a/docs/modules/playground.mjs +++ b/docs/modules/playground.mjs @@ -21,6 +21,9 @@ const playground = ( const containerEl = document.querySelector(container); const items = [...containerEl.querySelectorAll(item)]; const targetEl = document.querySelector(target); + const animationClasses = items.map( + (item) => `animate__${item.getAttribute('data-animation')}`, + ); setEndListener(targetEl, target.replace('.', '')); @@ -31,6 +34,9 @@ const playground = ( clearAll(items); const animation = `animate__${el.parentElement.getAttribute('data-animation')}`; + targetEl.classList.remove(...animationClasses); + // Flush removal so selecting the same animation starts a new run. + void targetEl.offsetWidth; targetEl.classList.add('animate__animated', animation); document.documentElement.classList.add('isPlaying'); document.documentElement.classList.remove('animationList-active'); diff --git a/tests/playground-restart.js b/tests/playground-restart.js new file mode 100644 index 000000000..8a38d2d34 --- /dev/null +++ b/tests/playground-restart.js @@ -0,0 +1,65 @@ +// Run with Node after installing @playwright/test and its browsers. +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const {chromium, firefox, webkit} = require('@playwright/test'); +const compileAnimationList = require('../docsSource/compileAnimationList'); +const css = fs.readFileSync(path.join(__dirname, '../animate.css'), 'utf8'); +const playground = fs + .readFileSync(path.join(__dirname, '../docs/modules/playground.mjs'), 'utf8') + .replace('export default playground;', 'playground();'); + +(async () => { + for (const engine of [chromium, firefox, webkit]) { + const browser = await engine.launch(); + try { + const page = await browser.newPage({reducedMotion: 'no-preference'}); + await page.setContent(` +