1.0.0 • Published 3 years ago

compodraw-instructs v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Basic CompoDraw JS Drawing Instructions

Provides essential instructs for CompoDrawJS. With this instructs package, you can compose and draw basic shapes and visual effects like rectangle, ellipse, crop, move, rotate, and more.

How to Install

  1. Make sure CompoDrawJS already installed.
  2. Add to your project with Yarn:
    yarn add compodraw-instructs
    or with NPM:
    npm install compodraw-instructs --save
    or you can download the bundled JavaScript file for plain HTML or PHP project
  3. That's it! for more info, see reference below.

References

Crop

The fast way to remove excessive drawing. If you want cut other than in square, use Mask instead.

<crop
  x="0"  width="128"
  y="0"  height="128">

  <!-- Other instructs here... -->

</crop>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber128Value in pixels.
heightnumber128Value in pixels.
contentInstruct[][]Other instructs inside this are here.

Elevate

Like shadow, but you just have to set depth value to create realistic drop shadow.

<elevate
  depth="4" angle="0">

  <!-- Other instructs here... -->

</elevate>
PropertyData TypeDefault ValueDescription
depthnumber4Z axis depth perception, in pixel.
anglenumber0Angle of incoming light in degrees, 0 is from above.
contentInstruct[][]Other instructs inside this are here.

Ellipse

Draw an ellipse shape.

<ellipse
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.

EllipseStroke

Draw an ellipse outline.

<ellipse-stroke
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
  thickness="1"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.
thicknessnumber1Value in pixels.

GradientLinear

Fills linear gradient color to the containing shape.

<gradient
  startX="0"  endX="100"
  startY="0"  endY="100"
  points={0.0: "#000000", 1.0: "#ffffff"}>

  <!-- Other instructs here... -->

</gradient>

or

<gradient-linear
  startX="0"  endX="100"
  startY="0"  endY="100"
  points={0.0: "#000000", 1.0: "#ffffff"}>

  <!-- Other instructs here... -->

</gradient-linear>
PropertyData TypeDefault ValueDescription
startXnumber0Value in pixels.
startYnumber0Value in pixels.
endXnumber100Value in pixels.
endYnumber100Value in pixels.
pointsGradientPointsType{0.0: "#000000", 1.0: "#ffffff"}Position of colors, indices are between 0.0 and 1.0.
contentInstruct[][]Other instructs inside this are here.

GradientRadial

Fills radial gradient color to the containing shape.

<gradient-radial
  x="0" y="0" radius="100"
  points={0.0: "#000000", 1.0: "#ffffff"}>

  <!-- Other instructs here... -->

</gradient-radial>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
radiusnumber100Value in pixels.
pointsGradientPointsType{0.0: "#000000", 1.0: "#ffffff"}Position of colors, indices are between 0.0 and 1.0.
contentInstruct[][]Other instructs inside this are here.

Group

Stacks multiple instructions into one.

<group>
 <!-- Other instructs here... -->
</group>
PropertyData TypeDefault ValueDescription
contentInstruct[][]Other instructs inside this are here.

Image

Draw a fully loaded image, you have to make sure the source is completely downloaded before draw.

<image
  source={...}
  x="0"  width="0"
  y="0"  height="0"
/>
PropertyData TypeDefault ValueDescription
sourceCanvasImageSource?undefinedFully loaded SVG, image DOM, or bitmap
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumberNaNValue in pixels, set NaN to use original width.
heightnumberNaNValue in pixels, set NaN to use original height.

Mask

Like crop but you can use custom shape.

<mask
  shape={...}
  allowIntersect="false">

  <!-- Other instructs here... -->

</mask>
PropertyData TypeDefault ValueDescription
shapeInstruct or nullnullCustom shape, set null to deactivate masking.
allowIntersectbooleanfalseIf true, transparent color exist at intersection.
contentInstruct[][]Other instructs inside this are here.

Move

Add offset as big as (x, y) point.

<move x="0" y="0">
  <!-- Other instructs here... -->
</move>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.

Path

Draw custom shape based on array of vertices.

<path
  x="0"  width="NaN"
  y="0"  height="NaN"
  color="#000000">

  x: 10, y: 10;
  x: 10, y: 30, smooth;
  x: 30, y: 10;

</path>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumberNaNValue in pixels, set NaN to use original width.
heightnumberNaNValue in pixels, set NaN to use original height.
colorstring"#000000"CSS standard color.
verticesPathVertex[][]Array of vertices.
contentstring""Easy way to write vertices, as shown above.

PathStroke

Draw custom line path based on array of vertices.

