All files / src/render/svg visual-element.ts

93.75% Statements 15/16
80% Branches 8/10
66.67% Functions 2/3
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4533x 33x   33x   33x 33x 33x 33x 33x 33x   33x                       2x 1x   1x 1x           11x                    
import { visualElement } from ".."
import { scrapeMotionValuesFromProps } from "./utils/scrape-motion-values"
import { SVGRenderState } from "./types"
import { htmlConfig } from "../html/visual-element"
import { DOMVisualElementOptions } from "../dom/types"
import { buildSVGAttrs } from "./utils/build-attrs"
import { camelToDash } from "../dom/utils/camel-to-dash"
import { camelCaseAttributes } from "./utils/camel-case-attrs"
import { isTransformProp } from "../html/utils/transform"
import { renderSVG } from "./utils/render"
import { getDefaultValueType } from "../dom/value-types/defaults"
 
export const svgVisualElement = visualElement<
    SVGElement,
    SVGRenderState,
    DOMVisualElementOptions
>({
    ...(htmlConfig as any),
 
    getBaseTarget(props, key) {
        return props[key]
    },
 
    readValueFromInstance(domElement, key) {
        if (isTransformProp(key)) {
            return getDefaultValueType(key)?.default || 0
        }
        key = !camelCaseAttributes.has(key) ? camelToDash(key) : key
        return domElement.getAttribute(key)
    },
 
    scrapeMotionValuesFromProps,
 
    build(_element, renderState, latestValues, options, props) {
        buildSVGAttrs(
            renderState,
            latestValues,
            options,
            props.transformTemplate
        )
    },
 
    render: renderSVG,
})