npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-simple-drawing

v0.5.6

Published

A simple drawing tool

Downloads

20

Readme

Vue image-painter(原作者代码)

图片涂鸦、绘制、标注

在线预览(GitHub)

在线预览(Gitee)

支持功能

1.画笔颜色 🎨

2.画笔粗细 ✏️

3.画布放大 🔍

4.画布缩小 🔍

5.清除画布 🧹

6.保存图片 🏔

7.回退一步 ↩️

8.前进一步 ↪️

画笔工具类型

1.画笔 ✏️

2.直线 📏

3.圆形 ⚪️

4.矩形 🔲

5.橡皮 🧽

6.文字 📝

实现思路

创建三个不同作用的画布

// 用于绘制的画板
this.canvas_front = document.getElementById("ctx_front");

// 用于生成绘制后效果图的画板
this.canvas_back = document.getElementById("ctx_back");

// 底图画板,橡皮擦除时获取像素放到绘制画板中,达到不擦出底图的效果(移动过快会产生问题)
this.canvas_base = document.getElementById("ctx_base");

鼠标按下判断工具类型,记录初始位置

let mousedown = (e) => {
    this.ctx_front.strokeStyle = this.defaultColor;
    this.ctx_front.lineWidth = this.slide;
    e = e || window.event;
    sx = e.clientX - this.canvas_front.offsetLeft;
    sy = e.clientY - this.canvas_front.offsetTop;

    this.ctx_front.moveTo(sx, sy);
    this.canDraw = true;
    ...

若是输入文字则定位输入框到画布中,失焦或回车文字绘制到画布中

this.handleTextBlur();
    this.text = "";
    text.style.fontSize = 14 + this.slide * 10 + "px";
    text.style.color = this.defaultColor;
    text.style.left =
              e.offsetX + this.canvas_front.offsetLeft - 20 + "px";
    text.style.top =
              e.offsetY + this.canvas_front.offsetTop - 10 + "px";
    text.style.zIndex = 10;
    text.style.display = "block";
    this.tl = e.offsetX - 20;
    this.tt = e.offsetY + 10;
    break;

    ...

handleTextBlur() {
      let text = document.getElementById("text");
      this.ctx_front.font = `300 ${text.style.fontSize} sans-serif`;
      this.ctx_front.fillStyle = this.defaultColor;
      this.ctx_front.fillText(this.text, this.tl, this.tt);
      text.style.display = "none";
      this.handleSaveCanvasStore();
    }

鼠标移动,根据工具类型绘制不同路径

 let mousemove = (e) => {
        e = e || window.event;
        mx = e.clientX - this.canvas_front.offsetLeft;
        my = e.clientY - this.canvas_front.offsetTop;
        const cbx = this.ctx_base.getImageData(
          e.offsetX - this.slide / 2,
          e.offsetY - this.slide / 2,
          this.slide * 2,
          this.slide * 2
        );
    ...

若工具类型是橡皮,则从 canvas_base 中获取底图像素放回 canvas_front 中

    const cbx = this.ctx_base.getImageData(
          e.offsetX - this.slide / 2,
          e.offsetY - this.slide / 2,
          this.slide * 2,
          this.slide * 2
    );

    ...

 this.ctx_front.putImageData(
                cbx,
                e.offsetX - this.slide / 2,
                e.offsetY - this.slide / 2
              );
    ...

鼠标抬起,从绘制画布 canvas_front 生成绘制图并绘制到 canvas_back 中,然后再重绘 canvas_front

handleSaveCanvasStore() {
      let url = this.canvas_front.toDataURL();
      let image = new Image();
      image.src = url;
      image.onload = () => {
        this.ctx_front.clearRect(
          0,
          0,
          this.canvas_front.width,
          this.canvas_front.height
        );
        this.ctx_front.drawImage(image, 0, 0, image.width, image.height);
        this.ctx_back.drawImage(image, 0, 0, image.width, image.height);
        const url2 = this.canvas_back.toDataURL();
        this.currentImg.url = url2;
        this.currentImg.index += 1;
        this.canvasStore.push(url2);
        this.prevDis = false;
        console.log(this.canvasStore);
      };
    },

最终保存图片

let canvas = document.getElementById("ctx_back");
    this.$refs.download.href = canvas.toDataURL();
    this.$refs.download.click();

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Lints and fixes files

npm run lint

组件prop

initConfig: { type:Object, default: () => { return { bgColor: '#ffffff', // 背景色 【默认白色】 strokeColor: '#333333', // 笔触颜色 【默认黑色】 width:400, // 默认宽度 px 【默认400】 height: 400 // 默认高度 px 【默认400】 } } }