-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquireMatrix.min.js
1 lines (1 loc) · 2.95 KB
/
quireMatrix.min.js
1
!function(){var e=function(e){var t="string"==typeof e?document.getElementById(e):e[0],n=t.getContext("2d"),o=t.height,i=t.width,s=20,a=1,r={0:"1",1:"0","0*":"1*","1*":"0*","0+":"1+","1+":"0+","1x":"1x",2:"0","2*":"0",3:"0","3*":"0",4:"0","4*":"0","0+*":"1+*","1+*":"0+*"};function h(){n.moveTo(0,o-a*s),n.lineTo(i/2,o-(a-1)*s)}function l(e){n.beginPath(),e&&n.setLineDash([5]),n.moveTo(i,o-a*s),n.lineTo(i/2,o-(a-1)*s),n.lineTo(i/2-i/10,o-a*s+.75*s),n.stroke(),e&&n.setLineDash([])}function c(e){n.beginPath(),e&&n.setLineDash([5]),h(),n.lineTo(i/2+i/10,o-a*s+.75*s),n.stroke(),e&&n.setLineDash([])}function g(e){n.beginPath(),e&&n.setLineDash([5]),h(),n.lineTo(0,o-a*s-s/2),n.stroke(),n.setLineDash([])}function T(e){n.beginPath(),e&&n.setLineDash([5]),h(),n.lineTo(0,o-a*s-s/3),n.stroke(),n.moveTo(i/2,o-(a-1)*s),n.lineTo(0,o-a*s-2*s/3),n.stroke(),n.setLineDash([])}function u(e){n.beginPath(),e&&n.setLineDash([5]),h(),n.lineTo(0,o-a*s-s/4),n.stroke(),n.moveTo(i/2,o-(a-1)*s),n.lineTo(0,o-a*s-2*s/4),n.stroke(),n.moveTo(i/2,o-(a-1)*s),n.lineTo(0,o-a*s-3*s/4),n.stroke(),n.setLineDash([])}n.lineWidth=1.5,this.addRow=function(e){"1"===e?(n.beginPath(),h(),n.stroke()):"1+"===e?c():"1x"===e?(n.beginPath(),h(),n.lineTo(i,o-s*a),n.stroke()):"1x*"===e?(n.beginPath(),n.setLineDash([5]),h(),n.lineTo(i,o-s*a),n.stroke(),n.setLineDash([])):"1*"===e?(n.beginPath(),n.moveTo(0,o-a*s),n.lineTo(i/2,o-(a-1)*s),n.stroke(),n.beginPath(),n.setLineDash([5]),n.moveTo(i/2,o-(a-1)*s),n.lineTo(i,o-s*a),n.stroke(),n.setLineDash([])):"0"===e?(n.beginPath(),n.moveTo(i/2,o-(a-1)*s),n.lineTo(i,o-s*a),n.stroke()):"0*"===e?(n.beginPath(),n.setLineDash([5]),n.moveTo(0,o-a*s),n.lineTo(i/2,o-(a-1)*s),n.stroke(),n.setLineDash([]),n.beginPath(),n.moveTo(i/2,o-(a-1)*s),n.lineTo(i,o-s*a),n.stroke()):"0+"===e?l():"2"===e?g():"2*"===e?g(!0):"3"===e?T():"3*"===e?T(!0):"4"===e?u():"4*"===e?u(!0):"0+*"===e?l(!0):"1+*"===e&&c(!0),a++},this.clear=function(){a=1,n.clearRect(0,0,i,o),n.beginPath()},this.parseString=function(e,n){var i=this,a=!!n&&("string"==typeof n?document.getElementById(n):n[0]),h=0;if(i.clear(),!e||""===e)return"";var l=e.replace(/\/$/,"").split("/");l.length>3&&(o=50+l.length*s,t.setAttribute("height",o)),l.forEach(function(e){e&&("1x*"!==e&&"1+*"!==e&&(h+=parseInt(e.replace("*","").replace("x",""))),i.addRow(e))});var c=l.reverse();c.forEach(function(e,t,n){if(void 0!==r[e]&&(n[t]=r[e]),e&&"1x*"!==n[t]){var o=n[t]?parseInt(n[t].replace("*","").replace("x","")):0;h+=isNaN(o)?0:o}});var g={text:c.join("/"),tot:2*h};return a?(a.innerHTML="",a.innerHTML="<code><strong>"+g.text+"</strong></code><br>Total: <strong>"+g.tot+"</strong> pages"):console.log(g),g},this.observeInput=function(e,t){var n,o,i,s="string"==typeof e?document.getElementById(e):e[0],a=this;a.parseString(s.value,t),o="input",i=function(){a.parseString(s.value,t)},(n=s).addEventListener?n.addEventListener(o,i,!1):n.attachEvent&&n.attachEvent("on"+o,i)}};"undefined"!=typeof module&&void 0!==module.exports?module.exports=e:window.Matrix=e}();