JS API

shape(code)

A polygon() value, or a shape() when round curves the corners, from the same code as @shape, as a string, without a doodle. It comes from css-doodle/generator, with the other generator exports.

Syntax

  • import { shape } from 'css-doodle/generator'
  • shape('<preset> [<k>]')
  • shape('<command>: <value>; ...')

The presets and commands are those of @shape. Several arguments are read as one list of commands. Other @ functions such as @r do not run, so the same code always gives the same shape. Without code, or with an unknown name, the result is a triangle.

Examples

import { shape } from 'css-doodle/generator';

shape('clover 4');
// 'polygon(99% 50%,…)'

shape('square; round: .5');
// 'shape(from …,curve to … with …,…,close)'

element.style.clipPath = shape(`
  points: 5;
  r: cos(5t);
`);

See also