Skip to content

Commit

Permalink
feat: 3.2.3 代码完成
Browse files Browse the repository at this point in the history
  • Loading branch information
theajack committed Mar 18, 2023
1 parent de3da44 commit f1e19d9
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a href="https://paypal.me/tackchen">
<img src="https://img.shields.io/badge/Donate-PayPal-142c8e" alt="test">
</a>
<a href="https://shiyix.cn/wx-pay.png">
<a href="https://shiyix.cn/images/wx-pay.png">
<img src="https://img.shields.io/badge/Donate-Wechat Pay-00c250" alt="test">
</a>
</p>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a href="https://paypal.me/tackchen">
<img src="https://img.shields.io/badge/Donate-PayPal-142c8e" alt="test">
</a>
<a href="https://shiyix.cn/wx-pay.png">
<a href="https://shiyix.cn/images/wx-pay.png">
<img src="https://img.shields.io/badge/Donate-Wechat Pay-00c250" alt="test">
</a>
</p>
Expand Down
33 changes: 16 additions & 17 deletions helper/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

1. 拼音联想输入法权重调整
2. 语音识别 优化

## 3.2.3 todo

1. 馡 姈 字补齐 done
2. 梁的繁体也是梁,现在是樑 done
3. spellToWord 部分情况下报错 cnchar.spellToWord('dǐnɡ', 'array') done 字符错误增加了一个提示
4. cnchar.idiom(['','','好','']) -> 模式下仅支持查询首个汉字的拼音 done 增加了第二个可选参数 手动指定类型 cnchar.idiom(['','','好',''], 'char')
5. cnchar.voice无法在苹果设备上播放 done(需要用户交互 增加一个提示)
6. cnchar/src/cnchar/plugin/input/associate/ass-spell.ts 测试代码遗留 done 已删除
7. 字典 离线使用 没有效果
8. cnchar.transformTone('peng4', true).spell // pǐng cnchar.transformTone('zi3', true).spell // zū
9. writer 加上canvas渲染
10. 风的默认读音
11. 例如 【当】字 生成 dānɡ 中的g是全角。在数据检索时会无法匹配。ing、ong、eng都有此问题。
12. draw type为stroke时,没有animateComplete事件,或者说有没有什么其他方式得到绘制完成事件
13. cnchar.sortSpell 排序中有特殊字符或者标点符号方法拿不到返回值
14. 修复word插件在macos ios中的正则零宽断言的兼容性问题
3. writer 加上canvas渲染

## 3.2.3

1. 馡 姈 字补齐 [done]
2. 梁的繁体也是梁,现在是樑 [done]
3. spellToWord 部分情况下报错 cnchar.spellToWord('dǐnɡ', 'array') [done] 字符错误增加了一个提示 ɡ!==g
4. cnchar.idiom(['','','好','']) -> 模式下仅支持查询首个汉字的拼音 [done] 增加了第二个可选参数 手动指定类型 cnchar.idiom(['','','好',''], 'char')
5. cnchar.voice无法在苹果设备上播放 [done](需要用户交互 增加一个提示)
6. cnchar/src/cnchar/plugin/input/associate/ass-spell.ts 测试代码遗留 [done] 已删除
7. 字典 离线使用 没有效果 [done] 修复 cnchar.setResourceBase 无效问题
8. 风的默认读音 [done]
9. draw type为stroke时,没有animateComplete事件,或者说有没有什么其他方式得到绘制完成事件 [done] 增加 onComplete 事件
10. cnchar.sortSpell 排序中有特殊字符或者标点符号方法拿不到返回值 [done] 对非汉字的内容做兼容处理
11. 修复word插件在macos ios中的正则零宽断言的兼容性问题 [done]
12. 增加 restartAnimation 方法 并对pause和resume在step模式下做了bugfix [done]

## 3.2.2

Expand Down
34 changes: 24 additions & 10 deletions public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import '../src/cnchar/plugin/input';
import '../src/cnchar/plugin/name';
import custom from './custom-plugin';
cnchar.use(custom);

cnchar.setResourceBase('https://cdn.jsdelivr.net/npm/cnchar-data/');

