vendor: 10,031 bytes, lines 1-235
1import { r as reactExports, j as jsxRuntimeExports } from "./vendor-react-Bay9Y7Lb.js"; 2import { i as isHTMLElement, g as getFeatureDefinitions, c as setFeatureDefinitions, d as isMotionValue, e as isControllingVariants, f as isVariantLabel, h as isForcedMotionValue, j as buildHTMLStyles, k as buildSVGAttrs, n as isSVGTag, o as resolveMotionValue, p as isVariantNode, q as isAnimationControls, t as resolveVariantFromProps, u as scrapeMotionValuesFromProps, v as scrapeMotionValuesFromProps$1, w as optimizedAppearDataAttribute, S as SVGVisualElement, H as HTMLVisualElement, F as Feature, x as createAnimationState, y as resolveVariant, z as isPrimaryPointer, A as addDomEvent, B as frameData, C as frame, D as pipe, E as cancelFrame, G as secondsToMilliseconds, I as millisecondsToSeconds, J as mixNumber, K as calcLength, L as progress, M as clamp, N as createBox, O as eachAxis, P as measurePageBox, Q as convertBoxToBoundingBox, R as convertBoundingBoxToBox, T as addValueToWillChange, U as animateMotionValue, V as setDragLock, W as resize, X as percent, Y as isElementTextInput, Z as noop, _ as microtask, $ as globalProjectionState, a0 as HTMLProjectionNode, a1 as hover, a2 as press } from "./vendor-dVNaLJx_.js"; 3const LayoutGroupContext = reactExports.createContext({}); 4function useConstant(init) { 5 const ref = reactExports.useRef(null); 6 if (ref.current === null) { 7 ref.current = init(); 8 } 9 return ref.current; 10} 11const isBrowser = typeof window !== "undefined"; 12const useIsomorphicLayoutEffect = isBrowser ? reactExports.useLayoutEffect : reactExports.useEffect; 13const PresenceContext = /* @__PURE__ */ reactExports.createContext(null); 14const MotionConfigContext = reactExports.createContext({ 15 transformPagePoint: (p) => p, 16 isStatic: false, 17 reducedMotion: "never" 18}); 19function setRef(ref, value) { 20 if (typeof ref === "function") { 21 return ref(value); 22 } else if (ref !== null && ref !== void 0) { 23 ref.current = value; 24 } 25} 26function composeRefs(...refs) { 27 return (node) => { 28 let hasCleanup = false; 29 const cleanups = refs.map((ref) => { 30 const cleanup = setRef(ref, node); 31 if (!hasCleanup && typeof cleanup === "function") { 32 hasCleanup = true; 33 } 34 return cleanup; 35 }); 36 if (hasCleanup) { 37 return () => { 38 for (let i = 0; i < cleanups.length; i++) { 39 const cleanup = cleanups[i]; 40 if (typeof cleanup === "function") { 41 cleanup(); 42 } else { 43 setRef(refs[i], null); 44 } 45 } 46 }; 47 } 48 }; 49} 50function useComposedRefs(...refs) { 51 return reactExports.useCallback(composeRefs(...refs), refs); 52} 53class PopChildMeasure extends reactExports.Component { 54 getSnapshotBeforeUpdate(prevProps) { 55 const element = this.props.childRef.current; 56 if (isHTMLElement(element) && prevProps.isPresent && !this.props.isPresent && this.props.pop !== false) { 57 const parent = element.offsetParent; 58 const parentWidth = isHTMLElement(parent) ? parent.offsetWidth || 0 : 0; 59 const parentHeight = isHTMLElement(parent) ? parent.offsetHeight || 0 : 0; 60 const computedStyle = getComputedStyle(element); 61 const size = this.props.sizeRef.current; 62 size.height = parseFloat(computedStyle.height); 63 size.width = parseFloat(computedStyle.width); 64 size.top = element.offsetTop; 65 size.left = element.offsetLeft; 66 size.right = parentWidth - size.width - size.left; 67 size.bottom = parentHeight - size.height - size.top; 68 } 69 return null; 70 } 71 /** 72 * Required with getSnapshotBeforeUpdate to stop React complaining. 73 */ 74 componentDidUpdate() { 75 } 76 render() { 77 return this.props.children; 78 } 79} 80function PopChild({ children, isPresent, anchorX, anchorY, root, pop }) { 81 var _a; 82 const id2 = reactExports.useId(); 83 const ref = reactExports.useRef(null); 84 const size = reactExports.useRef({ 85 width: 0, 86 height: 0, 87 top: 0, 88 left: 0, 89 right: 0, 90 bottom: 0 91 }); 92 const { nonce } = reactExports.useContext(MotionConfigContext); 93 const childRef = ((_a = children.props) == null ? void 0 : _a.ref) ?? (children == null ? void 0 : children.ref); 94 const composedRef = useComposedRefs(ref, childRef); 95 reactExports.useInsertionEffect(() => { 96 const { width, height, top, left, right, bottom } = size.current; 97 if (isPresent || pop === false || !ref.current || !width || !height) 98 return; 99 const x = anchorX === "left" ? `left: ${left}` : `right: ${right}`; 100 const y = anchorY === "bottom" ? `bottom: ${bottom}` : `top: ${top}`; 101 ref.current.dataset.motionPopId = id2; 102 const style = document.createElement("style"); 103 if (nonce) 104 style.nonce = nonce; 105 const parent = root ?? document.head; 106 parent.appendChild(style); 107 if (style.sheet) { 108 style.sheet.insertRule(` 109 [data-motion-pop-id="${id2}"] { 110 position: absolute !important; 111 width: ${width}px !important; 112 height: ${height}px !important; 113 ${x}px !important; 114 ${y}px !important; 115 } 116 `); 117 } 118 return () => { 119 var _a2; 120 (_a2 = ref.current) == null ? void 0 : _a2.removeAttribute("data-motion-pop-id"); 121 if (parent.contains(style)) { 122 parent.removeChild(style); 123 } 124 }; 125 }, [isPresent]); 126 return jsxRuntimeExports.jsx(PopChildMeasure, { isPresent, childRef: ref, sizeRef: size, pop, children: pop === false ? children : reactExports.cloneElement(children, { ref: composedRef }) }); 127} 128const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, anchorY, root }) => { 129 const presenceChildren = useConstant(newChildrenMap); 130 const id2 = reactExports.useId(); 131 let isReusedContext = true; 132 let context = reactExports.useMemo(() => { 133 isReusedContext = false; 134 return { 135 id: id2, 136 initial, 137 isPresent, 138 custom, 139 onExitComplete: (childId) => { 140 presenceChildren.set(childId, true); 141 for (const isComplete of presenceChildren.values()) { 142 if (!isComplete) 143 return; 144 } 145 onExitComplete && onExitComplete(); 146 }, 147 register: (childId) => { 148 presenceChildren.set(childId, false); 149 return () => presenceChildren.delete(childId); 150 } 151 }; 152 }, [isPresent, presenceChildren, onExitComplete]); 153 if (presenceAffectsLayout && isReusedContext) { 154 context = { ...context }; 155 } 156 reactExports.useMemo(() => { 157 presenceChildren.forEach((_, key) => presenceChildren.set(key, false)); 158 }, [isPresent]); 159 reactExports.useEffect(() => { 160 !isPresent && !presenceChildren.size && onExitComplete && onExitComplete(); 161 }, [isPresent]); 162 children = jsxRuntimeExports.jsx(PopChild, { pop: mode === "popLayout", isPresent, anchorX, anchorY, root, children }); 163 return jsxRuntimeExports.jsx(PresenceContext.Provider, { value: context, children }); 164}; 165function newChildrenMap() { 166 return /* @__PURE__ */ new Map(); 167} 168function usePresence(subscribe = true) { 169 const context = reactExports.useContext(PresenceContext); 170 if (context === null) 171 return [true, null]; 172 const { isPresent, onExitComplete, register } = context; 173 const id2 = reactExports.useId(); 174 reactExports.useEffect(() => { 175 if (subscribe) { 176 return register(id2); 177 } 178 }, [subscribe]); 179 const safeToRemove = reactExports.useCallback(() => subscribe && onExitComplete && onExitComplete(id2), [id2, onExitComplete, subscribe]); 180 return !isPresent && onExitComplete ? [false, safeToRemove] : [true]; 181} 182const getChildKey = (child) => child.key || ""; 183function onlyElements(children) { 184 const filtered = []; 185 reactExports.Children.forEach(children, (child) => { 186 if (reactExports.isValidElement(child)) 187 filtered.push(child); 188 }); 189 return filtered; 190} 191const AnimatePresence = ({ children, custom, initial = true, onExitComplete, presenceAffectsLayout = true, mode = "sync", propagate = false, anchorX = "left", anchorY = "top", root }) => { 192 const [isParentPresent, safeToRemove] = usePresence(propagate); 193 const presentChildren = reactExports.useMemo(() => onlyElements(children), [children]); 194 const presentKeys = propagate && !isParentPresent ? [] : presentChildren.map(getChildKey); 195 const isInitialRender = reactExports.useRef(true); 196 const pendingPresentChildren = reactExports.useRef(presentChildren); 197 const exitComplete = useConstant(() => /* @__PURE__ */ new Map()); 198 const exitingComponents = reactExports.useRef(/* @__PURE__ */ new Set()); 199 const [diffedChildren, setDiffedChildren] = reactExports.useState(presentChildren); 200 const [renderedChildren, setRenderedChildren] = reactExports.useState(presentChildren); 201 useIsomorphicLayoutEffect(() => { 202 isInitialRender.current = false; 203 pendingPresentChildren.current = presentChildren; 204 for (let i = 0; i < renderedChildren.length; i++) { 205 const key = getChildKey(renderedChildren[i]); 206 if (!presentKeys.includes(key)) { 207 if (exitComplete.get(key) !== true) { 208 exitComplete.set(key, false); 209 } 210 } else { 211 exitComplete.delete(key); 212 exitingComponents.current.delete(key); 213 } 214 } 215 }, [renderedChildren, presentKeys.length, presentKeys.join("-")]); 216 const exitingChildren = []; 217 if (presentChildren !== diffedChildren) { 218 let nextChildren = [...presentChildren]; 219 for (let i = 0; i < renderedChildren.length; i++) { 220 const child = renderedChildren[i]; 221 const key = getChildKey(child); 222 if (!presentKeys.includes(key)) { 223 nextChildren.splice(i, 0, child); 224 exitingChildren.push(child); 225 } 226 } 227 if (mode === "wait" && exitingChildren.length) { 228 nextChildren = exitingChildren; 229 } 230 setRenderedChildren(onlyElements(nextChildren)); 231 setDiffedChildren(presentChildren); 232 return null; 233 } 234 const { forceRender } = reactExports.useContext(LayoutGroupContext); 235 return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: renderedChildren.map((child) => {
236 const key = getChildKey(child); 237 const isPresent = propagate && !isParentPresent ? false : presentChildren === renderedChildren || presentKeys.includes(key); 238 const onExit = () => { 239 if (exitingComponents.current.has(key)) { 240 return; 241 } 242 if (exitComplete.has(key)) { 243 exitingComponents.current.add(key); 244 exitComplete.set(key, true); 245 } else { 246 return; 247 } 248 let isEveryExitComplete = true; 249 exitComplete.forEach((isExitComplete) => { 250 if (!isExitComplete) 251 isEveryExitComplete = false; 252 }); 253 if (isEveryExitComplete) { 254 forceRender == null ? void 0 : forceRender(); 255 setRenderedChildren(pendingPresentChildren.current); 256 propagate && (safeToRemove == null ? void 0 : safeToRemove()); 257 onExitComplete && onExitComplete(); 258 } 259 }; 260 return jsxRuntimeExports.jsx(PresenceChild, { isPresent, initial: !isInitialRender.current || initial ? void 0 : false, custom, presenceAffectsLayout, mode, root, onExitComplete: isPresent ? void 0 : onExit, anchorX, anchorY, children: child }, key); 261 }) }); 262}; 263const LazyContext = reactExports.createContext({ strict: false }); 264const featureProps = { 265 animation: [ 266 "animate", 267 "variants", 268 "whileHover", 269 "whileTap", 270 "exit", 271 "whileInView", 272 "whileFocus", 273 "whileDrag" 274 ], 275 exit: ["exit"], 276 drag: ["drag", "dragControls"], 277 focus: ["whileFocus"], 278 hover: ["whileHover", "onHoverStart", "onHoverEnd"], 279 tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"], 280 pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"], 281 inView: ["whileInView", "onViewportEnter", "onViewportLeave"], 282 layout: ["layout", "layoutId"] 283}; 284let isInitialized = false; 285function initFeatureDefinitions() { 286 if (isInitialized) 287 return; 288 const initialFeatureDefinitions = {}; 289 for (const key in featureProps) { 290 initialFeatureDefinitions[key] = { 291 isEnabled: (props) => featureProps[key].some((name) => !!props[name]) 292 }; 293 } 294 setFeatureDefinitions(initialFeatureDefinitions); 295 isInitialized = true; 296} 297function getInitializedFeatureDefinitions() { 298 initFeatureDefinitions(); 299 return getFeatureDefinitions(); 300} 301function loadFeatures(features) { 302 const featureDefinitions = getInitializedFeatureDefinitions(); 303 for (const key in features) { 304 featureDefinitions[key] = { 305 ...featureDefinitions[key], 306 ...features[key] 307 }; 308 } 309 setFeatureDefinitions(featureDefinitions); 310} 311const validMotionProps = /* @__PURE__ */ new Set([ 312 "animate", 313 "exit", 314 "variants", 315 "initial", 316 "style", 317 "values", 318 "variants", 319 "transition", 320 "transformTemplate", 321 "custom", 322 "inherit", 323 "onBeforeLayoutMeasure", 324 "onAnimationStart", 325 "onAnimationComplete", 326 "onUpdate", 327 "onDragStart", 328 "onDrag", 329 "onDragEnd", 330 "onMeasureDragConstraints", 331 "onDirectionLock", 332 "onDragTransitionEnd", 333 "_dragX", 334 "_dragY", 335 "onHoverStart", 336 "onHoverEnd", 337 "onViewportEnter", 338 "onViewportLeave", 339 "globalTapTarget", 340 "propagate", 341 "ignoreStrict", 342 "viewport" 343]); 344function isValidMotionProp(key) { 345 return key.startsWith("while") || key.startsWith("drag") && key !== "draggable" || key.startsWith("layout") || key.startsWith("onTap") || key.startsWith("onPan") || key.startsWith("onLayout") || validMotionProps.has(key); 346} 347let shouldForward = (key) => !isValidMotionProp(key); 348function loadExternalIsValidProp(isValidProp) { 349 if (typeof isValidProp !== "function") 350 return; 351 shouldForward = (key) => key.startsWith("on") ? !isValidMotionProp(key) : isValidProp(key); 352} 353try { 354 const emotionPkg = "@emotion/is-prop-valid"; 355 loadExternalIsValidProp(require(emotionPkg).default); 356} catch { 357} 358function filterProps(props, isDom, forwardMotionProps) { 359 const filteredProps = {}; 360 for (const key in props) { 361 if (key === "values" && typeof props.values === "object") 362 continue; 363 if (isMotionValue(props[key])) 364 continue; 365 if (shouldForward(key) || forwardMotionProps === true && isValidMotionProp(key) || !isDom && !isValidMotionProp(key) || // If trying to use native HTML drag events, forward drag listeners 366 props["draggable"] && key.startsWith("onDrag")) { 367 filteredProps[key] = props[key]; 368 } 369 } 370 return filteredProps; 371} 372const MotionContext = /* @__PURE__ */ reactExports.createContext({}); 373function getCurrentTreeVariants(props, context) { 374 if (isControllingVariants(props)) { 375 const { initial, animate } = props; 376 return { 377 initial: initial === false || isVariantLabel(initial) ? initial : void 0, 378 animate: isVariantLabel(animate) ? animate : void 0 379 }; 380 } 381 return props.inherit !== false ? context : {}; 382} 383function useCreateMotionContext(props) { 384 const { initial, animate } = getCurrentTreeVariants(props, reactExports.useContext(MotionContext)); 385 return reactExports.useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]); 386} 387function variantLabelsAsDependency(prop) { 388 return Array.isArray(prop) ? prop.join(" ") : prop; 389} 390const createHtmlRenderState = () => ({ 391 style: {}, 392 transform: {}, 393 transformOrigin: {}, 394 vars: {} 395}); 396function copyRawValuesOnly(target, source, props) { 397 for (const key in source) { 398 if (!isMotionValue(source[key]) && !isForcedMotionValue(key, props)) { 399 target[key] = source[key]; 400 } 401 } 402} 403function useInitialMotionValues({ transformTemplate }, visualState) { 404 return reactExports.useMemo(() => { 405 const state = createHtmlRenderState(); 406 buildHTMLStyles(state, visualState, transformTemplate); 407 return Object.assign({}, state.vars, state.style); 408 }, [visualState]); 409} 410function useStyle(props, visualState) { 411 const styleProp = props.style || {}; 412 const style = {}; 413 copyRawValuesOnly(style, styleProp, props); 414 Object.assign(style, useInitialMotionValues(props, visualState)); 415 return style; 416} 417function useHTMLProps(props, visualState) { 418 const htmlProps = {}; 419 const style = useStyle(props, visualState); 420 if (props.drag && props.dragListener !== false) { 421 htmlProps.draggable = false;
422 style.userSelect = style.WebkitUserSelect = style.WebkitTouchCallout = "none"; 423 style.touchAction = props.drag === true ? "none" : `pan-${props.drag === "x" ? "y" : "x"}`; 424 } 425 if (props.tabIndex === void 0 && (props.onTap || props.onTapStart || props.whileTap)) { 426 htmlProps.tabIndex = 0; 427 } 428 htmlProps.style = style; 429 return htmlProps; 430} 431const createSvgRenderState = () => ({ 432 ...createHtmlRenderState(), 433 attrs: {} 434}); 435function useSVGProps(props, visualState, _isStatic, Component) { 436 const visualProps = reactExports.useMemo(() => { 437 const state = createSvgRenderState(); 438 buildSVGAttrs(state, visualState, isSVGTag(Component), props.transformTemplate, props.style); 439 return { 440 ...state.attrs, 441 style: { ...state.style } 442 }; 443 }, [visualState]); 444 if (props.style) { 445 const rawStyles = {}; 446 copyRawValuesOnly(rawStyles, props.style, props); 447 visualProps.style = { ...rawStyles, ...visualProps.style }; 448 } 449 return visualProps; 450} 451const lowercaseSVGElements = [ 452 "animate", 453 "circle", 454 "defs", 455 "desc", 456 "ellipse", 457 "g", 458 "image", 459 "line", 460 "filter", 461 "marker", 462 "mask", 463 "metadata", 464 "path", 465 "pattern", 466 "polygon", 467 "polyline", 468 "rect", 469 "stop", 470 "switch", 471 "symbol", 472 "svg", 473 "text", 474 "tspan", 475 "use", 476 "view" 477]; 478function isSVGComponent(Component) { 479 if ( 480 /** 481 * If it's not a string, it's a custom React component. Currently we only support 482 * HTML custom React components. 483 */ 484 typeof Component !== "string" || /** 485 * If it contains a dash, the element is a custom HTML webcomponent. 486 */ 487 Component.includes("-") 488 ) { 489 return false; 490 } else if ( 491 /** 492 * If it's in our list of lowercase SVG tags, it's an SVG component 493 */ 494 lowercaseSVGElements.indexOf(Component) > -1 || /** 495 * If it contains a capital letter, it's an SVG component 496 */ 497 /[A-Z]/u.test(Component) 498 ) { 499 return true; 500 } 501 return false; 502} 503function useRender(Component, props, ref, { latestValues }, isStatic, forwardMotionProps = false, isSVG) { 504 const useVisualProps = isSVG ?? isSVGComponent(Component) ? useSVGProps : useHTMLProps; 505 const visualProps = useVisualProps(props, latestValues, isStatic, Component); 506 const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps); 507 const elementProps = Component !== reactExports.Fragment ? { ...filteredProps, ...visualProps, ref } : {}; 508 const { children } = props; 509 const renderedChildren = reactExports.useMemo(() => isMotionValue(children) ? children.get() : children, [children]); 510 return reactExports.createElement(Component, { 511 ...elementProps, 512 children: renderedChildren 513 }); 514} 515function makeState({ scrapeMotionValuesFromProps: scrapeMotionValuesFromProps2, createRenderState }, props, context, presenceContext) { 516 const state = { 517 latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps2), 518 renderState: createRenderState() 519 }; 520 return state; 521} 522function makeLatestValues(props, context, presenceContext, scrapeMotionValues) { 523 const values = {}; 524 const motionValues = scrapeMotionValues(props, {}); 525 for (const key in motionValues) { 526 values[key] = resolveMotionValue(motionValues[key]); 527 } 528 let { initial, animate } = props; 529 const isControllingVariants$1 = isControllingVariants(props); 530 const isVariantNode$1 = isVariantNode(props); 531 if (context && isVariantNode$1 && !isControllingVariants$1 && props.inherit !== false) { 532 if (initial === void 0) 533 initial = context.initial; 534 if (animate === void 0) 535 animate = context.animate; 536 } 537 let isInitialAnimationBlocked = presenceContext ? presenceContext.initial === false : false; 538 isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false; 539 const variantToSet = isInitialAnimationBlocked ? animate : initial; 540 if (variantToSet && typeof variantToSet !== "boolean" && !isAnimationControls(variantToSet)) { 541 const list = Array.isArray(variantToSet) ? variantToSet : [variantToSet]; 542 for (let i = 0; i < list.length; i++) { 543 const resolved = resolveVariantFromProps(props, list[i]); 544 if (resolved) { 545 const { transitionEnd, transition, ...target } = resolved; 546 for (const key in target) { 547 let valueTarget = target[key]; 548 if (Array.isArray(valueTarget)) { 549 const index = isInitialAnimationBlocked ? valueTarget.length - 1 : 0; 550 valueTarget = valueTarget[index]; 551 } 552 if (valueTarget !== null) { 553 values[key] = valueTarget; 554 } 555 } 556 for (const key in transitionEnd) { 557 values[key] = transitionEnd[key]; 558 } 559 } 560 } 561 } 562 return values; 563} 564const makeUseVisualState = (config) => (props, isStatic) => { 565 const context = reactExports.useContext(MotionContext); 566 const presenceContext = reactExports.useContext(PresenceContext); 567 const make = () => makeState(config, props, context, presenceContext); 568 return isStatic ? make() : useConstant(make); 569}; 570const useHTMLVisualState = /* @__PURE__ */ makeUseVisualState({ 571 scrapeMotionValuesFromProps, 572 createRenderState: createHtmlRenderState 573}); 574const useSVGVisualState = /* @__PURE__ */ makeUseVisualState({ 575 scrapeMotionValuesFromProps: scrapeMotionValuesFromProps$1, 576 createRenderState: createSvgRenderState 577}); 578const motionComponentSymbol = Symbol.for("motionComponentSymbol"); 579function useMotionRef(visualState, visualElement, externalRef) { 580 const externalRefContainer = reactExports.useRef(externalRef); 581 reactExports.useInsertionEffect(() => { 582 externalRefContainer.current = externalRef; 583 }); 584 const refCleanup = reactExports.useRef(null); 585 return reactExports.useCallback((instance) => { 586 var _a; 587 if (instance) { 588 (_a = visualState.onMount) == null ? void 0 : _a.call(visualState, instance); 589 } 590 const ref = externalRefContainer.current; 591 if (typeof ref === "function") { 592 if (instance) { 593 const cleanup = ref(instance); 594 if (typeof cleanup === "function") { 595 refCleanup.current = cleanup; 596 } 597 } else if (refCleanup.current) { 598 refCleanup.current(); 599 refCleanup.current = null; 600 } else { 601 ref(instance); 602 } 603 } else if (ref) { 604 ref.current = instance; 605 } 606 if (visualElement) { 607 instance ? visualElement.mount(instance) : visualElement.unmount(); 608 } 609 }, [visualElement]); 610} 611const SwitchLayoutGroupContext = reactExports.createContext({}); 612function isRefObject(ref) { 613 return ref && typeof ref === "object" && Object.prototype.hasOwnProperty.call(ref, "current"); 614} 615function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor, isSVG) { 616 var _a, _b; 617 const { visualElement: parent } = reactExports.useContext(MotionContext); 618 const lazyContext = reactExports.useContext(LazyContext); 619 const presenceContext = reactExports.useContext(PresenceContext); 620 const motionConfig = reactExports.useContext(MotionConfigContext); 621 const reducedMotionConfig = motionConfig.reducedMotion; 622 const skipAnimations = motionConfig.skipAnimations; 623 const visualElementRef = reactExports.useRef(null); 624 const hasMountedOnce = reactExports.useRef(false); 625 createVisualElement = createVisualElement || lazyContext.renderer; 626 if (!visualElementRef.current && createVisualElement) { 627 visualElementRef.current = createVisualElement(Component, { 628 visualState, 629 parent, 630 props, 631 presenceContext,
632 blockInitialAnimation: presenceContext ? presenceContext.initial === false : false, 633 reducedMotionConfig, 634 skipAnimations, 635 isSVG 636 }); 637 if (hasMountedOnce.current && visualElementRef.current) { 638 visualElementRef.current.manuallyAnimateOnMount = true; 639 } 640 } 641 const visualElement = visualElementRef.current; 642 const initialLayoutGroupConfig = reactExports.useContext(SwitchLayoutGroupContext); 643 if (visualElement && !visualElement.projection && ProjectionNodeConstructor && (visualElement.type === "html" || visualElement.type === "svg")) { 644 createProjectionNode(visualElementRef.current, props, ProjectionNodeConstructor, initialLayoutGroupConfig); 645 } 646 const isMounted = reactExports.useRef(false); 647 reactExports.useInsertionEffect(() => { 648 if (visualElement && isMounted.current) { 649 visualElement.update(props, presenceContext); 650 } 651 }); 652 const optimisedAppearId = props[optimizedAppearDataAttribute]; 653 const wantsHandoff = reactExports.useRef(Boolean(optimisedAppearId) && typeof window !== "undefined" && !((_a = window.MotionHandoffIsComplete) == null ? void 0 : _a.call(window, optimisedAppearId)) && ((_b = window.MotionHasOptimisedAnimation) == null ? void 0 : _b.call(window, optimisedAppearId))); 654 useIsomorphicLayoutEffect(() => { 655 hasMountedOnce.current = true; 656 if (!visualElement) 657 return; 658 isMounted.current = true; 659 window.MotionIsMounted = true; 660 visualElement.updateFeatures(); 661 visualElement.scheduleRenderMicrotask(); 662 if (wantsHandoff.current && visualElement.animationState) { 663 visualElement.animationState.animateChanges(); 664 } 665 }); 666 reactExports.useEffect(() => { 667 if (!visualElement) 668 return; 669 if (!wantsHandoff.current && visualElement.animationState) { 670 visualElement.animationState.animateChanges(); 671 } 672 if (wantsHandoff.current) { 673 queueMicrotask(() => { 674 var _a2; 675 (_a2 = window.MotionHandoffMarkAsComplete) == null ? void 0 : _a2.call(window, optimisedAppearId); 676 }); 677 wantsHandoff.current = false; 678 } 679 visualElement.enteringChildren = void 0; 680 }); 681 return visualElement; 682} 683function createProjectionNode(visualElement, props, ProjectionNodeConstructor, initialPromotionConfig) { 684 const { layoutId, layout: layout2, drag: drag2, dragConstraints, layoutScroll, layoutRoot, layoutAnchor, layoutCrossfade } = props; 685 visualElement.projection = new ProjectionNodeConstructor(visualElement.latestValues, props["data-framer-portal-id"] ? void 0 : getClosestProjectingNode(visualElement.parent)); 686 visualElement.projection.setOptions({ 687 layoutId, 688 layout: layout2, 689 alwaysMeasureLayout: Boolean(drag2) || dragConstraints && isRefObject(dragConstraints), 690 visualElement, 691 /** 692 * TODO: Update options in an effect. This could be tricky as it'll be too late 693 * to update by the time layout animations run. 694 * We also need to fix this safeToRemove by linking it up to the one returned by usePresence, 695 * ensuring it gets called if there's no potential layout animations. 696 * 697 */ 698 animationType: typeof layout2 === "string" ? layout2 : "both", 699 initialPromotionConfig, 700 crossfade: layoutCrossfade, 701 layoutScroll, 702 layoutRoot, 703 layoutAnchor 704 }); 705} 706function getClosestProjectingNode(visualElement) { 707 if (!visualElement) 708 return void 0; 709 return visualElement.options.allowProjection !== false ? visualElement.projection : getClosestProjectingNode(visualElement.parent); 710} 711function createMotionComponent(Component, { forwardMotionProps = false, type } = {}, preloadedFeatures, createVisualElement) { 712 preloadedFeatures && loadFeatures(preloadedFeatures); 713 const isSVG = type ? type === "svg" : isSVGComponent(Component); 714 const useVisualState = isSVG ? useSVGVisualState : useHTMLVisualState; 715 function MotionDOMComponent(props, externalRef) { 716 let MeasureLayout2; 717 const configAndProps = { 718 ...reactExports.useContext(MotionConfigContext), 719 ...props, 720 layoutId: useLayoutId(props) 721 }; 722 const { isStatic } = configAndProps; 723 const context = useCreateMotionContext(props); 724 const visualState = useVisualState(props, isStatic); 725 if (!isStatic && typeof window !== "undefined") { 726 useStrictMode(); 727 const layoutProjection = getProjectionFunctionality(configAndProps); 728 MeasureLayout2 = layoutProjection.MeasureLayout; 729 context.visualElement = useVisualElement(Component, visualState, configAndProps, createVisualElement, layoutProjection.ProjectionNode, isSVG); 730 } 731 return jsxRuntimeExports.jsxs(MotionContext.Provider, { value: context, children: [MeasureLayout2 && context.visualElement ? jsxRuntimeExports.jsx(MeasureLayout2, { visualElement: context.visualElement, ...configAndProps }) : null, useRender(Component, props, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, forwardMotionProps, isSVG)] }); 732 } 733 MotionDOMComponent.displayName = `motion.${typeof Component === "string" ? Component : `create(${Component.displayName ?? Component.name ?? ""})`}`; 734 const ForwardRefMotionComponent = reactExports.forwardRef(MotionDOMComponent); 735 ForwardRefMotionComponent[motionComponentSymbol] = Component; 736 return ForwardRefMotionComponent; 737} 738function useLayoutId({ layoutId }) { 739 const layoutGroupId = reactExports.useContext(LayoutGroupContext).id; 740 return layoutGroupId && layoutId !== void 0 ? layoutGroupId + "-" + layoutId : layoutId; 741} 742function useStrictMode(configAndProps, preloadedFeatures) { 743 reactExports.useContext(LazyContext).strict; 744} 745function getProjectionFunctionality(props) { 746 const featureDefinitions = getInitializedFeatureDefinitions(); 747 const { drag: drag2, layout: layout2 } = featureDefinitions; 748 if (!drag2 && !layout2) 749 return {}; 750 const combined = { ...drag2, ...layout2 }; 751 return { 752 MeasureLayout: (drag2 == null ? void 0 : drag2.isEnabled(props)) || (layout2 == null ? void 0 : layout2.isEnabled(props)) ? combined.MeasureLayout : void 0, 753 ProjectionNode: combined.ProjectionNode 754 }; 755} 756function createMotionProxy(preloadedFeatures, createVisualElement) { 757 if (typeof Proxy === "undefined") { 758 return createMotionComponent; 759 } 760 const componentCache = /* @__PURE__ */ new Map(); 761 const factory = (Component, options) => { 762 return createMotionComponent(Component, options, preloadedFeatures, createVisualElement); 763 }; 764 const deprecatedFactoryFunction = (Component, options) => { 765 return factory(Component, options); 766 }; 767 return new Proxy(deprecatedFactoryFunction, { 768 /** 769 * Called when `motion` is referenced with a prop: `motion.div`, `motion.input` etc.
vendor: 18,865 bytes, lines 770-1323
770 * The prop name is passed through as `key` and we can use that to generate a `motion` 771 * DOM component with that name. 772 */ 773 get: (_target, key) => { 774 if (key === "create") 775 return factory; 776 if (!componentCache.has(key)) { 777 componentCache.set(key, createMotionComponent(key, void 0, preloadedFeatures, createVisualElement)); 778 } 779 return componentCache.get(key); 780 } 781 }); 782} 783const createDomVisualElement = (Component, options) => { 784 const isSVG = options.isSVG ?? isSVGComponent(Component); 785 return isSVG ? new SVGVisualElement(options) : new HTMLVisualElement(options, { 786 allowProjection: Component !== reactExports.Fragment 787 }); 788}; 789class AnimationFeature extends Feature { 790 /** 791 * We dynamically generate the AnimationState manager as it contains a reference 792 * to the underlying animation library. We only want to load that if we load this, 793 * so people can optionally code split it out using the `m` component. 794 */ 795 constructor(node) { 796 super(node); 797 node.animationState || (node.animationState = createAnimationState(node)); 798 } 799 updateAnimationControlsSubscription() { 800 const { animate } = this.node.getProps(); 801 if (isAnimationControls(animate)) { 802 this.unmountControls = animate.subscribe(this.node); 803 } 804 } 805 /** 806 * Subscribe any provided AnimationControls to the component's VisualElement 807 */ 808 mount() { 809 this.updateAnimationControlsSubscription(); 810 } 811 update() { 812 const { animate } = this.node.getProps(); 813 const { animate: prevAnimate } = this.node.prevProps || {}; 814 if (animate !== prevAnimate) { 815 this.updateAnimationControlsSubscription(); 816 } 817 } 818 unmount() { 819 var _a; 820 this.node.animationState.reset(); 821 (_a = this.unmountControls) == null ? void 0 : _a.call(this); 822 } 823} 824let id = 0; 825class ExitAnimationFeature extends Feature { 826 constructor() { 827 super(...arguments); 828 this.id = id++; 829 this.isExitComplete = false; 830 } 831 update() { 832 var _a; 833 if (!this.node.presenceContext) 834 return; 835 const { isPresent, onExitComplete } = this.node.presenceContext; 836 const { isPresent: prevIsPresent } = this.node.prevPresenceContext || {}; 837 if (!this.node.animationState || isPresent === prevIsPresent) { 838 return; 839 } 840 if (isPresent && prevIsPresent === false) { 841 if (this.isExitComplete) { 842 const { initial, custom } = this.node.getProps(); 843 if (typeof initial === "string") { 844 const resolved = resolveVariant(this.node, initial, custom); 845 if (resolved) { 846 const { transition, transitionEnd, ...target } = resolved; 847 for (const key in target) { 848 (_a = this.node.getValue(key)) == null ? void 0 : _a.jump(target[key]); 849 } 850 } 851 } 852 this.node.animationState.reset(); 853 this.node.animationState.animateChanges(); 854 } else { 855 this.node.animationState.setActive("exit", false); 856 } 857 this.isExitComplete = false; 858 return; 859 } 860 const exitAnimation = this.node.animationState.setActive("exit", !isPresent); 861 if (onExitComplete && !isPresent) { 862 exitAnimation.then(() => { 863 this.isExitComplete = true; 864 onExitComplete(this.id); 865 }); 866 } 867 } 868 mount() { 869 const { register, onExitComplete } = this.node.presenceContext || {}; 870 if (onExitComplete) { 871 onExitComplete(this.id); 872 } 873 if (register) { 874 this.unmount = register(this.id); 875 } 876 } 877 unmount() { 878 } 879} 880const animations = { 881 animation: { 882 Feature: AnimationFeature 883 }, 884 exit: { 885 Feature: ExitAnimationFeature 886 } 887}; 888function extractEventInfo(event) { 889 return { 890 point: { 891 x: event.pageX, 892 y: event.pageY 893 } 894 }; 895} 896const addPointerInfo = (handler) => (event) => isPrimaryPointer(event) && handler(event, extractEventInfo(event)); 897function addPointerEvent(target, eventName, handler, options) { 898 return addDomEvent(target, eventName, addPointerInfo(handler), options); 899} 900const getContextWindow = ({ current }) => { 901 return current ? current.ownerDocument.defaultView : null; 902}; 903const distance = (a, b) => Math.abs(a - b); 904function distance2D(a, b) { 905 const xDelta = distance(a.x, b.x); 906 const yDelta = distance(a.y, b.y); 907 return Math.sqrt(xDelta ** 2 + yDelta ** 2); 908} 909const overflowStyles = /* @__PURE__ */ new Set(["auto", "scroll"]); 910class PanSession { 911 constructor(event, handlers, { transformPagePoint, contextWindow = window, dragSnapToOrigin = false, distanceThreshold = 3, element } = {}) { 912 this.startEvent = null; 913 this.lastMoveEvent = null; 914 this.lastMoveEventInfo = null; 915 this.lastRawMoveEventInfo = null; 916 this.handlers = {}; 917 this.contextWindow = window; 918 this.scrollPositions = /* @__PURE__ */ new Map(); 919 this.removeScrollListeners = null; 920 this.onElementScroll = (event2) => { 921 this.handleScroll(event2.target); 922 }; 923 this.onWindowScroll = () => { 924 this.handleScroll(window); 925 }; 926 this.updatePoint = () => { 927 if (!(this.lastMoveEvent && this.lastMoveEventInfo)) 928 return; 929 if (this.lastRawMoveEventInfo) { 930 this.lastMoveEventInfo = transformPoint(this.lastRawMoveEventInfo, this.transformPagePoint); 931 } 932 const info2 = getPanInfo(this.lastMoveEventInfo, this.history); 933 const isPanStarted = this.startEvent !== null; 934 const isDistancePastThreshold = distance2D(info2.offset, { x: 0, y: 0 }) >= this.distanceThreshold; 935 if (!isPanStarted && !isDistancePastThreshold) 936 return; 937 const { point: point2 } = info2; 938 const { timestamp: timestamp2 } = frameData; 939 this.history.push({ ...point2, timestamp: timestamp2 }); 940 const { onStart, onMove } = this.handlers; 941 if (!isPanStarted) { 942 onStart && onStart(this.lastMoveEvent, info2); 943 this.startEvent = this.lastMoveEvent; 944 } 945 onMove && onMove(this.lastMoveEvent, info2); 946 }; 947 this.handlePointerMove = (event2, info2) => { 948 this.lastMoveEvent = event2; 949 this.lastRawMoveEventInfo = info2; 950 this.lastMoveEventInfo = transformPoint(info2, this.transformPagePoint); 951 frame.update(this.updatePoint, true); 952 }; 953 this.handlePointerUp = (event2, info2) => { 954 this.end(); 955 const { onEnd, onSessionEnd, resumeAnimation } = this.handlers; 956 if (this.dragSnapToOrigin || !this.startEvent) { 957 resumeAnimation && resumeAnimation(); 958 } 959 if (!(this.lastMoveEvent && this.lastMoveEventInfo)) 960 return; 961 const panInfo = getPanInfo(event2.type === "pointercancel" ? this.lastMoveEventInfo : transformPoint(info2, this.transformPagePoint), this.history); 962 if (this.startEvent && onEnd) { 963 onEnd(event2, panInfo); 964 } 965 onSessionEnd && onSessionEnd(event2, panInfo); 966 }; 967 if (!isPrimaryPointer(event)) 968 return; 969 this.dragSnapToOrigin = dragSnapToOrigin; 970 this.handlers = handlers; 971 this.transformPagePoint = transformPagePoint; 972 this.distanceThreshold = distanceThreshold; 973 this.contextWindow = contextWindow || window; 974 const info = extractEventInfo(event); 975 const initialInfo = transformPoint(info, this.transformPagePoint); 976 const { point } = initialInfo; 977 const { timestamp } = frameData; 978 this.history = [{ ...point, timestamp }]; 979 const { onSessionStart } = handlers; 980 onSessionStart && onSessionStart(event, getPanInfo(initialInfo, this.history)); 981 this.removeListeners = pipe(addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove), addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp), addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp)); 982 if (element) { 983 this.startScrollTracking(element); 984 } 985 } 986 /** 987 * Start tracking scroll on ancestors and window. 988 */ 989 startScrollTracking(element) { 990 let current = element.parentElement; 991 while (current) { 992 const style = getComputedStyle(current); 993 if (overflowStyles.has(style.overflowX) || overflowStyles.has(style.overflowY)) { 994 this.scrollPositions.set(current, { 995 x: current.scrollLeft, 996 y: current.scrollTop 997 }); 998 } 999 current = current.parentElement; 1000 } 1001 this.scrollPositions.set(window, { 1002 x: window.scrollX, 1003 y: window.scrollY 1004 }); 1005 window.addEventListener("scroll", this.onElementScroll, { 1006 capture: true 1007 }); 1008 window.addEventListener("scroll", this.onWindowScroll); 1009 this.removeScrollListeners = () => { 1010 window.removeEventListener("scroll", this.onElementScroll, { 1011 capture: true 1012 }); 1013 window.removeEventListener("scroll", this.onWindowScroll); 1014 }; 1015 } 1016 /** 1017 * Handle scroll compensation during drag. 1018 * 1019 * For element scroll: adjusts history origin since pageX/pageY doesn't change. 1020 * For window scroll: adjusts lastMoveEventInfo since pageX/pageY would change. 1021 */ 1022 handleScroll(target) { 1023 const initial = this.scrollPositions.get(target); 1024 if (!initial) 1025 return; 1026 const isWindow = target === window; 1027 const current = isWindow ? { x: window.scrollX, y: window.scrollY } : { 1028 x: target.scrollLeft, 1029 y: target.scrollTop 1030 }; 1031 const delta = { x: current.x - initial.x, y: current.y - initial.y }; 1032 if (delta.x === 0 && delta.y === 0) 1033 return; 1034 if (isWindow) { 1035 if (this.lastMoveEventInfo) { 1036 this.lastMoveEventInfo.point.x += delta.x; 1037 this.lastMoveEventInfo.point.y += delta.y; 1038 } 1039 } else { 1040 if (this.history.length > 0) { 1041 this.history[0].x -= delta.x; 1042 this.history[0].y -= delta.y; 1043 } 1044 } 1045 this.scrollPositions.set(target, current); 1046 frame.update(this.updatePoint, true); 1047 } 1048 updateHandlers(handlers) { 1049 this.handlers = handlers; 1050 } 1051 end() { 1052 this.removeListeners && this.removeListeners(); 1053 this.removeScrollListeners && this.removeScrollListeners(); 1054 this.scrollPositions.clear(); 1055 cancelFrame(this.updatePoint); 1056 } 1057} 1058function transformPoint(info, transformPagePoint) { 1059 return transformPagePoint ? { point: transformPagePoint(info.point) } : info; 1060} 1061function subtractPoint(a, b) { 1062 return { x: a.x - b.x, y: a.y - b.y }; 1063} 1064function getPanInfo({ point }, history) { 1065 return { 1066 point, 1067 delta: subtractPoint(point, lastDevicePoint(history)), 1068 offset: subtractPoint(point, startDevicePoint(history)), 1069 velocity: getVelocity(history, 0.1) 1070 }; 1071} 1072function startDevicePoint(history) { 1073 return history[0]; 1074} 1075function lastDevicePoint(history) { 1076 return history[history.length - 1]; 1077} 1078function getVelocity(history, timeDelta) { 1079 if (history.length < 2) { 1080 return { x: 0, y: 0 }; 1081 } 1082 let i = history.length - 1; 1083 let timestampedPoint = null; 1084 const lastPoint = lastDevicePoint(history); 1085 while (i >= 0) { 1086 timestampedPoint = history[i]; 1087 if (lastPoint.timestamp - timestampedPoint.timestamp > secondsToMilliseconds(timeDelta)) { 1088 break; 1089 } 1090 i--; 1091 } 1092 if (!timestampedPoint) { 1093 return { x: 0, y: 0 }; 1094 } 1095 if (timestampedPoint === history[0] && history.length > 2 && lastPoint.timestamp - timestampedPoint.timestamp > secondsToMilliseconds(timeDelta) * 2) { 1096 timestampedPoint = history[1]; 1097 } 1098 const time = millisecondsToSeconds(lastPoint.timestamp - timestampedPoint.timestamp); 1099 if (time === 0) { 1100 return { x: 0, y: 0 }; 1101 } 1102 const currentVelocity = { 1103 x: (lastPoint.x - timestampedPoint.x) / time, 1104 y: (lastPoint.y - timestampedPoint.y) / time 1105 }; 1106 if (currentVelocity.x === Infinity) { 1107 currentVelocity.x = 0; 1108 } 1109 if (currentVelocity.y === Infinity) { 1110 currentVelocity.y = 0; 1111 } 1112 return currentVelocity; 1113} 1114function applyConstraints(point, { min, max }, elastic) { 1115 if (min !== void 0 && point < min) { 1116 point = elastic ? mixNumber(min, point, elastic.min) : Math.max(point, min); 1117 } else if (max !== void 0 && point > max) { 1118 point = elastic ? mixNumber(max, point, elastic.max) : Math.min(point, max); 1119 } 1120 return point; 1121} 1122function calcRelativeAxisConstraints(axis, min, max) { 1123 return { 1124 min: min !== void 0 ? axis.min + min : void 0, 1125 max: max !== void 0 ? axis.max + max - (axis.max - axis.min) : void 0 1126 }; 1127} 1128function calcRelativeConstraints(layoutBox, { top, left, bottom, right }) { 1129 return { 1130 x: calcRelativeAxisConstraints(layoutBox.x, left, right), 1131 y: calcRelativeAxisConstraints(layoutBox.y, top, bottom) 1132 }; 1133} 1134function calcViewportAxisConstraints(layoutAxis, constraintsAxis) { 1135 let min = constraintsAxis.min - layoutAxis.min; 1136 let max = constraintsAxis.max - layoutAxis.max; 1137 if (constraintsAxis.max - constraintsAxis.min < layoutAxis.max - layoutAxis.min) { 1138 [min, max] = [max, min]; 1139 } 1140 return { min, max }; 1141} 1142function calcViewportConstraints(layoutBox, constraintsBox) { 1143 return { 1144 x: calcViewportAxisConstraints(layoutBox.x, constraintsBox.x), 1145 y: calcViewportAxisConstraints(layoutBox.y, constraintsBox.y) 1146 }; 1147} 1148function calcOrigin(source, target) { 1149 let origin = 0.5; 1150 const sourceLength = calcLength(source); 1151 const targetLength = calcLength(target); 1152 if (targetLength > sourceLength) { 1153 origin = progress(target.min, target.max - sourceLength, source.min); 1154 } else if (sourceLength > targetLength) { 1155 origin = progress(source.min, source.max - targetLength, target.min); 1156 } 1157 return clamp(0, 1, origin); 1158} 1159function rebaseAxisConstraints(layout2, constraints) { 1160 const relativeConstraints = {}; 1161 if (constraints.min !== void 0) { 1162 relativeConstraints.min = constraints.min - layout2.min; 1163 } 1164 if (constraints.max !== void 0) { 1165 relativeConstraints.max = constraints.max - layout2.min; 1166 } 1167 return relativeConstraints; 1168} 1169const defaultElastic = 0.35; 1170function resolveDragElastic(dragElastic = defaultElastic) { 1171 if (dragElastic === false) { 1172 dragElastic = 0; 1173 } else if (dragElastic === true) { 1174 dragElastic = defaultElastic; 1175 } 1176 return { 1177 x: resolveAxisElastic(dragElastic, "left", "right"), 1178 y: resolveAxisElastic(dragElastic, "top", "bottom") 1179 }; 1180} 1181function resolveAxisElastic(dragElastic, minLabel, maxLabel) { 1182 return { 1183 min: resolvePointElastic(dragElastic, minLabel), 1184 max: resolvePointElastic(dragElastic, maxLabel) 1185 }; 1186} 1187function resolvePointElastic(dragElastic, label) { 1188 return typeof dragElastic === "number" ? dragElastic : dragElastic[label] || 0; 1189} 1190const elementDragControls = /* @__PURE__ */ new WeakMap(); 1191class VisualElementDragControls { 1192 constructor(visualElement) { 1193 this.openDragLock = null; 1194 this.isDragging = false; 1195 this.currentDirection = null; 1196 this.originPoint = { x: 0, y: 0 }; 1197 this.constraints = false; 1198 this.hasMutatedConstraints = false; 1199 this.elastic = createBox(); 1200 this.latestPointerEvent = null; 1201 this.latestPanInfo = null; 1202 this.visualElement = visualElement; 1203 } 1204 start(originEvent, { snapToCursor = false, distanceThreshold } = {}) { 1205 const { presenceContext } = this.visualElement; 1206 if (presenceContext && presenceContext.isPresent === false) 1207 return; 1208 const onSessionStart = (event) => { 1209 if (snapToCursor) { 1210 this.snapToCursor(extractEventInfo(event).point); 1211 } 1212 this.stopAnimation(); 1213 }; 1214 const onStart = (event, info) => { 1215 const { drag: drag2, dragPropagation, onDragStart } = this.getProps(); 1216 if (drag2 && !dragPropagation) { 1217 if (this.openDragLock) 1218 this.openDragLock(); 1219 this.openDragLock = setDragLock(drag2); 1220 if (!this.openDragLock) 1221 return; 1222 } 1223 this.latestPointerEvent = event; 1224 this.latestPanInfo = info; 1225 this.isDragging = true; 1226 this.currentDirection = null; 1227 this.resolveConstraints(); 1228 if (this.visualElement.projection) { 1229 this.visualElement.projection.isAnimationBlocked = true; 1230 this.visualElement.projection.target = void 0; 1231 } 1232 eachAxis((axis) => { 1233 let current = this.getAxisMotionValue(axis).get() || 0; 1234 if (percent.test(current)) { 1235 const { projection } = this.visualElement; 1236 if (projection && projection.layout) { 1237 const measuredAxis = projection.layout.layoutBox[axis]; 1238 if (measuredAxis) { 1239 const length = calcLength(measuredAxis); 1240 current = length * (parseFloat(current) / 100); 1241 } 1242 } 1243 } 1244 this.originPoint[axis] = current; 1245 }); 1246 if (onDragStart) { 1247 frame.update(() => onDragStart(event, info), false, true); 1248 } 1249 addValueToWillChange(this.visualElement, "transform"); 1250 const { animationState } = this.visualElement; 1251 animationState && animationState.setActive("whileDrag", true); 1252 }; 1253 const onMove = (event, info) => { 1254 this.latestPointerEvent = event; 1255 this.latestPanInfo = info; 1256 const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag } = this.getProps(); 1257 if (!dragPropagation && !this.openDragLock) 1258 return; 1259 const { offset } = info; 1260 if (dragDirectionLock && this.currentDirection === null) { 1261 this.currentDirection = getCurrentDirection(offset); 1262 if (this.currentDirection !== null) { 1263 onDirectionLock && onDirectionLock(this.currentDirection); 1264 } 1265 return; 1266 } 1267 this.updateAxis("x", info.point, offset); 1268 this.updateAxis("y", info.point, offset); 1269 this.visualElement.render(); 1270 if (onDrag) { 1271 frame.update(() => onDrag(event, info), false, true); 1272 } 1273 }; 1274 const onSessionEnd = (event, info) => { 1275 this.latestPointerEvent = event; 1276 this.latestPanInfo = info; 1277 this.stop(event, info); 1278 this.latestPointerEvent = null; 1279 this.latestPanInfo = null; 1280 }; 1281 const resumeAnimation = () => { 1282 const { dragSnapToOrigin: snap } = this.getProps(); 1283 if (snap || this.constraints) { 1284 this.startAnimation({ x: 0, y: 0 }); 1285 } 1286 }; 1287 const { dragSnapToOrigin } = this.getProps(); 1288 this.panSession = new PanSession(originEvent, { 1289 onSessionStart, 1290 onStart, 1291 onMove, 1292 onSessionEnd, 1293 resumeAnimation 1294 }, { 1295 transformPagePoint: this.visualElement.getTransformPagePoint(), 1296 dragSnapToOrigin, 1297 distanceThreshold, 1298 contextWindow: getContextWindow(this.visualElement), 1299 element: this.visualElement.current 1300 }); 1301 } 1302 /** 1303 * @internal 1304 */ 1305 stop(event, panInfo) { 1306 const finalEvent = event || this.latestPointerEvent; 1307 const finalPanInfo = panInfo || this.latestPanInfo; 1308 const isDragging = this.isDragging; 1309 this.cancel(); 1310 if (!isDragging || !finalPanInfo || !finalEvent) 1311 return; 1312 const { velocity } = finalPanInfo; 1313 this.startAnimation(velocity); 1314 const { onDragEnd } = this.getProps(); 1315 if (onDragEnd) { 1316 frame.postRender(() => onDragEnd(finalEvent, finalPanInfo)); 1317 } 1318 } 1319 /** 1320 * @internal 1321 */ 1322 cancel() { 1323 this.isDragging = false;
1324 const { projection, animationState } = this.visualElement; 1325 if (projection) { 1326 projection.isAnimationBlocked = false; 1327 } 1328 this.endPanSession(); 1329 const { dragPropagation } = this.getProps(); 1330 if (!dragPropagation && this.openDragLock) { 1331 this.openDragLock(); 1332 this.openDragLock = null; 1333 } 1334 animationState && animationState.setActive("whileDrag", false); 1335 } 1336 /** 1337 * Clean up the pan session without modifying other drag state. 1338 * This is used during unmount to ensure event listeners are removed 1339 * without affecting projection animations or drag locks. 1340 * @internal 1341 */ 1342 endPanSession() { 1343 this.panSession && this.panSession.end(); 1344 this.panSession = void 0; 1345 } 1346 updateAxis(axis, _point, offset) { 1347 const { drag: drag2 } = this.getProps(); 1348 if (!offset || !shouldDrag(axis, drag2, this.currentDirection)) 1349 return; 1350 const axisValue = this.getAxisMotionValue(axis); 1351 let next = this.originPoint[axis] + offset[axis]; 1352 if (this.constraints && this.constraints[axis]) { 1353 next = applyConstraints(next, this.constraints[axis], this.elastic[axis]); 1354 } 1355 axisValue.set(next); 1356 } 1357 resolveConstraints() { 1358 var _a; 1359 const { dragConstraints, dragElastic } = this.getProps(); 1360 const layout2 = this.visualElement.projection && !this.visualElement.projection.layout ? this.visualElement.projection.measure(false) : (_a = this.visualElement.projection) == null ? void 0 : _a.layout; 1361 const prevConstraints = this.constraints; 1362 if (dragConstraints && isRefObject(dragConstraints)) { 1363 if (!this.constraints) { 1364 this.constraints = this.resolveRefConstraints(); 1365 } 1366 } else { 1367 if (dragConstraints && layout2) { 1368 this.constraints = calcRelativeConstraints(layout2.layoutBox, dragConstraints); 1369 } else { 1370 this.constraints = false; 1371 } 1372 } 1373 this.elastic = resolveDragElastic(dragElastic); 1374 if (prevConstraints !== this.constraints && !isRefObject(dragConstraints) && layout2 && this.constraints && !this.hasMutatedConstraints) { 1375 eachAxis((axis) => { 1376 if (this.constraints !== false && this.getAxisMotionValue(axis)) { 1377 this.constraints[axis] = rebaseAxisConstraints(layout2.layoutBox[axis], this.constraints[axis]); 1378 } 1379 }); 1380 } 1381 } 1382 resolveRefConstraints() { 1383 const { dragConstraints: constraints, onMeasureDragConstraints } = this.getProps(); 1384 if (!constraints || !isRefObject(constraints)) 1385 return false; 1386 const constraintsElement = constraints.current; 1387 const { projection } = this.visualElement; 1388 if (!projection || !projection.layout) 1389 return false; 1390 const constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint()); 1391 let measuredConstraints = calcViewportConstraints(projection.layout.layoutBox, constraintsBox); 1392 if (onMeasureDragConstraints) { 1393 const userConstraints = onMeasureDragConstraints(convertBoxToBoundingBox(measuredConstraints)); 1394 this.hasMutatedConstraints = !!userConstraints; 1395 if (userConstraints) { 1396 measuredConstraints = convertBoundingBoxToBox(userConstraints); 1397 } 1398 } 1399 return measuredConstraints; 1400 } 1401 startAnimation(velocity) { 1402 const { drag: drag2, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd } = this.getProps(); 1403 const constraints = this.constraints || {}; 1404 const momentumAnimations = eachAxis((axis) => { 1405 if (!shouldDrag(axis, drag2, this.currentDirection)) { 1406 return; 1407 } 1408 let transition = constraints && constraints[axis] || {}; 1409 if (dragSnapToOrigin === true || dragSnapToOrigin === axis) 1410 transition = { min: 0, max: 0 }; 1411 const bounceStiffness = dragElastic ? 200 : 1e6; 1412 const bounceDamping = dragElastic ? 40 : 1e7; 1413 const inertia = { 1414 type: "inertia", 1415 velocity: dragMomentum ? velocity[axis] : 0, 1416 bounceStiffness, 1417 bounceDamping, 1418 timeConstant: 750, 1419 restDelta: 1, 1420 restSpeed: 10, 1421 ...dragTransition, 1422 ...transition 1423 }; 1424 return this.startAxisValueAnimation(axis, inertia); 1425 }); 1426 return Promise.all(momentumAnimations).then(onDragTransitionEnd); 1427 } 1428 startAxisValueAnimation(axis, transition) { 1429 const axisValue = this.getAxisMotionValue(axis); 1430 addValueToWillChange(this.visualElement, axis); 1431 return axisValue.start(animateMotionValue(axis, axisValue, 0, transition, this.visualElement, false)); 1432 } 1433 stopAnimation() { 1434 eachAxis((axis) => this.getAxisMotionValue(axis).stop()); 1435 } 1436 /** 1437 * Drag works differently depending on which props are provided. 1438 * 1439 * - If _dragX and _dragY are provided, we output the gesture delta directly to those motion values. 1440 * - Otherwise, we apply the delta to the x/y motion values. 1441 */ 1442 getAxisMotionValue(axis) { 1443 const dragKey = `_drag${axis.toUpperCase()}`; 1444 const props = this.visualElement.getProps(); 1445 const externalMotionValue = props[dragKey]; 1446 return externalMotionValue ? externalMotionValue : this.visualElement.getValue(axis, (props.initial ? props.initial[axis] : void 0) || 0); 1447 } 1448 snapToCursor(point) { 1449 eachAxis((axis) => { 1450 const { drag: drag2 } = this.getProps(); 1451 if (!shouldDrag(axis, drag2, this.currentDirection)) 1452 return; 1453 const { projection } = this.visualElement; 1454 const axisValue = this.getAxisMotionValue(axis); 1455 if (projection && projection.layout) { 1456 const { min, max } = projection.layout.layoutBox[axis]; 1457 const current = axisValue.get() || 0; 1458 axisValue.set(point[axis] - mixNumber(min, max, 0.5) + current); 1459 } 1460 }); 1461 } 1462 /** 1463 * When the viewport resizes we want to check if the measured constraints 1464 * have changed and, if so, reposition the element within those new constraints 1465 * relative to where it was before the resize. 1466 */ 1467 scalePositionWithinConstraints() { 1468 if (!this.visualElement.current) 1469 return; 1470 const { drag: drag2, dragConstraints } = this.getProps(); 1471 const { projection } = this.visualElement; 1472 if (!isRefObject(dragConstraints) || !projection || !this.constraints) 1473 return; 1474 this.stopAnimation(); 1475 const boxProgress = { x: 0, y: 0 }; 1476 eachAxis((axis) => { 1477 const axisValue = this.getAxisMotionValue(axis); 1478 if (axisValue && this.constraints !== false) { 1479 const latest = axisValue.get(); 1480 boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]); 1481 } 1482 }); 1483 const { transformTemplate } = this.visualElement.getProps(); 1484 this.visualElement.current.style.transform = transformTemplate ? transformTemplate({}, "") : "none"; 1485 projection.root && projection.root.updateScroll(); 1486 projection.updateLayout(); 1487 this.constraints = false;
vendor: 14,946 bytes, lines 1488-1944
1488 this.resolveConstraints(); 1489 eachAxis((axis) => { 1490 if (!shouldDrag(axis, drag2, null)) 1491 return; 1492 const axisValue = this.getAxisMotionValue(axis); 1493 const { min, max } = this.constraints[axis]; 1494 axisValue.set(mixNumber(min, max, boxProgress[axis])); 1495 }); 1496 this.visualElement.render(); 1497 } 1498 addListeners() { 1499 if (!this.visualElement.current) 1500 return; 1501 elementDragControls.set(this.visualElement, this); 1502 const element = this.visualElement.current; 1503 const stopPointerListener = addPointerEvent(element, "pointerdown", (event) => { 1504 const { drag: drag2, dragListener = true } = this.getProps(); 1505 const target = event.target; 1506 const isClickingTextInputChild = target !== element && isElementTextInput(target); 1507 if (drag2 && dragListener && !isClickingTextInputChild) { 1508 this.start(event); 1509 } 1510 }); 1511 let stopResizeObservers; 1512 const measureDragConstraints = () => { 1513 const { dragConstraints } = this.getProps(); 1514 if (isRefObject(dragConstraints) && dragConstraints.current) { 1515 this.constraints = this.resolveRefConstraints(); 1516 if (!stopResizeObservers) { 1517 stopResizeObservers = startResizeObservers(element, dragConstraints.current, () => this.scalePositionWithinConstraints()); 1518 } 1519 } 1520 }; 1521 const { projection } = this.visualElement; 1522 const stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints); 1523 if (projection && !projection.layout) { 1524 projection.root && projection.root.updateScroll(); 1525 projection.updateLayout(); 1526 } 1527 frame.read(measureDragConstraints); 1528 const stopResizeListener = addDomEvent(window, "resize", () => this.scalePositionWithinConstraints()); 1529 const stopLayoutUpdateListener = projection.addEventListener("didUpdate", ({ delta, hasLayoutChanged }) => { 1530 if (this.isDragging && hasLayoutChanged) { 1531 eachAxis((axis) => { 1532 const motionValue = this.getAxisMotionValue(axis); 1533 if (!motionValue) 1534 return; 1535 this.originPoint[axis] += delta[axis].translate; 1536 motionValue.set(motionValue.get() + delta[axis].translate); 1537 }); 1538 this.visualElement.render(); 1539 } 1540 }); 1541 return () => { 1542 stopResizeListener(); 1543 stopPointerListener(); 1544 stopMeasureLayoutListener(); 1545 stopLayoutUpdateListener && stopLayoutUpdateListener(); 1546 stopResizeObservers && stopResizeObservers(); 1547 }; 1548 } 1549 getProps() { 1550 const props = this.visualElement.getProps(); 1551 const { drag: drag2 = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true } = props; 1552 return { 1553 ...props, 1554 drag: drag2, 1555 dragDirectionLock, 1556 dragPropagation, 1557 dragConstraints, 1558 dragElastic, 1559 dragMomentum 1560 }; 1561 } 1562} 1563function skipFirstCall(callback) { 1564 let isFirst = true; 1565 return () => { 1566 if (isFirst) { 1567 isFirst = false; 1568 return; 1569 } 1570 callback(); 1571 }; 1572} 1573function startResizeObservers(element, constraintsElement, onResize) { 1574 const stopElement = resize(element, skipFirstCall(onResize)); 1575 const stopContainer = resize(constraintsElement, skipFirstCall(onResize)); 1576 return () => { 1577 stopElement(); 1578 stopContainer(); 1579 }; 1580} 1581function shouldDrag(direction, drag2, currentDirection) { 1582 return (drag2 === true || drag2 === direction) && (currentDirection === null || currentDirection === direction); 1583} 1584function getCurrentDirection(offset, lockThreshold = 10) { 1585 let direction = null; 1586 if (Math.abs(offset.y) > lockThreshold) { 1587 direction = "y"; 1588 } else if (Math.abs(offset.x) > lockThreshold) { 1589 direction = "x"; 1590 } 1591 return direction; 1592} 1593class DragGesture extends Feature { 1594 constructor(node) { 1595 super(node); 1596 this.removeGroupControls = noop; 1597 this.removeListeners = noop; 1598 this.controls = new VisualElementDragControls(node); 1599 } 1600 mount() { 1601 const { dragControls } = this.node.getProps(); 1602 if (dragControls) { 1603 this.removeGroupControls = dragControls.subscribe(this.controls); 1604 } 1605 this.removeListeners = this.controls.addListeners() || noop; 1606 } 1607 update() { 1608 const { dragControls } = this.node.getProps(); 1609 const { dragControls: prevDragControls } = this.node.prevProps || {}; 1610 if (dragControls !== prevDragControls) { 1611 this.removeGroupControls(); 1612 if (dragControls) { 1613 this.removeGroupControls = dragControls.subscribe(this.controls); 1614 } 1615 } 1616 } 1617 unmount() { 1618 this.removeGroupControls(); 1619 this.removeListeners(); 1620 if (!this.controls.isDragging) { 1621 this.controls.endPanSession(); 1622 } 1623 } 1624} 1625const asyncHandler = (handler) => (event, info) => { 1626 if (handler) { 1627 frame.update(() => handler(event, info), false, true); 1628 } 1629}; 1630class PanGesture extends Feature { 1631 constructor() { 1632 super(...arguments); 1633 this.removePointerDownListener = noop; 1634 } 1635 onPointerDown(pointerDownEvent) { 1636 this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), { 1637 transformPagePoint: this.node.getTransformPagePoint(), 1638 contextWindow: getContextWindow(this.node) 1639 }); 1640 } 1641 createPanHandlers() { 1642 const { onPanSessionStart, onPanStart, onPan, onPanEnd } = this.node.getProps(); 1643 return { 1644 onSessionStart: asyncHandler(onPanSessionStart), 1645 onStart: asyncHandler(onPanStart), 1646 onMove: asyncHandler(onPan), 1647 onEnd: (event, info) => { 1648 delete this.session; 1649 if (onPanEnd) { 1650 frame.postRender(() => onPanEnd(event, info)); 1651 } 1652 } 1653 }; 1654 } 1655 mount() { 1656 this.removePointerDownListener = addPointerEvent(this.node.current, "pointerdown", (event) => this.onPointerDown(event)); 1657 } 1658 update() { 1659 this.session && this.session.updateHandlers(this.createPanHandlers()); 1660 } 1661 unmount() { 1662 this.removePointerDownListener(); 1663 this.session && this.session.end(); 1664 } 1665} 1666let hasTakenAnySnapshot = false; 1667class MeasureLayoutWithContext extends reactExports.Component { 1668 /** 1669 * This only mounts projection nodes for components that 1670 * need measuring, we might want to do it for all components 1671 * in order to incorporate transforms 1672 */ 1673 componentDidMount() { 1674 const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props; 1675 const { projection } = visualElement; 1676 if (projection) { 1677 if (layoutGroup.group) 1678 layoutGroup.group.add(projection); 1679 if (switchLayoutGroup && switchLayoutGroup.register && layoutId) { 1680 switchLayoutGroup.register(projection); 1681 } 1682 if (hasTakenAnySnapshot) { 1683 projection.root.didUpdate(); 1684 } 1685 projection.addEventListener("animationComplete", () => { 1686 this.safeToRemove(); 1687 }); 1688 projection.setOptions({ 1689 ...projection.options, 1690 layoutDependency: this.props.layoutDependency, 1691 onExitComplete: () => this.safeToRemove() 1692 }); 1693 } 1694 globalProjectionState.hasEverUpdated = true; 1695 } 1696 getSnapshotBeforeUpdate(prevProps) { 1697 const { layoutDependency, visualElement, drag: drag2, isPresent } = this.props; 1698 const { projection } = visualElement; 1699 if (!projection) 1700 return null; 1701 projection.isPresent = isPresent; 1702 if (prevProps.layoutDependency !== layoutDependency) { 1703 projection.setOptions({ 1704 ...projection.options, 1705 layoutDependency 1706 }); 1707 } 1708 hasTakenAnySnapshot = true; 1709 if (drag2 || prevProps.layoutDependency !== layoutDependency || layoutDependency === void 0 || prevProps.isPresent !== isPresent) { 1710 projection.willUpdate(); 1711 } else { 1712 this.safeToRemove(); 1713 } 1714 if (prevProps.isPresent !== isPresent) { 1715 if (isPresent) { 1716 projection.promote(); 1717 } else if (!projection.relegate()) { 1718 frame.postRender(() => { 1719 const stack = projection.getStack(); 1720 if (!stack || !stack.members.length) { 1721 this.safeToRemove(); 1722 } 1723 }); 1724 } 1725 } 1726 return null; 1727 } 1728 componentDidUpdate() { 1729 const { visualElement, layoutAnchor } = this.props; 1730 const { projection } = visualElement; 1731 if (projection) { 1732 projection.options.layoutAnchor = layoutAnchor; 1733 projection.root.didUpdate(); 1734 microtask.postRender(() => { 1735 if (!projection.currentAnimation && projection.isLead()) { 1736 this.safeToRemove(); 1737 } 1738 }); 1739 } 1740 } 1741 componentWillUnmount() { 1742 const { visualElement, layoutGroup, switchLayoutGroup: promoteContext } = this.props; 1743 const { projection } = visualElement; 1744 hasTakenAnySnapshot = true; 1745 if (projection) { 1746 projection.scheduleCheckAfterUnmount(); 1747 if (layoutGroup && layoutGroup.group) 1748 layoutGroup.group.remove(projection); 1749 if (promoteContext && promoteContext.deregister) 1750 promoteContext.deregister(projection); 1751 } 1752 } 1753 safeToRemove() { 1754 const { safeToRemove } = this.props; 1755 safeToRemove && safeToRemove(); 1756 } 1757 render() { 1758 return null; 1759 } 1760} 1761function MeasureLayout(props) { 1762 const [isPresent, safeToRemove] = usePresence(); 1763 const layoutGroup = reactExports.useContext(LayoutGroupContext); 1764 return jsxRuntimeExports.jsx(MeasureLayoutWithContext, { ...props, layoutGroup, switchLayoutGroup: reactExports.useContext(SwitchLayoutGroupContext), isPresent, safeToRemove }); 1765} 1766const drag = { 1767 pan: { 1768 Feature: PanGesture 1769 }, 1770 drag: { 1771 Feature: DragGesture, 1772 ProjectionNode: HTMLProjectionNode, 1773 MeasureLayout 1774 } 1775}; 1776function handleHoverEvent(node, event, lifecycle) { 1777 const { props } = node; 1778 if (node.animationState && props.whileHover) { 1779 node.animationState.setActive("whileHover", lifecycle === "Start"); 1780 } 1781 const eventName = "onHover" + lifecycle; 1782 const callback = props[eventName]; 1783 if (callback) { 1784 frame.postRender(() => callback(event, extractEventInfo(event))); 1785 } 1786} 1787class HoverGesture extends Feature { 1788 mount() { 1789 const { current } = this.node; 1790 if (!current) 1791 return; 1792 this.unmount = hover(current, (_element, startEvent) => { 1793 handleHoverEvent(this.node, startEvent, "Start"); 1794 return (endEvent) => handleHoverEvent(this.node, endEvent, "End"); 1795 }); 1796 } 1797 unmount() { 1798 } 1799} 1800class FocusGesture extends Feature { 1801 constructor() { 1802 super(...arguments); 1803 this.isActive = false; 1804 } 1805 onFocus() { 1806 let isFocusVisible = false; 1807 try { 1808 isFocusVisible = this.node.current.matches(":focus-visible"); 1809 } catch (e) { 1810 isFocusVisible = true; 1811 } 1812 if (!isFocusVisible || !this.node.animationState) 1813 return; 1814 this.node.animationState.setActive("whileFocus", true); 1815 this.isActive = true; 1816 } 1817 onBlur() { 1818 if (!this.isActive || !this.node.animationState) 1819 return; 1820 this.node.animationState.setActive("whileFocus", false); 1821 this.isActive = false; 1822 } 1823 mount() { 1824 this.unmount = pipe(addDomEvent(this.node.current, "focus", () => this.onFocus()), addDomEvent(this.node.current, "blur", () => this.onBlur())); 1825 } 1826 unmount() { 1827 } 1828} 1829function handlePressEvent(node, event, lifecycle) { 1830 const { props } = node; 1831 if (node.current instanceof HTMLButtonElement && node.current.disabled) { 1832 return; 1833 } 1834 if (node.animationState && props.whileTap) { 1835 node.animationState.setActive("whileTap", lifecycle === "Start"); 1836 } 1837 const eventName = "onTap" + (lifecycle === "End" ? "" : lifecycle); 1838 const callback = props[eventName]; 1839 if (callback) { 1840 frame.postRender(() => callback(event, extractEventInfo(event))); 1841 } 1842} 1843class PressGesture extends Feature { 1844 mount() { 1845 const { current } = this.node; 1846 if (!current) 1847 return; 1848 const { globalTapTarget, propagate } = this.node.props; 1849 this.unmount = press(current, (_element, startEvent) => { 1850 handlePressEvent(this.node, startEvent, "Start"); 1851 return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel"); 1852 }, { 1853 useGlobalTarget: globalTapTarget, 1854 stopPropagation: (propagate == null ? void 0 : propagate.tap) === false 1855 }); 1856 } 1857 unmount() { 1858 } 1859} 1860const observerCallbacks = /* @__PURE__ */ new WeakMap(); 1861const observers = /* @__PURE__ */ new WeakMap(); 1862const fireObserverCallback = (entry) => { 1863 const callback = observerCallbacks.get(entry.target); 1864 callback && callback(entry); 1865}; 1866const fireAllObserverCallbacks = (entries) => { 1867 entries.forEach(fireObserverCallback); 1868}; 1869function initIntersectionObserver({ root, ...options }) { 1870 const lookupRoot = root || document; 1871 if (!observers.has(lookupRoot)) { 1872 observers.set(lookupRoot, {}); 1873 } 1874 const rootObservers = observers.get(lookupRoot); 1875 const key = JSON.stringify(options); 1876 if (!rootObservers[key]) { 1877 rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options }); 1878 } 1879 return rootObservers[key]; 1880} 1881function observeIntersection(element, options, callback) { 1882 const rootInteresectionObserver = initIntersectionObserver(options); 1883 observerCallbacks.set(element, callback); 1884 rootInteresectionObserver.observe(element); 1885 return () => { 1886 observerCallbacks.delete(element); 1887 rootInteresectionObserver.unobserve(element); 1888 }; 1889} 1890const thresholdNames = { 1891 some: 0, 1892 all: 1 1893}; 1894class InViewFeature extends Feature { 1895 constructor() { 1896 super(...arguments); 1897 this.hasEnteredView = false; 1898 this.isInView = false; 1899 } 1900 startObserver() { 1901 var _a; 1902 (_a = this.stopObserver) == null ? void 0 : _a.call(this); 1903 const { viewport = {} } = this.node.getProps(); 1904 const { root, margin: rootMargin, amount = "some", once } = viewport; 1905 const options = { 1906 root: root ? root.current : void 0, 1907 rootMargin, 1908 threshold: typeof amount === "number" ? amount : thresholdNames[amount] 1909 }; 1910 const onIntersectionUpdate = (entry) => { 1911 const { isIntersecting } = entry; 1912 if (this.isInView === isIntersecting) 1913 return; 1914 this.isInView = isIntersecting; 1915 if (once && !isIntersecting && this.hasEnteredView) { 1916 return; 1917 } else if (isIntersecting) { 1918 this.hasEnteredView = true; 1919 } 1920 if (this.node.animationState) { 1921 this.node.animationState.setActive("whileInView", isIntersecting); 1922 } 1923 const { onViewportEnter, onViewportLeave } = this.node.getProps(); 1924 const callback = isIntersecting ? onViewportEnter : onViewportLeave; 1925 callback && callback(entry); 1926 }; 1927 this.stopObserver = observeIntersection(this.node.current, options, onIntersectionUpdate); 1928 } 1929 mount() { 1930 this.startObserver(); 1931 } 1932 update() { 1933 if (typeof IntersectionObserver === "undefined") 1934 return; 1935 const { props, prevProps } = this.node; 1936 const hasOptionsChanged = ["amount", "margin", "root"].some(hasViewportOptionChanged(props, prevProps)); 1937 if (hasOptionsChanged) { 1938 this.startObserver(); 1939 } 1940 } 1941 unmount() { 1942 var _a; 1943 (_a = this.stopObserver) == null ? void 0 : _a.call(this); 1944 this.hasEnteredView = false;
1945 this.isInView = false; 1946 } 1947} 1948function hasViewportOptionChanged({ viewport = {} }, { viewport: prevViewport = {} } = {}) { 1949 return (name) => viewport[name] !== prevViewport[name]; 1950} 1951const gestureAnimations = { 1952 inView: { 1953 Feature: InViewFeature 1954 }, 1955 tap: { 1956 Feature: PressGesture 1957 }, 1958 focus: { 1959 Feature: FocusGesture 1960 }, 1961 hover: { 1962 Feature: HoverGesture 1963 } 1964}; 1965const layout = { 1966 layout: { 1967 ProjectionNode: HTMLProjectionNode, 1968 MeasureLayout 1969 } 1970}; 1971const featureBundle = { 1972 ...animations, 1973 ...gestureAnimations, 1974 ...drag, 1975 ...layout 1976}; 1977const motion = /* @__PURE__ */ createMotionProxy(featureBundle, createDomVisualElement); 1978function useAnimationFrame(callback) { 1979 const initialTimestamp = reactExports.useRef(0); 1980 const { isStatic } = reactExports.useContext(MotionConfigContext); 1981 reactExports.useEffect(() => { 1982 if (isStatic) 1983 return; 1984 const provideTimeSinceStart = ({ timestamp, delta }) => { 1985 if (!initialTimestamp.current) 1986 initialTimestamp.current = timestamp; 1987 callback(timestamp - initialTimestamp.current, delta); 1988 }; 1989 frame.update(provideTimeSinceStart, true); 1990 return () => cancelFrame(provideTimeSinceStart); 1991 }, [callback]); 1992} 1993export { 1994 AnimatePresence as A, 1995 motion as m, 1996 useAnimationFrame as u 1997};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.