Class MaskElement

java.lang.Object
com.vaadin.flow.dom.Node<com.vaadin.flow.dom.Element>
com.vaadin.flow.dom.Element
org.vaadin.firitin.element.svg.SvgElement
org.vaadin.firitin.element.svg.MaskElement
All Implemented Interfaces:
Serializable

public class MaskElement extends SvgElement
A typed Java API for the SVG <mask> element.

The <mask> element defines an alpha mask for compositing the current object into the background. A mask is used to create transparency effects that are more complex than simple opacity.

Unlike clip paths which create hard edges, masks can create soft edges and gradual transparency using the luminance or alpha values of the mask contents.

Masks must be placed inside a <defs> element and referenced using the mask attribute (e.g., mask="url(#myMask)").

Write-Only vs Read-Write Methods

This class provides two variants for each attribute setter:

  • Default methods (e.g., x(), y()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved via getAttribute().
  • RW methods (e.g., xRW(), yRW()) - Use traditional setAttribute() which stores values on the server for later retrieval.
See Also:
  • Constructor Details

    • MaskElement

      public MaskElement()
    • MaskElement

      public MaskElement(String id)
      Creates a mask with the given ID.
      Parameters:
      id - the ID for referencing this mask
  • Method Details

    • x

      public MaskElement x(double x)
      Sets the x coordinate of the mask area.

      Uses write-only optimization. Use xRW(double) if you need to read the value back.

      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • x

      public MaskElement x(String x)
      Sets the x coordinate with a unit.

      Uses write-only optimization. Use xRW(String) if you need to read the value back.

      Parameters:
      x - the x coordinate (e.g., "-10%")
      Returns:
      this element for method chaining
    • xRW

      public MaskElement xRW(double x)
      Sets the x coordinate of the mask area (read-write).
      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • xRW

      public MaskElement xRW(String x)
      Sets the x coordinate with a unit (read-write).
      Parameters:
      x - the x coordinate (e.g., "-10%")
      Returns:
      this element for method chaining
    • y

      public MaskElement y(double y)
      Sets the y coordinate of the mask area.

      Uses write-only optimization. Use yRW(double) if you need to read the value back.

      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • y

      public MaskElement y(String y)
      Sets the y coordinate with a unit.

      Uses write-only optimization. Use yRW(String) if you need to read the value back.

      Parameters:
      y - the y coordinate (e.g., "-10%")
      Returns:
      this element for method chaining
    • yRW

      public MaskElement yRW(double y)
      Sets the y coordinate of the mask area (read-write).
      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • yRW

      public MaskElement yRW(String y)
      Sets the y coordinate with a unit (read-write).
      Parameters:
      y - the y coordinate (e.g., "-10%")
      Returns:
      this element for method chaining
    • width

      public MaskElement width(double width)
      Sets the width of the mask area.

      Uses write-only optimization. Use widthRW(double) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • width

      public MaskElement width(String width)
      Sets the width with a unit.

      Uses write-only optimization. Use widthRW(String) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width (e.g., "120%")
      Returns:
      this element for method chaining
    • widthRW

      public MaskElement widthRW(double width)
      Sets the width of the mask area (read-write).
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • widthRW

      public MaskElement widthRW(String width)
      Sets the width with a unit (read-write).
      Parameters:
      width - the width (e.g., "120%")
      Returns:
      this element for method chaining
    • height

      public MaskElement height(double height)
      Sets the height of the mask area.

      Uses write-only optimization. Use heightRW(double) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • height

      public MaskElement height(String height)
      Sets the height with a unit.

      Uses write-only optimization. Use heightRW(String) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height (e.g., "120%")
      Returns:
      this element for method chaining
    • heightRW

      public MaskElement heightRW(double height)
      Sets the height of the mask area (read-write).
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • heightRW

      public MaskElement heightRW(String height)
      Sets the height with a unit (read-write).
      Parameters:
      height - the height (e.g., "120%")
      Returns:
      this element for method chaining
    • bounds

      public MaskElement bounds(double x, double y, double width, double height)
      Sets the bounds of the mask area.

      Uses write-only optimization. Use boundsRW(double, double, double, double) if you need to read the values back.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • boundsRW

      public MaskElement boundsRW(double x, double y, double width, double height)
      Sets the bounds of the mask area (read-write).
      Parameters:
      x - the x coordinate
      y - the y coordinate
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • maskUnits

      public MaskElement maskUnits(MaskElement.MaskUnits units)
      Sets the coordinate system for x, y, width, height attributes.

      Uses write-only optimization. Use maskUnitsRW(MaskUnits) if you need to read the value back.

      Parameters:
      units - the mask units
      Returns:
      this element for method chaining
    • maskUnitsRW

      public MaskElement maskUnitsRW(MaskElement.MaskUnits units)
      Sets the coordinate system for x, y, width, height attributes (read-write).
      Parameters:
      units - the mask units
      Returns:
      this element for method chaining
    • maskContentUnits

      public MaskElement maskContentUnits(MaskElement.MaskUnits units)
      Sets the coordinate system for the mask contents.

      Uses write-only optimization. Use maskContentUnitsRW(MaskUnits) if you need to read the value back.

      Parameters:
      units - the mask content units
      Returns:
      this element for method chaining
    • maskContentUnitsRW

      public MaskElement maskContentUnitsRW(MaskElement.MaskUnits units)
      Sets the coordinate system for the mask contents (read-write).
      Parameters:
      units - the mask content units
      Returns:
      this element for method chaining
    • add

      public MaskElement add(SvgElement... elements)
      Adds content elements to this mask.

      White areas in the mask content will be fully visible, black areas will be fully transparent, and gray areas will be partially transparent.

      Parameters:
      elements - the elements that define the mask
      Returns:
      this element for method chaining