JavaScript animation engine
v4.1.1
Julian Garnierb5a5ff8c5187
diff --git a/examples/assets/css/styles.css b/examples/assets/css/styles.cssindex 99afce33..a17bec6e 100644--- a/examples/assets/css/styles.css+++ b/examples/assets/css/styles.css@@ -1,6 +1,8 @@:root {--black: #252423;--white: #F6F4F2;+ --white-2: #FFF;+ --grey: #b8b6b3;--red: #FF4B4B;--orange: #FF8F42;--lightorange: #FFC730;@@ -14,6 +16,8 @@--lavender: #8453E3;--purple: #C26EFF;--pink: #FB89FB;++ --input-border-radius: .25rem;}*, *:before, *:after {@@ -83,6 +87,8 @@ body {}}+/* Logs */+.log {--width: 22ch;--height: 20ch;@@ -99,10 +105,87 @@ body {white-space: pre;background-color: rgba(0, 0, 0, .5);}-.log span {- animation: reveal 2s ease-in-out forwards;-}+@keyframes reveal {from { opacity: 1; }to { opacity: .4; }-}\ No newline at end of file+}++.log span {+ animation: reveal 2s ease-in-out forwards;+}++/* Inputs */++button,+select {+ width: 100%;+ flex-shrink: .5;+ border: none;+ background-color: var(--white);+ border-radius: var(--input-border-radius);+ white-space: nowrap;+ margin: 0;+ height: 2rem;+}++button {+ padding: 0 .75rem;+}++select:disabled,+button:disabled {+ background-color: var(--grey);+}++select:not(:disabled):hover,+button:not(:disabled):hover {+ cursor: pointer;+ background-color: var(--white-2);+}++legend {+ display: flex;+ gap: .5rem;+ flex-direction: row;+ align-items: center;+ justify-content: flex-start;+ width: 100%;+ height: 2rem;+}++label {+ display: flex;+ gap: .5rem;+ flex-direction: row;+ align-items: center;+ justify-content: flex-start;+ height: 2rem;+}++fieldset {+ display: flex;+ flex-wrap: nowrap;+ flex-direction: row;+ justify-content: center;+ align-items: center;+ gap: 1px;+}++fieldset.vertical {+ flex-direction: column;+ justify-content: flex-start;+ align-items: flex-start;+}++fieldset > * {+ border-radius: 0;+}++fieldset > *:first-child {+ border-radius: var(--input-border-radius) 0 0 var(--input-border-radius);+}++fieldset > *:last-child {+ border-radius: 0 var(--input-border-radius) var(--input-border-radius) 0;+}diff --git a/examples/draggable-playground/index.html b/examples/draggable-playground/index.htmlindex 0522451c..76e22b93 100644--- a/examples/draggable-playground/index.html+++ b/examples/draggable-playground/index.html@@ -411,6 +411,8 @@left: .5em;bottom: .5em;border-radius: .75em;+ width: auto;+ height: auto;}.drawer {@@ -647,10 +649,10 @@<li class="draggable carousel-item"></li></ul></div>- <div class="carousel-buttons">+ <fieldset class="carousel-buttons"><button class="button carousel-prev">PREV</button><button class="button carousel-next">NEXT</button>- </div>+ </fieldset><p>This is the drawer content. <a href="https://animejs.com">This is a link with a <span>span</span>.</a> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis cursus nisi sit amet pulvinar. This is the drawer content. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis cursus nisi sit amet pulvinar. This is the drawer content. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis cursus nisi sit amet pulvinar. This is the drawer content. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis cursus nisi sit amet pulvinar.</p>diff --git a/examples/text/hover-effects/index.html b/examples/text/hover-effects/index.htmlindex 06cd4928..c493cdb3 100644--- a/examples/text/hover-effects/index.html+++ b/examples/text/hover-effects/index.html@@ -10,123 +10,116 @@<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:[email protected]&display=swap" rel="stylesheet"><style>-body {- display: flex;- justify-content: center;- flex-direction: column;- align-items: center;- min-height: 100svh;- font-family: "Noto Sans JP", sans-serif;- font-kerning: none;- font-variant-ligatures: none;- text-rendering: optimizeSpeed;-}+ body {+ display: flex;+ justify-content: center;+ flex-direction: column;+ align-items: center;+ min-height: 100svh;+ font-family: "Noto Sans JP", sans-serif;+ font-kerning: none;+ font-variant-ligatures: none;+ text-rendering: optimizeSpeed;+ }-main {- margin: 0 auto;- padding: 20px;- width: 100%;- max-width: 1200px;- display: grid;- grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));- gap: 20px;- justify-content: center;- container-type: inline-size;-}+ main {+ margin: 0 auto;+ padding: 20px;+ width: 100%;+ max-width: 1200px;+ display: grid;+ grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));+ gap: 20px;+ justify-content: center;+ container-type: inline-size;+ }-article {- display: flex;- flex-direction: column;- justify-content: center;- align-items: center;- min-height: 200px;- padding: 20px;- container-type: inline-size;- border-radius: 1cqw;- background: #2A2A2A;- color: #D0D0D0;- transition: background-color .25s ease-out;-}+ article {+ display: flex;+ flex-direction: column;+ justify-content: center;+ align-items: center;+ min-height: 200px;+ padding: 20px;+ container-type: inline-size;+ border-radius: 1cqw;+ background: #2A2A2A;+ color: #D0D0D0;+ transition: background-color .25s ease-out;+ }-article:has(p) {- /*justify-content: flex-start;*/- align-items: flex-start;-}+ article:has(p) {+ /*justify-content: flex-start;*/+ align-items: flex-start;+ }-article:hover {- cursor: default;- background: #303030;-}+ article:hover {+ cursor: default;+ background: #303030;+ }-article a,-article a span {- color: var(--red);-}+ article h2 {+ text-align: center;+ font-size: clamp(20px, 8cqw, 30px);+ will-change: transform;+ }-article a span {- text-decoration: underline;-}+ .word-3d {+ perspective: 1000px;+ position: relative;+ transform-style: preserve-3d;+ transform-origin: 50% 50% 1rem;+ }-article code {- font-family: monospace;- color: #B0B0B0;-}+ .face {+ position: absolute;+ left: 0;+ opacity: 0;+ }-article p {- width: 100%;- font-size: clamp(14px, 5cqw, 18px);-}+ .face-front {+ opacity: 1;+ }-article strong {- font-weight: 600;-}+ .face-bottom {+ top: 100%;+ transform-origin: 50% 0%;+ transform: rotateX(90deg);+ }-article h2 {- text-align: center;- font-size: clamp(20px, 8cqw, 30px);-}+ .face-top {+ bottom: 100%;+ transform-origin: 50% 100%;+ transform: rotateX(-90deg);+ }++ .face-back {+ top: 0;+ transform-origin: 50% 50%;+ transform: translateZ(2.5rem) rotateX(-180deg);+ }</style></head><body><main>- <article id="info">- <p>This is a collection of text effects made with Anime.js v4 and the new text splitter utility function.</p>- <p>Hover the cards to trigger the animations.</p>- <p>Learn more at <a href="https://animejs.com/documentation">animejs.com</a>.</p>+ <article id="horizontal-split">+ <h2>Horizontal split</h2></article><article id="wavy-text-effect"><h2>Waaaaavvvvy</h2></article>- <article id="slide-up">+ <article id="raining-letters"><h2>Raining letters</h2></article>- <article id="light-words">+ <article id="subtle-highlight"><h2>Subtle text highlight</h2></article><article id="words-3d-jp"><h2>3Dで単語を回転させる</h2></article>- <article id="words-slide-x">- <h2>Horizontal shift split</h2>- </article>- <article id="lines-mask">- <p>This is an example of lines masking that works by only splitting words. This allows animating per line even when the text contains multiple levels of nested elements, like <a href="https://animejs.com/">links with multiple words and nested <strong>strong & <em>em tags</em></strong></a>.</p>- </article>- <article>- <h2>Effect 5</h2>- </article>- <article>- <h2>Effect 6</h2>- </article>- <article>- <h2>Effect 7</h2>- </article>- <article>- <h2>Effect 8</h2>- </article>- <article>- <h2>Effect 9</h2>+ <article id="exploding-characters">+ <h2>Exploding characters</h2></article></main><script type="module" src="./index.js"></script>diff --git a/examples/text/hover-effects/index.js b/examples/text/hover-effects/index.jsindex 313d42d6..8c1e89fa 100644--- a/examples/text/hover-effects/index.js+++ b/examples/text/hover-effects/index.js@@ -2,219 +2,206 @@ import {animate,createScope,createSpring,- createDraggable,createTimeline,stagger,text,utils,} from '../../../lib/anime.esm.js';-// Wait until the fonts are all loaded-document.fonts.ready.then(() => {-- createScope({- root: '#wavy-text-effect',- defaults: { ease: 'inOut(3)', duration: 350 },- }).add(({ root }) => {-- const params = {- split: text.split('h2', { chars: true }),- strength: 0,- };-- const waveAnim = createTimeline().add(params.split.chars, {- y: [`-50%`, `50%`],- duration: 500,- loop: true,- alternate: true,- ease: 'inOut(2)',- autoplay: false,- modifier: v => v * params.strength,- }, stagger(50)).seek(1000);-- root.addEventListener('pointerenter', () => animate(params, {- strength: 1,- onBegin: () => waveAnim.play(),- }));-- root.addEventListener('pointerleave', () => animate(params, {- strength: 0,- onComplete: () => waveAnim.pause(),- }));-+createScope({+ root: '#horizontal-split',+ defaults: {+ ease: 'outQuad',+ duration: 500,+ }+}).add((scope) => {++ const { root, methods } = scope;++ text.split('h2', {+ chars: {+ class: 'char',+ clone: 'left',+ wrap: 'clip',+ },});- createScope({- root: '#slide-up',- }).add((self) => {-- const { root, methods } = self;-- text.split('h2', {- chars: {- class: 'char',- clone: 'top',- wrap: 'clip',- },- });+ const rotateAnim = createTimeline({+ autoplay: false,+ defaults: { ease: 'inOutQuad', duration: 400, }+ })+ .add('.char > span', { x: '100%' }, stagger(5, { use: 'data-char' }))- const ease = createSpring({ stiffness: 90, damping: 12 });+ scope.add('onEnter', () => animate(rotateAnim, { progress: 1 }));+ scope.add('onLeave', () => animate(rotateAnim, { progress: 0 }));- self.add('onEnter', e => {- createTimeline().add('.char > span', {- y: '100%',- composition: 'blend',- ease,- }, stagger(10, { use: 'data-char', from: 'random' }));- });+ root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));+ root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));- self.add('onLeave', e => {- createTimeline().add('.char > span', {- y: '0%',- composition: 'blend',- ease,- }, stagger(10, { use: 'data-char', from: 'random' }));- });-- root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));- root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));-- });+});- createScope({- root: '#light-words',- defaults: { ease: 'out(3)', duration: 350, composition: 'blend' },- }).add((self) => {+createScope({+ root: '#wavy-text-effect',+ defaults: { ease: 'inOut(3)', duration: 350 },+}).add((scope) => {++ const { root } = scope;++ const params = {+ split: text.split('h2', { chars: true }),+ strength: 0,+ };++ const waveAnim = createTimeline().add(params.split.chars, {+ y: [`-50%`, `50%`],+ duration: 500,+ loop: true,+ alternate: true,+ ease: 'inOut(2)',+ autoplay: false,+ modifier: v => v * params.strength,+ }, stagger(50)).seek(1000);++ root.addEventListener('pointerenter', () => animate(params, {+ strength: 1,+ onBegin: () => waveAnim.play(),+ }));++ root.addEventListener('pointerleave', () => animate(params, {+ strength: 0,+ onComplete: () => waveAnim.pause(),+ }));- const { root, methods } = self;+});- const { chars } = text.split('h2', { chars: true });+createScope({+ root: '#raining-letters',+}).add((scope) => {- utils.set(chars, { opacity: .25 });+ const { root, methods } = scope;- self.add('onEnter', e => {- createTimeline().add(chars, { opacity: 1 }, stagger(5));- });+ text.split('h2', {+ chars: {+ class: 'char',+ clone: 'top',+ wrap: 'clip',+ },+ });- self.add('onLeave', e => {- createTimeline().add(chars, { opacity: .25 }, stagger(5));- });+ const ease = createSpring({ stiffness: 90, damping: 11 });- root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));- root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));+ scope.add('onEnter', () => {+ createTimeline().add('.char > span', {+ y: '100%',+ composition: 'blend',+ ease,+ }, stagger(10, { use: 'data-char', from: 'random' }));+ });+ scope.add('onLeave', () => {+ createTimeline().add('.char > span', {+ y: '0%',+ composition: 'blend',+ ease,+ }, stagger(10, { use: 'data-char', from: 'random' }));});- createScope({- root: '#words-3d-jp',- defaults: {- ease: 'outQuad',- duration: 500,- }- }).add((self) => {-- const { root, methods } = self;-- text.split('h2', {- words: `<span class="word-3d" style="position: relative; transform-style: preserve-3d; transform-origin: 50% 0%">- <span style="transform-origin: 50% 0%; transform: rotateX(0deg)">{value}</span>- <span style="position: absolute; top: 100%; left: 0; transform-origin: 50% 0%; transform: rotateX(90deg)">{value}</span>- </span>`,- lines: false,- chars: false,- })-- const wordStagger = stagger(100, { use: 'data-word', start: 0 });-- const rotateAnim = createTimeline({- autoplay: false,- defaults: { ease: 'inOutQuad', duration: 400, }- })- .add('.word-3d', { rotateX: -90 }, wordStagger)- .add('.word-3d > span:first-child', { opacity: [1, .25] }, wordStagger)- .add('.word-3d > span:last-child', { opacity: [.25, 1] }, wordStagger)-- self.add('onEnter', e => {- animate(rotateAnim, { progress: 1 });- });-- self.add('onLeave', e => {- animate(rotateAnim, { progress: 0 });- });-- root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));- root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));+ root.addEventListener('pointerenter', methods.onEnter);+ root.addEventListener('pointerleave', methods.onLeave);- });+});- createScope({- root: '#words-slide-x',- defaults: {- ease: 'outQuad',- duration: 500,- }- }).add((self) => {-- const { root, methods } = self;-- text.split('h2', {- chars: {- class: 'char',- clone: 'left',- wrap: 'clip',- },- });+createScope({+ root: '#subtle-highlight',+ defaults: { ease: 'out(3)', duration: 350, composition: 'blend' },+}).add((scope) => {- const rotateAnim = createTimeline({- autoplay: false,- defaults: { ease: 'inOutQuad', duration: 400, }- })- .add('.char > span', { x: '100%' }, stagger(5, { use: 'data-char' }))+ const { root, methods } = scope;+ const { chars } = text.split('h2', { chars: true });- self.add('onEnter', e => {- animate(rotateAnim, { progress: 1 });- });+ utils.set(chars, { opacity: .25 });- self.add('onLeave', e => {- animate(rotateAnim, { progress: 0 });- });+ scope.add('onEnter', () => createTimeline().add(chars, { opacity: 1, textShadow: '0 0 30px rgba(255,255,255,.9)' }, stagger(12)));+ scope.add('onLeave', () => createTimeline().add(chars, { opacity: .25, textShadow: '0 0 0px rgba(255,255,255,0)' }, stagger(12)));- root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));- root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));+ root.addEventListener('pointerenter', methods.onEnter);+ root.addEventListener('pointerleave', methods.onLeave);++});+createScope({+ root: '#words-3d-jp',+ defaults: {+ ease: 'outQuad',+ }+}).add((scope) => {++ const { root, methods } = scope;++ text.split('h2', {+ words: `<span class="word-3d word-{i}">+ <em class="face face-top">{value}</em>+ <em class="face-front">{value}</em>+ <em class="face face-bottom">{value}</em>+ <em class="face face-back">{value}</em>+ </span>`,});- createScope({- root: '#lines-mask',- defaults: {- duration: 300,- composition: 'blend',- }- }).add((self) => {+ const wordStagger = stagger(50, { use: 'data-word', start: 0 });- const { root, methods } = self;+ const rotateAnim = createTimeline({+ autoplay: false,+ defaults: { ease: 'inOut(2)', duration: 750 }+ })+ .add('.word-3d', { rotateX: -180 }, wordStagger)+ .add('.word-3d .face-top', { opacity: [0, 0, 0] }, wordStagger)+ .add('.word-3d .face-front', { opacity: [1, 0, 0] }, wordStagger)+ .add('.word-3d .face-bottom', { opacity: [0, 1, 0] }, wordStagger)+ .add('.word-3d .face-back', { opacity: [0, 0, 1] }, wordStagger)- text.split('p', {- lines: {- class: 'line',- clone: 'top',- wrap: 'clip',- },- });+ scope.add('onEnter', () => animate(rotateAnim, { progress: 1 }));+ scope.add('onLeave', () => animate(rotateAnim, { progress: 0 }));- utils.set('.line > span:first-child', { color: '#A0A0A0' });+ root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));+ root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));- self.add('onEnter', e => {- animate('.line > span', { y: '100%', delay: stagger(50) })- });+});- self.add('onLeave', e => {- animate('.line > span', { y: 0, delay: stagger(50) })- });+createScope({+ root: '#exploding-characters',+}).add((scope) => {- root.addEventListener('pointerenter', /** @type {EventListener} */(methods.onEnter));- root.addEventListener('pointerleave', /** @type {EventListener} */(methods.onLeave));+ const { root, methods } = scope;+ const { chars } = text.split('h2', { chars: true });+ scope.add('onEnter', () => {+ createTimeline().add(chars, {+ x: {+ to: () => utils.random(-3, 3) + 'rem',+ duration: () => utils.random(150, 500),+ },+ y: () => utils.random(-5, 5) + 'rem',+ rotate: () => utils.random(-180, 180),+ duration: () => utils.random(200, 750),+ ease: 'outCirc', composition: 'blend',+ }, stagger(5, { from: 'random' }));});-});+ scope.add('onLeave', () => {+ createTimeline().add(chars, {+ x: { to: 0, delay: 75 },+ y: 0,+ duration: () => utils.random(200, 400),+ rotate: {+ to: 0,+ delay: 150,+ duration: () => utils.random(300, 400),+ },+ ease: 'inOut(2)', composition: 'blend',+ }, stagger(10, { from: 'random' }));+ });++ root.addEventListener('pointerenter', methods.onEnter);+ root.addEventListener('pointerleave', methods.onLeave);++});\ No newline at end of filediff --git a/examples/text/split-effects/index.html b/examples/text/split-effects/index.htmlindex c4226d44..cbb40d51 100644--- a/examples/text/split-effects/index.html+++ b/examples/text/split-effects/index.html@@ -24,20 +24,6 @@text-rendering: optimizeSpeed;}- .controls {- display: flex;- gap: .5rem;- flex-direction: row;- justify-content: center;- align-items: center;- }-- .button {- padding: .125rem .5rem;- border: none;- border-radius: .125rem;- }-main {display: flex;flex-direction: row;@@ -65,12 +51,12 @@Wave propagation and fluid dynamics encompass several interconnected physical phenomena that govern how water moves through oceanic systems, demonstrating the fundamental principles of energy transfer and momentum conservation. Wave "continuation" describes how energy persists through water long after the initial disturbance has passed, with individual water particles following elliptical orbital paths that decrease in amplitude with depth, creating the illusion of forward motion while actually moving in circular patterns. "Differential flow" occurs because various layers of water move at different velocities—surface currents respond to wind stress differently than deeper thermohaline circulation, and coastal waters behave distinctly from open ocean systems. A related phenomenon is "hydrodynamic lag," where water masses respond gradually to driving forces, whether from atmospheric pressure, gravitational pull, or temperature gradients. This lag affects everything from floating objects like debris and marine organisms to distinct water bodies themselves, such as upwelling zones and convergence areas. In oceanic circulation, deep water acts as the primary driver, with surface waves, spray, and foam representing secondary responses to local conditions. Water masses with different densities, such as warm surface layers and cold deep currents, or areas with varying salinity, exhibit more independent behavior than uniform water columns. Extreme manifestations of these forces create phenomena like rogue waves and storm surges, while calmer conditions require precise balance between competing forces to maintain stable patterns. Even apparently static water bodies demonstrate constant motion through molecular vibration, thermal convection, and microscopic currents that prevent true stagnation and maintain the ocean's dynamic equilibrium.</p></main>- <div class="controls">- <button class="button" id="revert">REVERT</button>- <button class="button" id="split">SPLIT & ANIMATE</button>- <button class="button" id="reorder">TIDY UP</button>- <button class="button" id="debug">SHOW DEBUG</button>- </div>+ <fieldset>+ <button id="revert">REVERT</button>+ <button id="split">SPLIT & ANIMATE</button>+ <button id="reorder">TIDY UP</button>+ <button id="debug">SHOW DEBUG</button>+ </fieldset><script type="module" src="./index.js"></script></body></html>\ No newline at end of filediff --git a/examples/text/split-playground/index.html b/examples/text/split-playground/index.htmlindex e093e27e..e922dc59 100644--- a/examples/text/split-playground/index.html+++ b/examples/text/split-playground/index.html@@ -17,10 +17,6 @@width: 100%;min-height: 100dvh;padding: 2rem;- font-family: "Noto Sans JP", sans-serif;- font-kerning: none;- font-variant-ligatures: none;- text-rendering: optimizeSpeed;}body.is-ready {@@ -28,49 +24,43 @@}aside {+ --border-radius: .75rem;justify-self: flex-end;width: 12rem;- padding: .75rem 1rem;- border-radius: .5rem;- background-color: #404040;+ border-radius: var(--border-radius);}aside li {list-style: none;- margin-bottom: .5rem;- }-- fieldset {- display: flex;- flex-direction: column;- width: 100%;+ padding: 1rem;+ background-color: #404040;+ margin-bottom: 1px;}- legend {- padding-bottom: .25rem;+ aside li:first-child {+ border-top-left-radius: var(--border-radius);+ border-top-right-radius: var(--border-radius);}- fieldset:disabled {- opacity: .5;+ aside li:last-child {+ border-bottom-left-radius: var(--border-radius);+ border-bottom-right-radius: var(--border-radius);}- fieldset input,- fieldset select {+ .field input,+ .field select {width: 50%;- margin: 0px;- border-radius: .25rem;- }-- fieldset input {- padding-left: .25rem;- padding-right: .25rem;}.field {width: 100%;display: flex;justify-content: space-between;- padding-bottom: .25rem;+ align-items: center;+ }++ fieldset:disabled .field {+ opacity: .5;}main {@@ -85,7 +75,11 @@width: 100%;max-width: 800px;justify-self: center;+ font-family: "Noto Sans JP", sans-serif;font-weight: 400;+ font-kerning: none;+ font-variant-ligatures: none;+ text-rendering: optimizeSpeed;}article h1 {@@ -95,29 +89,17 @@line-height: 1.4;}- article span:has(~ span h1) h1 {- margin-bottom: 0;- }-article p {font-size: 1.25rem;line-height: 1.5;margin-bottom: 1rem;}- article span:has(~ span p) p {- margin-bottom: 0;- }-article ul {padding-left: 1rem;margin-bottom: 1rem;}- article span:has(~ span ul) ul {- margin-bottom: 0;- }-article a {color: var(--red);text-decoration: underline;@@ -127,17 +109,27 @@text-decoration: underline;}- .nested { color: rgba(200, 100, 200, 1) }- .nested .nested { color: rgba(200, 100, 200, .8) }- .nested .nested .nested { color: rgba(200, 100, 200, .6) }- .nested .nested .nested .nested { color: rgba(200, 100, 200, .4) }- .nested .nested .nested .nested .nested { color: rgba(200, 100, 200, .2) }+ .nested { color: rgba(200, 100, 100, 1) }+ .nested .nested { color: rgba(200, 100, 100, .8) }+ .nested .nested .nested { color: rgba(200, 100, 100, .6) }+ .nested .nested .nested .nested { color: rgba(200, 100, 100, .4) }+ .nested .nested .nested .nested .nested { color: rgba(200, 100, 100, .2) }code {color: rgba(200, 200, 200, 1);font-family: monospace;}+ article span:has(~ span h1) h1,+ article span:has(~ span p) p,+ article span:has(~ span ul) ul {+ margin-bottom: 0;+ }++ article span:has(p) + span:has(ul) {+ margin-top: 1rem;+ }+</style></head><body class="is-debug">@@ -159,160 +151,158 @@<li>And is 100% responsive.</li></ul><p>- Check out the full documenation and learn more at <a href="https://animejs.com/documentation">animejs.com/documentation</a>.+ Check out the full documenation and learn more at <a href="https://animejs.com/documentation/text/split">animejs.com/documentation</a>.</p></article></main><aside id="parameters"><form id="splitForm"><ul>- <li>- <legend>- <input type="checkbox" id="lines" name="lines">- <label for="lines">lines</label>- </legend>- <fieldset id="lines-options">- <div class="field">- <label for="lines-wrap">wrap:</label>- <select id="lines-wrap" name="lines-wrap">- <option value="false">false</option>- <option value="clip">clip</option>- <option value="visible">visible</option>- </select>- </div>- <div class="field">- <label for="lines-clone">clone:</label>- <select id="lines-clone" name="lines-clone">- <option value="false">false</option>- <option value="top">top</option>- <option value="right">right</option>- <option value="bottom">bottom</option>- <option value="left">left</option>- </select>- </div>- <div class="field">- <label for="lines-animate">animate:</label>- <select id="lines-animate" name="lines-animate">- <option value="false">false</option>- <option value="250">200ms</option>- <option value="500">500ms</option>- <option value="750">750ms</option>- <option value="1000">1000ms</option>- </select>- </div>- <div class="field">- <label for="lines-stagger">stagger:</label>- <select id="lines-stagger" name="lines-stagger">- <option value="10">10</option>- <option value="50">50</option>- <option value="200">200</option>- <option value="random">random</option>- </select>- </div>- </fieldset>- </li>- <li>- <input type="checkbox" id="words" name="words" checked>- <label for="words">words</label>- <fieldset id="words-options">- <div class="field">- <label for="words-wrap">wrap:</label>- <select id="words-wrap" name="words-wrap">- <option value="false">false</option>- <option selected value="clip">clip</option>- <option value="visible">visible</option>- </select>- </div>- <div class="field">- <label for="words-clone">clone:</label>- <select id="words-clone" name="words-clone">- <option value="false">false</option>- <option value="top">top</option>- <option value="right">right</option>- <option selected value="bottom">bottom</option>- <option value="left">left</option>- </select>- </div>- <div class="field">- <label for="words-animate">animate:</label>- <select id="words-animate" name="words-animate">- <option value="false">false</option>- <option value="250">250ms</option>- <option value="500">500ms</option>- <option value="750">750ms</option>- <option value="1000">1000ms</option>- </select>- </div>- <div class="field">- <label for="words-stagger">stagger:</label>- <select id="words-stagger" name="words-stagger">- <option value="10">10</option>- <option value="50">50</option>- <option value="200">200</option>- <option value="random">random</option>- </select>- </div>- </fieldset>- </li>- <li>- <input type="checkbox" id="chars" name="chars">- <label for="chars">chars</label>- <fieldset id="chars-options">- <div class="field">- <label for="chars-wrap">wrap:</label>- <select id="chars-wrap" name="chars-wrap">- <option value="false">false</option>- <option value="clip">clip</option>- <option value="visible">visible</option>- </select>- </div>- <div class="field">- <label for="chars-clone">clone:</label>- <select id="chars-clone" name="chars-clone">- <option value="false">false</option>- <option value="top">top</option>- <option value="right">right</option>- <option value="bottom">bottom</option>- <option value="left">left</option>- </select>- </div>- <div class="field">- <label for="chars-animate">animate:</label>- <select id="chars-animate" name="chars-animate">- <option value="false">false</option>- <option value="250">250ms</option>- <option value="500">500ms</option>- <option value="750">750ms</option>- <option value="1000">1000ms</option>- </select>- </div>- <div class="field">- <label for="chars-stagger">stagger:</label>- <select id="chars-stagger" name="chars-stagger">- <option value="10">10</option>- <option value="50">50</option>- <option value="200">200</option>- <option value="random">random</option>- </select>- </div>- </fieldset>- </li>- <li>- <input type="checkbox" id="includeSpaces" name="includeSpaces">- <label for="includeSpaces">includeSpaces</label>- </li>- <li>- <input type="checkbox" id="accessible" name="accessible" checked>- <label for="accessible">accessible</label>- </li>- <li>- <input type="checkbox" id="debug" name="debug" checked>- <label for="debug">debug</label>- </li>+ <li>+ <fieldset class="vertical" id="lines-options">+ <legend>+ <label for="lines"><input type="checkbox" id="lines" name="lines"> lines</label>+ </legend>+ <div class="field">+ <label for="lines-wrap">wrap</label>+ <select id="lines-wrap" name="lines-wrap">+ <option value="false">false</option>+ <option value="clip">clip</option>+ <option value="visible">visible</option>+ </select>+ </div>+ <div class="field">+ <label for="lines-clone">clone</label>+ <select id="lines-clone" name="lines-clone">+ <option value="false">false</option>+ <option value="top">top</option>+ <option value="right">right</option>+ <option value="bottom">bottom</option>+ <option value="left">left</option>+ </select>+ </div>+ <div class="field">+ <label for="lines-animate">animate</label>+ <select id="lines-animate" name="lines-animate">+ <option value="false">false</option>+ <option value="250">200ms</option>+ <option value="500">500ms</option>+ <option value="750">750ms</option>+ <option value="1000">1000ms</option>+ </select>+ </div>+ <div class="field">+ <label for="lines-stagger">stagger</label>+ <select id="lines-stagger" name="lines-stagger">+ <option value="10">10</option>+ <option value="50">50</option>+ <option value="200">200</option>+ <option value="random">random</option>+ </select>+ </div>+ </fieldset>+ </li>+ <li>+ <fieldset class="vertical" id="words-options">+ <legend>+ <label for="words"><input type="checkbox" id="words" name="words" checked> words</label>+ </legend>+ <div class="field">+ <label for="words-wrap">wrap</label>+ <select id="words-wrap" name="words-wrap">+ <option value="false">false</option>+ <option value="clip">clip</option>+ <option value="visible">visible</option>+ </select>+ </div>+ <div class="field">+ <label for="words-clone">clone</label>+ <select id="words-clone" name="words-clone">+ <option value="false">false</option>+ <option value="top">top</option>+ <option value="right">right</option>+ <option value="bottom">bottom</option>+ <option value="left">left</option>+ </select>+ </div>+ <div class="field">+ <label for="words-animate">animate</label>+ <select id="words-animate" name="words-animate">+ <option value="false">false</option>+ <option value="250">250ms</option>+ <option value="500">500ms</option>+ <option value="750">750ms</option>+ <option value="1000">1000ms</option>+ </select>+ </div>+ <div class="field">+ <label for="words-stagger">stagger</label>+ <select id="words-stagger" name="words-stagger">+ <option value="10">10</option>+ <option value="50">50</option>+ <option value="200">200</option>+ <option value="random">random</option>+ </select>+ </div>+ </fieldset>+ </li>+ <li>+ <fieldset class="vertical" id="chars-options">+ <legend>+ <label for="chars"><input type="checkbox" id="chars" name="chars"> chars</label>+ </legend>+ <div class="field">+ <label for="chars-wrap">wrap</label>+ <select id="chars-wrap" name="chars-wrap">+ <option value="false">false</option>+ <option value="clip">clip</option>+ <option value="visible">visible</option>+ </select>+ </div>+ <div class="field">+ <label for="chars-clone">clone</label>+ <select id="chars-clone" name="chars-clone">+ <option value="false">false</option>+ <option value="top">top</option>+ <option value="right">right</option>+ <option value="bottom">bottom</option>+ <option value="left">left</option>+ </select>+ </div>+ <div class="field">+ <label for="chars-animate">animate</label>+ <select id="chars-animate" name="chars-animate">+ <option value="false">false</option>+ <option value="250">250ms</option>+ <option value="500">500ms</option>+ <option value="750">750ms</option>+ <option value="1000">1000ms</option>+ </select>+ </div>+ <div class="field">+ <label for="chars-stagger">stagger</label>+ <select id="chars-stagger" name="chars-stagger">+ <option value="10">10</option>+ <option value="50">50</option>+ <option value="200">200</option>+ <option value="random">random</option>+ </select>+ </div>+ </fieldset>+ </li>+ <li>+ <label for="includeSpaces"><input type="checkbox" id="includeSpaces" name="includeSpaces"> includeSpaces</label>+ <label for="accessible"><input type="checkbox" id="accessible" name="accessible" checked> accessible</label>+ <label for="debug"><input type="checkbox" id="debug" name="debug" checked> debug</label>+ </li>+ <li>+ <fieldset>+ <button type="button" class="button" id="revert" name="revert">Revert</button>+ <button type="button" class="button" id="split" name="revert">Split</button>+ </fieldset>+ </li></ul></form>- <button id="revert" name="revert">Revert</button>- <button id="split" name="revert">Split</button></aside><script type="module" src="./index.js"></script></body>diff --git a/src/text.js b/src/text.jsindex dcef1a21..c7c0b046 100644--- a/src/text.js+++ b/src/text.js@@ -379,6 +379,10 @@ export class TextSplitter {const fontsReady = doc.fonts.status !== 'loading';const canSplitLines = lineTemplate && fontsReady;this.ready = !lineTemplate || fontsReady;+ if (canSplitLines || clearCache) {+ // No need to revert effects animations here since it's already taken care by the refreshable+ this.effectsCleanups.forEach(cleanup => isFnc(cleanup) && cleanup(this));+ }if (!isCached) {if (clearCache) {$el.innerHTML = this.html;@@ -387,10 +391,7 @@ export class TextSplitter {this.splitNode($el);this.cache = $el.innerHTML;}- // Always reset the html when splitting by linesif (canSplitLines) {- // No need to revert effects animations here since it's already taken care by the refreshable- this.effectsCleanups.forEach(cleanup => isFnc(cleanup) && cleanup(this));if (isCached) $el.innerHTML = this.cache;this.lines.length = 0;if (wordTemplate) this.words = getAllTopLevelElements($el, wordType);@@ -444,9 +445,6 @@ export class TextSplitter {}words.length = 0;}- if (canSplitLines || clearCache) {- this.effects.forEach((effect, i) => this.effectsCleanups[i] = effect(this));- }if (this.accessible && (canSplitLines || !isCached)) {const $accessible = doc.createElement('span');// Make the accessible element visually-hidden (https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html)@@ -459,6 +457,9 @@ export class TextSplitter {this.chars.forEach(setAriaHidden);}this.width = /** @type {HTMLElement} */($el).offsetWidth;+ if (canSplitLines || clearCache) {+ this.effects.forEach((effect, i) => this.effectsCleanups[i] = effect(this));+ }return this;}diff --git a/tests/suites/text.test.js b/tests/suites/text.test.jsindex 34dddb24..ab5dc117 100644--- a/tests/suites/text.test.js+++ b/tests/suites/text.test.js@@ -356,9 +356,13 @@ suite('Text', () => {const split = text.split($p, {lines: true,})- .addEffect(() => {+ .addEffect(self => {calls++;+ self.words.forEach(($word, i) => $word.setAttribute('data-test', i));return () => {+ self.words.forEach(($word, i) => {+ expect(+$word.setAttribute('data-test')).to.equal(i);+ });cleanups++;}});@@ -396,4 +400,32 @@ suite('Text', () => {}, 10);});+ test('refresh() should properly call cleanups function', resolve => {+ document.fonts.ready.then(() => {+ let calls = 0;+ let cleanups = 0;+ const [ $p ] = utils.$('#split-text p');+ const split = text.split($p, {+ lines: true,+ })+ .addEffect(self => {+ calls++;+ self.words.forEach(($word, i) => $word.setAttribute('data-test', i));+ return () => {+ self.words.forEach(($word, i) => {+ expect(+$word.getAttribute('data-test')).to.equal(i);+ });+ cleanups++;+ }+ });+ setTimeout(() => {+ expect(calls).to.equal(1);+ expect(cleanups).to.equal(0);+ split.refresh();+ split.revert();+ resolve();+ }, 10);+ });+ });+});