fix: integrate add clipPath into element.go
This commit is contained in:
parent
a96bb2c0be
commit
dd1824c4dc
3 changed files with 10 additions and 10 deletions
|
|
@ -3,7 +3,6 @@ package d2svg
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/d2themes"
|
"oss.terrastruct.com/d2/d2themes"
|
||||||
|
|
@ -18,10 +17,7 @@ func classHeader(labelMaskID string, shape d2target.Shape, box *geo.Box, text st
|
||||||
rectEl.Width, rectEl.Height = box.Width, box.Height
|
rectEl.Width, rectEl.Height = box.Width, box.Height
|
||||||
rectEl.Fill = shape.Fill
|
rectEl.Fill = shape.Fill
|
||||||
rectEl.ClassName = "class_header"
|
rectEl.ClassName = "class_header"
|
||||||
str := rectEl.Render()
|
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID))
|
||||||
if shape.BorderRadius != 0 {
|
|
||||||
str = strings.Replace(str, "/>", fmt.Sprintf(`clip-path="url(#%v-%v)" />`, labelMaskID, shape.ID), 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if text != "" {
|
if text != "" {
|
||||||
tl := label.InsideMiddleCenter.GetPointOnBox(
|
tl := label.InsideMiddleCenter.GetPointOnBox(
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package d2svg
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/d2themes"
|
"oss.terrastruct.com/d2/d2themes"
|
||||||
|
|
@ -47,10 +46,7 @@ func tableHeader(labelMaskID string, shape d2target.Shape, box *geo.Box, text st
|
||||||
rectEl.Width, rectEl.Height = box.Width, box.Height
|
rectEl.Width, rectEl.Height = box.Width, box.Height
|
||||||
rectEl.Fill = shape.Fill
|
rectEl.Fill = shape.Fill
|
||||||
rectEl.ClassName = "class_header"
|
rectEl.ClassName = "class_header"
|
||||||
str := rectEl.Render()
|
str := rectEl.RenderWithClipPath(fmt.Sprintf("%v-%v", labelMaskID, shape.ID))
|
||||||
if shape.BorderRadius != 0 {
|
|
||||||
str = strings.Replace(str, "/>", fmt.Sprintf(`clip-path="url(#%v-%v)" />`, labelMaskID, shape.ID), 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if text != "" {
|
if text != "" {
|
||||||
tl := label.InsideMiddleLeft.GetPointOnBox(
|
tl := label.InsideMiddleLeft.GetPointOnBox(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package d2themes
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/color"
|
"oss.terrastruct.com/d2/lib/color"
|
||||||
)
|
)
|
||||||
|
|
@ -100,6 +101,13 @@ func (el *ThemableElement) SetMaskUrl(url string) {
|
||||||
el.Mask = fmt.Sprintf("url(#%s)", url)
|
el.Mask = fmt.Sprintf("url(#%s)", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (el *ThemableElement) RenderWithClipPath(id string) string {
|
||||||
|
out := el.Render()
|
||||||
|
out = strings.Replace(out, "/>", fmt.Sprintf(`clip-path="url(#%v)" />`, id), 1)
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func (el *ThemableElement) Render() string {
|
func (el *ThemableElement) Render() string {
|
||||||
out := "<" + el.tag
|
out := "<" + el.tag
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue