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

mem-htmlcanvas

v1.1.3

Published

> 将html dom渲染成海报图,前端开发0成本上手。 > 依赖xtemplate模板预发,可以学习其基本语法 [xtemplate](https://www.npmjs.com/package/xtemplate) > 如果不使用模板渲染没关系,可以直接使用已有dom进行渲染,详情情看文档

Downloads

14

Readme

MemHtmlCanvas 海报图合成工具

将html dom渲染成海报图,前端开发0成本上手。 依赖xtemplate模板预发,可以学习其基本语法 xtemplate 如果不使用模板渲染没关系,可以直接使用已有dom进行渲染,详情情看文档


安装

$ npm install mem-htmlcanvas --save

用法

new MemHtmlCanvas(xtpl, [options]); MemHtmlCanvas.renderFragment(dom, [options]);


import MemHtmlCanvas from 'mem-htmlcanvas';
import shareXtpl from './share.xtpl';

const canvasObj = new MemHtmlCanvas(shareXtpl);

const data = {
    nick: '哆啦A梦',
    tel: 18815583912
}
canvasObj.render(data).then(({imgUrl}) => {
    // imgUrl则为生成海报图的base64编码
});

// 或者

MemHtmlCanvas.renderFragment(document.querySelect('#box')).then(({imgUrl}) => {
    // imgUrl则为生成海报图的base64编码
});


文档

OPTIONS

preview : true(默认)/false

是否开启预览功能,如果为true,则可以用previewDom.show();预览渲染结果,如果为false,则只输出canvas对象。

canvasObj.render(data).then(({imgUrl, previewDom}) => {
    previewDom.show();
});

onlyCanvas : true/false(默认)

是否只渲染canvas,如果为true,则不会有imgUrl生成。

const canvasObj = new MemHtmlCanvas(shareXtpl, {
    onlyCanvas: true,
});

canvasObj.render(data).then(({imgUrl, previewDom}) => {
    previewDom.show();
});

scale: 2(默认)

canvas画布默认放大比例,一般不修改。

注意事项

  • canvas不支持多行文本溢出截取的属性,本模块输出textOverflow方法可以给你处理此ui问题,用法如下:
import {textOverflow} from 'mem-htmlcanvas';
let title = textOverflow({
    width: 320, // 容器的宽度
    fontSize: 36, // 文本字体
    line: 2, // 文本显示多少行
    lineHeight: 42, // 行高
    text: '舒比奇动动乐舞曲小内裤M22/L20/XL18/XXL18片【1包装】'
})