hanzi-writer
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -1,2 +0,6 @@ | ||
/*! Hanzi Writer v2.3.0 | https://chanind.github.io/hanzi-writer */ | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.HanziWriter=i():t.HanziWriter=i()}("undefined"!=typeof self?self:this,function(){return function(n){var r={};function o(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return n[t].call(i.exports,i,i.exports,o),i.l=!0,i.exports}return o.m=n,o.c=r,o.d=function(t,i,n){o.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},o.n=function(t){var i=t&&t.t?function(){return t.default}:function(){return t};return o.d(i,"a",i),i},o.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},o.p="",o(o.s=9)}([function(c,t,i){"use strict";(function(t){var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var i=t.performance&&function(){return t.performance.now()}||function(){return Date.now()},n=t.requestAnimationFrame||function(t){return setTimeout(function(){return t(i())},1e3/60)},r=t.cancelAnimationFrame||clearTimeout,o=function(t){for(var n=Object(t),i=arguments.length,r=Array(1<i?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];return r.forEach(function(t){if(null!=t)for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i])}),n},h=Object.assign||o;var s=0;var e=t.navigator&&t.navigator.userAgent||"",a=0<e.indexOf("MSIE ")||0<e.indexOf("Trident/")||0<e.indexOf("Edge/");c.exports={e:o,arrLast:function(t){return t[t.length-1]},assign:h,average:function(t){return t.reduce(function(t,i){return i+t},0)/t.length},callIfExists:function(t,i){return t&&t(i),i},cancelAnimationFrame:r,colorStringToVals:function(t){var i=t.toUpperCase().trim();if(/^#([A-F0-9]{3}){1,2}$/.test(i)){var n=i.substring(1).split("");3===n.length&&(n=[n[0],n[0],n[1],n[1],n[2],n[2]]);var r=""+n.join("");return{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16),a:1}}var o=i.match(/^RGBA?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*(\d*\.?\d+))?\)$/);if(o)return{r:parseInt(o[1],10),g:parseInt(o[2],10),b:parseInt(o[3],10),a:parseFloat(o[4]||1,10)};throw new Error("Invalid color: "+t)},copyAndMergeDeep:function t(i,n){var r=h({},i);for(var o in n){var s=i[o],e=n[o];s!==e&&(s&&e&&"object"===(void 0===s?"undefined":u(s))&&"object"===(void 0===e?"undefined":u(e))&&!Array.isArray(e)?r[o]=t(s,e):r[o]=e)}return r},counter:function(){return++s},emptyFunc:function(){},inflate:function(t,i){for(var n=t.split("."),r={},o=r,s=0;s<n.length;s++){var e=s===n.length-1?i:{};o[n[s]]=e,o=e}return r},objRepeat:function(t,i){for(var n={},r=0;r<i;r++)n[r]=t;return n},performanceNow:i,requestAnimationFrame:n,timeout:function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;return new Promise(function(t,i){setTimeout(t,n)})},trim:function(t){return t.replace(/^\s+/,"").replace(/\s+$/,"")},isMsBrowser:a}}).call(t,i(1))},function(Ia,Ja){var Ka;Ka=function(){return this}();try{Ka=Ka||Function("return this")()||eval("this")}catch(t){"object"==typeof window&&(Ka=window)}Ia.exports=Ka},function(t,i,n){"use strict";var r=n(0),e=r.average,v=r.arrLast,u=function(t,i){return{x:t.x-i.x,y:t.y-i.y}},s=function(t){return Math.sqrt(Math.pow(t.x,2)+Math.pow(t.y,2))},l=function(t,i){return s(u(t,i))},h=function(t){var i=10*(1<arguments.length&&void 0!==arguments[1]?arguments[1]:1);return{x:Math.round(i*t.x)/i,y:Math.round(i*t.y)/i}},d=function(t){var r=t[0];return t.slice(1).reduce(function(t,i){var n=l(i,r);return r=i,t+n},0)},p=function(t,i,n){var r=u(i,t),o=n/s(r);return{x:i.x+o*r.x,y:i.y+o*r.y}},a=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:.05,u=t.slice(0,1);return t.slice(1).forEach(function(t){var i=u[u.length-1],n=l(t,i);if(e<n)for(var r=Math.ceil(n/e),o=n/r,s=0;s<r;s++)u.push(p(t,i,-1*o*(s+1)));else u.push(t)}),u},c=function(t){for(var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:30,n=d(t)/(i-1),r=[t[0]],o=v(t),s=t.slice(1),e=0;e<i-2;e++)for(var u=v(r),h=n,a=!1;!a;){var c=l(u,s[0]);if(c<h)h-=c,u=s.shift();else{var f=p(u,s[0],h-c);r.push(f),a=!0}}return r.push(o),r},f=function(t){if(t.length<3)return t;var s=[t[0],t[1]];return t.slice(2).forEach(function(t,i){var n=s.length,r=u(t,s[n-1]),o=u(s[n-1],s[n-2]);r.y*o.x-r.x*o.y==0&&s.pop(),s.push(t)}),s};t.exports={round:h,equals:function(t,i){return t.x===i.x&&t.y===i.y},distance:l,getPathString:function(t){var i=1<arguments.length&&void 0!==arguments[1]&&arguments[1],n=h(t[0]),r=t.slice(1),o="M "+n.x+" "+n.y;return r.forEach(function(t){var i=h(t);o+=" L "+i.x+" "+i.y}),i&&(o+="Z"),o},frechetDist:function(r,o){for(var s=[],t=0;t<r.length;t++){s.push([]);for(var i=0;i<o.length;i++)s[t].push(-1)}return function t(i,n){return-1<s[i][n]||(s[i][n]=0===i&&0===n?l(r[0],o[0]):0<i&&0===n?Math.max(t(i-1,0),l(r[i],o[0])):0===i&&0<n?Math.max(t(0,n-1),l(r[0],o[n])):0<i&&0<n?Math.max(Math.min(t(i-1,n),t(i-1,n-1),t(i,n-1)),l(r[i],o[n])):1/0),s[i][n]}(r.length-1,o.length-1)},length:d,rotate:function(t,i){return t.map(function(t){return{x:Math.cos(i)*t.x-Math.sin(i)*t.y,y:Math.sin(i)*t.x+Math.cos(i)*t.y}})},subtract:u,extendStart:function(t,i){var n=f(t);if(n.length<2)return n;var r=n[1],o=n[0],s=p(r,o,i),e=n.slice(1);return e.unshift(s),e},cosineSimilarity:function(t,i){return(t.x*i.x+t.y*i.y)/s(t)/s(i)},outlineCurve:c,u:p,h:f,subdivideCurve:a,normalizeCurve:function(t){var i=c(t),n={x:e(i.map(function(t){return t.x})),y:e(i.map(function(t){return t.y}))},r=i.map(function(t){return u(t,n)}),o=Math.sqrt(e([Math.pow(r[0].x,2)+Math.pow(r[0].y,2),Math.pow(v(r).x,2)+Math.pow(v(r).y,2)])),s=r.map(function(t){return{x:t.x/o,y:t.y/o}});return a(s)}}},function(t,i,n){"use strict";(function(n){function r(t,i,n){t.setAttributeNS(null,i,n)}t.exports={createElm:function(t){return n.document.createElementNS("http://www.w3.org/2000/svg",t)},attrs:function(i,n){Object.keys(n).forEach(function(t){return r(i,t,n[t])})},attr:r,removeElm:function(t){t&&t.parentNode.removeChild(t)},urlIdRef:function(t){var i="";return n.location&&n.location.href&&(i=n.location.href.replace(/#[^#]*$/,"")),"url("+i+"#"+t+")"}}}).call(i,n(1))},function(t,i,n){"use strict";function s(t,i,n){return i in t?Object.defineProperty(t,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[i]=n,t}var u=n(5),e=n(0).objRepeat,h=function(t,i,n){return[new u("character."+t+".strokes",e({opacity:1,displayPortion:1},i.strokes.length),{duration:n,force:!0})]},a=function(t,i,n){return[new u("character."+t+".opacity",0,{duration:n,force:!0})].concat(h(t,i,0))},c=function(t,i,n){var r=i.strokeNum,o=(i.getLength()+600)/(3*n);return[new u("character."+t,{opacity:1,strokes:s({},r,{displayPortion:0,opacity:1})}),new u("character."+t+".strokes."+r+".displayPortion",1,{duration:o})]},f=function(n,t,i,r,o){var s=a(n,t,i);return(s=s.concat(h(n,t,0))).push(new u("character."+n,{opacity:1,strokes:e({opacity:0},t.strokes.length)},{force:!0})),t.strokes.forEach(function(t,i){0<i&&s.push(new u.Delay(o)),s=s.concat(c(n,t,r))}),s};t.exports={showStrokes:h,showCharacter:function(t,i,n){return[new u("character."+t,{opacity:1,strokes:e({opacity:1,displayPortion:1},i.strokes.length)},{duration:n,force:!0})]},hideCharacter:a,highlightStroke:function(t,i,n){var r=t.strokeNum,o=(t.getLength()+600)/(3*n);return[new u("character.highlight.strokeColor",i),new u("character.highlight",{opacity:1,strokes:s({},r,{displayPortion:0,opacity:0})}),new u("character.highlight.strokes."+r,{displayPortion:1,opacity:1},{duration:o}),new u("character.highlight.strokes."+r+".opacity",0,{duration:o})]},animateCharacter:f,animateCharacterLoop:function(t,i,n,r,o,s){var e=f(t,i,n,r,o);return e.push(new u.Delay(s)),e},animateStroke:c,animateSingleStroke:function(o,s,t,i){return[new u("character."+o,function(t){for(var i=t.character[o],n={opacity:1,strokes:{}},r=0;r<s.strokes.length;r++)n.strokes[r]={opacity:i.opacity*i.strokes[r].opacity};return n})].concat(c(o,s.strokes[t],i))},showStroke:function(t,i,n){return[new u("character."+t+".strokes."+i,{displayPortion:1,opacity:1},{duration:n,force:!0})]},updateColor:function(t,i,n){return[new u("options."+t,i,{duration:n})]}}},function(t,i,n){"use strict";var r=n(0),o=r.inflate,s=r.performanceNow,e=r.requestAnimationFrame,u=r.cancelAnimationFrame;function h(t,i){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.scope=t,this.f=i,this.v=n.duration||0,this.w=n.force,this.k=0,this.C=this.M.bind(this),this.S=null}function a(t){this.v=t,this.j=null,this.P=!1}h.prototype.run=function(t){var i=this;return this.O||this.A(t),0===this.v&&t.updateState(this.O),0===this.v||function t(i,n){for(var r in n)if(n.hasOwnProperty(r)){var o=n[r],s=i[r];if(0<=o){if(o!==s)return!1}else if(!t(s,o))return!1}return!0}(t.state,this.O)?Promise.resolve():(this.F=t,this.D=t.state,this.j=s(),this.T=e(this.C),new Promise(function(t){i.I=t}))},h.prototype.pause=function(){null===this.S&&(this.T&&u(this.T),this.S=s())},h.prototype.resume=function(){null!==this.S&&(this.T=e(this.C),this.k+=s()-this.S,this.S=null)},h.prototype.M=function(t){if(null===this.S){var i,n=Math.min(1,(t-this.j-this.k)/this.v);if(1===n)this.F.updateState(this.O),this.T=null,this.cancel(this.F);else{var r=(i=n,-Math.cos(i*Math.PI)/2+.5);this.F.updateState(function t(i,n,r){var o={};for(var s in n){var e=n[s],u=i[s];o[s]=0<=e?r*(e-u)+u:t(u,e,r)}return o}(this.D,this.O,r)),this.T=e(this.C)}}},h.prototype.A=function(t){var i=this.f;"function"==typeof this.f&&(i=this.f(t.state)),this.O=o(this.scope,i)},h.prototype.cancel=function(t){this.I&&this.I(),this.I=null,this.T&&u(this.T),this.T=null,this.w&&(this.O||this.A(t),t.updateState(this.O))},a.prototype.pause=function(){if(!this.P){var t=s()-this.j;this.v=Math.max(0,this.v-t),clearTimeout(this.W),this.P=!0}},a.prototype.resume=function(){var t=this;this.P&&(this.j=s(),this.W=setTimeout(function(){return t.cancel()},this.v),this.P=!1)},a.prototype.run=function(){var i=this,t=new Promise(function(t){i.I=t});return this.j=s(),this.W=setTimeout(function(){return i.cancel()},this.v),t},a.prototype.cancel=function(){clearTimeout(this.W),this.I&&this.I(),this.I=!1},h.Delay=a,t.exports=h},function(t,i,n){"use strict";function r(){}r.prototype.z=function(t){return.999*this.R*(1-t)},r.prototype.H=function(t){var i=t.strokeColor,n=t.radicalColor;return n&&this.L.isInRadical?n:i},t.exports=r},function(n,t,i){"use strict";(function(i){function t(){}t.prototype.addPointerStartListener=function(i){var n=this;this.node.addEventListener("mousedown",function(t){i(n.U(t,n._))}),this.node.addEventListener("touchstart",function(t){i(n.U(t,n.K))})},t.prototype.addPointerMoveListener=function(i){var n=this;this.node.addEventListener("mousemove",function(t){i(n.U(t,n._))}),this.node.addEventListener("touchmove",function(t){i(n.U(t,n.K))})},t.prototype.addPointerEndListener=function(t){i.document.addEventListener("mouseup",t),i.document.addEventListener("touchend",t)},t.prototype.getBoundingClientRect=function(){return this.node.getBoundingClientRect()},t.prototype.U=function(t,i){var n=this;return{getPoint:function(){return i.call(n,t)},preventDefault:function(){return t.preventDefault()}}},t.prototype._=function(t){var i=this.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}},t.prototype.K=function(t){var i=this.getBoundingClientRect();return{x:t.touches[0].clientX-i.left,y:t.touches[0].clientY-i.top}},n.exports=t}).call(t,i(1))},function(t,i,n){"use strict";t.exports={drawPath:function(i,t){i.beginPath();var n=t[0],r=t.slice(1);i.moveTo(n.x,n.y),r.forEach(function(t){i.lineTo(t.x,t.y)}),i.stroke()},pathStringToCanvas:function(t){var i=t.split(/(^|\s+)(?=[A-Z])/).filter(function(t){return" "!==t}),e=[function(t){return t.beginPath()}];return i.forEach(function(t){var i,n=t.split(/\s+/),r=(i=n,Array.isArray(i)?i:Array.from(i)),o=r[0],s=r.slice(1).map(function(t){return parseFloat(t)});"M"===o?e.push(function(t){return t.moveTo.apply(t,s)}):"L"===o?e.push(function(t){return t.lineTo.apply(t,s)}):"C"===o?e.push(function(t){return t.bezierCurveTo.apply(t,s)}):"Q"===o&&e.push(function(t){return t.quadraticCurveTo.apply(t,s)})}),function(i){return e.forEach(function(t){return t(i)})}}}},function(t,i,n){"use strict";var o=n(10),s=n(11),e=n(14),r=n(15),u=n(19),h=n(25),a=n(31),c=n(32),f=n(4),v=n(0),l=v.assign,d=v.callIfExists,p=v.trim,y=v.colorStringToVals,w={charDataLoader:a,onLoadCharDataError:null,onLoadCharDataSuccess:null,showOutline:!0,showCharacter:!0,renderer:"svg",width:null,height:null,padding:20,strokeAnimationSpeed:1,strokeFadeDuration:400,strokeHighlightDuration:200,strokeHighlightSpeed:2,delayBetweenStrokes:1e3,delayBetweenLoops:2e3,strokeColor:"#555",radicalColor:null,highlightColor:"#AAF",outlineColor:"#DDD",drawingColor:"#333",leniency:1,showHintAfterMisses:3,highlightOnComplete:!0,highlightCompleteColor:null,drawingFadeDuration:300,drawingWidth:4,strokeWidth:2,outlineWidth:2,rendererOverride:{}};function g(){if(0<arguments.length){var t=void 0,i={},n=arguments.length<=0?void 0:arguments[0];1<arguments.length&&(i="string"==typeof(arguments.length<=1?void 0:arguments[1])?(console.warn("Using new HanziWriter() to set a character is deprecated. Use HanziWriter.create() instead"),t=arguments.length<=1?void 0:arguments[1],(arguments.length<=2?void 0:arguments[2])||{}):arguments.length<=1?void 0:arguments[1]),this.N(n,i),t&&this.setCharacter(t)}}g.prototype.showCharacter=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.B.showCharacter=!0,this.G(function(){return t.F.run(f.showCharacter("main",t.V,"number"==typeof i.duration?i.duration:t.B.strokeFadeDuration)).then(function(t){return d(i.onComplete,t)})})},g.prototype.hideCharacter=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.B.showCharacter=!1,this.G(function(){return t.F.run(f.hideCharacter("main",t.V,"number"==typeof i.duration?i.duration:t.B.strokeFadeDuration)).then(function(t){return d(i.onComplete,t)})})},g.prototype.animateCharacter=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.cancelQuiz(),this.G(function(){return t.F.run(f.animateCharacter("main",t.V,t.B.strokeFadeDuration,t.B.strokeAnimationSpeed,t.B.delayBetweenStrokes)).then(function(t){return d(i.onComplete,t)})})},g.prototype.animateStroke=function(t){var i=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return this.cancelQuiz(),this.G(function(){return i.F.run(f.animateSingleStroke("main",i.V,t,i.B.strokeAnimationSpeed)).then(function(t){return d(n.onComplete,t)})})},g.prototype.highlightStroke=function(t){var i=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return this.G(function(){return i.F.run(f.highlightStroke(i.V.strokes[t],i.B.highlightColor,i.B.strokeHighlightSpeed)).then(function(t){return d(n.onComplete,t)})})},g.prototype.loopCharacterAnimation=function(){var t=this;0<arguments.length&&void 0!==arguments[0]&&arguments[0];return this.cancelQuiz(),this.G(function(){return t.F.run(f.animateCharacterLoop("main",t.V,t.B.strokeFadeDuration,t.B.strokeAnimationSpeed,t.B.delayBetweenStrokes,t.B.delayBetweenLoops),{loop:!0})})},g.prototype.pauseAnimation=function(){var t=this;return this.G(function(){return t.F.pauseAll()})},g.prototype.resumeAnimation=function(){var t=this;return this.G(function(){return t.F.resumeAll()})},g.prototype.showOutline=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.B.showOutline=!0,this.G(function(){return t.F.run(f.showCharacter("outline",t.V,"number"==typeof i.duration?i.duration:t.B.strokeFadeDuration)).then(function(t){return d(i.onComplete,t)})})},g.prototype.hideOutline=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.B.showOutline=!1,this.G(function(){return t.F.run(f.hideCharacter("outline",t.V,"number"==typeof i.duration?i.duration:t.B.strokeFadeDuration)).then(function(t){return d(i.onComplete,t)})})},g.prototype.updateColor=function(o,s){var e=this,u=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return this.G(function(){var t="number"==typeof u.duration?u.duration:e.B.strokeFadeDuration,i=s;"radicalColor"!==o||s||(i=e.B.strokeColor);var n=y(i);e.B[o]=s;var r=f.updateColor(o,n,t);return"radicalColor"!==o||s||(r=r.concat(f.updateColor(o,null,0))),e.F.run(r).then(function(t){return d(u.onComplete,t)})})},g.prototype.quiz=function(){var t=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.G(function(){t.cancelQuiz(),t.$=new r(t.V,t.F,t.q),t.$.startQuiz(l({},t.B,i))})},g.prototype.cancelQuiz=function(){this.$&&(this.$.cancel(),this.$=null)},g.prototype.setCharacter=function(n){var r=this;return this.cancelQuiz(),this.J=n,this.Q&&this.Q.destroy(),this.F&&this.F.cancelAll(),this.Q=null,this.Z=this.X.loadCharData(n).then(function(t){if(!r.X.loadingFailed){r.V=s(n,t),r.q=new e(r.B);var i=new r.Y.HanziWriterRenderer(r.V,r.q);r.Q=i,r.F=new o(r.V,r.B,function(t){i.render(t)}),r.Q.mount(r.target),r.Q.render(r.F.state)}}),this.Z},g.prototype.N=function(t,i){var n="canvas"===i.renderer?h:u,r=i.rendererOverride||{};return this.Y={HanziWriterRenderer:r.HanziWriterRenderer||n.HanziWriterRenderer,createRenderTarget:r.createRenderTarget||n.createRenderTarget},this.target=this.Y.createRenderTarget(t,i.width,i.height),this.B=this.tt(i),this.X=new c(this.B),this.it(),this.$=null,this},g.prototype.tt=function(t){var i=l({},w,t);return t.strokeAnimationDuration&&!t.strokeAnimationSpeed&&(i.strokeAnimationSpeed=500/i.strokeAnimationDuration),t.strokeHighlightDuration&&!t.strokeHighlightSpeed&&(i.strokeHighlightSpeed=500/i.strokeHighlightDuration),t.highlightCompleteColor||(i.highlightCompleteColor=i.highlightColor),this.nt(i)},g.prototype.nt=function(t){var i=l({},t);if(i.width&&!i.height)i.height=i.width;else if(i.height&&!i.width)i.width=i.height;else if(!i.width&&!i.height){var n=this.target.getBoundingClientRect(),r=n.width,o=n.height,s=Math.min(r,o);i.width=s,i.height=s}return i},g.prototype.G=function(t){var i=this;if(this.X.loadingFailed)throw Error("Failed to load character data. Call setCharacter and try again.");return this.Z.then(function(){if(!i.X.loadingFailed)return t()})},g.prototype.it=function(){var i=this;this.target.addPointerStartListener(function(t){i.$&&(t.preventDefault(),i.rt("startUserStroke",t.getPoint()))}),this.target.addPointerMoveListener(function(t){i.$&&(t.preventDefault(),i.rt("continueUserStroke",t.getPoint()))}),this.target.addPointerEndListener(function(){return i.rt("endUserStroke")})},g.prototype.rt=function(t){var i;if(this.$){for(var n=arguments.length,r=Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];(i=this.$)[t].apply(i,r)}},g.create=function(t,i){var n=new g(t,2<arguments.length&&void 0!==arguments[2]?arguments[2]:{});return n.setCharacter(i),n};var k=null,m=null;g.loadCharacterData=function(t){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=void 0;return n=k&&m===i?k:new c(l({},w,i)),m=i,(k=n).loadCharData(t)},g.getScalingTransform=function(t,i){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,r=new e({width:t,height:i,padding:n});return{x:r.xOffset,y:r.yOffset,scale:r.scale,transform:p("\n translate("+r.xOffset+", "+(r.height-r.yOffset)+")\n scale("+r.scale+", "+-1*r.scale+")\n ").replace(/\s+/g," ")}},t.exports=g},function(t,i,n){"use strict";var r=n(0),o=r.copyAndMergeDeep,s=r.colorStringToVals;function e(t,i,n){this.ot=n,this.st=[],this.state={options:{drawingFadeDuration:i.drawingFadeDuration,drawingWidth:i.drawingWidth,drawingColor:s(i.drawingColor),strokeColor:s(i.strokeColor),outlineColor:s(i.outlineColor),radicalColor:s(i.radicalColor||i.strokeColor),highlightColor:s(i.highlightColor)},character:{main:{opacity:i.showCharacter?1:0,strokes:{}},outline:{opacity:i.showOutline?1:0,strokes:{}},highlight:{opacity:1,strokes:{}}},userStrokes:null};for(var r=0;r<t.strokes.length;r++)this.state.character.main.strokes[r]={opacity:1,displayPortion:1},this.state.character.outline.strokes[r]={opacity:1,displayPortion:1},this.state.character.highlight.strokes[r]={opacity:0,displayPortion:1}}e.prototype.updateState=function(t){var i=o(this.state,t);this.ot(i,this.state),this.state=i},e.prototype.run=function(n){var r=this,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},s=n.map(function(t){return t.scope}).filter(function(t){return t});return this.cancelMutations(s),new Promise(function(t){var i={et:!0,ut:0,I:t,ht:n,at:o.loop,ct:s};r.st.push(i),r.ft(i)})},e.prototype.ft=function(i){var t=this;if(i.et){var n=i.ht;if(i.ut>=n.length){if(!i.at)return i.et=!1,this.st=this.st.filter(function(t){return t!==i}),void i.I({canceled:!1});i.ut=0}i.ht[i.ut].run(this).then(function(){i.et&&(i.ut++,t.ft(i))})}},e.prototype.vt=function(){return this.st.map(function(t){return t.ht[t.ut]})},e.prototype.pauseAll=function(){this.vt().forEach(function(t){return t.pause()})},e.prototype.resumeAll=function(){this.vt().forEach(function(t){return t.resume()})},e.prototype.cancelMutations=function(t){var r=this;this.st.forEach(function(n){n.ct.forEach(function(i){t.forEach(function(t){(0<=i.indexOf(t)||0<=t.indexOf(i))&&r.lt(n)})})})},e.prototype.cancelAll=function(){this.cancelMutations([""])},e.prototype.lt=function(i){i.et=!1;for(var t=i.ut;t<i.ht.length;t++)i.ht[t].cancel(this);i.I&&i.I({canceled:!0}),this.st=this.st.filter(function(t){return t!==i})},t.exports=e},function(t,i,n){"use strict";var s=function(t,i){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,i){var n=[],r=!0,o=!1,s=void 0;try{for(var e,u=t[Symbol.iterator]();!(r=(e=u.next()).done)&&(n.push(e.value),!i||n.length!==i);r=!0);}catch(t){o=!0,s=t}finally{try{!r&&u.return&&u.return()}finally{if(o)throw s}}return n}(t,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")},e=n(12),r=n(13),o=function(o){return o.strokes.map(function(t,i){var n,r=o.medians[i].map(function(t){var i=s(t,2);return{x:i[0],y:i[1]}});return new e(t,r,i,(n=i,o.radStrokes&&0<=o.radStrokes.indexOf(n)))})};t.exports=function(t,i){var n=o(i);return new r(t,n)}},function(t,i,n){"use strict";var r=n(2),o=r.subtract,s=r.distance,e=r.length;function u(t,i,n){var r=3<arguments.length&&void 0!==arguments[3]&&arguments[3];this.path=t,this.points=i,this.strokeNum=n,this.isInRadical=r}u.prototype.getStartingPoint=function(){return this.points[0]},u.prototype.getEndingPoint=function(){return this.points[this.points.length-1]},u.prototype.getLength=function(){return e(this.points)},u.prototype.getVectors=function(){var n=this.points[0];return this.points.slice(1).map(function(t){var i=o(t,n);return n=t,i})},u.prototype.getDistance=function(i){var t=this.points.map(function(t){return s(t,i)});return Math.min.apply(Math,t)},u.prototype.getAverageDistance=function(t){var n=this;return t.reduce(function(t,i){return t+n.getDistance(i)},0)/t.length},t.exports=u},function(t,i,n){"use strict";t.exports=function(t,i){this.symbol=t,this.strokes=i}},function(t,i,n){"use strict";var a=[{x:0,y:-124},{x:1024,y:900}];function r(t){this.B=t,this.width=t.width,this.height=t.height,this.dt()}r.prototype.convertExternalPoint=function(t){return{x:(t.x-this.xOffset)/this.scale,y:(this.height-this.yOffset-t.y)/this.scale}},r.prototype.dt=function(){var t=a,i=t[1].x-t[0].x,n=t[1].y-t[0].y,r=this.width-2*this.B.padding,o=this.height-2*this.B.padding,s=r/i,e=o/n;this.scale=Math.min(s,e);var u=this.B.padding+(r-this.scale*i)/2,h=this.B.padding+(o-this.scale*n)/2;this.xOffset=-1*t[0].x*this.scale+u,this.yOffset=-1*t[0].y*this.scale+h},t.exports=r},function(t,i,n){"use strict";var r=n(16),o=n(17),s=n(0),e=s.callIfExists,u=s.counter,h=n(18),a=n(2),c=n(4),f=function(t){return{pathString:a.getPathString(t.externalPoints),points:t.points.map(function(t){return a.round(t)})}};function v(t,i,n){this.V=t,this.F=i,this.et=!1,this.q=n}v.prototype.startQuiz=function(t){this.et=!0,this.B=t,this.pt=0,this.yt=0,this.wt=0,this.F.run(h.startQuiz(this.V,t.strokeFadeDuration))},v.prototype.startUserStroke=function(t){var i=this.q.convertExternalPoint(t);if(!this.et)return null;if(this.gt)return this.endUserStroke();var n=u();this.gt=new o(n,i,t),this.F.run(h.startUserStroke(n,i))},v.prototype.continueUserStroke=function(t){if(this.gt){var i=this.q.convertExternalPoint(t);this.gt.appendPoint(i,t);var n=this.gt.points.slice(0);this.F.run(h.updateUserStroke(this.gt.id,n))}},v.prototype.endUserStroke=function(){if(this.gt)if(this.F.run(h.removeUserStroke(this.gt.id,this.B.drawingFadeDuration)),1!==this.gt.points.length){var t=this.kt(),i=0<this.F.state.character.outline.opacity;r(this.gt,this.V,this.pt,{isOutlineVisible:i,leniency:this.B.leniency})?this.mt():(this.bt(),this.yt>=this.B.showHintAfterMisses&&!1!==this.B.showHintAfterMisses&&this.F.run(h.highlightStroke(t,this.B.highlightColor,this.B.strokeHighlightSpeed))),this.gt=null}else this.gt=null},v.prototype.cancel=function(){this.et=!1,this.gt&&this.F.run(h.removeUserStroke(this.gt.id,this.B.drawingFadeDuration))},v.prototype.mt=function(){e(this.B.onCorrectStroke,{character:this.V.symbol,strokeNum:this.pt,mistakesOnStroke:this.yt,totalMistakes:this.wt,strokesRemaining:this.V.strokes.length-this.pt-1,drawnPath:f(this.gt)});var t=c.showStroke("main",this.pt,this.B.strokeFadeDuration);this.pt+=1,this.yt=0,this.pt===this.V.strokes.length&&(this.et=!1,e(this.B.onComplete,{character:this.V.symbol,totalMistakes:this.wt}),this.B.highlightOnComplete&&(t=t.concat(h.highlightCompleteChar(this.V,this.B.highlightCompleteColor,2*this.B.strokeHighlightDuration)))),this.F.run(t)},v.prototype.bt=function(){this.yt+=1,this.wt+=1,e(this.B.onMistake,{character:this.V.symbol,strokeNum:this.pt,mistakesOnStroke:this.yt,totalMistakes:this.wt,strokesRemaining:this.V.strokes.length-this.pt,drawnPath:f(this.gt)})},v.prototype.kt=function(){return this.V.strokes[this.pt]},t.exports=v},function(t,i,n){"use strict";var r=n(0),h=r.average,l=r.assign,o=n(2),a=o.cosineSimilarity,d=o.equals,j=o.frechetDist,P=o.distance,c=o.subtract,x=o.normalizeCurve,O=o.rotate,A=o.length,F=function(t,i){var n,r,o,s=(r=[],o=(n=t)[0],n.slice(1).forEach(function(t){r.push(c(t,o)),o=t}),r),e=i.getVectors(),u=s.map(function(i){var t=e.map(function(t){return a(t,i)});return Math.max.apply(Math,t)});return 0<h(u)},D=[Math.PI/16,Math.PI/32,0,-1*Math.PI/32,-1*Math.PI/16],p=function(t,i,n){var r=n.leniency,o=void 0===r?1:r,s=n.isOutlineVisible,e=void 0!==s&&s,u=i.getAverageDistance(t),h=u<=350*(e||0<i.strokeNum?.5:1)*o;if(!h)return{isMatch:!1,avgDist:u};var a,c,f,v,l,d,p,y,w,g,k,m,b=(a=t,f=o,v=P((c=i).getStartingPoint(),a[0]),l=P(c.getEndingPoint(),a[a.length-1]),v<=250*f&&l<=250*f),C=F(t,i),M=(d=t,p=i.points,y=o,w=x(d),g=x(p),k=1/0,D.forEach(function(t){var i=j(w,O(g,t));i<k&&(k=i)}),k<=.4*y),S=(m=i,.35<=o*(A(t)+25)/(m.getLength()+25));return{isMatch:h&&b&&C&&M&&S,avgDist:u}};t.exports=function(t,i,n){var r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},o=function(t){if(t.length<2)return t;var i=[t[0]];return t.slice(1).forEach(function(t){d(t,i[i.length-1])||i.push(t)}),i}(t.points);if(o.length<2)return null;var s=p(o,i.strokes[n],r);if(!s.isMatch)return!1;for(var e=i.strokes.slice(n+1),u=s.avgDist,h=0;h<e.length;h++){var a=p(o,e[h],r);a.isMatch&&a.avgDist<u&&(u=a.avgDist)}if(u<s.avgDist){var c=.6*(u+s.avgDist)/(2*s.avgDist),f=(r.leniency||1)*c,v=l({},r,{leniency:f});return p(o,i.strokes[n],v).isMatch}return!0}},function(t,i,n){"use strict";function r(t,i,n){this.id=t,this.points=[i],this.externalPoints=[n]}r.prototype.appendPoint=function(t,i){this.points.push(t),this.externalPoints.push(i)},t.exports=r},function(t,i,n){"use strict";var r=n(5),o=n(4),s=n(0).objRepeat;t.exports={highlightCompleteChar:function(t,i,n){return[new r("character.highlight.strokeColor",i)].concat(o.hideCharacter("highlight",t)).concat(o.showCharacter("highlight",t,n/2)).concat(o.hideCharacter("highlight",t,n/2))},highlightStroke:o.highlightStroke,startQuiz:function(t,i){return o.hideCharacter("main",t,i).concat([new r("character.highlight",{opacity:1,strokes:s({opacity:0},t.strokes.length)},{force:!0}),new r("character.main",{opacity:1,strokes:s({opacity:0},t.strokes.length)},{force:!0})])},startUserStroke:function(t,i){return[new r("quiz.activeUserStrokeId",t,{force:!0}),new r("userStrokes."+t,{points:[i],opacity:1},{force:!0})]},updateUserStroke:function(t,i){return[new r("userStrokes."+t+".points",i,{force:!0})]},removeUserStroke:function(t,i){return[new r("userStrokes."+t+".opacity",0,{duration:i}),new r("userStrokes."+t,null,{force:!0})]}}},function(t,i,n){"use strict";var r=n(20),o=n(24);t.exports={HanziWriterRenderer:r,createRenderTarget:o.init}},function(t,i,n){"use strict";var r=n(21),e=n(23),u=n(0).assign,o=n(3);function s(t,i){this.V=t,this.q=i,this.Ct=new r(t),this.Mt=new r(t),this.St=new r(t),this.jt={}}s.prototype.mount=function(t){var i=t.createSubRenderTarget(),n=i.svg;o.attr(n,"transform","\n translate("+this.q.xOffset+", "+(this.q.height-this.q.yOffset)+")\n scale("+this.q.scale+", "+-1*this.q.scale+")\n "),this.Mt.mount(i),this.Ct.mount(i),this.St.mount(i),this.Pt=i},s.prototype.render=function(r){var o=this;this.Mt.render({opacity:r.character.outline.opacity,strokes:r.character.outline.strokes,strokeColor:r.options.outlineColor}),this.Ct.render({opacity:r.character.main.opacity,strokes:r.character.main.strokes,strokeColor:r.options.strokeColor,radicalColor:r.options.radicalColor}),this.St.render({opacity:r.character.highlight.opacity,strokes:r.character.highlight.strokes,strokeColor:r.options.highlightColor});var s=r.userStrokes||{};Object.keys(this.jt).forEach(function(t){s[t]||(o.jt[t].destroy(),delete o.jt[t])}),Object.keys(s).forEach(function(t){if(s[t]){var i=u({strokeWidth:r.options.drawingWidth,strokeColor:r.options.drawingColor},s[t]),n=o.jt[t];n||((n=new e).mount(o.Pt),o.jt[t]=n),n.render(i)}})},s.prototype.destroy=function(){o.removeElm(this.Pt.svg),this.Pt.defs.innerHTML=""},t.exports=s},function(t,i,n){"use strict";var r=n(0).isMsBrowser,o=n(22);function s(t){this.xt={},this.Ot=t.strokes.map(function(t){return new o(t)})}s.prototype.mount=function(t){var n=t.createSubRenderTarget();this.At=n.svg,this.Ot.forEach(function(t,i){t.mount(n)})},s.prototype.render=function(t){if(t!==this.xt){t.opacity!==this.xt.opacity&&(this.At.style.opacity=t.opacity,r||(0===t.opacity?this.At.style.display="none":0===this.xt.opacity&&this.At.style.removeProperty("display")));var i=!this.xt||t.strokeColor!==this.xt.strokeColor||t.radicalColor!==this.xt.radicalColor;if(i||t.strokes!==this.xt.strokes)for(var n=0;n<this.Ot.length;n++)!i&&this.xt.strokes&&t.strokes[n]===this.xt.strokes[n]||this.Ot[n].render({strokeColor:t.strokeColor,radicalColor:t.radicalColor,opacity:t.strokes[n].opacity,displayPortion:t.strokes[n].displayPortion});this.xt=t}},t.exports=s},function(t,i,n){"use strict";var r=n(0).counter,e=n(3),o=n(2),s=o.extendStart,u=o.getPathString,h=n(6);function a(t){this.xt={},this.L=t,this.R=t.getLength()+100}(a.prototype=Object.create(h.prototype)).mount=function(t){this.Ft=e.createElm("path"),this.Dt=e.createElm("clipPath"),this.Tt=e.createElm("path");var i="mask-"+r();e.attr(this.Dt,"id",i),e.attr(this.Tt,"d",this.L.path),this.Ft.style.opacity=0,e.attr(this.Ft,"clip-path",e.urlIdRef(i));var n=s(this.L.points,100);return e.attr(this.Ft,"d",u(n)),e.attrs(this.Ft,{stroke:"#FFFFFF","stroke-width":200,fill:"none","stroke-linecap":"round","stroke-linejoin":"miter","stroke-dasharray":this.R+","+this.R}),this.Dt.appendChild(this.Tt),t.defs.appendChild(this.Dt),t.svg.appendChild(this.Ft),this},a.prototype.render=function(t){if(t!==this.xt){t.displayPortion!==this.xt.displayPortion&&(this.Ft.style.strokeDashoffset=this.z(t.displayPortion));var i=this.H(t);if(i!==this.H(this.xt)){var n=i.r,r=i.g,o=i.b,s=i.a;e.attrs(this.Ft,{stroke:"rgba("+n+","+r+","+o+","+s+")"})}t.opacity!==this.xt.opacity&&(this.Ft.style.opacity=t.opacity),this.xt=t}},t.exports=a},function(t,i,n){"use strict";var e=n(3),u=n(2).getPathString;function r(){this.xt={}}r.prototype.mount=function(t){this.Et=e.createElm("path"),t.svg.appendChild(this.Et)},r.prototype.render=function(t){if(t!==this.xt){if(t.strokeColor!==this.xt.strokeColor||t.strokeWidth!==this.xt.strokeWidth){var i=t.strokeColor,n=i.r,r=i.g,o=i.b,s=i.a;e.attrs(this.Et,{fill:"none",stroke:"rgba("+n+","+r+","+o+","+s+")","stroke-width":t.strokeWidth,"stroke-linecap":"round","stroke-linejoin":"round"})}t.opacity!==this.xt.opacity&&e.attr(this.Et,"opacity",t.opacity),t.points!==this.xt.points&&e.attr(this.Et,"d",u(t.points)),this.xt=t}},r.prototype.destroy=function(){e.removeElm(this.Et)},t.exports=r},function(i,t,r){"use strict";(function(u){var t=r(3),h=t.createElm,a=t.attrs,n=r(7);function c(t,i){this.svg=t,this.defs=i,this.node=t,this.node.createSVGPoint&&(this.It=this.node.createSVGPoint())}(c.prototype=Object.create(n.prototype)).createSubRenderTarget=function(){var t=h("g");return this.svg.appendChild(t),new c(t,this.defs)},c.prototype._=function(t){if(this.It){this.It.x=t.clientX,this.It.y=t.clientY;var i=this.It.matrixTransform(this.node.getScreenCTM().inverse());return{x:i.x,y:i.y}}return n.prototype._.call(this,t)},c.prototype.K=function(t){if(this.It){this.It.x=t.touches[0].clientX,this.It.y=t.touches[0].clientY;var i=this.It.matrixTransform(this.node.getScreenCTM().inverse());return{x:i.x,y:i.y}}return n.prototype.K.call(this,t)},c.init=function(t){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"100%",n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"100%",r=void 0,o=t;if("string"==typeof t&&(o=u.document.getElementById(t)),!o)throw new Error("HanziWriter target element not found: "+t);var s=o.nodeName.toUpperCase();"SVG"===s||"G"===s?r=o:(r=h("svg"),o.appendChild(r)),a(r,{width:i,height:n});var e=h("defs");return r.appendChild(e),new c(r,e)},i.exports=c}).call(t,r(1))},function(t,i,n){"use strict";var r=n(26),o=n(30);t.exports={HanziWriterRenderer:r,createRenderTarget:o.init}},function(t,i,n){"use strict";var r=n(27),s=n(29),e=n(0).assign;function o(t,i){this.V=t,this.q=i,this.Ct=new r(t),this.Mt=new r(t),this.St=new r(t)}o.prototype.mount=function(t){this.Wt=t},o.prototype.zt=function(t){var i=this.Wt.getContext();i.clearRect(0,0,this.q.width,this.q.height),i.save(),i.translate(this.q.xOffset,this.q.height-this.q.yOffset),i.transform(1,0,0,-1,0,0),i.scale(this.q.scale,this.q.scale),t(i),i.restore(),i.draw&&i.draw()},o.prototype.render=function(o){var t=this;this.zt(function(n){t.Mt.render(n,{opacity:o.character.outline.opacity,strokes:o.character.outline.strokes,strokeColor:o.options.outlineColor}),t.Ct.render(n,{opacity:o.character.main.opacity,strokes:o.character.main.strokes,strokeColor:o.options.strokeColor,radicalColor:o.options.radicalColor}),t.St.render(n,{opacity:o.character.highlight.opacity,strokes:o.character.highlight.strokes,strokeColor:o.options.highlightColor});var r=o.userStrokes||{};Object.keys(r).forEach(function(t){if(r[t]){var i=e({strokeWidth:o.options.drawingWidth,strokeColor:o.options.drawingColor},r[t]);s(n,i)}})})},o.prototype.destroy=function(){},t.exports=o},function(t,i,n){"use strict";var r=n(28);function o(t){this.Ot=t.strokes.map(function(t){return new r(t)})}o.prototype.render=function(t,i){if(!(i.opacity<.05))for(var n=0;n<this.Ot.length;n++)this.Ot[n].render(t,{strokeColor:i.strokeColor,radicalColor:i.radicalColor,opacity:i.strokes[n].opacity*i.opacity,displayPortion:i.strokes[n].displayPortion})},t.exports=o},function(e,t,u){"use strict";(function(n){var r=u(2).extendStart,t=u(8),a=t.drawPath,o=t.pathStringToCanvas,i=u(6);function s(t){var i=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];this.L=t,this.R=t.getLength()+100,i&&n.Path2D?this.Rt=new n.Path2D(this.L.path):this.Ht=o(this.L.path),this.Lt=r(this.L.points,100)}(s.prototype=Object.create(i.prototype)).render=function(t,i){if(!(i.opacity<.05)){t.save(),this.Rt?t.clip(this.Rt):(this.Ht(t),t.globalAlpha=0,t.stroke(),t.clip());var n=this.H(i),r=n.r,o=n.g,s=n.b,e=n.a,u=1===e?"rgb("+r+","+o+","+s+")":"rgb("+r+","+o+","+s+","+e+")",h=this.z(i.displayPortion);t.globalAlpha=i.opacity,t.strokeStyle=u,t.fillStyle=u,t.lineWidth=200,t.lineCap="round",t.lineJoin="round",t.setLineDash([this.R,this.R],h),t.lineDashOffset=h,a(t,this.Lt),t.restore()}},e.exports=s}).call(t,u(1))},function(t,i,n){"use strict";var u=n(8).drawPath;t.exports=function(t,i){if(!(i.opacity<.05)){var n=i.strokeColor,r=n.r,o=n.g,s=n.b,e=n.a;t.save(),t.globalAlpha=i.opacity,t.lineWidth=i.strokeWidth,t.strokeStyle="rgba("+r+","+o+","+s+","+e+")",t.lineCap="round",t.lineJoin="round",u(t,i.points),t.restore()}}},function(i,t,n){"use strict";(function(s){var t=n(7);function e(t){this.node=t}(e.prototype=Object.create(t.prototype)).getContext=function(){return this.node.getContext("2d")},e.init=function(t){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"100%",n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"100%",r=void 0,o=t;if("string"==typeof t&&(o=s.document.getElementById(t)),!o)throw new Error("HanziWriter target element not found: "+t);return"CANVAS"===o.nodeName.toUpperCase()?r=o:(r=s.document.createElement("canvas"),o.appendChild(r)),r.setAttribute("width",i),r.setAttribute("height",n),new e(r)},i.exports=e}).call(t,n(1))},function(t,i,n){"use strict";(function(o){t.exports=function(t,i,n){var r=new o.XMLHttpRequest;r.overrideMimeType&&r.overrideMimeType("application/json"),r.open("GET","https://cdn.jsdelivr.net/npm/hanzi-writer-data@2.0/"+t+".json",!0),r.onerror=function(t){n(r,t)},r.onreadystatechange=function(){4===r.readyState&&(200===r.status?i(JSON.parse(r.responseText)):0!==r.status&&n&&n(r))},r.send(null)}}).call(i,n(1))},function(t,i,n){"use strict";var r=n(0).callIfExists;function o(t){this.Ut=0,this.B=t,this._t=!1,this.loadingFailed=!1}o.prototype.Kt=function(t,i){var n=this,r=function(t){i===n.Ut&&n.I(t)},o=this.B.charDataLoader(t,r,function(t){i===n.Ut&&n.Nt(t)});o&&r(o)},o.prototype.Bt=function(){var n=this;return new Promise(function(t,i){n.I=t,n.Nt=i}).then(function(t){return n._t=!1,r(n.B.onLoadCharDataSuccess,t),t},function(t){if(n._t=!1,n.loadingFailed=!0,r(n.B.onLoadCharDataError,t),!n.B.onLoadCharDataError){if(t instanceof Error)throw t;var i=new Error("Failed to load char data for "+n.Gt);throw i.reason=t,i}})},o.prototype.loadCharData=function(t){this.Gt=t;var i=this.Bt();return this.loadingFailed=!1,this._t=!0,this.Ut++,this.Kt(t,this.Ut),i},t.exports=o}])}); | ||
/** | ||
* Hanzi Writer v3.0.0 | https://chanind.github.io/hanzi-writer | ||
*/ | ||
var HanziWriter=function(){"use strict";const t="undefined"==typeof window?global:window,e=t.performance&&(()=>t.performance.now())||(()=>Date.now()),r=t.requestAnimationFrame||(t=>setTimeout(()=>t(e()),1e3/60)),i=t.cancelAnimationFrame||clearTimeout;function s(t){return t[t.length-1]}function o(t,e){const r={...t};for(const i in e){const s=t[i],n=e[i];s!==n&&(s&&n&&"object"==typeof s&&"object"==typeof n&&!Array.isArray(n)?r[i]=o(s,n):r[i]=n)}return r}let n=0;function a(){return n++,n}function h(t){return t.reduce((t,e)=>e+t,0)/t.length}function c(t){const e=t.toUpperCase().trim();if(/^#([A-F0-9]{3}){1,2}$/.test(e)){let t=e.substring(1).split("");3===t.length&&(t=[t[0],t[0],t[1],t[1],t[2],t[2]]);const r=""+t.join("");return{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16),a:1}}const r=e.match(/^RGBA?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*(\d*\.?\d+))?\)$/);if(r)return{r:parseInt(r[1],10),g:parseInt(r[2],10),b:parseInt(r[3],10),a:parseFloat(r[4]||1,10)};throw new Error("Invalid color: "+t)}function l(t,e){const r={};for(let i=0;i<e;i++)r[i]=t;return r}const u=t.navigator?.userAgent||"",d=u.indexOf("MSIE ")>0||u.indexOf("Trident/")>0||u.indexOf("Edge/")>0,_=()=>{};class p{constructor(t,e,r=_){this._mutationChains=[],this._onStateChange=r,this.state={options:{drawingFadeDuration:e.drawingFadeDuration,drawingWidth:e.drawingWidth,drawingColor:c(e.drawingColor),strokeColor:c(e.strokeColor),outlineColor:c(e.outlineColor),radicalColor:c(e.radicalColor||e.strokeColor),highlightColor:c(e.highlightColor)},character:{main:{opacity:e.showCharacter?1:0,strokes:{}},outline:{opacity:e.showOutline?1:0,strokes:{}},highlight:{opacity:1,strokes:{}}},userStrokes:null};for(let e=0;e<t.strokes.length;e++)this.state.character.main.strokes[e]={opacity:1,displayPortion:1},this.state.character.outline.strokes[e]={opacity:1,displayPortion:1},this.state.character.highlight.strokes[e]={opacity:0,displayPortion:1}}updateState(t){const e=o(this.state,t);this._onStateChange(e,this.state),this.state=e}run(t,e={}){const r=t.map(t=>t.scope);return this.cancelMutations(r),new Promise(i=>{const s={_isActive:!0,_index:0,_resolve:i,_mutations:t,_loop:e.loop,_scopes:r};this._mutationChains.push(s),this._run(s)})}_run(t){if(!t._isActive)return;const e=t._mutations;if(t._index>=e.length){if(!t._loop)return t._isActive=!1,this._mutationChains=this._mutationChains.filter(e=>e!==t),void t._resolve({canceled:!1});t._index=0}t._mutations[t._index].run(this).then(()=>{t._isActive&&(t._index++,this._run(t))})}_getActiveMutations(){return this._mutationChains.map(t=>t._mutations[t._index])}pauseAll(){this._getActiveMutations().forEach(t=>t.pause())}resumeAll(){this._getActiveMutations().forEach(t=>t.resume())}cancelMutations(t){for(const e of this._mutationChains)for(const r of e._scopes)for(const i of t)(r.startsWith(i)||i.startsWith(r))&&this._cancelMutationChain(e)}cancelAll(){this.cancelMutations([""])}_cancelMutationChain(t){t._isActive=!1;for(let e=t._index;e<t._mutations.length;e++)t._mutations[e].cancel(this);t._resolve?.({canceled:!0}),this._mutationChains=this._mutationChains.filter(e=>e!==t)}}const g=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),k=t=>Math.sqrt(Math.pow(t.x,2)+Math.pow(t.y,2)),f=(t,e)=>k(g(t,e)),m=(t,e=1)=>{const r=10*e;return{x:Math.round(r*t.x)/r,y:Math.round(r*t.y)/r}},y=t=>{let e=t[0];return t.slice(1).reduce((t,r)=>{const i=f(r,e);return e=r,t+i},0)},C=(t,e,r)=>{const i=g(e,t),s=r/k(i);return{x:e.x+s*i.x,y:e.y+s*i.y}},w=t=>{const e=((t,e=30)=>{const r=y(t)/(e-1),i=[t[0]],o=s(t),n=t.slice(1);for(let t=0;t<e-2;t++){let t=s(i),e=r,o=!1;for(;!o;){const r=f(t,n[0]);if(r<e)e-=r,t=n.shift();else{const s=C(t,n[0],e-r);i.push(s),o=!0}}}return i.push(o),i})(t),r={x:h(e.map(t=>t.x)),y:h(e.map(t=>t.y))},i=e.map(t=>g(t,r)),o=Math.sqrt(h([Math.pow(i[0].x,2)+Math.pow(i[0].y,2),Math.pow(s(i).x,2)+Math.pow(s(i).y,2)]));return((t,e=.05)=>{const r=t.slice(0,1);for(const i of t.slice(1)){const t=r[r.length-1],s=f(i,t);if(s>e){const o=Math.ceil(s/e),n=s/o;for(let e=0;e<o;e++)r.push(C(i,t,-1*n*(e+1)))}else r.push(i)}return r})(i.map(t=>({x:t.x/o,y:t.y/o})))};function S(t,e=!1){const r=m(t[0]),i=t.slice(1);let s=`M ${r.x} ${r.y}`;return i.forEach(t=>{const e=m(t);s+=` L ${e.x} ${e.y}`}),e&&(s+="Z"),s}const P=(t,e)=>{const r=(t=>{if(t.length<3)return t;const e=[t[0],t[1]];return t.slice(2).forEach(t=>{const r=e.length,i=g(t,e[r-1]),s=g(e[r-1],e[r-2]);i.y*s.x-i.x*s.y==0&&e.pop(),e.push(t)}),e})(t);if(r.length<2)return r;const i=r[1],s=r[0],o=C(i,s,e),n=r.slice(1);return n.unshift(o),n};class v{constructor(t,e,r,i=!1){this.path=t,this.points=e,this.strokeNum=r,this.isInRadical=i}getStartingPoint(){return this.points[0]}getEndingPoint(){return this.points[this.points.length-1]}getLength(){return y(this.points)}getVectors(){let t=this.points[0];return this.points.slice(1).map(e=>{const r=g(e,t);return t=e,r})}getDistance(t){const e=this.points.map(e=>f(e,t));return Math.min(...e)}getAverageDistance(t){return t.reduce((t,e)=>t+this.getDistance(e),0)/t.length}}class x{constructor(t,e){this.symbol=t,this.strokes=e}}function D({radStrokes:t,strokes:e,medians:r}){return e.map((e,i)=>{const s=r[i].map(t=>{const[e,r]=t;return{x:e,y:r}});return new v(e,s,i,(o=i,(t?.indexOf(o)??-1)>=0));var o})}const[M,R]=[{x:0,y:-124},{x:1024,y:900}],T=R.x-M.x,A=R.y-M.y;class O{constructor(t){const{padding:e,width:r,height:i}=t;this.padding=e,this.width=r,this.height=i;const s=r-2*e,o=i-2*e,n=s/T,a=o/A;this.scale=Math.min(n,a);const h=e+(s-this.scale*T)/2,c=e+(o-this.scale*A)/2;this.xOffset=-1*M.x*this.scale+h,this.yOffset=-1*M.y*this.scale+c}convertExternalPoint(t){return{x:(t.x-this.xOffset)/this.scale,y:(this.height-this.yOffset-t.y)/this.scale}}}const $=(t,e)=>{const r=(t=>{const e=[];let r=t[0];return t.slice(1).forEach(t=>{e.push(g(t,r)),r=t}),e})(t),i=e.getVectors();return h(r.map(t=>{const e=i.map(e=>{return i=t,((r=e).x*i.x+r.y*i.y)/k(r)/k(i);var r,i});return Math.max(...e)}))>0},L=t=>{if(t.length<2)return t;const[e,...r]=t,i=[e];for(const t of r)s=t,o=i[i.length-1],(s.x!==o.x||s.y!==o.y)&&i.push(t);var s,o;return i},b=[Math.PI/16,Math.PI/32,0,-1*Math.PI/32,-1*Math.PI/16],E=(t,e,r)=>{const i=w(t),s=w(e);let o=1/0;return b.forEach(t=>{const e=((t,e)=>{const r=t.length>=e.length?t:e,i=t.length>=e.length?e:t,s=(t,e,s,o)=>{if(0===t&&0===e)return f(r[0],i[0]);if(t>0&&0===e)return Math.max(s[0],f(r[t],i[0]));const n=o[o.length-1];return 0===t&&e>0?Math.max(n,f(r[0],i[e])):Math.max(Math.min(s[e],s[e-1],n),f(r[t],i[e]))};let o=[];for(let t=0;t<r.length;t++){const e=[];for(let r=0;r<i.length;r++)e.push(s(t,r,o,e));o=e}return o[i.length-1]})(i,((t,e)=>t.map(t=>({x:Math.cos(e)*t.x-Math.sin(e)*t.y,y:Math.sin(e)*t.x+Math.cos(e)*t.y})))(s,t));e<o&&(o=e)}),o<=.4*r},F=(t,e,r)=>{const{leniency:i=1,isOutlineVisible:s=!1}=r,o=e.getAverageDistance(t),n=o<=350*(s||e.strokeNum>0?.5:1)*i;if(!n)return{isMatch:!1,avgDist:o};const a=((t,e,r)=>{const i=f(e.getStartingPoint(),t[0]),s=f(e.getEndingPoint(),t[t.length-1]);return i<=250*r&&s<=250*r})(t,e,i),h=$(t,e),c=E(t,e.points,i),l=((t,e,r)=>r*(y(t)+25)/(e.getLength()+25)>=.35)(t,e,i);return{isMatch:n&&a&&h&&c&&l,avgDist:o}};class W{constructor(t,e,r){this.id=t,this.points=[e],this.externalPoints=[r]}appendPoint(t,e){this.points.push(t),this.externalPoints.push(e)}}class z{constructor(t,e,i={}){this._tick=t=>{if(null!==this._startPauseTime)return;const e=Math.min(1,(t-this._startTime-this._pausedDuration)/this._duration);if(1===e)this._renderState.updateState(this._values),this._frameHandle=void 0,this.cancel(this._renderState);else{const t=q(e),i=H(this._startState,this._values,t);this._renderState.updateState(i),this._frameHandle=r(this._tick)}},this.scope=t,this._valuesOrCallable=e,this._duration=i.duration||0,this._force=i.force,this._pausedDuration=0,this._startPauseTime=null}run(t){return this._values||this._inflateValues(t),0===this._duration&&t.updateState(this._values),0===this._duration||I(t.state,this._values)?Promise.resolve():(this._renderState=t,this._startState=t.state,this._startTime=performance.now(),this._frameHandle=r(this._tick),new Promise(t=>{this._resolve=t}))}_inflateValues(t){let e=this._valuesOrCallable;"function"==typeof this._valuesOrCallable&&(e=this._valuesOrCallable(t.state)),this._values=function(t,e){const r=t.split("."),i={};let s=i;for(let t=0;t<r.length;t++){const i=t===r.length-1?e:{};s[r[t]]=i,s=i}return i}(this.scope,e)}pause(){null===this._startPauseTime&&(this._frameHandle&&i(this._frameHandle),this._startPauseTime=performance.now())}resume(){null!==this._startPauseTime&&(this._frameHandle=r(this._tick),this._pausedDuration+=performance.now()-this._startPauseTime,this._startPauseTime=null)}cancel(t){this._resolve?.(),this._resolve=void 0,i(this._frameHandle||-1),this._frameHandle=void 0,this._force&&(this._values||this._inflateValues(t),t.updateState(this._values))}}function H(t,e,r){const i={};for(const s in e){const o=e[s],n=t?.[s];i[s]="number"==typeof n&&"number"==typeof o&&o>=0?r*(o-n)+n:H(n,o,r)}return i}function I(t,e){for(const r in e){const i=e[r],s=t?.[r];if(i>=0){if(i!==s)return!1}else if(!I(s,i))return!1}return!0}z.Delay=class{constructor(t){this._duration=t,this._startTime=null,this._paused=!1,this.scope="delay."+t}run(){return this._startTime=e(),this._runningPromise=new Promise(t=>{this._resolve=t,this._timeout=setTimeout(()=>this.cancel(),this._duration)}),this._runningPromise}pause(){if(this._paused)return;const t=performance.now()-(this._startTime||0);this._duration=Math.max(0,this._duration-t),clearTimeout(this._timeout),this._paused=!0}resume(){this._paused&&(this._startTime=performance.now(),this._timeout=setTimeout(()=>this.cancel(),this._duration),this._paused=!1)}cancel(){clearTimeout(this._timeout),this._resolve&&this._resolve(),this._resolve=void 0}};const q=t=>-Math.cos(t*Math.PI)/2+.5,B=(t,e,r)=>[new z(`character.${t}.strokes`,l({opacity:1,displayPortion:1},e.strokes.length),{duration:r,force:!0})],N=(t,e,r)=>[new z("character."+t,{opacity:1,strokes:l({opacity:1,displayPortion:1},e.strokes.length)},{duration:r,force:!0})],j=(t,e,r)=>[new z(`character.${t}.opacity`,0,{duration:r,force:!0}),...B(t,e,0)],U=(t,e,r)=>[new z("options."+t,e,{duration:r})],V=(t,e,r)=>{const i=t.strokeNum,s=(t.getLength()+600)/(3*r);return[new z("character.highlight.strokeColor",e),new z("character.highlight",{opacity:1,strokes:{[i]:{displayPortion:0,opacity:0}}}),new z("character.highlight.strokes."+i,{displayPortion:1,opacity:1},{duration:s}),new z(`character.highlight.strokes.${i}.opacity`,0,{duration:s})]},Q=(t,e,r)=>{const i=e.strokeNum,s=(e.getLength()+600)/(3*r);return[new z("character."+t,{opacity:1,strokes:{[i]:{displayPortion:0,opacity:1}}}),new z(`character.${t}.strokes.${i}.displayPortion`,1,{duration:s})]},G=(t,e,r,i)=>{const s=e.strokes[r];return[new z("character."+t,r=>{const i=r.character[t],s={opacity:1,strokes:{}};for(let t=0;t<e.strokes.length;t++)s.strokes[t]={opacity:i.opacity*i.strokes[t].opacity};return s}),...Q(t,s,i)]},X=(t,e,r,i,s)=>{let o=j(t,e,r);return o=o.concat(B(t,e,0)),o.push(new z("character."+t,{opacity:1,strokes:l({opacity:0},e.strokes.length)},{force:!0})),e.strokes.forEach((e,r)=>{r>0&&o.push(new z.Delay(s)),o=o.concat(Q(t,e,i))}),o},K=(t,e)=>[new z(`userStrokes.${t}.opacity`,0,{duration:e}),new z("userStrokes."+t,null,{force:!0})];class Y{constructor(t,e,r){this._currentStrokeIndex=0,this._mistakesOnStroke=0,this._totalMistakes=0,this._character=t,this._renderState=e,this._isActive=!1,this._positioner=r}startQuiz(t){return this._isActive=!0,this._options=t,this._currentStrokeIndex=0,this._mistakesOnStroke=0,this._totalMistakes=0,this._renderState.run((e=this._character,r=t.strokeFadeDuration,[...j("main",e,r),new z("character.highlight",{opacity:1,strokes:l({opacity:0},e.strokes.length)},{force:!0}),new z("character.main",{opacity:1,strokes:l({opacity:0},e.strokes.length)},{force:!0})]));var e,r}startUserStroke(t){if(!this._isActive)return null;if(this._userStroke)return this.endUserStroke();const e=this._positioner.convertExternalPoint(t),r=a();return this._userStroke=new W(r,e,t),this._renderState.run(((t,e)=>[new z("quiz.activeUserStrokeId",t,{force:!0}),new z("userStrokes."+t,{points:[e],opacity:1},{force:!0})])(r,e))}continueUserStroke(t){if(!this._userStroke)return Promise.resolve();const e=this._positioner.convertExternalPoint(t);this._userStroke.appendPoint(e,t);const r=this._userStroke.points.slice(0);return this._renderState.run((i=this._userStroke.id,[new z(`userStrokes.${i}.points`,r,{force:!0})]));var i}endUserStroke(){if(!this._userStroke)return;if(this._renderState.run(K(this._userStroke.id,this._options.drawingFadeDuration??300)),1===this._userStroke.points.length)return void(this._userStroke=void 0);const t=this._getCurrentStroke();if(function(t,e,r,i={}){const s=e.strokes,o=L(t.points);if(o.length<2)return null;const{isMatch:n,avgDist:a}=F(o,s[r],i);if(!n)return!1;const h=s.slice(r+1);let c=a;for(let t=0;t<h.length;t++){const{isMatch:e,avgDist:r}=F(o,h[t],i);e&&r<c&&(c=r)}if(c<a){const t=.6*(c+a)/(2*a),{isMatch:e}=F(o,s[r],{...i,leniency:(i.leniency||1)*t});return e}return!0}(this._userStroke,this._character,this._currentStrokeIndex,{isOutlineVisible:this._renderState.state.character.outline.opacity>0,leniency:this._options.leniency}))this._handleSuccess();else{this._handleFailure();const{showHintAfterMisses:e,highlightColor:r,strokeHighlightSpeed:i}=this._options;!1!==e&&this._mistakesOnStroke>=e&&this._renderState.run(V(t,c(r),i))}this._userStroke=void 0}cancel(){this._isActive=!1,this._userStroke&&this._renderState.run(K(this._userStroke.id,this._options.drawingFadeDuration))}_getStrokeData(t=!1){return{character:this._character.symbol,strokeNum:this._currentStrokeIndex,mistakesOnStroke:this._mistakesOnStroke,totalMistakes:this._totalMistakes,strokesRemaining:this._character.strokes.length-this._currentStrokeIndex-(t?1:0),drawnPath:(e=this._userStroke,{pathString:S(e.externalPoints),points:e.points.map(t=>m(t))})};var e}_handleSuccess(){if(!this._options)return;const{strokes:t,symbol:e}=this._character,{onCorrectStroke:r,onComplete:i,highlightOnComplete:s,strokeFadeDuration:o,strokeHighlightDuration:n}=this._options;r?.(this._getStrokeData(!0));let a=(h="main",c=this._currentStrokeIndex,[new z(`character.${h}.strokes.${c}`,{displayPortion:1,opacity:1},{duration:o,force:!0})]);var h,c;this._mistakesOnStroke=0,this._currentStrokeIndex+=1;this._currentStrokeIndex===t.length&&(this._isActive=!1,i?.({character:e,totalMistakes:this._totalMistakes}),s&&(a=a.concat(((t,e)=>[...j("highlight",t),...N("highlight",t,e/2),...j("highlight",t,e/2)])(this._character,2*(n||0))))),this._renderState.run(a)}_handleFailure(){this._mistakesOnStroke+=1,this._totalMistakes+=1,this._options.onMistake?.(this._getStrokeData())}_getCurrentStroke(){return this._character.strokes[this._currentStrokeIndex]}}function J(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Z(t,e,r){t.setAttributeNS(null,e,r)}function tt(t,e){Object.keys(e).forEach(r=>Z(t,r,e[r]))}function et(t){t?.parentNode?.removeChild(t)}class rt{constructor(t){this.stroke=t,this._pathLength=t.getLength()+rt.STROKE_WIDTH/2}_getStrokeDashoffset(t){return.999*this._pathLength*(1-t)}_getColor({strokeColor:t,radicalColor:e}){return e&&this.stroke.isInRadical?e:t}}rt.STROKE_WIDTH=200;class it extends rt{constructor(t){super(t),this._oldProps=void 0}mount(t){this._animationPath=J("path"),this._clip=J("clipPath"),this._strokePath=J("path");const e="mask-"+a();Z(this._clip,"id",e),Z(this._strokePath,"d",this.stroke.path),this._animationPath.style.opacity="0",Z(this._animationPath,"clip-path",function(t){let e="";return window.location&&window.location.href&&(e=window.location.href.replace(/#[^#]*$/,"")),`url(${e}#${t})`}(e));const r=P(this.stroke.points,100);return Z(this._animationPath,"d",S(r)),tt(this._animationPath,{stroke:"#FFFFFF","stroke-width":200..toString(),fill:"none","stroke-linecap":"round","stroke-linejoin":"miter","stroke-dasharray":`${this._pathLength},${this._pathLength}`}),this._clip.appendChild(this._strokePath),t.defs.appendChild(this._clip),t.svg.appendChild(this._animationPath),this}render(t){if(t===this._oldProps||!this._animationPath)return;t.displayPortion!==this._oldProps?.displayPortion&&(this._animationPath.style.strokeDashoffset=this._getStrokeDashoffset(t.displayPortion).toString());const e=this._getColor(t);if(!this._oldProps||e!==this._getColor(this._oldProps)){const{r:t,g:r,b:i,a:s}=e;tt(this._animationPath,{stroke:`rgba(${t},${r},${i},${s})`})}t.opacity!==this._oldProps?.opacity&&(this._animationPath.style.opacity=t.opacity.toString()),this._oldProps=t}}class st{constructor(t){this._oldProps=void 0,this._strokeRenderers=t.strokes.map(t=>new it(t))}mount(t){const e=t.createSubRenderTarget();this._group=e.svg,this._strokeRenderers.forEach(t=>{t.mount(e)})}render(t){if(t===this._oldProps||!this._group)return;const{opacity:e,strokes:r,strokeColor:i,radicalColor:s=null}=t;e!==this._oldProps?.opacity&&(this._group.style.opacity=e.toString(),d||(0===e?this._group.style.display="none":0===this._oldProps?.opacity&&this._group.style.removeProperty("display")));const o=!this._oldProps||i!==this._oldProps.strokeColor||s!==this._oldProps.radicalColor;if(o||r!==this._oldProps?.strokes)for(let t=0;t<this._strokeRenderers.length;t++)!o&&this._oldProps?.strokes&&r[t]===this._oldProps.strokes[t]||this._strokeRenderers[t].render({strokeColor:i,radicalColor:s,opacity:r[t].opacity,displayPortion:r[t].displayPortion});this._oldProps=t}}class ot{constructor(){this._oldProps=void 0}mount(t){this._path=J("path"),t.svg.appendChild(this._path)}render(t){if(this._path&&t!==this._oldProps){if(t.strokeColor!==this._oldProps?.strokeColor||t.strokeWidth!==this._oldProps?.strokeWidth){const{r:e,g:r,b:i,a:s}=t.strokeColor;tt(this._path,{fill:"none",stroke:`rgba(${e},${r},${i},${s})`,"stroke-width":t.strokeWidth.toString(),"stroke-linecap":"round","stroke-linejoin":"round"})}t.opacity!==this._oldProps?.opacity&&Z(this._path,"opacity",t.opacity.toString()),t.points!==this._oldProps?.points&&Z(this._path,"d",S(t.points)),this._oldProps=t}}destroy(){et(this._path)}}class nt{constructor(t){this.node=t}addPointerStartListener(t){this.node.addEventListener("mousedown",e=>{t(this._eventify(e,this._getMousePoint))}),this.node.addEventListener("touchstart",e=>{t(this._eventify(e,this._getTouchPoint))})}addPointerMoveListener(t){this.node.addEventListener("mousemove",e=>{t(this._eventify(e,this._getMousePoint))}),this.node.addEventListener("touchmove",e=>{t(this._eventify(e,this._getTouchPoint))})}addPointerEndListener(t){document.addEventListener("mouseup",t),document.addEventListener("touchend",t)}getBoundingClientRect(){return this.node.getBoundingClientRect()}_eventify(t,e){return{getPoint:()=>e.call(this,t),preventDefault:()=>t.preventDefault()}}_getMousePoint(t){const{left:e,top:r}=this.getBoundingClientRect();return{x:t.clientX-e,y:t.clientY-r}}_getTouchPoint(t){const{left:e,top:r}=this.getBoundingClientRect();return{x:t.touches[0].clientX-e,y:t.touches[0].clientY-r}}}class at extends nt{constructor(t,e){super(t),this.svg=t,this.defs=e,"createSVGPoint"in t&&(this._pt=t.createSVGPoint())}static init(t,e="100%",r="100%"){const i="string"==typeof t?document.getElementById(t):t;if(!i)throw new Error("HanziWriter target element not found: "+t);const s=i.nodeName.toUpperCase(),o=(()=>{if("SVG"===s||"G"===s)return i;{const t=J("svg");return i.appendChild(t),t}})();tt(o,{width:e,height:r});const n=J("defs");return o.appendChild(n),new at(o,n)}createSubRenderTarget(){const t=J("g");return this.svg.appendChild(t),new at(t,this.defs)}_getMousePoint(t){if(this._pt&&(this._pt.x=t.clientX,this._pt.y=t.clientY,"getScreenCTM"in this.node)){const t=this._pt.matrixTransform(this.node.getScreenCTM()?.inverse());return{x:t.x,y:t.y}}return super._getMousePoint.call(this,t)}_getTouchPoint(t){if(this._pt&&(this._pt.x=t.touches[0].clientX,this._pt.y=t.touches[0].clientY,"getScreenCTM"in this.node)){const t=this._pt.matrixTransform(this.node.getScreenCTM()?.inverse());return{x:t.x,y:t.y}}return super._getTouchPoint(t)}}var ht={HanziWriterRenderer:class{constructor(t,e){this._character=t,this._positioner=e,this._mainCharRenderer=new st(t),this._outlineCharRenderer=new st(t),this._highlightCharRenderer=new st(t),this._userStrokeRenderers={}}mount(t){const e=t.createSubRenderTarget(),r=e.svg,{xOffset:i,yOffset:s,height:o,scale:n}=this._positioner;Z(r,"transform",`translate(${i}, ${o-s}) scale(${n}, ${-1*n})`),this._outlineCharRenderer.mount(e),this._mainCharRenderer.mount(e),this._highlightCharRenderer.mount(e),this._positionedTarget=e}render(t){const{main:e,outline:r,highlight:i}=t.character,{outlineColor:s,radicalColor:o,highlightColor:n,strokeColor:a,drawingWidth:h,drawingColor:c}=t.options;this._outlineCharRenderer.render({opacity:r.opacity,strokes:r.strokes,strokeColor:s}),this._mainCharRenderer.render({opacity:e.opacity,strokes:e.strokes,strokeColor:a,radicalColor:o}),this._highlightCharRenderer.render({opacity:i.opacity,strokes:i.strokes,strokeColor:n});const l=t.userStrokes||{};for(const t in this._userStrokeRenderers)l[t]||(this._userStrokeRenderers[t]?.destroy(),delete this._userStrokeRenderers[t]);for(const t in l){const e=l[t];if(!e)continue;const r={strokeWidth:h,strokeColor:c,...e};(()=>{if(this._userStrokeRenderers[t])return this._userStrokeRenderers[t];const e=new ot;return e.mount(this._positionedTarget),this._userStrokeRenderers[t]=e,e})().render(r)}}destroy(){et(this._positionedTarget.svg),this._positionedTarget.defs.innerHTML=""}},createRenderTarget:at.init};const ct=(t,e)=>{t.beginPath();const r=e[0],i=e.slice(1);t.moveTo(r.x,r.y);for(const e of i)t.lineTo(e.x,e.y);t.stroke()};class lt extends rt{constructor(t,e=!0){super(t),e&&Path2D?this._path2D=new Path2D(this.stroke.path):this._pathCmd=(t=>{const e=t.split(/(^|\s+)(?=[A-Z])/).filter(t=>" "!==t),r=[t=>t.beginPath()];for(const t of e){const[e,...i]=t.split(/\s+/),s=i.map(t=>parseFloat(t));"M"===e?r.push(t=>t.moveTo(...s)):"L"===e?r.push(t=>t.lineTo(...s)):"C"===e?r.push(t=>t.bezierCurveTo(...s)):"Q"===e&&r.push(t=>t.quadraticCurveTo(...s))}return t=>r.forEach(e=>e(t))})(this.stroke.path),this._extendedMaskPoints=P(this.stroke.points,rt.STROKE_WIDTH/2)}render(t,e){if(e.opacity<.05)return;t.save(),this._path2D?t.clip(this._path2D):(this._pathCmd?.(t),t.globalAlpha=0,t.stroke(),t.clip());const{r:r,g:i,b:s,a:o}=this._getColor(e),n=1===o?`rgb(${r},${i},${s})`:`rgb(${r},${i},${s},${o})`,a=this._getStrokeDashoffset(e.displayPortion);t.globalAlpha=e.opacity,t.strokeStyle=n,t.fillStyle=n,t.lineWidth=rt.STROKE_WIDTH,t.lineCap="round",t.lineJoin="round",t.setLineDash([this._pathLength,this._pathLength],a),t.lineDashOffset=a,ct(t,this._extendedMaskPoints),t.restore()}}class ut{constructor(t){this._strokeRenderers=t.strokes.map(t=>new lt(t))}render(t,e){if(e.opacity<.05)return;const{opacity:r,strokeColor:i,radicalColor:s,strokes:o}=e;for(let e=0;e<this._strokeRenderers.length;e++)this._strokeRenderers[e].render(t,{strokeColor:i,radicalColor:s,opacity:o[e].opacity*r,displayPortion:o[e].displayPortion||0})}}function dt(t,e){if(e.opacity<.05)return;const{opacity:r,strokeWidth:i,strokeColor:s,points:o}=e,{r:n,g:a,b:h,a:c}=s;t.save(),t.globalAlpha=r,t.lineWidth=i,t.strokeStyle=`rgba(${n},${a},${h},${c})`,t.lineCap="round",t.lineJoin="round",ct(t,o),t.restore()}class _t extends nt{constructor(t){super(t)}static init(t,e="100%",r="100%"){const i="string"==typeof t?document.getElementById(t):t;if(!i)throw new Error("HanziWriter target element not found: "+t);const s=i.nodeName.toUpperCase(),o=(()=>{if("CANVAS"===s)return i;const t=document.createElement("canvas");return i.appendChild(t),t})();return o.setAttribute("width",e),o.setAttribute("height",r),new _t(o)}getContext(){return this.node.getContext("2d")}}var pt={HanziWriterRenderer:class{constructor(t,e){this.destroy=_,this._character=t,this._positioner=e,this._mainCharRenderer=new ut(t),this._outlineCharRenderer=new ut(t),this._highlightCharRenderer=new ut(t)}mount(t){this._target=t}_animationFrame(t){const{width:e,height:r,scale:i,xOffset:s,yOffset:o}=this._positioner,n=this._target.getContext();n.clearRect(0,0,e,r),n.save(),n.translate(s,r-o),n.transform(1,0,0,-1,0,0),n.scale(i,i),t(n),n.restore(),n.draw&&n.draw()}render(t){const{outline:e,main:r,highlight:i}=t.character,{outlineColor:s,strokeColor:o,radicalColor:n,highlightColor:a,drawingColor:h,drawingWidth:c}=t.options;this._animationFrame(l=>{this._outlineCharRenderer.render(l,{opacity:e.opacity,strokes:e.strokes,strokeColor:s}),this._mainCharRenderer.render(l,{opacity:r.opacity,strokes:r.strokes,strokeColor:o,radicalColor:n}),this._highlightCharRenderer.render(l,{opacity:i.opacity,strokes:i.strokes,strokeColor:a});const u=t.userStrokes||{};for(const t in u){const e=u[t];if(e){dt(l,{strokeWidth:c,strokeColor:h,...e})}}})}},createRenderTarget:_t.init};const gt={charDataLoader:(t,e,r)=>{const i=new XMLHttpRequest;i.overrideMimeType&&i.overrideMimeType("application/json"),i.open("GET",(t=>`https://cdn.jsdelivr.net/npm/hanzi-writer-data@2.0/${t}.json`)(t),!0),i.onerror=t=>{r(i,t)},i.onreadystatechange=()=>{4===i.readyState&&(200===i.status?e(JSON.parse(i.responseText)):0!==i.status&&r&&r(i))},i.send(null)},onLoadCharDataError:null,onLoadCharDataSuccess:null,showOutline:!0,showCharacter:!0,renderer:"svg",width:0,height:0,padding:20,strokeAnimationSpeed:1,strokeFadeDuration:400,strokeHighlightDuration:200,strokeHighlightSpeed:2,delayBetweenStrokes:1e3,delayBetweenLoops:2e3,strokeColor:"#555",radicalColor:null,highlightColor:"#AAF",outlineColor:"#DDD",drawingColor:"#333",leniency:1,showHintAfterMisses:3,highlightOnComplete:!0,highlightCompleteColor:null,drawingFadeDuration:300,drawingWidth:4,strokeWidth:2,outlineWidth:2,rendererOverride:{}};class kt{constructor(t){this._loadCounter=0,this._isLoading=!1,this.loadingFailed=!1,this._options=t}_debouncedLoad(t,e){const r=t=>{e===this._loadCounter&&this._resolve?.(t)},i=t=>{e===this._loadCounter&&this._reject?.(t)},s=this._options.charDataLoader(t,r,i);s&&("then"in s?s.then(r).catch(i):r(s))}_setupLoadingPromise(){return new Promise((t,e)=>{this._resolve=t,this._reject=e}).then(t=>(this._isLoading=!1,this._options.onLoadCharDataSuccess?.(t),t)).catch(t=>{if(this._isLoading=!1,this.loadingFailed=!0,this._options.onLoadCharDataError)return void this._options.onLoadCharDataError(t);if(t instanceof Error)throw t;const e=new Error("Failed to load char data for "+this._loadingChar);throw e.reason=t,e})}loadCharData(t){this._loadingChar=t;const e=this._setupLoadingPromise();return this.loadingFailed=!1,this._isLoading=!0,this._loadCounter++,this._debouncedLoad(t,this._loadCounter),e}}class ft{constructor(t,e={}){const{HanziWriterRenderer:r,createRenderTarget:i}="canvas"===e.renderer?pt:ht,s=e.rendererOverride||{};this._renderer={HanziWriterRenderer:s.HanziWriterRenderer||r,createRenderTarget:s.createRenderTarget||i},this.target=this._renderer.createRenderTarget(t,e.width,e.height),this._options=this._assignOptions(e),this._loadingManager=new kt(this._options),this._setupListeners()}static create(t,e,r){const i=new ft(t,r);return i.setCharacter(e),i}static loadCharacterData(t,e={}){const r=(()=>{const{_loadingManager:r,_loadingOptions:i}=ft;return r?._loadingChar===t&&i===e?r:new kt({...gt,...e})})();return ft._loadingManager=r,ft._loadingOptions=e,r.loadCharData(t)}static getScalingTransform(t,e,r=0){const i=new O({width:t,height:e,padding:r});return{x:i.xOffset,y:i.yOffset,scale:i.scale,transform:(s=`\n translate(${i.xOffset}, ${i.height-i.yOffset})\n scale(${i.scale}, ${-1*i.scale})\n `,s.replace(/^\s+/,"").replace(/\s+$/,"")).replace(/\s+/g," ")};var s}showCharacter(t={}){return this._options.showCharacter=!0,this._withData(()=>this._renderState?.run(N("main",this._character,typeof t.duration==="number"?t.duration:this._options.strokeFadeDuration)).then(e=>{t.onComplete?.(e);return e}))}hideCharacter(t={}){return this._options.showCharacter=!1,this._withData(()=>this._renderState?.run(j("main",this._character,typeof t.duration==="number"?t.duration:this._options.strokeFadeDuration)).then(e=>{t.onComplete?.(e);return e}))}animateCharacter(t={}){return this.cancelQuiz(),this._withData(()=>this._renderState?.run(X("main",this._character,this._options.strokeFadeDuration,this._options.strokeAnimationSpeed,this._options.delayBetweenStrokes)).then(e=>{t.onComplete?.(e);return e}))}animateStroke(t,e={}){return this.cancelQuiz(),this._withData(()=>this._renderState?.run(G("main",this._character,t,this._options.strokeAnimationSpeed)).then(t=>{e.onComplete?.(t);return t}))}highlightStroke(t,e={}){return this._withData(()=>{if(this._character&&this._renderState)return this._renderState.run(V(this._character.strokes[t],c(this._options.highlightColor),this._options.strokeHighlightSpeed)).then(t=>(e.onComplete?.(t),t))})}async loopCharacterAnimation(){return this.cancelQuiz(),this._withData(()=>this._renderState.run(((t,e,r,i,s,o)=>{const n=X(t,e,r,i,s);return n.push(new z.Delay(o)),n})("main",this._character,this._options.strokeFadeDuration,this._options.strokeAnimationSpeed,this._options.delayBetweenStrokes,this._options.delayBetweenLoops),{loop:!0}))}pauseAnimation(){return this._withData(()=>this._renderState?.pauseAll())}resumeAnimation(){return this._withData(()=>this._renderState?.resumeAll())}showOutline(t={}){return this._options.showOutline=!0,this._withData(()=>this._renderState?.run(N("outline",this._character,typeof t.duration==="number"?t.duration:this._options.strokeFadeDuration)).then(e=>{t.onComplete?.(e);return e}))}hideOutline(t={}){return this._options.showOutline=!1,this._withData(()=>this._renderState?.run(j("outline",this._character,typeof t.duration==="number"?t.duration:this._options.strokeFadeDuration)).then(e=>{t.onComplete?.(e);return e}))}updateColor(t,e,r={}){let i=[];const s=c((()=>"radicalColor"!==t||e?e:this._options.strokeColor)());this._options[t]=e;const o=r.duration??this._options.strokeFadeDuration;return i=i.concat(U(t,s,o)),"radicalColor"!==t||e||(i=i.concat(U(t,null,0))),this._withData(()=>this._renderState?.run(i).then(t=>{r.onComplete?.(t);return t}))}quiz(t={}){return this._withData(async()=>{this._character&&this._renderState&&this._positioner&&(this.cancelQuiz(),this._quiz=new Y(this._character,this._renderState,this._positioner),this._options={...this._options,...t},this._quiz.startQuiz(this._options))})}cancelQuiz(){this._quiz&&(this._quiz.cancel(),this._quiz=void 0)}setCharacter(t){return this.cancelQuiz(),this._char=t,this._hanziWriterRenderer&&this._hanziWriterRenderer.destroy(),this._renderState&&this._renderState.cancelAll(),this._hanziWriterRenderer=null,this._withDataPromise=this._loadingManager.loadCharData(t).then(e=>{if(!e||this._loadingManager.loadingFailed)return;this._character=function(t,e){const r=D(e);return new x(t,r)}(t,e);const{width:r,height:i,padding:s}=this._options;this._positioner=new O({width:r,height:i,padding:s});const o=new this._renderer.HanziWriterRenderer(this._character,this._positioner);this._hanziWriterRenderer=o,this._renderState=new p(this._character,this._options,t=>o.render(t)),this._hanziWriterRenderer.mount(this.target),this._hanziWriterRenderer.render(this._renderState.state)}),this._withDataPromise}_assignOptions(t){const e={...gt,...t};return t.strokeAnimationDuration&&!t.strokeAnimationSpeed&&(e.strokeAnimationSpeed=500/t.strokeAnimationDuration),t.strokeHighlightDuration&&!t.strokeHighlightSpeed&&(e.strokeHighlightSpeed=500/e.strokeHighlightDuration),t.highlightCompleteColor||(e.highlightCompleteColor=e.highlightColor),this._fillWidthAndHeight(e)}_fillWidthAndHeight(t){const e={...t};if(e.width&&!e.height)e.height=e.width;else if(e.height&&!e.width)e.width=e.height;else if(!e.width&&!e.height){const{width:t,height:r}=this.target.getBoundingClientRect(),i=Math.min(t,r);e.width=i,e.height=i}return e}_withData(t){if(this._loadingManager.loadingFailed)throw Error("Failed to load character data. Call setCharacter and try again.");return this._withDataPromise?this._withDataPromise.then(()=>{if(!this._loadingManager.loadingFailed)return t()}):Promise.resolve().then(t)}_setupListeners(){this.target.addPointerStartListener(t=>{this._quiz&&(t.preventDefault(),this._quiz.startUserStroke(t.getPoint()))}),this.target.addPointerMoveListener(t=>{this._quiz&&(t.preventDefault(),this._quiz.continueUserStroke(t.getPoint()))}),this.target.addPointerEndListener(()=>{this._quiz?.endUserStroke()})}}return ft._loadingManager=null,ft._loadingOptions=null,ft}(); | ||
//# sourceMappingURL=hanzi-writer.min.js.map |
{ | ||
"name": "hanzi-writer", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"author": "David Chanin <chanindav@gmail.com> (http://chanind.github.io/hanzi-writer/)", | ||
"description": "Hanzi Writer is a free and open-source javascript library for both animating simplified Chinese characters and quizzing users on character stroke order.", | ||
"repository": "chanind/hanzi-writer", | ||
"main": "dist/hanzi-writer.js", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/types/index.esm.d.ts", | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.0.1", | ||
"babel-jest": "^24.8.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.0", | ||
"codecov": "^3.3.0", | ||
"eslint": "^4.17.0", | ||
"eslint-config-airbnb": "^15.1.0", | ||
"eslint-loader": "^1.9.0", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-jsx-a11y": "^5.1.1", | ||
"eslint-plugin-no-for-of-loops": "^1.0.0", | ||
"eslint-plugin-react": "^7.4.0", | ||
"grunt": "^1.0.1", | ||
"grunt-contrib-clean": "^1.1.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-uglify": "^3.1.0", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-webpack": "^3.0.2", | ||
"hanzi-writer-data": "^1.0.0", | ||
"jest-canvas-mock": "^2.1.0", | ||
"jest-cli": "^24.8.0", | ||
"lolex": "2.3.2", | ||
"nise": "^1.2.5", | ||
"semantic-release": "^15.13.12", | ||
"webpack": "^3.6.0" | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@sinonjs/fake-timers": "^6.0.1", | ||
"@types/jest": "^26.0.14", | ||
"@types/nise": "^1.4.0", | ||
"@types/sinonjs__fake-timers": "^6.0.2", | ||
"@typescript-eslint/eslint-plugin": "^4.4.0", | ||
"@typescript-eslint/parser": "^4.4.0", | ||
"@wessberg/rollup-plugin-ts": "^1.3.5", | ||
"codecov": "^3.8.0", | ||
"eslint": "^7.11.0", | ||
"hanzi-writer-data": "^2.0.1", | ||
"jest-canvas-mock": "2.1.0", | ||
"jest-cli": "^26.5.3", | ||
"jest-fetch-mock": "^3.0.3", | ||
"nise": "^4.0.4", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.29.0", | ||
"rollup-plugin-filesize": "^9.1.0", | ||
"rollup-plugin-license": "^2.2.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semantic-release": "^17.2.0", | ||
"typescript": "^4.1.3" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"lint-test": "eslint -c .eslintrc-jest src", | ||
"build": "grunt", | ||
"prepublishOnly": "grunt", | ||
"semantic-release": "semantic-release" | ||
"lint-test": "eslint -c .eslintrc src", | ||
"lint-fix": "eslint --fix --ext .tsx,.ts .", | ||
"build": "rm -rf dist && rollup -c", | ||
"prepublishOnly": "rollup -c", | ||
"semantic-release": "semantic-release", | ||
"prettier": "prettier -w src", | ||
"typecheck": "tsc --noEmit --skipLibCheck" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"jest": { | ||
@@ -51,10 +58,7 @@ "setupFiles": [ | ||
], | ||
"transform": { | ||
".*": "<rootDir>/../babel-jest-processor.js" | ||
}, | ||
"testURL": "https://test.com/url#tag", | ||
"rootDir": "src", | ||
"coverageDirectory": "../coverage/", | ||
"testURL": "https://test.com/url#tag", | ||
"collectCoverage": true | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
785197
26
15
8036
1