-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcthsl-bundle.js
10 lines (7 loc) · 5.08 KB
/
bcthsl-bundle.js
1
2
3
4
5
6
7
8
9
10
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,a=Array(e.length);t<e.length;t++)a[t]=e[t];return a}return Array.from(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,a,r){return a&&e(t.prototype,a),r&&e(t,r),t}}(),Artifier=function(){function e(){_classCallCheck(this,e),this.artifyImageOnload()}return _createClass(e,[{key:"artifyImageOnload",value:function(){var e=this;document.addEventListener("DOMContentLoaded",function(){var t=document.querySelector(".Canvas"),a=t.getContext("2d");document.querySelector(".Uploader").addEventListener("change",function(r){var n=new Image,o=new FileReader;o.onload=function(e){n.src=e.target.result},o.readAsDataURL(r.target.files[0]),n.onload=function(){var r=document.querySelector(".Content").offsetHeight-document.querySelector(".UploadWrapper").offsetHeight,o=r/n.height,u=Math.round(n.width*o);t.height=r,t.width=u,a.drawImage(n,0,0,u,r);var i=new ImageData(e.artFunction(a,u,r),u);a.putImageData(i,0,0)}})})}},{key:"artFunction",value:function(e,t,a){return new Uint8ClampedArray(e.getImageData(0,0,t,a).data)}},{key:"rgbToHsl",value:function(e){var t=e[0]/255,a=e[1]/255,r=e[2]/255,n=Math.max(t,a,r),o=Math.min(t,a,r),u=void 0,i=void 0,c=(n+o)/2;if(n===o)u=i=0;else{var l=n-o;switch(i=c>.5?l/(2-n-o):l/(n+o),n){case t:u=(a-r)/l+(a<r?6:0);break;case a:u=(r-t)/l+2;break;case r:u=(t-a)/l+4}u/=6}return[360*u,100*i,100*c]}},{key:"rgbaToRgb",value:function(e){var t=e[0]/255,a=e[1]/255,r=e[2]/255,n=e[3]/255,o=[];return o[0]=255*(1-n+n*t),o[1]=255*(1-n+n*a),o[2]=255*(1-n+n*r),[].concat(o,[255])}},{key:"getPixelAt",value:function(e,t,a,r){var n=4*e*a+4*t;return[r[n],r[n+1],r[n+2],r[n+3]]}},{key:"mergeArrays",value:function(e,t){e.push.apply(e,_toConsumableArray(t))}}]),e}();exports.default=Artifier;
},{}],2:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),_constants=require("./constants.js"),_Artifier2=require("./Artifier.js"),_Artifier3=_interopRequireDefault(_Artifier2),BasicColorTerminalHsl=function(t){function e(){_classCallCheck(this,e);var t=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return t.colorsForCanvas=[_constants.RED,_constants.ORANGE,_constants.YELLOW,_constants.GREEN,_constants.BLUE,_constants.PURPLE,_constants.PINK,_constants.WHITE,_constants.BLACK,_constants.GRAY,_constants.BROWN],t.colors=t.colorsForCanvas.map(t.rgbToHsl),t}return _inherits(e,t),_createClass(e,[{key:"artFunction",value:function(t,e,r){for(var n=t.getImageData(0,0,e,r).data,o=this.colors,s=[],a=0;a<r;a++)for(var i=0;i<e;i++){var c=this.getPixelAt(a,i,e,n);255!==c[3]&&(c=this.rgbaToRgb(c));for(var l=this.rgbToHsl(c),u=void 0,f=1e9,_=0;_<o.length;_++){var p=o[_],b=p[0]-l[0],h=p[1]-l[1],y=p[2]-l[2],v=b*b+h*h+y*y;v<f&&(f=v,u=_)}this.mergeArrays(s,this.colorsForCanvas[u])}return new Uint8ClampedArray(s)}}]),e}(_Artifier3.default),bct=new BasicColorTerminalHsl;
},{"./Artifier.js":1,"./constants.js":3}],3:[function(require,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var RED=exports.RED=[255,0,0,255],ORANGE=exports.ORANGE=[255,165,0,255],YELLOW=exports.YELLOW=[255,255,0,255],GREEN=exports.GREEN=[0,128,0,255],BLUE=exports.BLUE=[0,0,255,255],PURPLE=exports.PURPLE=[128,0,128,255],PINK=exports.PINK=[255,192,203,255],WHITE=exports.WHITE=[0,0,0,255],BLACK=exports.BLACK=[255,255,255,255],GRAY=exports.GRAY=[128,128,128,255],BROWN=exports.BROWN=[128,42,42,255];
},{}]},{},[2]);