0.12.13 • Published 3 months ago

sketch-editor v0.12.13

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

sketch-editor

A sketch Render&Editor on Canvas/WebGL.

NPM version CI

Install

npm install sketch-editor

Usage

如果文档有pdf图片,需要前置引入pdfjs-dist库,也可以使用cdn文件:

<script src="https://gw.alipayobjects.com/os/lib/pdfjs-dist/3.11.174/build/pdf.min.js"></script>

如果需要颜色选择器功能,需要前置引入vanilla-picker库,也可以使用cdn文件:

<script src="https://gw.alipayobjects.com/os/lib/vanilla-picker/2.12.3/dist/vanilla-picker.min.js"></script>

拿到sketch文件的ArrayBuffer后:

import sketchEditor from 'sketch-editor';

// css自行修改引入,这里是举例
import 'sketch-editor/dist/style.css';

// 一些建议的手动配置
sketchEditor.config.tile = true; // 开启tile优化大尺寸大文件(持续改进中)

// 一些有用的前置方法
sketchEditor.style.font.registerLocalFonts(); // 异步注册本地字体

// 真正的读取渲染逻辑
sketchEditor
  .openAndConvertSketchBuffer(arrayBuffer) // 读取sketch的buffer
  // .openAndConvertPsdBuffer(arrayBuffer) // 如果是psd用这个
  .then(json => {
    const dpi = 2;
    
    // 渲染
    const $canvasC = document.querySelector('#canvas-container');
    const { clientWidth, clientHeight } = $canvasC;
    const canvas = document.createElement('canvas');
    canvas.width = clientWidth * dpi;
    canvas.height = clientHeight * dpi;
    $canvasC.appendChild(canvas);
    const root = sketchEditor.parse(json, {
      dpi,
      canvas,
    });
    
    // 可选控制,鼠标键盘基础操作
    const listener = sketchEditor.control.initCanvasControl(root, $canvasC);
    // page列表展示
    sketchEditor.control.initPageList(root, document.querySelector('#page'), listener);
    // 图层树结构展示
    sketchEditor.control.initTree(root, document.querySelector('#tree'), listener);
    // 右侧属性面板展示
    sketchEditor.control.initPanel(root, document.querySelector('#side'), listener);
    // 缩放情况展示
    sketchEditor.control.initZoom(root, document.querySelector('#zoom'), listener);
  });

Dev

npm run dev

sketch-editor的诞生离不开 karas 开源项目。

Demo

License

MIT License

0.9.8

7 months ago

0.9.7

7 months ago

0.12.10

3 months ago

0.12.11

3 months ago

0.9.9

7 months ago

0.9.4

8 months ago

0.9.6

7 months ago

0.9.5

7 months ago

0.10.1

7 months ago

0.10.2

7 months ago

0.10.3

7 months ago

0.10.4

7 months ago

0.12.12

3 months ago

0.10.5

7 months ago

0.12.13

3 months ago

0.10.0

7 months ago

0.11.8

6 months ago

0.11.9

6 months ago

0.11.0

6 months ago

0.11.1

6 months ago

0.11.2

6 months ago

0.11.3

6 months ago

0.11.4

6 months ago

0.11.5

6 months ago

0.11.6

6 months ago

0.11.7

6 months ago

0.12.7

4 months ago

0.12.8

4 months ago

0.12.9

4 months ago

0.12.0

4 months ago

0.12.1

4 months ago

0.12.2

4 months ago

0.12.3

4 months ago

0.12.4

4 months ago

0.12.5

4 months ago

0.12.6

4 months ago

0.11.10

5 months ago

0.11.11

5 months ago

0.11.12

5 months ago

0.11.13

5 months ago

0.9.3

8 months ago

0.8.1

8 months ago

0.9.0

8 months ago

0.9.2

8 months ago

0.9.1

8 months ago

0.7.15

8 months ago

0.8.0

8 months ago

0.7.14

8 months ago

0.4.9

10 months ago

0.4.8

10 months ago

0.7.2

8 months ago

0.7.1

8 months ago

0.7.4

8 months ago

0.7.3

8 months ago

0.7.0

8 months ago

0.7.11

8 months ago

0.7.10

8 months ago

0.7.13

8 months ago

0.7.12

8 months ago

0.5.8

9 months ago

0.5.7

9 months ago

0.4.10

10 months ago

0.4.17

9 months ago

0.4.15

10 months ago

0.4.16

9 months ago

0.4.13

10 months ago

0.4.14

10 months ago

0.4.11

10 months ago

0.4.12

10 months ago

0.6.7

9 months ago

0.6.6

9 months ago

0.6.9

9 months ago

0.6.8

9 months ago

0.5.4

9 months ago

0.5.3

9 months ago

0.5.6

9 months ago

0.5.5

9 months ago

0.5.0

9 months ago

0.5.2

9 months ago

0.5.1

9 months ago

0.7.9

8 months ago

0.7.6

8 months ago

0.7.5

8 months ago

0.7.8

8 months ago

0.7.7

8 months ago

0.6.3

9 months ago

0.6.2

9 months ago

0.6.5

9 months ago

0.6.1

9 months ago

0.6.0

9 months ago

0.2.14

11 months ago

0.2.13

11 months ago

0.2.12

11 months ago

0.2.11

11 months ago

0.2.10

11 months ago

0.3.0

11 months ago

0.3.6

10 months ago

0.3.5

10 months ago

0.3.8

10 months ago

0.3.7

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.3.9

10 months ago

0.3.13

10 months ago

0.3.12

10 months ago

0.3.11

10 months ago

0.3.10

10 months ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.2.1

12 months ago

0.2.0

12 months ago

0.4.5

10 months ago

0.2.7

11 months ago

0.4.4

10 months ago

0.2.6

11 months ago

0.4.7

10 months ago

0.2.9

11 months ago

0.4.6

10 months ago

0.2.8

11 months ago

0.4.1

10 months ago

0.2.3

11 months ago

0.4.0

10 months ago

0.2.2

11 months ago

0.4.3

10 months ago

0.2.5

11 months ago

0.4.2

10 months ago

0.2.4

11 months ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.22

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.15

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago