Convert Figma logo to code with AI

tldraw logotldraw

whiteboard SDK / infinite canvas SDK

39,865
2,496
39,865
349

Top Related Projects

Virtual whiteboard for sketching hand-drawn like diagrams

1,302

draw.io is a JavaScript, client-side editor for general diagramming.

19,076

Shared data types for building collaborative software

29,961

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser

20,304

Create graphics with a hand-drawn, sketchy, appearance

12,768

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.

Quick Overview

tldraw is an open-source digital whiteboard and diagramming tool. It provides a flexible, customizable drawing canvas that can be embedded in web applications or used as a standalone tool. tldraw offers a rich set of features for creating diagrams, sketches, and collaborative drawings.

Pros

  • Highly customizable and extensible
  • Supports real-time collaboration
  • Offers a wide range of drawing tools and shapes
  • Can be easily integrated into existing web applications

Cons

  • Learning curve for advanced customization
  • Limited export options compared to some commercial alternatives
  • Documentation could be more comprehensive for complex use cases
  • Performance may degrade with very large or complex drawings

Code Examples

  1. Creating a basic tldraw instance:
import { Tldraw } from '@tldraw/tldraw'

function App() {
  return <Tldraw />
}
  1. Adding custom shapes:
import { Tldraw, createCustomShapeId } from '@tldraw/tldraw'

const customShapes = {
  myCustomShape: {
    type: 'myCustomShape',
    getShape: (props) => ({
      id: createCustomShapeId('myCustomShape'),
      type: 'myCustomShape',
      x: props.x,
      y: props.y,
      width: 100,
      height: 100,
    }),
    component: MyCustomShapeComponent,
  },
}

function App() {
  return <Tldraw shapes={customShapes} />
}
  1. Handling events:
import { Tldraw } from '@tldraw/tldraw'

function App() {
  const handleChange = (app) => {
    console.log('Canvas changed:', app.getSnapshot())
  }

  return <Tldraw onChange={handleChange} />
}

Getting Started

To get started with tldraw, follow these steps:

  1. Install tldraw in your project:

    npm install @tldraw/tldraw
    
  2. Import and use the Tldraw component in your React application:

    import { Tldraw } from '@tldraw/tldraw'
    
    function App() {
      return (
        <div style={{ position: 'fixed', inset: 0 }}>
          <Tldraw />
        </div>
      )
    }
    
    export default App
    
  3. Customize the Tldraw instance by passing props for additional functionality, such as persistence, collaboration, or custom tools.

Competitor Comparisons

Virtual whiteboard for sketching hand-drawn like diagrams

Pros of Excalidraw

  • Simpler and more lightweight, focusing on quick sketches and diagrams
  • Better support for collaborative editing in real-time
  • More extensive library of pre-made shapes and icons

Cons of Excalidraw

  • Less powerful for complex diagrams or professional-grade illustrations
  • Fewer advanced features and customization options
  • Limited integration capabilities with other tools and platforms

Code Comparison

Excalidraw (React component usage):

import { Excalidraw } from "@excalidraw/excalidraw";

<Excalidraw
  initialData={initialData}
  onChange={(elements, state) => console.log("Elements :", elements, "State : ", state)}
/>

tldraw (React component usage):

import { Tldraw } from '@tldraw/tldraw'

<Tldraw
  document={document}
  onMount={(app) => console.log('The app has mounted')}
/>

Both libraries offer React components for easy integration, but tldraw provides more advanced features and a more extensive API for customization. Excalidraw focuses on simplicity and ease of use, while tldraw offers more powerful tools for complex diagramming and illustration needs.

1,302

draw.io is a JavaScript, client-side editor for general diagramming.

Pros of draw.io

  • More extensive feature set, including advanced diagramming tools
  • Supports a wider range of export formats
  • Offers both web-based and desktop applications

Cons of draw.io

  • Steeper learning curve due to more complex interface
  • Larger codebase, potentially slower performance in some scenarios
  • Less modern UI/UX compared to tldraw

Code Comparison

draw.io (JavaScript):

mxGraph.prototype.insertVertex = function(parent, id, value, x, y, width, height, style, relative)
{
    var vertex = this.createVertex(parent, id, value, x, y, width, height, style, relative);
    return this.addCell(vertex, parent);
};

tldraw (TypeScript):

export function createShapeId(id?: string): TLShapeId {
  return id ? (`shape:${id}` as TLShapeId) : uniqueId('shape')
}

The code snippets show different approaches to creating elements. draw.io uses a more traditional object-oriented style, while tldraw employs a functional approach with TypeScript.

19,076

Shared data types for building collaborative software

Pros of yjs

  • More versatile for general real-time collaboration across various data types
  • Better suited for complex distributed systems and offline-first applications
  • Offers a modular architecture allowing for customization and flexibility

Cons of yjs

  • Steeper learning curve due to its more complex nature
  • May require more setup and configuration for specific use cases
  • Less focused on drawing and whiteboarding features

Code Comparison

yjs:

import * as Y from 'yjs'
import { WebsocketProvider } from 'y-websocket'

const ydoc = new Y.Doc()
const provider = new WebsocketProvider('ws://localhost:1234', 'my-room', ydoc)
const ytext = ydoc.getText('mytext')

tldraw:

import { Tldraw } from '@tldraw/tldraw'

function App() {
  return <Tldraw />
}

