konva vs fabric
キャンバスライブラリ
konvafabric

キャンバスライブラリ

FabricとKonvaは、HTML5キャンバスを操作するための強力なJavaScriptライブラリです。これらのライブラリは、グラフィックやアニメーションを簡単に描画し、インタラクティブなアプリケーションを構築するための機能を提供します。Fabricは特にオブジェクト指向のアプローチを採用しており、オブジェクトの作成や操作が容易です。一方、Konvaは2D描画に特化しており、パフォーマンスを重視した設計がされています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
konva1,141,76714,2751.47 MB2612日前MIT
fabric715,23231,03525.8 MB4641ヶ月前MIT

機能比較: konva vs fabric

オブジェクト管理

  • konva:

    Konvaもオブジェクトの管理機能を持っていますが、特にパフォーマンスに優れた描画エンジンを使用しており、大量のオブジェクトを扱う際にもスムーズな描画が可能です。

  • fabric:

    Fabricは、キャンバス上のオブジェクトを簡単に作成、操作、削除できる機能を提供します。オブジェクトは、グループ化や変形、回転、スケーリングが可能で、直感的なインターフェースを通じて操作できます。

アニメーション

  • konva:

    Konvaは、アニメーションに特化したAPIを提供しており、フレームごとのアニメーションを簡単に実装できます。特に、アニメーションのパフォーマンスが高く、大量のオブジェクトを動かす際にも効果的です。

  • fabric:

    Fabricはアニメーション機能を提供しており、オブジェクトのプロパティを時間に応じて変更することができます。これにより、インタラクティブな体験を提供することが可能です。

イベント処理

  • konva:

    Konvaもイベント処理機能を持っており、特にタッチイベントに強いです。モバイルデバイスでのインタラクションを重視した設計がされています。

  • fabric:

    Fabricは、オブジェクトに対するユーザーのインタラクションを簡単に処理できるイベントシステムを持っています。クリックやドラッグなどのイベントを簡単に設定できます。

描画パフォーマンス

  • konva:

    Konvaは、レイヤーを使用して描画を最適化しており、必要な部分だけを再描画するため、パフォーマンスが非常に高いです。特に、アニメーションや大量のオブジェクトを扱う場合に優れています。

  • fabric:

    Fabricは、描画の際にオブジェクトを再描画する必要がある場合がありますが、オブジェクトの数が多くなるとパフォーマンスが低下する可能性があります。

学習曲線

  • konva:

    Konvaは、シンプルなAPIを提供しているため、学習曲線は緩やかです。特に、2D描画に特化しているため、特定の用途に対して直感的に使いやすいです。

  • fabric:

    Fabricは、オブジェクト指向のアプローチを採用しているため、初めてのユーザーでも比較的簡単に学習できます。ドキュメントも充実しており、サンプルが豊富です。

選び方: konva vs fabric

  • konva:

    Konvaは、パフォーマンスを重視した2D描画が必要な場合に適しています。特に、アニメーションや大量のオブジェクトを扱う場合に優れたパフォーマンスを発揮します。

  • fabric:

    Fabricは、オブジェクト指向のアプローチを重視し、複雑なオブジェクトの操作や編集が必要な場合に適しています。特に、画像やテキストを含むインタラクティブなアプリケーションを構築する際に便利です。

konva のREADME

Konva logo

Konva

Financial Contributors on Open Collective npm version Build Status Build StatusCDNJS version

Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.

You can draw things onto the stage, add event listeners to them, move them, scale them, and rotate them independently from other shapes to support high performance animations, even if your application uses thousands of shapes. Served hot with a side of awesomeness.

This repository began as a GitHub fork of ericdrowell/KineticJS.

Quick Look

<script src="https://unpkg.com/konva@10.0.0-1/konva.min.js"></script>
<div id="container"></div>
<script>
  var stage = new Konva.Stage({
    container: 'container',
    width: window.innerWidth,
    height: window.innerHeight,
  });

  // add canvas element
  var layer = new Konva.Layer();
  stage.add(layer);

  // create shape
  var box = new Konva.Rect({
    x: 50,
    y: 50,
    width: 100,
    height: 50,
    fill: '#00D2FF',
    stroke: 'black',
    strokeWidth: 4,
    draggable: true,
  });
  layer.add(box);

  // add cursor styling
  box.on('mouseover', function () {
    document.body.style.cursor = 'pointer';
  });
  box.on('mouseout', function () {
    document.body.style.cursor = 'default';
  });
</script>

Browsers support

Konva works in all modern mobile and desktop browsers. A browser need to be capable to run javascript code from ES2015 spec. For older browsers you may need polyfills for missing functions.

At the current moment Konva doesn't work in IE11 directly. To make it work you just need to provide some polyfills such as Array.prototype.find, String.prototype.trimLeft, String.prototype.trimRight, Array.from.

Debugging

The Chrome inspector simply shows the canvas element. To see the Konva objects and their details, install the konva-dev extension at https://github.com/konvajs/konva-devtool.

Loading and installing Konva

Konva supports UMD loading. So you can use all possible variants to load the framework into your project:

Load Konva via classical <script> tag from CDN:

<script src="https://unpkg.com/konva@10.0.0-1/konva.min.js"></script>

Install with npm:

npm install konva --save
// The modern way (e.g. an ES6-style import for webpack, parcel)
import Konva from 'konva';

Typescript usage

Add DOM definitions into your tsconfig.json:

{
  "compilerOptions": {
    "lib": [
        "es6",
        "dom"
    ]
  }
}

3 Minimal bundle

import Konva from 'konva/lib/Core';
// Now you have a Konva object with Stage, Layer, FastLayer, Group, Shape and some additional utils function.
// Also core currently already have support for drag&drop and animations.
// BUT there are no shapes (rect, circle, etc), no filters.

// but you can simply add anything you need:
import { Rect } from 'konva/lib/shapes/Rect';
// importing a shape will automatically inject it into Konva object

var rect1 = new Rect();
// or:
var shape = new Konva.Rect();

// for filters you can use this:
import { Blur } from 'konva/lib/filters/Blur';

4 NodeJS env

In order to run konva in nodejs environment you also need to install canvas or skia-canvas package manually for rendering backend.

# node-canvas backend
npm install konva canvas
# skia-canvas backend
npm install konva skia-canvas

Then you can use the same Konva API and all Konva demos will work just fine. You just don't need to use container attribute in your stage.

import Konva from 'konva';
import 'konva/canvas-backend'; // or import 'konva/skia-backend';

const stage = new Konva.Stage({
  width: 500,
  height: 500,
});
// then all regular Konva code will work

Backers

https://simpleshow.com https://www.notably.ai/

Change log

See CHANGELOG.md.

Building the Konva Framework

To make a full build run npm run build. The command will compile all typescript files, combine then into one bundle and run minifier.

Testing

Konva uses Mocha for testing.

  • If you need run test only one time run npm run test.
  • While developing it is easy to use npm start. Just run it and go to http://localhost:1234/unit-tests.html. The watcher will rebuild the bundle on any change.

Konva is covered with hundreds of tests and well over a thousand assertions. Konva uses TDD (test driven development) which means that every new feature or bug fix is accompanied with at least one new test.

Generate documentation

Run npx gulp api which will build the documentation files and place them in the api folder.

Pull Requests

I'd be happy to review any pull requests that may better the Konva project, in particular if you have a bug fix, enhancement, or a new shape (see src/shapes for examples). Before doing so, please first make sure that all of the tests pass (npm run test).

Contributors

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]