regl-shape
Version:
2D shape shader for regl
53 lines (52 loc) • 2.11 kB
TypeScript
import { Regl, Buffer, Texture2D, BoundingBox } from "regl";
import { InputColor } from "color-normalize";
import { Bounds } from "array-bounds";
export declare enum JoinStyle {
Bevel = "bevel",
Round = "round",
Rect = "rect"
}
export declare type ShapeProps = {
/** Number of points to in the shape. */
count: number;
/** Stroke color of the shape. Can either be a single color or an array of colors containing a color for every point in the shape. The format of a single color is either a CSS color string or an array with `0..1` values, eg. `"red"` or `[0, 0, 0, 1]`. */
color: InputColor | InputColor[];
/** Fill area enclosed by line with defined color. */
fill: InputColor | null;
/** Transparency of the shape's stroke (`0..1`). */
opacity: number;
/** Thickness of the shape's stroke in px (`>0`). */
thickness: number;
/** Array with dash lengths in px, altering color/space pairs, ie. `[2,10, 5,10, ...]`. `null` corresponds to solid line. */
dashes: number[] | null;
/** Join style: `"rect"`, `"round"`, `"bevel"`. Applied to caps too. */
join: JoinStyle;
/** Max ratio of the join length to the thickness. */
miterLimit: number;
/** Connect last point with the first point with a stroke. */
close: boolean;
/** Enable overlay of line segments. */
overlay: boolean;
/** Visible data range. */
range: Bounds;
/** Area within canvas. */
viewport: BoundingBox;
/** Value for the z-axis of the shapes position. */
depth: number;
};
export interface InnerShapeProps extends ShapeProps {
scale: number[];
scaleFract: number[];
translate: number[];
translateFract: number[];
dashLength: number;
dashTexture: Texture2D;
colorBuffer: Buffer;
positionBuffer: Buffer;
positionFractBuffer: Buffer;
triangles: number[] | null;
fillColor: Uint8Array | null;
}
export default function (regl: Regl): {
createShape(points: Float64Array, initialPartialProps?: Partial<ShapeProps> | undefined): (partialProps?: Partial<ShapeProps> | undefined) => void;
};