A JavaScript library that lets you curve type on the web.

Overview

CircleType

Build Status

A JavaScript library that lets you curve type on the web.

Demo: https://circletype.labwire.ca

Installation

In a browser:

<script src="circletype.min.js"></script>

Using npm:

$ npm i circletype --save

Load ES module:

import CircleType from `circletype`;

API

CircleType

A CircleType instance creates a circular text element.

Kind: global class

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 = new CircleType(document.getElementById('myElement'));

// Set the text radius and direction. Note: setter methods are chainable.
circleType.radius(200).dir(-1);

// Provide your own splitter function to handle emojis
// @see https://github.com/orling/grapheme-splitter
const splitter = new GraphemeSplitter()
new CircleType(
  document.getElementById('myElement'),
  splitter.splitGraphemes.bind(splitter)
);

circleType.radius(value) ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

// Set the radius to 150 pixels.
circleType.radius(150);

circleType.radius() ⇒ number

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 = new CircleType(document.getElementById('myElement'));

circleType.radius();
//=> 150

circleType.dir(value) ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

// Set the direction to counter-clockwise.
circleType.dir(-1);

// Set the direction to clockwise.
circleType.dir(1);

circleType.dir() ⇒ number

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 = new CircleType(document.getElementById('myElement'));

circleType.dir();
//=> 1 (clockwise)

circleType.forceWidth(value) ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

circleType.radius(384);

console.log(circleType.container);
//=> <div style="position: relative; height: 3.18275em;">...</div>

// Enable the force width option
circleType.forceWidth(true);

console.log(circleType.container);
//=> <div style="position: relative; height: 3.18275em; width: 12.7473em;">...</div>

circleType.forceWidth() ⇒ boolean

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 = new CircleType(document.getElementById('myElement'));

circleType.forceWidth();
//=> false

circleType.forceHeight(value) ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

circleType.radius(384);

console.log(circleType.container);
//=> <div style="position: relative; height: 3.18275em;">...</div>

// Disable the force height option
circleType.forceHeight(false);

console.log(circleType.container);
//=> <div style="position: relative;">...</div>

circleType.forceHeight() ⇒ boolean

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 = new CircleType(document.getElementById('myElement'));

circleType.forceHeight();
//=> true

circleType.refresh() ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

circleType.refresh();

circleType.destroy() ⇒ CircleType

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 = new CircleType(document.getElementById('myElement'));

