...

Source file src/oss.terrastruct.com/d2/d2themes/sketch_overlay.go

Documentation: oss.terrastruct.com/d2/d2themes

     1  package d2themes
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"oss.terrastruct.com/d2/lib/color"
     7  )
     8  
     9  type ThemableSketchOverlay struct {
    10  	el   *ThemableElement
    11  	fill string
    12  }
    13  
    14  func NewThemableSketchOverlay(el *ThemableElement, fill string) *ThemableSketchOverlay {
    15  	return &ThemableSketchOverlay{
    16  		el,
    17  		fill,
    18  	}
    19  }
    20  
    21  // TODO we can just call el.Copy() to prevent that
    22  // WARNING: Do not reuse the element afterwards as this function changes the Class property
    23  func (o *ThemableSketchOverlay) Render() (string, error) {
    24  	if color.IsThemeColor(o.fill) {
    25  		o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", o.fill) // e.g. sketch-overlay-B3
    26  	} else {
    27  		lc, err := color.LuminanceCategory(o.fill)
    28  		if err != nil {
    29  			return "", err
    30  		}
    31  		o.el.ClassName += fmt.Sprintf(" sketch-overlay-%s", lc) // e.g. sketch-overlay-dark
    32  	}
    33  
    34  	return o.el.Render(), nil
    35  }
    36  

View as plain text