Summary

yjs is a more general-purpose real-time collaboration framework, while tldraw is specifically designed for creating collaborative drawing and diagramming applications. yjs offers greater flexibility and scalability for various data types, but may require more setup. tldraw provides a simpler, out-of-the-box solution for whiteboarding and drawing features, but with less customization options for other collaboration scenarios.

29,961

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser

Pros of Fabric.js

  • More mature and established library with a larger community and ecosystem
  • Offers a wider range of features for canvas manipulation and object handling
  • Better suited for complex, interactive canvas applications

Cons of Fabric.js

  • Steeper learning curve due to its extensive API and features
  • Larger file size, which may impact load times for simpler projects
  • Less focused on collaborative drawing and whiteboarding features

Code Comparison

Fabric.js:

var canvas = new fabric.Canvas('canvas');
var rect = new fabric.Rect({
  left: 100,
  top: 100,
  fill: 'red',
  width: 20,
  height: 20
});
canvas.add(rect);

Tldraw:

import { Tldraw } from '@tldraw/tldraw'

export default function App() {
  return <Tldraw />
}

Summary

Fabric.js is a powerful and versatile canvas manipulation library, offering extensive features for complex applications. Tldraw, on the other hand, is more focused on collaborative drawing and whiteboarding, with a simpler API and faster setup for basic projects. The choice between the two depends on the specific requirements of your project and the level of canvas manipulation needed.

20,304

Create graphics with a hand-drawn, sketchy, appearance

Pros of Rough

  • Focused on creating hand-drawn, sketchy graphics
  • Lightweight and can be easily integrated into various JavaScript projects
  • Supports both SVG and Canvas rendering

Cons of Rough

  • Limited to creating individual shapes and lines
  • Lacks advanced drawing tools and features
  • No built-in user interface or interactive elements

Code Comparison

Rough:

const rc = rough.canvas(document.getElementById('canvas'));
rc.rectangle(10, 10, 200, 200, { fill: 'red' });
rc.circle(50, 50, 80, { stroke: 'blue', strokeWidth: 2 });

Tldraw:

const app = new TldrawApp();
app.createShapes([
  { type: 'rectangle', x: 10, y: 10, width: 200, height: 200, style: { fill: 'red' } },
  { type: 'ellipse', x: 50, y: 50, radius: [40, 40], style: { stroke: 'blue' } }
]);

Rough is more focused on creating individual sketchy graphics, while Tldraw provides a complete drawing application with a user interface and more advanced features. Rough is better suited for adding hand-drawn style elements to existing projects, whereas Tldraw is designed for creating and editing complex drawings and diagrams.

12,768

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.

Pros of Konva

  • More flexible and lower-level canvas manipulation library
  • Better performance for complex, interactive visualizations
  • Extensive documentation and large community support

Cons of Konva

  • Steeper learning curve for beginners
  • Requires more code to create basic shapes and interactions
  • Less opinionated, which may lead to inconsistent implementations

Code Comparison

Konva:

const stage = new Konva.Stage({
  container: 'container',
  width: 400,
  height: 400
});

const layer = new Konva.Layer();
const rect = new Konva.Rect({
  x: 50,
  y: 50,
  width: 100,
  height: 100,
  fill: 'red'
});

layer.add(rect);
stage.add(layer);

tldraw:

import { Tldraw } from '@tldraw/tldraw'

function App() {
  return <Tldraw />
}

Summary

Konva is a powerful, low-level canvas manipulation library that offers more flexibility and better performance for complex visualizations. However, it has a steeper learning curve and requires more code to create basic shapes. tldraw, on the other hand, provides a higher-level abstraction for creating drawing applications, making it easier to get started but potentially less flexible for advanced use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

tldraw

Welcome to the public monorepo for tldraw. tldraw is a library for creating infinite canvas experiences in React. It's the software behind the digital whiteboard tldraw.com.

Click here to learn about our license and pricing.

Installation

npm i tldraw

Usage

import { Tldraw } from 'tldraw'
import 'tldraw/tldraw.css'

export default function App() {
	return (
		<div style={{ position: 'fixed', inset: 0 }}>
			<Tldraw />
		</div>
	)
}

Learn more at tldraw.dev.

Local development

The local development server will run our examples app. The basic example will show any changes you've made to the codebase.

To run the local development server, first clone this repo.

Enable corepack to make sure you have the right version of yarn:

corepack enable

Install dependencies:

yarn

Start the local development server:

yarn dev

Open the example project at localhost:5420.

License

The tldraw SDK is provided under the tldraw license.

You can use the tldraw SDK in commercial or non-commercial projects so long as you preserve the "Made with tldraw" watermark on the canvas. To remove the watermark, you can purchase a business license. Visit tldraw.dev to learn more.

Trademarks

Copyright (c) 2024-present tldraw Inc. The tldraw name and logo are trademarks of tldraw. Please see our trademark guidelines for info on acceptable usage.

Distributions

You can find tldraw on npm here.

Contribution

Please see our contributing guide. Found a bug? Please submit an issue.

Community

Have questions, comments or feedback? Join our discord. For the latest news and release notes, visit tldraw.dev.

Contributors

Star History

Star History Chart

Contact

Find us on Twitter/X at @tldraw. You can contact us by email at hello@tldraw.com.

NPM DownloadsLast 30 Days