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

mp-canvas

v1.0.2

Published

微信小程序canvas工具

Downloads

5

Readme

概述

微信小程序 canvas 绘图封装方法

安装

clone 本项目,将 mp-canvas.js 放到你的小程序项目里。

在小程序中使用 mp-canvas

import { drawTextarea } from "path/to/mp-canvas";

const ctx = wx.createCanvasContext("myCanvas");

drawTextarea(ctx, "测试", {
  x: 270,
  y: 70,
  fontSize: 24,
  lineHeight: 33
});

ctx.draw();

方法

drawTextarea(context, text, options)

文本绘制,支持超出...,删除线和下划线

用法

import { drawTextarea } from "path/to/mp-canvas";

const ctx = wx.createCanvasContext("myCanvas");

drawTextarea(ctx, "测试", {
  x: 20,
  y: 20,
  textDecoration: "line-through"
});

ctx.draw();

参数

  • context:canvas 上下文,通过wx.createCanvasContext获得
  • text:文本内容
  • options:配置项,见下表

配置

| 配置名 | 类型 | 默认值 | 描述 | | -------------- | -------------- | ------- | ----------------------------------------- | | x | number | 0 | 文字在画布 x 轴上的位置,px | | y | number | 0 | 文字在画布 y 轴上的位置,px | | fontSize | number | 20 | 文字大小,px | | lineHeight | number | 20 | 行高,px | | fontWeight | String | normal | 文字粗细,支持 css 里font-weight的配置 | | color | string | #333333 | 文字颜色 | | textDecoration | string/boolean | false | 文本修饰,支持line-throughunderline | | maxWidth | number/boolean | false | 最大宽度,超过此宽度会换行显示,px | | column | number/boolean | false | 最大行数,超过此行数会以...显示 |

drawRoundRect(context, options)

绘制圆角矩形

用法

import { drawRoundRect } from "path/to/mp-canvas";

const ctx = wx.createCanvasContext("myCanvas");

drawRoundRect(ctx, {
  x: 310,
  y: 391,
  width: 110,
  height: 40,
  borderRadius: 4,
  borderColor: "#F21A21",
  borderWidth: 2
});

ctx.draw();

参数

  • context:canvas 上下文,通过wx.createCanvasContext获得
  • options:配置项,见下表

配置

| 配置名 | 类型 | 默认值 | 描述 | | -------------- | -------------- | ------- | ---------------------------- | | x | number | 0 | 矩形在画布 x 轴上的位置,px | | y | number | 0 | 矩形在画布 y 轴上的位置,px | | width | number | 0 | 矩形宽度,px | | height | number | 0 | 矩形高度,px | | borderRadius | number | 4 | 矩形圆角,px | | borderWidth | number | 0 | 边框宽度,px | | borderColor | string | #333 | 边框颜色 | | backgroundColor | string | #fff | 背景颜色 |

circleImg(context, imgUrl, x, y, d)

绘制圆框图片

用法

import { circleImg } from "path/to/mp-canvas";

const ctx = wx.createCanvasContext("myCanvas");

circleImg(ctx, localImageUrl, 20, 493, 20)

ctx.draw();

参数

  • context:canvas 上下文,通过wx.createCanvasContext获得
  • imgUrl:本地图片地址
  • x:圆框图片在x轴上位置,px
  • y:圆框图片在y轴上位置,px
  • d:圆框图片直径,px