UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

1 lines 3.8 kB
{"version":3,"file":"HTMLVisualElement.mjs","sources":["../../../../src/render/html/HTMLVisualElement.ts"],"sourcesContent":["import {\n AnyResolvedKeyframe,\n defaultTransformValue,\n isCSSVariableName,\n readTransformValue,\n transformProps,\n} from \"motion-dom\"\nimport type { Box } from \"motion-utils\"\nimport { MotionConfigContext } from \"../../context/MotionConfigContext\"\nimport { MotionProps } from \"../../motion/types\"\nimport { measureViewportBox } from \"../../projection/utils/measure\"\nimport { DOMVisualElement } from \"../dom/DOMVisualElement\"\nimport { DOMVisualElementOptions } from \"../dom/types\"\nimport type { ResolvedValues } from \"../types\"\nimport { VisualElement } from \"../VisualElement\"\nimport { HTMLRenderState } from \"./types\"\nimport { buildHTMLStyles } from \"./utils/build-styles\"\nimport { renderHTML } from \"./utils/render\"\nimport { scrapeMotionValuesFromProps } from \"./utils/scrape-motion-values\"\n\nexport function getComputedStyle(element: HTMLElement) {\n return window.getComputedStyle(element)\n}\n\nexport class HTMLVisualElement extends DOMVisualElement<\n HTMLElement,\n HTMLRenderState,\n DOMVisualElementOptions\n> {\n type = \"html\"\n\n readValueFromInstance(\n instance: HTMLElement,\n key: string\n ): AnyResolvedKeyframe | null | undefined {\n if (transformProps.has(key)) {\n return this.projection?.isProjecting\n ? defaultTransformValue(key)\n : readTransformValue(instance, key)\n } else {\n const computedStyle = getComputedStyle(instance)\n const value =\n (isCSSVariableName(key)\n ? computedStyle.getPropertyValue(key)\n : computedStyle[key as keyof typeof computedStyle]) || 0\n\n return typeof value === \"string\" ? value.trim() : (value as number)\n }\n }\n\n measureInstanceViewportBox(\n instance: HTMLElement,\n { transformPagePoint }: MotionProps & Partial<MotionConfigContext>\n ): Box {\n return measureViewportBox(instance, transformPagePoint)\n }\n\n build(\n renderState: HTMLRenderState,\n latestValues: ResolvedValues,\n props: MotionProps\n ) {\n buildHTMLStyles(renderState, latestValues, props.transformTemplate)\n }\n\n scrapeMotionValuesFromProps(\n props: MotionProps,\n prevProps: MotionProps,\n visualElement: VisualElement\n ) {\n return scrapeMotionValuesFromProps(props, prevProps, visualElement)\n }\n\n renderInstance = renderHTML\n}\n"],"names":[],"mappings":";;;;;;;AAoBM,SAAU,gBAAgB,CAAC,OAAoB,EAAA;AACjD,IAAA,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;AAC3C,CAAC;AAEK,MAAO,iBAAkB,SAAQ,gBAItC,CAAA;AAJD,IAAA,WAAA,GAAA;;QAKI,IAAI,CAAA,IAAA,GAAG,MAAM,CAAA;QA4Cb,IAAc,CAAA,cAAA,GAAG,UAAU,CAAA;KAC9B;IA3CG,qBAAqB,CACjB,QAAqB,EACrB,GAAW,EAAA;AAEX,QAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,YAAA,OAAO,IAAI,CAAC,UAAU,EAAE,YAAY;AAChC,kBAAE,qBAAqB,CAAC,GAAG,CAAC;AAC5B,kBAAE,kBAAkB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;SAC1C;aAAM;AACH,YAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AAChD,YAAA,MAAM,KAAK,GACP,CAAC,iBAAiB,CAAC,GAAG,CAAC;AACnB,kBAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC;kBACnC,aAAa,CAAC,GAAiC,CAAC,KAAK,CAAC,CAAA;AAEhE,YAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,GAAI,KAAgB,CAAA;SACtE;KACJ;AAED,IAAA,0BAA0B,CACtB,QAAqB,EACrB,EAAE,kBAAkB,EAA8C,EAAA;AAElE,QAAA,OAAO,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAA;KAC1D;AAED,IAAA,KAAK,CACD,WAA4B,EAC5B,YAA4B,EAC5B,KAAkB,EAAA;QAElB,eAAe,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAA;KACtE;AAED,IAAA,2BAA2B,CACvB,KAAkB,EAClB,SAAsB,EACtB,aAA4B,EAAA;QAE5B,OAAO,2BAA2B,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAA;KACtE;AAGJ;;;;"}