Comparing version 0.3.2 to 0.3.3
@@ -10,2 +10,6 @@ # Changelog | ||
## [0.3.3] - 2018-10-21 | ||
### Added | ||
- DOM.walkNodeTree() | ||
- CanvasPixelBuffer.clear()/sync() | ||
@@ -45,3 +49,4 @@ ## [0.3.2] - 2018-08-24 | ||
[Unreleased]: https://github.com/Sphinxxxx/abo-utils/compare/v0.3.2...HEAD | ||
[Unreleased]: https://github.com/Sphinxxxx/abo-utils/compare/v0.3.3...HEAD | ||
[0.3.3]: https://github.com/Sphinxxxx/abo-utils/compare/v0.3.2...v0.3.3 | ||
[0.3.2]: https://github.com/Sphinxxxx/abo-utils/compare/v0.3.1...v0.3.2 | ||
@@ -48,0 +53,0 @@ [0.3.1]: https://github.com/Sphinxxxx/abo-utils/compare/v0.3.0...v0.3.1 |
/*! | ||
* abo-utils v0.3.2 | ||
* abo-utils v0.3.3 | ||
* https://github.com/Sphinxxxx/abo-utils | ||
@@ -31,2 +31,32 @@ * | ||
function walkNodeTree(root, options) { | ||
options = options || {}; | ||
var inspect = options.inspect || function (n) { | ||
return true; | ||
}, | ||
collect = options.collect || function (n) { | ||
return true; | ||
}; | ||
var walker = document.createTreeWalker(root, NodeFilter.SHOW_ALL, { | ||
acceptNode: function acceptNode(node) { | ||
if (!inspect(node)) { | ||
return NodeFilter.FILTER_REJECT; | ||
} | ||
if (!collect(node)) { | ||
return NodeFilter.FILTER_SKIP; | ||
} | ||
return NodeFilter.FILTER_ACCEPT; | ||
} | ||
}); | ||
var nodes = [];var n = void 0; | ||
while (n = walker.nextNode()) { | ||
options.callback && options.callback(n); | ||
nodes.push(n); | ||
} | ||
return nodes; | ||
} | ||
function nodeName(elm, name) { | ||
@@ -215,2 +245,3 @@ if (elm && name) { | ||
selectors: selectors, | ||
walkNodeTree: walkNodeTree, | ||
nodeName: nodeName, | ||
@@ -522,3 +553,3 @@ createElement: createElement, | ||
this.targetContext = canvas.getContext('2d'); | ||
this.targetData = this.targetContext.getImageData(0, 0, this.w, this.h); | ||
this.sync(); | ||
} | ||
@@ -544,2 +575,15 @@ | ||
} | ||
}, { | ||
key: 'sync', | ||
value: function sync() { | ||
this.targetData = this.targetContext.getImageData(0, 0, this.w, this.h); | ||
} | ||
}, { | ||
key: 'clear', | ||
value: function clear() { | ||
this.targetContext.clearRect(0, 0, this.w, this.h); | ||
this.sync(); | ||
} | ||
}]); | ||
@@ -546,0 +590,0 @@ return CanvasPixelBuffer; |
/*! | ||
* abo-utils v0.3.2 | ||
* abo-utils v0.3.3 | ||
* https://github.com/Sphinxxxx/abo-utils | ||
@@ -8,2 +8,2 @@ * | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.ABOUtils={})}(this,function(e){"use strict";function i(e,t){var n=(t=t||document).querySelectorAll(e);return Array.from(n)}function t(e,t){return(t=t||document).querySelector(e)}var n=t;function c(e,t){if(e&&t)return e.nodeName.toLowerCase()===t.toLowerCase()}function r(e,t,n){var r=e.split(/([#\.])/);if(1<r.length){e=r[0]||"div",n=n||{};for(var a=1;a<r.length-1;a++){var o=r[a],i=r[a+1];"#"===o?n.id=i:n.class=n.class?n.class+" "+i:i,a++}}var c="svg"===e.toLowerCase()?"http://www.w3.org/2000/svg":t?t.namespaceURI:null,u=c?document.createElementNS(c,e):document.createElement(e);if(n)for(var l in n)u.setAttribute(l,n[l]);return t&&t.appendChild(u),u}function u(e,t,n){e.addEventListener(t,n,!1)}function a(e,r,a){(a=a||{}).autoRevoke;function n(e){if(e){e=Array.from(e);var t=a.acceptedTypes;if(t&&(e=e.filter(function(e){return t.includes(e.type)})),e.length){var n=e.map(o);r(n)}}}function o(e){return{url:URL.createObjectURL(e),file:e}}c(e,"INPUT")&&"file"===e.type?u(e,"change",function(e){var t=e.currentTarget;t.files&&n(t.files)}):(u(e,"dragover",function(e){return e.preventDefault()}),u(e,"drop",function(e){e.preventDefault(),n(e.dataTransfer.files)}))}function o(t){return function(e){t(e[0])}}var l=Object.freeze({$$:i,$:n,$$1:t,selectors:function(){return[n,i]},nodeName:c,createElement:r,relativeMousePos:function(e,t,n){function r(e,t,n){return Math.max(t,Math.min(e,n))}var a=t.getBoundingClientRect(),o=e.clientX-a.left,i=e.clientY-a.top;return n&&(o=r(o,0,a.width),i=r(i,0,a.height)),[o,i]},addEvent:u,live:function(e,a,o){document.addEventListener(e,function(e){var t=i(a);if(t&&t.length){for(var n=e.target,r=-1;n&&-1===(r=t.indexOf(n));)n=n.parentElement;-1<r&&o.call(n,e)}})},animate:function(a,o,i){var c=void 0,u=void 0;return requestAnimationFrame(function e(t){c||(c=t);var n=(t-c)/a,r=n%1;i&&Math.trunc(n)%2&&(r=1-r),o(r,n),u||requestAnimationFrame(e)}),{cancel:function(){u=!0}}},dropFiles:a,dropFile:function(e,t){a(e,o(t))},dropImage:function(e,t){a(e,o(t),{acceptedTypes:["image/png","image/jpeg","image/gif","image/svg","image/svg+xml"]})}});function f(e,t,n){e[t]||Object.defineProperty(e,t,{value:n})}f(Array,"from",function(e){return Array.prototype.slice.call(e)}),f(Math,"trunc",function(e){return e<0?Math.ceil(e):Math.floor(e)}),f(Number,"isNaN",function(e){return e!=e}),f(Array.prototype,"includes",function(a,o){return(o=o||0)<0&&(o=this.length+o),this.some(function(e,t){return o<=t&&(n=e,r=a,Number.isNaN(n)?Number.isNaN(r):n===r);var n,r})});var s=Element.prototype;f(s,"matches",s.msMatchesSelector||s.webkitMatchesSelector),f(s,"closest",function(e){var t=this;do{if(t.matches(e))return t;t=c(t,"svg")?t.parentNode:t.parentElement}while(t);return null}),f(HTMLCanvasElement.prototype,"toBlob",function(a,o,i){var c=this;setTimeout(function(){for(var e=atob(c.toDataURL(o,i).split(",")[1]),t=e.length,n=new Uint8Array(t),r=0;r<t;r++)n[r]=e.charCodeAt(r);a(new Blob([n],{type:o||"image/png"}))})});var h=Object.freeze({});var v=Object.freeze({clamp:function(e,t,n){return Math.max(t,Math.min(e,n))},lerp:function n(e,r,a){return Array.isArray(e)?e.map(function(e,t){return n(e,r[t],a)}):(1-a)*e+a*r}});function d(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)}function b(e,t,n){return Math.abs((t[0]-e[0])*(n[1]-e[1])-(n[0]-e[0])*(t[1]-e[1]))/2}function m(e,t,n){var r=d(t,n),a=d(n,e),o=d(e,t),i=r+a+o,c=i/2;return{r:b(e,t,n)/c,c:[(r*e[0]+a*t[0]+o*n[0])/i,(r*e[1]+a*t[1]+o*n[1])/i]}}function y(e,t,n,r){var a=m(e,t,n),o=a.c,i=(a.r+r)/a.r;function c(e){var t=e[0]-o[0],n=e[1]-o[1];return[t*i+o[0],n*i+o[1]]}return[c(e),c(t),c(n)]}var p=Object.freeze({distance:d,rotatePoint:function(e,t){var n=e[0],r=e[1],a=Math.cos(t),o=Math.sin(t);return[a*n-o*r,o*n+a*r]},angleBetween:function(e,t,n){function r(e){return e*e}var a=void 0;if(n){var o=r(t[0]-e[0])+r(t[1]-e[1]),i=r(t[0]-n[0])+r(t[1]-n[1]),c=r(n[0]-e[0])+r(n[1]-e[1]);a=Math.acos((o+i-c)/Math.sqrt(4*o*i))}else{var u=t[0]-e[0],l=t[1]-e[1];a=Math.atan2(l,u)}return a},triangleArea:b,triangleIncircle:m,expandTriangle:y}),g=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),w=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,a=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){a=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(a)throw o}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")};var M=function(){function r(e,t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.w=e.width=t||e.width,this.h=e.height=n||e.height,this.targetContext=e.getContext("2d"),this.targetData=this.targetContext.getImageData(0,0,this.w,this.h)}return g(r,[{key:"setPixel",value:function(e,t,n){var r=4*(t*this.w+e),a=this.targetData.data;a[r]=n[0],a[r+1]=n[1],a[r+2]=n[2],a[r+3]=3<n.length?n[3]:255}},{key:"render",value:function(){this.targetContext.putImageData(this.targetData,0,0)}}]),r}(),x=Object.freeze({drawImageTriangle:function(e,t,n,r,a,o,i,c,u){function l(e,t,n,r,a,o,i,c,u){var l=((o-u)*(t-a)-(n-o)*(a-c))/((r-i)*(t-a)-(e-r)*(a-c)),f=((o-u)*(e-r)-(n-o)*(r-i))/((a-c)*(e-r)-(t-a)*(r-i));return[l,f,n-e*l-t*f]}if(u){var f,s,h,v,d=b(o,i,c),m=b(n,r,a);f=y(o,i,c,.3),o=(s=w(f,3))[0],i=s[1],c=s[2],h=y(n,r,a,.3*m/d),n=(v=w(h,3))[0],r=v[1],a=v[2]}var p=l(n[0],n[1],o[0],r[0],r[1],i[0],a[0],a[1],c[0]),g=l(n[0],n[1],o[1],r[0],r[1],i[1],a[0],a[1],c[1]);t.save(),t.setTransform(p[0],g[0],p[1],g[1],p[2],g[2]),t.beginPath(),t.moveTo(n[0],n[1]),t.lineTo(r[0],r[1]),t.lineTo(a[0],a[1]),t.closePath(),t.clip(),t.drawImage(e,0,0,e.width,e.height),t.restore()},CanvasPixelBuffer:M}),T={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},C=/([astvzqmhlc])([^astvzqmhlc]*)/gi;var A=Object.freeze({parsePath:function(e){var o=[];return e.replace(C,function(e,t,n){var r,a=t.toLowerCase();for(n=(r=(r=(r=n).replace(/(\.\d+)(?=\.)/g,"$1 ")).match(/-?[.0-9]+(?:e[-+]?\d+)?/gi))?r.map(Number):[],"m"===a&&2<n.length&&(o.push([t].concat(n.splice(0,2))),a="l",t="m"===t?"l":"L");;){if(n.length===T[a])return n.unshift(t),o.push(n);if(n.length<T[a])throw new Error("Malformed path data: "+[t,n]);o.push([t].concat(n.splice(0,T[a])))}}),o},absolutizePath:function(e){var a=0,o=0,i=0,c=0;return e.map(function(e){var t=(e=e.slice())[0],n=t.toUpperCase();if(e.startPoint={x:i,y:c},t!==n)switch(e[0]=n,t){case"a":e[6]+=i,e[7]+=c;break;case"v":e[1]+=c;break;case"h":e[1]+=i;break;default:for(var r=1;r<e.length;)e[r++]+=i,e[r++]+=c}switch(n){case"Z":i=a,c=o;break;case"H":i=e[1];break;case"V":c=e[1];break;case"M":i=a=e[1],c=o=e[2];break;default:i=e[e.length-2],c=e[e.length-1]}return e.endPoint={x:i,y:c},e})},serializePath:function(e){return e.reduce(function(e,t){return e+t[0]+t.slice(1).join(",")},"")}});function E(){var e=new Date,t=("00"+e.getMilliseconds()).substr(-3);return e.toTimeString().split(" ")[0]+"."+t}var N=Object.freeze({printTime:E,log2:function(){var e="["+E()+"]",t=Array.from(arguments);t.unshift(e),console.log.apply(console,t)},alertErrors:function(){window.onerror=function(e,t,n){alert(E()+" - Error message: "+e+"\nURL: "+t+"\nLine Number: "+n)}},logToScreen:function(){var t=r("#abo-log",document.body,{style:"position:fixed;top:0;left:0;z-index:9999;white-space:pre;pointer-events:none;background-color:rgba(255,255,255,.5);"});console._log=console.log,console.log=function(){var e=Array.from(arguments).join(" ");t.textContent=e+"\n"+t.textContent}}});e.Polys=h,e.Math=v,e.Geom=p,e.DOM=l,e.Canvas=x,e.SVG=A,e.Debug=N,e.htmlEncode=function(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML},e.htmlDecode=function(e){var t=document.createElement("a");return t.innerHTML=e,t.textContent},e.getQueryVariable=function(e){for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var r=t[n].split("=");if(r[0]===e)return r[1]}return!1},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.ABOUtils={})}(this,function(e){"use strict";function i(e,t){var n=(t=t||document).querySelectorAll(e);return Array.from(n)}function t(e,t){return(t=t||document).querySelector(e)}var n=t;function c(e,t){if(e&&t)return e.nodeName.toLowerCase()===t.toLowerCase()}function r(e,t,n){var r=e.split(/([#\.])/);if(1<r.length){e=r[0]||"div",n=n||{};for(var a=1;a<r.length-1;a++){var o=r[a],i=r[a+1];"#"===o?n.id=i:n.class=n.class?n.class+" "+i:i,a++}}var c="svg"===e.toLowerCase()?"http://www.w3.org/2000/svg":t?t.namespaceURI:null,u=c?document.createElementNS(c,e):document.createElement(e);if(n)for(var l in n)u.setAttribute(l,n[l]);return t&&t.appendChild(u),u}function u(e,t,n){e.addEventListener(t,n,!1)}function a(e,r,a){(a=a||{}).autoRevoke;function n(e){if(e){e=Array.from(e);var t=a.acceptedTypes;if(t&&(e=e.filter(function(e){return t.includes(e.type)})),e.length){var n=e.map(o);r(n)}}}function o(e){return{url:URL.createObjectURL(e),file:e}}c(e,"INPUT")&&"file"===e.type?u(e,"change",function(e){var t=e.currentTarget;t.files&&n(t.files)}):(u(e,"dragover",function(e){return e.preventDefault()}),u(e,"drop",function(e){e.preventDefault(),n(e.dataTransfer.files)}))}function o(t){return function(e){t(e[0])}}var l=Object.freeze({$$:i,$:n,$$1:t,selectors:function(){return[n,i]},walkNodeTree:function(e,t){for(var n=(t=t||{}).inspect||function(e){return!0},r=t.collect||function(e){return!0},a=document.createTreeWalker(e,NodeFilter.SHOW_ALL,{acceptNode:function(e){return n(e)?r(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT}}),o=[],i=void 0;i=a.nextNode();)t.callback&&t.callback(i),o.push(i);return o},nodeName:c,createElement:r,relativeMousePos:function(e,t,n){function r(e,t,n){return Math.max(t,Math.min(e,n))}var a=t.getBoundingClientRect(),o=e.clientX-a.left,i=e.clientY-a.top;return n&&(o=r(o,0,a.width),i=r(i,0,a.height)),[o,i]},addEvent:u,live:function(e,a,o){document.addEventListener(e,function(e){var t=i(a);if(t&&t.length){for(var n=e.target,r=-1;n&&-1===(r=t.indexOf(n));)n=n.parentElement;-1<r&&o.call(n,e)}})},animate:function(a,o,i){var c=void 0,u=void 0;return requestAnimationFrame(function e(t){c||(c=t);var n=(t-c)/a,r=n%1;i&&Math.trunc(n)%2&&(r=1-r),o(r,n),u||requestAnimationFrame(e)}),{cancel:function(){u=!0}}},dropFiles:a,dropFile:function(e,t){a(e,o(t))},dropImage:function(e,t){a(e,o(t),{acceptedTypes:["image/png","image/jpeg","image/gif","image/svg","image/svg+xml"]})}});function s(e,t,n){e[t]||Object.defineProperty(e,t,{value:n})}s(Array,"from",function(e){return Array.prototype.slice.call(e)}),s(Math,"trunc",function(e){return e<0?Math.ceil(e):Math.floor(e)}),s(Number,"isNaN",function(e){return e!=e}),s(Array.prototype,"includes",function(a,o){return(o=o||0)<0&&(o=this.length+o),this.some(function(e,t){return o<=t&&(n=e,r=a,Number.isNaN(n)?Number.isNaN(r):n===r);var n,r})});var f=Element.prototype;s(f,"matches",f.msMatchesSelector||f.webkitMatchesSelector),s(f,"closest",function(e){var t=this;do{if(t.matches(e))return t;t=c(t,"svg")?t.parentNode:t.parentElement}while(t);return null}),s(HTMLCanvasElement.prototype,"toBlob",function(a,o,i){var c=this;setTimeout(function(){for(var e=atob(c.toDataURL(o,i).split(",")[1]),t=e.length,n=new Uint8Array(t),r=0;r<t;r++)n[r]=e.charCodeAt(r);a(new Blob([n],{type:o||"image/png"}))})});var h=Object.freeze({});var d=Object.freeze({clamp:function(e,t,n){return Math.max(t,Math.min(e,n))},lerp:function n(e,r,a){return Array.isArray(e)?e.map(function(e,t){return n(e,r[t],a)}):(1-a)*e+a*r}});function v(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)}function y(e,t,n){return Math.abs((t[0]-e[0])*(n[1]-e[1])-(n[0]-e[0])*(t[1]-e[1]))/2}function p(e,t,n){var r=v(t,n),a=v(n,e),o=v(e,t),i=r+a+o,c=i/2;return{r:y(e,t,n)/c,c:[(r*e[0]+a*t[0]+o*n[0])/i,(r*e[1]+a*t[1]+o*n[1])/i]}}function b(e,t,n,r){var a=p(e,t,n),o=a.c,i=(a.r+r)/a.r;function c(e){var t=e[0]-o[0],n=e[1]-o[1];return[t*i+o[0],n*i+o[1]]}return[c(e),c(t),c(n)]}var m=Object.freeze({distance:v,rotatePoint:function(e,t){var n=e[0],r=e[1],a=Math.cos(t),o=Math.sin(t);return[a*n-o*r,o*n+a*r]},angleBetween:function(e,t,n){function r(e){return e*e}var a=void 0;if(n){var o=r(t[0]-e[0])+r(t[1]-e[1]),i=r(t[0]-n[0])+r(t[1]-n[1]),c=r(n[0]-e[0])+r(n[1]-e[1]);a=Math.acos((o+i-c)/Math.sqrt(4*o*i))}else{var u=t[0]-e[0],l=t[1]-e[1];a=Math.atan2(l,u)}return a},triangleArea:y,triangleIncircle:p,expandTriangle:b}),g=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),w=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,a=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){a=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(a)throw o}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")};var T=function(){function r(e,t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.w=e.width=t||e.width,this.h=e.height=n||e.height,this.targetContext=e.getContext("2d"),this.sync()}return g(r,[{key:"setPixel",value:function(e,t,n){var r=4*(t*this.w+e),a=this.targetData.data;a[r]=n[0],a[r+1]=n[1],a[r+2]=n[2],a[r+3]=3<n.length?n[3]:255}},{key:"render",value:function(){this.targetContext.putImageData(this.targetData,0,0)}},{key:"sync",value:function(){this.targetData=this.targetContext.getImageData(0,0,this.w,this.h)}},{key:"clear",value:function(){this.targetContext.clearRect(0,0,this.w,this.h),this.sync()}}]),r}(),M=Object.freeze({drawImageTriangle:function(e,t,n,r,a,o,i,c,u){function l(e,t,n,r,a,o,i,c,u){var l=((o-u)*(t-a)-(n-o)*(a-c))/((r-i)*(t-a)-(e-r)*(a-c)),s=((o-u)*(e-r)-(n-o)*(r-i))/((a-c)*(e-r)-(t-a)*(r-i));return[l,s,n-e*l-t*s]}if(u){var s,f,h,d,v=y(o,i,c),p=y(n,r,a);s=b(o,i,c,.3),o=(f=w(s,3))[0],i=f[1],c=f[2],h=b(n,r,a,.3*p/v),n=(d=w(h,3))[0],r=d[1],a=d[2]}var m=l(n[0],n[1],o[0],r[0],r[1],i[0],a[0],a[1],c[0]),g=l(n[0],n[1],o[1],r[0],r[1],i[1],a[0],a[1],c[1]);t.save(),t.setTransform(m[0],g[0],m[1],g[1],m[2],g[2]),t.beginPath(),t.moveTo(n[0],n[1]),t.lineTo(r[0],r[1]),t.lineTo(a[0],a[1]),t.closePath(),t.clip(),t.drawImage(e,0,0,e.width,e.height),t.restore()},CanvasPixelBuffer:T}),x={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},N=/([astvzqmhlc])([^astvzqmhlc]*)/gi;var C=Object.freeze({parsePath:function(e){var o=[];return e.replace(N,function(e,t,n){var r,a=t.toLowerCase();for(n=(r=(r=(r=n).replace(/(\.\d+)(?=\.)/g,"$1 ")).match(/-?[.0-9]+(?:e[-+]?\d+)?/gi))?r.map(Number):[],"m"===a&&2<n.length&&(o.push([t].concat(n.splice(0,2))),a="l",t="m"===t?"l":"L");;){if(n.length===x[a])return n.unshift(t),o.push(n);if(n.length<x[a])throw new Error("Malformed path data: "+[t,n]);o.push([t].concat(n.splice(0,x[a])))}}),o},absolutizePath:function(e){var a=0,o=0,i=0,c=0;return e.map(function(e){var t=(e=e.slice())[0],n=t.toUpperCase();if(e.startPoint={x:i,y:c},t!==n)switch(e[0]=n,t){case"a":e[6]+=i,e[7]+=c;break;case"v":e[1]+=c;break;case"h":e[1]+=i;break;default:for(var r=1;r<e.length;)e[r++]+=i,e[r++]+=c}switch(n){case"Z":i=a,c=o;break;case"H":i=e[1];break;case"V":c=e[1];break;case"M":i=a=e[1],c=o=e[2];break;default:i=e[e.length-2],c=e[e.length-1]}return e.endPoint={x:i,y:c},e})},serializePath:function(e){return e.reduce(function(e,t){return e+t[0]+t.slice(1).join(",")},"")}});function E(){var e=new Date,t=("00"+e.getMilliseconds()).substr(-3);return e.toTimeString().split(" ")[0]+"."+t}var A=Object.freeze({printTime:E,log2:function(){var e="["+E()+"]",t=Array.from(arguments);t.unshift(e),console.log.apply(console,t)},alertErrors:function(){window.onerror=function(e,t,n){alert(E()+" - Error message: "+e+"\nURL: "+t+"\nLine Number: "+n)}},logToScreen:function(){var t=r("#abo-log",document.body,{style:"position:fixed;top:0;left:0;z-index:9999;white-space:pre;pointer-events:none;background-color:rgba(255,255,255,.5);"});console._log=console.log,console.log=function(){var e=Array.from(arguments).join(" ");t.textContent=e+"\n"+t.textContent}}});e.Polys=h,e.Math=d,e.Geom=m,e.DOM=l,e.Canvas=M,e.SVG=C,e.Debug=A,e.htmlEncode=function(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML},e.htmlDecode=function(e){var t=document.createElement("a");return t.innerHTML=e,t.textContent},e.getQueryVariable=function(e){for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var r=t[n].split("=");if(r[0]===e)return r[1]}return!1},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "abo-utils", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "JS utils and polyfills.", | ||
@@ -5,0 +5,0 @@ "author": "Andreas Borgen", |
@@ -102,3 +102,3 @@ import * as geom from './utils-geom'; | ||
this.targetContext = canvas.getContext('2d'); | ||
this.targetData = this.targetContext.getImageData(0,0, this.w,this.h); | ||
this.sync(); | ||
} | ||
@@ -120,2 +120,12 @@ | ||
} | ||
//Useful if shapes are drawn using normal canvas methods. | ||
sync() { | ||
this.targetData = this.targetContext.getImageData(0,0, this.w,this.h); | ||
} | ||
clear() { | ||
this.targetContext.clearRect(0,0, this.w,this.h); | ||
this.sync(); | ||
} | ||
} | ||
@@ -122,0 +132,0 @@ |
/*global URL*/ | ||
/*global NodeFilter*/ | ||
@@ -22,2 +23,30 @@ | ||
//https://stackoverflow.com/questions/10730309/find-all-text-nodes-in-html-page | ||
function walkNodeTree(root, options) { | ||
options = options || {}; | ||
const inspect = options.inspect || (n => true), | ||
collect = options.collect || (n => true); | ||
const walker = document.createTreeWalker( | ||
root, | ||
NodeFilter.SHOW_ALL, | ||
{ | ||
acceptNode: function(node) { | ||
if(!inspect(node)) { return NodeFilter.FILTER_REJECT; } | ||
if(!collect(node)) { return NodeFilter.FILTER_SKIP; } | ||
return NodeFilter.FILTER_ACCEPT; | ||
} | ||
} | ||
); | ||
const nodes = []; let n; | ||
while(n = walker.nextNode()) { | ||
options.callback && options.callback(n); | ||
nodes.push(n); | ||
} | ||
return nodes; | ||
} | ||
function nodeName(elm, name) { | ||
@@ -225,2 +254,2 @@ //Element.nodeName/tagName is uppercase ..except when it's not: | ||
export { $$, $,$$1, selectors, nodeName, createElement, relativeMousePos, addEvent, live, animate, dropFiles, dropFile, dropImage }; | ||
export { $$, $,$$1, selectors, walkNodeTree, nodeName, createElement, relativeMousePos, addEvent, live, animate, dropFiles, dropFile, dropImage }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60789
1335