// import spell from '../src/main/spell-dict-jian.json';
// // import cncharDraw from '../src/plugin/draw';
Expand Down Expand Up @@ -98,26 +98,40 @@ console.log(cnchar.xhy('上晃下摇', 'fuzzy', 'answer', 'second')); // ['醉
// // 返回数组
// console.log(cnchar.radical('你好呀', 'array')); // ["亻", "女", "口"]
// window.keys = Object.keys(spell);
cnchar.draw('你好九', {});
cnchar.draw('你好九', {
type: cnchar.draw.TYPE.STROKE,
el: '#drawArea',
style: {
radicalColor: '#44f',
backgroundColor: '#ccc'
},
onComplete () {
console.log('draw normal complete');
}
});
(window as any).ww = cnchar.draw('一三二', {
type: cnchar.draw.TYPE.ANIMATION,
animation: {
animateComplete () {
console.log('animateComplete');
},
loopAnimate: true,
autoAnimate: false, // false 时点击出发animate 只能触发一次
// stepByStep: false
autoAnimate: true, // false 时点击出发animate 只能触发一次
stepByStep: false
},
onComplete () {
console.log('draw animation complete');
}
});
cnchar.draw('你好二', {
// renderer: 'canvas',
type: cnchar.draw.TYPE.STROKE,
el: '#drawArea',
style: {
radicalColor: '#44f',
backgroundColor: '#ccc'
},
test: {
onTestStatus (d: any) {
console.log(d);
}
},
onComplete () {
console.log('draw stroke complete');
}
});
cnchar.draw('中国', {
Expand Down
1 change: 0 additions & 1 deletion src/cnchar-types/plugin/draw/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export interface IDrawClassOption {
}

export interface IDrawStrokeOption {

}

export interface IDrawOption extends IDrawStyleOption, IDrawLineOption, IDrawAnimationOption, IDrawTestOption {
Expand Down
8 changes: 8 additions & 0 deletions src/cnchar-types/plugin/draw/hanzi-writer.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* @Author: chenzhongsheng
* @Date: 2022-10-09 09:18:54
* @Description: Coding something
*/
import {IDrawOption, ITestStatusData} from './common';

declare type TDrawType = 'normal' | 'animation' | 'stroke' | 'test';
Expand Down Expand Up @@ -26,8 +31,11 @@ export default class HanziWriter {
x: number;
y: number;
};
text: string;
pauseAnimation(): void;
resumeAnimation(): void;
setCharacter(str: string): void;
// restartAnimation(): void;
animateStroke(strokeNum: number, options: {onComplete(): void}): void;
V: any;
}
9 changes: 9 additions & 0 deletions src/cnchar-types/plugin/draw/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* @Author: chenzhongsheng
* @Date: 2022-10-09 09:18:54
* @Description: Coding something
*/
import {
IDrawAnimationOption,
IDrawLineOption,
Expand All @@ -19,6 +24,8 @@ export interface IWriterOptionWithoutText {
animation?: IDrawAnimationOption,
stroke?: IDrawStrokeOption,
test?: IDrawTestOption,
onComplete?: () => void,
// renderer?: 'svg'|'canvas',
}
export interface IWriterOption extends IWriterOptionWithoutText {
text?: string;
Expand All @@ -29,8 +36,10 @@ export interface IWriter {
type: TDrawType;
text: Array<string>;
writers: Array<HanziWriter>;
_onComplete?: () => void;
startAnimation(): boolean;
drawNextStroke(onComplete?: ()=>void): boolean;
pauseAnimation(): void;
resumeAnimation(): void;
restartAnimation(): void;
}
2 changes: 1 addition & 1 deletion src/cnchar/common/build-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: tackchen
* @Date: 2022-04-10 19:03:21
* @LastEditors: Please set LastEditors
* @LastEditTime: 2022-06-18 13:12:58
* @LastEditTime: 2023-03-18 22:22:12
* @FilePath: /cnchar/src/cnchar/common/build-resource.ts
* @Description: Coding something
*/
Expand Down
3 changes: 2 additions & 1 deletion src/cnchar/main/dict/spell-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@
"蹲": "dūn",
"靚": "liàng",
"刹": "shā",
"彷": "páng"
"彷": "páng",
"风": "fēng"
}
5 changes: 5 additions & 0 deletions src/cnchar/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* @Author: chenzhongsheng
* @Date: 2022-10-09 09:18:54
* @Description: Coding something
*/
import version from './version';
import {spell, tones, stroke, arg,
dealUpLowFirst, removeTone, sumStroke,
Expand Down
11 changes: 9 additions & 2 deletions src/cnchar/main/utils/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
* @Author: tackchen
* @Date: 2022-04-10 18:31:22
* @LastEditors: Please set LastEditors
* @LastEditTime: 2022-06-18 13:12:04
* @LastEditTime: 2023-03-18 22:27:39
* @FilePath: /cnchar/src/cnchar/main/utils/resource.ts
* @Description: Coding something
*/
import ICnChar from 'cnchar-types';

let resourceBase = '';

export function setResourceBase (url: string): void {
export function setResourceBase (this: ICnChar, url: string): void {
resourceBase = url;
this.plugins.forEach(name => {
const plugin = (this as any)[name];
if (!plugin) return;
plugin._refreshResource?.(this);
});
}

export function getResourceBase (): string {
Expand Down
9 changes: 8 additions & 1 deletion src/cnchar/main/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ function pretreat (spell: string, tone: boolean): string {
if (_cnchar.isCnChar(spell)) {
return _cnchar.spell(spell, ...arr) as string;
}
return _cnchar._.transformTone(spell, tone).spell;
try {
return _cnchar._.transformTone(spell, tone).spell;
} catch (e) {
console.warn(e.message);
return '';
}
}

export function compareSpell (
Expand All @@ -39,7 +44,9 @@ export function compareSpell (
tone: boolean = false
): CompareType {
spell1 = pretreat(spell1, tone);
if (!spell1) return TYPE.MORE;
spell2 = pretreat(spell2, tone);
if (!spell2) return TYPE.LESS;
for (let i = 0; i < spell1.length; i++) {
if (!spell2[i]) { // spell1与spell2值前面拼音一样,但是spell1长度大于spell2 说明 spell1 > spell2
return TYPE.MORE;
Expand Down
2 changes: 0 additions & 2 deletions src/cnchar/main/utils/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export function spell (dict: Json<string>, originArgs: Array<string>): string |
const ch: string = strs[i];

const addIntoPolyRes = (spell: string) => {
debugger;
isDefaultSpell(ch, spell) ? res[i].unshift(spell) : res[i].push(spell);
debugger;
};

if (isCnChar(ch)) { // 如果是汉字
Expand Down
65 changes: 53 additions & 12 deletions src/cnchar/plugin/draw/animation-stroke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: theajack
* @Date: 2021-08-05 23:05:21
* @LastEditor: theajack
* @LastEditTime: 2021-08-06 00:30:19
* @LastEditTime: 2023-03-18 21:37:32
* @Description: Coding something
* @FilePath: \cnchar\src\cnchar\plugin\draw\animation-stroke.ts
*/
Expand Down Expand Up @@ -41,7 +41,7 @@ export class AnimationWriter {
}

private _getCurrentCharStrokeNumber () {
return this.writers[this.currentCharIndex].V.strokes.length;
return this.curWriter.V.strokes.length;
}

private _isStepMode () {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class AnimationWriter {
writer.hideCharacter();
});
}
this.writers[this.currentCharIndex].animateStroke(this.currentStrokeIndex, {
this.curWriter.animateStroke(this.currentStrokeIndex, {
onComplete: () => {
onComplete();
this.strokeDrawLocked = false;
Expand All @@ -111,33 +111,69 @@ export class AnimationWriter {
return false;
}
this.drawMode = DRAW_MODE.ANIMATION;
this._start();
return true;
}

_start () {
if (this.option.loopAnimate) {
this._loop();
} else {
this._animate(this.option.animateComplete);
this._animate(this._onAnimateComplete);
}
return true;
}

_onAnimateComplete () {
this.option.animateComplete?.();
this.writer._onComplete?.();
}

pause () {
if (this.isPaused || !this._isStepMode()) return;
if (this.isPaused) return;
this.isPaused = true;

this.writers[this.currentCharIndex].pauseAnimation();
if (this._isStepMode()) {
this.curWriter.pauseAnimation();
} else {
this.writers.forEach(w => {w.pauseAnimation();});
}
}

resume () {
if (!this.isPaused || !this._isStepMode()) return;
if (!this.isPaused) return;
this.isPaused = false;

this.writers[this.currentCharIndex].resumeAnimation();
if (this._isStepMode()) {
this.curWriter.resumeAnimation();
} else {
this.writers.forEach(w => {w.resumeAnimation();});
}
}

restart () {
if (this._isStepMode()) {
this.pause();
clearTimeout(this._strokeTimer);
const curWriter = this.curWriter;
curWriter.setCharacter(curWriter.text);
this._start();
setTimeout(() => {
this.isPaused = false;
}, 10);
} else {
this.writers.forEach(w => {w.setCharacter(w.text);});
}
}


get curWriter () {
return this.writers[this.currentCharIndex];
}

private _loop () {
const opt = this.option;
this._animate(() => {
if (opt.animateComplete)
opt.animateComplete();
this._onAnimateComplete();
setTimeout(() => {
this._loop();
}, opt.delayBetweenStrokes);
Expand All @@ -156,11 +192,16 @@ export class AnimationWriter {
}
});
}

private _strokeTimer: any = null;

private _animateStep (index: number, complete: IComplete = () => {}): void {
this.currentCharIndex = index;
this._animateSingle(index, (end: boolean) => {
if (this.isPaused) return;
if (!end) {
setTimeout(() => {
this._strokeTimer = setTimeout(() => {
if (this.isPaused) return;
this._animateStep(index + 1, complete);
}, this.option.delayBetweenStrokes);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cnchar/plugin/draw/hanzi-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ export default (function (n) {
var r = this;
return (
this.cancelQuiz(),
(this.J = n),
(this.text = n),
this.Q && this.Q.destroy(),
this.F && this.F.cancelAll(),
(this.Q = null),
Expand Down
Loading

0 comments on commit f1e19d9

Please sign in to comment.