CircleType
A JavaScript library that lets you curve type on the web.
Demo: https://circletype.labwire.ca
Installation
In a browser:
Using npm:
$ npm i circletype --save
Load ES module:
;
API
CircleType
A CircleType instance creates a circular text element.
Kind: global class
- CircleType
- new CircleType(elem, [splitter])
- .radius(value) ⇒
CircleType
- .radius() ⇒
number
- .dir(value) ⇒
CircleType
- .dir() ⇒
number
- .forceWidth(value) ⇒
CircleType
- .forceWidth() ⇒
boolean
- .forceHeight(value) ⇒
CircleType
- .forceHeight() ⇒
boolean
- .refresh() ⇒
CircleType
- .destroy() ⇒
CircleType
new CircleType(elem, [splitter])
Param | Type | Description |
---|---|---|
elem | HTMLElement |
A target HTML element. |
[splitter] | function |
An optional function used to split the element's text content into individual characters |
Example
// Instantiate `CircleType` with an HTML element.const circleType = document; // Set the text radius and direction. Note: setter methods are chainable.circleTypedir-1; // Provide your own splitter function to handle emojis// @see https://github.com/orling/grapheme-splitterconst splitter = document splittersplitGraphemes;
CircleType
circleType.radius(value) ⇒ Sets the desired text radius. The minimum radius is the radius required
for the text to form a complete circle. If value
is less than the minimum
radius, the minimum radius is used.
Kind: instance method of CircleType
Returns: CircleType
- The current instance.
Param | Type | Description |
---|---|---|
value | number |
A new text radius in pixels. |
Example
const circleType = document; // Set the radius to 150 pixels.circleType;
number
circleType.radius() ⇒ Gets the text radius in pixels. The default radius is the radius required for the text to form a complete circle.
Kind: instance method of CircleType
Returns: number
- The current text radius.
Example
const circleType = document; circleType;//=> 150
CircleType
circleType.dir(value) ⇒ Sets the text direction. 1
is clockwise, -1
is counter-clockwise.
Kind: instance method of CircleType
Returns: CircleType
- The current instance.
Param | Type | Description |
---|---|---|
value | number |
A new text direction. |
Example
const circleType = document; // Set the direction to counter-clockwise.circleTypedir-1; // Set the direction to clockwise.circleTypedir1;
number
circleType.dir() ⇒ Gets the text direction. 1
is clockwise, -1
is counter-clockwise.
Kind: instance method of CircleType
Returns: number
- The current text radius.
Example
const circleType = document; circleTypedir;//=> 1 (clockwise)
CircleType
circleType.forceWidth(value) ⇒ Sets the forceWidth
option. If true
the width of the arc is calculated
and applied to the element as an inline style.
Kind: instance method of CircleType
Returns: CircleType
- The current instance.
Param | Type | Description |
---|---|---|
value | boolean |
true if the width should be set |
Example
const circleType = document; circleType; console;//=> <div style="position: relative; height: 3.18275em;">...</div> // Enable the force width optioncircleType; console;//=> <div style="position: relative; height: 3.18275em; width: 12.7473em;">...</div>
boolean
circleType.forceWidth() ⇒ Gets the forceWidth
option. If true
the width of the arc is calculated
and applied to the element as an inline style. Defaults to false
.
Kind: instance method of CircleType
Returns: boolean
- The current forceWidth
value
Example
const circleType = document; circleType;//=> false
CircleType
circleType.forceHeight(value) ⇒ Sets the forceHeight
option. If true
the height of the arc is calculated
and applied to the element as an inline style.
Kind: instance method of CircleType
Returns: CircleType
- The current instance.
Param | Type | Description |
---|---|---|
value | boolean |
true if the height should be set |
Example
const circleType = document; circleType; console;//=> <div style="position: relative; height: 3.18275em;">...</div> // Disable the force height optioncircleType; console;//=> <div style="position: relative;">...</div>
boolean
circleType.forceHeight() ⇒ Gets the forceHeight
option. If true
the height of the arc is calculated
and applied to the element as an inline style. Defaults to true
.
Kind: instance method of CircleType
Returns: boolean
- The current forceHeight
value
Example
const circleType = document; circleType;//=> true
CircleType
circleType.refresh() ⇒ Schedules a task to recalculate the height of the element. This should be called if the font size is ever changed.
Kind: instance method of CircleType
Returns: CircleType
- The current instance.
Example
const circleType = document; circleType;
CircleType
circleType.destroy() ⇒ Removes the CircleType effect from the element, restoring it to its original state.
Kind: instance method of CircleType
Returns: CircleType
- This instance.
Example
const circleType = document; // Restore `myElement` to its original state.circleType;
Development Commands
Command | Description |
---|---|
npm run dev |
Start dev server |
npm start |
Build for release |
npm test |
Run unit and screenshot tests |
npm run docs |
Generate documentation |
npm run reference |
Generate reference screenshots |