Git Product home page Git Product logo

hanzi-writer-miniprogram's Introduction

Hanzi Writer Wechat Miniprogram Plugin (微信小程序组件)

CircleCI npm

Warning

This miniprogram plugin is no longer maintained. The last version can be installed with npm install hanzi-writer-miniprogram@beta.

This component can be used in a Wechat miniprogram to add Hanzi Writer for character stroke animations and quizzing.

Installation

npm install hanzi-writer-miniprogram

Usage

In your page.json, first add the following to enable the hanzi-writer-view component:

{
  "usingComponents": {
    "hanzi-writer-view": "hanzi-writer-miniprogram/hanzi-writer-view"
  }
}

Then, add a hanzi-writer-view component to your page. You must add an id, width, and height, like below:

<hanzi-writer-view id="hz-writer" width="300" height="300" />

Then in your page, you can control the view via createHanziWriterContext(options), like below:

import createHanziWriterContext from 'hanzi-writer-miniprogram';

Page({
  onLoad: function() {
    this.writerCtx = createHanziWriterContext({
      id: 'hz-writer',
      character: '你',
      page: this,
    });

    // You can call any normal HanziWriter method here
    this.writerCtx.loopCharacterAnimation();
  }
});

This method requires the id from the hanzi-writer-view component in wxml, and the current page.

By default, character data is loaded from the hanzi-writer CDN, so you'll need to add https://cdn.jsdelivr.net to your list of approved domain names. Otherwise, you can provide your own charDataLoader function and load character data however you like. You can read more about loading character data here.

You can also pass any other normal Hanzi Writer options to createHanziWriterContext, except for width and height which are set in the hanzi-writer-view component. You can see a full list of options here.

Further Documentations

For more info and docs on Hanzi Writer check out https://chanind.github.io/hanzi-writer

Data source

The chinese character svg and stroke order data used by Hanzi Writer is derived from the Make me a Hanzi project with some slight tweaks. The data can be found in the Hanzi Writer Data repo. There's a visualizer for this data here.

Contributing

Pull requests are welcome! If you would like to contribute code, you'll need to be able to build the project locally. After cloning the Hanzi Writer repo, you can get it set up by running:

yarn install

LICENSE

Hanzi Writer is released under an MIT license.

The Hanzi Writer data comes from the Make Me A Hanzi project, which extracted the data from fonts by Arphic Technology, a Taiwanese font forge that released their work under a permissive license in 1999. You can redistribute and/or modify this data under the terms of the Arphic Public License as published by Arphic Technology Co., Ltd. A copy of this license can be found in ARPHICPL.TXT.

hanzi-writer-miniprogram's People

Contributors

chanind avatar junaya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hanzi-writer-miniprogram's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

problem when built with uni-app for app

Hi, the hanzi-writer is a nice project. Thanks a lot.

I changed the code for usage in uni-app(which could use Vue to write miniprogram and app).

It runs well in miniprogram, but not correct when built into app.

image

  • it will black all strokes when first stoke ani;
  • can not see the animation;
  • has blank in stroke;

I'm trying to see the code to know why.

If any suggestion on why it could be that, please let me know.

Thanks.

iPhone6 run the hanzi-writer slowly

I copy the demo and test the quiz feature by iphone 6 ( ios 12.4 ). it seem the miniprogram respond slowly after a stroke. But it is faster on android phone. can improve the performance for iphone 6?

微信小程序基础库2.32.3不能显示汉字

调试时运行报错
WAServiceMainContext.js?t=wechat&s=1702002645097&v=2.32.3:1
TypeError: Cannot read property 'clearRect' of undefined
at HanziWriterRenderer._animationFrame (hanzi-writer.js:2427)
at HanziWriterRenderer.render (hanzi-writer.js:2441)
at hanzi-writer.js:1201

请问有人有遇到吗,要怎么解决,谢谢

微信小程序引用的时候显示缺少声明文件,怎么解决

Error: module "miniprogram_npm/hanzi-writer-miniprogram/hanzi-writer" is not defined
module "C:/Users/123/Desktop/\u4E2D\u6587\u6D3Emini/weapp-house-mall-master/node_modules/_hanzi-writer-miniprogram@1.0.4@hanzi-writer-miniprogram/miniprogram_dist/index"
无法找到模块“hanzi-writer-miniprogram”的声明文件。“C:/Users/123/Desktop/中文派mini/weapp-house-mall-master/node_modules/_hanzi-writer-miniprogram@1.0.4@hanzi-writer-miniprogram/miniprogram_dist/index.js”隐式拥有 "any" 类型。
Try npm install @types/hanzi-writer-miniprogram if it exists or add a new declaration (.d.ts) file containing declare module 'hanzi-writer-miniprogram';ts(7016)

Finally! Half done! About display problems!(最终,搞定一半!关于显示问题!)

I modified this file:

file:miniprogram_npm/hanzi-writer-miniprogram/index.js
method:var RenderTarget = function () { // xxxxx }

  function RenderTarget(view) {
    _classCallCheck(this, RenderTarget);

    this.view = view;
    this.eventEmitter = new _EventEmitter2.default();
    //this.ctx = polyfillCanvasCtx(wx.createCanvasContext('writer-canvas', view));
    //this.canvas = this.view.selectComponent('#writer-canvas');

    const query = wx.createSelectorQuery().in(view);
    query.select('#writer-canvas')
         .fields({ node: true, size: true })
	 .exec((res) => {
            console.log("res1");
            console.log(res);
            console.log("res2");

            this.canvas = res[0].node;
            //this.ctx = polyfillCanvasCtx(this.canvas.getContext('2d'));
            this.ctx = this.canvas.getContext('2d');
         });
  }

截屏2021-11-19 下午2 04 41 2

but, there is a problem its display:

截屏2021-11-19 下午2 11 38

how to debug

how to build the dev project? I want to debug it.

Abnormal display of real machine

In the simulator of the wechat miniprogram development environment, the display of canvas Chinese characters is correct. however, on a real machine, preview, canvas's strokes looks like reversed, scale problem? iPhone6+ In latest version of WeChat.

Unable to initiate Path2D of strokes during preview on a real phone

I am porting this component to a Taro component.
It runs pretty well in Wechat's dev tool, but I met this error during preview on an android phone.

MiniProgramError: "illegal param to init BindingPath2D" String

It looks like that HanziWriter's StrokeRenderer is using Path2D by default, which Wechat does not support very well on real phone, thus during preview on real phone, no stroke has been rendered to the canvas.

A bypass is to change the constructor of StrokeRenderer not to use Path2D, but I really would like to know, you how you guys solve this issue, if it ever happened to you?

微信小程序中怎么实现这个功能

function renderFanningStrokes(target, strokes) {
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.style.width = '75px';
svg.style.height = '75px';
svg.style.border = '1px solid #EEE'
svg.style.marginRight = '3px'
target.appendChild(svg);
var group = document.createElementNS('http://www.w3.org/2000/svg', 'g');

// set the transform property on the g element so the character renders at 75x75
var transformData = HanziWriter.getScalingTransform(75, 75);
group.setAttributeNS(null, 'transform', transformData.transform);
svg.appendChild(group);

strokes.forEach(function(strokePath) {
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttributeNS(null, 'd', strokePath);
// style the character paths
path.style.fill = '#555';
group.appendChild(path);
});
}

HanziWriter.loadCharacterData('是').then(function(charData) {
var target = document.getElementById('target');
for (var i = 0; i < charData.strokes.length; i++) {
var strokesPortion = charData.strokes.slice(0, i + 1);
renderFanningStrokes(target, strokesPortion);
}
});

how can i use this method @ miniprogarm please

module "pages/index1/hanzi-writer-miniprogram" is not defined

Followed instruction part of Doc as following:

But when I try to preview my mini program, there's an error as following:

index1 is my current main page, and I'm pretty sure hanzi-writer-miniprogram was installed currectly.

Not sure why it checks plugin under index1. Could anybody help? Thanks in advance!

How to optimize slow in miniprogram?

Hi, chanind

In Quiz model
User drawing a straight line is ok, But drawing the polyline is very slow.

In iphone, painting every step is very slow?

Please give me some optimize suggestions, thx

微信小程序2d 按代码添加后不显示

您好!请问一下微信小程序添加之后 用更新的 2d 的那种方式 ,但是画布不显示! 然后用旧版的方式,书写测验的时候也不能用加粗的功能,drawingWidth 就是这个设置不起作用 请帮忙看看

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.