MCPcopy
hub / github.com/formkit/auto-animate / remove

Function remove

src/index.ts:662–740  ·  view source on GitHub ↗

* Animates the removal of an element. * @param el - Element to remove

(el: Element)

Source from the content-addressed store, hash-verified

660 * @param el - Element to remove
661 */
662function remove(el: Element) {
663 if (!siblings.has(el) || !coords.has(el)) return
664
665 const [prev, next] = siblings.get(el)!
666 Object.defineProperty(el, DEL, { value: true, configurable: true })
667 const finalX = window.scrollX
668 const finalY = window.scrollY
669
670 if (
671 next &&
672 (next.parentNode as any) &&
673 (next.parentNode as any) instanceof Element
674 ) {
675 ;(next.parentNode as Element).insertBefore(el, next)
676 } else if (prev && (prev.parentNode as any)) {
677 ;(prev.parentNode as Element).appendChild(el)
678 } else {
679 getTarget(el)?.appendChild(el)
680 }
681 if (!isEnabled(el)) return cleanUp(el)
682
683 const [top, left, width, height] = deletePosition(el)
684 const optionsOrPlugin = getOptions(el)
685 const oldCoords = coords.get(el)!
686 if (finalX !== scrollX || finalY !== scrollY) {
687 adjustScroll(el, finalX, finalY, optionsOrPlugin)
688 }
689
690 let animation: Animation
691 let styleReset: Partial<CSSStyleDeclaration> = {
692 position: "absolute",
693 top: `${top}px`,
694 left: `${left}px`,
695 width: `${width}px`,
696 height: `${height}px`,
697 margin: "0",
698 pointerEvents: "none",
699 transformOrigin: "center",
700 zIndex: "100",
701 }
702
703 if (!isPlugin(optionsOrPlugin)) {
704 Object.assign((el as HTMLElement).style, styleReset)
705 animation = (el as HTMLElement).animate(
706 [
707 {
708 transform: "scale(1)",
709 opacity: 1,
710 },
711 {
712 transform: "scale(.98)",
713 opacity: 0,
714 },
715 ],
716 {
717 duration: (optionsOrPlugin as AutoAnimateOptions).duration,
718 easing: "ease-out",
719 },

Callers 1

animateFunction · 0.85

Calls 8

getTargetFunction · 0.85
isEnabledFunction · 0.85
cleanUpFunction · 0.85
deletePositionFunction · 0.85
getOptionsFunction · 0.85
adjustScrollFunction · 0.85
isPluginFunction · 0.85
getPluginTupleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…