18 Star 121 Fork 48

purestart / vue-fabric

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

vue-fabric

purestart vue-fabric.

Installation

npm install vue-fabric --save

依赖

下载customiseControls.min.js.和 fabric.min.js.到本地 static/js/文件下

本地项目 index.html 引入

<script type="text/javascript" src="./static/js/fabric.min.js"></script>
<script type="text/javascript" src="./static/js/customiseControls.min.js"></script>

Import

在main.js中
import 'vue-fabric/dist/vue-fabric.min.css';
import { Fabric } from 'vue-fabric';
Vue.use(Fabric);

使用

 <vue-fabric ref="canvas" :width="width" :height="height"></vue-fabric>

Usage

Props

Name Type Default Description
id String "canvas" id
width Number 0 canvas width
height Number 0 canvas height

Function

方法调用 this.$refs.canvas.方法名(params)

createImage(url,options) 绘制图片

params Type Description
url String image url
options Object id(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性

createImageByImg(img,options) 绘制图片

params Type Description
img Image对象 new Image对象
options Object id(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性

createTextbox(text,options) 绘制文本

params Type Description
text String text content
options Object width,left,top,fill(颜色),fontSize,id,fontFamily,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性

createItext(text,options) 绘制可编辑文本(可换行显示文本)

params Type Description
text String text content
options Object width,left,top,fill(颜色),fontSize,id,editable(是否可编辑),fontFamily,fontSize,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性

createRect(options) 绘制矩形

options Type Description
left Number left
top Number top
width Number Rect width
height Number Rect height
fillColor String Rect fillColor
id String 唯一标识 id
其它属性兼容 all 兼容原生其它属性

freeDrawConfig(options) 开启/关闭自由绘制(画笔)

options Type Description
isDrawingMode Boolean 是否开启自由绘制 true/false
color String 绘制线颜色
drawWidth Number 绘制线宽

eraseDrawConfig(options) 开启自由绘制橡皮擦(只对当前绘制画布有效)

options Type Description
color String 选填,擦除颜色默认白色
drawWidth Number 橡皮擦线宽

createLine(options) 绘制直线

options Type Description
x,y,x1,y1 Number line points,直线两点坐标
fillColor String fillColor 填充颜色
strokeColor String strokeColor 绘制颜色
其它属性兼容 all 兼容原生其它属性

drawDottedline(options) 绘制虚线

options Type Description
x,y,x1,y1 Number line points,直线两点坐标
color String 绘制线颜色
drawWidth Number 绘制线宽
offset Number 默认 6,每隔 offset 个像素空 empty 个像素
empty Number 默认 3,每隔 offset 个像素空 empty 个像素
其它属性兼容 all 兼容原生其它属性

drawArrowLine(options) 绘制箭头直线

options Type Description
x,y,x1,y1 Number line points,直线两点坐标
color String 绘制线颜色
drawWidth Number 绘制线宽
fillColor Number 默认透明,填充颜色
theta Number 默认 35,箭头角度大小
headlen Number 默认 35,箭头角度大小
其它属性兼容 all 兼容原生其它属性

createTriangle(options) 绘制三角形

options Type Description
x,y,x1,y1,x2,y2 Number 三角形 3 点坐标位置
left,top Number position 位置
color String 绘制线颜色
fillColor String fillColor 填充颜色
drawWidth Number 绘制线宽
其它属性兼容 all 兼容原生其它属性

createEqualTriangle(options) 绘制等边三角形

options Type Description
left,top Number position 位置
fill String fillColor 填充颜色
width Number 三角形底边宽度
height Number 三角形高
其它属性兼容 all 兼容原生其它属性

drawByPath(pathArray,options) 根据轨迹绘制图形

params Type Description
pathArray Array 轨迹所在点数组,按顺序正时针或逆时针,如三角形 [[50, 50], [120, 120], [80, 160]]
options Object left,top,strokeColor,strokeWidth,fillColor,...其它属性

createCircle(options) 绘制圆

options Type Description
left,top Number position 位置
fill String fillColor 填充颜色
radius Number 圆形半径
其它属性兼容 all 兼容原生其它属性

createEllipse(options) 绘制椭圆

options Type Description
rx,ry Number rx , ry 椭圆两个长轴尺寸和短轴尺寸
left,top Number position 位置
fillColor String fillColor 填充颜色
strokeColor String strokeColor 绘制线颜色
angle Number angle 倾斜角度
其它属性兼容 all 兼容原生其它属性

setRotate(angle) 旋转选中元素

params Type Description
angle Number 旋转角度

setSelection(flag) 设置画布是否可以框选

params Type Description
flag Boolean 画布是否可以框选

setBackgroundImage(options) 设置画布背景图片

options Type Description
imgUrl String 背景图片 Url
angle Number 旋转角度
opacity Number 背景图片透明度
width Number 默认为canvas宽度 背景图片宽度
height Number 默认为canvas高度 背景图片高度
scaleX Number 水平缩放
scaleY Number 垂直缩放
crossOrigin String 可为'anonymous',加载跨域图片

renderAll() 重新渲染画布

setBackgroundColor(color) 设置画布背景颜色

params Type Description
color String 背景颜色

toggleMirror(options) 设置图片元素镜像翻转

options Type Description
flip String 可选值 X,Y 默认值 X , 镜像翻转 X,Y

setCornerIcons(options) 自定义操作元素图片

options Type Description
size Npmber 图片大小 px
borderColor String 图片边框颜色
cornerBackgroundColor String 设置背景颜色
cornerShape String 形状,默认'rect' ,可选'rect', 'circle'
tl String top left 左上角元素图片地址(本地只能 static 下的图片)
tr String top right 右上角元素图片地址(本地只能 static 下的图片)
bl String bottom left 左下角元素图片地址(本地只能 static 下的图片)
br String bottom right 右下角元素图片地址(本地只能 static 下的图片)
ml String middle left 中间左边元素图片地址(本地只能 static 下的图片)
mr String middle right 中间右边元素图片地址(本地只能 static 下的图片)
mtr String middle top 顶部元素图片地址(本地只能 static 下的图片)

toNextLayer() 设置当前选中画布到下一层

toLastLayer() 设置当前选中画布到上一层

toBottomLayer() 设置当前选中画布到底层

toTopLayer() 设置当前选中画布到顶层

discardActive() 取消选中

getObjects() 获取当前画布上的所有元素对象

clear() 清除当前画布上的所有元素对象

toDataUrl() 返回当前画布的 base64 图片

toJson() 返回当前画布的 json 对象

loadFromJSON(json,cb) 从 json 对象中加载画布数据

params Type Description
json Object json 对象
cb Function 加载完成回调函数

toSvg() 返回当前画布的 svg 图片

removeCurrentObj() 删除当前选中对象

getEditObj() 返回当前选中对象,并不在画布上显示,用于编辑当前元素

setEditObj(obj) 设置添加对象到画布

deactivateOne(obj) 取消选中对象(框选的时候选中多个对象使用)

事件

 <vue-fabric ref="canvas" @selection:created="selected" :width="width" :height="height"></vue-fabric>

鼠标事件

name Type Description
mouse:down event mouse down
mouse:up event mouse up
mouse:move event mouse move
mouse:dblclick event mouse dblclick
mouse:over event mouse over
mouse:out event mouse out

其它事件

name Type Description
selection:created event 选中 canvas 元素对象,单选和多选都会触发此事件
selection:updated event selection updated
selection:cleared event selection cleared
before:selection:cleared event before selection cleared
object:added event 当有元素被添加进来时候触发
object:removed event object removed
object:modified event object modified
object:rotating event object rotating
object:scaling event object scaling
object:moving event object moving

Changelog

2018.08.26

v0.1.4 * 初始化组件库

2018.09.20

v0.1.8 * 新增 api 常用接口创建文档

2019.01.19---v0.1.9

  • 新增画板事件,鼠标事件、选中事件等
  • 新增绘制三角形
  • 新增绘制虚线
  • 新增画笔自由绘制
  • 新增绘制箭头
  • 新增取消选中方法

2019.01.31---v0.1.10

  • 修改绘制图片(createImage 方法)不能定位 top 的 BUG
  • 修改镜像翻转函数 toggleMirror ,新增参数 options ,X 翻转和 Y 翻转

2019.05.09---v0.1.20

  • fix webpack-dev-server 版本导致的 npm run dev fail
  • 新增方法 drawByPath 根据轨迹绘制形状图形

2020.03.02---v0.1.26

  • 新增属性id 修复一个页面使用多个vue-fabric没有渲染成功的问题

2020.04.15---v0.1.27

  • 修复id = "canvas"的情况下会报错的问题

2020.05.08---v0.1.28

  • 修复更新Mirror只有图片生效的问题

2020.07.07---v0.1.29

  • 新增优化图片无法被选中属性设置 evented 和 selectable 感谢 @jessieyyy
  • 新增取消单个选中的方法 deactivateOne(obj)
  • 修复image top 和 left 定位bug

2020.07.21---v0.1.37

  • 新增createImageByImg(img, options)方法 其中参数img是Image对象
  • 新增setSelection(flag) 设置画布是否可以框选
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2018 purestart Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

基于fabric.js库 创建的vue版本fabric组件,定制画板,图片组合绘制 expand collapse
JavaScript and 3 more languages
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
JavaScript
1
https://gitee.com/_pure/vue-fabric.git
git@gitee.com:_pure/vue-fabric.git
_pure
vue-fabric
vue-fabric
master

Search