Class ClipPath

java.lang.Object
com.oorian.css.ClipPath

public class ClipPath extends Object
A builder for composing CSS clip-path property values.

ClipPath provides a type-safe, fluent API for building CSS clip-path strings. Only one shape can be active at a time — each shape method replaces the current value.

Usage:


 // Circle clip
 element.setClipPath(new ClipPath().circle("50%"));
 // Result: clip-path: circle(50%)

 // Polygon clip (triangle)
 element.setClipPath(new ClipPath()
     .polygon("50% 0%", "100% 100%", "0% 100%"));
 // Result: clip-path: polygon(50% 0%, 100% 100%, 0% 100%)

 // Inset with rounded corners
 element.setClipPath(new ClipPath()
     .insetRound("10px 20px 30px 40px", "5px"));
 // Result: clip-path: inset(10px 20px 30px 40px round 5px)

 // Use with CssRule
 CssRule rule = new CssRule(".clipped");
 rule.setClipPath(new ClipPath().ellipse("50%", "40%"));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ClipPath

      public ClipPath()
      Constructs an empty ClipPath.
  • Method Details

    • circle

      public ClipPath circle(String radius)
      Sets a circle() clip shape.
      Parameters:
      radius - the circle radius (e.g., "50%", "100px", "closest-side")
      Returns:
      this ClipPath for method chaining
    • circle

      public ClipPath circle(int pixels)
      Sets a circle() clip shape with a pixel radius.
      Parameters:
      pixels - the circle radius in pixels
      Returns:
      this ClipPath for method chaining
    • circle

      public ClipPath circle(Units radius)
      Sets a circle() clip shape with a Units radius.
      Parameters:
      radius - the circle radius as a Units value (e.g., new Px(100), new Percent(50))
      Returns:
      this ClipPath for method chaining
    • circleAt

      public ClipPath circleAt(String radius, String position)
      Sets a circle() clip shape with a position.
      Parameters:
      radius - the circle radius (e.g., "50%", "100px")
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • circleAt

      public ClipPath circleAt(int pixels, String position)
      Sets a circle() clip shape with a pixel radius and position.
      Parameters:
      pixels - the circle radius in pixels
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • circleAt

      public ClipPath circleAt(Units radius, String position)
      Sets a circle() clip shape with a Units radius and position.
      Parameters:
      radius - the circle radius as a Units value
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • ellipse

      public ClipPath ellipse(String rx, String ry)
      Sets an ellipse() clip shape.
      Parameters:
      rx - the horizontal radius (e.g., "50%", "100px")
      ry - the vertical radius (e.g., "40%", "80px")
      Returns:
      this ClipPath for method chaining
    • ellipse

      public ClipPath ellipse(int rx, int ry)
      Sets an ellipse() clip shape with pixel radii.
      Parameters:
      rx - the horizontal radius in pixels
      ry - the vertical radius in pixels
      Returns:
      this ClipPath for method chaining
    • ellipse

      public ClipPath ellipse(Units rx, Units ry)
      Sets an ellipse() clip shape with Units radii.
      Parameters:
      rx - the horizontal radius as a Units value
      ry - the vertical radius as a Units value
      Returns:
      this ClipPath for method chaining
    • ellipseAt

      public ClipPath ellipseAt(String rx, String ry, String position)
      Sets an ellipse() clip shape with a position.
      Parameters:
      rx - the horizontal radius (e.g., "50%")
      ry - the vertical radius (e.g., "40%")
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • ellipseAt

      public ClipPath ellipseAt(int rx, int ry, String position)
      Sets an ellipse() clip shape with pixel radii and a position.
      Parameters:
      rx - the horizontal radius in pixels
      ry - the vertical radius in pixels
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • ellipseAt

      public ClipPath ellipseAt(Units rx, Units ry, String position)
      Sets an ellipse() clip shape with Units radii and a position.
      Parameters:
      rx - the horizontal radius as a Units value
      ry - the vertical radius as a Units value
      position - the center position (e.g., "50% 50%", "center")
      Returns:
      this ClipPath for method chaining
    • inset

      public ClipPath inset(String values)
      Sets an inset() clip shape.
      Parameters:
      values - the inset values (e.g., "10px", "10px 20px 30px 40px")
      Returns:
      this ClipPath for method chaining
    • inset

      public ClipPath inset(int pixels)
      Sets a uniform inset() clip shape with a pixel value.
      Parameters:
      pixels - the uniform inset distance in pixels
      Returns:
      this ClipPath for method chaining
    • inset

      public ClipPath inset(Units inset)
      Sets a uniform inset() clip shape with a Units value.
      Parameters:
      inset - the uniform inset distance as a Units value
      Returns:
      this ClipPath for method chaining
    • inset

      public ClipPath inset(int top, int right, int bottom, int left)
      Sets an inset() clip shape with individual pixel values for each side.
      Parameters:
      top - the top inset in pixels
      right - the right inset in pixels
      bottom - the bottom inset in pixels
      left - the left inset in pixels
      Returns:
      this ClipPath for method chaining
    • inset

      public ClipPath inset(Units top, Units right, Units bottom, Units left)
      Sets an inset() clip shape with individual Units values for each side.
      Parameters:
      top - the top inset as a Units value
      right - the right inset as a Units value
      bottom - the bottom inset as a Units value
      left - the left inset as a Units value
      Returns:
      this ClipPath for method chaining
    • insetRound

      public ClipPath insetRound(String values, String borderRadius)
      Sets an inset() clip shape with rounded corners.
      Parameters:
      values - the inset values (e.g., "10px 20px 30px 40px")
      borderRadius - the border-radius for the inset (e.g., "5px", "10px 20px")
      Returns:
      this ClipPath for method chaining
    • insetRound

      public ClipPath insetRound(int pixels, int borderRadiusPx)
      Sets an inset() clip shape with a pixel inset and pixel border radius.
      Parameters:
      pixels - the uniform inset distance in pixels
      borderRadiusPx - the border-radius in pixels
      Returns:
      this ClipPath for method chaining
    • polygon

      public ClipPath polygon(String... points)
      Sets a polygon() clip shape.
      Parameters:
      points - the polygon vertex points (e.g., "50% 0%", "100% 100%", "0% 100%")
      Returns:
      this ClipPath for method chaining
    • path

      public ClipPath path(String svgPath)
      Sets a path() clip shape using an SVG path string.
      Parameters:
      svgPath - the SVG path data (e.g., "M0,0 L100,0 L100,100 Z")
      Returns:
      this ClipPath for method chaining
    • url

      public ClipPath url(String url)
      Sets a url() reference to an SVG clipPath element.
      Parameters:
      url - the URL or fragment reference (e.g., "#clipId", "clip.svg#myClip")
      Returns:
      this ClipPath for method chaining
    • toString

      public String toString()
      Returns the CSS clip-path string.
      Overrides:
      toString in class Object
      Returns:
      the clip-path value, or "none" if no shape has been set