framer-motion
Version:
A simple and powerful JavaScript animation library
1 lines • 4.03 kB
Source Map (JSON)
{"version":3,"file":"SVGVisualElement.mjs","sources":["../../../../src/render/svg/SVGVisualElement.ts"],"sourcesContent":["import {\n AnyResolvedKeyframe,\n getDefaultValueType,\n MotionValue,\n transformProps,\n} from \"motion-dom\"\nimport { MotionProps, MotionStyle } from \"../../motion/types\"\nimport { createBox } from \"../../projection/geometry/models\"\nimport { IProjectionNode } from \"../../projection/node/types\"\nimport { DOMVisualElement } from \"../dom/DOMVisualElement\"\nimport { DOMVisualElementOptions } from \"../dom/types\"\nimport { camelToDash } from \"../dom/utils/camel-to-dash\"\nimport { ResolvedValues } from \"../types\"\nimport { VisualElement } from \"../VisualElement\"\nimport { SVGRenderState } from \"./types\"\nimport { buildSVGAttrs } from \"./utils/build-attrs\"\nimport { camelCaseAttributes } from \"./utils/camel-case-attrs\"\nimport { isSVGTag } from \"./utils/is-svg-tag\"\nimport { renderSVG } from \"./utils/render\"\nimport { scrapeMotionValuesFromProps } from \"./utils/scrape-motion-values\"\n\nexport class SVGVisualElement extends DOMVisualElement<\n SVGElement,\n SVGRenderState,\n DOMVisualElementOptions\n> {\n type = \"svg\"\n\n isSVGTag = false\n\n getBaseTargetFromProps(\n props: MotionProps,\n key: string\n ): AnyResolvedKeyframe | MotionValue<any> | undefined {\n return props[key as keyof MotionProps]\n }\n\n readValueFromInstance(instance: SVGElement, key: string) {\n if (transformProps.has(key)) {\n const defaultType = getDefaultValueType(key)\n return defaultType ? defaultType.default || 0 : 0\n }\n key = !camelCaseAttributes.has(key) ? camelToDash(key) : key\n return instance.getAttribute(key)\n }\n\n measureInstanceViewportBox = createBox\n\n scrapeMotionValuesFromProps(\n props: MotionProps,\n prevProps: MotionProps,\n visualElement: VisualElement\n ) {\n return scrapeMotionValuesFromProps(props, prevProps, visualElement)\n }\n\n build(\n renderState: SVGRenderState,\n latestValues: ResolvedValues,\n props: MotionProps\n ) {\n buildSVGAttrs(\n renderState,\n latestValues,\n this.isSVGTag,\n props.transformTemplate,\n props.style\n )\n }\n\n renderInstance(\n instance: SVGElement,\n renderState: SVGRenderState,\n styleProp?: MotionStyle | undefined,\n projection?: IProjectionNode<unknown> | undefined\n ): void {\n renderSVG(instance, renderState, styleProp, projection)\n }\n\n mount(instance: SVGElement) {\n this.isSVGTag = isSVGTag(instance.tagName)\n super.mount(instance)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBM,MAAO,gBAAiB,SAAQ,gBAIrC,CAAA;AAJD,IAAA,WAAA,GAAA;;QAKI,IAAI,CAAA,IAAA,GAAG,KAAK,CAAA;QAEZ,IAAQ,CAAA,QAAA,GAAG,KAAK,CAAA;QAkBhB,IAA0B,CAAA,0BAAA,GAAG,SAAS,CAAA;KAqCzC;IArDG,sBAAsB,CAClB,KAAkB,EAClB,GAAW,EAAA;AAEX,QAAA,OAAO,KAAK,CAAC,GAAwB,CAAC,CAAA;KACzC;IAED,qBAAqB,CAAC,QAAoB,EAAE,GAAW,EAAA;AACnD,QAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,YAAA,MAAM,WAAW,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAA;AAC5C,YAAA,OAAO,WAAW,GAAG,WAAW,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;SACpD;AACD,QAAA,GAAG,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;AAC5D,QAAA,OAAO,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;KACpC;AAID,IAAA,2BAA2B,CACvB,KAAkB,EAClB,SAAsB,EACtB,aAA4B,EAAA;QAE5B,OAAO,2BAA2B,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAA;KACtE;AAED,IAAA,KAAK,CACD,WAA2B,EAC3B,YAA4B,EAC5B,KAAkB,EAAA;AAElB,QAAA,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