// Restore `myElement` to its original state.
circleType.destroy();

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
Comments
  • Provide a callback which is executed once the transforms are completed

    Provide a callback which is executed once the transforms are completed

    I'm sure there are better ways to implement this, but I just thought I'd share a modification that I found useful. Any thoughts? You could equally employ something like $(elem).circleType({...}).then(function () {...}), but this was sufficient for my needs

    opened by soutar 5
  • Doesn't work with iOS emojis

    Doesn't work with iOS emojis

    This line https://github.com/peterhry/CircleType/blob/ffebbcc65803e1e203bde9522a8ff115de884b73/src/utils/splitNode.js#L13

    .split('')
    

    wrongly splits emojis in iOS webview, if you change to

    for (const char of trimmedText) {
      // char
    }
    

    it will work with iOS emojis

    bug wip 
    opened by brunolm 4
  • Bower

    Bower

    Hey Peter,

    Would you consider adding CircleType to Bower? I've put up an example manifest file but this PR is more just to see if you'd be interested

    http://bower.io/docs/creating-packages/

    opened by soutar 4
  • Fix for issue #129

    Fix for issue #129

    The function getBoundingClientRect() might return 0 for width or height when the element is an inline element. Setting a display type inline-block fixes this.

    opened by StephanWagner 3
  • circletype.min.js once work only when i reload the page

    circletype.min.js once work only when i reload the page

    Hi,

    I used circletype.min.js in my wordpress with in header :

    and i've created Html module with visual composer with : capture d ecran 2018-11-30 a 11 41 26

    When i load the page the tittle load bad (picture 1), but when i reload the tittle is good (picture2) ...

    picture-1 picture-2

    Can you help me please ?

    Thanks, Bastien

    opened by Hellobast 3
  • Semicolon error in npm installed with yarn

    Semicolon error in npm installed with yarn

    I have installed a version with bower and it is working. However, I have installed circleType with yarn in another project and, when i do gulp to generate the app.js file, the file generated does not work. The error is: TypeError: (intermediate value)(...) is not a function When i go to the file /node_modules/circletype.js/circletype.js i can see these last lines:

    if (document.readyState !== 'complete') { elem.style.visibility = 'hidden' $(window).on('load', function () { elem.style.visibility = 'visible' layout() }) } else { layout() } }) } })) If I manually add a semicolon at the end of the last line and i do the gulp process it works like a charm. In the bower version the file finish fine with semicolon.

    I have resolved the problem by placing circletype library at the last position of the gulpfile. This way there are no more libraries after circleType and there is no error. But I don't think this is a definitive solution.

    opened by hisie 3
  • New option `updateWidth`

    New option `updateWidth`

    Provide a new option updateWidth which, when true, will calculate the width of each element and apply it via an inline style. The option is false by default as it breaks the FitText example.

    Any thoughts?

    opened by soutar 3
  • Having trouble figuring out how to get the curved text to be spaced closer together

    Having trouble figuring out how to get the curved text to be spaced closer together

    Hey! First off just wanna say awesome job on a really helpful library, thanks!

    I was having trouble getting my text to be spaced closer together. I thought it would be simply by playing around with forceWidth and/or forceHeight (still not quite sure how these work), but nothing seems to be working. Here's the text I have right now:

    Screen Shot 2020-08-10 at 7 50 21 PM

    My goal is to get the letters to be spaced closer together so that the text curves up to only around the red lines pictured below. Is there any way to achieve this through the library and/or CSS?

    Screen Shot 2020-08-10 at 7 53 53 PM

    Edit: I did decrease the font-size a bit and it helped a little, but the letters are still spaced out a little more than I'd like. It's so close!

    Screen Shot 2020-08-10 at 8 18 39 PM

    Thanks!

    opened by MannanK 2
  • Destroy effect

    Destroy effect

    Hi Peter,

    Your plugin is very interesting and work perfectly, but i have one problem : I need to remove dynamically the effect, and you didn't add such method in your plugin to make that. Could you explain me how to create this function easily ?

    Thanks in advance

    enhancement 
    opened by ghost 2
  • Allow circled links

    Allow circled links

    Hey,

    this is my first pull request so please don't mind mistakes. I have extended to plugin to allow the usage of links (provided as hashmap). What do you think about it?

    opened by ne0h 2
  • Inaccessible

    Inaccessible

    This plugin is inaccessible to screen reader users as every letter is read out on its own. This happens because there are spans around each letter. Possible solution: Use aria-hidden to hide those spans for screen readers, while duplicating the text in the respective element and moving it out of the viewport so this duplicated text can be picked up by screen readers.

    opened by yatil 2
  • CircleType.js not adding text to

    CircleType.js not adding text to "aria-label"

    Been tryna follow the docs here, https://circletype.labwire.ca/, on how to set this up and think I've followed everything correctly, however, the expected result isn't what I get.

    In the examples on the page referenced above, the text inside the target element gets pulled into the "aria-label" attribute, whereas for me it's always blank.

    Here's my code:

    Reviews Reviews Reviews

    .circular-text_wrapper { top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2;

    .circular-text {
        color: transparent;
        -webkit-text-stroke: 1px $navy;
        font-family: $sedgwickAveDisplay;
        font-size: 24px;
        font-weight: 400;
        font-style: normal;
        line-height: 24px;
        text-transform: uppercase;
    }
    

    }

    const circleType = new CircleType( document.getElementById('circular-text') ).radius();

    The circletype.min.js file is pulling in ahead of the above JS, and I'm not getting any errors in the console - and as far as I can tell it is at least trying to work as it does remove my text from #circular-text, just never adds it to the aria-label for whatever reason.

    You can inspect the code here, https://matthewmeaklim.com - it's inside the image within the reviews section just above the footer.

    I guess I'm doing something daft but can't for the life of me see what it is.

    Many thanks in advance.

    P.S. Looks to be a great plugin from the examples!

    opened by matthewmeaklim 2
  • Whitespaces are being ignored at the end or beginning of text

    Whitespaces are being ignored at the end or beginning of text

    Firstly thank you for your work!

    Unfortunatley I'm experiencing an Issue regarding whitespaces at the end or beginning of a text I'm using CircleType on. It seems that the whitespaces are being ignored, resulting in an uneven result when using some seperators like this:

    CircleType_WhitespaceIssue

    I also tried using protected whitespaces like '&#160' or ' ' but without success.

    Would it be possible to take ending or beginning whitespaces into account when using CircleType?

    Thanks and Greetings from Germany!

    opened by cophiesarius 1
  • letter-spacing bug with multiple text

    letter-spacing bug with multiple text

    Hello! Firstly: thank you for ur job, u're awesome!

    And secondly I have problem: Screen Shot 2021-08-08 at 5 42 27 PM

    First element - has normal letter spacing, but second and third elements has other spacing. I'm trying to use letter-spacing parameter in css, trying to use in js (elem.style.letterSpacing), but all of it works just on first element. What I need to do?

    Part of code (I'm using svelte):

    for (let i = 0; i < text.length; i++) {
        let circleType = new CircleType(text[i]);
        circleType.radius(360).dir(tabs[i].dir);
     }
    
      <p class="text" bind:this={text[i]} style="transform: rotate({tabs[i].rotate}deg) translate(0, {tabs[i].translate}px) scale({tabs[i].dir})">{tab.title}</p>
    
    opened by devilka4321 1
  • Replaced div container element with span

    Replaced div container element with span

    May be worth changing this over...

    The majority of people using the library are probably going to be using it in hx and p elements, where div elements aren't valid. Not a huge issue at all, but definitely worth thinking about :)

    opened by danny-pearson 1
  • Adds method to make full circle for any given radius.

    Adds method to make full circle for any given radius.

    I hope you don't mind me submitting this, I was looking for a way of doing this with the package at work today but it felt a bit too hacky. I really like the the ease of using this library, and I feel like this would be a nice feature to add :)

    This adds a new fullCircle() method which will create equal spacing between each letter, making a full circle for any given radius.

    Screenshot 2020-11-19 at 03 12 07
    opened by danny-pearson 5
Releases(2.3.1)
A lightweight, easy to use Javascript injector for radical Web Typography

Lettering.js, a jQuery plugin for radical Web Typography We developed a lightweight, easy to use Javascript span injector for radical Web Typography,

Dave Rupert 5.4k Dec 20, 2022
Web typography at its finest: font-size and line-height based on element width.

FlowType.JS Responsive web typography at its finest: font-size and line-height based on element width. Check out the demo site. What does FlowType.JS

Simple Focus 4.6k Dec 30, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Curve Fitting in JavaScript.

regression-js regression-js is a JavaScript module containing a collection of linear least-squares fitting methods for simple data analysis. Installat

Tom Alexander 883 Dec 24, 2022
Jquery.iocurve - jQuery plugin like Tone Curve on Photoshop or GIMP

jquery.iocurve jQuery plugin like Tone Curve on Photoshop or GIMP. See Official page for more information. Quick start Create HTML and open in your br

null 5 Jul 28, 2022
An implementation of Bézier curve rendering and manipulation, using the HTML5 Canvas API.

Bézier Curves An implementation of Bézier curve rendering and manipulation, using the HTML5 Canvas API. How does it work? Bézier curves can be simply

nethe550 1 Apr 13, 2022
A type speed checking website which lets you check your typing speed and shows the real-tme leaderboards with mongodb as DB and express as backend

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Sreehari jayaraj 8 Mar 27, 2022
💻 Countries Web is a web application that lets you view data for all the countries in the world and filter them by country name and continent.

?? Countries Web View Demo This is the Countries Web, a web application that lets you view data for all the countries in the world and filter them by

João Gabriel 5 Jun 23, 2022
svgMap is a JavaScript library that lets you easily create an interactable world map comparing customizable data for each country.

svgMap svgMap is a JavaScript library that lets you easily create an interactable world map comparing customizable data for each country. Live demo: h

Stephan Wagner 155 Dec 25, 2022
OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.

OpenUI5. Build Once. Run on any device. What is it? OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on al

SAP 2.7k Dec 31, 2022
JSON Hero is an open-source, beautiful JSON explorer for the web that lets you browse, search and navigate your JSON files at speed. 🚀

JSON Hero makes reading and understand JSON files easy by giving you a clean and beautiful UI packed with extra features.

JSON Hero 7.2k Jan 9, 2023
An Obsidian plugin that lets you browse the web within Obsidian.

Obsidian Web Browser An Obsidian plugin that allows you to browse the web within Obsidian using v1.0 tabs. The core functionality of the plugin, rende

Dion Tryban 102 Dec 28, 2022
Type predicate functions for checking if a value is of a specific type or asserting that it is.

As-Is Description As-Is contains two modules. Is - Type predicates for checking values are of certain types. As - Asserting values are of a certain ty

Declan Fitzpatrick 8 Feb 10, 2022
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
🧬 A type builder for pagination with prisma and type-graphql.

?? Prisma TypeGraphql Pagination Prisma TypeGraphql Pagination builds prisma pagination types for type-graphql. import { ... } from 'type-graphql'

Arthur Fiorette 2 Apr 21, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Devansh Jethmalani 17 Sep 21, 2022
A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

go2type go2type.vercel.app (backup site) A typescript transpiler that convert golang's type to typescript's type. Help front-end developer to work fas

Oanakiaja 8 Sep 26, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022