<path-stroke
  x="0"  width="NaN"
  y="0"  height="NaN"
  color="#000000"
  thickness="1"
  sharp="false"
  autoConnect="false">

  x: 10, y: 10;
  x: 10, y: 30, smooth;
  x: 30, y: 10;

</path-stroke>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumberNaNValue in pixels, set NaN to use original width.
heightnumberNaNValue in pixels, set NaN to use original height.
colorstring"#000000"CSS standard color.
thicknessnumber1Value in pixels.
sharpbooleanfalseSet to true for sharp edges.
autoConnectbooleanfalseSet true to prevent unconnected path ends.
verticesPathStrokeVertex[][]Array of vertices.
contentstring""Easy way to write vertices, as shown above.

Rectangle

Draw a rectangle shape.

<rectangle
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.

RectangleStroke

Draw a rectangle shape.

<rectangle-stroke
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
  thickness="1"
  sharp="false"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.
thicknessnumber1Value in pixels.
sharpbooleanfalseSet to true for sharp edges.

RectangleRound

Draw a rounded rectangle shape.

<rectangle-round
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
  cornerRadius="16"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.
cornerRadiusnumber100Value in pixels.

RectangleRoundStroke

Draw a rounded rectangle outline.

<rectangle-round-stroke
  x="0"  width="100"
  y="0"  height="100"
  color="#000000"
  cornerRadius="16"
  thickness="1"
/>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
widthnumber100Value in pixels.
heightnumber100Value in pixels.
colorstring"#000000"CSS standard color.
cornerRadiusnumber100Value in pixels.
thicknessnumber1Value in pixels.

Rotate

Add angle of rotation with specified center point.

<rotate
  x="0" y="0"
  angle="0">

  <!-- Other instructs here... -->

</rotate>
PropertyData TypeDefault ValueDescription
xnumber0X axis center point, in pixels.
ynumber0Y axis center point, in pixels.
anglenumber0Value in degrees (0 - 359).
contentInstruct[][]Other instructs inside this are here.

Scale

Multiple the size of drawn graphics.

<scale x="1" y="1">
  <!-- Other instructs here... -->
</scale>
PropertyData TypeDefault ValueDescription
xnumber1.0Value in fraction.
ynumber1.0Value in fraction.
contentInstruct[][]Other instructs inside this are here.

Shadow

Give customizable shadow effects to drawn graphics.

<shadow
  blur="8"
  color="rgba(0,0,0,0.32)"
  x="4" y="4">

  <!-- Other instructs here... -->

</shadow>
PropertyData TypeDefault ValueDescription
blurnumber8Value in pixels.
colorstring"rgba(0,0,0,0.32)"CSS standard color.
xnumber0Value in pixels.
ynumber0Value in pixels.
contentInstruct[][]Other instructs inside this are here.

Text

Draw multiline or a single line of text with default fonts.

WARNING: If you are using JSX, put \n at the end of every line of text because JSX cannot recognize line-break automatically.

<text
  x="0" size="18"
  y="0" align="left"
  style="bold|italic"
  color="#000000">

  Lorem Ipsum
  Dolor Amet

</text>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
sizenumber18Value in pixels.
colorstring"rgba(0,0,0,0.32)"CSS standard color.
valuestring""Text string to be drawn.
stylestring""Can be "bold", "italic", or combination of them.
alignstring"left"It can be one of "left", "center", or "right".
valuestring""Text string to be drawn.
contentstring""Symbolic link to value.

TextStroke

Draw outlined multiline or a single line of text.

WARNING: If you are using JSX, put \n at the end of every line of text because JSX cannot recognize line-break automatically.

<text-stroke
  x="0" size="18"
  y="0" align="left"
  style="bold|italic"
  color="#000000"
  thickness="1">

  Lorem Ipsum
  Dolor Amet

</text-stroke>
PropertyData TypeDefault ValueDescription
xnumber0Value in pixels.
ynumber0Value in pixels.
sizenumber18Value in pixels.
colorstring"rgba(0,0,0,0.32)"CSS standard color.
valuestring""Text string to be drawn.
stylestring""Can be "bold", "italic", or combination of them.
alignstring"left"It can be one of "left", "center", or "right".
thicknessnumber1Value in pixels.
valuestring""Text string to be drawn.
contentstring""Symbolic link to value.

Transparent

Set transparency of specific drawing.

<transparent value="1">
  <!-- Other instructs here... -->
</transparent>
PropertyData TypeDefault ValueDescription
valuenumber1In fraction between 0.0 and 1.0.
contentInstruct[][]Other instructs inside this are here.