-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.min.js
10 lines (10 loc) · 4.93 KB
/
canvas.min.js
1
2
3
4
5
6
7
8
9
10
Object.observe||function(b,k){var q=function(a){var b=a.call(a),c=typeof c;return"object"===typeof k.alert?function(m){return b===a.call(m)||!!m&&typeof m.toString==c&&typeof m.valueOf==c&&/^\s*\bfunction\b/.test(""+m)}:function(c){return b===a.call(c)}}(b.prototype.toString),g=function(a,b){if("object"!==typeof a)throw new TypeError("Object.observeObject called on non-object");if(!1===q(b))throw new TypeError("Object.observeObject: Expecting function");if(!0===Object.isFrozen(b))throw new TypeError("Object.observeObject: Expecting unfrozen function");
},e=function(){var a=[],b=function(b,c){g(b,c);Object.getNotifier(b).addListener(c);-1===a.indexOf(b)?a.push(b):Object.getNotifier(b)._checkPropertyListing()};b.prototype.deliverChangeRecords=function(a){Object.getNotifier(a).deliverChangeRecords()};a.lastScanned=0;var c=function(a){return function(){for(var b=0,n=a.length,d=new Date,e=!1,b=a.lastScanned;b<n&&!e;b++)Object.getNotifier(a[b])._checkPropertyListing(),e=100<new Date-d;a.lastScanned=b<n?b:0;setTimeout(c,100)}}(a);setTimeout(c,100);return b}(),
a=function(a){var b=[],c=[],d=!1,e=[],h=[],f=this;Object.defineProperty(f,"_watching",{get:function(b){return function(){return b}}(a)});var g=function(b,a){var c=Object.getOwnPropertyDescriptor(b,a),d;(d="getNotifier"===a)||(d=("undefined"===typeof c?!1:"get"in c||"set"in c)||!c.enumerable);if(d)return!1;if(b instanceof Array&&!isNaN(parseFloat(a))&&isFinite(a))return c=e.length,e[c]=a,h[c]=b[a],!0;(function(a,c){e[a]=c;h[a]=b[c];Object.defineProperty(b,c,{get:function(){return h[a]},set:function(d){var e=
h[a];if(e===d?0===e&&1/e!==1/d:e===e||d===d)Object.getNotifier(b).queueUpdate(b,c,"updated",h[a]),h[a]=d}})})(e.length,a);return!0};f._checkPropertyListing=function(a){for(var b=f._watching,c=Object.keys(b),d=0,n=c.length,l=e.slice(0),k=!a,m,p,d=0;d<n;d++)a=c[d],m=b[a],-1===(p=e.indexOf(a))?g(b,a)&&k&&f.queueUpdate(b,a,"new",null,b[a]):(b instanceof Array&&!isNaN(parseFloat(a))&&isFinite(a)&&h[p]!==m&&(k&&f.queueUpdate(b,a,"updated",h[p],m),h[p]=m),l.splice(l.indexOf(a),1));if(k)for(n=l.length,d=
0;d<n;d++)p=e.indexOf(l[d]),f.queueUpdate(b,l[d],"deleted",h[p]),e.splice(p,1),h.splice(p,1)};f.addListener=function(a){-1===b.indexOf(a)&&b.push(a)};f.removeListener=function(a){a=b.indexOf(a);-1<a&&b.splice(a,1)};f.listeners=function(){return b};f.queueUpdate=function(a,b,c,d){this.queueUpdates([{type:c,object:a,name:b,oldValue:d}])};f.queueUpdates=function(a){for(var b=this,e=0,n=a.length||0,l,e=0;e<n;e++)l=a[e],c.push(l);d&&clearTimeout(d);d=setTimeout(function(){d=!1;b.deliverChangeRecords()},
100)};f.deliverChangeRecords=function(){for(var a=0,d=b.length,e=!0,a=0;a<d&&e;a++)"function"===typeof b[a]&&(b[a]===console.log?console.log(c):e=!b[a](c));c=[]};f._checkPropertyListing(!0)},c=[],d=[];b.getNotifier=function(b){var e=d.indexOf(b);(e=-1<e?c[e]:!1)||(e=d.length,d[e]=b,e=c[e]=new a(b));return e};b.observe=function(a,b){return new e(a,b)};b.unobserve=function(a,c){g(a,c);b.getNotifier(a).removeListener(c)}}(Object,this);
function canvas(b){function k(a,c){if(a instanceof Array)for(var d in a)k(a[d]);else if(a instanceof Object){if(a.hire)if(a.hire instanceof Object)k(a.hire,a);else if(a.hire instanceof Array)for(var l in a.hire)k(a.hire[l],c);c||(c=a);for(d in a)c[d]||(c[d]=a[d]);a.draw&&(g.beginPath(),g.fillStyle=c.color,a.draw(g,c),g.stroke());if(a.onmouseover||a.onmousedown||a.onmouseup||a.onmouseout||a.draggable)b.events.push(a),a.evtid=b.events.length;c.evtid&&a.draw&&(e.ctx.beginPath(),e.ctx.fillStyle=b.generateColor(c.evtid),
a.draw(e.ctx,c),g.stroke());Object.observe(a,q)}}function q(a){b.redraw()}var g=b.getContext("2d");b.ctx=g;b.model=[];b.events=[];var e=document.createElement("canvas");document.body.appendChild(e);e.ctx=e.getContext("2d");e.width=b.width;e.height=b.height;Object.observe(b.model,q);b.redraw=function(){g.clearRect(0,0,b.width,b.height);b.events=[];e.width=b.width;e.height=b.height;e.ctx.clearRect(0,0,b.width,b.height);k(b.model,b.model)};b.generateColor=function(a){for(a=a.toString(16);6>a.length;)a=
"0"+a;return"#"+a};b.expand=function(){b.height=b.parentNode.offsetHeight;b.width=b.parentNode.offsetWidth;b.redraw();b.parentNode.onresize=b.expand};b.onmousemove=function(a){for(var c in b.events){var d=b.events[c];if(d.hover&&(b.events[c].hover=!1,d.onmouseout))d.onmouseout();d.drag&&(d.x+=a.offsetX-d.dragx,d.y+=a.offsetY-d.dragy,d.dragx=a.offsetX,d.dragy=a.offsetY,b.redraw())}c=e.ctx.getImageData(a.offsetX,a.offsetY,1,1).data;if(0!=c[2]){if((a=b.events[c[2]-1])&&!a.hover&&a.onmouseover)a.onmouseover();
a&&(a.hover=!0)}};b.onmousedown=function(a){var c=e.ctx.getImageData(a.offsetX,a.offsetY,1,1).data;if(0!=c[2]){c=b.events[c[2]-1];if(c.onmousedown)c.onmousedown();c.draggable&&(c.drag=!0,c.dragx=a.offsetX,c.dragy=a.offsetY)}};b.onmouseup=function(a){for(var c in b.events)b.events[c].drag&&(delete b.events[c].drag,delete b.events[c].dragx,delete b.events[c].dragy);c=e.ctx.getImageData(a.offsetX,a.offsetY,1,1).data;if(0!=c[2]&&(a=b.events[c[2]-1],a.onmouseup))a.onmouseup()};return b};