Skip to content

Instantly share code, notes, and snippets.

@Vac1911
Created May 5, 2021 16:59
Show Gist options
  • Save Vac1911/0d26b268ca38651cd53562a6f4bd618f to your computer and use it in GitHub Desktop.
Save Vac1911/0d26b268ca38651cd53562a6f4bd618f to your computer and use it in GitHub Desktop.
const i=new WeakMap;class t{constructor(t,s){this.startPaused=!1,this.disabled=!1,this.flips=new Set,this.pendingComplete=!1,this.host=t,this.flipOptions=s.flipOptions||{},this.startPaused=!!s.startPaused,this.disabled=!!s.disabled,this.onComplete=s.onComplete,i.set(this.host,this)}async add(i){var t,s;this.flips.add(i),this.startPaused&&(null===(t=i.animation)||void 0===t||t.pause()),this.pendingComplete=!0,await i.finished,this.pendingComplete&&!this.isAnimating&&(this.pendingComplete=!1,null===(s=this.onComplete)||void 0===s||s.call(this))}remove(i){this.flips.delete(i)}pause(){this.flips.forEach((i=>{var t;return null===(t=i.animation)||void 0===t?void 0:t.pause()}))}play(){this.flips.forEach((i=>{var t;return null===(t=i.animation)||void 0===t?void 0:t.play()}))}cancel(){this.flips.forEach((i=>{var t;return null===(t=i.animation)||void 0===t?void 0:t.cancel()})),this.flips.clear()}finish(){this.flips.forEach((i=>{var t;return null===(t=i.animation)||void 0===t?void 0:t.finish()})),this.flips.clear()}togglePlay(){this.isPlaying?this.pause():this.play()}get isAnimating(){return this.flips.size>0}get isPlaying(){return Array.from(this.flips).some((i=>{var t;return"running"===(null===(t=i.animation)||void 0===t?void 0:t.playState)}))}async finished(){await Promise.all(Array.from(this.flips).map((i=>i.finished)))}}export{t as FlipController,i as flipControllers};
//# sourceMappingURL=flip-controller.js.map
@Vac1911
Copy link
Author

Vac1911 commented May 5, 2021

Put this file into your node_modules/@lit-labs/motion folder. Make sure this file is named flip-controller.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment