iDraw.js

A simple JavaScript framework for Drawing on the web

README

iDraw.js


iDraw.js is a simple JavaScript framework for Drawing on the web.


一个面向Web绘图的JavaScript框架



idraw.js.org




CI

    
Version License









@idraw/studio Preview


The preview of @idraw/studo. Click here to get it.


Install


  1. ```
  2. npm i idraw
  3. ```

Getting Started


Common


  1. ```js
  2. import iDraw from 'idraw';

  3. const idraw = new iDraw(
  4.   document.querySelector('#app'),
  5.   {
  6.     width: 600,
  7.     height: 400,
  8.     contextWidth: 600,
  9.     contextHeight: 400,
  10.     devicePixelRatio: 1,
  11.   }
  12. );
  13. idraw.addElement({
  14.   name: "rect-1",
  15.   x: 140,
  16.   y: 120,
  17.   w: 200,
  18.   h: 100,
  19.   type: "rect",
  20.   desc: {
  21.     bgColor: "#f7d3c1",
  22.     borderRadius: 20,
  23.     borderWidth: 4,
  24.     borderColor: "#ff6032",
  25.   },
  26. });
  27. ```

React


  1. ```jsx
  2. import iDraw from 'idraw';
  3. import { useEffect, useRef } from 'react';

  4. function Demo() {
  5.   const ref = useRef(null);
  6.   useEffect(() => {
  7.     const idraw = new iDraw(ref.current, {
  8.       width: 600,
  9.       height: 400,
  10.       contextWidth: 600,
  11.       contextHeight: 400,
  12.       devicePixelRatio: 1,
  13.     });
  14.     idraw.addElement({
  15.       name: "rect-001",
  16.       x: 140,
  17.       y: 120,
  18.       w: 200,
  19.       h: 100,
  20.       type: "rect",
  21.       desc: {
  22.         bgColor: "#f7d3c1",
  23.         borderRadius: 20,
  24.         borderWidth: 4,
  25.         borderColor: "#ff6032",
  26.       },
  27.     })
  28.   }, []);

  29.   return (
  30.     <div ref={ref}></div>
  31.   )
  32. }
  33. ```

Vue


  1. ```html
  2. <template>
  3.   <div ref="mount"></div>
  4. </template>
  5. <script setup >
  6. import iDraw from 'idraw';
  7. import { ref, onMounted } from 'vue'
  8. const mount = ref();
  9. onMounted(() => {
  10.   const idraw = new iDraw(mount.value, {
  11.     width: 600,
  12.     height: 400,
  13.     contextWidth: 600,
  14.     contextHeight: 400,
  15.     devicePixelRatio: 1,
  16.   });
  17.   idraw.addElement({
  18.     name: "rect-001",
  19.     x: 140,
  20.     y: 120,
  21.     w: 200,
  22.     h: 100,
  23.     type: "rect",
  24.     desc: {
  25.       bgColor: "#f7d3c1",
  26.       borderRadius: 20,
  27.       borderWidth: 4,
  28.       borderColor: "#ff6032",
  29.     },
  30.   })
  31. })
  32. </script>
  33. ```


Contributing


We appreciate your help!

To contribute, please follow the steps:

Step 1: Prepare Project


- git clone git@github.com:idrawjs/idraw.git
- cd idraw
- npm i
- npm run init

Step 2: Development


- npm run dev to select and develop single package