@yamada-ui/motion
Version:
Yamada UI motion components
1 lines • 1.71 kB
Source Map (JSON)
{"version":3,"sources":["../src/factory.ts"],"sourcesContent":["import type { StyledOptions } from \"@yamada-ui/core\"\nimport type { ComponentType, ForwardRefExoticComponent } from \"react\"\nimport type { MotionAs, MotionComponents, MotionFactory } from \"./motion.types\"\nimport { styled } from \"@yamada-ui/core\"\nimport { motion as _motion } from \"motion/react\"\n\ninterface Factory extends MotionFactory, MotionComponents {}\n\nfunction factory() {\n const cache = new Map<MotionAs, ComponentType<any>>()\n\n return new Proxy(styled, {\n apply: (_target, _thisArg, [el, options]: [MotionAs, StyledOptions]) => {\n const component = styled(el, options) as ForwardRefExoticComponent<any>\n\n return _motion.create(component)\n },\n\n get: (_target, el: MotionAs) => {\n if (!cache.has(el)) {\n const component = styled(el) as ForwardRefExoticComponent<any>\n\n cache.set(el, _motion.create(component))\n }\n\n return cache.get(el)\n },\n }) as Factory\n}\n\n/**\n * `motion` is a component that allows for the easy implementation of a wide variety of animations.\n *\n * @see Docs https://yamada-ui.com/components/other/motion\n */\nexport const motion = factory()\n"],"mappings":";;;AAGA,SAAS,cAAc;AACvB,SAAS,UAAU,eAAe;AAIlC,SAAS,UAAU;AACjB,QAAM,QAAQ,oBAAI,IAAkC;AAEpD,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,OAAO,CAAC,SAAS,UAAU,CAAC,IAAI,OAAO,MAAiC;AACtE,YAAM,YAAY,OAAO,IAAI,OAAO;AAEpC,aAAO,QAAQ,OAAO,SAAS;AAAA,IACjC;AAAA,IAEA,KAAK,CAAC,SAAS,OAAiB;AAC9B,UAAI,CAAC,MAAM,IAAI,EAAE,GAAG;AAClB,cAAM,YAAY,OAAO,EAAE;AAE3B,cAAM,IAAI,IAAI,QAAQ,OAAO,SAAS,CAAC;AAAA,MACzC;AAEA,aAAO,MAAM,IAAI,EAAE;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAOO,IAAM,SAAS,QAAQ;","names":[]}