diff --git a/dist/leon.js b/dist/leon.js new file mode 100644 index 0000000..2d1c57b --- /dev/null +++ b/dist/leon.js @@ -0,0 +1 @@ +var LeonSans=function(t){var r={};function e(i){if(r[i])return r[i].exports;var n=r[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,e),n.l=!0,n.exports}return e.m=t,e.c=r,e.d=function(t,r,i){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var n in t)e.d(i,n,function(r){return t[r]}.bind(null,n));return i},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){var i=e(1).default;t.exports=i},function(t,r,e){"use strict";function i(t){return(i="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})(t)}function n(t,r){for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:0,y:arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,w:t.rect.w*d*r,h:(t.rect.h+220)*d*r}}function x(t,r,e){return{x:t/2,y:(r-130*d*e)/2}}function b(t,r,e){var i=t.ratio.x1,n=t.ratio.x2,a=t.ratio.y1,l=t.ratio.y2;return{r:r,cr:e,fr1:u,fr2:y,gx1:i,gx2:n,gy1:a,gy2:l}}function g(t,r,e,i,n){var a=(i-n)/(r-e)*(t-e)+n;return ai&&(a=i),a}function m(t){var r,e,i,n,a,l,o,s,f,h,u,y=t.typo.p.length,d=[];for(r=0;r0)for(i=0;i0&&"a"!=r.pos.type){var i=r.lengths*e;t.setLineDash([r.lengths]),t.lineDashOffset=r.direction*(i+r.lengths),t.stroke()}}})}return d}function _(t,r){var e,i,n=t.length,a=[];for(e=0;e0){var s=e*o;t.setLineDash([e]),t.lineDashOffset=r.direction*(s+e),t.stroke()}return l}function H(t,r,e,i){var n,a;if(1==r.drawing.value)for(n=r.lines.length,a=0;a0&&(c[0].start=1,Array.prototype.push.apply(d,c))}return d}function et(t,r,e){var i,n,a,l,o,s,f,h=t.length,u=[],y=1,d=1;for(r>-1&&(d=g(r,1,0,80,10)*e),i=0;i0&&null!=(f=it(o,tt,l,s))&&(y&&(f.type="m",y=0),u.push(f)),tt=new V(o);return u}function it(t,r,e,i){if(t.type=e.type,t.distance=e.distance,t.num=i,r&&null==t.rotation){var n=t.x-r.x,a=t.y-r.y,l=Math.atan2(n,a);t.rotation=-l}else t.rotation=t.rotation;return t.rotation==ft?null:t}function nt(t,r){var e=at(t.x1,t.x2,t.x3,t.x4,r),i=at(t.y1,t.y2,t.y3,t.y4,r),n=lt(t.x1,t.x2,t.x3,t.x4,r),a=lt(t.y1,t.y2,t.y3,t.y4,r);return new V({x:e,y:i,rotation:-Math.atan2(n,a)})}function at(t,r,e,i,n){var a=n*n;return t+(3*-t+n*(3*t-t*n))*n+(3*r+n*(-6*r+3*r*n))*n+(3*e-3*e*n)*a+i*(a*n)}function lt(t,r,e,i,n){return 3*n*n*(3*r-t-3*e+i)+6*n*(t-2*r+e)+3*(-t+r)}var ot=Math.PI/180*180,st=Math.PI/180*90,ft=-100,ht="tofu",ut=824;function yt(t,r,e,i,n,a,l,o){var s,f=[],h=o.length;for(s=0;s":yt(423,90,352,0,0,0,0,[{d:-1,v:[["m",0,0,{x:-1,y:.3,r:ct(0,0,90,176)}],["l",90,176,{r:ot,f:1}],["l",0,352,{x:-1,y:.3,f:1}]]}]),"/":yt(433,130,352,0,0,0,0,[{d:1,v:[["m",0,352,{r:ct(0,352,130,0),f:1,y:0}],["l",130,0,{y:0}]]}])},mt=Object.assign({},pt,xt,bt,gt);function _t(t){var r=mt[t]||mt[ht];return r.v=t,r}function wt(t,r,e,i){var n;return n=t.indexOf("\n")>0?t.split("\n"):t.indexOf("\\n")>0?t.split("\\n"):[t],0==e?function(t){var r,e=[],i=t.length;for(r=0;r=e&&(y+=1,u=s.w,d[y]=[]);y+=1}var c=[];for(a=d.length,n=0;n0&&(" "==i[0]&&i.shift()," "==i[i.length-1]&&i.pop(),i.length>0&&c.push(i));return c}(n,r,e):function(t,r,e){var i,n,a,l,o,s,f,h,u,y,d=0,c=0,v=0,x=[];for(h=t.length,o=0;oe&&(d=c,x[v+=1]=[]),x[v].push(n)}v+=1,d=0}h=x.length;var b=[];for(o=0;o0&&b.push(a);return b}(n,r,e)}function Pt(t,r){return{c:(t-r)/2,r:t-r,l:0}}function kt(t,r){for(var e=0;e0&&void 0!==arguments[0]?arguments[0]:{},i=e.text,n=void 0===i?"":i,a=e.size,l=void 0===a?500:a,s=e.weight,f=void 0===s?o:s,h=e.color,u=void 0===h?["#000000"]:h,y=e.colorful,d=void 0===y?["#c5d73f","#9d529c","#49a9db","#fec330","#5eb96e","#fc5356","#f38f31"]:y,c=e.tracking,v=void 0===c?0:c,p=e.leading,x=void 0===p?0:p,b=e.align,g=void 0===b?"left":b,m=e.pathGap,_=void 0===m?.5:m,w=e.amplitude,P=void 0===w?.5:w,k=e.width,S=void 0===k?0:k,W=e.breakWord,D=void 0!==W&&W,T=e.fps,I=void 0===T?30:T,O=e.isPath,R=void 0!==O&&O,F=e.isWave,M=void 0!==F&&F;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),(t=Tt(this,Ot(r).call(this))).size_=l,t.weight_=f,t.color_=u,t.colorful_=function(t){for(var r,e,i=t.slice(),n=i.length,a=n;a--;)r=Math.random()*n|0,e=i[a],i[a]=i[r],i[r]=e;return i}(d),t.tracking_=v,t.leading_=x,t.pathGap_=_,t.amplitude_=P,t.width_=S,t.breakWord_=D,t.fps_=I,t.fpsTime_=1e3/t.fps_,t.isPath_=R,t.isWave_=M,t.model=new St,t.str_=null,t.time_=null,t.isFps_=!1,t.isForceRander_=!1,t.updateID_=0,t.dPathsID_=null,t.pPathsID_=null,t.wPathsID_=null,t.guideID_=null,t.text=n,t.model.align=g,t}var e,i,n;return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&Rt(t,r)}(r,a),e=r,(i=[{key:"on",value:function(t,e){It(Ot(r.prototype),"on",this).call(this,t,e),this.update()}},{key:"off",value:function(t,e){It(Ot(r.prototype),"off",this).call(this,t,e)}},{key:"position",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.model.position(t,r)&&(this.updateID_++,this.updateSignal())}},{key:"update",value:function(){this.updateID_++,this.model.update(this.str_,this.width_,this.breakWord_,this.weight_,this.size_,this.tracking_,this.leading_),this.isPath_||this.isWave_?(this.updatePatternPaths(),this.updateWavePaths()):this.updateSignal()}},{key:"updateGuide",value:function(){this.guideID_!=this.updateID_&&(this.guideID_=this.updateID_,this.model.updateGuide())}},{key:"updateDrawingPaths",value:function(){this.dPathsID_!=this.updateID_&&(this.dPathsID_=this.updateID_,this.model.updateDrawingPaths())}},{key:"updatePatternPaths",value:function(t){this.isPath_&&(t||this.pPathsID_!=this.updateID_)&&(this.pPathsID_=this.updateID_,this.model.updatePatternPaths(this.pathGap_),this.isForceRander_=!0,this.updateSignal())}},{key:"updateWavePaths",value:function(t){this.isWave_&&(t||this.wPathsID_!=this.updateID_)&&(this.wPathsID_=this.updateID_,this.model.updateWavePaths(this.pathGap_),this.isForceRander_=!0,this.updateSignal())}},{key:"updateSignal",value:function(){this.model.updateLinesForRect(),this.model.updatePathsForRect(),this.dispatch("update",this.model)}},{key:"reset",value:function(){this.size_=500,this.weight_=o,this.color_=["#000000"],this.tracking_=0,this.leading_=0,this.pathGap_=.5,this.amplitude_=.5,this.width_=0,this.breakWord_=!1,this.fps_=30,this.fpsTime_=1e3/this.fps_,this.isPath_=!1,this.isWave_=!1,this.str_=null,this.time_=null,this.isFps_=!1,this.isForceRander_=!1,this.updateID_=0,this.dPathsID_=null,this.pPathsID_=null,this.wPathsID_=null,this.guideID_=null,this.model.reset()}},{key:"dispose",value:function(){this.reset(),this.model=null}},{key:"drawPixi",value:function(t){var r,e,i,n=this.model.data.length;for(r=0;rq&&(X(t),t.beginPath(),f&&t.moveTo(f.x,f.y),t.lineTo(s.x,s.y),y+=B(t,o,u,h,n,y)),f=s):"b"==s.type&&((u=C(f.x,f.y,s.x,s.y,s.x2,s.y2,s.x3,s.y3))/r.scale>q&&(X(t),t.beginPath(),f&&t.moveTo(f.x,f.y),t.bezierCurveTo(s.x,s.y,s.x2,s.y2,s.x3,s.y3),y+=B(t,o,u,h,n,y)),f={x:s.x3,y:s.y3})}(t,this.model,this.colorful_)}},{key:"wave",value:function(t,r){t.lineWidth=this.lineWidth,r&&(this.time_||(this.time_=r),r-this.time_>this.fpsTime_||this.isForceRander_?(this.time_=r,this.isFps_=!0):this.isFps_=!1),this.isForceRander_=!1;var e,i,n=this.model.data.length;for(e=0;es&&(t=s),this.weight_!=t&&(this.weight_=t,this.update(),this.isForceRander_=!0)}},{key:"color",get:function(){return this.color_},set:function(t){this.color_!=t&&(this.color_=t)}},{key:"tracking",get:function(){return this.tracking_},set:function(t){this.tracking_!=t&&(this.tracking_=t,this.update(),this.isForceRander_=!0)}},{key:"leading",get:function(){return this.leading_},set:function(t){this.leading_!=t&&(this.leading_=t,this.update(),this.isForceRander_=!0)}},{key:"align",get:function(){return this.model.align},set:function(t){this.model.align!=t&&(this.model.align=t,this.updateID_++,this.updateSignal())}},{key:"pathGap",get:function(){return this.pathGap_},set:function(t){this.pathGap_!=t&&(this.pathGap_=t,this.updatePatternPaths(!0),this.updateWavePaths(!0),this.isForceRander_=!0)}},{key:"amplitude",get:function(){return this.amplitude_},set:function(t){this.amplitude_=t}},{key:"rect",get:function(){return this.model.rect}},{key:"maxWidth",set:function(t){this.width_!=t&&(this.width_=t,this.update())},get:function(){return this.width_}},{key:"breakWord",set:function(t){this.breakWord_!=t&&(this.breakWord_=t,this.update())},get:function(){return this.breakWord_}},{key:"isPath",get:function(){return this.isPath_},set:function(t){this.isPath_=t,this.updatePatternPaths(!0)}},{key:"isWave",get:function(){return this.isWave_},set:function(t){this.isWave_=t,this.updateWavePaths(!0)}},{key:"fps",get:function(){return this.fps_},set:function(t){this.fps_=t,this.fpsTime_=1e3/this.fps_}},{key:"lineWidth",get:function(){return this.model.lineWidth}},{key:"scale",get:function(){return this.model.scale}},{key:"drawing",get:function(){return this.model.drawing}},{key:"data",get:function(){return this.model.data}},{key:"paths",get:function(){return this.model.paths}},{key:"drawingPaths",get:function(){return this.model.drawingPaths}},{key:"wavePaths",get:function(){return this.model.wavePaths}}])&&Dt(e.prototype,i),n&&Dt(e,n),r}()}]); \ No newline at end of file diff --git a/examples/all.html b/examples/all.html new file mode 100644 index 0000000..5023769 --- /dev/null +++ b/examples/all.html @@ -0,0 +1,111 @@ + + + + + + + + Leon Sans - All + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/canvas-basic.html b/examples/canvas-basic.html new file mode 100644 index 0000000..f8c0755 --- /dev/null +++ b/examples/canvas-basic.html @@ -0,0 +1,120 @@ + + + + + + + + Leon Sans - Canvas Basic + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/color-pattern.html b/examples/color-pattern.html new file mode 100644 index 0000000..ca60abd --- /dev/null +++ b/examples/color-pattern.html @@ -0,0 +1,144 @@ + + + + + + + + LeonSans - Color Pattern + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/colorful.html b/examples/colorful.html new file mode 100644 index 0000000..68259e9 --- /dev/null +++ b/examples/colorful.html @@ -0,0 +1,113 @@ + + + + + + + + Leon Sans - Colorful + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/gradient.html b/examples/gradient.html new file mode 100644 index 0000000..8681abb --- /dev/null +++ b/examples/gradient.html @@ -0,0 +1,109 @@ + + + + + + + + Leon Sans - Gradient + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/grid.html b/examples/grid.html new file mode 100644 index 0000000..ac54b6c --- /dev/null +++ b/examples/grid.html @@ -0,0 +1,94 @@ + + + + + + + + Leon Sans - Grids + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 0000000..f408a5d --- /dev/null +++ b/examples/index.html @@ -0,0 +1,267 @@ + + + + + + + + Leon Sans examples + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/mask-tiling-pixi.html b/examples/mask-tiling-pixi.html new file mode 100644 index 0000000..322b5e9 --- /dev/null +++ b/examples/mask-tiling-pixi.html @@ -0,0 +1,199 @@ + + + + + + + + Leon Sans - MASK + Tiling PIXI + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/metaball-pixi.html b/examples/metaball-pixi.html new file mode 100644 index 0000000..cf3fc79 --- /dev/null +++ b/examples/metaball-pixi.html @@ -0,0 +1,230 @@ + + + + + + + + Leon Sans - Metaball PIXI + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/morphing-pixi.html b/examples/morphing-pixi.html new file mode 100644 index 0000000..293727c --- /dev/null +++ b/examples/morphing-pixi.html @@ -0,0 +1,232 @@ + + + + + + + + Leon Sans - Morphing PIXI + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/pattern.html b/examples/pattern.html new file mode 100644 index 0000000..1b50b04 --- /dev/null +++ b/examples/pattern.html @@ -0,0 +1,94 @@ + + + + + + + + Leon Sans - Pattern + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/plants-pixi.html b/examples/plants-pixi.html new file mode 100644 index 0000000..02b3b74 --- /dev/null +++ b/examples/plants-pixi.html @@ -0,0 +1,227 @@ + + + + + + + + Leon Sans - Plants PIXI + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/wave.html b/examples/wave.html new file mode 100644 index 0000000..3c83872 --- /dev/null +++ b/examples/wave.html @@ -0,0 +1,82 @@ + + + + + + + + Leon Sans - Wave + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/webgl-basic-pixi.html b/examples/webgl-basic-pixi.html new file mode 100644 index 0000000..28c8f5a --- /dev/null +++ b/examples/webgl-basic-pixi.html @@ -0,0 +1,124 @@ + + + + + + + + Leon Sans - WebGL Basic PIXI + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..1b9c716 --- /dev/null +++ b/src/index.js @@ -0,0 +1,2 @@ +const LeonSans = require('./LeonSans').default; +module.exports = LeonSans; \ No newline at end of file diff --git a/src/leonsans.js b/src/leonsans.js new file mode 100644 index 0000000..620536a --- /dev/null +++ b/src/leonsans.js @@ -0,0 +1,521 @@ +import { + Dispatcher +} from './core/dispatcher.js'; +import { + MIN_FONT_WEIGHT, + MAX_FONT_WEIGHT, + shuffle +} from './core/util.js'; +import { + Lines +} from './draw/canvas/lines.js'; +import { + Points +} from './draw/canvas/points.js'; +import { + Grids +} from './draw/canvas/grids.js'; +import { + Wave +} from './draw/canvas/wave.js'; +import { + Pattern +} from './draw/canvas/pattern.js'; +import { + Color +} from './draw/canvas/color.js'; +import { + Colorful +} from './draw/canvas/colorful.js'; +import { + PixiLines +} from './draw/pixi/lines.js'; +import { + PixiColor +} from './draw/pixi/color.js'; +import { + Model +} from './core/model.js'; + + +export default class LeonSans extends Dispatcher { + constructor({ + text = '', + size = 500, + weight = MIN_FONT_WEIGHT, + color = ['#000000'], + colorful = ['#c5d73f', '#9d529c', '#49a9db', '#fec330', '#5eb96e', '#fc5356', '#f38f31'], + tracking = 0, + leading = 0, + align = 'left', + pathGap = 0.5, + amplitude = 0.5, + width = 0, + breakWord = false, + fps = 30, + isPath = false, + isWave = false, + } = {}) { + super(); + + this.size_ = size; + this.weight_ = weight; + this.color_ = color; + this.colorful_ = shuffle(colorful); + this.tracking_ = tracking; + this.leading_ = leading; + this.pathGap_ = pathGap; + this.amplitude_ = amplitude; + this.width_ = width; + this.breakWord_ = breakWord; + this.fps_ = fps; + this.fpsTime_ = 1000 / this.fps_; + this.isPath_ = isPath; + this.isWave_ = isWave; + + this.model = new Model(); + + this.str_ = null; + + this.time_ = null; + this.isFps_ = false; + this.isForceRander_ = false; + + this.updateID_ = 0; + this.dPathsID_ = null; + this.pPathsID_ = null; + this.wPathsID_ = null; + this.guideID_ = null; + + this.text = text; + + this.model.align = align; + } + + on(event, callback) { + super.on(event, callback); + this.update(); + } + + off(event, callback) { + super.off(event, callback); + } + + get text() { + return this.str_; + } + + set text(str) { + if (this.str_ == str) return; + this.str_ = str; + this.update(); + } + + get size() { + return this.size_; + } + + set size(v) { + if (this.size_ == v) return; + this.size_ = v; + this.update(); + this.isForceRander_ = true; + } + + get weight() { + return this.weight_; + } + + set weight(v) { + if (v < MIN_FONT_WEIGHT) { + v = MIN_FONT_WEIGHT; + } else if (v > MAX_FONT_WEIGHT) { + v = MAX_FONT_WEIGHT; + } + if (this.weight_ == v) return; + this.weight_ = v; + this.update(); + this.isForceRander_ = true; + } + + get color() { + return this.color_; + } + + set color(v) { + if (this.color_ == v) return; + this.color_ = v; + } + + get tracking() { + return this.tracking_; + } + + set tracking(v) { + if (this.tracking_ == v) return; + this.tracking_ = v; + this.update(); + this.isForceRander_ = true; + } + + get leading() { + return this.leading_; + } + + set leading(v) { + if (this.leading_ == v) return; + this.leading_ = v; + this.update(); + this.isForceRander_ = true; + } + + get align() { + return this.model.align; + } + + set align(v) { + if (this.model.align != v) { + this.model.align = v; + this.updateID_++; + this.updateSignal(); + } + } + + get pathGap() { + return this.pathGap_; + } + + set pathGap(v) { + if (this.pathGap_ != v) { + this.pathGap_ = v; + this.updatePatternPaths(true); + this.updateWavePaths(true); + this.isForceRander_ = true; + } + } + + get amplitude() { + return this.amplitude_; + } + + set amplitude(v) { + this.amplitude_ = v; + } + + get rect() { + return this.model.rect; + } + + set maxWidth(v) { + if (this.width_ == v) return; + this.width_ = v; + this.update(); + } + + get maxWidth() { + return this.width_; + } + + set breakWord(v) { + if (this.breakWord_ == v) return; + this.breakWord_ = v; + this.update(); + } + + get breakWord() { + return this.breakWord_; + } + + get isPath() { + return this.isPath_; + } + + set isPath(v) { + this.isPath_ = v; + this.updatePatternPaths(true); + } + + get isWave() { + return this.isWave_; + } + + set isWave(v) { + this.isWave_ = v; + this.updateWavePaths(true); + } + + get fps() { + return this.fps_; + } + + set fps(v) { + this.fps_ = v; + this.fpsTime_ = 1000 / this.fps_; + } + + get lineWidth() { + return this.model.lineWidth; + } + + get scale() { + return this.model.scale; + } + + get drawing() { + return this.model.drawing; + } + + get data() { + return this.model.data; + } + + get paths() { + return this.model.paths; + } + + get drawingPaths() { + return this.model.drawingPaths; + } + + get wavePaths() { + return this.model.wavePaths; + } + + position(x = 0, y = 0) { + if (this.model.position(x, y)) { + this.updateID_++; + this.updateSignal(); + } + } + + update() { + this.updateID_++; + + this.model.update( + this.str_, + this.width_, + this.breakWord_, + this.weight_, + this.size_, + this.tracking_, + this.leading_ + ); + + if (this.isPath_ || this.isWave_) { + this.updatePatternPaths(); + this.updateWavePaths(); + } else { + this.updateSignal(); + } + } + + updateGuide() { + if (this.guideID_ != this.updateID_) { + this.guideID_ = this.updateID_; + this.model.updateGuide(); + } + } + + /** + * Update paths for drawing in WebGL (PIXI.js). It's very expensive, only call when it needs. + */ + updateDrawingPaths() { + if (this.dPathsID_ != this.updateID_) { + this.dPathsID_ = this.updateID_; + this.model.updateDrawingPaths(); + } + } + + /** + * Update paths for pattern + * @param {boolean} force - Force execution + */ + updatePatternPaths(force) { + if (this.isPath_ && (force || this.pPathsID_ != this.updateID_)) { + this.pPathsID_ = this.updateID_; + this.model.updatePatternPaths(this.pathGap_); + this.isForceRander_ = true; + this.updateSignal(); + } + } + + /** + * Update paths for wave effect + * @param {boolean} force - Force execution + */ + updateWavePaths(force) { + if (this.isWave_ && (force || this.wPathsID_ != this.updateID_)) { + this.wPathsID_ = this.updateID_; + this.model.updateWavePaths(this.pathGap_); + this.isForceRander_ = true; + this.updateSignal(); + } + } + + updateSignal() { + this.model.updateLinesForRect(); + this.model.updatePathsForRect(); + this.dispatch('update', this.model); + } + + reset() { + this.size_ = 500; + this.weight_ = MIN_FONT_WEIGHT; + this.color_ = ['#000000']; + this.tracking_ = 0; + this.leading_ = 0; + this.pathGap_ = 0.5; + this.amplitude_ = 0.5; + this.width_ = 0; + this.breakWord_ = false; + this.fps_ = 30; + this.fpsTime_ = 1000 / this.fps_; + this.isPath_ = false; + this.isWave_ = false; + + this.str_ = null; + + this.time_ = null; + this.isFps_ = false; + this.isForceRander_ = false; + + this.updateID_ = 0; + this.dPathsID_ = null; + this.pPathsID_ = null; + this.wPathsID_ = null; + this.guideID_ = null; + + this.model.reset(); + } + + dispose() { + this.reset(); + this.model = null; + } + + /** + * Draw text in WebGL with PIXI.js + * @param {PIXI.Graphics} graphics + */ + drawPixi(graphics) { + const total = this.model.data.length; + let i, d, color; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + color = PixiColor(i, d, this.color_); + PixiLines(graphics, d, this.lineWidth, color); + } + } + + /** + * Draw text in the Canvas element. + * @param {CanvasRenderingContext2D} ctx + */ + draw(ctx) { + ctx.lineWidth = this.lineWidth; + const total = this.model.data.length; + let i, d; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + Color(ctx, i, d, this.color_); + Lines(ctx, d); + } + } + + /** + * Draw the colorful effect. + * @param {CanvasRenderingContext2D} ctx + */ + drawColorful(ctx) { + ctx.lineWidth = this.lineWidth; + Colorful(ctx, this.model, this.colorful_); + } + + /** + * Draw the wave effect. + * @param {CanvasRenderingContext2D} ctx + * @param {DOMHighResTimeStamp} t time stemp from requestAnimationFrame() + */ + wave(ctx, t) { + ctx.lineWidth = this.lineWidth; + + if (t) { + if (!this.time_) this.time_ = t; + const p = t - this.time_; + if (p > this.fpsTime_ || this.isForceRander_) { + this.time_ = t; + this.isFps_ = true; + } else { + this.isFps_ = false; + } + } + this.isForceRander_ = false; + + const total = this.model.data.length; + let i, d; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + Color(ctx, i, d, this.color_); + Wave(ctx, d, this.model.scale, this.amplitude_, this.weight_, this.isFps_); + } + } + + /** + * Draw rectangle shapes at each path point. + * @param {CanvasRenderingContext2D} ctx + * @param {number} w pattern width + * @param {number} h pattern height + */ + pattern(ctx, w, h) { + const tw = w * this.model.scale; + const th = h * this.model.scale; + + const total = this.model.data.length; + let i, d; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + Pattern(ctx, d, tw, th); + } + } + + /** + * Draw grid for each type. + * @param {CanvasRenderingContext2D} ctx + */ + grid(ctx) { + this.updateGuide(); + + const total = this.model.data.length; + let i, d; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + Grids(ctx, d); + } + } + + /** + * Draw circles at each drawing point and lines for each type. + * @param {CanvasRenderingContext2D} ctx + */ + point(ctx) { + const total = this.model.data.length; + let i, d; + for (i = 0; i < total; i++) { + d = this.model.data[i]; + Points(ctx, d); + } + } + + /** + * Draw outline box for the text. + * @param {CanvasRenderingContext2D} ctx + * @private + */ + box(ctx) { + ctx.lineWidth = 1; + ctx.beginPath(); + ctx.strokeStyle = "#0b90dc"; + ctx.rect(this.model.rect.x, this.model.rect.y, this.model.rect.w, this.model.rect.h); + ctx.stroke(); + } +} \ No newline at end of file