import { TLDefaultColorTheme, TLGeoShape, TLShapeId, toDomPrecision } from '@bigbluebutton/editor' import * as React from 'react' import { ShapeFill, getShapeFillSvg, getSvgWithShapeFill, useDefaultColorTheme, } from '../../shared/ShapeFill' import { getPerfectDashProps } from '../../shared/getPerfectDashProps' import { getOvalPerimeter, getOvalSolidPath } from '../helpers' export const DashStyleOval = React.memo(function DashStyleOval({ w, h, strokeWidth: sw, dash, color, fill, }: Pick & { strokeWidth: number id: TLShapeId }) { const theme = useDefaultColorTheme() const d = getOvalSolidPath(w, h) const perimeter = getOvalPerimeter(w, h) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps( perimeter < 64 ? perimeter * 2 : perimeter, sw, { style: dash, snap: 4, start: 'outset', end: 'outset', closed: true, } ) return ( <> ) }) export function DashStyleOvalSvg({ w, h, strokeWidth: sw, dash, color, theme, fill, }: Pick & { strokeWidth: number id: TLShapeId theme: TLDefaultColorTheme }) { const d = getOvalSolidPath(w, h) const perimeter = getOvalPerimeter(w, h) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps( perimeter < 64 ? perimeter * 2 : perimeter, sw, { style: dash, snap: 4, closed: true, } ) const strokeElement = document.createElementNS('http://www.w3.org/2000/svg', 'path') strokeElement.setAttribute('d', d) strokeElement.setAttribute('stroke-width', sw.toString()) strokeElement.setAttribute('width', w.toString()) strokeElement.setAttribute('height', h.toString()) strokeElement.setAttribute('fill', 'none') strokeElement.setAttribute('stroke', theme[color].solid) strokeElement.setAttribute('stroke-dasharray', strokeDasharray) strokeElement.setAttribute('stroke-dashoffset', strokeDashoffset) // Get the fill element, if any const fillElement = getShapeFillSvg({ d, fill, color, theme, }) return getSvgWithShapeFill(strokeElement, fillElement) }