{"version":3,"file":"SVGVisualElement.mjs","sources":["../../../../src/render/svg/SVGVisualElement.ts"],"sourcesContent":["import type { AnyResolvedKeyframe } from \"../../animation/types\"\nimport type { MotionValue } from \"../../value\"\nimport type { MotionNodeOptions } from \"../../node/types\"\nimport { transformProps } from \"../utils/keys-transform\"\nimport { getDefaultValueType } from \"../../value/types/maps/defaults\"\nimport { createBox } from \"../../projection/geometry/models\"\nimport { DOMVisualElement } from \"../dom/DOMVisualElement\"\nimport { defaultTransformValue } from \"../dom/parse-transform\"\nimport type { DOMVisualElementOptions } from \"../dom/types\"\nimport { camelToDash } from \"../dom/utils/camel-to-dash\"\nimport type { ResolvedValues } from \"../types\"\nimport type { VisualElement, MotionStyle } from \"../VisualElement\"\nimport { SVGRenderState } from \"./types\"\nimport { buildSVGAttrs, cssStyleProperties } 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\"\nexport class SVGVisualElement extends DOMVisualElement<\n SVGElement,\n SVGRenderState,\n DOMVisualElementOptions\n> {\n type = \"svg\"\n\n isSVGTag = false\n\n getBaseTargetFromProps(\n props: MotionNodeOptions,\n key: string\n ): AnyResolvedKeyframe | MotionValue | undefined {\n /**\n * An independent transform's base is never an attribute of the same\n * name, e.g. is a position, not a translate. Like HTML it\n * comes from style, falling back to the transform's default.\n */\n return transformProps.has(key)\n ? super.getBaseTargetFromProps(props, key) ??\n defaultTransformValue(key)\n : props[key as keyof MotionNodeOptions]\n }\n\n /**\n * An independent transform's origin is never read from the DOM, so it\n * starts from its latest or default value and renders on mount.\n */\n getDefaultValue(key: string) {\n return transformProps.has(key)\n ? this.latestValues[key] ?? defaultTransformValue(key)\n : undefined\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\n if (cssStyleProperties.includes(key)) {\n const computedStyle = getComputedStyle(instance)\n const value = computedStyle[key as keyof typeof computedStyle]\n if (typeof value === \"string\" && value) return value.trim()\n }\n\n key = !camelCaseAttributes.has(key) ? camelToDash(key) : key\n return instance.getAttribute(key)\n }\n\n measureInstanceViewportBox = createBox\n\n scrapeMotionValuesFromProps(\n props: MotionNodeOptions,\n prevProps: MotionNodeOptions,\n visualElement: VisualElement\n ) {\n return scrapeMotionValuesFromProps(props, prevProps, visualElement)\n }\n\n build(\n renderState: SVGRenderState,\n latestValues: ResolvedValues,\n props: MotionNodeOptions\n ) {\n buildSVGAttrs(\n renderState,\n latestValues,\n this.isSVGTag,\n props.transformTemplate,\n (props as any).style\n )\n }\n\n renderInstance(\n instance: SVGElement,\n renderState: SVGRenderState,\n styleProp?: MotionStyle | undefined,\n projection?: any\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":";;;;;;;;;;;;AAkBM,MAAO,gBAAiB,SAAQ,gBAIrC,CAAA;AAJD,IAAA,WAAA,GAAA;;QAKI,IAAA,CAAA,IAAI,GAAG,KAAK;QAEZ,IAAA,CAAA,QAAQ,GAAG,KAAK;QA2ChB,IAAA,CAAA,0BAA0B,GAAG,SAAS;IAqC1C;IA9EI,sBAAsB,CAClB,KAAwB,EACxB,GAAW,EAAA;AAEX;;;;AAIG;AACH,QAAA,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG;cACvB,KAAK,CAAC,sBAAsB,CAAC,KAAK,EAAE,GAAG,CAAC;gBACpC,qBAAqB,CAAC,GAAG;AAC/B,cAAE,KAAK,CAAC,GAA8B,CAAC;IAC/C;AAEA;;;AAGG;AACH,IAAA,eAAe,CAAC,GAAW,EAAA;AACvB,QAAA,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG;cACvB,IAAI,CAAC,YA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